Home Get all the dictionaries in the file without having to hard code them into a variable
Reply: 0

Get all the dictionaries in the file without having to hard code them into a variable

Radical Edward
1#
Radical Edward Published in 2018-01-09 17:14:14Z

I have a python file formatted like so:

###############
dictionaries
###############

dict0 = {keys....values...info}
.
.
.
dict8 = {keys...values...stuff}


################
functions
################

def get_dicts:
    dicts = dict0, dict1, dict2, dict3, dict4, dict5, dict6, dict7, dict8 # i don't like this
    return dicts

I want to know if there is an existing method in python that will automatically grab all the dictionaries so that I don't have to hard code them into the dicts variable within get_dicts().

Any time I add a new dictionary or delete a dictionary, I don't want to have to have to also update variable in the function. It is a bit messy.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.316361 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO