Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Python (IronPython) report "Illegal characters in path" when the word bin is used?

I am getting an "Illegal characters in path" error when doing chdir commands in Iron Python. This is happening in run time with my code, but even in the Iron Python console it has this issue. I'm using the nt module because in code the os module does not work (appears to be a known issue).

Doing a little bit of playing around it turns out the "illegal characters" is actually the word bin. Below is the text from the console that shows me getting the error only when i navigate to the bin directory.

Here is the example

>>> nt.chdir('c:\Users\xxxxx\Documents\Visual Studio 2010\Projects\xxx')
>>> nt.chdir('c:\Users\xxxxx\Documents\Visual Studio 2010\Projects\xxx\Directory')
>>> nt.chdir('c:\Users\xxxxx\Documents\Visual Studio 2010\Projects\xxx\Directory\bin')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Illegal characters in path.

Whats worse is I'll navigate to a totally different directory (that doesn't even have a bin directory) and try to navigate to a subdirectory "bin" and i'll still get that error!

Any Ideas?

like image 861
Mike Avatar asked Sep 11 '12 13:09

Mike


1 Answers

The \ path separator is also a python escape character. Double them, or better yet, use r'' raw python literals instead:

r'c:\Users\xxxxx\Documents\Visual Studio 2010\Projects\xxx'
'c:\\Users\\xxxxx\\Documents\\Visual Studio 2010\\Projects\\xxx'

For example, \n is a newline character, and \t is interpreted as a TAB. In your specific case, \b is interpreted as a backspace.

like image 182
Martijn Pieters Avatar answered Sep 19 '22 16:09

Martijn Pieters