python - Reading lines from a text file into a variable -
i've got text file on desktop, lines.txt
:
lines stuff stuff lines lines boats boats lines
and i'm trying read variable, every time print it, empty list. here's code:
class="snippet-code-html lang-html prettyprint-override">inf = 'c:/users/me/desktop/text.txt' def repeatwords(inf): import string infile = open(inf, 'r') text = infile.readlines() infile.close() print(text) repeatwords(inf)
when print(text)
, empty list. doing wrong?
there lot of problems code. have no thought phone call print(text)
, needs after assigned to. here's corrected version:
def repeat_words(in_f, out_f): open(in_f, 'r') infile: text = infile.readlines() print(text)
python python-3.x
No comments:
Post a Comment