String handling and the percent operator
Anthra Norell
anthra.norell at tiscalinet.ch
Fri Jul 14 04:23:52 EDT 2006
----- Original Message -----
From: "Tom Plunket" <gamedev at fancy.org>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Friday, July 14, 2006 12:49 AM
Subject: String handling and the percent operator
> I have some code to autogenerate some boilerplate code so that I don't
> need to do the tedious setup stuff when I want to create a new module.
>
> So, my script prompts the user for the module name, then opens two
> files and those files each get the contents of one of these functions:
>
etc.
Tom
Might this be an idea? Put symbolic names into your templates, as many
as you want and replace them with the real names:
boilerplate = """
# Module MODULE
# DATE
# SUMMARY
class CLASS
pass
if __name__ == '__main__':
import unittest
unittest.main('CLASS_t')
"""
names = '''
MODULE=Corner_Cutter
"DATE=%s"
"SUMMARY=Fast stuff"
CLASS=Sharpener
''' % time.ctime ()
import SE
Stream_Editor = SE.SE (names)
print Stream_Editor (boilerplate)
# Module Corner_Cutter
# Fri Jul 14 10:16:53 2006
# Fast stuff
class Sharpener
pass
if __name__ == '__main__':
import unittest
unittest.main('Sharpener_t')
Will also do files:
Stream_Editor ('boilerplates/module_template', 'projects/%s.py' %
Stream_Editor ('MODULE'))
'projects/Corner_Cutter.py'
You'd have to download SE from the Cheese Shop. I managed to upload at least
the description, but people tell me that the program isn't there. So while I
struggle with the upload (assistance welcome) I send out SE by individual
request. If you want to try it, just tell me.
Cheers
Frederic
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060714/682ed371/attachment.html>
More information about the Python-list
mailing list