草庐IT

python - 类型 <type 'numpy.string_' > 和 <type 'str' > 有什么区别?

类型之间有区别吗和? 最佳答案 numpy.string_是用于包含固定宽度字节字符串的数组的NumPy数据类型。另一方面,str是原生Python类型,不能用作NumPy数组的数据类型*。如果您创建一个包含字符串的NumPy数组,该数组将使用numpy.string_类型(或Python3中的numpy.unicode_类型)。更准确地说,该数组将使用np.string_的子数据类型。:>>>a=np.array(['abc','xy'])>>>aarray(['abc','xy'],dtype='>>np.issubdtype(

python - 为什么 print ("text"+ str(var1) + "more text"+ str(var2)) 被描述为 "disapproved"?

为什么下面的代码在“SnakesandCoffee”对Blender的Printmultipleargumentsinpython帖子的评论中被称为“古老的不认可打印方法”?是否与Python2或Python3的后端代码/实现有关?print("Totalscorefor"+str(name)+"is"+str(score)) 最佳答案 添加许多字符串不被批准,因为:与其他替代方案相比,它的可读性并不高。它的效率不如其他选择。如果您有其他类型,则必须手动调用它们的str。而且,是的,它真的很旧。:-)理论上,字符串加法会创建一个新字

python - 如何修复此 "TypeError: ' str' 对象不可调用“错误?

我正在创建一个基本程序,该程序将使用GUI获取商品价格,如果初始价格低于10,则减价10%,如果初始价格低于10,则减价20%初始价格大于十:importeasyguiprice=easygui.enterbox("Whatisthepriceoftheitem?")iffloat(price)10:easygui.msgbox("Yournewpriceis:$"(float(price)*0.2))虽然我一直收到这个错误:easygui.msgbox("Yournewpriceis:$"(float(price)*0.1))TypeError:'str'objectisnotcal

python - 子进程 "TypeError: a bytes-like object is required, not ' str'"

我正在使用来自apreviouslyaskedquestionafewyearsago的代码但是,我认为这已经过时了。尝试运行代码时,我收到了上面的错误。我仍然是Python的新手,所以我无法从类似的问题中得到太多的澄清。有谁知道为什么会这样?importsubprocessdefgetLength(filename):result=subprocess.Popen(["ffprobe",filename],stdout=subprocess.PIPE,stderr=subprocess.STDOUT)return[xforxinresult.stdout.readlines()if"

python - 类型错误 : unbound method "method name" must be called with "Class name" instance as first argument (got str instance instead)

我认为这应该是一个简单的问题。我有下一节课:classGruposHandler(webapp.RequestHandler):defget(self):self.obtenerPagina()defobtenerPagina(self,pOpcion=None,pMensajeInformacion=None):opcion=pOpcionifpOpcionisnotNoneelseself.request.get('opcion')usuario=obtenerUsuario()rsGrupos=obtenerGruposAll()listaOtrosGrupos=[]listaG

python - 类型错误 : 'int' object is not callable, ,, len()

我写了一个程序来玩刽子手---它还没有完成,但由于某种原因它给了我一个错误...importturtlen=Falsey=Truelist=()print("welcometothehangman!youwordis?")word=raw_input()len=len(word)forxinrange(70):printprint"_"*lenwhilen==False:whiley==True:print"insertaletter:"p=raw_input()leenghthp=len(p)ifleengthp!=1:print"youdidntgivemealetter!!!"e

python - 当 >64 位时从 __len__() 返回

在这个问题中,我处理的是IPv6网络地址空间,所以长度是2^(128-subnet)。看起来python(至少在这台机器上)最多可以处理64位有符号数作为__len__()的返回值。所以len(IP('2001::/66'))有效,但len(IP('2001::/65'))失败。fromIPyimportIPlen(IP('2001::/64'))Traceback(mostrecentcalllast):File"test.py",line2,inlen(IP('2001::/64'))OverflowError:longinttoolargetoconverttoint有问题的IP

Python - 'str' 对象没有属性 'close'

我正在努力弄清楚为什么我写的这几行代码不需要关闭属性:fromsysimportargvfromos.pathimportexistsscript,from_file,to_file=argvfile_content=open(from_file).read()new_file=open(to_file,'w').write(file_content)new_file.close()file_content.close()我读了一些东西和其他人的帖子,但他们的脚本比我目前正在学习的要复杂得多,所以我不明白为什么。我正在努力学习Python,非常感谢任何帮助。

python - create_string_buffer 抛出错误 TypeError : str/bytes expected instead of str instance

我正在尝试这个简单的ctypes示例并得到提到的错误>>>fromctypesimportcreate_string_buffer>>>str=create_string_buffer("hello")Traceback(mostrecentcalllast):File"",line1,inFile"C:\Python32\lib\ctypes\__init__.py",line59,increate_string_bufferbuf.value=initTypeError:str/bytesexpectedinsteadofstrinstance有谁知道我做错了什么吗?同样,我试图将

python - 'str' 对象没有属性 'get'

我正在研究Django中的Braintree集成。我关注了thisguide:但是,我收到错误消息'str'objecthasnoattribute'get'。View.pyfromdjango.shortcutsimportrender,render_to_responsefromdjango.http.responseimportHttpResponseimportbraintreebraintree.Configuration.configure(braintree.Environment.Sandbox,"privatekeyhere","merchantkeyhere","p