data validation when creating an object

R

Rita

I would like to do some data validation when its going to a class.

class Foo(object):
def __init__(self):
pass

I know its frowned upon to do work in the __init__() method and only
declarations should be there.

So, should i create a function called validateData(self) inside foo?

I would call the object like this

x=Foo()
x.validateData()

Is this the preferred way? Is there a way I can run validateData()
automatically, maybe put it in __init__? Or are there other techniques
people use for this sort of thing?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top