[Tutor] readline
Mike McTernan
livingmike at gmail.com
Wed Jul 31 22:12:50 CEST 2013
I am having problems with the readline command in Python 2.7.
I have a text file that has 12 lines of text, each line represents a
response to a variable called star_sign that is collected via
raw_input.
However, instead of printing the line 5 it prints the first 5 letters on line 1.
Here is the program:
from sys import argv
script, zodiac = argv
prediction = open(zodiac, "r")
prompt = "> "
def welcome():
print "Welcome to your daily horoscope"
horoscope()
def horoscope():
print "I can predict your future"
print "What is your starsign?"
star_sign = raw_input(prompt)
if "Leo" in star_sign:
print prediction.readline(5)
else:
print "You gonna die"
welcome()
More information about the Tutor
mailing list