Windows path in Python
you can use always:
'C:/mydir'
this works both in linux and windows.
Other posibility is
'C:\\mydir'
if you have problems with some names you can also try raw string literals:
r'C:\mydir'
however best practice is to use the os.path
module functions that always select the correct configuration for your OS:
os.path.join(mydir, myfile)
From python 3.4 you can also use the pathlib module. This is equivelent to the above:
pathlib.Path(mydir, myfile)
or
pathlib.Path(mydir) / myfile
How to add a folder to the Windows PATH with Python?
You should use:
os.environ['PATH'] += R";C:\my\folder"
Python Convert Windows File path in a variable
I've solved it.
The issues lies with the python interpreter. \t and all the others don't exist as such data, but are interpretations of nonprint characters.
So I got a bit lucky and someone else already faced the same problem and solved it with a hard brute-force method:
http://code.activestate.com/recipes/65211/
I just had to find it.
After that I have a raw string without escaped characters, and just need to run the simple replace() on it to get a workable path.
Python windows path
Thanks for all the help, in the end it was solved by removing 1 backslash.
<add key="logfilepath" value="\Logs\LogMain.log" />
to
<add key="logfilepath" value="Logs\LogMain.log" />
How to add a directory to System path variable in Python
sys.path
is not the same as the PATH
variable specifying where to search for binaries:
sys.path
A list of strings that specifies the search path for modules. Initialized from the environment variable PYTHONPATH, plus an installation-dependent default.
You want to set the PATH
variable in os.environ
instead.
app_path = os.path.join(root_path, 'other', 'dir', 'to', 'app')
os.environ["PATH"] += os.pathsep + os.path.join(os.getcwd(), 'node')
Related Topics
How to Create a Density Plot in Matplotlib
How to Sort a Dictionary by Value
How to Count the Occurrences of a List Item
What Exactly Do "U" and "R" String Prefixes Do, and What Are Raw String Literals
Remap Values in Pandas Column With a Dict, Preserve Nans
How to Put the Legend Outside the Plot
Difference Between Old Style and New Style Classes in Python
Check If Multiple Strings Exist in Another String
Download Large File in Python With Requests
What Does the "Yield" Keyword Do
Are Global Variables Thread-Safe in Flask? How to Share Data Between Requests
Evaluating a Mathematical Expression in a String
When Should I (Not) Want to Use Pandas Apply() in My Code
How to Type Hint a Method With the Type of the Enclosing Class