&gt; os.path.expanduser(&quot;~&#x2F;.cache&#x2F;ssh2_list&quot;)<p>Please, consider $XDG_CACHE_HOME. Not everyone likes the default directory layout.<p>I think, ugly-looking but reasonably portable version would look like<p><pre><code>  os.path.join(os.environ.get(&quot;XDG_CACHE_HOME&quot;, os.path.join(os.path.expanduser(&quot;~&quot;), &quot;.cache&quot;)), &quot;ssh2_list&quot;)</code></pre>