By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,275 Members | 1,745 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,275 IT Pros & Developers. It's quick & easy.

NameError: x

P: 2
This problem is occurring in Jython:

Expand|Select|Wrap|Line Numbers
  1. File "<iostream>", line 0, in execute
  2. NameError: x
  3.  
Expand|Select|Wrap|Line Numbers
  1. class test(cycleevent):
  2.     x = 100
  3.     def execute(a, b):
  4.         global x
  5.         x -= 1
  6.         player.sendMessage("testing....")
  7.         if x == 0:
  8.             b.stop()
  9. def stop(a):
  10.     return
  11.  
Why is it throwing this? cycleevent being a Java abstract class.
Nov 11 '10 #1
Share this Question
Share on Google+
2 Replies


P: 2
Fixed it myself! Completely new to Python...
Nov 11 '10 #2

bvdet
Expert Mod 2.5K+
P: 2,851
The answer is in Python scoping rules. The global namespace for a function is always the module in which the function is defined. In your case you can directly access the variable with the dot operator: test.x -= 1
Nov 11 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.