Skip to main content

Posts

The Implied Module Path

We all know there is an implied path to import from for the main module, but it seems a few people get mixed about the details of how this works. In particular, it seems that this path is being confused for the current working directory . Here is a little note to help remember the distinction. Any module implicitly can import packages and modules in the same directory its file resides in, which is os.path.dirname(the_module.__file__) Often you run a script, when starting out, from its own directory, so that this implied path is the current working directory . This fact is purely a coincidence. The result boils down simply to understanding that any import can be relative to the module it appears in , and if you run a local (not system-wide available) script, that just happens to be your current directory, by coincidence.

Minimal Working Examples: How to, Why, and Who cares

When you have a problem and you rush to colleagues, or strangers on IRC and mailing lists, you've got to present a problem they'll want to help you fix, and with all the information they need to fix it. You can't give them information they dont need, because any extra work filing through your unrelated code is going to reduce the chances anyone will put in the time to help you. We can state a few rules about seeking help with code. Ask the question clearly and don't be ambiguous about your intentions and requirements. If you need to include code, it needs to include all important context. Present the problem without reference to out-of-context issues. Don't come in with a link to your entire body of code telling us it doesn't work. What doesn't work is asking for help like that. Besides telling us exactly how things don't work, and what they are doing compared to what you are expecting, you need to give us code that specifically and only demonstrates the...

Standard Gems: colorsys

Lots of us do color work. Maybe you're writing a full-fledged Photoshop killer, or you just want a utility to do some bulk conversions or color scheme generations. Well, in any case, you might find the often-forgotten colorsys module handy. You can easily convert between different color component systems with these included functions: hls_to_rgb(h, l, s) hsv_to_rgb(h, s, v) rgb_to_hls(r, g, b) rgb_to_hsv(r, g, b) rgb_to_yiq(r, g, b) yiq_to_rgb(y, i, q)

Book Review: Practices of an Agile Developer

Software development is widely known as having the largest gap of any discipline between the best known practices and the actual practices utilized in the field. The most depressing part of that statement is how inaccurate the qualifier of "widely known" probably is, because if the gap was as well and widely known as it should be, the gap would be shrinking much faster than it is. Is the gap even shrinking at all? One of the things on the good end of this gap is the collective practices known as Agile Development. The creation of software is fluid and must be adaptable at a moments notice, defined as it is created, and grown rather than built, says the mantras of the agile development proponents. They contrast to the traditional and aging mentality of designing everything before writing anything, following a walled path to the goal, and building monoliths of code. The differences between the old side and the new side are great, and this is the gap we need to wade across to so...

RTFM Not Just a Disgruntled Reply

Are you or have you been new to something technical? Of course. Have you asked a question when you were lost? Have you been told, by those who you trusted to enlighten your path, "RTFM!"? Well, you are not alone, and if you felt you got a raw deal, you are not alone. However, you are wrong. "RTFM" is a perfectly valid and, despite the opinion of many, very good advice in your time of need, indeed. The camp of the knowledge seekers is seperated into two groups, with the line between them varying depending on the context. The first and largest group is the active knowledge seeker, who is after some bit of information. The second and smaller group are those who have that information. The seeking group has two options to get what they need: utilizing known resources, such as books and articles and tutorials; or, asking those who have previously sought and found, and can give them the information they seek quickly, without wading through entire volumes of documentation. ...

Pure Functions in the Python Standard Library?

I am toying with a small package for working with and developing pure functions in Python. An important part of this is allowing the pure functions you write to use as much of the standard library as possible, while remaining pure. What functions in the standard library could you call pure? Builtin types, the entire math library, the itertools module, etc. are on my list, but I don't want to miss things. Any suggestions? So far I have a decorator that ensures a function A) only takes immutables and known-pure functions as arguments, and B) ensures any global names used within the function are pure functions. It is primitive, but a start. I hope to take this further with some actual uses, such as create working processes locally and remotely and pushing pure functions to them. This also has interesting potential for optimizing large computations, like executing functions before they are called when the potential arguments are known. Pure functions are interesting and might be a nice...