pythonic andragogy...
Below is a transcript of my first Python training session with a friend from Jordan, Arabic speaking but completely fluent in English (knows QWERTY touch type better). She has PhD and previous programming experience in a much earlier job, so this is hardly a high school student. And yet I start my introduction in much the same way, using my "objects first" approach (not unlike AlgebraFirst in some math circles). As I was writing to a prominent Python teacher the other day: """ In an "objects first" mindset, we run like hell from the CS1/CS2 tendency to look at objects as "2nd year advance topic" i.e. we'll gradually slog through data structures, procedural programming, flow of control, conditions, types, type coercion... and then spring "objects" on ya as a Grand Unified Theory (like now we're ready for Einstein level Python). No, no and no. The OO revolution was about making programming easier *from the top* i.e. we're taking everyday commonsense about "things with attributes and behaviors" and expressing those directly. So you need to *start* by explaining what Python being an object oriented language means, by starting with very simple Foo and Bar classes, or better Biotum, Dog, Monkey, then subclass as mammal. This counts as a preview or trailer (to a film), enrolls the student in the idea that (a) hey, I'm learning what OO means at last and (b) hey, thinking this way is really natural after a bit. Because once we've done the work to show a user defined type, then we have the concept of type (type of object). That then anchors the whole discussion of native or __builtin__ types e.g. now that you've seen a Biotum, a Python (everything is a python in python), it's really natural to see List type, Vector type (non-native), Integer type as "just more creatures with __ribs__." """ We switched the keyboard back and forth. Like when she tries to feed the snake both a carrot and some beer, that crashes because the args don't match, but even though I warned her, she wanted to see the error message anyway. Our venue with Powell's Technical, Personal Telco node for Wifi: http://www.personaltelco.net/ http://www.powells.com/technicalbooks We also talked a lot about micro-lending to women i.e. would there be any overlap between Python skills and a small business managed by women? I'll have more about that aspect in my blogs. I need to connect her to Idealist.org -- maybe through PPUG, where several from that organization have leadership roles. Transcript follows: Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information.
class Snake: def __init__(self, name): self.me = name
kirby_snake = Snake("Kirby Urner") kirby_snake.me 'Kirby Urner' 2 ** 10000 19950631168807583848837421626835850838234968318861924548520089498529438830221946631919961684036194597899331129423209124271556491349413781117593785932096323957855730046793794526765246551266059895520550086918193311542508608460618104685509074866089624888090489894838009253941633257850621568309473902556912388065225096643874441046759871626985453222868538161694315775629640762836880760732228535091641476183956381458969463899410840960536267821064621427333394036525565649530603142680234969400335934316651459297773279665775606172582031407994198179607378245683762280037302885487251900834464581454650557929601414833921615734588139257095379769119277800826957735674444123062018757836325502728323789270710373802866393031428133241401624195671690574061419654342324638801248856147305207431992259611796250130992860241708340807605932320161268492288496255841312844061536738951487114256315111089745514203313820202931640957596464756010405845841566072044962867016515061920631004186422275908670900574606417856951911456055068251250406007519842261898059237118054444788072906395242548339221982707404473162376760846613033778706039803413197133493654622700563169937455508241780972810983291314403571877524768509857276937926433221599399876886660808368837838027643282775172273657572744784112294389733810861607423253291974813120197604178281965697475898164531258434135959862784130128185406283476649088690521047580882615823961985770122407044330583075869039319604603404973156583208672105913300903752823415539745394397715257455290510212310947321610753474825740775273986348298498340756937955646638621874569499279016572103701364433135817214311791398222983845847334440270964182851005072927748364550578634501100852987812389473928699540834346158807043959118985815145779177143619698728131459483783202081474982171858011389071228250905826817436220577475921417653715687725614904582904992461028630081535583308130101987675856234343538955409175623400844887526162643568648833519463720377293240094456246923254350400678027273837755376406726898636241037491410966718557050759098100246789880178271925953381282421954028302759408448955014676668389697996886241636313376393903373455801407636741877711055384225739499110186468219696581651485130494222369947714763069155468217682876200362777257723781365331611196811280792669481887201298643660768551639860534602297871557517947385246369446923087894265948217008051120322365496288169035739121368338393591756418733850510970271613915439590991598154654417336311656936031122249937969999226781732358023111862644575299135758175008199839236284615249881088960232244362173771618086357015468484058622329792853875623486556440536962622018963571028812361567512543338303270029097668650568557157505516727518899194129711337690149916181315171544007728650573189557450920330185304847113818315407324053319038462084036421763703911550639789000742853672196280903477974533320468368795868580237952218629120080742819551317948157624448298518461509704888027274721574688131594750409732115080498190455803416826949787141316063210686391511681774304792596709376
class Snake: def __init__(self, name): self.me = name self.stomach = [] def eat(self, food): self.stomach.append(food) def __repr__(self): return "Snake(%s)" %
SyntaxError: invalid syntax (<pyshell#16>, line 8)
class Snake: def __init__(self, name): self.me = name self.stomach = [] def eat(self, food): self.stomach.append(food) def __repr__(self): return "Snake(%s)" % self.me
tag = Snake("Dr. Tag") tag Snake(Dr. Tag) snake2 = Snake("Kirby") snake2 Snake(Kirby) snake2.eat("beer") snake2.stomach ['beer'] snake2.eat("carrot") snake2.stomach ['beer', 'carrot'] tag.stomach [] tag.eat("carrot","beer") Traceback (most recent call last): File "<pyshell#28>", line 1, in <module> tag.eat("carrot","beer") TypeError: eat() takes exactly 2 positional arguments (3 given) a = [] a [] a.append(2) a [2] a.append(8) a [2, 8] a.append("the wonderful food of the day") a [2, 8, 'the wonderful food of the day'] a.pop(0) 2 a [8, 'the wonderful food of the day'] tag.stomach [] tag.eat("carrot") tag.eat("beer") tag.stomach ['carrot', 'beer'] tag.stomach("hummus") Traceback (most recent call last): File "<pyshell#43>", line 1, in <module> tag.stomach("hummus") TypeError: 'list' object is not callable tag.eat("hummus") tag.stomach ['carrot', 'beer', 'hummus'] snake2.stomach ['beer', 'carrot'] class Snake: def __init__(self, name): self.me = name self.stomach = [] def eat(self, food): self.stomach.append(food) def poop(self): if len(self.stomach) > 0: return self.stomach.pop(0) def __repr__(self): return "Snake(%s)" % self.me
newsnake = Snake("Kirby") newsnake.stomach [] newsnake.poop() newsnake.eat("something yummy") newsnake.stomach ['something yummy'] newsnake.poop() 'something yummy' newsnake.stomach []
"""
Note that I didn't get into my uroboros thing with the self-eating Python, per Vilnius slides (EuroPython 2007). Kirby
participants (1)
-
kirby urner