[Tutor] Files and file attributes

Harry Kattz gibbs05@flash.net
Wed, 21 Feb 2001 17:39:30 -0600


This is a multi-part message in MIME format.

------=_NextPart_000_1421_01C09C2D.3EF0BE40
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Greetings Robert & All,

I've had the same problem with opening files in other directories.  The =
problem's that Windows style path separator.  Python interprets them as =
escape characters, so it's turning those '\t's into tabs.

I've solved it in the following ways:
1). Using raw strings:
    f =3D open(r"C:\tmp\testfile", 'r+')
2). Using capital T's:  ;-)
    f =3D open('C:\Tmp\Testfile', 'r+')

There's more than one way to do it.  Wait!   That's that other 'P' =
language...  Just use the first method. :-)

As for g.write('string')...  Can you give us the error you're receiving?


Good luck,
Sam
  ----- Original Message -----=20
  From: Pat/Bob Fisher=20
  To: tutor@python.org=20
  Sent: Wednesday, February 21, 2001 4:55 PM
  Subject: [Tutor] Files and file attributes


  I am pretty new at programming in Python, but have had experience in =
programming in other languages.  I went through the tutorial which I =
thought was fairly good, except the section on the methods of file =
objects was pretty sparse.  It seems to me that dealing with files is =
rather awkward. I have used the  list representation  filelist =3D =
f.readlines() and then used the fine list methods to manipulate the =
filelist, but I am having trouble getting a new file from  my new =
filelist.  The g.write('string') gives me a whole lot of extraneous =
stuff.
  Another problem I am having is trying  to open files in other =
directories.  For example,
  =20
     f=3Dopen('C:\tmp\testfile','r+') just doesn't work for me.
  =20
  Can anyone help, or at least tell me where I can learn more about file =
manipulation?
  I suppose it is obvious I am using a windows platform, specifically =
WindowsME.
  =20
  Thanks in advance,
  Robert Fisher
  pbfisher@bigfoot.com

------=_NextPart_000_1421_01C09C2D.3EF0BE40
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.3018.900" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Greetings Robert &amp; All,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>I've had the same problem with opening files in =
other=20
directories.&nbsp; The problem's that Windows style path =
separator.&nbsp; Python=20
interprets them as escape characters, so it's turning those '\t's into=20
tabs.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>I've solved it in the following ways:</FONT></DIV>
<DIV><FONT size=3D2>1). Using raw strings:</FONT></DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; f =3D open(r"C:\tmp\testfile",=20
'r+')</FONT></DIV>
<DIV><FONT size=3D2>2). Using capital T's:&nbsp; ;-)</FONT></DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; f =3D open('C:\Tmp\Testfile',=20
'r+')</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>There's more than one way to do it.&nbsp; =
Wait!&nbsp;&nbsp;=20
That's that other 'P' language...&nbsp; Just use the first method.=20
:-)</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>As for g.write('string')...&nbsp; Can you give us =
the error=20
you're receiving?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>Good luck,</FONT></DIV>
<DIV><FONT size=3D2>Sam</FONT></DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A href=3D"mailto:pbfisher@ispchannel.com" =
title=3Dpbfisher@ispchannel.com>Pat/Bob=20
  Fisher</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
href=3D"mailto:tutor@python.org"=20
  title=3Dtutor@python.org>tutor@python.org</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Wednesday, February 21, =
2001 4:55=20
  PM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Tutor] Files and file =

  attributes</DIV>
  <DIV><BR></DIV>
  <DIV><FONT face=3D"Courier New" size=3D2>I am pretty new at =
programming in Python,=20
  but have had experience in programming in other languages.&nbsp; I =
went=20
  through the tutorial which I thought was fairly good, except the =
section on=20
  the methods of file objects was pretty sparse.&nbsp; It seems to me =
that=20
  dealing with files is rather awkward. I have used the&nbsp; list=20
  representation&nbsp; filelist =3D f.readlines() and then used the fine =
list=20
  methods to manipulate the filelist, but I am having trouble getting a =
new file=20
  from&nbsp; my new filelist.&nbsp; The g.write('string') gives me a =
whole lot=20
  of extraneous stuff.</FONT></DIV>
  <DIV><FONT face=3D"Courier New" size=3D2>Another problem I am having =
is=20
  trying&nbsp; to open files in other directories.&nbsp; For=20
  example,</FONT></DIV>
  <DIV><FONT face=3D"Courier New" size=3D2>&nbsp;</FONT></DIV>
  <DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;=20
  f=3Dopen('C:\tmp\testfile','r+') just doesn't work for =
me.</FONT></DIV>
  <DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3D"Courier New" size=3D2>Can anyone help, or at least =
tell me=20
  where I can learn more about file manipulation?</FONT></DIV>
  <DIV><FONT face=3D"Courier New" size=3D2>I suppose it is obvious I am =
using a=20
  windows platform, specifically WindowsME.</FONT></DIV>
  <DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3D"Courier New" size=3D2>Thanks in =
advance,</FONT></DIV>
  <DIV><FONT face=3D"Courier New" size=3D2>Robert Fisher</FONT></DIV>
  <DIV><FONT face=3D"Courier New"=20
size=3D2>pbfisher@bigfoot.com</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_1421_01C09C2D.3EF0BE40--