python 函数中类的作用域

我想要输出x的值,但在函数test2()中不做为参数传入类Foo中,这个怎么处理呢。我把x=1放在模块的作用域中就不报错。程序如下:

 class Foo(object):
    def test(self):
        print x

def test2():
    x=1
    foo = Foo()
    foo.test()

if __name__ == "__main__":
    test2()

x=1定义在方法外面

那个值应该是设为一个范围的吧,例如这样:
begin
for i in 1..10 loop
insert into t1 values ('A');
end loop;
commit;
end

你需要要用全局变量。不然local变量没法找到