Answer the question
In order to leave comments, you need to log in
IndexError: list index out of range why so?
There is such a file, which contains such data as: game, login, password.
Next, we need the computer to output like this:
Game: .. Login: .. Password: ..
The code is like this:
import os
import csv
from tkinter import *
import tkinter as tk
from tkinter import filedialog
import webbrowser as web
def close_window():
global login
login = login_entry.get()
root.destroy()
def choose_file():
global file_path
file_path = filedialog.askopenfilename(filetypes = [("CSV", ".csv")])
root = Tk()
root.title('Пароли')
root.geometry('400x260')
login_label = Label(root, text = 'Введите логин')
login_label.pack(anchor = CENTER)
login_entry = Entry(root)
login_entry.pack(anchor = CENTER)
Button_choose_file = Button(root, text = "Выбрать файл" , command =choose_file)
Button_choose_file.pack(anchor = S)
Button = Button(root, text = "Начать" , command =close_window)
Button.pack()
root.mainloop()
with open (file_path , 'r') as f:
a = csv.reader(f, delimiter = ';')
s = 0
data_csv_read = ""
for i in a:
s+=1
game_csv , login_csv , password_csv = i
data_csv_read.append((game_csv, login_csv, password_csv))
games_len = len(data_csv_read)
print(data_csv_read)
print(games_len)
games_len = int(games_len)
for i in range(games_len):
game_plus = int(0)
login_plus = int(1)
password_plus = int(2)
print('Игра: ' + str(data_csv_read[game_plus]) + " Логин: " + str(data_csv_read[login_plus]) + " Пароль: " + str(data_csv_read[password_plus]))
game_plus += 1
login_plus += 1
password_plus += 1
Traceback (most recent call last):
File "D:\!all\rm\passwordik.py", line 55, in <module>
print('Игра: ' + str(data_csv_read[game_plus]) + " Логин: " + str(data_csv_read[login_plus]) + " Пароль: " + str(data_csv_read[password_plus]))
IndexError: list index out of range
Answer the question
In order to leave comments, you need to log in
Well, you clearly wrote list index out of range. Have you tried to translate this expression? What about understanding?
You have two entries in the file.
Here data_csv_read[password_plus] you probably think that you are accessing the "password" field of your current record? In fact, you are accessing the second element of the data_csv_read list, because you wrote password_plus = int(2) beforehand. Those. in fact we have
and you have only two such records. obviously it was necessary to write something like
But this, of course, is not all the problems that you have.
To put it mildly, this fragment causes bewilderment:
data_csv_read[2]
data_csv_read[i][password_plus]
for i in range(games_len):
game_plus = int(0)
login_plus = int(1)
password_plus = int(2)
..........
game_plus += 1
login_plus += 1
password_plus += 1
data_csv_read = ""
data_csv_read.append((game_csv, login_csv, password_csv))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question