Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexError: list index out of range #13

Open
Devanshi2096 opened this issue Jul 9, 2017 · 4 comments
Open

IndexError: list index out of range #13

Devanshi2096 opened this issue Jul 9, 2017 · 4 comments

Comments

@Devanshi2096
Copy link

I am getting an error in this line of the code as follows:
label = int(filename.split('/')[2])
IndexError: list index out of range

So i tried changing it as follows:
label = (filename.split("\")[2])
label1 = int(label)
Im = Image.open(filename)
pixel = Im.load()
width, height = Im.size
for x in range(0, width):
for y in range(0, height):
data_image.append(pixel[y, x])

		data_label.append(label1)

and i again got error as:
label1 = int(label)
ValueError: invalid literal for int() with base 10: 'im9085.png'

I am using this script on the data given here itself.
How should i solve this error and get all the 4 files required?

@ijbo
Copy link

ijbo commented Jul 12, 2017

label = (filename.split("\")[2]) -->int(filename.split('\\')[1])

@ArtemGuy
Copy link

ArtemGuy commented Mar 6, 2018

@ijbo thank you very much. Can you explain your solution, please. I am new in pyton.

@ShalluSharma
Copy link

ShalluSharma commented Oct 13, 2018

label = (filename.split("\")[2]) -->int(filename.split('\\')[1])

When I using this, it is giving me a syntax error:

File "<ipython-input-11-87b010b918dc>", line 25 label = (filename.split("\")[2])-->int(filename.split('\\')[1]) ^ SyntaxError: EOL while scanning string literal

I am not able to understand what's the problem. Please, help me.

@relgukxilef
Copy link

There's a misunderstanding @ShalluSharma. What @ijbo meant was to replace the "\" with '\\' as the \ is a so called escape character and will be interpreted differently by the interpreter.

Actually, it should not be necessary to use \ in paths at all as using / will usually work as expected on Windows too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants