如何访问我的args,列出 man
中的数据类型# test1.py #!/usr/bin/env python def main(): print 'main function' one() def one(): print 'one function' my_args = ["QA-65"] def two(): print 'two function' if __name__ == "__main__": main() getattr(my_args, pop)
答案 0 :(得分:3)
如果return
来自one()
,您可以{/ 1}}。
#!/usr/bin/env python
def main():
print 'main function'
args = one() # returns my_args, which i'm assigning to args
print 'i got args from one():', args
print args.pop()
def one():
print 'one function'
my_args = ["QA-65"]
return my_args
def two():
print 'two function'
if __name__ == "__main__":
main()
#getattr(my_args, pop)
# ^^^ Moved this up to main() ^^^
输出:
main function
one function
i got args from one(): ['QA-65']
QA-65
答案 1 :(得分:0)
你可以使用global
执行此操作。
#!/usr/bin/env python
def main():
print 'main function'
one()
def one():
print 'one function'
global my_args
my_args = ["QA-65"]
def two():
print 'two function'
if __name__ == "__main__":
main()
print my_args.pop()
仅仅因为你 可以 并不意味着你应该这样做!