草庐IT

SITE_NAME

全部标签

python - 导入错误 : cannot import name 'Timestamp'

我已使用以下代码在我的python3.6.3中成功安装了ggplot:condainstall-cconda-forgeggplot但是当我使用下面的代码将它导入我的笔记本时,我收到了一个错误:fromggplotimport*ImportError:cannotimportname'Timestamp'如果我能解决这个问题,我将不胜感激。 最佳答案 我也遇到了同样的问题。请转到.../site-packages/ggplot/stats/smoothers.py并更改frompandas.libimportTimestamp到fr

python - 如何在 Django 中使用 first_name、last_name 修改创建 UserProfile 表单?

如果认为我的问题非常明显,几乎每个使用UserProfile的开发人员都应该能够回答。但是,我在django文档或DjangoBook中找不到任何帮助。当您想在Django表单中创建UserProfile表单时,您希望修改配置文件字段以及一些User字段。但是没有forms.UserProfileForm(还没有?)!你是怎么做到的? 最佳答案 我今天偶然发现了这个,经过一番谷歌搜索后,我发现了一个我认为更简洁的解决方案:#informs.pyclassUserForm(forms.ModelForm):classMeta:mode

python - Python 模块中的 __name__ 变量是如何定义的?

我知道thestandardexample:如果你直接执行一个模块,那么它的__name__全局变量被定义为"__main__"。但是,我在文档中找不到关于在一般情况下如何定义__name__的精确描述。moduledocumentation说...Withinamodule,themodule'sname(asastring)isavailableasthevalueoftheglobalvariable__name__....但是“模块的名称”是什么意思?它只是模块的名称(删除了.py的文件名),还是包含完全限定的包名称?Python模块中__name__变量的值是如何确定的?对于

python - 在单元测试中模拟 open(file_name)

这个问题在这里已经有了答案:HowdoImockthefilesysteminPythonunittests?(5个回答)关闭去年。我有一个打开csv文件并设置标题的源代码值(value)关联。源码如下:defParseCsvFile(source):"""Parsethecsvfile.Args:source:filetobeparsedReturns:thelistofdictionaryentities;eachdictionarycontainsattributetovaluemappingoritsequivalent."""globalrack_filerack_type_

python - 导入错误 : cannot import name

我有两个文件app.py和mod_login.pyapp.pyfromflaskimportFlaskfrommod_loginimportmod_loginapp=Flask(__name__)app.config.update(USERNAME='admin',PASSWORD='default')mod_login.py#coding:utf8fromflaskimportBlueprint,render_template,redirect,session,url_for,requestfromfunctoolsimportwrapsfromappimportappmod_log

python - 导入错误 : cannot import name wraps

我在Ubuntu14.04.2LTS上使用python2.7.6。我正在使用模拟来模拟一些单元测试,并注意到当我导入模拟时它无法导入包装。不确定是否应该使用不同版本的mock或6来使其导入工作?找不到任何相关答案,而且我没有使用虚拟环境。mock模块说它与python2.7.x兼容:https://pypi.python.org/pypi/mock模拟==1.1.3六==1.9.0Python2.7.6(default,Mar222014,22:59:56)[GCC4.8.2]onlinux2Type"help","copyright","credits"or"license"form

python - Python 成语 "if __name__ == ' __main_ _'"的 clojure 等价物是什么?

我正在涉足clojure,但在尝试确定这个常见的python习语的clojure(和/或Lisp)等价物时遇到了一些麻烦。习语是在一个python模块的底部通常有一点测试代码,然后是运行代码的语句,例如:#mymodule.pyclassMyClass(object):"""Mainlogic/codeforthelibraryliveshere"""passdef_runTests():#CodewhichtestsvariousaspectsofMyClass...mc=MyClass()#etc...assert2+2==4if__name__=='__main__':_runT

python - 错误 : NameError: name 'subprocess' is not defined

这个问题不太可能帮助任何future的访客;它仅与一个小地理区域、一个特定时刻或一个非常狭窄的情况相关,而这些情况通常不适用于互联网的全局受众。如需帮助使这个问题更广泛地适用,visitthehelpcenter.关闭9年前。#!/usr/bin/python3username='joe'#generatepassphrasepw_length=6phrase=subprocess.check_output(['pwgen',str(pw_length),'1'])phrase=phrase.decode('utf-8').strip()dev_null=open('/dev/null

python - 导入错误 : cannot import name np_utils

我正在尝试运行以下example来自keras但我收到此错误:ImportErrorTraceback(mostrecentcalllast)in()8importnumpyasnp9importmatplotlib.pyplotasplt--->10fromkeras.modelsimportSequential11fromkeras.layersimportDense,LSTM12/usr/local/lib/python2.7/dist-packages/keras/__init__.pyin()1from__future__importabsolute_import2---->

python - related_name 参数在 Django 模型中没有按预期工作?

我最近在我的Django模型中遇到了ForeignKey冲突。我需要有两个外键(owner、assigned_to)最终指向同一个模型(一个用户)。据我了解,我需要一个related_name参数来解决该问题。所以我这样做了:assigned_to=models.ForeignKey(TaskUser,blank=True,null=True,related_name='user_assignment')和owner=models.ForeignKey(TaskUser,related_name="user_ownership"但我仍然收到错误消息:tasks.task:Accesso