Function decorators

2008-09-04 Thread Aigars Aigars
Good day all,

I am learning Python and came up to decorators.

The question is: Why does function FoodList return value None?

The code in attachment.
Thank you,
Aigars

testingVarLogger.py
Description: application/unknown-application-x-python
--
http://mail.python.org/mailman/listinfo/python-list

Cancel instance create

2008-09-06 Thread Aigars Aigars
Good day,

I want MyClass to perform some tests and if them fail, I do not want
instance to be created. 

But in code I wrote instance is created and also has parameters, that
it should not have in case of tests failure.

Is there a way to perform tests in MyClass.__init__ and set instance
to None without any parameters?

I do not want che code outside MyClass.__init__ to know anything
about tests performed, and make decision to allow or prevent instance
creation.  

The code I wrote is:
**
class MyClass():
 def __init__(self):
  self.param = "spam"
  Test = False
   if Test == True: 
  print "Creating
instance..."
   return 
 else:
  print "Instance creation
not allowed..."
  self = None
  return None
a = MyClass()
print a
print a.param
*

Thanks,
Aigars
--
http://mail.python.org/mailman/listinfo/python-list

Re: Cancel instance create

2008-09-06 Thread Aigars Aigars
I do not want code outside my class to perform tests and decide to
create instance or not.
Fredrik Lundh's advice to rise exception works perfectly.

Thanks to all,
Aigars
 Quoting Mohamed Yousef : Ù‹What about no Constructor , and a
custom instancing function that can
 return either None or the instance wanted
 --
 http://mail.python.org/mailman/listinfo/python-list
 

Links:
--
[1] mailto:[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list