TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Uncommon Uses of Python in Commonly Used Libraries

178 pointsby 7d7nalmost 3 years ago

8 comments

codethiefalmost 3 years ago
&gt; That said, is there a reason not to use relative imports?<p>Yes, they make reading imports across your entire project rather difficult: Suddenly there are multiple ways of referring to the same module. If you ever have to do a project-wide search &amp; replace during a refactoring (because your favorite refactoring tool failed you), this will be hell.<p>Moreover, in each file you&#x27;ll end up with a weird blend of absolute and relative imports, depending on what was shorter or looked nicer to the author at the time. Not nice to look at <i>at all</i>.<p>&gt; This led me to dig into why we might add to __init__.py<p>…or why we might rather not. Init files are one of the main reasons imports in Python often behave in unexpected ways. As a library user I do <i>not</i> want to study the library&#x27;s init files first, but unfortunately I often have to in order to understand what is going on. (Case in point: Tensorflow 1&#x2F;2. To this day, I can&#x27;t claim I understand how exactly their init magic works and time and again I get bitten by failed imports.)
评论 #32532173 未加载
vonwoodsonalmost 3 years ago
“There should be one– and preferably only one –obvious way to do it.“<p>If you’re not maintaining one of the libraries listed in the article, and try to pull any of this “clever” stuff you’ll be bitten on the ankle by a pythonic snake. No exceptions.
评论 #32533163 未加载
评论 #32531315 未加载
评论 #32531327 未加载
norwalkbearalmost 3 years ago
Python: if something can be done weird, someone will do it.<p>I know I&#x27;m guilty of doing dynamic library imports and monkey patching things.
评论 #32532399 未加载
OJFordalmost 3 years ago
Surely the most common reason for __init__ file content is re-exporting some otherwise deeper objects. The second is probably laziness - just bung it all in __init__!
评论 #32531514 未加载
O__________Oalmost 3 years ago
Recently was also looking around for quantifiable stats on Python for: downloads, usage, FAQs, etc. — and found these:<p><a href="https:&#x2F;&#x2F;pypistats.org&#x2F;top" rel="nofollow">https:&#x2F;&#x2F;pypistats.org&#x2F;top</a><p><a href="https:&#x2F;&#x2F;www.programcreek.com&#x2F;python&#x2F;index&#x2F;module&#x2F;list" rel="nofollow">https:&#x2F;&#x2F;www.programcreek.com&#x2F;python&#x2F;index&#x2F;module&#x2F;list</a><p><a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;tagged&#x2F;python?tab=Votes" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;tagged&#x2F;python?tab=Votes</a><p>Anyone know of any others or large collections of Python source code that are easy to download?
评论 #32533762 未加载
pyuser583almost 3 years ago
I would add overriding boolean dunder methods: __and__, __or__, __xor__ dunder methods.<p>Even more rare is overriding bitwise shift operations: __rshift__, __lshift__ etc. This is unfortunate, as these methods are only natively implemented in integers, so they’re basically freebies.
评论 #32533889 未加载
CloudYelleralmost 3 years ago
I think multiple inheritance will always scare me. What order do the superclass inits run in? What happens if they do conflicting things? What if some superclasses call super().__init__ and others don&#x27;t?<p>No thanks, I&#x27;ll suffer through reading a few additional lines of:<p>class SomeBusinessyThing:<p><pre><code> def __init__(self, util, other_util): self._util = util self._other_util = other_util @classmethod def create(cls): return cls(util_module.Util(), other_module.Other()) def calculate(self): source = self_other_util.get_source() return self._util.get_stuff(source) </code></pre> vs<p>class SomeBusinessyThing(Utils, Other):<p><pre><code> def __init__(self, \*kwargs): # What does this do? No one knows super().__init__(self, \*kwargs) def calculate(self): source = self.get_source() return self.get_stuff(source)</code></pre>
评论 #32530661 未加载
评论 #32531149 未加载
评论 #32530231 未加载
评论 #32530164 未加载
评论 #32530173 未加载
评论 #32530294 未加载
userbinatoralmost 3 years ago
I thought the article would be about &quot;uncommon uses&quot; as in &quot;I didn&#x27;t know this library had pieces written in Python&quot;. Relatedly, the original BitTorrent client might be one of the first widely-distributed applications written in Python.
评论 #32530101 未加载
评论 #32530296 未加载