Using %systemdrive% in python
<p>I would like to open and work with a file with Python however I would like to use Windows <code>%systemdrive%</code> when referring to a file instead of full path. 
This piece of code works:</p>

<pre><code>if not os.path.isfile('C:\\Work\\test\sample.txt'):
</code></pre>

<p>This does not:</p>

<pre><code>if not os.path.isfile('%systemdrive%\\Work\\test\\sample.txt'):
</code></pre>

<p>Any idea? Thank you in advance!</p>

<p>You can use <a href="https://docs.python.org/3.6/library/os.html?highlight=environment#os.environ" rel="nofollow">os.environ</a></p>

<pre><code>import os
import os.path
fn = r'{0}\Work\test\sample.txt'.format( os.environ['systemdrive'] )
if not os.path.isfile(fn):
    ...
</code></pre>

python windows