I have this piece of code:
import os
def listdir(path):
print(os.listdir(path))
print '\n'.join(os.listdir(path))
which returns
['.idea', 'commands', 'testfile.py', '__pycache__']
.idea
commands
testfile.py
__pycache__
None
I do not understand why I get None value on the last line? Thank for any advice.
When you call
listdir, are you trying to print its return value?listdirdoesn't return a value, so if you did that theprintstatement will printNone. Leave out thatprint: