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,598
  • 3
  • 24
  • 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
  • 59,056
  • 16
  • 119
  • 195
1
>>> print ('\n'.join(['1','2','3','4']))
1
2
3
4
dawg
  • 90,796
  • 20
  • 120
  • 197