Skip to main content
21 votes

What side-effects, if any, are okay when importing a python module?

logging # Creates a logfile logging.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 ...
J_H's user avatar
  • 7,600
13 votes

What side-effects, if any, are okay when importing a python module?

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 ...
freakish's user avatar
  • 1,916
6 votes
Accepted

When the stack frames become computationally expensive

There are two questions here: What is the cost of function call? Is inlining a function worth it? So first of all a function call costs. Saving registers, setting up frame, two jumps, loading ...
freakish's user avatar
  • 1,916
4 votes
Accepted

Best practices for setting up a test suite for a python library?

I think this question is not necessarily restricted to Python or the tools you mentioned - it is always the same situation whenever you develop software in an environment which differs from the ...
Doc Brown's user avatar
  • 210k
3 votes

What side-effects, if any, are okay when importing a python module?

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 ...
bta's user avatar
  • 1,161

Only top scored, non community-wiki answers of a minimum length are eligible