HI!

I have a problem:
I want to initalize a class by a condition.
For example:

class something:
	def __init__(self,a):
		self.a = a
		if self.a == 0:
			#break initalization
                else:
                        #continue initalization

How do I break the initalization?

Thank u and sorry for my english!

Recommended Answers

All 4 Replies

return

Since __init__() is a method, you can return out of it.

How do you mean?
If i use this:

class A:
      def __init__(self):
           return None
 
a = A()

The class initalized in the same way.

no, in the conditional:

class something:
	def __init__(self,a):
		self.a = a
		if self.a == 0:
			return
                else:
                        #continue initalization

Thank you very much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.