When you import platform you are bringing in the standard library module named platform. Run this experiment:
import platform
print(platform)
The output will be something like:
<module 'platform' from 'C:\\Users\\ellio\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\platform.py'>
This will never be "android"
You could use try/except to log an error. You could then see a clear error in the log.
Somthing like:
try:
with open(filename) as f:
data = f.read()
...
except OSError as e:
Logger.exception(f'file read error in setting_read() {filename} {e}')
This would leave a useful message in the log.
If you change directories, or move to a new computer you could have a set or errors to fix.
A context manager in python handles enter and exit conditions automatically. Specifically for a file it automatically closes the file and cleanly handles closing the file if an exception occurs.
Splitting the read and write make the code more readable and maintainable. It makes it very easy to understand what is happening where the function is called.
The user_data_dir is a directory string that is created by kivy that puts user data in (generally) the right place for user data for each platform. Run this experiment on Windows and Android:
from kivy.lang import Builder
kv = """
Label:
text: app.user_data_dir
"""
class MyUserDatDirApp(App):
def build(self):
return Builder.load_string(kv)
def on_start(self):
print(f'{self.user_data_dir=}')
MyUserDatDirApp().run()
On my Windows machine I see: self.user_data_dir='C:\\Users\\ellio\\AppData\\Roaming\\myuserdatdir'
Here is a small pathlib example, relevant to your code:
from pathlib import Path
path = Path().cwd() / 'settings.txt'
print(path)
base_path = Path(__file__).parent
settings_path = base_path / 'settings.text'
print(base_path)
print(settings_path)