1
doc_holder_str = ''
sample_H_value = open("C:\testGupixwin\BX-N-H.HED", "r")
standard_conc_value = open("C:\testGupixwin\gupixwin_H_stdConc.txt", "r")
sample_H_value_str = sample_H_value.readline()
while sample_H_value_str is not '' :
    stripper_sample_H = float(sample_H_value_str[5:].lstrip(' '))

I'm trying to write a piece of code (as shown above) which reads some values, do some calculations on it and returns the said values. I am using the LiClipse IDE, for python.

I have tested my code and it works, but when I tried to run it with real data, ( for which I created a new folder to put in all the files I will be working with) I received an OS error suggesting I inserted an invalid argument.

The error report says ;

Traceback (most recent call last):
File "C:\Python34\workspace\Gupixwin_Project.py", line 11, in <module>
sample_H_value = open("C:\testGupixwin\BX-N-H.HED", "r")
OSError: [Errno 22] Invalid argument: 'C:\testGupixwin\\BX-N-H.HED'

on clicking on the C:\testGupixwin\\BX-N-H.HED it bring up a message box suggesting, and I quote,

The definition was found at C:\testGupixwin\BX-N-H.HED, (which cannot be opened because it is a compiled extension)

I must point out that I feel the error is that the system sees ...\\BX-N.... Instead of ..\BX-N... Which I expect.

Some one suggested I do this

[Open Window -> Preferences, goto PyDev -> Editor -> Code Style -> File Types, look for "Valid source files (comma-separated)" and append ", log".]

I HAVE DONE THIS BUT I STILL GET THE OSERROR REPORT.

Thanks for any assistance

1 Answers1

0

I think the problem is the escaping with \

alternate the string in: open("C:\testGupixwin\BX-N-H.HED", "r") with:

open( r"C:\testGupixwin\BX-N-H.HED", "r" ) #rawstring
# or 
open( "C:\\testGupixwin\\BX-N-H.HED", "r" ) #escaping the '\' with '\'

(also do this in the following line)

Skandix
  • 1,916
  • 6
  • 27
  • 36
  • it worked, thank you. I do not understand why my initial code did not work and ur suggestions did. could u help in explaining the issue, so that i can learn from this. or point me to something to study oon it @Skandix – Chukwunonso Feb 15 '18 at 11:44
  • Sure, for the second approach: take a look at [this answer](https://stackoverflow.com/a/24085681/4464653) from [Why do backslashes appear twice?](https://stackoverflow.com/q/24085680/4464653). Regarding the `r` in front of the string: it does the same - every sign in represented by a single `char`, therefore no backslash escaping. Finally, I'm glad you asked for a reference to study from - I feel like no one does this. One upvote for that ;) – Skandix Feb 15 '18 at 11:46