0

I want to save a list of strings in the python Array. My code is as below:

import os
Images_list=[os.listdir("/home/metal-machine/Pictures/new")]
print Images_list[0]

It only prints the list in the [0] and when I use

print Images_list[1]

It returns the error as: IndexError: list index out of range

I am sure this "index out of range" is because all the elements of list are not separated by comma.

For that I can also use split() method in Python.

images_list.split()

And the above command splits the files but putting commas in-between all of them, but why Python By-default not put commas in between all the elements? Is sunch kind of list is valid in Python?

1
  • I also tried print ', '.join(mylist) Commented Mar 17, 2015 at 4:46

1 Answer 1

1

Why not write code that is a bit more error free

for images in Images_list:
    print images
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.