Request for feedback on my first Python program
Erik Max Francis
max at alcyone.com
Fri May 30 20:50:31 EDT 2003
Scott Meyers wrote:
> - I'm used to a compiler complaining if I reference a variable
> without
> declaring it. Python doesn't do this, nor can I find mention of
> some
> kind of warning mode that will cause it to do it. I've also read
> a
> tiny little bit about pyChecker. Is it common to use such tools,
> or do
> real Python programmers go bareback?
It's hard to see how you would do this in Python, since Python lacks
declarations. It's legal to reference a variable if you've already
defined it; it isn't otherwise (you get a NameError exception).
PyChecker can help with some systematic errors like this, and is always
worth running on any large project just as a sanity check, but
ultimately dynamic programming involves a different approach.
> - Is it better to get into the habit of (a) importing modules and
> using
> fully qualified names or (b) importing selective names from
> modules and
> using them without qualification? That is, which is generally
> better?
>
> import sys # a
> sys.exit(1)
>
> from sys import exit # b
> exit(1)
It's mostly a matter of style; I personally prefer the former unless
that creates hugely long names in the code). I would tend to say that
the latter approach is appropriate when you only need a few things from
the module in question. if you're using quite a bit of it, the former
notation makes more sense (except, of course, when it results in long
names; then importing an intermediate package would probably be
warranted).
--
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ Heaven ne'er helps the man who will not act.
\__/ Sophocles
More information about the Python-list
mailing list