I got a text file and saved it in python25 (a folder) as .txt. I need to import this file and I am getting syntax error that file is not defined. I am a complete biology novice to defining and importing files. Please help!

Recommended Answers

All 2 Replies

If the file has Python code, then it should end with a ".py" not ".txt". If it is not a Python file, but a file with text you want to read in the program then you open the file and read it. See #6 here for how to open and read a file http://www.daniweb.com/forums/thread20774.html

If you dont read the link;

yourfile = open('yourfilename.txt','r')
# r stands for read
yourtext = yourfile.readlines()
print yourtext
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.