Graps Graps wrote:
Hi all,

I tried

import aDict
import re
infile = open('text1.txt','rw')
outfile = open('text3.txt','w')
def replace_words(infile, aDict):
    rc=re.compile('|'.join(map(re.
escape, aDict)))
    def translate(match):
         return aDict[match.group(0)]
         return rc.sub(translate, infile)
outfile = replace_words(infile,aDict)

I am thrown with:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in replace_words
TypeError: argument 2 to map() must support iteration

I imported text2.txt , containing python dictionary as aDict.py. I want the replaced values in a separate file text3.txt.

You need to show us exactly what aDict.py contains.  If it looks like this:

   aDict = {
       'a': '1', ...
   }

then you should probably start your program with this:
   from aDict import aDict

--
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to