470,581 Members | 2,460 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,581 developers. It's quick & easy.

os.startfile() - one or two arguments?

Can any Windows user give a working example of adding a "command verb"
to os.startfile()?

When I try it, it squawks that it takes only one argument.
os.startfile('d:/','explore')

Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: startfile() takes exactly 1 argument (2 given)

from os module

startfile( path[, operation])
Start a file with its associated application.

When operation is not specified or 'open', this acts like
double-clicking the file in Windows Explorer, or giving the file name
as an argument to the start command from the interactive command shell:
the file is opened with whatever application (if any) its extension is
associated.

When another operation is given, it must be a ``command verb'' that
specifies what should be done with the file. Common verbs documented by
Microsoft are 'print' and 'edit' (to be used on files) as well as
'explore' and 'find' (to be used on directories).

Thanks,

rpd

"Give a man a fire and keep him warm for a day. Light a man on fire and
he will be warm for rest of his life." --Terry Pratchett

Apr 28 '06 #1
3 14330
BartlebyScrivener wrote:
Can any Windows user give a working example of adding a "command verb"
to os.startfile()?

When I try it, it squawks that it takes only one argument.
os.startfile('d:/','explore')

Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: startfile() takes exactly 1 argument (2 given)


Works fine for me with Python 2.5a2 on Win2K
I ran: os.startfile('c:/','explore')
And an explorer window popped up.

--Scott David Daniels
sc***********@acm.org
Apr 28 '06 #2
BartlebyScrivener wrote:
Can any Windows user give a working example of adding a "command verb"
to os.startfile()?

When I try it, it squawks that it takes only one argument.
os.startfile('d:/','explore')

Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: startfile() takes exactly 1 argument (2 given)

from os module

startfile( path[, operation])
Start a file with its associated application.

When operation is not specified or 'open', this acts like
double-clicking the file in Windows Explorer, or giving the file name
as an argument to the start command from the interactive command shell:
the file is opened with whatever application (if any) its extension is
associated.

When another operation is given, it must be a ``command verb'' that
specifies what should be done with the file. Common verbs documented by
Microsoft are 'print' and 'edit' (to be used on files) as well as
'explore' and 'find' (to be used on directories).


The optional second argument was added in Python 2.5 (currently in alpha).
These examples work for me, with python 2.5a2:

os.startfile("Rechnung-28.10.pdf", "print")
os.startfile("c:\\", "explore")

Thomas

Apr 28 '06 #3
Whoops! Sorry all. I was using the "in-development" version of the
documentation and didn't even realize it.

Thank you,

Rick

Apr 28 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Chuck Anderson | last post: by
2 posts views Thread by Matthias Huening | last post: by
6 posts views Thread by Timothy Smith | last post: by
2 posts views Thread by dcrespo | last post: by
7 posts views Thread by sfeher | last post: by
5 posts views Thread by ecuesta18 | last post: by
1 post views Thread by Alexnb | last post: by
1 post views Thread by livre | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.