Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: import syntax

Reply
Thread Tools

Re: import syntax

 
 
Joshua Landau
Guest
Posts: n/a
 
      07-29-2013
On 29 July 2013 21:23, Devyn Collier Johnson <(E-Mail Removed)>wrote:

>
> On 07/29/2013 04:20 PM, Tim Chase wrote:
>
>> On 2013-07-29 16:09, Dave Angel wrote:
>>
>>> On 07/29/2013 03:48 PM, Devyn Collier Johnson wrote:
>>>
>>>> The PEP8 recommends importing like this:
>>>>
>>>> import os
>>>> import re
>>>>
>>>> not like this:
>>>>
>>>> import os, re
>>>>
>>> I got a bit further, and if I'm only using a couple of functions
>>> from the import, I'll list them in the comment.
>>>

>> If I just plan to use a small subset, I tend to reach for the
>>
>> from sys import stdout, stderr, exit
>>
>> sort of syntax. I find it makes my code read a bit more cleanly than
>> having to type "sys.stderr.write(...)" everywhere but is still pretty
>> readable.
>>
>> -tkc
>>
>>
>> So, there are no advantages or disadvantages when disregarding

> readability?



Sure, just as one light is no brighter or dimmer than another when
disregarding luminosity.

As people have said, it improves diffs as well. It flows quicker into the
"from module import things" form (which I oft prefer), too.

When asking these questions, ask yourself "why would it *compile*
differently? It wouldn't. Plus, premature optimisation is the root of all
evil.

1) Write your code
2) If it's slow:
2a) Do you have time? If so:
2b) Is it important to speed up, or is the slowness not worth spending the
hours fixing?
2c) Profile it to see what's actually slow
2d) Realise that the slow part is not what you thought it was
2e) Fix the bit that's slow (and nothing else)
2f) Repeat from 2
3) Write some more code

 
Reply With Quote
 
 
 
 
Neil Cerutti
Guest
Posts: n/a
 
      07-30-2013
On 2013-07-29, Joshua Landau <(E-Mail Removed)> wrote:
> Sure, just as one light is no brighter or dimmer than another
> when disregarding luminosity.
>
> As people have said, it improves diffs as well. It flows
> quicker into the "from module import things" form (which I oft
> prefer), too.
>
> When asking these questions, ask yourself "why would it
> *compile* differently? It wouldn't. Plus, premature
> optimisation is the root of all evil.
>
> 1) Write your code
> 2) If it's slow:
> 2a) Do you have time? If so:
> 2b) Is it important to speed up, or is the slowness not worth spending the
> hours fixing?
> 2c) Profile it to see what's actually slow
> 2d) Realise that the slow part is not what you thought it was
> 2e) Fix the bit that's slow (and nothing else)
> 2f) Repeat from 2
> 3) Write some more code


1a) Does it work?
1b) Can you prove it?

It's best to at least have some regression tests before you start
refactoring and optimizing.

--
Neil Cerutti
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
to use import java.lang.* or import java.lang.Math or none at all? JPractitioner Java 13 02-24-2006 08:48 PM
XML Schema question - does "import" import elements? Vitali Gontsharuk XML 2 08-25-2005 07:33 PM
IMPORT STATIC; Why is "import static" file scope? Why not class scope? Paul Opal Java 12 10-10-2004 11:01 PM
GTK import doesn't import first time Dennis Python 2 08-18-2003 10:00 PM
import/from import question Artur M. Piwko Python 1 07-02-2003 07:04 PM



Advertisments