[Tutor] A question about sys.argv

Hugo Arts hugo.yoshi at gmail.com
Tue Nov 1 15:05:28 CET 2011

On Tue, Nov 1, 2011 at 2:48 PM, Jefferson Ragot <jbr5393 at gmail.com> wrote:
> In a Vista command prompt if I typed this:
>         >>> python  somescript.py  filename
> Will sys.argv[1] return a valid path or just the filename?
> If it just returns the filename, is there a simple way to get the path?

sys.argv contains exactly what you typed in on the command line.
Nothing more, nothing less. It doesn't care whether what you typed is
actually a filename or a plain number or some string, it just passes
the commands as they are.

You can use the os.path.abspath() function on your argument, that will
probably do what you want.


More information about the Tutor mailing list