对于以下Python 2.7代码:
#!/usr/bin/python
def funcA():
print "funcA"
c = 0
def funcB():
c += 3
print "funcB", c
def funcC():
print "funcC", c
print "c", c
funcB()
c += 2
funcC()
c += 2
funcB()
c += 2
funcC()
print "end"
funcA()
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
File "./a.py", line 9, in funcB
c += 3
UnboundLocalError: local variable 'c' referenced before assignment
Run Code Online (Sandbox Code Playgroud)
但是,当我注释掉该行c += 3中funcB,我得到以下的输出:
funcA
c 0
funcB 0
funcC 2
funcB 4
funcC 6
end
Run Code Online (Sandbox Code Playgroud)
c在 …
def myFunc( a, b ):
def innerFunc( c ):
print c
innerFunc( 2 )
print a, b
Run Code Online (Sandbox Code Playgroud)
如何直接访问内部函数?我想要格式化该函数的对象/地址
<function innerFunc at 0xa0d5fb4>
Run Code Online (Sandbox Code Playgroud)
我尝试使用myFunc._ getattr _('innerFunc'),但这不起作用.
我正在使用Linux 2.6.38(fc14).什么是ioctl标志来获取套接字文件描述符(例如,TCP套接字)上的可用空间量?我发现NetBSD有FIONREAD,FIONWRITE和FIONSPACE用于此类相关目的.但是,我只能在Linux中使用FIONREAD.