My first Python program
Chris Rebert
clp2 at rebertia.com
Tue Oct 12 15:45:56 EDT 2010
On Tue, Oct 12, 2010 at 12:14 PM, Seebs <usenet-nospam at seebs.net> wrote:
> So, I'm new to Python, though I've got a bit of experience in a few other
> languages. My overall impressions are pretty mixed, but overall positive;
> it's a reasonably expressive language which has a good mix between staying
> out of my way and taking care of stuff I don't want to waste attention on.
>
> My first project was to replace a shell script with a Python script.
<snip>
> The source in its current form:
>
> http://github.com/wrpseudo/pseudo/blob/master/makewrappers
>
> The underlying task is fairly ugly, and it's my first Python project,
> so the result isn't particularly pretty, but I'd be interested in
> feedback on it. However, I'm not at all sure whether it's appropriate for
> this group to post 467 lines of code with no question beyond "how am
> I screwing this up?"
>
> At this point, it does everything I want it to do, so the question isn't
> "how can I do this?", but "how should I have done this more idiomatically?"
1.
class SourceFile(object):
"A template for creating a source file"
Docstrings are typically triple-quoted, so ==>
class SourceFile(object):
"""A template for creating a source file"""
2.
self.f = file(path, 'r')
if not self.f:
return None
The "if" here is pointless; I'm reasonably sure files are always
considered boolean true.
3.
if not section in self.sections:
Python's grammar has "not in" as an "operator" for just such occasions ==>
if section not in self.sections:
4.
def emit(self, template, func = None):
PEP 8: "Don't use spaces around the '=' sign when used to indicate
[...] a default parameter value." ==>
def emit(self, template, func=None):
I stopped reading around line 272.
Cheers,
Chris
--
http://blog.rebertia.com
More information about the Python-list
mailing list