x = []
with open(filechoice) as fileobj:
for word in fileobj:
for ch in word:
f = ord(ch)
x = x.append(ord(ch))
But it returns this error:
"AttributeError: 'NoneType' object has no attribute 'append'"
How can I fix this error?
The
list.append()
method returnsNone
, and you replaced the list stored inx
with that return value:Don't assign back to
x
here;list.append()
alters the list in place:You can use a list comprehension to build the list instead: