By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,222 Members | 2,374 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,222 IT Pros & Developers. It's quick & easy.

Too long of a process to save .py scripts

jimpy
P: 7
Greetings,
Using Ubuntu 7.10 and Python 2.5.1 (r251:54863, Mar 7 2008, 04:10:12)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2

I am presently going through the "A Byte Of Python" tutorial.

When I copy the little .py scripts and save them, I find they must be in the /usr/bin directory.

But I cannot directly save them to that location. I have to save them to my Documents folder, then execute a "gksudo nautilus" command to access /usr/bin. Then click and drag the file into the /usr/bin directory.

Very cumbersoe, but I don't know any other way to get them in the right location.

Obviously, I am relatively new to Ubuntu, and absolutely new to Pythoon.

Thank you
Mar 18 '08 #1
Share this Question
Share on Google+
5 Replies


Expert 100+
P: 849
You do not need to save python scripts in /usr/bin. Make the first line of the script (every script) #!/usr/bin/python if you want to use ./ to run it after marking it executable with chmod. Otherwise, you can use python to run the script with the command 'python foo.py'.
Mar 18 '08 #2

jimpy
P: 7
Thank you for the reply, Lahari -
I do make the first line #! /usr/bin/python.
And I do make the scripts executable.
You last answer,
"Otherwise you can use python to run the script with the command python foo.py",
went over my head.
With the script residing in /usr/bin, I can open a terminal and type the just the script name, and it will execute.
My problem is getting the scripts into place without so much effort.
I know I am missing something here, but I just don't know what it is.
Mar 18 '08 #3

micmast
100+
P: 144
I think you want to execute it like this:

$> myprogram.py

right?

if so you need to add the directory to your working path

$> PATH=/my/home/dir/with/python/scripts/:$PATH

Don't forget the $PATH at the end!!!!


The easy way:

just add ./ in front of the script

$> ./myprogram.py
Mar 18 '08 #4

jimpy
P: 7
Ah yes ... that is good. Problem solved. Sometimes I can be very very dense.

Many thanks for the replies. It's really appreciated.

And now, onward and upward!
Mar 18 '08 #5

Expert 100+
P: 849
The 'python foo.py' is telling python to run the file foo.py. If you had a different file, say myfile.py, the command would be python myfile.py. This is more secure than adding . to your path. If you just type 'python' in, you'd get an interactive Python shell you can use to try things out that can be quite useful sometimes.
Mar 18 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.