#🔒 Python says file isn't readable despite the file being readable

33 messages · Page 1 of 1 (latest)

still belfry
#

I have tried stack overflow and w3 schools to sort this out. i have declarations above this code to create the files needed if they don't already exist and this works just fine. I get this error whenever I try to read the file, what's happening?

outer lightBOT
#

@still belfry

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

still belfry
#

Error:

Traceback (most recent call last):
File "c:\Users\***\OneDrive\Documents\python project 2025\Summer Programming Assignment 2025.py", line 91, in <module>
list_check()
File "c:\Users\
***\OneDrive\Documents\python project 2025\Summer Programming Assignment 2025.py", line 30, in list_check
print(g.read())
^^^^^^^^
io.UnsupportedOperation: not readable

manic willow
#

I'm not an expert or anything but try removing the +

still belfry
#

Code:

from datetime import datetime # allows additional metadata for user entries in all categories
import time # might need it. loading screens are cool if nothing else!

u = open("userdata.txt", "w") # user information for a personalised experience
f = open("food.txt", "w") # attempting to create save data per category for later checks.
g = open("transport.txt", "w")
j = open("utilities.txt", "w")
k = open("entertainment.txt", "w")
l = open("misc.txt", "w") # note to self: create option to clear save files

now = datetime.now()
current_time = now.strftime("%D/%M/%Y %H:%M:%S")
n = 0
category_check = False
running = True

def list_check():
print("1) Food\n 2) Transport\n 3) Utilities\n 4) Entertainment\n 5) Miscellaneous/Other")
while category_check == False:
checkcategory = int(input("Which category would you like to check?: "))
if checkcategory >= 6 or checkcategory <= 0:
time.sleep(1)
print("Please enter a valid number")
else:
if checkcategory == 1:
with open('food.txt', 'r+') as file:
print(f.read())
elif checkcategory == 2:
with open('transport.txt', 'r+') as file:
print(g.read())
elif checkcategory == 3:
with open('utilities.txt', 'r+') as file:
print(j.read())
elif checkcategory == 4:
with open('entertainment.txt', 'r+') as file:
print(k.read())
else:
with open('misc.txt', 'r+') as file:
print(l.read())

still belfry
#

i've tried read-only, append and read, write and read, etc

manic willow
#

Is it in the same directory/does the program have permission to read it?

#

Hmm

#

Maybe instead of g put file

manic willow
still belfry
#

there wasnt anything there

#

i'll try it again real quick now that ive made the files

manic willow
#

Does transport.txt exist?

#

Kk

still belfry
#

nothing

manic willow
#

Hmm

manic willow
still belfry
#

possibly

#

its not writing to the file either

#

ive just done a test entry and nothing

manic willow
still belfry
#

lemme try

#

ok so its not giving me an error message

manic willow
#

That's good

still belfry
#

but now its just asking the prompt over and over again

#

i probably just need to write an exit method

manic willow
#

Yeah probably

still belfry
#

ok now its not reading the file at all

#

like it just skips that step

outer lightBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.