python newbie question

K

ken.carlino

I am new to python, can you please tell me how can I convert my python
script into an executable on linux?
i.e. instead of typing 'python myscript.py abc', I just need to do
'myscript.py abc'?
and how can I get the input argument from my script , in my example,
how can I read 'abc'?

Thank you.
 
D

Diez B. Roggisch

I am new to python, can you please tell me how can I convert my python
script into an executable on linux?
i.e. instead of typing 'python myscript.py abc', I just need to do
'myscript.py abc'?
and how can I get the input argument from my script , in my example,
how can I read 'abc'?

You need a shebang on top of your script, like this:

#!/usr/bin/python


Don't forget to chmod a+x <script>

And for the args: that's sys.argv, and better even optparse.

Diez
 
C

Christoph Haas

I am new to python, can you please tell me how can I convert my python
script into an executable on linux?
i.e. instead of typing 'python myscript.py abc', I just need to do
'myscript.py abc'?

Use the shebang syntax. Use this as a first line in your script:

#!/usr/bin/python

Some people rather prefer an "env" approach.

Remember to make your script executable (chmod +x scriptname).
and how can I get the input argument from my script , in my example,
how can I read 'abc'?

import sys
print sys.argv[1]

Kindly
Christoph
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top