path1=r'c:\users\lijia\desktop\test.txt'
f=open(path1,'w')
f.write('this is a example\nmy name is jacky')
f.close()
print(list(map(lambda x:print('Processing:',x),[x for x in open(path1,'r').read()])))
运算结果如下:
不知道为何运行后会在下面产生很多个None,这是什么原因导致的呢?
path1=r'c:\users\lijia\desktop\test.txt'
f=open(path1,'w')
f.write('this is a example\nmy name is jacky')
f.close()
print(list(map(lambda x:print('Processing:',x),[x for x in open(path1,'r').read()])))
运算结果如下:
不知道为何运行后会在下面产生很多个None,这是什么原因导致的呢?
因为你用了print(list(... ,list里是map后的结果,而lambda没有返回值。这样写比较好:
lst=[x for x in open(path1,'r').read()]
def output(x):
print('Processing:',x)
any(map(output,lst))