reading in a string
Laurent POINTAL
pointal at lure.u-psud.fr
Wed May 17 07:56:39 EDT 2000
On Wed, 17 May 2000 02:58:09 GMT, ghost_man at my-deja.com wrote:
>: I am writing a python script that through the
>: os.system command calls VSS and imports the files
>: over. I then run
>: os.system('dir /s >> myfile.txt')
>:
>: I want to be able to read in the contents of the
>: file one line at a time and execute some command
>: on it. My problem is when the file is something
>: like C:\program files\python\temporary Python
>: reads it as c:\program files\python\011emporary
>:
>: I am getting tripped up by the \t switch. I
>: cannot at this point and time run string.replace
>: because it has already been converted over. Any
>: ideas how I can read the string in correctly? I
>: have explored the glob module and it would seem
>: very cumbersome to try and cover this. Is there
>: an easier way to read in the contents of my file
>: and have them import correctly?
How do you open and read your file?
open(filename,"r").read() to get all the file in a whole blok.
open(filename,"r").readlines() to get all the file in a list of lines.
Normally read and readlines may not interpret \ escape sequences.
A+
Laurent.
---
Laurent POINTAL - CNRS/LURE - Service Informatique Experiences
Tel/fax: 01 64 46 82 80 / 01 64 46 41 48
email : pointal at lure.u-psud.fr ou lpointal at planete.net
More information about the Python-list
mailing list