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

  • SEARCH
  • Home
  • 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 7575049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:35:22+00:00 2026-05-30T16:35:22+00:00

I have been here for a couple of months learning python from examples, but

  • 0

I have been here for a couple of months learning python from examples, but the time has come to ask one for myself.

I am currently working on a script here at work that scrapes the job queue from a website & sends a notification if a certain condition exists.

The hard part is out of the way & I have the results being split into nested lists, but when I try & search for a specific condition I get an error if it doesn’t exist.

customers = [['00:00:02', 'S3'], ['00:00:46', 'S2']]

[item for item in customers if 'S2' in item[1]]
print('%s %s') % (item[1], item[0])

The condition above works well if there is a ‘S2’ condition, but if there isn’t (because the page im scraping from may not have one) I get an error:

UnboundLocalError: local variable 'item' referenced before assignment

This is probably a very basic question but how can I stop this error from occurring?

  • 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-30T16:35:23+00:00Added an answer on May 30, 2026 at 4:35 pm

    In python 2.x, the variables used inside of list comprehensions (here, item) leaks out of the list comprehension into the surrounding scope. Using it afterwards is not typically a good idea, or clear code. Try something like this:

    filtered_list = [item for item in customers if 'S2' in item[1]]
    for item in filtered_list:
        print('%s %s') % (item[1], item[0])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I suppose similar problem would have been discussed here, but I couldn't find it.
The basics have already been answered here . But is there a pre-built PHP
So, there have been several posts here about importing and saving data from an
There have been many debates about this topic already here, but none of them
I feel like GUID/UUID questions have been done to death here, but I can't
I have been using Uploadify in my PHP application for the last couple months,
I have been programming iPhone SDK for around 6 months but am a bit
Ive only posted on here a couple of times and people have been very
I've been programming the iphone for a couple of months now and have 3
I have been working with ASP.NET MVC for a couple of months now and

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.