[python] polednice v pythonu
Martin Hassman
martin.hassman na vscht.cz
Pondělí Květen 12 08:24:15 CEST 2003
Zdravim,
predem se omlouvam za spamming (pokud to tak nekdo nazve :-),
ale snad by to nekoho mohlo pobavit.
Tak jsem po trapeni s pythonem a thready mel o vikendy nejakou inspirujici naladu a
preportoval jsem Polednici do pythonu. Jak se to povedlo ci nepovedlo posudte sami.
Jen schovivavost - ta anglictina neni dokonala a ani pres dukladne ladeni modulu
nevylucuji, ze tam neni nejaky bug ;-)
Kdyby se to nejak pres mail spatne zalomovalo, ci problemy s cestinou apod., tak jsem to
vystavil pod sebou
http://www.py.cz/Members/met/midday_witch.py (v utf-8)
#!/usr/bin/env python
# Porting of Czech poetry to Python
# Module: [midday_witch.py] (Polednice)
# Original module author: K. J. Erben
# Author of ported module: Martin Hassman
#
# 'U lavice dítě stálo,
# z plna hrdla křičelo.'
room = [bank, child, table, mother]
child.cry()
try:
child.stop_cry()
except IgnoreMotherError:
mother.echo("Bodejž bys jen trochu málo ty cikáně mlčelo!")
# 'Poledne v tom okamžení, táta přijde z roboty...'
from time import *
if localtime(time())[3:5] == (12, 0): # noon
room.append(father) # but this does not happen yet ;-)
# 'Mlč! Hle husar, kočárek -
# hrej si! - tu máš kohouta!'
room[2:2] = [hussar, buggy, cock]
# look at the actual situation: [bank, child, hussar, buggy, cock, table, mother]
# 'Než kohout, vůz i husárek
# bouch, bác! letí do kouta.'
fly = room[2:5]
del room[2:5]
room.append(fly)
del fly
# [bank, child, table, mother, [hussar, buggy, cock]]
child.cry()
# 'Pojď si proň ty Polednice...'
mother.echo("Midday Witch, where are you? Come in for my bad son!")
room.append(midday_witch)
# [bank, child, table, mother, [hussar, buggy, cock], midday_witch]
# simple description of the new object
# 'Malá, hnědá, hnáty křivé
# pod plachetkou osoba'
for k in midday_witch.keys:
print k, "=", midday_witch[k]
# this prints:
# height = small
# color = brown
# hands = bowed
# 'Dej sem dítě!'
midday_witch.echo("Give me the child!")
# simple objects relocation: mother runs to the child
# and sit with him on the bank
escape = [room[0], room[3], room[1]]
del room[3]
del room[0:2]
room[0:0] = [escape]
del escape
del child # mother trying to save his child deletes global reference to it,
# so the last reference to the child is in safe place - room[0],
# but this induce a critical problem later
# [ [bank, mother, child], table, [hussar, buggy, cock], midday_witch]
# 'Polednice blíž se plíží,
# blíž - a již je v zápětí.'
while room.index(midday_witch) > 1:
witch_position = room.index(midday_witch)
step = room[witch_position]
del room[witch_position]
room[witch_position - 1 : witch_position - 1] = [step]
del step
sleep(30) # midday_witch is moving a little bit slowly
# [ [bank, mother, child], midday_witch, table, [hussar, buggy, cock]]
# 'Již vztahuje po něm ruku'
try:
midday_witch["children"].append(room[0][2]) # this raises an exception
del room[0][2]
except StrongMotherError:
# 'Matka tisknouc ramena'
# 'klesá smyslů znavena'
fall = room[0][1:]
del room[0][1:]
room[1:1] = fall[0] # <-- here is a bad mother mistake
del fall # reference to the child lost, child died
# Sorry, but here is a piece of 'closed source' code :-(,
# we do not know exactly what happened until:
# 'Táta vchází do dveří.'
room.append(father)
# 'Ve mdlobách tu matka leží'
# look at the actual situation: [bank, mother, table, [hussar, buggy, cock], father]
try:
room.index(child) # father try to find his child
# but this gives only Exception
except ChildNotHereError:
import gc # child is not here, father searches the garbage collection
try:
gc.garbage.index(child)
except VeryBadError: # no child is not here :-(
father["sad"] = 1
print "That's all folks"
--
Martin Hassman
Institute of Chemical Technology in Prague
Department of Biochemistry and Microbiology
Jaky Internetovy prohlizec pouzivat? Zkuste Mozillu http://czilla.cz
Jabber: hassmanm na njs.netlab.cz, ICQ: #295399122
Další informace o konferenci Python