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 8146499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:01:24+00:00 2026-06-06T14:01:24+00:00

Edit: I’m trying to check the user input against a array of allowed inputs

  • 0

Edit:
I’m trying to check the user input against a array of allowed inputs to get a if statement to execute, a simple if you enter 'y' or 'yes' or 1 the code will run, i think i’m using the wrong constructs. 🙁

I have a really simple peiece of code that is meant to run user input against multiple possible conditions in a predefined array:

from spiders import test

run_test_spider = 0
condition = [1, 'yes', 'Yes', 'YES', 'y', 'Y']
x=-1
def spiders():

    for run_test_spider in condition:
        global x
        x=x+1
        if run_test_spider == condition[x]:
            test.main()
            print 'gotcha!'
        print 'running.......'
    print run_test_spider
    print 'hello'



print 'hello would you like to run a test spider?'
print '1,yes,y = Yes I do!!!'
print '0,no,n  = Nope!'
run_test_spider = raw_input(': ')

spiders()

I ran the debugger (pydev) in eclipse and once I input the string n to get a failed condition check, the debugger tells me the input automatically becomes 1, which causes the code to always execute the spider

does anyone know why my inputs are all becoming 1?

This 1 business is what eclipse is showing in its variables field, when I enter the input (once I step the debugger up to that point)

also the console spits out this: when I enter the input during debug:

Traceback (most recent call last):
  File "C:\Program Files\eclipse\plugins\org.python.pydev.debug_2.5.0.2012040618\pysrc\pydevd_comm.py", line 755, in doIt
    result = pydevd_vars.evaluateExpression(self.thread_id, self.frame_id, self.expression, self.doExec)
  File "C:\Program Files\eclipse\plugins\org.python.pydev.debug_2.5.0.2012040618\pysrc\pydevd_vars.py", line 384, in evaluateExpression
    result = eval(compiled, updated_globals, frame.f_locals)
  File "<string>", line 1, in <module>
NameError: name 'n' is not defined
  • 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-06-06T14:01:26+00:00Added an answer on June 6, 2026 at 2:01 pm
    for run_test_spider in condition:
    

    means that run_test_spider will be initialized with each element in condition.
    So you actually check if each item of condition is in it…

    EDIT: So this is your check:

    condition = [1, 'yes' 'y']
    
    def spiders():
    
        if run_test_spider.lower() in condition:
            test.main()
            print 'gotcha!'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: Duplicate of Should Entity Framework Context be Put into Using Statement? I've been
Edit: You can get the full source here: http://pastebin.com/m26693 Edit again: I added some
Edit: I would like to model a 1 to 0:1 relationship between User and
EDIT Leaving this for posterity, but nearly a year later, to get down voted,
EDIT: More detail here. Basically if you 1. open a tab1 to url1 (GET
EDIT: Sorry about ellipsis that's not what I actually have. For declaring an array
EDIT: void print(const int *v, const int size) { FILE *fpIn; fpIn = fopen(char-array.txt,
EDIT: I'd like to get a definitive answer on whether or not it's possible
Edit : Array should be CvMat or IplImage is not an error message specific
I'm trying to create an if statement in PHP that prevents a single post

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.