Execute script from ipython
Hi all, I have a script "myscript.py" located in "/usr/local/bin" on my linux box. I can execute it in ipython with run /usr/local/bin/myscript.py but not with run myscript.py even though /usr/local/bin is in my $PATH and in my $PYTHONPATH. What should I do to correct this? Best regards, Johan -- http://mail.python.org/mailman/listinfo/python-list
Re: Execute script from ipython
Thanks Chris! I tried using "!" instead of "run". It works but with a significant performance penalty. Best regards, Johan On Fri, Aug 19, 2011 at 5:11 PM, Chris Rebert wrote: > On Fri, Aug 19, 2011 at 6:00 AM, Johan Ekh wrote: > > Hi all, > > I have a script "myscript.py" located in "/usr/local/bin" on my linux > box. > > I can execute it in ipython with > > > > run /usr/local/bin/myscript.py > > > > but not with > > > > run myscript.py > > > > even though /usr/local/bin is in my $PATH and in my $PYTHONPATH. > > > > What should I do to correct this? > > Given that %run takes a filename and not a module name, I doubt > PYTHONPATH matters. ipython's docs for %run don't seem to indicate > that a search of any kind is performed. So, I'd say you have to either > pass a valid absolute or relative path to myscript.py, or run > myscript.py from bash instead of ipython. > > Changing your script's shebang line to ipython might also work > (haven't tried it myself). Or you could try patching ipython's run() > function to add this search feature you desire. > > Cheers, > Chris > -- > http://rebertia.com > -- http://mail.python.org/mailman/listinfo/python-list
optparse with numpy.array?
Hi all, I'm trying to use optparse to process command line parameters given to my program. It works as I expect for the types supported by optparse, i.e. int, float, string etc. but how can I pass a numpy.array or a list to my program? I have been searching for it but cannot find a good solution. By the way, I am a Python newbie so please be gentle... Best regards, Johan -- http://mail.python.org/mailman/listinfo/python-list
Re: optparse with numpy.array?
Thank you Robert, but what if I just want to create an array interactively, e.g. like m = array([1.0, 2.0, 3.0]), and pass it to my program? I tried extending optparse with a new type as explained in the link you gave me but I was not able to get it to work. Is it really neccessary follow that route just to pass an array? Lot's of people must have done this before! Best regards, Johan On Tue, Jan 27, 2009 at 1:00 AM, Robert Kern wrote: > On 2009-01-26 17:44, Johan Ekh wrote: > >> Hi all, >> I'm trying to use optparse to process command line parameters given to >> my program. >> It works as I expect for the types supported by optparse, i.e. int, >> float, string etc. but how can I >> pass a numpy.array or a list to my program? >> > > http://docs.python.org/library/optparse#optparse-extending-optparse > > Figure out the text format you want your users to type the value on the > command line, write a function that will take that text and convert it to an > array or list, then customize OptionParser to use that parser as given in > the link above. Keep in mind that your user probably won't want to need to > use whitespace or any kind of brackets. Commas are nice, though. > > You may also want to consider taking a filename and parsing that file > instead. > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless > enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: optparse with numpy.array?
Thank you James, but I just can't optparse to accept an array, only integers, floats ans strings. My code looks like this from optparse import OptionParser parser = OptionParser() parser.add_option('-t', '--dt', action='store', type='float', dest='dt_i', default=0.1, help='time increment where lsoda saves results') parser.add_option('-T', '--tstop', action='store', type='float', dest='tstop_i', default=1.0, help='duration of the solution') parser.add_option('-m', '--mass_vector', action='store', type='float', dest='m_i', default=[1.0, 1.0], help='vector with lumped masses') op, args = parser.parse_args(sys.argv[1:]) I want this to work for m_i = array([1.0, 2.0, 3.0]) but the optparse complains that m_i is not a float. Best regards, Johan On Tue, Jan 27, 2009 at 6:53 AM, James Mills wrote: > On Tue, Jan 27, 2009 at 3:45 PM, Johan Ekh wrote: > > Thank you Robert, > > but what if I just want to create an array interactively, e.g. like m = > > array([1.0, 2.0, 3.0]), and pass it > > to my program? I tried extending optparse with a new type as explained in > > the link you gave me > > but I was not able to get it to work. Is it really neccessary follow that > > route just to pass an array? > > Lot's of people must have done this before! > > Normally command line applications accept > a number of arguments which are available > in sys.argv > > cheers > James > -- http://mail.python.org/mailman/listinfo/python-list
Re: optparse with numpy.array?
Thanks, James I will try your suggestion! Robert, what mean with "interactively" is that i would like to create an array in the ipython shell, e.g. with m_i = array([1.0, 2.0, 3.0]) or by reading a file with values etc., and then execute my program with "myprog -m m_i" and thus pass the array "m_i" to my program. This is just an example. I would like to pass several arrays. My program will be wrapped inside a loop and the arrays are updated in each loop. I have never heard of the "argparse" library. Do you think that it would be better to use that in my case? Best regards, Johan On Tue, Jan 27, 2009 at 7:12 AM, Robert Kern wrote: > On 2009-01-27 00:01, Johan Ekh wrote: > >> Thank you James, >> but I just can't optparse to accept an array, only integers, floats ans >> strings. >> >> My code looks like this >> >> from optparse import OptionParser >> parser = OptionParser() >> parser.add_option('-t', '--dt', action='store', type='float', >> dest='dt_i', default=0.1, help='time increment where lsoda saves results') >> parser.add_option('-T', '--tstop', action='store', type='float', >> dest='tstop_i', default=1.0, help='duration of the solution') >> parser.add_option('-m', '--mass_vector', action='store', type='float', >> dest='m_i', default=[1.0, 1.0], help='vector with lumped masses') >> op, args = parser.parse_args(sys.argv[1:]) >> >> I want this to work for m_i = array([1.0, 2.0, 3.0]) but the optparse >> complains that m_i is not a float. >> > > Well, yes, because you declared that --mass_vector was type='float'. You > will need to subclass OptionParser in order to parse something that is not > one of the included types. Yes, it is a bit cumbersome; it's one of the > reasons I usually use the third-party argparse library instead. You only > need to supply a parsing function rather than subclass. > > I'm afraid I don't really understand what you want when you say that you > want to create an array interactively. Can you show me an example command > line that you want to parse? Keep in mind that in many shells, ()[] > characters are specially handled by the shell and are not convenient for > users. > > BTW, I am subscribed to the list. You do not need to Cc me. > > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless > enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Multiple python installations on opensuse?
Hi all, I use the finite element package ABAQUS that is partly built around python 2.4.3. ABAQUS ships with its own version of python 2.4.3 but it comes without third party libraries, e.g. numpy and scipy. In order to load these modules into ABAQUS python I must install python 2.4.3. on my opensuse laptop. How can I do this without interference with my python 2.6 installation that I use for all my non-ABAQUS python work? Best regards, Johan -- http://mail.python.org/mailman/listinfo/python-list