python - Works in shell but not as a program? -
i tried following in shell
infile = open("studentinfo.txt", "r") infile.read()
and returned text in file, want do. however, when wrote , saved program
def main(): infile = open("studentinfo.txt", "r") infile.read() main()
it returned blank lines.
your function never returns values, discarded again.
add return
statement:
def main(): infile = open("studentinfo.txt", "r") return infile.read()
also, in interactive interpreter, expression results echoed automatically unless result none
. in regular scripts, you'll have print results explicitly:
print(main())
Comments
Post a Comment