By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,089 Members | 2,359 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,089 IT Pros & Developers. It's quick & easy.

Tip of the day generator.

P: n/a
Hey i was wondering if any one would know if there was a way to have
python randomly read form a file or would you ahve to know the byte
postion and somehow randomize splicing the file so the sentence you
want show's up.

i.e have a file with a lot of tips and useless facts and then have
python randomly read one sentence when the code is run and print at
any time you would want it to.
Nov 28 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Joseph king wrote:
Hey i was wondering if any one would know if there was a way to have
python randomly read form a file or would you ahve to know the byte
postion and somehow randomize splicing the file so the sentence you
want show's up.

i.e have a file with a lot of tips and useless facts and then have
python randomly read one sentence when the code is run and print at
any time you would want it to.
import random
print random.choice(open("quotes").readlines())

Diez
Nov 28 '07 #2

P: n/a
On 2007-11-28, Neil Cerutti <ho*****@yahoo.comwrote:
import textwrap
import random
import os

print "Sigswap v0.4"
[...]
Yikes!

That program was in dire need of Pythonification. It must have
been written early in my Pythonology.

--
Neil Cerutti
Nov 28 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.