Python dedicated class for file names
<p>I am writing a program that utilises a large number of files. Does Python feature an inbuilt class for file paths, or does one have to be implemented by the user (like below):</p>

<pre><code>class FilePath:
    def __init__(path):
        shazam(path)

    def shazam(self, path):
        """ something happens, path is formatted, etc """
        self.formatted_path = foobar
</code></pre>

<p><strong>Why would it be useful?</strong></p>

<p>Suppose the program and its data is copied to a different operating system. The class could modify itself on launch to support the a different path separator.</p>

<p><strong>Why not just write it yourself?</strong></p>

<p>Someone might have already written a class in the standard Python library.</p>

<p>Python has several cross platform modules for dealing with the file system, <a href="https://docs.python.org/2/library/os.path.html" rel="nofollow">paths</a> and <a href="https://docs.python.org/2/library/os.html" rel="nofollow">operating system</a>.</p>

<p>The <a href="https://docs.python.org/2/library/os.html" rel="nofollow"><code>os</code></a> module specifically has an <a href="https://docs.python.org/2/library/os.html#os.sep" rel="nofollow"><code>os.sep</code></a> character.</p>

<p><a href="https://docs.python.org/2/library/os.path.html#os.path.join" rel="nofollow"><code>os.path.join()</code></a> is OS-aware and will use the correct separator when joining paths together.</p>

<p>Additionally, <a href="https://docs.python.org/2/library/os.path.html#os.path.normpath" rel="nofollow"><code>os.path.normpath()</code></a> will take any path and convert the separators to whatever the native OS supports.</p>

python file class variables