I
iMath
why [os.path.join(r'E:\Python', name) for name in []] returns [] ?
please explain it in detail ï¼
please explain it in detail ï¼
[]why [os.path.join(r'E:\Python', name) for name in []] returns [] ? please explain it in detail ï¼
[os.path.join(r'E:\Python', name) for name in []]
why [os.path.join(r'E:\Python', name) for name in []] returns [] ?
please explain it in detail ï¼
iMath said:why [os.path.join(r'E:\Python', name) for name in []] returns [] ?
why [os.path.join(r'E:\Python', name) for name in []] returns [] ?
please explain it in detail ï¼
在 2013å¹´1月29日星期二UTC+8下åˆ9æ—¶21分16秒,iMath写é“:
why [os.path.join(r'E:\Python', name) for name in []] returns [] ? please explain it in detail ï¼[os.path.join(r'E:\Python', name) for name in []]
[]
iMath wrote: > why [os.path.join(r'E:\Python', name) for name in []] returns [] ? Because you are iterating over an empty list, []. That list comprehension is the equivalent of: result = [] for name in []: result.append( os.path.join(r'E:\Python', name) ) Since you iterate over an empty list, the body of the loop never executes, and the result list remains empty. What did you expect it to do? -- Steven
why [os.path.join(r'E:\Python', name) for name in []] returns [] ? please explain it in detail ï¼
在 2013å¹´1月29日星期二UTC+8下åˆ9æ—¶33分26秒,Steven D'Aprano写é“:iMath wrote: > why [os.path.join(r'E:\Python', name) for name in []] returns [] ? Because you are iterating over an empty list, []. That list comprehension is the equivalent of: result = [] for name in []: result.append(os.path.join(r'E:\Python', name) ) Since you iterate over an empty list, the body of the loop never executes, and the result list remains empty. Whatdid you expect it to do? -- Steven
just in order to get the full path name of each file .
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.