6 ms·
I use python for datamining, and most of my work is done exploring data in iPython. > First, don't set any values in the outer scope that > aren't IN_ALL_CAPS.
by wodenokoto 12y ago
I use python for datamining, and most of my work is done exploring data in iPython.
> First, don't set any values in the outer scope that
> aren't IN_ALL_CAPS. Things like parsing arguments are
> best delegated to a function named main, so that any
> internal variables in that function do not live in the
> outer scope.
How do I inspect variables in my main function after I get unexpected results? I always have my main logic live in the outer scope because I often inspect variables "after the fact" in iPython.
How should I be doing this?
- hyperion2010 12y agoIf you are using the interpreter directly then that particular bit of advice is hard to follow since you basically live in global all the time. For that reason I would say that this advice applies mainly to .py files.
- LyndsySimon 12y agoAgreed. There's a big difference between "scripting" and "writing software" in terms of best practices. If you're writing some ETL scripts in an IPython notebook, it would be overkill to encapsulate everything to keep your global scope clean.
- msellout 12y agoI'd try to test smaller chunks of code for validity. If any block of code is longer than 12 lines, I get nervous that I don't understand what it's doing. Refactor your code into functions as you confirm the code behaves as expected in the interpreter. It's very difficult to write automated tests when all logic is in outer scope rather than chunked into functions.