executing python code

Steve Holden steve at holdenweb.com
Mon Nov 8 07:16:29 EST 2004


Mike Meyer wrote:

> mfuhr at fuhr.org (Michael Fuhr) writes:
> 
> 
>>Darren Dale <dd55 at cornell.edu> writes:
>>
>>>Yes, I did chmod, the script is in the current directory.
>>>$ mycode.py
>>>bash: mycode.py: command not found
>>>
>>>I just tried:
>>>$ ./mycode.py
>>>and that will execute.
>>
>>That means the directory isn't in your PATH environment variable,
>>neither as a full path (/path/to/the/directory) nor as ".", which
>>means the current directory.  For security reasons it's usually
>>wise to leave "." out of your PATH, so if you don't want to type
> 
> 
> Actually, those reasons relate to having "." early in your path. If
> it's the last thing on your path, you won't trigger any trojan horses.
> 
Sorry, but the advice still stands. As long as commands are typed 
correctly everything is OK, but someone (like me) who makes a lot of 
typing mistakes runs the risk of triggering a trojan whose name is a 
misspelling of a command. So the best advice about putting "." on your 
path is "don;t do that".

> 
>>./mycode.py each time then put your scripts in a directory that
>>PATH knows about.  As others have mentioned, a common place for
>>a user's private scripts is in ~/bin, that is, the "bin" directory
>>under your home directory.  If it doesn't exist then you can use
>>mkdir to create it, and if it's not in your PATH then you'll need
>>to add it.
> 
> 
> I find that symlinking ~/src/python/mycode.py to ~/bin/mycode means I
> get to invoke it without having to specify the extension, and don't
> have to reinstall the file if I change it.
> 
>      <mike

That works too. Of course under Linux/Unix there's no particular reason 
to use the .py extension in the first place.

regards
  Steve
-- 
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119



More information about the Python-list mailing list