[Baypiggies] Discussion for newbies/beginner night talks
marilyn at deliberate.com
Sat Feb 10 07:12:08 CET 2007
----- On Friday, February 9, 2007 whitaker at google.com wrote:
> On 2/9/07, Chad Netzer wrote:
>> First, I want to thank Dennis and Drew for speaking last night, and
>> Jim Stockford for hosting the post talk discussion.
>> I've created this thread to start discussion about the "newbie" night
>> that was talked about at the end of last night's meeting. If people
>> reply to this thread only (or mostly), those on the list who aren't
>> interested can easily ignore it. If we are to host a beginners night,
>> it will be best to start organizing it soon, in order to line up
>> topics, speakers, make timely announcements, etc.
>> One person at the meeting asked about Python "idioms", and in fact in
>> a previous email I brought up the idea of an "anti-idioms"
>> presentation. I'll get the ball rolling with a few idioms and tips
>> that I can think of, without explanation. If people are interested in
>> the why, or wish to add some, please reply and discuss. Perhaps it
>> could evolve into a good QA topic for beginners.
>> Also, if people have other ideas or suggestions for a beginners night,
>> please feel free to discuss them here.
>> Some Python beginner tips and idioms:
>> 1) Do not use lists, dicts, or any mutable object as default
>> arguments; use None instead.
>> 2) If you need to do a lot of string appends, use lists and join().
>> 3) Understand and use iterators in loops.
>> 4) Use dictionaries, sets, and other mappings for searches and
>> 5) Understand and use the decorate/sort/undecorate (DSU) idiom.
>> 6) Catch exceptions that you can handle, don't suppress ones you
>> 7) Ask forgiveness, not permission. Ie. perform conversions and
>> other operations using "try". Avoid queries to determine if an
>> operation will succeed.
>> 8) Use assert() to document your code.
>> 9) Don't overuse tuples as "read only" lists. Use them to make
>> dictionary keys, or pass around short lived groups of objects.
>> 10) Use open() to open files, not file(). (trivial, perhaps)
> #) Learn to use the unittest module. Buy the O'Reilly book "Unit Test
> Frameworks", read at least chapters 1-4 & 9. Challenge yourself to
> write all your code test-first.
>  - http://www.oreilly.com/catalog/unitest/
< hour with newbees? New to Python, but know another language?
I think I'd teach them:
if __name__ == '__main__':
Import it from another module and show how it doesn't run. Get them in a namespace state of mind.
The rest of the example syntax can be almost-english-python. What would be a fun example? Enumerate is impressive to push in there. Sneak in a regular expression with named groups? They probably worked all day so there is a limit to how much you can push into their brains so maybe demo more, taking up the time, and stuff in less material so they go home feeling like they got it.
But mostly, you want to get newbeez in a namespace state-of-mind.
p.s. Thanks for the tidbits of Pythonic wisdom. They're mostly pretty intermediate, I think. More please. Hurry! Before the announce list is announced and I gotta go.
> Russell Whitaker
> Sysops Tools Team Lead
> Google Inc., Mt View, CA
> "gets() remains as a monument to C's continuing support of buffer
> overruns." - Bill Frantz
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
More information about the Baypiggies