Mailing List Archive

python + bash + new user
hello,

I am not new to programming but new to python...i want to know how do i
call functions from the prompt....

joyce
python + bash + new user [ In reply to ]
In article <3793BE52.43E023BB@netcard.com>,
Joyce Stack <joyce@netcard.com> wrote:
>
>I am not new to programming but new to python...i want to know how do i
>call functions from the prompt....

From which prompt, python or bash? The python prompt should look
something like this:

% python
Python 1.5.2 (#6, Jun 29 1999, 15:08:27) [GCC 2.7.2] on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>>

You can then type any valid python command or expression at the ">>>"
python prompt. For example:

>>> int("3")
3
>>> x=int("3")
>>> x*x
9

Note that commands do not print output, but expressions do. And, yes,
startling as it is for a C programmer, "=" is *not* an expression but a
statement/command.
--
--- Aahz (@netcom.com)

Androgynous poly kinky vanilla queer het <*> http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6 (if you want to know, do some research)
python + bash + new user [ In reply to ]
Sorry about being vague...i meant the Bash prompt...i have gotten other simple
programs to work...changed mode and executed the programs ...but i dont know how to
run the program and pass a variable at the same time...

Thanking you for you help..

Joyce

Aahz Maruch wrote:

> In article <3793BE52.43E023BB@netcard.com>,
> Joyce Stack <joyce@netcard.com> wrote:
> >
> >I am not new to programming but new to python...i want to know how do i
> >call functions from the prompt....
>
> From which prompt, python or bash? The python prompt should look
> something like this:
>
> % python
> Python 1.5.2 (#6, Jun 29 1999, 15:08:27) [GCC 2.7.2] on sunos5
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>>
>
> You can then type any valid python command or expression at the ">>>"
> python prompt. For example:
>
> >>> int("3")
> 3
> >>> x=int("3")
> >>> x*x
> 9
>
> Note that commands do not print output, but expressions do. And, yes,
> startling as it is for a C programmer, "=" is *not* an expression but a
> statement/command.
> --
> --- Aahz (@netcom.com)
>
> Androgynous poly kinky vanilla queer het <*> http://www.rahul.net/aahz/
> Hugs and backrubs -- I break Rule 6 (if you want to know, do some research)
python + bash + new user [ In reply to ]
In article <3793C729.55DE42D0@netcard.com>,
Joyce Stack <joyce@netcard.com> wrote:
>
>Sorry about being vague...i meant the Bash prompt...i have gotten other
>simple programs to work...changed mode and executed the programs ...but
>i dont know how to run the program and pass a variable at the same
>time...

Look up sys.argv -- don't forget to "import sys" in your program.
--
--- Aahz (@netcom.com)

Androgynous poly kinky vanilla queer het <*> http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6 (if you want to know, do some research)
python + bash + new user [ In reply to ]
On Tue, Jul 20, 1999 at 12:42:42AM +0000, Joyce Stack wrote:
> Sorry about being vague...i meant the Bash prompt...i have gotten other simple
> programs to work...changed mode and executed the programs ...but i dont know how to
> run the program and pass a variable at the same time...
>

$ python -c "print 'Hello, I\'m called from the bash prompt... how nice\!'"

regards,
Gerrit.
python + bash + new user [ In reply to ]
Joyce Stack <joyce@netcard.com> wrote:
> Sorry about being vague...i meant the Bash prompt...i have gotten other simple
> programs to work...changed mode and executed the programs ...but i dont know how to
> run the program and pass a variable at the same time...

Gerrit showed you how to pass a command-line-script to python, and I will
show how to pass parameters to your script, you can ofcourse combine the two:)

$ cat simple.py
#!/usr/bin/python
from sys import argv
print "I'll show you my parameters:"
for p in argv:
print p

$ ./simple.py one parameter and others
./simple.py
one
parameter
and
others

hope this helps

--
groetjes, carel
python + bash + new user [ In reply to ]
Carel,

I did exactly as you said and chmod's etc but it just says that it doesnt recognise
"./simple.py" as a command.???..what am i doing work?? anyother simple programs will
work...

Joyce


Carel Fellinger wrote:

> Joyce Stack <joyce@netcard.com> wrote:
> > Sorry about being vague...i meant the Bash prompt...i have gotten other simple
> > programs to work...changed mode and executed the programs ...but i dont know how to
> > run the program and pass a variable at the same time...
>
> Gerrit showed you how to pass a command-line-script to python, and I will
> show how to pass parameters to your script, you can ofcourse combine the two:)
>
> $ cat simple.py
> #!/usr/bin/python
> from sys import argv
> print "I'll show you my parameters:"
> for p in argv:
> print p
>
> $ ./simple.py one parameter and others
> ./simple.py
> one
> parameter
> and
> others
>
> hope this helps
>
> --
> groetjes, carel
python + bash + new user [ In reply to ]
In article <3797AE3B.687785E5@netcard.com>,
Joyce Stack <joyce@netcard.com> wrote:
>
>I did exactly as you said and chmod's etc but it just says that it
>doesnt recognise "./simple.py" as a command.???..what am i doing work??
>anyother simple programs will work...

That's because you don't have Python installed at /usr/local/bin/python
(or you're on a Windoze box). Try 'python simple.py' instead.
--
--- Aahz (@netcom.com)

Androgynous poly kinky vanilla queer het <*> http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6 (if you want to know, do some research)
python + bash + new user [ In reply to ]
Joyce Stack wrote:
> I did exactly as you said and chmod's etc but it just
> says that it doesnt recognise "./simple.py" as a command.???
> > $ cat simple.py
> > #!/usr/bin/python

Joyce,

Your python interpreter is not located in /usr/bin. It may
be in /usr/local/bin. On many systems you can use the 'which'
command to determine where the executable is, e.g.

$ which python
/usr/local/bin/python

Alternatively, you can use the following line which works on
many Unix systems:

#!/usr/bin/env python
^---- note the space between env and python

symlink-it-there-when-your-sysadmin's-not-looking-ly yr's,

Jeff Bauer
Rubicon, Inc.
python + bash + new user [ In reply to ]
On Fri, 23 Jul 1999 01:37:31 GMT, Jeff Bauer <jbauer@rubic.com> wrote:
>Joyce Stack wrote:
>> I did exactly as you said and chmod's etc but it just
>> says that it doesnt recognise "./simple.py" as a command.???
>> > $ cat simple.py
>> > #!/usr/bin/python
>Your python interpreter is not located in /usr/bin. It may
>be in /usr/local/bin. On many systems you can use the 'which'
>command to determine where the executable is.
>Alternatively, you can use the following line which works on
>many Unix systems:
> #!/usr/bin/env python
>symlink-it-there-when-your-sysadmin's-not-looking-ly yr's,

So while we're on this topic, I seem to have hit a small snag... I'm
using RedHat 6.something at home, and it ships with Python 1.5.1. I've
also got an NT box at work where I'm using Python 1.5.2. In the
interests of being able to move scripts from one box to the other, I've
installed Python 1.5.2 in /opt/{bin,lib/python1.5,man/man1}. If I log
in myself, I can run /opt/bin/python, and get 1.5.2. I can also create
a program with "#!/opt/bin/python", and if I type in "python spam.py" at
the command prompt, it works just fine. Unfortunately, if I type in
"./spam.py", it doesn't do quite what I want it to. I've traced my
problems down to sys.path (when it works, it points at /opt, when it
doesn't, it points at /usr), but I can't seem to figure out where it's
getting set, or how I can change it. (I've tried setting $PYTHONHOME,
which works for me, but the whole reason I started this was to run cgi
scripts, and it's not working for the cgi scripts.)

So my question is this. Can I get python working in such a way that if
it's being run from /opt, it will check /opt before /usr? I'm not
averse to changing c files, and recompiling.

(Oh, yeah, the script is at http://tor.dhs.org/cgi-bin/daily.py It just
grabs a bunch of comics, the weather in sunny Toronto, and the word of
the day, and puts them all up on one convienent page. If any of the
people maintaining the script archives want a copy of it, I'ld be more
than happy to comment it, and send it off.)

Thanks,
Blake.

--
One Will. One Dream. One Truth. One Destiny. One Love.
python + bash + new user [ In reply to ]

I gave up on this on my RH system and just installed 1.5.2 on top of the
stuff in /usr. There are two places in /usr/lib/rhs/netcfp/netcfg.py where
you have to add defaults for a couple function arguments:

% diff netcfg.py~ netcfg.py
140c140
< def LinespeedMenu(master=None, variable, width='20'):
---
> def LinespeedMenu(master=None, variable=None, width='20'):
148c148
< def ModemportMenu(master=None, variable, width='20'):
---
> def ModemportMenu(master=None, variable=None, width='20'):

to get the netcfg command to work. You also have to enable the crypt module
(RH uses it somewhere). Other than that I've had no trouble.

Skip Montanaro | http://www.mojam.com/
skip@mojam.com | http://www.musi-cal.com/~skip/
847-475-3758