Question

I'd like to receive a list of user aliases for the purpose of looking up an email. As of now, I can do this for only 1 input with the following code:

def Lookup(Dict_list):
    user_alias = raw_input("Please enter User Alias: ")
    data = []
    for row in Dict_list:

        #print "row test"
        #print row
        if user_alias in row.values():
            print row


    for row in Dict_list:
        if user_alias == row['_cn6ca']:
                email = row['_chk2m']
                print email
                return email

But I want to be able to have the user enter in an unknown amount of these aliases (probably no more than 10) and store the resulting emails that are looked up in a way that will allow for their placement in a .csv

I was thinking I could have the user enter a list [PaulW, RandomQ, SaraHu, etc...] or have the user enter all aliases until done, in which case they enter 'Done'

How can I alter this code (I'm guessing the raw_data command) to accomplish this?

Was it helpful?

Solution

This will accept input until it reaches an empty line (or whatever sentinel you define).

#! /usr/bin/python2.7

print 'Please enter one alias per line. Leave blank when finished.'
aliases = [alias for alias in iter (raw_input, '') ]
print (aliases)

OTHER TIPS

You can ask the user to enter a list of aliases, separated by spaces, and then split the string:

In [15]: user_aliases = raw_input("Please enter User Aliases: ")
Please enter User Aliases: John Marry Harry

In [16]: for alias in user_aliases.split(): print alias
John
Marry
Harry

In [17]:

In case the user aliases can have spaces in them, ask them to use, say, a comma as a separator and split by that: user_aliases.split(',')

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top