• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 705
  • Last Modified:

Python function with while loop and raw_input not breaking

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
ltpitt
Asked:
ltpitt
1 Solution
 
Dan CraciunIT ConsultantCommented:
elif answer == "2" ?

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now