Note that there are some explanatory texts on larger screens.

plurals
  1. POpython and windows double backslash
    primarykey
    data
    text
    <p>I got a program running on my local machine which uses some files. I create the reference to the files by using: <code>os.path.join( tempfile.gettempdir(), 'filename.txt' )</code></p> <p>After that I'm running a program which accepts some parameters <code>--log-file filepath</code> where filepath is one of the files I just explained above.</p> <p>On my machine python creates backslashes for the paths but not double backslashes and the program complains because it's considered an escape character and should be a double backslash.</p> <p>Is there any standard way of making sure that I get a working path with double backslashes in python? I could use regex but I would prefer something similar to what <code>os.</code> provides. Maybe I'm missing something.</p> <p>I'm calling the program using <code>subprocess.Popen</code>:</p> <p><code>self._proc = subprocess.Popen( command.split( ' ' ) )</code></p> <p>where <code>command</code> is something like <code>pcix.exe --log-file file_path</code></p> <p>Also, running a test on my console shows that my python does not produce double backslash for paths:</p> <pre><code>&gt;&gt;&gt; print os.path.join(tempfile.gettempdir(), "test.txt") c:\users\manilo~1\appdata\local\temp\test.txt </code></pre> <p>Leaving out the print command produces the same path:</p> <pre><code>&gt;&gt;&gt; os.path.join(tempfile.gettempdir(), "test.txt") c:\users\manilo~1\appdata\local\temp\test.txt </code></pre> <p>Any idea why?</p> <p>P.S. The platform i'm running is <code>CPython</code></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload