raw_input with a pre-compiled data
Hi all. I need to use a function like the raw_input to read data from user command line, but I really like to pre-compile the choice and I'm not able to do this. There is some other function/module I can use? I wanna to pre-compile the raw_input input line with the current working path. -- -- luca -- http://mail.python.org/mailman/listinfo/python-list
Re: raw_input with a pre-compiled data
On Sat, Jun 20, 2009 at 7:17 AM, Luca wrote: > Hi all. > > I need to use a function like the raw_input to read data from user > command line, but I really like to pre-compile the choice and I'm not > able to do this. There is some other function/module I can use? > I wanna to pre-compile the raw_input input line with the current working path. What does "pre-compile" mean in this context? It's not clear at all, so I can't even understand your question. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: raw_input with a pre-compiled data
En Sat, 20 Jun 2009 11:17:01 -0300, Luca escribió: I need to use a function like the raw_input to read data from user command line, but I really like to pre-compile the choice and I'm not able to do this. There is some other function/module I can use? I wanna to pre-compile the raw_input input line with the current working path. What do you mean "pre-compile the raw_input input line"? Maybe you're looking for this: import os defpath = os.getcwd() path = raw_input("Enter path [%s]: " % defpath) if not path: path = defpath print "Using path=%s" % path -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: raw_input with a pre-compiled data
Luca wrote: Hi all. I need to use a function like the raw_input to read data from user command line, but I really like to pre-compile the choice and I'm not able to do this. There is some other function/module I can use? I wanna to pre-compile the raw_input input line with the current working path. You'll have to define several terms for us: 1) "pre-compile" - Are you coding in Python, or in C, or some other compiled language? Microsoft C has (had?) something called pre-compiled headers, but they never worked very well, so I kept them disabled. 2) "the choice" - what choice would that be? 3) "this" - what's this? 4) "current working path" - what does this mean? Do you perhaps mean "current directory" aka "current working directory" ? Or do you mean the path to the __main__ file? The only thing I can understand clearly is "read data from user command line". You get that from sys.argv usually, or you can parse it with optparse. Or if you need the line unmodified, AND if you're on Windows, you can use the win32 module to call something like GetCommandLine(). I'd have to check that last one, though. -- http://mail.python.org/mailman/listinfo/python-list
Re: raw_input with a pre-compiled data
patx wrote: Could you use if elif statements? Don't understand what you mean really? On Sat, Jun 20, 2009 at 3:01 PM, Dave Angel wrote: Luca wrote: Hi all. I need to use a function like the raw_input to read data from user command line, but I really like to pre-compile the choice and I'm not able to do this. There is some other function/module I can use? I wanna to pre-compile the raw_input input line with the current working path. You'll have to define several terms for us: 1) "pre-compile" - Are you coding in Python, or in C, or some other compiled language? Microsoft C has (had?) something called pre-compiled headers, but they never worked very well, so I kept them disabled. 2) "the choice" - what choice would that be? 3) "this" - what's this? 4) "current working path" - what does this mean? Do you perhaps mean "current directory" aka "current working directory" ? Or do you mean the path to the __main__ file? The only thing I can understand clearly is "read data from user command line". You get that from sys.argv usually, or you can parse it with optparse. Or if you need the line unmodified, AND if you're on Windows, you can use the win32 module to call something like GetCommandLine(). I'd have to check that last one, though. -- http://mail.python.org/mailman/listinfo/python-list This was sent off-list. And it was top-posted, so I'll have to copy his two questions here... Could you use if elif statements? Yes. Whenever they're needed. But I don't see the relevance to this thread. > Don't understand what you mean really? This "question" doesn't parse. -- http://mail.python.org/mailman/listinfo/python-list
Re: raw_input with a pre-compiled data
On Sat, Jun 20, 2009 at 6:38 PM, Chris Rebert wrote: > On Sat, Jun 20, 2009 at 7:17 AM, Luca wrote: >> Hi all. >> >> I need to use a function like the raw_input to read data from user >> command line, but I really like to pre-compile the choice and I'm not >> able to do this. There is some other function/module I can use? >> I wanna to pre-compile the raw_input input line with the current working >> path. > > What does "pre-compile" mean in this context? It's not clear at all, > so I can't even understand your question. I'm really sorry to all that replied... In fact I literally traduced a concept from italian and the term precompiled was not so clear... What I mean is this: I wanna that raw_input (or other modules) ask to the user the data, but some data inserted is already present, to the user can cancel it with the BACKSPACE key. Examples below (the "_" is the initial cursor position). >>> raw_input("Insert the directory to work: ") Insert the directory to work: _ What I need is: >>> XXX_raw_input("Insert the directory to work: ", default="/home/john/") Insert the directory to work: /home/john_ In the second example a user can cancel the text "/home/john". I hope this time is more clear, sorry again. -- -- luca -- http://mail.python.org/mailman/listinfo/python-list
Re: raw_input with a pre-compiled data
Luca wrote: > On Sat, Jun 20, 2009 at 6:38 PM, Chris Rebert wrote: >> On Sat, Jun 20, 2009 at 7:17 AM, Luca wrote: >>> Hi all. >>> >>> I need to use a function like the raw_input to read data from user >>> command line, but I really like to pre-compile the choice and I'm not >>> able to do this. There is some other function/module I can use? >>> I wanna to pre-compile the raw_input input line with the current working >>> path. >> >> What does "pre-compile" mean in this context? It's not clear at all, >> so I can't even understand your question. > > I'm really sorry to all that replied... In fact I literally traduced a With "traduced" you stumbled upon another false friend ;) http://it.wikipedia.org/wiki/Falso_amico > concept from italian and the term precompiled was not so clear... > > What I mean is this: I wanna that raw_input (or other modules) ask to > the user the data, but some data inserted is already present, to the > user can cancel it with the BACKSPACE key. > > Examples below (the "_" is the initial cursor position). > > >>> raw_input("Insert the directory to work: ") > Insert the directory to work: _ > > What I need is: > >>> XXX_raw_input("Insert the directory to work: ", > >>> default="/home/john/") > Insert the directory to work: /home/john_ > > In the second example a user can cancel the text "/home/john". > > I hope this time is more clear, sorry again. import readline def input_default(prompt, default): def startup_hook(): readline.insert_text(default) readline.set_startup_hook(startup_hook) try: return raw_input(prompt) finally: readline.set_startup_hook(None) print input_default("directory? ", default="/home/john") The cmd module may also be worth having a look. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: raw_input with a pre-compiled data
Peter Otten wrote: Luca wrote: On Sat, Jun 20, 2009 at 6:38 PM, Chris Rebert wrote: On Sat, Jun 20, 2009 at 7:17 AM, Luca wrote: Hi all. I need to use a function like the raw_input to read data from user command line, but I really like to pre-compile the choice and I'm not able to do this. There is some other function/module I can use? I wanna to pre-compile the raw_input input line with the current working path. What does "pre-compile" mean in this context? It's not clear at all, so I can't even understand your question. I'm really sorry to all that replied... In fact I literally traduced a With "traduced" you stumbled upon another false friend ;) http://it.wikipedia.org/wiki/Falso_amico concept from italian and the term precompiled was not so clear... What I mean is this: I wanna that raw_input (or other modules) ask to the user the data, but some data inserted is already present, to the user can cancel it with the BACKSPACE key. Examples below (the "_" is the initial cursor position). >>> raw_input("Insert the directory to work: ") Insert the directory to work: _ What I need is: >>> XXX_raw_input("Insert the directory to work: ", >>> default="/home/john/") Insert the directory to work: /home/john_ In the second example a user can cancel the text "/home/john". I hope this time is more clear, sorry again. import readline def input_default(prompt, default): def startup_hook(): readline.insert_text(default) readline.set_startup_hook(startup_hook) try: return raw_input(prompt) finally: readline.set_startup_hook(None) print input_default("directory? ", default="/home/john") The cmd module may also be worth having a look. Peter The readline module is specific to Unix implementations. I don't know what OS the OP was using. -- http://mail.python.org/mailman/listinfo/python-list
Re: raw_input with a pre-compiled data
On Sun, Jun 21, 2009 at 12:51 PM, Peter Otten<__pete...@web.de> wrote: > With "traduced" you stumbled upon another false friend ;) > > http://it.wikipedia.org/wiki/Falso_amico D'oh!!! x-) > import readline > > def input_default(prompt, default): > def startup_hook(): > readline.insert_text(default) > readline.set_startup_hook(startup_hook) > try: > return raw_input(prompt) > finally: > readline.set_startup_hook(None) > > print input_default("directory? ", default="/home/john") > Thanks! It works! This is working on Linux and MacOS too. > The readline module is specific to Unix implementations. > I don't know what OS the OP was using. Any one knows is this working also on Windows? I've no Win system right no to test this... -- -- luca -- http://mail.python.org/mailman/listinfo/python-list
Re: raw_input with a pre-compiled data
On Mon, Jun 22, 2009 at 1:19 AM, Luca wrote: > On Sun, Jun 21, 2009 at 12:51 PM, Peter Otten<__pete...@web.de> wrote: >> With "traduced" you stumbled upon another false friend ;) >> >> http://it.wikipedia.org/wiki/Falso_amico > > D'oh!!! x-) > >> import readline >> >> def input_default(prompt, default): >> def startup_hook(): >> readline.insert_text(default) >> readline.set_startup_hook(startup_hook) >> try: >> return raw_input(prompt) >> finally: >> readline.set_startup_hook(None) >> >> print input_default("directory? ", default="/home/john") >> > > Thanks! It works! This is working on Linux and MacOS too. > >> The readline module is specific to Unix implementations. >> I don't know what OS the OP was using. > > Any one knows is this working also on Windows? I've no Win system > right no to test this... No, it won't. "specific to Unix" == Unix-only Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: raw_input with a pre-compiled data
Luca wrote: > On Sun, Jun 21, 2009 at 12:51 PM, Peter Otten<__pete...@web.de> wrote: >> import readline > Any one knows is this working also on Windows? I've no Win system > right no to test this... I do not have Windows available, either, but you might try http://ipython.scipy.org/moin/PyReadline/Intro Peter -- http://mail.python.org/mailman/listinfo/python-list