3 ms·
I don't see this mentioned, but on python a file can be considered a singleton class. If you come from java, this may help you write better python code. No need
by TrianguloY 3y ago
I don't see this mentioned, but on python a file can be considered a singleton class. If you come from java, this may help you write better python code. No need to encapsulate things on a class! The file is the singleton itself!
- goatlover 3y agoAnd how much do the Python libraries make use of that as opposed to defining their own classes for you to use?
- jononomo 3y agoPython libraries make use of modules (i.e., Python files) all the time.
- not_jules 3y agoIt's how the majority of the stdlib is written. Construction of objects with the stdlib is pretty limited to things that allocate os resources (files, sockets, etc with obvious state full ness and destruction behavior) unless you're already operating on objects (dict views, iterators). The exceptions are those which were ported (unittest was a clone of java 's framework incl method names).
- seanthemon 3y agoThat's useful!