A program to display, update and save a dictionary as .csv I'm now looking for feedback on v2.0 of this program instead.

I'd like some feedback about my code. What bad habits do I have? What advice could help me write more Pythonic?

I'm trying to write a console application and want a tool to display, update and save settings in a dictionary.

def file_as_string(file_name):
    with open(file_name, 'r') as opened_file:
        string = opened_file.read().replace('\n', '')
        return string

def csv_as_dict(file_name):
    file_name = file_name + '.csv'
    import csv
    dictionary = {}
    for key, value in csv.reader(open(file_name)):
        dictionary[key] = value
    return dictionary

def print_formatted_dict(dictionary, key_title , value_title):
    print "{:^30} {:^15}".format('%s', '%s') % (key_title, value_title)
    for setting, value in dictionary.items():
        print "{:&lt;30} {:&lt;15}".format(setting, value)

def generic_prompt(prompt):
    value = raw_input(prompt)
    return value

def prompt_for_item(prompt, item):
    prompt = prompt + ' ' + item + ': '
    value = raw_input(prompt)        
    return value

def change_dict_value(dictionary, prompt, item):
    value = prompt_for_item(prompt, item)
    dictionary[item] = (value)
    return dictionary

def csv_save_dict(dictionary, file_name): 
    file_name = file_name + '.csv'
    import csv
    csv_file = csv.writer(open(file_name, "w"))
    for key, value in dictionary.items():
        csv_file.writerow([key, value])    

def change_dict(dictionary):
    specify_question = 'Specify'
    change_question = 'Change settings? '
    setting_question = 'Setting to change: '
    save_question = 'Save settings? '

    change_answer = generic_prompt(change_question)
    while change_answer not in yes_no:
        change_answer = generic_prompt(change_question)
    while change_answer == 'yes':
        change_item = generic_prompt(setting_question)
        while change_item not in dictionary:
            change_item = generic_prompt(setting_question)
        dictionary = change_dict_value(dictionary, specify_question, change_item)
        print_formatted_dict(dictionary, key_title, value_title)
        change_answer = generic_prompt(change_question)
        while change_answer not in yes_no:
            change_answer = generic_prompt(change_question)
        if change_answer == 'no':
            save_answer = generic_prompt(save_question)
            while save_answer not in yes_no:
                save_answer = generic_prompt(save_question)
            if save_answer == 'yes':
                filename_answer = generic_prompt(filename_question)
                csv_save_dict(dictionary, filename_answer)
    return dictionary

def load_dict(dictionary):
    load_answer = generic_prompt(load_question)
    while load_answer not in yes_no:
        load_answer = generic_prompt(load_question)
    if load_answer == 'yes':
        filename_answer = generic_prompt(filename_question)
        dictionary = csv_as_dict(filename_answer)
        print_formatted_dict(dictionary, key_title, value_title)
    if load_answer == 'no':
        pass
    return (dictionary, load_answer)

def load_change_loop(dictionary, load_answer):
    while load_answer == 'yes':
        dictionary = change_dict(dictionary)
        dictionary, load_answer = load_dict(dictionary)
    return dictionary

def main():
    default_dict = csv_as_dict(default_settings)
    print_formatted_dict(default_dict, key_title, value_title)
    dictionary = load_change_loop(default_dict, load_answer)
    return dictionary

#string variables
default_settings = 'default_settings'
load_question = 'Load a dictionary? '
filename_question = 'File name: '
key_title = 'Setting'
value_title = 'Value'
load_answer = 'yes'

#list variables
yes_no = ['yes', 'no']

main()


The console with highlighted user input looks like this:


The program begins by reading a default_settings.csv file, mine looks like this:
It's a pretty good program for a beginner.

A few points:

Put your import csv once at the top of the file, not in the functions that use csv. Importing is best thought of as an action at the start of your program, not as something that happens while performing an action.

You do this a lot:

while load_answer not in yes_no:
    load_answer = generic_prompt(load_question)
if load_answer == 'yes':


Anytime you find yourself repeating code, it'd be helpful to write a function instead. Something like:

   def ask_boolean_question(prompt):
       answer = ''
       while answer not in yes_no:
           answer = generic_prompt(prompt)
       return answer == 'yes'


Now your code can simply say:

  if ask_boolean_question(load_question):


And avoid repeating the loop everytime you ask a question.

Your program doesn't make its structure very clear. Given what your program does, your main function should read something like:

def main():
    manipulate_settings(default_settings)
    while ask_boolean_question(load_question):
         filename = generic_prompt(filename_question)
         manipulate_settings(filename)


Note that by reading this, you can see the program processes first the default settings, and then as many other settings files as you have inclination to use the program.