Python:' _io.textiowrapper'对象没有属性' isDigit'
运行代码时,我一直在遇到错误:
attributeError:'_io.textiowrapper'对象没有属性'isDigit'
这是我试图导入的文件的链接: https://onlinegdb.com/60jjt0vlc
此代码应读取输入文件名并验证t,然后写入锁定并说序列。
请帮助我解决这个问题
I keep getting the error when running my code:
AttributeError: '_io.TextIOWrapper' object has no attribute 'isdigit'
Here's a link to the file that I am trying to import:
https://onlinegdb.com/60JJt0vlC
this code should read the input file name and validate t then write the lock and say sequence.
please help me to solve this problem
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我现在无法编写任何代码来解决此问题,但我相信问题如下。
Python的isDigit()函数是字符串函数,这意味着仅在字符串对象上可用。由于您给出的错误,您正在尝试在_io.textiowrapper上执行isDigit()函数,而不是字符串。
我相信这样做的解决方法是在打开的文件上使用readlines()函数,以获取按线路分隔的文件中的字符串列表。然后,您可以在循环值中获取此列表的索引,然后使用此函数运行该函数,这应该有望起作用。
如果这不是您想要或需要帮助解决此问题的帮助,请在下面评论,我可以使用更详细的解决方案编辑答案。
I’m not able to write any code to fix this right now but I believe the issue is as follows.
Python’s isdigit() function is a string function meaning it is only available on string object. As the error you gave states you are trying to execute the isdigit() function on an _io.TextIOWrapper not a string.
I believe the fix for this is to use a readlines() function on the opened file to get a list of strings in the file separated by line break. Then you can take the index of this list at the loop value and run the function with this instead, which should hopefully work.
If this is not what you wanted or need help with resolving this problem then comment below and I can edit my answer with a more detailed solution.