newbie running IDLE with command line arguments

C

crypto

Hi,

I am trying to use IDLE in order to test my program. My program is the
following:

import sys, socket
size = 1024
host, port, message = sys.argv[1], int(sys.argv[2]), sys.argv[3]
print host

How do I run this program on IDLE? I trying Run->Run Module but it
gives me:

Traceback (most recent call last):
File "C:\Python24\userprograms\simpleclient.py", line 5, in
-toplevel-
host, port, message = sys.argv[1], int(sys.argv[2]), sys.argv[3]
IndexError: list index out of range

How do I enter the command arguments?

Thanks,
C29
 
Q

qwweeeit

Hi,
also if you print only 'host', running the script, you have to pass
all the 3 parameters, like:
python socket_script.py myserver 567 'All is OK!'
The parameter sys.argv[0] is of course the script 's name (in this
example: socket_script.py)
Bye.
 
Q

qwweeeit

Hi,
I apologize not to have answered to your question in a coherent way. I
can take as excuses that I don't know English very well or that I was
mistaken by the fact that you refer a piece of code with the error
traceback (instead of simply asking for how entering command
parameters in IDLE).
But the "real" reason is what I call the "guru syndrome", that takes
the newbies like me when they think they can teach something to
experts!
Of course I don't know the answer for your question, which can be
referred also to the interactive Python and, AFAIK, also to the script
itself.
The only suggestion is to wrap your code with embedded the wanted
parameters, and call it by means of import (but be carefull...I'm not
an expert!)
Bye.
 
P

Philippe C. Martin

I might be missing it, but I do not see anyway to set command line params in
IDLE.

You might hage to set the values in your code:
host, port, message = 'localhost', 9000, .....;
 
Z

zsolt-public4516

Hmm, I submitted an earlier message, but something seems to have gone
wrong.

Try this:

import sys

usingIdle = 0

for eachPath in sys.path:
if eachPath.find("idlelib"):
usingIdle = 1
break

if usingIdle:
host="localhost"
port="2000"
msg="Hello world"
else:
host, port, message = sys.argv[1], int(sys.argv[2]), sys.argv[3]

import sys, socket
size = 1024
print host
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top