Testing for the existence of a field in a class

Posted by Brett on Stack Overflow See other posts from Stack Overflow or by Brett
Published on 2010-04-20T05:37:10Z Indexed on 2010/04/20 5:43 UTC
Read the original article Hit count: 231

Filed under:
|
|
|

Hi, i have a quick question. I have a 2D array that stores an instance of a class. The elements of the array are assigned a particular class based on a text file that is read earlier in the program. Since i do not know without looking in the file what class is stored at a particular element i could refer to a field that doesn't exist at that index (referring to appearance when an instance of temp is stored in that index). i have come up with a method of testing this, but it is long winded and requires a second matrix. Is there a function to test for the existence of a field in a class?

class temp(): name = "default"

class temp1(): appearance = "@"

© Stack Overflow or respective owner

Related posts about python

Related posts about class