I have an incoming list of DB table names associated with my application. I 
want to iterate through this list of table names getting all of the 
entries for each table and then print some data from each tables' entry to 
a file. I've tried to write this so I can use it for as many 
app-associated tables as possible.

My problem is since the logic won't know which tables will be in the 
incoming list I need to try to reference the entries in each table 
using some kind of evaluated version of a variable containing the name of 
each table, as I iterate through the list.

I'm sure I could do this using an "eval" statement like this

tblComannd = "tblEntryLst = " + str(tableName) + ".objects.all()"

eval(tblComannd)

but I also know that the "eval" statement is not the safest thing to use.

So far I've tried to reference the table name in the following ways:

tblEntryLst = str(tableName).objects.all()
tblEntryLst = tableName.objects.all()

with no success at all and only an AttributeError exception being the 
result.

I think its possible since I've successfully done some similar things with 
referencing and saving the values of unknown keys for dictionaries similar 
to this:

new_dictionary[str(extracted_key)] = old_dictionary[str(extracted_key)]

but don't know this for sure.

Can someone please confirm if this is indeed possible to do or not, and if 
so give a general format or example for how to do it?

Any help would be much appreciated.

Thanks.

Henry
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e3430efb-7fc2-4baf-931b-6ec8d8580315%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to