Python Forum
code with no tuple gets : IndexError: tuple index out of range
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
code with no tuple gets : IndexError: tuple index out of range
#1
Hello! I'm in the works of a flask app which I already had issues with and some nice ppl helped me, and am having other issues...

I have this if statement:
if not ((lines[4] == lines[6] == dataseg[0]) & (lines[5] == dataseg[1])):
and I get this error:
Error:
if not ((lines[5] == lines[7] == dataseg[0]) & (lines[6] == dataseg[1])): IndexError: tuple index out of range
The full error being:
Error:
2020-11-03 17:09:58,492] ERROR in app: Exception on /send [POST] Traceback (most recent call last): File "/home/aggam/.local/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app response = self.full_dispatch_request() File "/home/aggam/.local/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request rv = self.handle_user_exception(e) File "/home/aggam/.local/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception reraise(exc_type, exc_value, tb) File "/home/aggam/.local/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise raise value File "/home/aggam/.local/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request rv = self.dispatch_request() File "/home/aggam/.local/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "app.py", line 70, in send return render_template("code.html", ERRS=check.check(code)) File "app.py", line 53, in check if not ((lines[5] == lines[7] == dataseg[0]) & (lines[6] == dataseg[1])): IndexError: tuple index out of range
Can u guys help me? (sry my code is a mess LMAO)

My code: https://pastebin.com/ukMv4nTy
Reply
#2
Without the code, we can't help much. But the error suggests that one of those variables is a tuple and the index is too large.

Before the if you could print the types of them:
print(f"dataseg is of type {type(dataseg)} and has {len(dataseg)} elements.")
print(f"lines is of type {type(lines)} and has {len(lines)} elements.")
That won't tell you why you have a tuple, but it will tell you which one it is and its length.
Reply
#3
(Nov-03-2020, 04:32 PM)bowlofred Wrote: Without the code, we can't help much. But the error suggests that one of those variables is a tuple and the index is too large.

Before the if you could print the types of them:
print(f"dataseg is of type {type(dataseg)} and has {len(dataseg)} elements.")
print(f"lines is of type {type(lines)} and has {len(lines)} elements.")
That won't tell you why you have a tuple, but it will tell you which one it is and its length.

I solved it, thanks !
Reply
#4
Did you really mean to do a bitwise and?
Reply
#5
(Nov-03-2020, 04:32 PM)bowlofred Wrote: Without the code, we can't help much. But the error suggests that one of those variables is a tuple and the index is too large.

Before the if you could print the types of them:
print(f"dataseg is of type {type(dataseg)} and has {len(dataseg)} elements.")
print(f"lines is of type {type(lines)} and has {len(lines)} elements.")
That won't tell you why you have a tuple, but it will tell you which one it is and its length.

I fixed i,Thanks for your help!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to resolve Index Error in my code? codify110 6 325 May-22-2021, 11:04 AM
Last Post: supuflounder
  in a list or tuple Skaperen 6 375 May-16-2021, 09:59 PM
Last Post: Skaperen
  Create SQLite columns from a list or tuple? snakes 6 478 May-04-2021, 12:06 PM
Last Post: snakes
  Sort Function: <' not supported between instances of 'float' and 'tuple' quest 2 342 Apr-30-2021, 07:37 PM
Last Post: quest
  TypeError: __str__ returned non-string (type tuple) Anldra12 1 658 Apr-13-2021, 07:50 AM
Last Post: Anldra12
  AttributeError: 'tuple' object has no attribute 'format' Anldra12 7 1,387 Apr-13-2021, 07:45 AM
Last Post: Anldra12
  IndexError: list index out of range brunolelli 11 852 Mar-25-2021, 11:36 PM
Last Post: brunolelli
  index of range, but data prints out mrc06405j 1 320 Mar-25-2021, 07:20 PM
Last Post: buran
  '|' character within Regex returns a tuple? pprod 10 620 Feb-19-2021, 05:29 PM
Last Post: eddywinch82
  What type of *data* is the name of a list/tuple/dict, etc? alloydog 9 746 Jan-30-2021, 07:11 AM
Last Post: alloydog

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020