469,934 Members | 1,847 Online

# Re: problems with opening files due to file's path

Gerhard HÃ¤ring wrote:

Alexnb wrote:
>Okay, so what I want my program to do it open a file, a music file in
specific, and for this we will say it is an .mp3. Well, I am using the
system() command from the os class. [...]

system("\"C:\Documents and Settings\Alex\My Documents\My
Music\Rhapsody\Bryanbros\Weezer\(2001)\04 - Island In The Sun.wma\"")
[...]
Try os.startfile() instead. It should work better.

-- Gerhard

--
http://mail.python.org/mailman/listinfo/python-list

No, it didn't work, but it gave me some interesting feedback when I ran it
in the shell. Heres what it told me:
>>os.startfile("C:\Documents and Settings\Alex\My Documents\My
Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm
Yours.wma")
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
os.startfile("C:\Documents and Settings\Alex\My Documents\My
Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm Yours.wma")

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"

See it made each backslash into two, and the one by the parenthesis and the
0 turned into an x....
--
View this message in context: http://www.nabble.com/problems-with-...p17759825.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Jun 27 '08 #1
34 4479
On Jun 10, 11:45*am, Alexnb <alexnbr...@gmail.comwrote:
Gerhard Häring wrote:
Alexnb wrote:
Okay, so what I want my program to do it open a file, a music file in
specific, and for this we will say it is an .mp3. Well, I am using the
system() command from the os class. [...]
system("\"C:\Documents and Settings\Alex\My Documents\My
Music\Rhapsody\Bryanbros\Weezer\(2001)\04 - Island In The Sun.wma\"")
[...]
Try os.startfile() instead. It should work better.
-- Gerhard
--
http://mail.python.org/mailman/listinfo/python-list

No, it didn't work, but it gave me some interesting feedback when I ran it
in the shell. Heres what it told me:
>os.startfile("C:\Documents and Settings\Alex\My Documents\My
Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm
Yours.wma")

Traceback (most recent call last):
* File "<pyshell#10>", line 1, in <module>
* * os.startfile("C:\Documents and Settings\Alex\My Documents\My
Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm Yours.wma")

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"

See it made each backslash into two, and the one by the parenthesis and the
0 turned into an x....
--
View this message in context:http://www.nabble.com/problems-with-...o-file%27s-pat...
Sent from the Python - python-list mailing list archive at Nabble.com.
Yeah. You need to either double all the backslashes or make it a raw
string by adding an "r" to the beginning, like so:

os.startfile(r'C:\path\to\my\file')

HTH

Mike
Jun 27 '08 #2

Hey thanks!, both the raw and the double backslashes worked. You are a
gentleman and a scholar.

Mike Driscoll wrote:

On Jun 10, 11:45 am, Alexnb <alexnbr...@gmail.comwrote:
>Gerhard HÃ¤ring wrote:
Alexnb wrote:
Okay, so what I want my program to do it open a file, a music file in
specific, and for this we will say it is an .mp3. Well, I am using the
system() command from the os class. [...]
>system("\"C:\Documents and Settings\Alex\My Documents\My
Music\Rhapsody\Bryanbros\Weezer\(2001)\04 - Island In The Sun.wma\"")
[...]
Try os.startfile() instead. It should work better.
-- Gerhard
--
http://mail.python.org/mailman/listinfo/python-list

No, it didn't work, but it gave me some interesting feedback when I ran
it
in the shell. Heres what it told me:
>>os.startfile("C:\Documents and Settings\Alex\My Documents\My
Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm
Yours.wma")

Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
os.startfile("C:\Documents and Settings\Alex\My Documents\My
Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm
Yours.wma")

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"

See it made each backslash into two, and the one by the parenthesis and
the
0 turned into an x....
--
View this message in
context:http://www.nabble.com/problems-with-...o-file%27s-pat...
Sent from the Python - python-list mailing list archive at Nabble.com.
Yeah. You need to either double all the backslashes or make it a raw
string by adding an "r" to the beginning, like so:

os.startfile(r'C:\path\to\my\file')

HTH

Mike
--
http://mail.python.org/mailman/listinfo/python-list
--
View this message in context: http://www.nabble.com/problems-with-...p17761126.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Jun 27 '08 #3

Well, now i've hit another problem, this time being that the path will be a
variable, and I can't figure out how to make startfile() make it raw with a
variable, if I put startfile(r variable), it doesn't work and
startfile(rvariable) obviously won't work, do you know how to make that work
or better yet, how to take a regular string that is given and make every
single "\" into a double "\\"?

Mike Driscoll wrote:

On Jun 10, 11:45 am, Alexnb <alexnbr...@gmail.comwrote:
>Gerhard HÃ¤ring wrote:
Alexnb wrote:
Okay, so what I want my program to do it open a file, a music file in
specific, and for this we will say it is an .mp3. Well, I am using the
system() command from the os class. [...]
>system("\"C:\Documents and Settings\Alex\My Documents\My
Music\Rhapsody\Bryanbros\Weezer\(2001)\04 - Island In The Sun.wma\"")
[...]
Try os.startfile() instead. It should work better.
-- Gerhard
--
http://mail.python.org/mailman/listinfo/python-list

No, it didn't work, but it gave me some interesting feedback when I ran
it
in the shell. Heres what it told me:
>>os.startfile("C:\Documents and Settings\Alex\My Documents\My
Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm
Yours.wma")

Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
os.startfile("C:\Documents and Settings\Alex\My Documents\My
Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm
Yours.wma")

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"

See it made each backslash into two, and the one by the parenthesis and
the
0 turned into an x....
--
View this message in
context:http://www.nabble.com/problems-with-...o-file%27s-pat...
Sent from the Python - python-list mailing list archive at Nabble.com.
Yeah. You need to either double all the backslashes or make it a raw
string by adding an "r" to the beginning, like so:

os.startfile(r'C:\path\to\my\file')

HTH

Mike
--
http://mail.python.org/mailman/listinfo/python-list
--
View this message in context: http://www.nabble.com/problems-with-...p17761338.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Jun 27 '08 #4
maybe try string substitution... not sure if that's really the BEST way to
do it but it should work

startfile(r"%s"%variable)

--------------------------------------------------
From: "Alexnb" <al********@gmail.com>
Sent: Tuesday, June 10, 2008 7:05 PM
To: <py*********@python.org>
Subject: Re: problems with opening files due to file's path
>
Well, now i've hit another problem, this time being that the path will be
a
variable, and I can't figure out how to make startfile() make it raw with
a
variable, if I put startfile(r variable), it doesn't work and
startfile(rvariable) obviously won't work, do you know how to make that
work
or better yet, how to take a regular string that is given and make every
single "\" into a double "\\"?

Mike Driscoll wrote:
>>
On Jun 10, 11:45 am, Alexnb <alexnbr...@gmail.comwrote:
>>Gerhard HÃ¤ring wrote:

Alexnb wrote:
Okay, so what I want my program to do it open a file, a music file in
specific, and for this we will say it is an .mp3. Well, I am using
the
system() command from the os class. [...]

system("\"C:\Documents and Settings\Alex\My Documents\My
Music\Rhapsody\Bryanbros\Weezer\(2001)\04 - Island In The Sun.wma\"")
[...]

Try os.startfile() instead. It should work better.

-- Gerhard

--
http://mail.python.org/mailman/listinfo/python-list

No, it didn't work, but it gave me some interesting feedback when I ran
it
in the shell. Heres what it told me:

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

Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
os.startfile("C:\Documents and Settings\Alex\My Documents\My
Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm
Yours.wma")

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"

See it made each backslash into two, and the one by the parenthesis and
the
0 turned into an x....
--
View this message in
context:http://www.nabble.com/problems-with-...o-file%27s-pat...
Sent from the Python - python-list mailing list archive at Nabble.com.

Yeah. You need to either double all the backslashes or make it a raw
string by adding an "r" to the beginning, like so:

os.startfile(r'C:\path\to\my\file')

HTH

Mike
--
http://mail.python.org/mailman/listinfo/python-list

--
View this message in context:
http://www.nabble.com/problems-with-...p17761338.html
Sent from the Python - python-list mailing list archive at Nabble.com.

--
http://mail.python.org/mailman/listinfo/python-list
Jun 27 '08 #5

No this time it perhaps gave me the worst of all heres what I entered, and
the output
>>startfile(r"%s"%full) ***full is the path***
startfile(r"%s"%full)

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"'
Thomas Morton wrote:

maybe try string substitution... not sure if that's really the BEST way to
do it but it should work

startfile(r"%s"%variable)

--------------------------------------------------
From: "Alexnb" <al********@gmail.com>
Sent: Tuesday, June 10, 2008 7:05 PM
To: <py*********@python.org>
Subject: Re: problems with opening files due to file's path
>>
Well, now i've hit another problem, this time being that the path will be
a
variable, and I can't figure out how to make startfile() make it raw with
a
variable, if I put startfile(r variable), it doesn't work and
startfile(rvariable) obviously won't work, do you know how to make that
work
or better yet, how to take a regular string that is given and make every
single "\" into a double "\\"?

Mike Driscoll wrote:
>>>
On Jun 10, 11:45 am, Alexnb <alexnbr...@gmail.comwrote:
Gerhard HÃ¤ring wrote:

Alexnb wrote:
Okay, so what I want my program to do it open a file, a music file
in
specific, and for this we will say it is an .mp3. Well, I am using
the
system() command from the os class. [...]

system("\"C:\Documents and Settings\Alex\My Documents\My
Music\Rhapsody\Bryanbros\Weezer\(2001)\04 - Island In The
Sun.wma\"")
[...]

Try os.startfile() instead. It should work better.

-- Gerhard

--
http://mail.python.org/mailman/listinfo/python-list

No, it didn't work, but it gave me some interesting feedback when I ran
it
in the shell. Heres what it told me:

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

Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
os.startfile("C:\Documents and Settings\Alex\My Documents\My
Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm
Yours.wma")

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"

See it made each backslash into two, and the one by the parenthesis and
the
0 turned into an x....
--
View this message in
context:http://www.nabble.com/problems-with-...o-file%27s-pat...
Sent from the Python - python-list mailing list archive at Nabble.com.

Yeah. You need to either double all the backslashes or make it a raw
string by adding an "r" to the beginning, like so:

os.startfile(r'C:\path\to\my\file')

HTH

Mike
--
http://mail.python.org/mailman/listinfo/python-list

--
View this message in context:
http://www.nabble.com/problems-with-...p17761338.html
Sent from the Python - python-list mailing list archive at Nabble.com.

--
http://mail.python.org/mailman/listinfo/python-list
--
http://mail.python.org/mailman/listinfo/python-list
--
View this message in context: http://www.nabble.com/problems-with-...p17761946.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Jun 27 '08 #6
On Jun 10, 1:25*pm, "Thomas Morton" <morton.tho...@googlemail.com>
wrote:
maybe try string substitution... not sure if that's really the BEST way to
do it but it should work

startfile(r"%s"%variable)

I concur. That should work. A slightly more in depth example (assuming
Windows):

os.startfile(r'C:\Documents and Settings\%s\Desktop\myApp.exe' %

or

os.startfile(r'C:\Program Files\%s' % myApp)

Hopefully this is what you are talking about. If you were referring to
passing in arguments, than you'll want to use the subprocess module

>
--------------------------------------------------
From: "Alexnb" <alexnbr...@gmail.com>
Sent: Tuesday, June 10, 2008 7:05 PM
To: <python-l...@python.org>
Subject: Re: problems with opening files due to file's path
Well, now i've hit another problem, this time being that the path will be
a
variable, and I can't figure out how to make startfile() make it raw with
a
variable, if I put startfile(r variable), it doesn't work and
startfile(rvariable) obviously won't work, do you know how to make that
work
or better yet, how to take a regular string that is given and make every
single "\" into a double "\\"?
<snip>

Mike
Jun 27 '08 #7

That would work, but not for what I want. See the file could be anywhere on
the user's system and so the entire path will be unique, and that didn't
work with a unique path. What is the subprocess module you are talking

Mike Driscoll wrote:

On Jun 10, 1:25Â*pm, "Thomas Morton" <morton.tho...@googlemail.com>
wrote:
>maybe try string substitution... not sure if that's really the BEST way
to
do it but it should work

startfile(r"%s"%variable)

I concur. That should work. A slightly more in depth example (assuming
Windows):

os.startfile(r'C:\Documents and Settings\%s\Desktop\myApp.exe' %

or

os.startfile(r'C:\Program Files\%s' % myApp)

Hopefully this is what you are talking about. If you were referring to
passing in arguments, than you'll want to use the subprocess module

>>
--------------------------------------------------
From: "Alexnb" <alexnbr...@gmail.com>
Sent: Tuesday, June 10, 2008 7:05 PM
To: <python-l...@python.org>
Subject: Re: problems with opening files due to file's path
Well, now i've hit another problem, this time being that the path will
be
a
variable, and I can't figure out how to make startfile() make it raw
with
a
variable, if I put startfile(r variable), it doesn't work and
startfile(rvariable) obviously won't work, do you know how to make that
work
or better yet, how to take a regular string that is given and make
every
single "\" into a double "\\"?
<snip>

Mike
--
http://mail.python.org/mailman/listinfo/python-list
--
View this message in context: http://www.nabble.com/problems-with-...p17762276.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Jun 27 '08 #8

Just tested locally in IDLE (I know I know!) and it works for me like this:
>>test = os.path.join(os.getcwd(),"NEWS.txt")
test
'D:\\Python25\\NEWS.txt'
>>os.startfile(r"%s"%test)
And the file opens...

Does the file definitely exist?

Tom
--------------------------------------------------
From: "Alexnb" <al********@gmail.com>
Sent: Tuesday, June 10, 2008 7:37 PM
To: <py*********@python.org>
Subject: Re: problems with opening files due to file's path
>
No this time it perhaps gave me the worst of all heres what I entered, and
the output
>>>startfile(r"%s"%full) ***full is the path***

startfile(r"%s"%full)

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"'
Thomas Morton wrote:
>>
maybe try string substitution... not sure if that's really the BEST way
to
do it but it should work

startfile(r"%s"%variable)

--------------------------------------------------
From: "Alexnb" <al********@gmail.com>
Sent: Tuesday, June 10, 2008 7:05 PM
To: <py*********@python.org>
Subject: Re: problems with opening files due to file's path
>>>
Well, now i've hit another problem, this time being that the path will
be
a
variable, and I can't figure out how to make startfile() make it raw
with
a
variable, if I put startfile(r variable), it doesn't work and
startfile(rvariable) obviously won't work, do you know how to make that
work
or better yet, how to take a regular string that is given and make every
single "\" into a double "\\"?

Mike Driscoll wrote:

On Jun 10, 11:45 am, Alexnb <alexnbr...@gmail.comwrote:
Gerhard HÃ¤ring wrote:
>
Alexnb wrote:
Okay, so what I want my program to do it open a file, a music file
in
specific, and for this we will say it is an .mp3. Well, I am using
the
system() command from the os class. [...]
>
system("\"C:\Documents and Settings\Alex\My Documents\My
Music\Rhapsody\Bryanbros\Weezer\(2001)\04 - Island In The
Sun.wma\"")
[...]
>
Try os.startfile() instead. It should work better.
>
-- Gerhard
>
--
http://mail.python.org/mailman/listinfo/python-list
>
No, it didn't work, but it gave me some interesting feedback when I
ran
it
in the shell. Heres what it told me:
>
>os.startfile("C:\Documents and Settings\Alex\My Documents\My
>Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm
>Yours.wma")
>
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
os.startfile("C:\Documents and Settings\Alex\My Documents\My
Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm
Yours.wma")
>
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"
>
See it made each backslash into two, and the one by the parenthesis
and
the
0 turned into an x....
--
View this message in
context:http://www.nabble.com/problems-with-...o-file%27s-pat...
Sent from the Python - python-list mailing list archive at Nabble.com.

Yeah. You need to either double all the backslashes or make it a raw
string by adding an "r" to the beginning, like so:

os.startfile(r'C:\path\to\my\file')

HTH

Mike
--
http://mail.python.org/mailman/listinfo/python-list

--
View this message in context:
http://www.nabble.com/problems-with-...p17761338.html
Sent from the Python - python-list mailing list archive at Nabble.com.

--
http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list

--
View this message in context:
http://www.nabble.com/problems-with-...p17761946.html
Sent from the Python - python-list mailing list archive at Nabble.com.

--
http://mail.python.org/mailman/listinfo/python-list
Jun 27 '08 #9
Alexnb wrote:
No this time it perhaps gave me the worst of all heres what I entered, and
the output
>>>startfile(r"%s"%full) ***full is the path***

startfile(r"%s"%full)

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"'
Contrary to what other posters have asserted, doing the above can't make
a difference. Putting 'r' in front of a string literal tells Python not
to give backslashes in the string literal any special treatment. Since
there are no backslashes in "%s", the 'r' does nothing.

Therefore, (r"%s"%full) is the same as ("%s"%full), which is the same as
(full), assuming that full is the name of a string.

The real answer lies in fixing the code where you're assigning the
pathname to 'full', which you haven't posted. Please post the code where
you're assigning the pathname, or better yet, post the complete code
you're running.

--
Carsten Haese
http://informixdb.sourceforge.net
Jun 27 '08 #10
On Jun 10, 2:09*pm, Carsten Haese <carsten.ha...@gmail.comwrote:
Alexnb wrote:
No this time it perhaps gave me the worst of all heres what I entered, and
the output
>>startfile(r"%s"%full) * ****full is the path***
startfile(r"%s"%full)
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"'

Contrary to what other posters have asserted, doing the above can't make
a difference. Putting 'r' in front of a string literal tells Python not
to give backslashes in the string literal any special treatment. Since
there are no backslashes in "%s", the 'r' does nothing.

I assumed the OP was trying to do the string substitution within a
path. If the OP is instead doing as you think, then you are quite
correct.
>
Therefore, (r"%s"%full) is the same as ("%s"%full), which is the same as
(full), assuming that full is the name of a string.

The real answer lies in fixing the code where you're assigning the
pathname to 'full', which you haven't posted. Please post the code where
you're assigning the pathname, or better yet, post the complete code
you're running.

--
Carsten Haesehttp://informixdb.sourceforge.net

Sometimes I get too eager to help and don't do enough mental

Mike
Jun 27 '08 #11
On Jun 10, 1:57*pm, Alexnb <alexnbr...@gmail.comwrote:
That would work, but not for what I want. See the file could be anywhere on
the user's system and so the entire path will be unique, and that didn't
work with a unique path. What is the subprocess module you are talking

<snip>

As Carsten pointed out, we don't really know what you're doing. Or at
least, I don't. Why do you even want to do string substitution? How
does the user navigate to the files that the user wants to open? Are
you using a GUI or a command line interface?

you this:

http://docs.python.org/lib/module-subprocess.html

Mike
Jun 27 '08 #12

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.

Mike Driscoll wrote:

On Jun 10, 1:57Â*pm, Alexnb <alexnbr...@gmail.comwrote:
>That would work, but not for what I want. See the file could be anywhere
on
the user's system and so the entire path will be unique, and that didn't
work with a unique path. What is the subprocess module you are talking

<snip>

As Carsten pointed out, we don't really know what you're doing. Or at
least, I don't. Why do you even want to do string substitution? How
does the user navigate to the files that the user wants to open? Are
you using a GUI or a command line interface?

you this:

http://docs.python.org/lib/module-subprocess.html

Mike
--
http://mail.python.org/mailman/listinfo/python-list
--
View this message in context: http://www.nabble.com/problems-with-...p17767518.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Jun 27 '08 #13
On 2008-06-11, Alexnb <al********@gmail.comwrote:
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

--
Grant Edwards grante Yow! With YOU, I can be
at MYSELF... We don't NEED
visi.com Dan Rather...
Jun 27 '08 #14

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 <al********@gmail.comwrote:
>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

--
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-...p17768511.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Jun 27 '08 #15
Alexnb wrote:
Okay, I don't understand how it is too vague, but here:

[snip a bunch of irrelevant examples...]

Did I clarify?
No. Earlier you wrote:
>On 2008-06-11, Alexnb <al********@gmail.comwrote:
>>I am using GUI, Tkinter to be exact. But regardless of how the
path gets there, it needs to opened correctly.
This implies that the file doesn't get opened correctly if the file name
is entered/chosen in the GUI. Yet, the examples you posted don't contain
any GUI code whatsoever. They merely demonstrate that you don't have a
firm grasp on how backslashes in string literals are treated.

So, this begs the question, do you actually have any GUI code that is
failing, or are you just worried, given the problems you had with string
literals, that the GUI code you have yet to write will fail in the same way?

If this is the case, you should just write the GUI code and try it. It
might just work. Backslashes entered into a GUI text box are not treated
the same as backslashes in a Python string literal.

If, on the other hand, you do have some GUI code for getting the file
name from the user, and that code is failing, then please, show us THAT
CODE and show us how it's failing.

--
Carsten Haese
http://informixdb.sourceforge.net
Jun 27 '08 #16
On 2008-06-11, Alexnb <al********@gmail.comwrote:
>>>path = "C:\Documents and Settings\Alex\My Documents\My
Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm
Yours.wma"
Your string doesn't contain what you think it does. Do a
"print path". Hint: the string "\01" consists of a single byte
who's value is 001 base 8.
>>>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"
Notice that the string in the error message contains \x01?
That's the byte that got changed.
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.
Right.
So if I could take the path varible and make ever "\" into a
"\\" then it would also work.
I don't understand the part about the path variable.

The backslash character is used in both C and Python as an
escape character so that you can encode special values in
string literals. For example: '\r' is a carriage return '\n'
is a linefeed, \0nnn is a single byte with the octal value nnn,
and so on.

Microsoft's choice of '\' as a path separator was a terribly
bad one (one of many made by Microsoft over the years). Most
Windows system calls will accept forward slashes, so the
easiest thing to do is usually just type the strings with
forward slashes.

--
Grant Edwards grante Yow! NOW do I get to blow
at out the CANLDES??
visi.com
Jun 27 '08 #17

I don't think you understand it doesn't matter how the variable gets there,
the same code is run regardless, I have no problem with the GUI, but you
asked, and so I told you. the code os.startfile(.... is run if there is a
GUI or it is a console app.
Carsten Haese-2 wrote:
>
Alexnb wrote:
>Okay, I don't understand how it is too vague, but here:

[snip a bunch of irrelevant examples...]

Did I clarify?

No. Earlier you wrote:
>>On 2008-06-11, Alexnb <al********@gmail.comwrote:
I am using GUI, Tkinter to be exact. But regardless of how the
path gets there, it needs to opened correctly.

This implies that the file doesn't get opened correctly if the file name
is entered/chosen in the GUI. Yet, the examples you posted don't contain
any GUI code whatsoever. They merely demonstrate that you don't have a
firm grasp on how backslashes in string literals are treated.

So, this begs the question, do you actually have any GUI code that is
failing, or are you just worried, given the problems you had with string
literals, that the GUI code you have yet to write will fail in the same
way?

If this is the case, you should just write the GUI code and try it. It
might just work. Backslashes entered into a GUI text box are not treated
the same as backslashes in a Python string literal.

If, on the other hand, you do have some GUI code for getting the file
name from the user, and that code is failing, then please, show us THAT
CODE and show us how it's failing.

--
Carsten Haese
http://informixdb.sourceforge.net
--
http://mail.python.org/mailman/listinfo/python-list

--
View this message in context: http://www.nabble.com/problems-with-...p17769178.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Jun 27 '08 #18
Alexnb wrote:
I don't think you understand it doesn't matter how the variable gets there
But it *does* matter. Compare this:

pyfilename = "C:\Somewhere\01 - Some Song.mp3"
pyprint filename
C:\Somewhere - Some Song.mp3

To this:

pyfilename = raw_input("Enter the filename: ")
Enter the filename: C:\Somewhere\01 - Some Song.mp3
pyprint filename
C:\Somewhere\01 - Some Song.mp3

Note that the "\01" in the first case seems to have disappeared, whereas
in the second case it's preserved.

description of the ACTUAL problem.

--
Carsten Haese
http://informixdb.sourceforge.net
Jun 27 '08 #19
On Jun 11, 10:07*am, Alexnb <alexnbr...@gmail.comwrote:
I don't think you understand it doesn't matter how the variable gets there,
the same code is run regardless, I have no problem with the GUI, but you
asked, and so I told you. the code os.startfile(.... is run if there is a
GUI or it is a console app.
(snip)

I think I know why you get confused by this, clearly, you have no idea
of what an escape character and escape sequence is.

Python (and C/C++ and some other languages) treats \ (the backspace
character) inside a string specially, it makes the character after the
backspace lose their special meaning OR get a special meaning, you
might probably be used to seeing something like this: 'First line
\nSecond Line', which when printed, would give:
>>print 'First Line\nSecond Line'
First Line
Second Line

The second behavior of the escape sequence is to make special
character (generally the backspace itself), lose their special
meaning:
>>print 'path\\file.txt'
path\file.txt

In some cases, you might sometimes want a path like this: 'path
\nick.txt'
if you do this:
>>print 'path\nick.txt'
path
ick.txt

because the \n is considered as a newline.

>>print 'path\\nick.txt'
path\nick.txt

or
>>print r'path\nick.txt'
path\nick.txt

the r'' string is raw string, most of the magics of a regular string
'' is lost for an r'' string. It allows you to avoid the need to
escape the special characters. Raw string is usually used for re
(regular expressions) and paths in Windows both of which uses the
backslash character regularly.

you first case of:
system("\"C:\Documents and Settings\Alex\My Documents\My Music\Rhapsody
\Bryanbros\Weezer\(2001)\04 - Island In The Sun.wma\"")

is interpreted by python as this:
"C:\Documents and Settings\Alex\My Documents\My Music\Rhapsody
\Bryanbros\Weezer\(2001) - Island In The Sun.wma"

Notice that the '\0' is substituted into '', because \0 is the escape
sequence for null character.
(Personally I think python should raise errors if any escape character
that isn't followed by a valid escape sequence is found (such as \D,
\A, \M, \M, \R, \B, \W, \(), but perhaps they're trying not to be too
mean for newbies.)

that should be correctly written like this:
system(r'"C:\Documents and Settings\Alex\My Documents\My Music\Rhapsody
\Bryanbros\Weezer\(2001)\04 - Island In The Sun.wma"')
or:
system('"C:\\Documents and Settings\\Alex\\My Documents\\My Music\
\Rhapsody\\Bryanbros\\Weezer\\(2001)\\04 - Island In The Sun.wma"')

Now, to the next question:
How if I want the path to come from a variable:
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)

I can see in a glance why it doesn't work, the string is escaped by
python, it should be written like this.
path = r"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)

OR:
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)

In most GUI toolkits (including Tkinter) and raw_input() function,
when you input a string (using the textbox, a.k.a Entry widget) it
would automatically be escaped for you, so when you input 'path\path
\file.txt', the GUI toolkit would convert it into 'path\\path\
\file.txt'.
Jun 27 '08 #20
Lie wrote:
In most GUI toolkits (including Tkinter) and raw_input() function,
when you input a string (using the textbox, a.k.a Entry widget) it
would automatically be escaped for you, so when you input 'path\path
\file.txt', the GUI toolkit would convert it into 'path\\path\
\file.txt'.
That's incorrect. If you enter text into a text box or in raw_input(),
*no* conversion of backslashes is happening. A backslash entered in
raw_input is just a backslash. A backslash entered in a textbox is just
a backslash. A backslash read from a file is just a backslash.

A "conversion" happens when you print the repr() of a string that was
obtained from raw_input or from a text box, because repr() tries to show
the string literal that would result in the contents, and in a string
literal, a backslash is not (always) a backslash, so repr() escapes the
backslashes:

pytext = raw_input("Enter some text: ")
Enter some text: This is a backslash: \
pyprint text
This is a backslash: \
pyprint repr(text)
'This is a backslash: \\'

As you can see, I entered a single backslash, and the string ends up
containing a single backslash. Only when I ask Python for the repr() of
the string does the backslash get doubled up.

--
Carsten Haese
http://informixdb.sourceforge.net
Jun 27 '08 #21
On Jun 11, 9:14*pm, Carsten Haese <carsten.ha...@gmail.comwrote:
Lie wrote:
In most GUI toolkits (including Tkinter) and raw_input() function,
when you input a string (using the textbox, a.k.a Entry widget) it
would automatically be escaped for you, so when you input 'path\path
\file.txt', the GUI toolkit would convert it into 'path\\path\
\file.txt'.

That's incorrect. If you enter text into a text box or in raw_input(),
*no* conversion of backslashes is happening. A backslash entered in
raw_input is just a backslash. A backslash entered in a textbox is just
a backslash. A backslash read from a file is just a backslash.
I know, but I thought it'd be easier for him to understand it like
that and discover the real 'how-it-works' later. My guilt is that I
forget to put a "this is not how it actually works behind the scene,
but you can think of it like this at least for now since this model is
A "conversion" happens when you print the repr() of a string that was
obtained from raw_input or from a text box, because repr() tries to show
the string literal that would result in the contents, and in a string
literal, a backslash is not (always) a backslash, so repr() escapes the
backslashes:

pytext = raw_input("Enter some text: ")
Enter some text: This is a backslash: \
pyprint text
This is a backslash: \
pyprint repr(text)
'This is a backslash: \\'

As you can see, I entered a single backslash, and the string ends up
containing a single backslash. Only when I ask Python for the repr() of
the string does the backslash get doubled up.

--
Carsten Haesehttp://informixdb.sourceforge.net
Jun 27 '08 #22

Okay, so as a response to all of you, I will be using the Entry() widget in
Tkinter to get this path. and the repr() function just makes all my
backslashes 4 instead of just 1, and it still screwes it up with the numbers
and parenthesis is has been since the first post. Oh and I know all about
escape characters, (\n,\b,\a,etc.) I can program C, not a lot, but enough to
know that I like python better. Anyway, so far I tried all of your stuff,
and it didn't work. infact, it puts backslashes in front of the "'" in some
of the words, such as "I'm" goes to "I\'m." So I posted the code I will be
using if you want to see the Tkinter code I can post it, but I don't see how
it will help.
Lie Ryan wrote:

On Jun 11, 9:14Â*pm, Carsten Haese <carsten.ha...@gmail.comwrote:
>Lie wrote:
In most GUI toolkits (including Tkinter) and raw_input() function,
when you input a string (using the textbox, a.k.a Entry widget) it
would automatically be escaped for you, so when you input 'path\path
\file.txt', the GUI toolkit would convert it into 'path\\path\
\file.txt'.

That's incorrect. If you enter text into a text box or in raw_input(),
*no* conversion of backslashes is happening. A backslash entered in
raw_input is just a backslash. A backslash entered in a textbox is just
a backslash. A backslash read from a file is just a backslash.
I know, but I thought it'd be easier for him to understand it like
that and discover the real 'how-it-works' later. My guilt is that I
forget to put a "this is not how it actually works behind the scene,
but you can think of it like this at least for now since this model is
>A "conversion" happens when you print the repr() of a string that was
obtained from raw_input or from a text box, because repr() tries to show
the string literal that would result in the contents, and in a string
literal, a backslash is not (always) a backslash, so repr() escapes the
backslashes:

pytext = raw_input("Enter some text: ")
Enter some text: This is a backslash: \
pyprint text
This is a backslash: \
pyprint repr(text)
'This is a backslash: \\'

As you can see, I entered a single backslash, and the string ends up
containing a single backslash. Only when I ask Python for the repr() of
the string does the backslash get doubled up.

--
Carsten Haesehttp://informixdb.sourceforge.net
--
http://mail.python.org/mailman/listinfo/python-list
--
View this message in context: http://www.nabble.com/problems-with-...p17782866.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Jun 27 '08 #23
Alexnb wrote:
Okay, so as a response to all of you, I will be using the Entry() widget in
Tkinter to get this path. and the repr() function just makes all my
backslashes 4 instead of just 1, and it still screwes it up with the numbers
and parenthesis is has been since the first post. Oh and I know all about
escape characters, (\n,\b,\a,etc.) I can program C, not a lot, but enough to
know that I like python better. Anyway, so far I tried all of your stuff,
and it didn't work. infact, it puts backslashes in front of the "'" in some
of the words, such as "I'm" goes to "I\'m." So I posted the code I will be
using if you want to see the Tkinter code I can post it, but I don't see how
it will help.
you several times to post your code. We're not doing this to waste your
our time by making us guess.

Seeing your code should enable us to see exactly what the problem is.
Your vague descriptions of what's going on are not useful because they
are filtered through your inaccurate understanding of what's going on. I
mean no offense by this, but if your understanding were accurate, you
wouldn't be here asking for help.

that gets the filename from the user and attempts to open the file. Also
tell us what input you're entering and the output the code produces.

--
Carsten Haese
http://informixdb.sourceforge.net
Jun 27 '08 #24
@Mike and the others yesterday

I did think after I posted that code (the string substitution thing) that it
might do that. Thanks for clarifying that it was rubbish :P

@ Alexnb

I'm do a lot of support on a community forum that uses Python as it's
language - I can tell you from experience that posting a chunk of code is
far easier to disseminate than a text description. As already mentioned the
fact that there IS a problem/question inherently means there is a missed
step of understanding. What ends up happening is that we form in our minds
the code we would use to do what your describing: what you have could be
totally different :)

Post-da-code :)

Tom

--------------------------------------------------
From: "Carsten Haese" <ca***********@gmail.com>
Sent: Wednesday, June 11, 2008 7:05 PM
Newsgroups: comp.lang.python
To: <py*********@python.org>
Subject: Re: problems with opening files due to file's path
Alexnb wrote:
>Okay, so as a response to all of you, I will be using the Entry() widget
in
Tkinter to get this path. and the repr() function just makes all my
backslashes 4 instead of just 1, and it still screwes it up with the
numbers
and parenthesis is has been since the first post. Oh and I know all about
escape characters, (\n,\b,\a,etc.) I can program C, not a lot, but enough
to
know that I like python better. Anyway, so far I tried all of your stuff,
and it didn't work. infact, it puts backslashes in front of the "'" in
some
of the words, such as "I'm" goes to "I\'m." So I posted the code I will
be
using if you want to see the Tkinter code I can post it, but I don't see
how
it will help.

you several times to post your code. We're not doing this to waste your
time by making us guess.

Seeing your code should enable us to see exactly what the problem is. Your
vague descriptions of what's going on are not useful because they are
filtered through your inaccurate understanding of what's going on. I mean
no offense by this, but if your understanding were accurate, you wouldn't

that gets the filename from the user and attempts to open the file. Also
tell us what input you're entering and the output the code produces.

--
Carsten Haese
http://informixdb.sourceforge.net
--
http://mail.python.org/mailman/listinfo/python-list
Jun 27 '08 #25
On 2008-06-11, Alexnb <al********@gmail.comwrote:
Okay, so as a response to all of you, I will be using the Entry() widget in
Tkinter to get this path.
OK.
and the repr() function just makes all my backslashes 4
instead of just 1, and it still screwes it up with the numbers
and parenthesis is has been since the first post.
I've absolutely no clue why you would be using the repr()
function.
Oh and I know all about escape characters, (\n,\b,\a,etc.)
Apparently not.
I can program C, not a lot, but enough to know that I like
python better. Anyway, so far I tried all of your stuff, and
it didn't work.
To what does "it" refer?
infact, it puts backslashes in front of the
"'" in some of the words, such as "I'm" goes to "I\'m."
Again, "it" doesn't seem to have a concrete referant.
So I posted the code I will be using if you want to see the
Tkinter code I can post it, but I don't see how it will help.
If you know what would help and what wouldn't, then you must
know enough to fix your problems. So please do so and quit
bothering the newgroup.

--
Grant Edwards grante Yow! I want another
at RE-WRITE on my CEASAR
Jun 27 '08 #26

I posted the underlying code, but I haven't made the GUI code because if I
can't get the underlying code right it doesn't matter, well in my eyes it
doesn't but I am probably wrong. But it will look somehting like this:

e = Entry()
#when user hits submit)
path = e.get()

os.startfile(path)

this is very simplified, but that is the idea, and basically exactly what
will happen, just if the path has some of those characters that conflict
with the \.
Carsten Haese-2 wrote:
>
Alexnb wrote:
>Okay, so as a response to all of you, I will be using the Entry() widget
in
Tkinter to get this path. and the repr() function just makes all my
backslashes 4 instead of just 1, and it still screwes it up with the
numbers
and parenthesis is has been since the first post. Oh and I know all about
escape characters, (\n,\b,\a,etc.) I can program C, not a lot, but enough
to
know that I like python better. Anyway, so far I tried all of your stuff,
and it didn't work. infact, it puts backslashes in front of the "'" in
some
of the words, such as "I'm" goes to "I\'m." So I posted the code I will
be
using if you want to see the Tkinter code I can post it, but I don't see
how
it will help.

you several times to post your code. We're not doing this to waste your
our time by making us guess.

Seeing your code should enable us to see exactly what the problem is.
Your vague descriptions of what's going on are not useful because they
are filtered through your inaccurate understanding of what's going on. I
mean no offense by this, but if your understanding were accurate, you
wouldn't be here asking for help.

that gets the filename from the user and attempts to open the file. Also
tell us what input you're entering and the output the code produces.

--
Carsten Haese
http://informixdb.sourceforge.net
--
http://mail.python.org/mailman/listinfo/python-list

--
View this message in context: http://www.nabble.com/problems-with-...p17786320.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Jun 27 '08 #27

path, as a variable conflicts with other characters in the path, creating
escape characters I don't want, so I need a way to send the string to the
os.startfile() in raw, or, with all the backslashes doubled. Thats it, I'll
write some code of what it should work like, because I probably should have
done that; but you don't have to act like I am retarded... that solves
nothing.
Grant Edwards wrote:
>
On 2008-06-11, Alexnb <al********@gmail.comwrote:
>Okay, so as a response to all of you, I will be using the Entry() widget
in
Tkinter to get this path.

OK.
>and the repr() function just makes all my backslashes 4
instead of just 1, and it still screwes it up with the numbers
and parenthesis is has been since the first post.

I've absolutely no clue why you would be using the repr()
function.
>Oh and I know all about escape characters, (\n,\b,\a,etc.)

Apparently not.
>I can program C, not a lot, but enough to know that I like
python better. Anyway, so far I tried all of your stuff, and
it didn't work.

To what does "it" refer?
>infact, it puts backslashes in front of the
"'" in some of the words, such as "I'm" goes to "I\'m."

Again, "it" doesn't seem to have a concrete referant.
>So I posted the code I will be using if you want to see the
Tkinter code I can post it, but I don't see how it will help.

If you know what would help and what wouldn't, then you must
know enough to fix your problems. So please do so and quit
bothering the newgroup.

--
Grant Edwards grante Yow! I want another
at RE-WRITE on my CEASAR
--
http://mail.python.org/mailman/listinfo/python-list

--
View this message in context: http://www.nabble.com/problems-with-...p17786386.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Jun 27 '08 #28

Okay, so I wrote some code of basically what I will be doing, only with
exactly what I need for this part of the program but here you go:

[code]

from Tkinter import*
import os

class myApp:
def __init__(self, parent):
self.parent = parent

self.baseContainer = Frame(self.parent)
self.baseContainer.pack()

self.e = Entry(self.baseContainer)
self.e.bind("<Return>", self.entryEnter)
self.e.pack()

self.Button1 = Button(self.baseContainer, command =
self.buttonClick)
self.Button1.configure(text="Submit")
self.Button1.pack()
def buttonClick(self):
print "Button1 was clicked"
path = self.e.get()
path = "\"" + path + "\""
print path
#os.startfile(path)

def entryEnter(self, event):
print "Enter was hit in the entry box"
self.buttonClick()
root = Tk()
myapp = myApp(root)
root.mainloop()

[code]

Alexnb wrote:
>
path, as a variable conflicts with other characters in the path, creating
escape characters I don't want, so I need a way to send the string to the
os.startfile() in raw, or, with all the backslashes doubled. Thats it,
I'll write some code of what it should work like, because I probably
should have done that; but you don't have to act like I am retarded...
that solves nothing.
Grant Edwards wrote:
>>
On 2008-06-11, Alexnb <al********@gmail.comwrote:
>>Okay, so as a response to all of you, I will be using the Entry() widget
in
Tkinter to get this path.

OK.
>>and the repr() function just makes all my backslashes 4
instead of just 1, and it still screwes it up with the numbers
and parenthesis is has been since the first post.

I've absolutely no clue why you would be using the repr()
function.
>>Oh and I know all about escape characters, (\n,\b,\a,etc.)

Apparently not.
>>I can program C, not a lot, but enough to know that I like
python better. Anyway, so far I tried all of your stuff, and
it didn't work.

To what does "it" refer?
>>infact, it puts backslashes in front of the
"'" in some of the words, such as "I'm" goes to "I\'m."

Again, "it" doesn't seem to have a concrete referant.
>>So I posted the code I will be using if you want to see the
Tkinter code I can post it, but I don't see how it will help.

If you know what would help and what wouldn't, then you must
know enough to fix your problems. So please do so and quit
bothering the newgroup.

--
Grant Edwards grante Yow! I want another
at RE-WRITE on my CEASAR
--
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-tp17759531p17786712.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Jun 27 '08 #29
On Wed, Jun 11, 2008 at 4:16 PM, Alexnb <al********@gmail.comwrote:
>
I posted the underlying code, but I haven't made the GUI code because if I
can't get the underlying code right it doesn't matter, well in my eyes it
doesn't but I am probably wrong. But it will look somehting like this:
What you're missing is that all of the problems you're having with
escape characters *only apply to string literals inside your python
source code.* If you're getting the string from the console, you
don't need to escape or change anything. If you're getting the string
from a Tk text box, you don't need to escape or change anything. If
you're getting the string from the filesystem, you don't need to
escape or change anything.

The only place you have to be careful is when you type out a literal
string inside your .py source code. When you do that, you need to
properly escape backslashes, either by putting them in raw strings, or

--
Jerry
Jun 27 '08 #30
Alexnb wrote:
We're frustrated with your apparent inability to understand anything
we're saying.
My problem is this; the
path, as a variable conflicts with other characters in the path, creating
escape characters I don't want, so I need a way to send the string to the
os.startfile() in raw, or, with all the backslashes doubled.
No, no, no, no, NO! That is not your problem! You are drawing unfounded
conclusions from the fact that you had to double up backslashes when the
filename came from a string literal. The situation is entirely different
when the filename comes from user input. No doubling up of backslashes
is necessary when the filename comes from user input. TRUST ME!

import os
filename = raw_input("Please enter a filename: ")
os.startfile(filename)

Once you get that to work, replace raw_input with a function that gets

Hope this helps,

--
Carsten Haese
http://informixdb.sourceforge.net
Jun 27 '08 #31

Well, I don't understand why I don't need to change anything because say I
run that code, which goes straight from the entry box to the startfile()
function. It doesn't work with some of the paths, that is the whole problem.
the problem is when I enter a path with those certain characters next to
each other. Everyone seems like there is some huge thing that I am
missing... and I don't know what it is, because when I run that code, with
that path I was talking about, I get an error, and it shows me that it is
because of the \0.
Jerry Hill wrote:
>
On Wed, Jun 11, 2008 at 4:16 PM, Alexnb <al********@gmail.comwrote:
>>
I posted the underlying code, but I haven't made the GUI code because if
I
can't get the underlying code right it doesn't matter, well in my eyes it
doesn't but I am probably wrong. But it will look somehting like this:

What you're missing is that all of the problems you're having with
escape characters *only apply to string literals inside your python
source code.* If you're getting the string from the console, you
don't need to escape or change anything. If you're getting the string
from a Tk text box, you don't need to escape or change anything. If
you're getting the string from the filesystem, you don't need to
escape or change anything.

The only place you have to be careful is when you type out a literal
string inside your .py source code. When you do that, you need to
properly escape backslashes, either by putting them in raw strings, or

--
Jerry
--
http://mail.python.org/mailman/listinfo/python-list

--
View this message in context: http://www.nabble.com/problems-with-...p17787168.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Jun 27 '08 #32
Alexnb wrote:
Okay, so I wrote some code of basically what I will be doing, only with
exactly what I need for this part of the program but here you go: [...]
Finally...
path = "\"" + path + "\""
That line of code is unnecessary. Delete it.

--
Carsten Haese
http://informixdb.sourceforge.net
Jun 27 '08 #33

Haha, okay well sorry that I was being so stupid, but I get it now and I
apoligize for causing you all the frustration. But I did get it to work
finally.
Carsten Haese-2 wrote:
>
Alexnb wrote:

We're frustrated with your apparent inability to understand anything
we're saying.
>My problem is this; the
path, as a variable conflicts with other characters in the path, creating
escape characters I don't want, so I need a way to send the string to the
os.startfile() in raw, or, with all the backslashes doubled.

No, no, no, no, NO! That is not your problem! You are drawing unfounded
conclusions from the fact that you had to double up backslashes when the
filename came from a string literal. The situation is entirely different
when the filename comes from user input. No doubling up of backslashes
is necessary when the filename comes from user input. TRUST ME!

import os
filename = raw_input("Please enter a filename: ")
os.startfile(filename)

Once you get that to work, replace raw_input with a function that gets

Hope this helps,

--
Carsten Haese
http://informixdb.sourceforge.net
--
http://mail.python.org/mailman/listinfo/python-list

--
View this message in context: http://www.nabble.com/problems-with-...p17787228.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Jun 27 '08 #34
Alexnb wrote:
Haha, okay well sorry that I was being so stupid, but I get it now
and I apoligize for causing you all the frustration. But I did get it to
work finally.
Jun 27 '08 #35

### This discussion thread is closed

Replies have been disabled for this discussion.