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! 4 9222
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(argstring):
(self.options,self.args) =
sub_opt_parser.parse_args(argstring.split())
f not self.args: self.args = "[default arguments]".split()
...
if __name__=="__main__":
myfunc(argstring)
This means editing the file every time. Since I'm on a Mac, I can also
use:
if __name__=="__main__":
from EasyDialogs import AskString
args = AskString('Options 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
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(argstring):
(self.options,self.args) =
sub_opt_parser.parse_args(argstring.split())
f not self.args: self.args = "[default arguments]".split()
...
if __name__=="__main__":
myfunc(argstring)
This means editing the file every time. Since I'm on a Mac, I can also
use:
if __name__=="__main__":
from EasyDialogs import AskString
args = AskString('Options 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
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('please supply missing argument: ')
else:
myArg = sys.argv[1]
print 'argument : %s' % myArg
"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> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: ezappsrUS |
last post by:
Hi,
I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
|
by: DizelArs |
last post by:
Hi all)
Faced with a problem, element.click() event doesn't work in Safari browser.
Tried various tricks like emulating touch event through a function:
let clickEvent = new Event('click', {...
|
by: F22F35 |
last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...
| |