# Use System variable in processing.py?

**URL:** <https://discourse.processing.org/t/use-system-variable-in-processing-py/20627>\
**Category:** Processing.py\
**Created:** [May 8, 2020, 12:49pm UTC](https://discourse.processing.org/t/use-system-variable-in-processing-py/20627 "2020-05-08T12:49:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![huahua](https://avatars.discourse-cdn.com/v4/letter/h/0ea827/32.png) [@huahua](https://discourse.processing.org/u/huahua)\
**Post date:** [May 8, 2020, 12:49pm UTC](https://discourse.processing.org/t/use-system-variable-in-processing-py/20627/1 "2020-05-08T12:49:06Z")

</div>

the codes in picture could be run successfully,but i am confused.  
i don’t know why i could’t use System variable directly in processing.py.  
i see the System variable could be used directly in java(processing).

help me.thank you very much!

 ![1](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/ae9941b28a9d49decf8ba1d9c5d95b74f49dab08.png)

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [May 8, 2020, 5:43pm UTC](https://discourse.processing.org/t/use-system-variable-in-processing-py/20627/2 "2020-05-08T17:43:21Z")

</div>

> [@huahua](#):
>
> I see the “System Variables” could be used directly in Java (Processing).

- “System Variables” is merely a Processing’s “sugar” term.
- Instead their actual nature is Java `class` instance fields.
- That is, _width_, _height_, _mouseX_, _sketchPath_, etc. are simply fields from `class` PApplet:  
[PApplet](http://Processing.GitHub.io/processing-javadocs/core/processing/core/PApplet.html#width)
- When we assign a value to a variable outside a `def` we create a `global` variable:  
[Globals \ Language (API)](http://Py.Processing.org/reference/globals.html)
- If that variable happens to have the same name as a PApplet member, we end up overshadowing its corresponding ` __builtin__ ` property.
- Once a PApplet member is overshadowed by a Python variable w/ the same name, we can still access the former via `this` or ` __builtin__ ` as a workaround:

```auto
width = 640 # global width overshadows __builtin__.width
print width, this.width # 640, 100

def setup():
    size(800, 600)
    print width, this.width, __builtin__.width # 640, 800, 800
    exit()

```

- Anyways, regardless the Processing flavor we’re coding on, it just makes sense to access _width_ & _height_ after **size()** has been invoked:  
[size() \ Language (API)](http://Py.Processing.org/reference/size.html)

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [May 9, 2020, 11:26pm UTC](https://discourse.processing.org/t/use-system-variable-in-processing-py/20627/3 "2020-05-09T23:26:48Z")

</div>

> [@GoToLoop](#):
>
> regardless the Processing flavor we’re coding on, it just makes sense to access _width_ & _height_ after **size()** has been invoked

This is key. Don’t declare this globally. They exist globally already, and they are defined by `size()` in `setup()`. Call size, then use them.

---

<div class="post-metadata">

**Author:** ![huahua](https://avatars.discourse-cdn.com/v4/letter/h/0ea827/32.png) [@huahua](https://discourse.processing.org/u/huahua)\
**Post date:** [May 10, 2020, 5:28am UTC](https://discourse.processing.org/t/use-system-variable-in-processing-py/20627/4 "2020-05-10T05:28:10Z")

</div>

Your words are clear，i understand now.  
You are so nice.  
Thank you very very very much.

---

<div class="post-metadata">

**Author:** ![huahua](https://avatars.discourse-cdn.com/v4/letter/h/0ea827/32.png) [@huahua](https://discourse.processing.org/u/huahua)\
**Post date:** [May 10, 2020, 5:29am UTC](https://discourse.processing.org/t/use-system-variable-in-processing-py/20627/5 "2020-05-10T05:29:47Z")

</div>

Thank you very much.
