TypeError: unhashable type: 'list'

joseph pareti joepareti54 at gmail.com
Wed Oct 23 03:51:47 EDT 2019


I am experimnenting with this (reproducer) code:
pattern_eur    = ['Total amount']
mylines = []                                # Declare an empty list.
with open ('tmp0.txt', 'rt') as myfile:     # Open tmp.txt for reading text.
    for myline in myfile:                   # For each line in the file,
        mylines.append(myline.rstrip('\n')) # strip newline and add to list.
for element in mylines:                     # For each element in the list,
   match_C = re.search(pattern_eur, element)
   if match_C:
     element = element + 2
     print(element)
--------------
the input file being:
$ cat tmp0.txt
line 0
line 1
Total amount

50000.00
linex
line z
line c
Total amount

43598
linekkkk
line m

Total amount

32000
line end -1
line end 0
line end 1
line end 2

------

My intent is to locate the line containing "Total amount", skip the next
line, then print the eur value. The program terminates as follows:
Traceback (most recent call last):
  File "search_then_advance.py", line 8, in <module>
    match_C = re.search(pattern_eur, element)
  File
"c:\Users\joepareti\Miniconda3\pkgs\python-3.7.1-h8c8aaf0_6\lib\re.py",
line 183, in search
    return _compile(pattern, flags).search(string)
  File
"c:\Users\joepareti\Miniconda3\pkgs\python-3.7.1-h8c8aaf0_6\lib\re.py",
line 276, in _compile
    return _cache[type(pattern), pattern, flags]
TypeError: unhashable type: 'list'

Thanks for any insigths --
-- 
Regards,
Joseph Pareti - Artificial Intelligence consultant
Joseph Pareti's AI Consulting Services
https://www.joepareti54-ai.com/
cell +49 1520 1600 209
cell +39 339 797 0644



More information about the Python-list mailing list