小编crk*_*crk的帖子

从父函数赋值给变量:"赋值前引用的局部变量"

对于以下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在 …

python

32
推荐指数
2
解决办法
4万
查看次数

访问函数的内部函数

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'),但这不起作用.

python python-2.7

4
推荐指数
1
解决办法
211
查看次数

什么是NetBSD的FIONSPACE ioctl在Linux中的等价物?

我正在使用Linux 2.6.38(fc14).什么是ioctl标志来获取套接字文件描述符(例如,TCP套接字)上的可用空间量?我发现NetBSD有FIONREAD,FIONWRITE和FIONSPACE用于此类相关目的.但是,我只能在Linux中使用FIONREAD.

sockets linux ioctl netbsd

1
推荐指数
1
解决办法
2293
查看次数

标签 统计

python ×2

ioctl ×1

linux ×1

netbsd ×1

python-2.7 ×1

sockets ×1