?
Solved

Python function with while loop and raw_input not breaking

Posted on 2014-04-15
1
Medium Priority
?
680 Views
Last Modified: 2014-04-15
Hello there!

I am preparing a small function the gets feed with csv data in a list and db data in other list.

Those lists look like (for a single record):

['Name', 'Surname', 'Other']

I would like to allow the user to compare two values and decide which value to keep.

My while loop goes on forever even if I have break in it...

What am I doing wrong?

def check_fields(fields_csv, fields_db):
        for field_csv in fields_csv:
            for field_db in fields_db:
                if field_csv == field_db:
                    while True:
                        print ""
                        print "1) Dato nel file csv: " + field_csv
                        print "2) Dato nel database: " + field_db
                        print ""
                        answer = str(raw_input("Which field you want to keep? [1 or 2]: "))
                        print ""
                        if answer == "1":
                            print "You choose 1"
                            global field_import
                            field_import = field_csv
                            break
                        elif answer == 2:
                            print "You choose"
                            global field_import
                            field_import = field_db
                            break

Open in new window

0
Comment
Question by:ltpitt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 2000 total points
ID: 40001910
elif answer == "2" ?

answer is a string, so it's should not be equal to a number...
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question