Solved

Python function with while loop and raw_input not breaking

Posted on 2014-04-15
1
631 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
1 Comment
 
LVL 34

Accepted Solution

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

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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Tools to develop a multi-ad screen with Python 2 96
SCP not working 7 61
Python threading 1 61
Python tuple index error 4 64
"The time has come," the Walrus said, "To talk of many things: Of sets--and lists--and dictionaries-- Of variable kinks-- And why you see it changing not-- And why so strange are strings." This part describes how variables and references (see …
Introduction On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced wi…
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 while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now