求助:python 的raw_input函数求助
在使用raw_input()函数时,如果不封装成类,不用unittest的框架是没问题的,控制台能正常输入,代码获取键盘输入也正常。但是如果封装成类,用unittest框架调用就控制台无法输入,一直阻塞在哪里。求解:截图如下:
这样就执行不了,一直阻塞在这里
class Strategy(unittest.TestCase):
def setUp(self):
self.base_url = first_url
self.verificationErrors = []
self.accept_next_alert = True
def testStrategy(self):
try:
floatnum = float(raw_input("Please input a float:"))
intnum = int(floatnum)
print 100/intnum
except ZeroDivisionError:
print "Error:you must input a float num which is large or equal then 1!"
except ValueError:
print "Error:you must input a float num!"执行后一直阻塞在终端输入,但是无法输入:
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Applications/PyCharm.app/Contents/helpers/pycharm/utrunner.py /Users/zhoulei/PycharmProjects/fund_management/Strategy001.py true
Testing started at 下午3:51 ...
如果不做任何封装,调动raw_input就没问题
try:
floatnum = float(raw_input("Please input a float:"))
intnum = int(floatnum)
print 100/intnum
except ZeroDivisionError:
print "Error:you must input a float num which is large or equal then 1!"
except ValueError:
print "Error:you must input a float num!"
结果:
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/zhoulei/PycharmProjects/fund_management/test.py
Please input a float:test
Error:you must input a float num!
Process finished with exit code 0
跪求大侠指导
页:
[1]