草庐IT

MYLIB_FUNCTION_ATTRIBUTE

全部标签

Python 转换样式 : inside or out of function?

我有一个需要对数字类型进行操作的函数。我正在读取要从文件中操作的数字,所以当我读取它们时,它们是字符串,而不是数字。是让我的函数容忍其他类型(下面的选项(A))更好,还是在调用函数之前转换为数字(下面的选项(B))更好?#Option(A)defnumeric_operation(arg):i=int(arg)#dosomethingnumericwithi#Option(B)defnumeric_operation(arg):#expectcallertocallnumeric_operation(int(arg))#dosomethingnumericwitharg

Windows : AttributeError: Can't get attribute "abc" 上 Jupyter 中的 python 多处理

我正在尝试运行一个简单的命令,该命令使用多处理按名称猜测性别。此代码在以前的机器上运行,所以可能与我的设置有关。下面是我的多处理代码:importsysimportgender_guesser.detectorasgenderimportmultiprocessingimporttimed=gender.Detector()defguess_gender(name):n=name.title()#makefirstletteruppercaseandtherestlowercaseg=d.get_gender(n)#guessgenderreturngls=['john','joe',

python - 优化 "difference function"的计算

我的代码调用了许多“差分函数”来计算“Yinalgorithm”(基频提取器)。差分函数(论文中的等式6)定义为:这是我对差异函数的实现:defdifferenceFunction(x,W,tau_max):df=[0]*tau_maxfortauinrange(1,tau_max):forjinrange(0,W-tau):tmp=long(x[j]-x[j+tau])df[tau]+=tmp*tmpreturndf例如:x=np.random.randint(0,high=32000,size=2048,dtype='int16')W=2048tau_max=106differen

python - urllib 模块错误!属性错误 : 'module' object has no attribute 'request'

我目前正在使用python中的“urllib”模块,并尝试使用它来提取网站的源代码:importurllibtemp=urllib.request.urlopen('https://www.quora.com/#')但是,我收到以下错误:Traceback(mostrecentcalllast):File"",line1,intemp=urllib.request.urlopen('https://www.quora.com/#')AttributeError:'module'objecthasnoattribute'request'顺便说一句,我正在使用Python2.7.5。

python - 属性错误 : module 'tensorflow' has no attribute 'reset_default_graph'

我已经安装了tensorflow版本r0.11。在我的文件名cartpole.py中,我导入了tensorflow:importtensorflowastf并使用它:tf.reset_default_graph()尝试在PyCharm中运行我的项目时出现此错误:intf.reset_default_graph()AttributeError:module'tensorflow'hasnoattribute'reset_default_graph'我该如何修复这个错误? 最佳答案 此功能已弃用。请改用tf.compat.v1.rese

python - 属性错误 : 'UUID' object has no attribute 'replace' when using backend-agnostic GUID type

我想在使用SQLAlchemy1.1.5的Postgresql数据库中拥有一个类型为uuid的主键ID,并使用pg8000适配器连接到数据库。我用了Backend-agnosticGUIDTyperecipe来自SQLAlchemy文档。当我想插入数据库时​​,出现如下错误File".../guid.py",line???,inprocess_result_valuereturnuuid.UUID(value)File"/usr/lib/python2.7/uuid.py",line131,in__init__hex=hex.replace('urn:','').replace('uu

python - Django 错误 : "' ChoiceField' object has no attribute 'is_hidden' "

Django模板在呈现时抛出“AttributeError”。我想要实现的是,在模板中,解析的表单将包含一个选择框,其中包含以下列表中的值。这是Forms.py文件:classCallForm(forms.ModelForm):classMeta():model=Callwidgets={'employee_id':forms.ChoiceField(choices=FormsTools.EmployeesToTuples(Employee.objects.all()))}解释:FormsTools.EmployeesToTuples(Employee.objects.all())--

Python 和函数式编程 : is there an apply() function?

Scala有apply()功能。我是Python的新手,我想知道我应该如何编写以下单行代码:(part_a,part_b)=(lambdax:re.search(r"(\w+)_(\d+)",x).groups())(input_string)我会觉得像这样的东西会更好:(part_a,part_b)=input_string.apply(lambdax:re.search(r"(\w+)_(\d+)",x).groups())从FF的角度来看,我错了吗?Python中有这样的构造吗?编辑:我知道摘得不好的片段。 最佳答案 写Has

python - 'numpy.float6 4' object has no attribute ' translate' 在 Python 中向 Mysql 插入值

importdatasetdb=dataset.connect(....)table=db[...]当我尝试向Mysql表中插入一些值时,发生了这个错误。我要插入到表中的示例值:print("Buy",ticker,price,date,OType,OSize)BuyAAPL93.43571428572016-05-12Market200data=dict(Order_Side='Buy',Ticker=ticker,Price=price,Order_Date=date,Order_Type=OType,Volume=OSize)table.insert(data)错误信息:Trac

python - aws lambda 无法导入模块 'lambda_function' : No module named 'requests'

我最近开始使用AWSLambda对我编写的一些Python代码使用触发器。我目前有2个lambda函数,它们都是用ZIP文件创建的。我创建的第二个应该用于测试触发事件。这是出于测试目的,所以我使用的是最好的代码:deflambda_handler(event,context):print("HelloWorld")但是,我得到了这个错误:Response:{"errorMessage":"Unabletoimportmodule'lambda_function'"}RequestID:"65024f16-172c-11e8-ab26-27ff3322e597"FunctionLogs: