roemhildtg roemhildtg - 1 year ago 79
Python Question

How can I convert a list to named variables in Python?

Is there a quick way in python to convert a list of values to named variables?

For example:

row = ['files', 'file.pdf', 'D1234', 43]

folder = row[0]
name = row[1]
doc_id = row[2]
page_num = row[3]

Answer Source

You can use unpacking

folder, name, doc_id, page_num = row
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download