[Tutor] Only appending one object to list, when I am expecting more than 1
Steven D'Aprano
steve at pearwood.info
Tue Feb 26 04:30:23 EST 2019
On Tue, Feb 26, 2019 at 09:09:56AM +0000, AdamC wrote:
> def createObjects(f):
> '''Takes a file object and iterates through entries, passing them to
> create
> object, depending on what object it is.'''
> for line in f:
> count = count + 1
This cannot be the code you are actually using, because that raises
UnboundLocalError. count is never initialised, so that function you give
cannot possibly run as shown.
py> def test():
... count = count + 1
...
py> test()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in test
UnboundLocalError: local variable 'count' referenced before assignment
There's no point us trying to debug code you aren't actually running.
Try again with the actual working code. It might help if you read this:
http://www.sscce.org/
--
Steven
More information about the Tutor
mailing list