亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区
Chinaunix
標(biāo)題:
python attribute error 還請(qǐng)高手指點(diǎn)
[打印本頁(yè)]
作者:
xu_liuzhen
時(shí)間:
2013-04-25 15:50
標(biāo)題:
python attribute error 還請(qǐng)高手指點(diǎn)
本帖最后由 xu_liuzhen 于 2013-04-25 15:53 編輯
用這個(gè)鏈接的方法獲取鍵盤輸入(
方法程序在這里
),
import select
import sys
import time
import os
import termios
def kbhit():
fd = sys.stdin.fileno()
r = select.select([sys.stdin],[],[],0.01)
rcode = ''
if len(r[0]) >0:
rcode = sys.stdin.read(1)
return rcode
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
new_settings = old_settings
#new_settings[3] = new_settings[3] & ~termios.ISIG
new_settings[3] = new_settings[3] & ~termios.ICANON
new_settings[3] = new_settings[3] & ~termios.ECHONL
print 'old setting %s'%(repr(old_settings))
termios.tcsetattr(fd,termios.TCSAFLUSH,new_settings)
while True:
c = kbhit()
if len(c) !=0 :
print 'K %s'%(c)
else:
print 'Sleep 1'
time.sleep(1)
復(fù)制代碼
自己寫小程序測(cè)試沒有問題,添加到其他程序里就報(bào)錯(cuò):
r = select.select([sys.stdin],[],[],0.01)
AttributeError: 'function' object has no attribute 'select'
還請(qǐng)大神們指點(diǎn)指點(diǎn)
作者:
jeppeter
時(shí)間:
2013-04-25 16:04
回復(fù)
1#
xu_liuzhen
你沒有給出具體的環(huán)境是怎么樣的。你是如何調(diào)用的,如果沒有這些信息,是不好決定是怎么回事的。要有上下文。
作者:
xu_liuzhen
時(shí)間:
2013-04-25 16:10
補(bǔ)充下,我的測(cè)試小程序是這樣的:
#!/usr/bin/python
import select
import sys
import time
import os
import termios
def kbhit():
fd = sys.stdin.fileno()
r = select.select([sys.stdin],[],[],0.01)
rcode = ''
print r
if len(r[0]) >0:
rcode = sys.stdin.read(1)
return rcode
def prints():
while True:
c = kbhit()
if c == 'b':
printsb()
elif c == 'c':
printsc()
elif c == 'd':
prints()
else:
print "sleep1"
time.sleep(1)
def printsb():
while True:
c = kbhit()
if c == 'b':
printsb()
elif c == 'c':
printsc()
elif c == 'd':
prints()
else:
print "b"
time.sleep(1)
def printsc():
while True:
c = kbhit()
if c == 'b':
printsb()
elif c == 'd':
prints()
else:
print "c"
time.sleep(1)
if __name__=='__main__':
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
new_settings = old_settings
new_settings[3] = new_settings[3] & ~termios.ISIG
new_settings[3] = new_settings[3] & ~termios.ICANON
new_settings[3] = new_settings[3] & ~termios.ECHONL
termios.tcsetattr(fd,termios.TCSAFLUSH,new_settings)
while True:
prints()
復(fù)制代碼
我把他添加到另一個(gè)程序里面,只是替換了那些調(diào)用的輸出函數(shù),然后就報(bào)錯(cuò)了
作者:
xu_liuzhen
時(shí)間:
2013-04-25 16:10
不好意思我沒說清楚,看我的補(bǔ)充
回復(fù)
2#
jeppeter
作者:
jeppeter
時(shí)間:
2013-04-25 21:19
回復(fù)
4#
xu_liuzhen
如果是你的程序,我測(cè)試過,就是沒有問題,可能的原因,是這些代碼沒有考慮到你的調(diào)用情況。如果沒有公布,可能是沒有辦法得到結(jié)果的。
歡迎光臨 Chinaunix (http://72891.cn/)
Powered by Discuz! X3.2