草庐IT

str_input

全部标签

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 - 为什么 input() 在我按下 enter 时会给出 SyntaxError?

我有以下python代码:print'Thisisasimplegame.'input('Pressentertocontinue...')print'Chooseanoption:'...但是当我按下Enter按钮时,出现以下错误:Traceback(mostrecentcalllast):File"E:/4.Python/temp.py",line2,ininput('Pressentertocontinue...')File"",line0^SyntaxError:unexpectedEOFwhileparsing附言我在Windows7上使用pythonIDLE2.6版。

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,如果有区别的话。 最佳答案

Python 正确使用 __str__ 和 __repr__

我当前的项目需要大量使用位域。我找到了一个简单、实用的recipeforbitafieldclass但它缺少一些我需要的功能,所以我决定扩展它。我只需要实现__str__和__repr__并且我想确保我遵循约定。__str__应该是非正式和简洁的,所以我让它返回位字段的十进制值(即str(bitfield11)将是“3”。__repr__应该是对象的官方表示,所以我让它返回实际的位字符串(即repr(bitfield11)将是“11”)。您认为此实现是否符合str和repr的约定?此外,我还使用了bin()函数来获取存储在类中的值的位串。这与Python干杯,皮特

《uni-app》表单组件-Input组件

本文分享的Input组件为uni-app的内置组件Input,非扩展组件,两者在用法上其实大同小异,只是扩展组件的属性以及事件更多…没有本质上的区别~《uni-app》表单组件-Input组件一.简介二.基础用法三.value属性与双向绑定四.type属性与password属性五.placeholder、placeholder-style、placeholder-class属性六.disabled属性七.maxlength属性八.confirm-type属性与confirm-hold属性九.@input事件十.@focus事件与@blur事件十一.@confirm事件十二.demo示例演示12

python - 类型错误 : 'str' does not support the buffer interface

importhashlibinfile=open("P:\\r.mp3",'r+b')data=infile.readline()hash=hashlib.md5()hash.update(data)hash_digest=hash.hexdigest()print(hash_digest)#hash_digest=hash_digest.encode('utf-8')print(hash_digest)withopen("lt.txt",'ab')asoutfile:outfile.write(hash_digest+'\n')#errorherewithopen("syncDB.t