'Python: '_io.TextIOWrapper' object has no attribute 'isdigit'

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

enter image description here

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



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 CmdCoder858