problems with opening files due to file's path
Lie.1296 at gmail.com
Wed Jun 11 16:39:15 CEST 2008
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
> 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
More information about the Python-list