[Tutor] Advice needed on first project
Adam
adam at monkeez.org
Thu Apr 15 12:49:25 EDT 2004
Thanks Magnus. I have some more related questions below
Magnus Lycka wrote:
> Adam wrote:
>
>>I've started coding some python as my first attempt at learning it - I
>>kind of learn things by doing them.
><snip>
>
> Try replacing the line:
>
> create_new_article.newarticle()
>
> with
>
> article_items = create_new_article.newarticle()
>
I did try this earlier, but must have had a syntax problem, or something
similar - it seemed to me to be the most obvious thing to do. Am I right
in thinking that the passed article_items and the menu article_items are
different references - or do they point to the same object? What I'm
trying to say is, does it produce a copy of that object, or is it
another pointer to that same object ?
>
>>I'd also appreciate some feedback on the code design. Does the code
>>reflect the best design, or would there be a better way of doing this?
>
>
> No. There is always a better way of doing things. Is it good enough?
> Well, since it doesn't actually work yet, and seems far from complete,
> I guess it's a bit early to say...
>
> One detail is that you shouldn't make lines longer that 70-80 characters
> (just like with normal text) as it gets difficult to read.
Agreed
> It's also not very pythonic to make such small modules. I this case
> I see no reason to make more than one file. Split it if it really needs
> to be split, i.e. if it gets big, has several maintainers etc. With the
> typical "if __name__ == '__main__':" trick, you can still use the code
> as a module even if it also works as a stand alone program.
Ah, I did wonder this - it is good to know this sooner than later. I
will try to encorporate the code in to fewer files.
> I also see two cases where it might be more pythonic to use a loop
> and a more data driven approach,
Hmm - I'm not sure what you mean here - would this involve producing
something like a query module, which acts as a menu which receives the
options that are available and then outputs them to the user and handles
the response? I imagine that this would save a lot of coding. Is this
possible? It is difficult for me to be clear without writing some code.
I might have a stab at this this evening.
> You might also consider using triple quoted milti line strings for
> your welcome message.
>
What benefit does this offer? I thought that the quotes pretty much
acted in the same ways, unless you used 'special chars', like " and '
inside them. Does this have something to do with the newline characters?
Thanks again. Already I feel at home!
adam
More information about the Tutor
mailing list