草庐IT

str_buff

全部标签

python - 类型错误 : Type str doesn't support the buffer API # find method?

这是我的输入:..........JimCramer‏@jimcramer26NovLovethisspirited&rigorous$TSLAdefense!RT@InfennonLabs:Whyaretheseidiotsselling#tslaaretheythatblind?@jimcramerFavorited5times...........例如这个“输入”在我的input变量中。这是我的代码:start_link=input.find('如果我运行它,我会得到以下错误:start_link=input.find('我该如何解决这个问题?注意:我的输入变量的类型是:

python - 带有字符串值的 AttributeError : Can only use . str 访问器,在 pandas 中使用 np.object_ dtype

Str.replace方法返回一个属性错误。dc_listings['price'].str.replace(',','')AttributeError:Canonlyuse.straccessorwithstringvalues,whichusenp.object_dtypeinpandas这是我的价格列的前5行。此堆栈溢出threadrecommends检查我的列是否有NAN值,但我列中的值都不是NAN。 最佳答案 如错误所述,您只能将.str与字符串列一起使用,并且您有一个float64。float中不会有任何逗号,所以你所拥

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

defparticipant_specific(request,participant):helper=RelayFunctions()info=helper.participant_specific_donation(participant)info1=helper.participant_specific_milestone(participant)data={'participant_specific_donation':info,'participant_specific_milestone':info1}json_serializer=serializers.get_seri

python - 需要一个类似字节的对象,而不是 'str' JSON 文件作为 STR 打开

我只学习了Python的基础知识,请原谅我,但我无法从其他帖子中确定修复方法。我用“r”打开我的JSON文件,我想我正在用r写信给它们,但它不喜欢那样。将其更改为'r'没有帮助:(对于以下部分:ifisinstance(to_write,list):self.log_file.write(''.join(to_write)+"")else:self.log_file.write(str(to_write)+"")self.log_file.flush()我得到的错误是:需要一个类似字节的对象,而不是“str”importmathimporttimefromrandomimportran

python - 属性错误 : 'str' object has no attribute 'fileno'

代码:importsubprocessdefprintit():foriinrange(6):forjinrange(6):query="selectrxpkts,txpktsfrom./log.csvwheredatapath="+str(i)+"andport="+str(j)fileName=str(i)+"_"+str(j)+".csv"withopen(fileName,"w+"):p=subprocess.Popen(["python","q","-H","-d",",",query],stdout=fileName)printit()错误:$pythonprocessLo

python:无法连接 'str' 和 'tuple' 对象(应该可以!)

我有一个代码:print"bug"+data[str.find(data,'%')+2:-1]temp=data[str.find(data,'%')+2:-1]time.sleep(1)print"bugtuple"+tuple(temp.split(','))然后我的应用程序显示:bug1,2,3Traceback(mostrecentcalllast):File"C:\Python26\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",line312,inRunScriptexeccodeObjectinmai

python - Python3 中的 ElementTree TypeError "write() argument must be str, not bytes"

使用Python3和ElementTree生成.SVG文件时遇到问题。fromxml.etreeimportElementTreeasetdoc=et.Element('svg',width='480',height='360',version='1.1',xmlns='http://www.w3.org/2000/svg')#Doingthingswithetanddocf=open('sample.svg','w')f.write('\n')f.write('\n')f.write(et.tostring(doc))f.close()函数et.tostring(doc)生成类型错误

python - python `str()`函数是否调用类的 `__str__()`函数?

如果我用它自己的__str__()函数定义一个类,str(a)是否等同于a.__str__(),a是我的类的一个实例吗?我检查了pythondoc,它没有明确说明是这种情况。 最佳答案 简短回答:是的!根据Pythondocs(我突出了相关部分):object.__str__(self)Calledbystr(object)andthebuilt-infunctionsformat()andprint()tocomputethe“informal”ornicelyprintablestringrepresentationofanob

python - AttributeError: 'str' 对象没有属性

我是Python编程的新手,我想尝试一下简单的文字冒险游戏,但我立即遇到了障碍。classuserInterface:def__init__(self,roomID,roomDesc,dirDesc,itemDesc):self.roomID=roomIDself.roomDesc=roomDescself.dirDesc=dirDescself.itemDesc=itemDescdefdisplayRoom(self):#Displaystheroomdescriptionprint(self.roomDesc)defdisplayDir(self):#Displaysavailab

python - 将 str 转换为路径类型?

我正在尝试与一些保存配置的现有代码交互,并期望一个类型为path.path的文件路径。代码期望从pygtk浏览器窗口返回文件路径(通过另一个函数)。我想在我的代码的其他地方调用save_config函数,使用基于不同输入的文件路径,由字符串元素构造。当我尝试运行代码时,我能够正确构造文件路径,但它是一个字符串类型,并且保存函数需要一个path.path类型。有没有办法将字符串转换为路径类型?我试过搜索,但只能找到相反的情况(字符串路径)。我也尝试使用os.path.join(),但它也返回一个字符串。编辑:这是python2.7,如果有区别的话。 最佳答案