[Tutor] loading modules only when needed and PEP 008

Eric Walstad eric at ericwalstad.com
Thu Mar 20 04:32:01 CET 2008


Hey Timmie,
Tim Michelsen wrote:
>> When I do this sort of thing I like
>> to move my imports into my functions/methods. 
> Would this then be compliant with the style recommendations?
Hm, I'm not sure.  I guess that if you consider that somewhere near the
top of the style guide it says something about 'foolish consistency'
than I suppose it does <wink>.  I think it's ok to deviate from the pep
when it makes sense to do so.  Define 'makes sense'.  I'm assuming that
importing the matplotlib at the top of your file is making your app
unusably slow; to me that is a great reason to break from the style guide.


>> And as we are talking about style, note that your else: pass isn't
>> really necessary but it does make it explicitly clear that you are 
>> choosing not to do anything if the plot_data isn't 'yes'. 
> Ok, so I already got some style here, at least...
I wouldn't include the 'else' bits, but that's my style.


>> Are those
>>  tabs you're using?  Four spaces are preferred, according to the
>> style guide.
> I always use 4 spaces. This sometimes leads to confusions when working 
> with the same editor on text files that rely tabs but this is another 
> issue...
Sorry.  In my mail reader the indentation looked like tabs.


More information about the Tutor mailing list