0

I have a list which is made by the following code:

[ self.directory + "/" + file for file in os.listdir(self.directory) ]

When i print this list out it appears on one line separated by commas.

How do I split this list so that when printed each listed item appears on its own line?

Thanks in advance

Steve Konves
  • 2,648
  • 3
  • 25
  • 44

2 Answers2

5

Well, if you want the items in a list in separate lines, you could have done

your_list = [ self.directory + "/" + file for file in os.listdir(self.directory) ]

for e in your_list:
    print e

or use str.split

print '\n'.join(your_list)
Abhijit
  • 62,056
  • 18
  • 131
  • 204
1
>>> print ('\n'.join(['1','2','3','4']))
1
2
3
4
dawg
  • 98,345
  • 23
  • 131
  • 206