Newb question: using python builtins?

I'm a newbie at developing plex channels but wanted to hack on some stuff... I'm having some really basic problems using python builtin functions.  For instance, if I try to use hasattr, I get the following error:

 

 

NameError: global name 'hasattr' is not defined
 
If I try to explicitly scope hasattr by doing __builtin__.hasattr(x, 'stuff') it tells me:
 
SyntaxError: Line 55: "__builtin__" is an invalid variable name because it starts with "_"
 
I get a similar error message if I try to import * from __builtin__. I am kind of at a loss. I must be missing something here. 
 
Any thoughts?
 
Thanks.

 

 

I have never used hasattr or others for objects, but I have used some of the ones for strings like len(), str(), int() etc. So I am not sure if its use of objects makes it different.

But it could be that it is just an issue with the syntax of your code and how you are calling it that is causing it not to be recognized.  If you post the snippet of the code where you have use it and got errors, these guys may be able to see if that is the issue.

I've been tinkering with the Apple Movie Trailers channel. Just adding a line like:

def MainMenu():
    oc = ObjectContainer(view_group='List')
    hasAddMethod = hasattr(oc, 'add')
    # ... and so on...
 
Will cause it to barf and die... It seems like there's some scoping issue or something, but being neither a Plex guru, nor a Python guru, I'm sorta flailing in the dark.

If you do something like object.__class__ it also throws an exception. I don't know why this is. I think Plex only allows a subset of Python. For example, open() also isn't supported.

The Plex plugin framework uses a “restricted” python which does not include some of the standard built-ins. For most basic built-in functions that are not available, there are Framework substitutes. I don’t know off the top if my head what the substitute for hasattr would be.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.