Answer by freakish for What side-effects, if any, are okay when importing a...
However, in a lot of cases, the side-effects are hard to avoid or may be desirable.They are never hard to avoid, and they are never desirable. Or maybe they somewhat are hard to avoid, because it...
View ArticleAnswer by J_H for What side-effects, if any, are okay when importing a python...
logging# Creates a logfilelogging.basicConfig(filename="module.log")No, don't do it!Now git status is dirty, it shows an untracked file.Protect this with a __main__ guard,or let __init__ do the...
View ArticleWhat side-effects, if any, are okay when importing a python module?
Generally, modules should not have side effects. However, in a lot of cases, the side-effects are hard to avoid or may be desirable. There are also popular packages with on-import side-effects.Which...
View ArticleAnswer by bta for What side-effects, if any, are okay when importing a python...
One big issue with your example logging code is that both those lines of code could fail for a multitude of reasons (read-only filesystem, invalid path, lack of filesystem permissions, etc). These...
View ArticleAnswer by Basilevs for What side-effects, if any, are okay when importing a...
TL;DRSide effects are unacceptable until they are unavoidable.ConventionPython libraries are "quick and dirty" - they rely heavily on global shared state and there is little to be done about that....
View Article