hi~~~

Steve Holden sholden at holdenweb.com
Mon Aug 19 22:55:25 CEST 2002


"d2002xx" <d2002xx at myrealbox.com> wrote ...
> > try this one :
> >
> > # file useless_msg.py
> > def useless_msg():
> >      print 'hi, I'm learning Python !'
> >
> > def main():
> >      while(1)
> >          useless_msg()
> >
> > if __name__ == '__main__':
> >      main()
> >
> >
> > $ python useless_msg.py
>
> Add a little complexity:
>
> #############################
> # file useless_msg2.py
> def generate_useless_msg():
>     while True:
>         yield "hi, I'm learning Python !"
>
> def main():
>     msg_list = generate_useless_msg()
>     for msg in msg_list:
>         print msg
>
> if __name__ == '__main__':
>     main()
> #############################
>
> Hmmm... You need python 2.3 to run this...
>
> Enjoy!
Thinking about your code, I somehow find naming factory functions with a
noun to "make more sense", since the code can then tell you more reliably
what you are using. Methods would normally be verbs (do this, do that,
transmogrify). I suppose factory methods would be VerbObjects (or, depending
on the cap style you prefer, verbObjects), so you could tell a
GeneratorGenerator to generateStringGenerator() or createAccountRecord.  So
I'd probably write...

#############################
# file useless_msg3.py
def useless_msg_generator():
    while True:
        yield "hi, I'm learning Python !"

def main():
    msg_list = useless_msg_generator()
    for msg in msg_list:
        print msg

if __name__ == '__main__':
    main()
#############################

Of course, this is probably s stylistic matter. If so then the bicycle shed
principle dictates that this will be a long thread. Personally I think we
can let it die, like my old .sig ;-)

regards

PS: For a second there I though your email address was ... at mycerealbox.com
;-)
-----------------------------------------------------------------------
Steve Holden                                  http://www.holdenweb.com/
Python Web Programming                        pydish.holdenweb.com/pwp/
Previous .sig file retired to                    www.homeforoldsigs.com
-----------------------------------------------------------------------






More information about the Python-list mailing list