473,544 Members | 1,822 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to pass an argument to a python program open in IDLE?

Hello,

I have open a Python program in the IDLE, but when I select the "run
module" under "run" menu, it
does not allow me to pass an argument to my Python program!
How do you pass an argument to a Python program under the IDLE? Thanks for
you help!

Nov 15 '06 #1
4 9396


On Nov 15, 7:56 am, tony...@philips .com wrote:
Hello,

I have open a Python program in the IDLE, but when I select the "run
module" under "run" menu, it
does not allow me to pass an argument to my Python program!
How do you pass an argument to a Python program under the IDLE? Thanks for
you help!
I'm using Python on an old Mac with the IDE. I think my solution would
work.

opt_parser = OptionParser()

def myfunc(argstrin g):
(self.options,s elf.args) =
sub_opt_parser. parse_args(args tring.split())
f not self.args: self.args = "[default arguments]".split()
...

if __name__=="__ma in__":
myfunc(argstrin g)
This means editing the file every time. Since I'm on a Mac, I can also
use:
if __name__=="__ma in__":
from EasyDialogs import AskString
args = AskString('Opti ons and Arguments')

myfunc(args)

I'm not sure how easy this is to implement on other platforms

Josh English
Jo************* *@gmail.com
http://www.spiritone.com/~english

Nov 15 '06 #2
Hello Josh,

Thanks for the reply. But I am not sure I understand your reply, may be
I need to explain my problem a bit more. I have a Python script which
needs an input argument to run.
e.g. python myscript.py xilinx. which run fine.

My problem is this: When I start IDLE GUI, then I open my script with
the edit window. (i.e.
File -open). I run my script under the edit window using run -run
module or F5. But IDLE does not allow me to input the argument to my
script, i.e. IDLE runs without prompting for the argument, then my
script fails. I wonder how can I pass the argument to my script under
IDLE?

Tony Ha.

Jo************* *@gmail.com wrote:
On Nov 15, 7:56 am, tony...@philips .com wrote:
Hello,

I have open a Python program in the IDLE, but when I select the "run
module" under "run" menu, it
does not allow me to pass an argument to my Python program!
How do you pass an argument to a Python program under the IDLE? Thanks for
you help!

I'm using Python on an old Mac with the IDE. I think my solution would
work.

opt_parser = OptionParser()

def myfunc(argstrin g):
(self.options,s elf.args) =
sub_opt_parser. parse_args(args tring.split())
f not self.args: self.args = "[default arguments]".split()
...

if __name__=="__ma in__":
myfunc(argstrin g)
This means editing the file every time. Since I'm on a Mac, I can also
use:
if __name__=="__ma in__":
from EasyDialogs import AskString
args = AskString('Opti ons and Arguments')

myfunc(args)

I'm not sure how easy this is to implement on other platforms

Josh English
Jo************* *@gmail.com
http://www.spiritone.com/~english
Nov 17 '06 #3

TonyHa wrote:
Hello Josh,

Thanks for the reply. But I am not sure I understand your reply, may be
I need to explain my problem a bit more. I have a Python script which
needs an input argument to run.
e.g. python myscript.py xilinx. which run fine.

My problem is this: When I start IDLE GUI, then I open my script with
the edit window. (i.e.
File -open). I run my script under the edit window using run -run
module or F5. But IDLE does not allow me to input the argument to my
script, i.e. IDLE runs without prompting for the argument, then my
script fails. I wonder how can I pass the argument to my script under
IDLE?

Tony Ha.
Just check the number of arguments and prompt if the argument is
missing:

import sys

if __name__ == '__main__':
numArgs = len(sys.argv)
if numArgs == 1:
myArg = raw_input('plea se supply missing argument: ')
else:
myArg = sys.argv[1]

print 'argument : %s' % myArg

Nov 17 '06 #4
"TonyHa" wrote:
My problem is this: When I start IDLE GUI, then I open my script with
the edit window. (i.e.
File -open). I run my script under the edit window using run -run
module or F5. But IDLE does not allow me to input the argument to my
script, i.e. IDLE runs without prompting for the argument, then my
script fails. I wonder how can I pass the argument to my script under
IDLE?
one would think that there would be a "set argument" command somewhere, but I
sure couldn't find it.

as a workaround, to help with testing, you can simply do:

import sys

if not sys.argv[1:]:
sys.argv += ["argument1" , "argument2" , "argument3"]

at the top of your program.

</F>

Nov 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2645
by: Gary Feldman | last post by:
Since I prefer to keep all my installed programs in one place, I went ahead and installed Python in Program Files/Python. The command line shell seems to work just fine, and I'm able to import things like urllib and its dependencies. However, I can't get Idle to startup. When I try running it manually (i.e. python ...idle.py), I get...
6
2237
by: Aubrey Hutchison | last post by:
Using Python 2,3,2 with idle for developing programs about 200 lines long. - Problem is not common to any specific program. Program are rather simple with no trick programming. Usually no classes but a few functions using math module with long integers. Usually for the first few tryout everything works fine and then idle locks "out" windows...
145
6191
by: David MacQuigg | last post by:
Playing with Prothon today, I am fascinated by the idea of eliminating classes in Python. I'm trying to figure out what fundamental benefit there is to having classes. Is all this complexity unecessary? Here is an example of a Python class with all three types of methods (instance, static, and class methods). # Example from Ch.23,...
0
334
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 393 open (+15) / 3315 closed (+17) / 3708 total (+32) Bugs : 908 open (+22) / 5975 closed (+49) / 6883 total (+71) RFE : 223 open ( -1) / 229 closed ( +2) / 452 total ( +1) New / Reopened Patches ______________________
7
8800
by: JAG CHAN | last post by:
Friends, As I had written earlier, I am trying to learn Python. I chose IDLE as an editor to learn Python. Now I find that it is an online editor. It is not possible for me to be always on online while learning. Kindly suggest me a suitable editor (for Windows XP) which does not require me to be on online. Regards.
7
3569
by: sam | last post by:
dear all, having spent the last couple of weeks getting to grips with python on windows, i am in the position of trying to make the transition to my newly arrived ultra 20. however, although there are plenty of files with idle somewhere in the title, idle.py (which i assume is the interpreter) will not open, as there is 'no installed...
6
5233
by: John (Z R) L | last post by:
Hi all, I am very new to programming, and I chose to study the Python language before C++. I am currently using the Wikibooks "Non-Programmer's Tutorial for Python", and am up to the section "Who goes there"? http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python/Who_Goes_There%3F But after clicking "run module" for " a = 1
12
2985
by: adamurbas | last post by:
ya so im pretty much a newb to this whole python thing... its pretty cool but i just started today and im already having trouble. i started to use a tutorial that i found somewhere and i followed the instructions and couldnt get the correct results. heres the code stuff... temperature=input("what is the temperature of the spam?") if...
2
2937
by: W. eWatson | last post by:
I had just finished working with IDLE, and tried to double-click on a py file. It produced an OK dialog with the path to the file and the msg "access denied." All my py files act that way. I rebooted and the same thing continues. I copied one py program to another computer, and accessed it there. Python 2.4. Suggestions? -- W. eWatson ...
0
7437
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7625
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7389
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5306
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4930
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3427
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1848
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.