[Tutor] 2 functions- are they state machines?
Kirk Bailey
idiot1 at netzero.net
Wed Aug 6 22:26:49 EDT 2003
These attack a subset of the task.
# This one turns wikiwords into http links
def createwikilinks(line): # is this a state machine?
line=string.split(line)
index=0
for word in line:
if wikiname(word): # ware wordwrap!
word='<a \
href=http://www.'+domainname+'/cgi-bin/wikinehesa.py/'+\
word+'">'+word+'</a>'
line[index]=word
index=index+1
line-string.join(line)
return line
# this one determines if a word is a wikiword.
def iswikiname(word): # is this a state machine?
transitions=0 # counts transitions
prior=0 # maintains priorletterstate
caps='ABCDEFGHIJKLMNOPQRSTUVWXYZ' # defines capital letter.
for letter in word: # check each letter 4 capitals
if letter in caps: # if this letter is a cap;
if prior==0: # if the last was not a cap,
prior=1 # note a cap was just processed
else: # if the last was a cap,
pass # noop prior already set
else: # if the current letter is not a cap;
if prior==1: # if the last one was a cap;
transitions=transitions+1 # a transition
prior=0 # note this letter was not a cap
else: # but if not...
pass # shine it on...
if transitions>1: # 2+ is a wikiword
return 1 # return a logical YES
else: #
return 0 # return a logical NO
--
end
Cheers!
Kirk D Bailey
+ think +
http://www.howlermonkey.net +-----+ http://www.tinylist.org
http://www.listville.net | BOX | http://www.sacredelectron.org
Thou art free"-ERIS +-----+ 'Got a light?'-Promethieus
+ think +
Fnord.
More information about the Tutor
mailing list