Print directory where file is saved with Python
<p>how could do print the path directory of my file saved with python.
For ad example, i start with idle3 (Fedora 24), i save the IDLE code on: /home/jetson/Desktop/Python/Programs and in the code is written:</p>

<pre><code>f = open("Hello.txt","w")
f.write("This is a test","\n")
f.close()
</code></pre>

<p>My question is: after f.close i would print the directory grabbed with </p>

<pre><code>import sys.os 

print("The file is saved in ",direcotrysaved)
</code></pre>

<p>It's possible?</p>

<p>Using f.name provides the file name if you didn't supply it as a separate variable.<br>
Using <code>os.path.abspath()</code> provides the full file name including it's directory path i.e. in this case "/home/rolf/def"<br>
Using <code>os.path.dirname()</code> strips the file name from the path, as that you already know.    </p>

<pre><code>&gt;&gt;&gt; import os
&gt;&gt;&gt; f=open('xxxx.txt','w')
&gt;&gt;&gt; f.close()
&gt;&gt;&gt; print(f.name,'Stored in', os.path.dirname(os.path.abspath(f.name)))

xxxx.txt Stored in /home/rolf/def
</code></pre>

python python-3.x