html随机选数代码介绍 html随机数生成器( 六 )


[dechin@dechin-manjaro pytest]$ python3 -m pip install flake8-htmlCollecting flake8-htmlDownloading flake8_html-0.4.1-py2.py3-none-any.whl (13 kB)Requirement already satisfied: pygments>=2.2.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from flake8-html) (2.7.2)Requirement already satisfied: flake8>=3.3.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from flake8-html) (3.8.4)Requirement already satisfied: jinja2>=2.9.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from flake8-html) (2.11.2)Requirement already satisfied: importlib-metadata in /home/dechin/anaconda3/lib/python3.8/site-packages (from flake8-html) (2.0.0)Requirement already satisfied: pycodestyle<2.7.0,>=2.6.0a1 in /home/dechin/anaconda3/lib/python3.8/site-packages (from flake8>=3.3.0->flake8-html) (2.6.0)Requirement already satisfied: mccabe<0.7.0,>=0.6.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from flake8>=3.3.0->flake8-html) (0.6.1)Requirement already satisfied: pyflakes<2.3.0,>=2.2.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from flake8>=3.3.0->flake8-html) (2.2.0)Requirement already satisfied: MarkupSafe>=0.23 in /home/dechin/anaconda3/lib/python3.8/site-packages (from jinja2>=2.9.0->flake8-html) (1.1.1)Requirement already satisfied: zipp>=0.5 in /home/dechin/anaconda3/lib/python3.8/site-packages (from importlib-metadata->flake8-html) (3.4.0)Installing collected packages: flake8-htmlSuccessfully installed flake8-html-0.4.1使用方法如下:
[dechin@dechin-20n2s01200 pytest]$ flake8 --format=html --htmldir=flake-report./random_number.py has issues: medium: 4在当前目录执行后,相关的规范的issue就不会在命令行里面逐一显示,都在flake-report目录下的index.html中可以查看:
我们可以点击进入相应文件的issue清单中去查看:
可以点击每一个issue,展开内容中包含了issue所对应行的代码内容:
经过一番修改之后,我们得到的flake8配置文件和源代码文件如下:
# .flake8[flake8]exclude = ./test*ignore = W391# random_number.pyfrom projectq import MainEnginefrom projectq.ops import H, Measuredef random_number_generator():eng = MainEngine()qubit = eng.allocate_qubit()H | qubiteng.flush()Measure | qubitrandom_number = int(qubit)eng.flush(deallocate_qubits=True)return random_numberif __name__ == '__main__':random_number = random_number_generator()print('Random number generated by quantum simulator is:{}'.format(random_number))最终我们的目的是使得flake8执行的issue清零:
[dechin@dechin-manjaro pytest]$ flake8 --format=html --htmldir=flake-report[dechin@dechin-manjaro pytest]$总结概要本文通过引入一个随机数生成器的案例,介绍了在量子计算中产生真随机数的方案,同时给出了量子计算模拟实现 。借此机会也同时介绍了python的单元测试库pytest的一些常规和扩展使用方法,以及python的编码规范测试库flake8的基本使用方法,希望能够对大家有所启发以及帮助 。


以上关于本文的内容,仅作参考!温馨提示:如遇健康、疾病相关的问题,请您及时就医或请专业人士给予相关指导!

「四川龙网」www.sichuanlong.com小编还为您精选了以下内容,希望对您有所帮助: