passing file from command line startup

MRAB python at mrabarnett.plus.com
Wed Aug 11 15:04:41 EDT 2010


Bradley Hintze wrote:
> Hi all,
> 
> Is there a way that I can startup my script and pass it a file? For example:
> 
> ~$ python myscript.py mytext.txt
> 
> and then access mytext.txt in myscript.py?
> 
> As a long shot, for myscript.py I tried
> 
> def __init__(fle):
>     print fle
> 
> expecting the full path to mytext.txt to be printed but that didn't work.
> 
> Obviously I've never done this. I hope the above makes sense. any help
> will be greatly appreciated.
> 
import sys

print sys.argv



More information about the Python-list mailing list