r/learnpython • • 14m 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

1 Upvotes

6 comments sorted by

•

u/D3str0yTh1ngs 9m ago

I will just start of by telling you that a binary file is not a python file and so using import on it makes no sense. Do something like this to read in the file:

with open("Breath of Fire II (USA) - Copy.sfc", "rb") as f:
    contents = f.read()

contents is thrus a variable containing the bytes of the file

•

u/hanjokazooie 7m ago

thank you!

•

u/Ender_Locke 4m ago

also you can’t have spaces like that. that’s like programming and file directories 101

•

u/hanjokazooie 3m ago

Makes sense, I am 101 right now

•

u/hanjokazooie 0m ago

Although this doesn't make sense to me, because its not a string. Why does open need to be "importBreathofFireII" as compared to something like "if XYZ is ABC" /genquestion

•

u/argh1989 12m ago

Import is for modules, not files.