Efficient python programming...

Steve Holden sholden at holdenweb.com
Fri Jun 7 09:39:31 EDT 2002


"Shagshag13" <shagshag13 at yahoo.fr> wrote in message
news:adpktk$17j3k$1 at ID-146704.news.dfncis.de...
>
> "gabor" <gabor at realtime.sk> a écrit dans le message de news:
mailman.1023401650.18434.python-list at python.org...
>
> > but if you want to know about specific python issues, then you have to
> > learn things like "dictionary are very well optimized etc.."
>
> That's what i'm asking : learning and understanding... but where should i
go ???
>
You may not want to hear this, but experience and thought are always going
to be your best guides. I am a much better programmer now than I was thirty
years ago. Why? Because I've done things wrong, and corrected my errors.
I've repeated the same tasks many times, and found out by practical
experience what works best (for me) and what doesn't. The meat between your
ears will provide you with important knowledge if you take the time to
analyse your experience. If you don't then you should remember that "those
who cannot remember history are doomed to repeat it".

> I'm wondering if there is a place to go to find "why this solution is
better in this
> appropriate case... ". For example, i was looking for the best pythoner's
way to
> remove duplicate in a list, and after reading many posts, i find at the
end of a
> cookbook recipe that it was :
>
> set = {}
> map(set.__setitem__, alist, [])
> alist = set.keys()
>
> But that's not trivial !!! And quite difficult to find...
>
... and not always appropriate. One of the things experience will teach you
is that when your list only contains ten elements the more obvious solutions
are to be preferred, since they will execute in maybe 100 microseconds
instead of 63.

> > those things doesn't make your code obfuscated..
>
> I agree :)
>
> > [file.printsize() for file in directory]
> >
> > they're the same, and everyone would recommend you the last one..
>
> Yes but i would have asked why this is the best... And i think that
> your answer would have helped me to become a better pythoner...
>
Of course, comp.lang.python itself is a good place to ask questions like
that. The more trivial the question, the more people will have their own
opinions, of course, so you will still need to use your intelligence to make
sense of the profusion of replies.

> I mean there should be a place to go where you could read generalities
> like "as dictionary are very well optimized, you can use it without
> trouble and for example it's best in : removing duplicates, ..." or
> "if you need to do an operation on a list use map because it's
> c-optimized", there are "object overhead if you...", and so on
> that's not in the books, that's not in 'dive in python',
> it's spreaded in Guido's essays, and posts over there... But i worry,
> you could miss it if you don't spend many time to search, and say
> "there should be a place for that"...
>
Perhaps you should think about writing a book? I did, and I know there are
lots of things I would have liked to include but didn't have space and/or
time.

> > so to summarize this: what do you want to know/learn?
>
> What a beginner should learn to do it the pythoner way...
>
> s13.
>
> ps : and sorry for my poor english and typos...
>
Don't worry about that. Your concern for knowing these things suggests that
you will be a good Python programmer. But the most important part of
becoming a good Python programmer is becoming a good programmer. Knowing the
right question sto ask is as important as getting the answers, so you are
already a good way down the path. Many of the required skills aren't
specific to Python...

regards
 Steve
--
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------








More information about the Python-list mailing list