[Tutor] Acessing files in Windows 2000

Dave S pythontut at pusspaws.net
Wed Mar 9 15:06:01 CET 2005


Danny Yoo wrote:

>[Windows bashing cut]
>
>Python's support for Windows stuff is actually quite good, thanks to the
>work of Mark Hammond:
>
>    http://starship.python.net/crew/mhammond/
>
>A lot of us here do use Windows for COM programming.  Let's get back to
>talking about Python programming and let's help Dave with his problem.
>
>
>The os.path module contains a function called expanduser() that returns
>the home directory of a given user.
>
>    http://www.python.org/doc/lib/module-os.path.html#l2h-1720
>
>I believe this should reliably return a path that looks something like
>'\\Documents and Settings\\[username]' on Windows systems.
>
>
>Dave, what happens if you try something like this?
>
>######
>import os.path
>print os.path.expanduser('~/memo.txt')
>f = open(os.path.expanduser('~/memo.txt'))
>######
>
>Show us what you see, and we can work from there.  Can you also give us
>the complete path where you see 'memo.txt' on your system?  Just right
>click the file; it should show up somewhere on the file's property page.
>
>
>Best of wishes to you!
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>  
>
Hello again,

Wow what a lot of replies.

OK here goes. I know little about win 2000 so when I

My computer > C > My documents I assumed that was where the my documents 
folder was,
Having gone through what you guys said I also have

C:\Documents and Settings\Administrator\My Documents

So I copied memo.txt to C:\Documents and Settings\Administrator\My 
Documents, ammended my code


memo_file = 'C:\Documents and Settings\Administrator\My Documents\memo.txt'
csv_file = 'c:\data.csv'

def palm_conv():

# The money sheet
map1 = [[0]*5 for n in xrange(42)]
map1_count = 6
# The time sheet
map2 = [['']*7 for n in xrange(75)]
map2_count = 0

day_map = {'sun':0, 'mon':1, 'tue':2, 'wed':3, 'thu':4, 'fri':5, 'sat':6}

sh_offset = 0
ot_offset = 0
ca_offset = 0
pa_offset = 0
su_offset = 0

time_slot = 0
text_slot = 0

memo = open(memo_file, 'r')


count = 0
raw_line = ' '
...

And got the following again ...

Traceback (most recent call last):
File "C:\Documents and Settings\Administrator\Desktop\palm.py", line 
268, in ?
palm_conv()
File "C:\Documents and Settings\Administrator\Desktop\palm.py", line 54, 
in palm_conv
memo = open(memo_file, 'r')
IOError: [Errno 2] No such file or directory: 'C:\\Documents and 
Settings\\Administrator\\My Documents\\memo.txt'
 >>>

So I tried your test code & got ...



 >>>
 >>>
 >>> import os.path
 >>> print os.path.expanduser('~/memo.txt')
C:\Documents and Settings\Administrator/memo.txt
 >>> f = open(os.path.expanduser('~/memo.txt'))
Traceback (most recent call last):
File "<pyshell#15>", line 1, in ?
f = open(os.path.expanduser('~/memo.txt'))
IOError: [Errno 2] No such file or directory: 'C:\\Documents and 
Settings\\Administrator/memo.txt'
 >>>

Now starting to doubt my sanity I again re-checked C:\Documents and 
Settings\Administrator\My Documents
and yes I do have a memo.txt there.

In C:\Documents and Settings I have the folders administrator, all users 
and compy, I put a copy of memo.txt in
compy as well & changed my code, same problem

Any ideas

Dave



More information about the Tutor mailing list