coding problem, help needed

Peter Hansen phansen at kaval.com
Mon Sep 4 01:29:13 EDT 2000


Erik Max Francis wrote:
> 
> Guy Van Rentergem wrote:
> 
> > line=inffile.readline()
> 
> Note that the line returned by File.readline will return a trailing
> newline.
> 
> > L1=string.split(line,',')
> > path=L1[0]
> > value1=L2[1]
> >
> > .....
> >
> > The values are ok but path is something like 'c:\\w'
> > 
> > What is going wrong?
> 
> I submit you're doing something else wrong along the way; this should
> work fine (provided the path doesn't contain any commas, obviously).

I agree with Erik.  I just tried exactly what you have, interactively,
(minus some bugs, like the use of the undefined L2 variable :-), and it
worked fine.

Ahh, wait, I think I see.  When you say "path is something like 'c:\\w'"
you actually mean "path is something like (exactly like)
'c:\\windows\\desktop\\terrain.ter', don't you?

You are attempting to display the contents of 'path' by just typing
'path' in interactive mode, aren't you?  Try typing 'print path' and see
the difference.  No single quotes and no double backslashes.  The
interactive mode is effectively using the repr() function to display the
contents in a printable format for you.  In doing so, it adds the
surrounding quotes and converts backslashes to double-backslashes, just
the way you would have to type the same string to get the same content.

In other words, nothing is going wrong at all.  See the description of
repr() in the Library Reference documentation under "Built-in
Functions"...

-- 
-------------------------------------------
Peter Hansen, P.Eng.



More information about the Python-list mailing list