Re: [Tutor] Acessing files in Windows 2000
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@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 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Acessing files in Windows 2000
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. Um --- So you have a file 'C:\Documents and Settings\Administrator\My Documents\memo.txt'... But you are attempting to open the file 'C:\Documents and Settings\Administrator\memo.txt'. There is a difference there! -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Acessing files in Windows 2000
[EMAIL PROTECTED] wrote: 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. Um --- So you have a file 'C:\Documents and Settings\Administrator\My Documents\memo.txt'... But you are attempting to open the file 'C:\Documents and Settings\Administrator\memo.txt'. There is a difference there! mmm ... I kind of see what you mean. Does anyone have like a realy large shovel so I can dig a hole and hide ? Thanks Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Acessing files in Windows 2000
mmm ... I kind of see what you mean. Does anyone have like a realy large shovel so I can dig a hole and hide ? No worries, we've all been there before. Sometimes you just can't see what's right in front of your face. Don't let it stop you, or stop you from asking questions. Peace Bill Mill bill.mill at gmail.com Thanks Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
RE: [Tutor] Acessing files in Windows 2000
Try c:\\my documents\\memo.txt John -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dave S Sent: Tuesday, March 08, 2005 14:24 To: Python Tutor Subject: [Tutor] Acessing files in Windows 2000 I have a script that converts data relating to my work. It works great on my Linux system but some of my colleagues run windows. I am attempting to convert the file paths to windows but am having no luck. I need to access 'memo.txt' in 'my documents' on windows am struggling. I have tried just about every combination of \ and / and \\ and // but to no avail. I need something like ... C:\My Documents\memo.txt Can anyone advise me ? Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
RE: [Tutor] Acessing files in Windows 2000
Try something like this (change the username to the user you're logged in as, or Administrator if that's how you're logged in): c:\\documents and settings\\username|Administrator\\my documents\\memo.txt -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Dave S Sent: Tuesday, March 08, 2005 4:24 PM To: Python Tutor Subject: [Tutor] Acessing files in Windows 2000 I have a script that converts data relating to my work. It works great on my Linux system but some of my colleagues run windows. I am attempting to convert the file paths to windows but am having no luck. I need to access 'memo.txt' in 'my documents' on windows am struggling. I have tried just about every combination of \ and / and \\ and // but to no avail. I need something like ... C:\My Documents\memo.txt Can anyone advise me ? Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Acessing files in Windows 2000
Quoting Dave S [EMAIL PROTECTED]: I need to access 'memo.txt' in 'my documents' on windows am struggling. I have tried just about every combination of \ and / and \\ and // but to no avail. I need something like ... C:\My Documents\memo.txt Can anyone advise me ? I've never had any trouble accessing files in Win2k with python. The following would all work for me: f1 = file('c:\\My Docments\\memo.txt') f2 = file('c:/My Documents/memo.txt') f3 = file(os.path.normpath('c:/My Documents/memo.txt')) # os.path.normpath normalizes a path; it also converts / to \\ on Windows platforms Is your path correct? The My Documents folder doesn't normally live in the root in Win2k; it is more likely to be found somewhere like C:\Documents and Settings\Username\My Documents. Or, in an office environment, it might be on a network share --- eg, H:\. HTH. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
RE: [Tutor] Acessing files in Windows 2000
I agree with a previous poster, check your path. I think either the path doesn't exist or you don't have permission to get to it. John -Original Message- From: Dave S [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 08, 2005 14:50 To: [EMAIL PROTECTED] Cc: 'Python Tutor' Subject: Re: [Tutor] Acessing files in Windows 2000 John Purser wrote: Try c:\\my documents\\memo.txt John Unfortunately thats a no go ... palm.py palm memo.txt to oocalc data.csv convertor, written by lentil ;) [EMAIL PROTECTED] - enter palm software in the title or it will be junked 09-03-2005 v1.02w Coded for Windows 07-03-2005 v1.02 Coded capitalization() + default to mon 03-03-2005 v1.01 Squished 1/9 decode bug 02-03-2005 v1.00 Coded for Linux 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:\\my documents\\memo.txt' If I try c:\\ or c:\ it always comes out as c:\\... and fails Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
RE: [Tutor] Acessing files in Windows 2000
I faced the same problem once.Dont remember the solution, but it is definitely the slashes which are causing the problem.I couldnt find a specific rule in whole of microsoft documentation, so i assume it has to be hit and try.Try a mix of backslashes n forward slashes till u get there. Whats worse, I had found that the rule is different for different versions of windows.Just proves what we all know...Windows Suxx. --- John Purser [EMAIL PROTECTED] wrote: I agree with a previous poster, check your path. I think either the path doesn't exist or you don't have permission to get to it. John -Original Message- From: Dave S [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 08, 2005 14:50 To: [EMAIL PROTECTED] Cc: 'Python Tutor' Subject: Re: [Tutor] Acessing files in Windows 2000 John Purser wrote: Try c:\\my documents\\memo.txt John Unfortunately thats a no go ... palm.py palm memo.txt to oocalc data.csv convertor, written by lentil ;) [EMAIL PROTECTED] - enter palm software in the title or it will be junked 09-03-2005 v1.02w Coded for Windows 07-03-2005 v1.02 Coded capitalization() + default to mon 03-03-2005 v1.01 Squished 1/9 decode bug 02-03-2005 v1.00 Coded for Linux 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:\\my documents\\memo.txt' If I try c:\\ or c:\ it always comes out as c:\\... and fails Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor __ Celebrate Yahoo!'s 10th Birthday! Yahoo! Netrospective: 100 Moments of the Web http://birthday.yahoo.com/netrospective/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Acessing files in Windows 2000
On Tue, 8 Mar 2005, Dave S wrote: IOError: [Errno 2] No such file or directory: 'c:\\my documents\\memo.txt' My two thoughts. 1) is there actually a directory named my documents at the root? I don't know about Win2000, but for Win XP, the my documents directory is actually C:\Documents and Settings\username\My Documents 2) The embedded space may be the issue, although I doubt that's it. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Acessing files in Windows 2000
[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@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Acessing files in Windows 2000
I have a script that converts data relating to my work. It works great on my Linux system but some of my colleagues run windows. I am attempting to convert the file paths to windows but am having no luck. I need to access 'memo.txt' in 'my documents' on windows am struggling. I have tried just about every combination of \ and / and \\ and // but to no avail. I need something like ... C:\My Documents\memo.txt You'll have to come up with some windows-specific trick to find out the current user, because my documents is actually in c:\documents and settings\currentusername\my documents\ Try getting it from the HOMEPATH environment variable. import os print os.environ['HOMEPATH'] Alan ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Acessing files in Windows 2000
On Mar 9, 2005, at 01:13, Shitiz Bansal wrote: Whats worse, I had found that the rule is different for different versions of windows.Just proves what we all know...Windows Suxx. The Windows OS sucks! And blows! At the same time! (name the reference, get a cookie ;) ) -- Max maxnoel_fr at yahoo dot fr -- ICQ #85274019 Look at you hacker... A pathetic creature of meat and bone, panting and sweating as you run through my corridors... How can you challenge a perfect, immortal machine? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor