简体   繁体   English

Python map v2.7在v3.2中没有长时间工作

[英]Python map v2.7 no long working in v3.2

My code in Python v2.7 is no longer working in Python v3.2 我在Python v2.7中的代码不再适用于Python v3.2

I have searched everywhere but I do not find this case. 我到处搜索,但我没有找到这种情况。 It seems that the function self.buildGraph(i, n) is never actually called 似乎函数self.buildGraph(i, n)实际上从未被调用过

n = 33
map(lambda i : self.buildGraph(i, n), range(n))

however with the function: 但是有了这个功能:

map(lambda x : fu(a, x), range(10))

there is no problem. 没有问题。

在python 3 map中返回lazy iterator对象 ,就像python 2中的imap一样,所以你需要评估你的迭代器,例如:

list(map(lambda i : self.buildGraph(i, n), range(n)))

我没有看到你的一个map示例如何给出你期望的,而另一个没有,但作为一般提示,当使用3.x中的现有2.x代码时 - 使用2to3工具确保地图/过滤器/范围等行为的变化......不要咬你的后方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python(v2.7)格式和打印 - Python (v2.7) format and print Python Wave模块仅在v2.7中工作,而在v3.4 Linux中不工作 - Python wave module only working in v2.7 not in v3.4 linux mysql for python 2. 7说没有找到Python v2.7 - mysql for python 2. 7 says Python v2.7 not found 字符串替换并保存到新文件(Python v2.7) - String Replacement and Saving to a New File (Python v2.7) 将.txt文件处理成字典(Python v2.7) - Process .txt file into dictionary (Python v2.7) python:从v2.7反向移植到v2.4时出现线程问题 - python: Threading issues while backporting to v2.4 from v2.7 Python v2.7请求v2.5.1-所有获取请求均返回HTTP错误503 - Python v2.7 Requests v2.5.1 - all get requests return HTTP Error 503 如何在两个不同的对象中生成线程并在python v2.7中进行协调? - How do I Spawn threads from two different objects and coordinate them in python v2.7? 由于不一致的错误消息,Doctest在Python v2.7中成功,但在Python 2.6中未成功 - Doctest succeeds in Python v2.7 but not with Python 2.6 due to inconsistent error message 如何在Python v2.7中批量读取然后将Weblink .JSON文件列表写入C驱动器上的指定位置 - How to batch read and then write a list of weblink .JSON files to specified locations on C drive in Python v2.7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM