User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 456,530 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,846 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 462 | Replies: 4
Reply
Join Date: Oct 2007
Posts: 3
Reputation: Yee is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Yee Yee is offline Offline
Newbie Poster

initalze class by a condition

  #1  
Oct 7th, 2007
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!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2006
Posts: 562
Reputation: jrcagle is on a distinguished road 
Rep Power: 4
Solved Threads: 72
jrcagle jrcagle is offline Offline
Posting Pro

Re: initalze class by a condition

  #2  
Oct 7th, 2007
return

Since __init__() is a method, you can return out of it.
Reply With Quote  
Join Date: Oct 2007
Posts: 3
Reputation: Yee is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Yee Yee is offline Offline
Newbie Poster

Re: initalze class by a condition

  #3  
Oct 8th, 2007
How do you mean?
If i use this:
class A:
      def __init__(self):
           return None
 
a = A()
The class initalized in the same way.
Last edited by Yee : Oct 8th, 2007 at 3:51 pm.
Reply With Quote  
Join Date: Jul 2006
Posts: 562
Reputation: jrcagle is on a distinguished road 
Rep Power: 4
Solved Threads: 72
jrcagle jrcagle is offline Offline
Posting Pro

Re: initalze class by a condition

  #4  
Oct 9th, 2007
no, in the conditional:

  1. class something:
  2. def __init__(self,a):
  3. self.a = a
  4. if self.a == 0:
  5. return
  6. else:
  7. #continue initalization
Reply With Quote  
Join Date: Oct 2007
Posts: 3
Reputation: Yee is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Yee Yee is offline Offline
Newbie Poster

Re: initalze class by a condition

  #5  
Oct 10th, 2007
Thank you very much!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Python Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Python Forum

All times are GMT -4. The time now is 4:28 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC