[Tutor] =?iso-8859-1
?Q?Reading=20and=20Writing=20=28No=20Arithme
t ic=3F=29?=
dman
dsh8290@rit.edu
Fri, 18 Jan 2002 22:54:15 -0500
On Fri, Jan 18, 2002 at 07:33:24PM -0500, tbrauch@tbrauch.com wrote:
| I am trying to write a quick little program to help me with a menial task...
| Isn't that the whole purpose of programming? I have a small html, let's
| call it info.html (because that is its name) file that consists of something
| like:
|
| <HTML><BODY>Some Inspirational Quote Here</Body><HTML>
|
| I also have a data file called info.data chock full o' inspirational quotes,
| one per line (they also might have some additional HTML such as links).
| What I am trying to do is find the best why to pull a line at random and
| insert it into the info.html file. What works with only a few lines in
| the data file is:
Here's what I did for my sigs :
~~~~~~~~~~~~~~~~~~~~~~
#!/usr/bin/env python
# docstring
"""
When executed it chooses a quote randomly and prints it on stdout. It
is quite useful for sig generation.
"""
quote_list = [
"""
But As for me and my household, we will serve the Lord.
Joshua 24:15
""",
"""
Thy Word is a lamp unto my feet
and a light unto my path.
Psalms 119:105
""",
"""
Python is executable pseudocode. Perl is executable line noise.
""",
<the rest are snipped for this post, you're welcome to them if you
mail me privately>
]
import random
# the signature; "%s" will be replaced by the qoute
sig = """\
%s\
"""
print ( sig % random.choice( quote_list ) )
~~~~~~~~~~~~~~~~~~~~~~
Pretty simple (about 3 lines, really) and no file IO to deal with.
The data is just some string literals in a list.
-D
--
If your life is a hard drive,
Christ can be your backup.