[Tutor] File path
Gus Tabares
gus.tabares@verizon.net
Sun Jun 8 20:18:02 2003
This is a multi-part message in MIME format.
------=_NextPart_000_000C_01C32DFA.D4BB3B60
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
MessageHomer,
You might want to try something along these lines:
#!/usr/bin/env python
fd = open('C:\\Directory\\Subdirectory\\textfile.txt', 'r')
fd.read()
You could also assign the directory string to a variable like this:
path = r'C:\Directory\Subdirectory\textfile.txt'
fd = open(path, 'r')
HTH,
Gus
-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
Homer Ellison
Sent: Sunday, June 08, 2003 5:32 PM
To: Python Tutor List
Subject: [Tutor] File path
Hello,
I'm new to programming in Python (and to object-oriented programming in
general). The programming experience I have is from a long time ago, so I'm
going to have many questions.
How do I specify the file path within my code to access files for reading
and writing? I'm using a PC with 32-bit Windows.
Thank you,
Homer
------=_NextPart_000_000C_01C32DFA.D4BB3B60
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Message</TITLE>
<META content=3D"text/html; charset=3Dus-ascii" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.3502.5390" name=3DGENERATOR></HEAD>
<BODY>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D000421400-09062003>Homer,</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D000421400-09062003></SPAN></FONT> </DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D000421400-09062003> You might want to try =
something=20
along these lines:</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D000421400-09062003></SPAN></FONT> </DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D000421400-09062003>#!/usr/bin/env python</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D000421400-09062003></SPAN></FONT> </DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D000421400-09062003>fd =3D=20
open('C:\\Directory\\Subdirectory\\textfile.txt', =
'r')</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D000421400-09062003>fd.read()</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D000421400-09062003></SPAN></FONT> </DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D000421400-09062003>You=20
could also assign the directory string to a variable like=20
this:</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D000421400-09062003></SPAN></FONT> </DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D000421400-09062003>path =3D=20
r'C:\Directory\Subdirectory\textfile.txt'</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D000421400-09062003>fd =3D=20
open(path, 'r')</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D000421400-09062003></SPAN></FONT> </DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D000421400-09062003></SPAN></FONT> </DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D000421400-09062003>HTH,</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D000421400-09062003>Gus</SPAN></FONT></DIV>
<BLOCKQUOTE style=3D"MARGIN-RIGHT: 0px">
<DIV align=3Dleft class=3DOutlookMessageHeader dir=3Dltr><FONT =
face=3DTahoma=20
size=3D2>-----Original Message-----<BR><B>From:</B> =
tutor-admin@python.org=20
[mailto:tutor-admin@python.org]<B>On Behalf Of </B>Homer=20
Ellison<BR><B>Sent:</B> Sunday, June 08, 2003 5:32 PM<BR><B>To:</B> =
Python=20
Tutor List<BR><B>Subject:</B> [Tutor] File path<BR><BR></DIV></FONT>
<DIV><SPAN class=3D322492821-08062003><FONT face=3DArial=20
size=3D2>Hello,</FONT></SPAN></DIV>
<DIV><SPAN class=3D322492821-08062003><FONT face=3DArial=20
size=3D2></FONT></SPAN> </DIV>
<DIV><SPAN class=3D322492821-08062003><FONT face=3DArial size=3D2>I'm =
new to=20
programming in Python (and to object-oriented programming in general). =
The=20
programming experience I have is from a long time ago, so I'm going to =
have=20
many questions.</FONT></SPAN></DIV>
<DIV><SPAN class=3D322492821-08062003><FONT face=3DArial=20
size=3D2></FONT></SPAN> </DIV>
<DIV><SPAN class=3D322492821-08062003><FONT face=3DArial size=3D2>How =
do I specify=20
the file path within my code to access files for reading and writing? =
I'm=20
using a PC with 32-bit Windows.</FONT></SPAN></DIV>
<DIV><SPAN class=3D322492821-08062003><FONT face=3DArial=20
size=3D2></FONT></SPAN> </DIV>
<DIV><SPAN class=3D322492821-08062003><FONT face=3DArial =
size=3D2>Thank=20
you,</FONT></SPAN></DIV>
<DIV><SPAN class=3D322492821-08062003><FONT face=3DArial=20
size=3D2>Homer</FONT></SPAN></DIV>
<DIV><SPAN class=3D322492821-08062003><FONT face=3DArial=20
size=3D2></FONT></SPAN> </DIV></BLOCKQUOTE></BODY></HTML>
------=_NextPart_000_000C_01C32DFA.D4BB3B60--