problems with opening files due to file's path

Alexnb alexnbryan at gmail.com
Wed Jun 11 03:55:25 CEST 2008


Okay, I don't understand how it is too vague, but here:

>>> path = "C:\Documents and Settings\Alex\My Documents\My
>>> Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm
>>> Yours.wma"
>>> os.startfile(path)
Traceback (most recent call last):
  File "<pyshell#39>", line 1, in <module>
    os.startfile(path)
WindowsError: [Error 2] The system cannot find the file specified:
"C:\\Documents and Settings\\Alex\\My Documents\\My
Music\\Rhapsody\\Bryanbros\\Jason Mraz\\I'm Yours (Single)\x01 - I'm
Yours.wma"

Here's another way:

>>> os.startfile(r"%s"%path)
Traceback (most recent call last):
  File "<pyshell#40>", line 1, in <module>
    os.startfile(r"%s"%path)
WindowsError: [Error 2] The system cannot find the file specified:
"C:\\Documents and Settings\\Alex\\My Documents\\My
Music\\Rhapsody\\Bryanbros\\Jason Mraz\\I'm Yours (Single)\x01 - I'm
Yours.wma"

Same output, however if I personally input it like so:

>>> os.startfile("C:\\Documents and Settings\\Alex\\My Documents\\My
>>> Music\\Rhapsody\\Bryanbros\\Jason Mraz\\I'm Yours (Single)\\01 - I'm
>>> Yours.wma")

It works out fine because I can make each backslash doubles so it doesn't
mess stuff up. So if I could take the path varible and make ever "\" into a
"\\" then it would also work. 

Did I clarify?



Grant Edwards wrote:
> 
> On 2008-06-11, Alexnb <alexnbryan at gmail.com> wrote:
> 
>> I am using GUI, Tkinter to be exact. But regardless of how the
>> path gets there, it needs to opened correctly. The problem I
>> am running into is that the program receives a path of a file,
>> either .wma or .mp3 and is supposed to open it. I run into
>> problems when there is either a ")" or a number next to the
>> backslash "\" in the file path. I am looking for a way to make
>> it work with a variable, I can make it work when I physically
>> type it in, but not with a variable that holds the path.
> 
> You're going to have to show us code and example input and
> output. Your description of the problem is far too vague for
> anybody to help you.
> 
> -- 
> Grant Edwards                   grante             Yow!  With YOU, I can
> be
>                                   at               MYSELF... We don't NEED
>                                visi.com            Dan Rather...
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

-- 
View this message in context: http://www.nabble.com/problems-with-opening-files-due-to-file%27s-path-tp17759531p17768511.html
Sent from the Python - python-list mailing list archive at Nabble.com.




More information about the Python-list mailing list