Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
int list have no len()
#1
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()
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
(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]
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020