It's obvious I'm doing something wrong, but I can't find help online as to why. I want to create an if function that prints out that the inputted file contains no data. When I run this and request an empty.txt file, it skips straight to the else: and I get
Enter name of file: empty.txt
In the terminal, instead of the printed result, I'm asking for.
# Ask user to input file, open and and read file
userinput = input('Enter name of file: ')
userfile = open(userinput)
data = userfile.read()
#if file is empty print "x contains no data"
if data is None:
print(userinput + ' contains no data.')
else:
print(data)
userfile.close()