# Newb question: using python builtins?

**URL:** <https://forums.plex.tv/t/newb-question-using-python-builtins/41197>\
**Category:** Dev/API Corner\
**Tags:** plugin-dev\
**Created:** [August 24, 2013, 6:46pm UTC](https://forums.plex.tv/t/newb-question-using-python-builtins/41197 "2013-08-24T18:46:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jourh](https://avatars.discourse-cdn.com/v4/letter/j/8c91f0/32.png) [@jourh](https://forums.plex.tv/u/jourh)\
**Post date:** [August 24, 2013, 6:46pm UTC](https://forums.plex.tv/t/newb-question-using-python-builtins/41197/1 "2013-08-24T18:46:58Z")

</div>

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. &nbsp;For instance, if I try to use hasattr, I get the following error:

&nbsp;

&nbsp;

NameError: global name 'hasattr' is not defined

&nbsp;

If I try to explicitly scope hasattr by doing \_\_builtin\_\_.hasattr(x, 'stuff') it tells me:

&nbsp;

SyntaxError: Line 55: "\_\_builtin\_\_" is an invalid variable name because it starts with "\_"

&nbsp;

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.&nbsp;

&nbsp;

Any thoughts?

&nbsp;

Thanks.

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![shopgirl284](https://avatars.discourse-cdn.com/v4/letter/s/f6c823/32.png) [@shopgirl284](https://forums.plex.tv/u/shopgirl284)\
**Post date:** [August 24, 2013, 8:12pm UTC](https://forums.plex.tv/t/newb-question-using-python-builtins/41197/2 "2013-08-24T20:12:41Z")

</div>

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.&nbsp; 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.

---

<div class="post-metadata">

**Author:** ![jourh](https://avatars.discourse-cdn.com/v4/letter/j/8c91f0/32.png) [@jourh](https://forums.plex.tv/u/jourh)\
**Post date:** [August 24, 2013, 11:25pm UTC](https://forums.plex.tv/t/newb-question-using-python-builtins/41197/3 "2013-08-24T23:25:00Z")

</div>

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

def MainMenu():

&nbsp; &nbsp; oc = ObjectContainer(view\_group='List')

**&nbsp; &nbsp; hasAddMethod = hasattr(oc, 'add')**

&nbsp; &nbsp; # ... and so on...

&nbsp;

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.

---

<div class="post-metadata">

**Author:** ![l\_b](https://avatars.discourse-cdn.com/v4/letter/l/ed8c4c/32.png) [@l\_b](https://forums.plex.tv/u/l_b)\
**Post date:** [August 25, 2013, 12:39am UTC](https://forums.plex.tv/t/newb-question-using-python-builtins/41197/4 "2013-08-25T00:39:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mikedm139](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/mikedm139/32/96909_2.png) [@mikedm139](https://forums.plex.tv/u/mikedm139)\
**Post date:** [August 25, 2013, 2:07am UTC](https://forums.plex.tv/t/newb-question-using-python-builtins/41197/5 "2013-08-25T02:07:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [December 20, 2019, 11:57pm UTC](https://forums.plex.tv/t/newb-question-using-python-builtins/41197/6 "2019-12-20T23:57:51Z")

</div>

Closed on December 20, 2019, 11:57pm UTC

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