<https://forum.vectorworks.net/index.php?/topic/45379-global-variables-with-imported-functions/>
<http://schema.org/text>
"I like to deconstruct my larger more complicated scripts into smaller files.  It helps me stay organized.\n \n\n\n\tI'm trying to get imported functions to use global variables that I have created but, it's not working the way I like and I'm not sure why.\n \n\n\n\tI have a main script that defines the global variables.  The main script also imports demo.py and calls the function draw.\n \n\n\n\tThe demo.py script is basically an if/else test.  I've imported another file named shapes.py which has functions to draw shapes.\n \n\n\n\t-If the global variable 'w' is less than 6 call function myrectangle() from shapes.py\n \n\n\n\t-If the global variable 'w' is greater than 6 call function myoval() from shapes.py\n \n\n\n\t-if the global variable 'w' is equal to 6 print \"Hello World\" in a Alert Box.\n \n\n\n\tWhen i try to run i get: NameError: global name 'x' is not defined.  I thought that if I had global variables defined in the main script i would be able to use them in the imported functions.  Am I doing something wrong?\n \n\n\n\tmain.py\n \n\n\nimport vs\nimport demo\n\nw=vs.PLineLength\nh=vs.PBoxWidth\nx = 0\ny = 0\ny = y-h/2\n\ndemo.draw()\n\n\n\tdemo.py\n \n\n\nimport vs\nimport shapes\n\ndef draw():\n\n\tvs.PenSize(2);\n\n\tif w &lt; 6:\n\n\t\tshapes.myrectangle()\n\n\telif w &gt; 6:\n\n\t\tshapes.myoval()\n\n\telif w == 6:\n\n\t\tvs.AlrtDialog('Hello world.')\n\n\n\tshapes.py\n \n\n\nimport vs\n\ndef myrectangle():\n\n\tvs.Rect(x,y, x+w,y+h)\n\ndef myoval():\n\n\tvs.Oval(x,y, x+w,y+h)\n\n\n\t \n \n"
<https://forum.vectorworks.net/index.php?/topic/45379-global-variables-with-imported-functions/#comment-231565>