AttributeError: module 'itertools' has no attribute 'imap'

Larry Martell larry.martell at gmail.com
Thu Aug 8 12:24:53 EDT 2019


On Thu, Aug 8, 2019 at 12:16 PM Larry Martell <larry.martell at gmail.com> wrote:
>
> On Thu, Aug 8, 2019 at 11:30 AM Peter Otten <__peter__ at web.de> wrote:
> >
> > Larry Martell wrote:
> >
> > > I have some code that is using the pyke package
> > > (https://sourceforge.net/projects/pyke/). That project seems fairly
> > > dead, so asking here.
> > >
> > > There is a pyke function that returns a context manager with an
> > > iterable map. In py2.7 I did this:
> > >
> > > from pyke import knowledge_engine
> > > vasculopathy_engine =
> > > knowledge_engine.engine((rule_base_source_folder,
> > > (compiled_rule_base_folder)))
> > > with vasculopathy_engine.prove_goal(...) as presentationGen:
> > >     for vals, plan in presentationGen:
> > >
> > > But in py3 that fails with: AttributeError: module 'itertools' has no
> > > attribute 'imap'
> >
> > In Python 3 the map() builtin is "lazy", so you can use that instead.
> >
> > > I tried converting presentationGen to a list but get the same error.
> > >
> > > How can I make this work in py3?
> >
> > The problem is in the project rather than in your code -- you have to port
> > pyke to Python 3 before you can use it. If you want to go that route you may
> > give the 2to3 tool a try:
> >
> > $ cat demo.py
> > import itertools
> >
> > for i in itertools.imap(abs, [-1, 1]):
> >     print i
> > $ 2to3 -w demo.py
> > [...]
> > $ cat demo.py
> > import itertools
> >
> > for i in map(abs, [-1, 1]):
> >     print(i)
> > $
>
> Pyke has been ported to py3. Here is the code that returns the data I
> am trying to process:
>
> return map(self.doctor_answer, it)
>
> I don't see anything calling imap.

I grepped through the entire pyke code and imap is not in there.



More information about the Python-list mailing list