Python Forum
'int' object is not subscriptable - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: 'int' object is not subscriptable (/thread-15593.html)



'int' object is not subscriptable - lateublegende - Jan-23-2019

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


RE: 'int' object is not subscriptable - ichabod801 - Jan-23-2019

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.


RE: 'int' object is not subscriptable - lateublegende - Jan-24-2019

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.