TypeError: '_TemporaryFileWrapper' object is not an iterator

Antoon Pardon antoon.pardon at rece.vub.ac.be
Wed Jul 27 10:01:47 EDT 2016


I am rewriting a program so it can work in python3.

I am making progress, but now I stumble on the exception mentioned in
the subject.
The code still works in python2.

What I'm doing is to write the results to temporary file that needs to be
sorted afterwards. For as far as I understand after done writing all to
the file and seeking it to the beginning I get the following when I start
reading from it.

Traceback (most recent call last):
  File "/local/home/apardon/src/fietsroutes/pymain.py", line 132, in main
    Exit_Nr = process(sys.argv)
  File "/local/home/apardon/src/fietsroutes/route.py", line 491, in program
    make_routes(map)
  File "/local/home/apardon/src/fietsroutes/route.py", line 465, in make_routes
    for rt in sortfile(allroutes, load, dump):
  File "/local/home/apardon/src/fietsroutes/filesort.py", line 129, in sortfile
    prv = next(itr)
  File "/local/home/apardon/src/fietsroutes/filesort.py", line 67, in Queuer
    buf = take(21, itr)
  File "/local/home/apardon/src/fietsroutes/filesort.py", line 21, in take
    ls.append(next(iterable))
  File "/local/home/apardon/src/fietsroutes/filesort.py", line 35, in loading
    ln = load(fl)
  File "/local/home/apardon/src/fietsroutes/route.py", line 366, in load
    return greep(next(fl))
TypeError: '_TemporaryFileWrapper' object is not an iterator
Locals by frame, innermost last

Frame main in /local/home/apardon/src/fietsroutes/pymain.py at line 149
                  pn = 'route'
             process = <function program at 0x7f2651a12b70>

Frame program in /local/home/apardon/src/fietsroutes/route.py at line 491
                argv = ['route', '-r', '45']
               index = 3
                 map = {'84Bh': {'83Bh': 17, '01Wo': 42, '85Bm': 37}, '70Rb': {'18Rb': 26, '03Zu': 91, "43Gd'": 33}, "43Gd'": { ...

Frame make_routes in /local/home/apardon/src/fietsroutes/route.py at line 465
               Dists = {'35HS': 204, '91Rt': 208, '79Oi': 492, "61Ch'": 347, '78AP': 479, '33Bt': 444, '241L': 429, '54Rh': 385 ...
           MinLength = 249
              OldMin = 216
           allroutes = <tempfile._TemporaryFileWrapper object at 0x7f2650b09c88>
                dest = '16Pl'
                dist = 58
                last = '86Ll'
           last_time = 1469626452.5767715
                 map = {'84Bh': {'83Bh': 17, '01Wo': 42, '85Bm': 37}, '70Rb': {'18Rb': 26, '03Zu': 91, "43Gd'": 33}, "43Gd'": { ...
                  nr = 29
                nwrt = ('16Pl', '86Ll', '80Wz', '79Bs', '59Bs', '69Vs', "70Vs'", '70Vs"', "78Th'", '78Th"', '48Th', '45Th', '01 ...
               nwtot = 274
                 prv = '80Wz'
               route = ('86Ll', '80Wz', '79Bs', '59Bs', '69Vs', "70Vs'", '70Vs"', "78Th'", '78Th"', '48Th', '45Th', '01Th', '04 ...
               start = '00Th'
               total = 216
               vizor = ''

Frame sortfile in /local/home/apardon/src/fietsroutes/filesort.py at line 129
                  fl = <tempfile._TemporaryFileWrapper object at 0x7f2650b09c88>
                 in1 = <tempfile._TemporaryFileWrapper object at 0x7f2650b09cf8>
                 in2 = <tempfile._TemporaryFileWrapper object at 0x7f2650af6358>
                 itr = <generator object Queuer at 0x7f2650b4e9d8>
                 ou1 = <tempfile._TemporaryFileWrapper object at 0x7f2650af6160>
                 ou2 = <tempfile._TemporaryFileWrapper object at 0x7f2650af6550>
               swaps = 0
                warn = <built-in method write of _io.TextIOWrapper object at 0x7f26535a67e0>

Frame Queuer in /local/home/apardon/src/fietsroutes/filesort.py at line 67
                  fl = <tempfile._TemporaryFileWrapper object at 0x7f2650b09c88>
                 itr = <generator object loading at 0x7f2650b4ec18>

Frame take in /local/home/apardon/src/fietsroutes/filesort.py at line 23
                   _ = 0
            iterable = <generator object loading at 0x7f2650b4ec18>
                  ls = []
                   n = 21

Frame loading in /local/home/apardon/src/fietsroutes/filesort.py at line 40
                  fl = <tempfile._TemporaryFileWrapper object at 0x7f2650b09c88>

Frame load in /local/home/apardon/src/fietsroutes/route.py at line 366
                  fl = <tempfile._TemporaryFileWrapper object at 0x7f2650b09c88>




More information about the Python-list mailing list