generating unique variable name via loops

Jean-Michel Pichavant jeanmichel at sequans.com
Tue Nov 4 09:38:52 EST 2014


----- Original Message -----
> From: "Fatih Güven" <mfthguven at gmail.com>
> I have a structured and repetitive data. I want to read a .txt file
> line by line and classified it to call easily. For example employee1
> has a name, a salary, shift, age etc. and employee2 and other 101
> employee have all of it.
> 
> Call employee1.name or employee2.salary and assign it to a new
> variable, something etc.

Some python 2.7 pseudo code to give you some leads

employes = {}
with open('file.txt') as f_:
  for line in f_:
    name, age, phone = line.split(',')
    employes[name] = (age, phone)

print employes

If your file is a csv format, it could even be easier using the csv module.

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.


More information about the Python-list mailing list