r/learnpython • u/hanjokazooie • 4d ago
Trying to import a file into Thonny
Trying to import a rom file to convert to bytes and then mod, but the game title has "of" in it, so it returns as a syntax error. I guess the IDE thinks I'm trying to write an if statement? Anyway, google wasn't helpful, so i came here.
Code below
import Breath of Fire II (USA) - Copy.sfc
2
Upvotes
5
u/D3str0yTh1ngs 4d ago
I will just start of by telling you that a binary file is not a python file and so using
importon it makes no sense. Do something like this to read in the file:contentsis thrus a variable containing the bytes of the file1
u/hanjokazooie 4d ago
edit: What's a subreddit thats beginner friendly for future questions
1
u/Ender_Locke 4d ago
also you can’t have spaces like that. that’s like programming and file directories 101
2
u/argh1989 4d ago
Import is for modules, not files.
2
u/DHTechdev 4d ago
The short version is that import wants a module name, not a file path. Python reads "import Breath of Fire II" as "import Breath" followed by stray words, so it chokes at "of". "if XYZ is ABC" works because if has its own grammar that accepts any expression after it. For the rom, open it with open(path, "rb") and read the bytes like the earlier reply showed.