I'm trying to modify an existing Python script even though I'm very inexperience in Python.
The script is a __init__.py
file and is a Plex Plugin for a custom Agent.
The exiting relevant section of code looks like:
class CustomAgent(Agent.Movies):
def update(self, metadata, media, lang):
uri = "http://domain.tld/file?id=%s" % (urllib.quote(metadata.id))
data = JSON.ObjectFromURL(uri)
Instead of reaching out to a website I'm trying to have the agent open up a tsv file to get values for various fields.
class CustomAgent(Agent.Movies):
def update(self, metadata, media, lang):
with open("db.tsv", "r") as fp:
line = fp.readline()
while line:
...
My problem is I'm getting the "NameError: global name 'open' is not defined" error. At first I thought I didn't import something that I needed to import but couldn't find any relevant libraries(?).
Searching online suggests (if I'm interpreting it right) that it's because the script is shutting down before the relevant code gets executed. But I don't understand how to resolve the issue.
I think the issue might be because it's an __init__.py
file but I didn't choose the name, its what the Plex Plugin Framework has as the name and I don't think it's something I can change.
How can I open another file in Python?