Skip to content

Instantly share code, notes, and snippets.

@paomian
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save paomian/89aa78d1192f4327270a to your computer and use it in GitHub Desktop.

Select an option

Save paomian/89aa78d1192f4327270a to your computer and use it in GitHub Desktop.
queue = Queue
class A():
def __init__(queue): #传入一个'queue'的字符串
exec('global %s' % queue)
self.queue = queue
@overminder
Copy link

你如果只是想要读写全局变量的话,可以用 globals() 这个 dict:

self.queue = globals()[queue_name]

@paomian
Copy link
Author

paomian commented Sep 26, 2014

@overminder 啊啊啊,我也找到那个了,不敢确定。这个是全局变量表

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment