Class with some instruction inside [duplicate]
up vote
-2
down vote
favorite
This question already has an answer here:
Why does a class' body get executed at definition time?
2 answers
I have seen that if I write this code:
class Test:
print("inside class")
def __init__(self):
pass
Test()
I have this output: 'inside class'
It is strange, is a class only a function in python?
It is possible to simulate a class with a function?
python class
marked as duplicate by Håken Lid, Thierry Lathuille, eyllanesc
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 11 at 15:52
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
up vote
-2
down vote
favorite
This question already has an answer here:
Why does a class' body get executed at definition time?
2 answers
I have seen that if I write this code:
class Test:
print("inside class")
def __init__(self):
pass
Test()
I have this output: 'inside class'
It is strange, is a class only a function in python?
It is possible to simulate a class with a function?
python class
marked as duplicate by Håken Lid, Thierry Lathuille, eyllanesc
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 11 at 15:52
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
That code is called as the class body is defined / evaluates
– N Chauhan
Nov 11 at 15:50
Don't forget to indent your code.. as it written now, it is simply a syntax error
– Maor Refaeli
Nov 11 at 15:53
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
This question already has an answer here:
Why does a class' body get executed at definition time?
2 answers
I have seen that if I write this code:
class Test:
print("inside class")
def __init__(self):
pass
Test()
I have this output: 'inside class'
It is strange, is a class only a function in python?
It is possible to simulate a class with a function?
python class
This question already has an answer here:
Why does a class' body get executed at definition time?
2 answers
I have seen that if I write this code:
class Test:
print("inside class")
def __init__(self):
pass
Test()
I have this output: 'inside class'
It is strange, is a class only a function in python?
It is possible to simulate a class with a function?
This question already has an answer here:
Why does a class' body get executed at definition time?
2 answers
python class
python class
edited Nov 11 at 16:00
asked Nov 11 at 15:47
asv
585719
585719
marked as duplicate by Håken Lid, Thierry Lathuille, eyllanesc
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 11 at 15:52
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Håken Lid, Thierry Lathuille, eyllanesc
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 11 at 15:52
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
That code is called as the class body is defined / evaluates
– N Chauhan
Nov 11 at 15:50
Don't forget to indent your code.. as it written now, it is simply a syntax error
– Maor Refaeli
Nov 11 at 15:53
add a comment |
That code is called as the class body is defined / evaluates
– N Chauhan
Nov 11 at 15:50
Don't forget to indent your code.. as it written now, it is simply a syntax error
– Maor Refaeli
Nov 11 at 15:53
That code is called as the class body is defined / evaluates
– N Chauhan
Nov 11 at 15:50
That code is called as the class body is defined / evaluates
– N Chauhan
Nov 11 at 15:50
Don't forget to indent your code.. as it written now, it is simply a syntax error
– Maor Refaeli
Nov 11 at 15:53
Don't forget to indent your code.. as it written now, it is simply a syntax error
– Maor Refaeli
Nov 11 at 15:53
add a comment |
1 Answer
1
active
oldest
votes
up vote
4
down vote
accepted
No, one point in which they differ is the time when their bodies are executed.
Function and method bodies are not executed on import time, but class bodies (even nested class bodies) are.
Demo script:
class Upper:
print('Upper')
class Mid:
print('Mid')
def method(self):
class Low:
print('Low')
print('method')
Output:
$ python3
>>> import demo
Upper
Mid
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
No, one point in which they differ is the time when their bodies are executed.
Function and method bodies are not executed on import time, but class bodies (even nested class bodies) are.
Demo script:
class Upper:
print('Upper')
class Mid:
print('Mid')
def method(self):
class Low:
print('Low')
print('method')
Output:
$ python3
>>> import demo
Upper
Mid
add a comment |
up vote
4
down vote
accepted
No, one point in which they differ is the time when their bodies are executed.
Function and method bodies are not executed on import time, but class bodies (even nested class bodies) are.
Demo script:
class Upper:
print('Upper')
class Mid:
print('Mid')
def method(self):
class Low:
print('Low')
print('method')
Output:
$ python3
>>> import demo
Upper
Mid
add a comment |
up vote
4
down vote
accepted
up vote
4
down vote
accepted
No, one point in which they differ is the time when their bodies are executed.
Function and method bodies are not executed on import time, but class bodies (even nested class bodies) are.
Demo script:
class Upper:
print('Upper')
class Mid:
print('Mid')
def method(self):
class Low:
print('Low')
print('method')
Output:
$ python3
>>> import demo
Upper
Mid
No, one point in which they differ is the time when their bodies are executed.
Function and method bodies are not executed on import time, but class bodies (even nested class bodies) are.
Demo script:
class Upper:
print('Upper')
class Mid:
print('Mid')
def method(self):
class Low:
print('Low')
print('method')
Output:
$ python3
>>> import demo
Upper
Mid
answered Nov 11 at 15:49
timgeb
47.3k116287
47.3k116287
add a comment |
add a comment |
That code is called as the class body is defined / evaluates
– N Chauhan
Nov 11 at 15:50
Don't forget to indent your code.. as it written now, it is simply a syntax error
– Maor Refaeli
Nov 11 at 15:53