Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 214275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:21:32+00:00 2026-05-11T18:21:32+00:00

Deep inside my code, in a nested if inside a nested for inside a

  • 0

Deep inside my code, in a nested if inside a nested for inside a class method, I’m comparing a certain index value to the length of a certain list, to validate I can access that index. The code looks something like that:

if t.index_value < len(work_list):
    ... do stuff ...
else:
    ... print some error ...

For clarification, index_value is at least zero (validated somewhere else). To my surprise, even though I know the index_value data is valid, the code keeps going to the “else:” clause. I added some ad-hoc debug code:

print('Checking whether '+str(t.index_value)+"<"+str(len(work_list)))

x = t.index_value
y = len(work_list)

print(x)
print(y)
print(x<y)

if t.index_value < len(work_list):
    ... do stuff ...
else:
    ... print some error ...

Following is the output:

>> Checking whether 3<4
>> 3
>> 4
>> False

Can anyone help me understand what’s going on here?

Further clarifications:

  • work_list is a local variable instantiated within the method
  • t is a class instance, instantiated within the method ( t = SomeClass() )

Update: The problem was that the type of t.index_value was UNICODE and not int. The reason was that I deserialized the contents of t from a text file, where the value of index_value is represented by a single digit character. After I extracted it from the text, I immediately assigned it to index_value, without passing it through int() which it what I should have done, and that solved the problem.

I decided to keep the “controversial” title despite the fact it’s clearly my bug and not Python’s, because people with the same problem may find it using this title.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:21:32+00:00Added an answer on May 11, 2026 at 6:21 pm

    In my experience, what is the type of “t.index_value”? Maybe it is a string “3”.

    >>> print '3' < 4
    False
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 219k
  • Answers 219k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It seems prettey decent and better than average inputvalidation. Personanlly… May 12, 2026 at 11:48 pm
  • Editorial Team
    Editorial Team added an answer I figured it out. First, the missing template is because… May 12, 2026 at 11:48 pm
  • Editorial Team
    Editorial Team added an answer admin.site.unregister(User) admin.site.register(User, YourUserAdmin) May 12, 2026 at 11:48 pm

Related Questions

Given a function, I'm trying to find out the names of the nested functions
I have a function that checks whether a type is a subtype of another
I currently have a page structure that consists of a page(Parent) that includes an
For the longest time, I've been using the following basic formatting for SQL queries

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.