473,387 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 11833
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

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

Similar topics

5
by: | last post by:
Hi, I have a Windows Service that uses a referenced dotnet-dll. In my dll I set some public string to a stringvalue that I get from reading a xml-file(my config file). It works fine if I use it...
1
by: William Starr Moake | last post by:
Another problem with absolute paths in the WYSIWYG editor I'm putting together. The function to toggle between WYSIWYG and HTML modes works except for one glitch. If you use a relative path for...
9
by: Grant Edwards | last post by:
I have several python apps (some wxPython, some plain text-mode stuff) that I distribute internally for installation on Win32 machines. They're bundled/installed using py2exe and inno setup. I...
6
by: Laszlo Zsolt Nagy | last post by:
Sorry, I realized that the import zlib was not executed from my (working) service. So here is the question: why can't I use zlib from a win32 service? Is there any way to make it working? ...
4
by: gnah | last post by:
Greetings, I hope my problem is easy to fix, I'm pretty new with php - but I am getting weird results with the opendir() function. It may just be a path problem, but I don't see which variable...
3
by: route_coder | last post by:
I am using access database to create a crystal report in VB.NET Everything works fine when I run on my machine. But when I am deploying it other windows machines. It is asking for database server...
0
by: Ingo Eichenseher | last post by:
I've the follwing configuration: <httpHandlers> <add verb="GET" path="FilmImage.jpg" type="oaky.ImageHandler" validate="false"/> </httpHandlers> IIS is configured to handle '.jpg' via...
1
by: gnewsgroup | last post by:
I have a user control called Footer.ascx, in which a background image is inserted like so: <div id="footerdiv" style="background-image:url('Images/ mybackground.jpg');...
6
by: Marcin201 | last post by:
Is there an built-in functionality in python to convert Windows paths to Unix paths? I am running into problems when creating data files on Windows and the running them on a Unix platform. I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.