471,344 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,344 software developers and data experts.

Windows XP os.chdir() path problem...

GTXY20
29
Hi there,

I have been pulling my hair out with the following error - here is the code:

Expand|Select|Wrap|Line Numbers
  1. os.chdir("..\data")
  2. uhdatafile = open("%s.txt" % self.datafile, 'r')
  3.  
which gives me the following error:

Expand|Select|Wrap|Line Numbers
  1. WindowsError: [Error 2] The system cannot find the file specified: 'C:\\Documents and Settings\\HHG\\Desktop\\Reportsdata
  2.  
can anyone shed soem light, I have imported os and I have also tried indicating \\data, /data, //data.

Thanks so much.

G.
Oct 12 '07 #1
4 11721
bartonc
6,596 Expert 4TB
Hi there,

I have been pulling my hair out with the following error - here is the code:

Expand|Select|Wrap|Line Numbers
  1. os.chdir("..\data")
  2. uhdatafile = open("%s.txt" % self.datafile, 'r')
  3.  
which gives me the following error:

Expand|Select|Wrap|Line Numbers
  1. WindowsError: [Error 2] The system cannot find the file specified: 'C:\\Documents and Settings\\HHG\\Desktop\\Reportsdata
  2.  
can anyone shed soem light, I have imported os and I have also tried indicating \\data, /data, //data.

Thanks so much.

G.
use raw strings for Windows path variables!
Expand|Select|Wrap|Line Numbers
  1. os.chdir(r"..\data")
  2. uhdatafile = open("%s.txt" % self.datafile, 'r')
  3.  
Also look at
normpath( path)

Normalize a pathname. This collapses redundant separators and up-level references so that A//B, A/./B and A/foo/../B all become A/B. It does not normalize the case (use normcase() for that). On Windows, it converts forward slashes to backward slashes. It should be understood that this may change the meaning of the path if it contains symbolic links!
Oct 12 '07 #2
bartonc
6,596 Expert 4TB
use raw strings for Windows path variables!
Expand|Select|Wrap|Line Numbers
  1. os.chdir(r"..\data")
  2. uhdatafile = open("%s.txt" % self.datafile, 'r')
  3.  
Also look at
Expand|Select|Wrap|Line Numbers
  1. >>> os.getcwd()
  2. 'D:\\My Documents\\HETAP Project\\2.13a'
  3. >>> os.path.normpath('..')
  4. '..'
  5. >>> os.path.abspath('..')
  6. 'D:\\My Documents\\HETAP Project'
  7. >>> 
  8. >>> os.path.abspath(r'..\2.12a')
  9. 'D:\\My Documents\\HETAP Project\\2.12a'
  10. >>> os.path.abspath('..\2.12a')
  11. 'D:\\My Documents\\HETAP Project\\2.13a\\..\x02.12a'
  12. >>> os.path.abspath('..\\2.12a')
  13. 'D:\\My Documents\\HETAP Project\\2.12a'
  14. >>> 
Oct 12 '07 #3
GTXY20
29
Perfect - thank you.
Oct 12 '07 #4
bartonc
6,596 Expert 4TB
Perfect - thank you.
Any time .
Oct 12 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by William Starr Moake | last post: by
9 posts views Thread by Grant Edwards | last post: by
6 posts views Thread by Laszlo Zsolt Nagy | last post: by
4 posts views Thread by gnah | last post: by
3 posts views Thread by route_coder | last post: by
reply views Thread by Ingo Eichenseher | last post: by
1 post views Thread by gnewsgroup | last post: by
6 posts views Thread by Marcin201 | last post: by
reply views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.