init inside def

T

targetsmart

Hi,
today I just came across a python code snippet where __init__ was
defined inside a function..
I am not able to understand the reason why

The code snippet was similar like

def func1(a,b):
def __init__():
func2(a,b)
def func2(a,b):
if a == b:
return True
else:
return False
return False

So far I have seen __init__ only used inside class definitions not
inside any function, could somebody tell me how __init__ can be useful
inside a function definition..?

Thanks,
Vivek.
 
B

bruno.desthuilliers

Hi,
today I just came across a python code snippet where __init__ was
defined inside a function..
I am not able to understand the reason why

The code snippet was similar like

def func1(a,b):
  def __init__():
    func2(a,b)
  def func2(a,b):
    if a == b:
      return True
    else:
      return False
  return False

So far I have seen __init__ only used inside class definitions not
inside any function, could somebody tell me how __init__ can be useful
inside a function definition..?

__init__ as an inner function name has no special meaning. And in the
above snippet it happens to to be totally useless since it's not
neither called nor returned nor used in any way. In fact, since func2
is not used neither (and totally braindead FWIW), the above snippet is
functionally equivalent to:

def func1(a, b):
return False

Perhaps the real snippet would make more sense ?
 

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,772
Messages
2,569,593
Members
45,108
Latest member
AlbertEste
Top