How to Print a Path in Python?
<p>I want to make a script open the CMD and then enter a path:</p>

<pre><code>import pyautogui as pag
pag.hotkey('win','r')     
pag.typewrite('cmd')
pag.press('enter')
pag.typewrite('C:\Users\XY\AppData\')
</code></pre>

<p>that doesn't work. So, I tried this:</p>

<pre><code>import pyautogui as pag
pag.hotkey('win','r')
pag.typewrite('cmd')
pag.press('enter')
pag.typewrite('C:\\Users\\huba5_000\\AppData\\')
</code></pre>

<p>However, this entered <code>C:?Users?XY?AppData?</code></p>

<p>What I want it to enter is <code>C:\Users\XY\AppData\</code>. Do you know what I should write instead of '\\' ? </p>

<p>Thank you in advance!</p>

<p>when a string is read in from <code>input()</code> or from text boxes in gui's (in general.. idk about pag) the extra slashes are automatically put in. They are not automatically put in for string literals in your code however and must be escaped (hence the double slash). Here is a short console session (python 2.7) showing that functionality:</p>

<pre class="lang-python prettyprint-override"><code>>>> s = raw_input('enter a path: ') #change raw_input to input() for python 3.x
enter a path: \usr\var
>>> s
'\\usr\\var'
>>> print s
\usr\var</code></pre>

<p>notice when I entered the path, I did not escape my backslashes, yet when I call the internal representation of <code>s</code> they have been put in for me. when I want the output format, I call print to execute any formatting (escapes) contained within the string</p>

python python-3.x printing pyautogui