I am writing a python script that process lists read from a file:
l = readListFromFile( myFile )
for i in l :
# do something to each element
All works fine when l
has more than one element.
However, when there is only one element in the list readFromFile
returns l
as a scalar and not as a list. Hence for i in l
fails with error
object is not iterable
I have no control over readFromFile
, and my question is how can I make python treat l
as a alist even in the case where l
has only a single element?