Python Forum

Full Version: 'int' object is not subscriptable
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
my code
line = line.strip()
            except AttributeError:
                line = line
            line+1    
            lines = open("T:\donne\donne.txt").read().splitlines()
            lines.append([1])
            lines=line
            lines= int(linestowrite)
            open("T:\donne\donne.txt",'w').write((lines[1]).join(lines))
            break
my error
Error:
Traceback (most recent call last): File "Z:\programmepython\ssh2.py", line 49, in <module> open("T:\donne\donne.txt",'w').write((lines[1]).join(lines)) TypeError: 'int' object is not subscriptable
how I fix that? my var is all defined. I use python 3.7.1
It's not clear how to fix that, because it's not clear what you are trying to do. The source of your error is lines 7-8. Note that on line 5 you read the file into a list. One line 6 you add another list to the end of that list. Then on line 7, you get rid of all of that, and replace it with line, which appears to be an integer. Then you get rid of that, and replace it by converting some other variable to an integer. So, yeah, lines is an integer when you try to do lines[1] on line 9. The error indicates that you can subscript an integer. The list you could have subscripted is long gone.
thank for have explain to my what I have do, that not easy to adapt a scipt found on a web site for your script, the next time, I will try to not add many line that just ruin the script. a beginer who has a to big idea for he school project.