python - How can I check that a text file has at least 1 character -
i have text file how can check in python text file has @ least 1 number or alphabetic character , not white spaces.
here did. read file putting data string data
. used data.strip()
remove leading , trailing whitespace. checked see if there left data.strip()
. if there have characters in file, if not file has whitespace or empty.
with open("filename.txt", "r") file: data = file.read() if data.strip(): print("empty") else: print("full")
Comments
Post a Comment