Python编程代码复制的简单介绍
python不能复制粘贴代码
python不能复制粘贴代码是操作不对。
1、安装pyperclip1.1使用方法1.1.1复制1.1.2粘贴。
2、安装PyKeyboard2.1安装pywin32点击下载pywin32下载whl文件,之后用命令行pipinstall安装,注意选择好对应的版本。
Python编程怎么复制?
解释器是交互式的,类似于很早的basic,不太适用直接粘贴。所以建议你:
在windows之下安装的python有一个idle集成开发环境,在那里new个新文件,复制粘贴源代码,点run菜单运行即可。也可在windows的“命令提示符”下用python直接执行你用记事本写好的.py文件。像我们一般都用比较专业的开发环境,比如vs里面包含的python,总之有很多种选择,就看自己的喜好了
石头剪刀布python编程代码
player = int(input(“请出拳 石头(1)/剪刀(2)/布(3)”))
computer = 1
if((player == 1 and computer == 2) or
(player == 2 and computer == 3) or
(player == 3 and computer == 1)):
print(“欧耶!电脑弱爆了!”)
elif player == computer:
print(“心有灵犀,再来一盘!”)
else:
print(“不行,我要和你决战到天明!”)
执行的时候,第一行一定要单独复制,因为你需要输入一个数值
如何使用python编写测试脚本
1)doctest
使用doctest是一种类似于命令行尝试的方式,用法很简单,如下
复制代码代码如下:
def f(n):
"""
f(1)
1
f(2)
2
"""
print(n)
if __name__ == '__main__':
import doctest
doctest.testmod()
应该来说是足够简单了,另外还有一种方式doctest.testfile(filename),就是把命令行的方式放在文件里进行测试。
2)unittest
unittest历史悠久,最早可以追溯到上世纪七八十年代了,C++,Java里也都有类似的实现,Python里的实现很简单。
unittest在python里主要的实现方式是TestCase,TestSuite。用法还是例子起步。
复制代码代码如下:
from widget import Widget
import unittest
# 执行测试的类
class WidgetTestCase(unittest.TestCase):
def setUp(self):
self.widget = Widget()
def tearDown(self):
self.widget.dispose()
self.widget = None
def testSize(self):
self.assertEqual(self.widget.getSize(), (40, 40))
def testResize(self):
self.widget.resize(100, 100)
self.assertEqual(self.widget.getSize(), (100, 100))
# 测试
if __name__ == "__main__":
# 构造测试集
suite = unittest.TestSuite()
suite.addTest(WidgetTestCase("testSize"))
suite.addTest(WidgetTestCase("testResize"))
# 执行测试
runner = unittest.TextTestRunner()
runner.run(suite)
简单的说,1构造TestCase(测试用例),其中的setup和teardown负责预处理和善后工作。2构造测试集,添加用例3执行测试需要说明的是测试方法,在Python中有N多测试函数,主要的有:
TestCase.assert_(expr[, msg])
TestCase.failUnless(expr[, msg])
TestCase.assertTrue(expr[, msg])
TestCase.assertEqual(first, second[, msg])
TestCase.failUnlessEqual(first, second[, msg])
TestCase.assertNotEqual(first, second[, msg])
TestCase.failIfEqual(first, second[, msg])
TestCase.assertAlmostEqual(first, second[, places[, msg]])
TestCase.failUnlessAlmostEqual(first, second[, places[, msg]])
TestCase.assertNotAlmostEqual(first, second[, places[, msg]])
TestCase.failIfAlmostEqual(first, second[, places[, msg]])
TestCase.assertRaises(exception, callable, ...)
TestCase.failUnlessRaises(exception, callable, ...)
TestCase.failIf(expr[, msg])
TestCase.assertFalse(expr[, msg])
TestCase.fail([msg])