Hi All, have a question

P

Paul Metzger

Hi, I'm still a relative Python newbie, though I am learning more with every
project:) I have a script I wrote to back up a Linux server to another
server. The script is centered around the OS module. Problem is, then I put
the #!/usr/bin/python in the front and try to run it as a executable, it
comes up and tells me the module can't be imported, and the rest goes
straight to hell from there. Thing is, if I run the script with the
interpreter manually (IE, python backup.py) it runs just fine. On the other
two servers, it works just like it should, I type back up and it runs. Does
anyone have any ideas where I need to start looking?

Thanks in advance,

Paul
 
B

Ben Finney

Hi, I'm still a relative Python newbie, though I am learning more with every
project:)

Glad you're charging ahead with your learning.
I put
the #!/usr/bin/python in the front

Presumably you mean this was placed on the first line.

To make your script a little more portable, the shebang line should be:

#!/usr/bin/env python

This will execute the "python" command from wherever it resides,
presuming it is in the user's execution PATH environment variable.
try to run it as a executable, it comes up and tells me the module
can't be imported

Please show the exact command you're typing, and the exact error
message.


To make a script that can be imported as a module *and* executed as a
script, put the "do this stuff when run as a script" at the end in the
following conditional block:

if ( __name__ == '__main__' ):
# do the main purpose of this script

More here:

<http://www.python.org/doc/current/lib/module-main.html>
 

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

Forum statistics

Threads
474,178
Messages
2,570,955
Members
47,509
Latest member
Jack116

Latest Threads

Top