if __name__ == '__main__':
filename = open('sevi.txt', 'wb')
content = filename.write("Cats are smarter than dogs")
for line in content.read():
match = re.findall('[A-Z]+', line)
print match
filename.close()
I am new to python. I am just opening a file and writing some text into it. Later reading the content find all the characters in it by using regular expression. but I am getting the error as 'NoneType' object has no attribute 'read'. if I use readlines also, I am getting the error.
filename.write()returnsNonein Python 2. Did you mean to usefilename.read()instead? You'll need to open the file inw+mode to be able to do that though.openfunction takes a file name string and returns a file object, so calling that file objectfilenameis somewhat confusing.