<story><title>Show HN: PyFilesystem 2.0 – A Python interface to filesystems of all kinds</title><url>https://www.willmcgugan.com/blog/tech/post/announcing-pyfilesystem-2/</url></story><parent_chain><item><author>amyjess</author><text>Oh, this looks really nice. Thank you for posting it!&lt;p&gt;A while back, I had an idea for modelling a filesystem as a dict, so maybe this will inspire me to get off my ass and actually write it.&lt;p&gt;Basically, the idea is that this:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    foo = rootfs[&amp;#x27;home&amp;#x27;][&amp;#x27;amyjess&amp;#x27;][&amp;#x27;stuff&amp;#x27;][&amp;#x27;foo.txt&amp;#x27;]
    rootfs[&amp;#x27;home&amp;#x27;][&amp;#x27;amyjess&amp;#x27;][&amp;#x27;stuff&amp;#x27;][&amp;#x27;bar.txt&amp;#x27;] = bar
&lt;/code&gt;&lt;/pre&gt;
would be equivalent to this:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    with open(&amp;#x27;&amp;#x2F;home&amp;#x2F;amyjess&amp;#x2F;stuff&amp;#x2F;foo.txt&amp;#x27;, &amp;#x27;r&amp;#x27;) as foo_file:
        foo = foo_file.read()
    with open(&amp;#x27;&amp;#x2F;home&amp;#x2F;amyjess&amp;#x2F;stuff&amp;#x2F;bar.txt&amp;#x27;, &amp;#x27;w&amp;#x27;) as bar_file:
        bar_file.write(bar)
&lt;/code&gt;&lt;/pre&gt;
I really want to implement that now.</text></item></parent_chain><comment><author>existencebox</author><text>It&amp;#x27;s funny you mention that, I have literally that functionality in my &amp;quot;blob storage&amp;quot; python wrapper.  Currently it&amp;#x27;s just like 50 lines of code I use for internal ad-hoc storage because as it turns out, reasoning about storage as a hierarchy is really nice.  (I also let you index with a list, where the list is the hierarchical path; the key part being composibility, which I imagine you can do reasonably with both models).&lt;p&gt;Interesting to know that it&amp;#x27;s a more common pattern.  I will have to think a bit on where that may go.  I had always shot down any &amp;quot;value&amp;quot; with &amp;quot;it&amp;#x27;s just a thin transformation on top of path.join&amp;quot;. (yay self-deprecation or something?)</text></comment>
<story><title>Show HN: PyFilesystem 2.0 – A Python interface to filesystems of all kinds</title><url>https://www.willmcgugan.com/blog/tech/post/announcing-pyfilesystem-2/</url></story><parent_chain><item><author>amyjess</author><text>Oh, this looks really nice. Thank you for posting it!&lt;p&gt;A while back, I had an idea for modelling a filesystem as a dict, so maybe this will inspire me to get off my ass and actually write it.&lt;p&gt;Basically, the idea is that this:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    foo = rootfs[&amp;#x27;home&amp;#x27;][&amp;#x27;amyjess&amp;#x27;][&amp;#x27;stuff&amp;#x27;][&amp;#x27;foo.txt&amp;#x27;]
    rootfs[&amp;#x27;home&amp;#x27;][&amp;#x27;amyjess&amp;#x27;][&amp;#x27;stuff&amp;#x27;][&amp;#x27;bar.txt&amp;#x27;] = bar
&lt;/code&gt;&lt;/pre&gt;
would be equivalent to this:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    with open(&amp;#x27;&amp;#x2F;home&amp;#x2F;amyjess&amp;#x2F;stuff&amp;#x2F;foo.txt&amp;#x27;, &amp;#x27;r&amp;#x27;) as foo_file:
        foo = foo_file.read()
    with open(&amp;#x27;&amp;#x2F;home&amp;#x2F;amyjess&amp;#x2F;stuff&amp;#x2F;bar.txt&amp;#x27;, &amp;#x27;w&amp;#x27;) as bar_file:
        bar_file.write(bar)
&lt;/code&gt;&lt;/pre&gt;
I really want to implement that now.</text></item></parent_chain><comment><author>dom0</author><text>You might want to look at pathlib:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    with (Path.home() &amp;#x2F; &amp;#x27;.config&amp;#x27; &amp;#x2F; &amp;#x27;1234.conf&amp;#x27;).open() as fd:
        print(&amp;#x27;Hello&amp;#x27;, file=fd)
&lt;/code&gt;&lt;/pre&gt;
Granted, with &amp;#x2F; precedence you&amp;#x27;ll often need parens to group &amp;#x2F; before .</text></comment>