Python Forum
int list have no len() - 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 list have no len() (/thread-16944.html)



int list have no len() - lateublegende - Mar-21-2019

I try to write my list, but I need len() for write it.
if I write in str, they print 5 item.
this is my code
y=list(map(int, y))
print(y)
y[0]+=1
print(y)

f = sftp.open("/home/pi/SiteCyberdependance/donne/donne.txt", "w+")
with sftp.open("/home/pi/SiteCyberdependance/donne/donne.txt", "w") as f:
            sftp=paramiko.SFTPFile.write
            f.write(y[item])
Error:
TypeError: object of type 'int' has no len()



RE: int list have no len() - ichabod801 - Mar-21-2019

There is not enough information here. I don't see len used anywhere in the posted code, and you don't provide the full error message (traceback), so we don't know which line is causing the error.

And why do you keep using line 8? I keep seeing it in code you post. I can't see any use for it except blocking the use of the sftp module later in your code.


RE: int list have no len() - snippsat - Mar-21-2019

(Mar-21-2019, 02:06 PM)lateublegende Wrote: I try to write my list, but I need len() for write it.
if I write in str, they print 5 item.
Most be str to write paramiko doc.
Example if have list with integers,need to convent fourth and back to original list.
lst = [1, 2, 3 ,4]
# Most be string befor write
lst = ','.join(str(i) for i in lst)
with open('test.dat', 'w') as f:
    f.write(lst)

with open('test.dat') as f:
    lst = f.read().split(',')
    lst = [int(i) for i in lst]
    print(lst)
Output:
[1, 2, 3, 4]