Re: Trying to avoid using the "eval" command/statement

2015-04-15 Thread Henry Versemann
ok. On Wednesday, April 15, 2015 at 3:39:26 PM UTC-5, Vijay Khemlani wrote: > > tblEntryObj seems to be an instance of your model, it is not a dictionary, > so normally it wouldn't have a "keys" method. > > On Wed, Apr 15, 2015 at 5:32 PM, Henry Versemann > wrote: > >>

Re: Trying to avoid using the "eval" command/statement

2015-04-15 Thread Vijay Khemlani
tblEntryObj seems to be an instance of your model, it is not a dictionary, so normally it wouldn't have a "keys" method. On Wed, Apr 15, 2015 at 5:32 PM, Henry Versemann wrote: > Vijay, > > I tried your method, and while it got me the table class that I wanted, > for some

Re: Trying to avoid using the "eval" command/statement

2015-04-15 Thread Henry Versemann
Vijay, I tried your method, and while it got me the table class that I wanted, for some reason when I try to get into the actual list of entries in the desired table, I can't seem to get to either the keys or values of any of the list objects. So I'm not sure what's going on. Here's some

Re: Trying to avoid using the "eval" command/statement

2015-04-15 Thread Henry Versemann
Thanks for the help Stephen. On Wednesday, April 15, 2015 at 11:53:09 AM UTC-5, Stephen Butler wrote: > > Or, if you know all the Model classes are in the same module that > you've imported, it should be as easy as: > > from myapp import models > > model_class = getattr(models, tableName) > >

Re: Trying to avoid using the "eval" command/statement

2015-04-15 Thread Vijay Khemlani
You can use get_model from django.db.models.loading import get_model YourModel = get_model('your_app', tableName) On Wed, Apr 15, 2015 at 2:01 PM, Tim Chase wrote: > On 2015-04-15 09:45, Henry Versemann wrote: > > My problem is since the logic won't know which

Re: Trying to avoid using the "eval" command/statement

2015-04-15 Thread Tim Chase
On 2015-04-15 09:45, Henry Versemann wrote: > 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

Re: Trying to avoid using the "eval" command/statement

2015-04-15 Thread Stephen J. Butler
Or, if you know all the Model classes are in the same module that you've imported, it should be as easy as: from myapp import models model_class = getattr(models, tableName) On Wed, Apr 15, 2015 at 11:50 AM, Stephen J. Butler wrote: > Classes (MyModel) are attributes

Re: Trying to avoid using the "eval" command/statement

2015-04-15 Thread Stephen J. Butler
Classes (MyModel) are attributes of the module (myapp.models). No reason to use eval. You can get the module from importlib and then the class from using getattr() on the module. http://stackoverflow.com/questions/10773348/get-python-class-object-from-string On Wed, Apr 15, 2015 at 11:45 AM,

Trying to avoid using the "eval" command/statement

2015-04-15 Thread Henry Versemann
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

Re: Using the eval() command

2015-03-12 Thread Carl Meyer
Hi Henry, On 03/10/2015 07:37 PM, Henry Versemann wrote: > So how does an expression like you suggested above ( > innerDict['+newinnrkey+'] = newinnrval ) work then? > It seems like it wouldn't work without enclosing the expression > with quotes or double-quotes, and even then it seems like it

Re: Using the eval() command

2015-03-12 Thread Tom Evans
On Wed, Mar 11, 2015 at 1:24 AM, Henry Versemann wrote: > so its valid python code to write the expression > > innerDict['+newinnrkey+'] > > without enclosing the parts outside of the plus-signs surrounding the > "newinnrkey" variable within quotes or double quotes? > I'm

Re: Using the eval() command

2015-03-11 Thread Henry Versemann
Carl, Thanks for the advice and information. I'm certainly going to try it. Thanks again for the help. Henry On Wednesday, March 11, 2015 at 11:05:38 AM UTC-5, Carl Meyer wrote: > Hi Henry, > > On 03/10/2015 07:37 PM, Henry Versemann wrote: > > So how does an expression like you suggested

Re: Using the eval() command

2015-03-10 Thread Henry Versemann
So how does an expression like you suggested above ( innerDict['+newinnrkey+'] = newinnrval ) work then? It seems like it wouldn't work without enclosing the expression with quotes or double-quotes, and even then it seems like it would only become some kind of string instead of a statement

Re: Using the eval() command

2015-03-10 Thread Henry Versemann
so its valid python code to write the expression innerDict['+newinnrkey+'] without enclosing the parts outside of the plus-signs surrounding the "newinnrkey" variable within quotes or double quotes? I'm not sure I've ever heard or seen such python code before anywhere. Can you explain or point

Re: Using the eval() command

2015-03-10 Thread Carl Meyer
Hi Henry, On 03/10/2015 03:25 PM, Henry Versemann wrote: > I have a new dictionary that I want to build, using data from another > dictionary. I have a view which is receiving a single key/value pair > from the original dictionary. Then in the view I've defined the new > dictionary like this: >

Re: Using the eval() command

2015-03-10 Thread Bill Freeman
eval() operates on an expression, not a statement. Assignment makes it a statement. Why wouldn't you just say: innerDict['+newinnrkey+'] = newinnrval On Tue, Mar 10, 2015 at 5:25 PM, Henry Versemann wrote: > I have a new dictionary that I want to build, using data

Using the eval() command

2015-03-10 Thread Henry Versemann
I have a new dictionary that I want to build, using data from another dictionary. I have a view which is receiving a single key/value pair from the original dictionary. Then in the view I've defined the new dictionary like this: innerDict = {} Now I want to make this as dynamic as possible