Is there any way I can create an anonymous object in Python? In Java I would write new ClassName()
, but in Python it does not work
Asked
Active
Viewed 89 times
0

hooman
- 11
- 2
-
3Just calling ClassName() creates an instance, and then you can store these in an array or something. Is that what you want? – SH7890 May 25 '17 at 16:23
-
2What do you mean by "anonymous objects"? Are you asking how to create an object from a class in Python? – juanpa.arrivillaga May 25 '17 at 16:26
-
@AlexvanVliet I don't think this question is actually about anonymous classes... – juanpa.arrivillaga May 25 '17 at 16:26
-
@SH7890 That is exactly what I want, but I had problems after creating new objects in that way (without word `new`) in C++, will it work properly here? – hooman May 25 '17 at 16:27
-
Python != C++, and `new` isn't even a keyword... – juanpa.arrivillaga May 25 '17 at 16:29
-
@juanpa.arrivillaga yeah I thought so but after looking it isn't you're right. I didn't really understand the point of anonymous objects so I thought of anonymous classes, because an "anonymous object" is just an object not linked to a variable – Alex May 25 '17 at 16:30
-
@hooman You can do it that way in python. There is no new operator in python. You can use a list comprehension http://www.pythonforbeginners.com/basics/list-comprehensions-in-python if you want. – SH7890 May 25 '17 at 16:34