草庐IT

prog_name

全部标签

python - 如何测试或模拟 "if __name__ == ' __main_ _'"内容

假设我有一个包含以下内容的模块:defmain():passif__name__=="__main__":main()我想为下半部分编写一个单元测试(我想实现100%的覆盖率)。我发现了执行import/__name__设置机制的runpy内置模块,但我不知道如何模拟或以其他方式检查main()函数被调用。这是我迄今为止尝试过的:importrunpyimportmock@mock.patch('foobar.main')deftest_main(self,main):runpy.run_module('foobar',run_name='__main__')main.assert_c

python - 导入错误 : cannot import name HTTPSHandler using PIP

使用pip安装python包时遇到HTTPSHandler错误,以下是堆栈跟踪,--------desktop:~$pipinstallDjango==1.3Traceback(mostrecentcalllast):File"/home/env/.genv/bin/pip",line9,inload_entry_point('pip==1.4.1','console_scripts','pip')()File"/home/env/.genv/lib/python2.7/site-packages/pkg_resources.py",line378,inload_entry_point

python - 导入错误 : cannot import name HTTPSHandler using PIP

使用pip安装python包时遇到HTTPSHandler错误,以下是堆栈跟踪,--------desktop:~$pipinstallDjango==1.3Traceback(mostrecentcalllast):File"/home/env/.genv/bin/pip",line9,inload_entry_point('pip==1.4.1','console_scripts','pip')()File"/home/env/.genv/lib/python2.7/site-packages/pkg_resources.py",line378,inload_entry_point

python - flask 导入错误 : No Module Named Flask

我在这里学习Flask教程:http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world我到了尝试./run.py的地步,我得到了:Traceback(mostrecentcalllast):File"./run.py",line3,infromappimportappFile"/Users/benjaminclayman/Desktop/microblog/app/__init__.py",line1,infromflaskimportFlaskImportError:Nomodulena

python - flask 导入错误 : No Module Named Flask

我在这里学习Flask教程:http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world我到了尝试./run.py的地步,我得到了:Traceback(mostrecentcalllast):File"./run.py",line3,infromappimportappFile"/Users/benjaminclayman/Desktop/microblog/app/__init__.py",line1,infromflaskimportFlaskImportError:Nomodulena

python - 错误 : No module named psycopg2. 扩展

我正在尝试为我的django项目设置一个PostgreSQL数据库,感谢对我上一个问题ProblemssettingupapostgreSQLdatabaseforadjangoproject的回复,我相信我现在已经完成了。.我现在正在尝试在终端中运行命令“pythonmanage.pyrunserver”来启动我的本地主机,但是当我运行该命令时,我看到了这个响应......Error:Nomodulenamedpsycopg2.extensions我不确定这意味着什么-我尝试下载psycopg2,但似乎找不到使用自制软件下载psycopg2的方法。我尝试过easy_install、p

python - 错误 : No module named psycopg2. 扩展

我正在尝试为我的django项目设置一个PostgreSQL数据库,感谢对我上一个问题ProblemssettingupapostgreSQLdatabaseforadjangoproject的回复,我相信我现在已经完成了。.我现在正在尝试在终端中运行命令“pythonmanage.pyrunserver”来启动我的本地主机,但是当我运行该命令时,我看到了这个响应......Error:Nomodulenamedpsycopg2.extensions我不确定这意味着什么-我尝试下载psycopg2,但似乎找不到使用自制软件下载psycopg2的方法。我尝试过easy_install、p

python - 来自 Python : No module named lambda_function 的 AWS 错误

我正在创建一个AWSLambdapython部署包。我正在使用一个外部依赖请求。我使用AWSdocumentation安装了外部依赖项.下面是我的Python代码。importrequestsprint('Loadingfunction')s3=boto3.client('s3')deflambda_handler(event,context):#print("Receivedevent:"+json.dumps(event,indent=2))#Gettheobjectfromtheeventandshowitscontenttypebucket=event['Records'][0

python - 来自 Python : No module named lambda_function 的 AWS 错误

我正在创建一个AWSLambdapython部署包。我正在使用一个外部依赖请求。我使用AWSdocumentation安装了外部依赖项.下面是我的Python代码。importrequestsprint('Loadingfunction')s3=boto3.client('s3')deflambda_handler(event,context):#print("Receivedevent:"+json.dumps(event,indent=2))#Gettheobjectfromtheeventandshowitscontenttypebucket=event['Records'][0

python - UnicodeEncodeError : 'ascii' codec can't encode character at special name

这个问题在这里已经有了答案:UnicodeEncodeError:'ascii'codeccan'tencodecharacteru'\xa0'inposition20:ordinalnotinrange(128)(34个回答)关闭6年前。我的python(ver2.7)脚本运行良好,可以从本地html文件中获取一些公司名称,但是当涉及到一些特定的国家名称时,它会给出这个错误“UnicodeEncodeError:'ascii'codeccan'tencodecharacter”当这个公司名称出现时特别出错公司名称:KühlfixKälteanlagenIng.GerhardDocze