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

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -