0

I'm working on module which saved users' data onto Parse.com cloud. Using Parse.py library, I need to do this:

class Cat:
    pass
cat = Cat()
cat.name = 'Alice'
cat.save()

Where Cat is name of table in cloud.
Is it possible somehow to create class dynamically from string not having it anywhere else before?
Here is suggested, that there's module with pre-defined class.
Here eval is also used on pre-defined class.

So, it it possible to create class dynamicallly in runtime only from string? Something like:

save_data('Alice','myclass')

def upload(cat_name, class_name):
    class_name.name = cat_name
    class_name.save()
Community
  • 1
  • 1
Groosha
  • 2,897
  • 2
  • 22
  • 38
  • 1
    possible duplicate of [How can I dynamically create derived classes from a base class](http://stackoverflow.com/questions/15247075/how-can-i-dynamically-create-derived-classes-from-a-base-class) – Daniel Renshaw Jul 22 '15 at 15:30
  • Looks more like a duplicate of http://stackoverflow.com/questions/547829/how-to-dynamically-load-a-python-class OP is trying to load a class, not create a new one. – Hans Then Jul 22 '15 at 15:35
  • I mean Abstract class, not class with pre-defined arguments And I'm not trying to import it, I'm creating new in runtime – Groosha Jul 22 '15 at 15:40
  • @Kondra007 What exactly do you mean by an abstract class? A class that cannot be instantiated? – Anand S Kumar Jul 22 '15 at 15:45
  • @AnandSKumar I mean: `class Foo: pass` where (in my case) `Foo` is given as string in runtime – Groosha Jul 22 '15 at 15:46

0 Answers0