problems with opening files due to file's path

Alexnb alexnbryan at gmail.com
Wed Jun 11 19:20:10 CEST 2008


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... at gmail.com> wrote:
>> 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
> easier to grasp (although misleading)".
> 
>> 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:
>>
>> py> text = raw_input("Enter some text: ")
>> Enter some text: This is a backslash: \
>> py> print text
>> This is a backslash: \
>> py> print 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-opening-files-due-to-file%27s-path-tp17759531p17782866.html
Sent from the Python - python-list mailing list archive at Nabble.com.




More information about the Python-list mailing list