Solved

Python function with while loop and raw_input not breaking

Posted on 2014-04-15
1
645 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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How best should I print a graphical chess game state with Python? 6 87
Python output problem 10 54
Macports Import Problem 4 60
Trying to run a Python File 11 72
Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
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 strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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 …

803 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