I don't understand why something this simple isn't very intuitive.
This is what I have so far:
print("Enter name of file on Desktop:")
filename = sys.stdin.readline()
directory = os.path.join(os.path.expanduser("~"),"Desktop")
for subdir, dirs, files in os.walk(directory):
for file in files:
if file.startswith(filename):
f = open(os.path.join(subdir, file),'r+', encoding="Latin-1")
data = f.read()
print(data)
f.close()
Why can't I pass the sys.stdin that was assigned to the variable filename to the 'if' statement:
`if file.startswith(filename):`?
I tried:
if file.startswith(str(filename)):
if file.startswith("'" + filename + "'")
if file.startswith(filename):
no options seem to "go through" and no errors pop up.
It just pretends like I didn't pass anything. Any help? Thanks.