M-a-S wrote:
[color=blue]
> Why is there the pass statement? I think, the expression statement would be enough:
>
> class C:
> None
>
> while True:
> None
>[/color]
No. None is just a value (now variable), not a statment.
M-a-S wrote:[color=blue]
>
> Why is there the pass statement? I think, the expression statement would be enough:
>
> class C:
> None
>
> while True:
> None[/color]
For readability. Pass makes more sense. You seem to think minimalism
is inherently good... (?)
"M-a-S" <NO-MAIL@hotmail.co m> wrote in message
news:iRI9b.1299 6$x21.4462@twis ter.southeast.r r.com...[color=blue]
> Why is there the pass statement? I think, the expression statement would[/color]
be enough:[color=blue]
>
> class C:
> None
>
> while True:
> None[/color]
You don't actally need Pass. A docstring is sufficient:
"John Roth" <newsgroups@jhr othjr.com> wrote in message news:vmeq2go7e7 fq62@news.super news.com...[color=blue]
>
> You don't actally need Pass. A docstring is sufficient:
>
> class C:
> "this is a class"
>
> while True:
> "loop de loop de loop"
>
> John Roth[/color]
M-a-S wrote:
[color=blue]
> Why is there the pass statement? I think, the expression statement would be enough:
>
> class C:
> None
>
> while True:
> None[/color]
'pass' is a no-op statement that, according to the tutorial, is used when a
statement is required syntactically but the program requires no action.
Your code, using None, has the same effect. However, there's a slight
difference in the bytecode that is generated:
[color=blue][color=green][color=darkred]
>>> def f(): pass[/color][/color][/color]
....[color=blue][color=green][color=darkred]
>>> def g(): None[/color][/color][/color]
....[color=blue][color=green][color=darkred]
>>> import dis
>>> dis.dis(f)[/color][/color][/color]
1 0 LOAD_CONST 0 (None)
3 RETURN_VALUE[color=blue][color=green][color=darkred]
>>> dis.dis(g)[/color][/color][/color]
1 0 LOAD_GLOBAL 0 (None)
3 POP_TOP
4 LOAD_CONST 0 (None)
7 RETURN_VALUE
This is probably irrelevant, but it wouldn't be correct to say that using pass
is exactly the same as using None.
M-a-S wrote:[color=blue]
>
> "John Roth" <newsgroups@jhr othjr.com> wrote in message news:vmeq2go7e7 fq62@news.super news.com...
>[color=green]
>>You don't actally need Pass. A docstring is sufficient:
>>
>>class C:
>> "this is a class"
>>
>>while True:
>> "loop de loop de loop"
>>[/color]
> A good idea! Thanks![/color]
Not a so good idea, since the pass statement is explicit (and explicit
is better than implicit).
Originally posted by M-A-S
[color=blue]
> A good idea! Thanks![/color]
[color=blue]
>[/color]
[color=blue]
> "John Roth" <newsgroups@jhr othjr.com> wrote in message news:vme-
> q2go7e7fq62@new s.supernews.com "]...super news.co-
> m[/url]...[/color]
[color=blue][color=green]
> > You don't actally need Pass. A docstring is sufficient:[/color][/color]
[color=blue][color=green]
> > class C:[/color][/color]
[color=blue][color=green]
> > "this is a class"[/color][/color]
[color=blue][color=green]
> > while True:[/color][/color]
[color=blue][color=green]
> > "loop de loop de loop"[/color][/color]
[color=blue][color=green]
> > John Roth[/color][/color]
I find "pass" shows that something could be there, sort of "insert stuff
here if you like/need to". A string as such doesn't have that effect.
Obviously you could always make up some useless statement instead of
pass, but pass just looks more elegant IMO. You probably should use it
if you plan on showing your code to others.
--
Contact info (decode with rot13): cebwrpg5@bcrenz nvy.pbz
Fcnzserr! Cyrnfr qb abg hfr va choyvp zrffntrf. V ernq gur yvfg, ab arrq gb PP.
"Hans Nowak" <hans@zephyrfal con.org> wrote in message news:mailman.10 63743501.23038. python-list@python.org ...[color=blue]
> 'pass' is a no-op statement that, according to the tutorial, is used when a
> statement is required syntactically but the program requires no action.[/color]
I know. I just state that there is NO need for it. Just define in __builtins__
pass = None and that's it.
BTW Algol-68 used 'skip' for both purposes (no action and no data).
[color=blue]
> Your code, using None, has the same effect. However, there's a slight
> difference in the bytecode that is generated:
>[color=green][color=darkred]
> >>> def f(): pass[/color][/color]
> ...[color=green][color=darkred]
> >>> def g(): None[/color][/color]
> ...[color=green][color=darkred]
> >>> import dis
> >>> dis.dis(f)[/color][/color]
> 1 0 LOAD_CONST 0 (None)
> 3 RETURN_VALUE[color=green][color=darkred]
> >>> dis.dis(g)[/color][/color]
> 1 0 LOAD_GLOBAL 0 (None)
> 3 POP_TOP
> 4 LOAD_CONST 0 (None)
> 7 RETURN_VALUE
>
> This is probably irrelevant, but it wouldn't be correct to say that using pass
> is exactly the same as using None.
>
> HTH,
>
> --
> Hans (hans@zephyrfal con.org)
> http://zephyrfalcon.org/[/color]
That's just a question of optimization.
And thank you for showing me how to dig to the code!
"Andrei" <see@my.signatu re.com> wrote in message news:3377992.10 63747732@dbforu ms.com...[color=blue]
> I find "pass" shows that something could be there, sort of "insert stuff
> here if you like/need to". A string as such doesn't have that effect.
> Obviously you could always make up some useless statement instead of
> pass, but pass just looks more elegant IMO. You probably should use it
> if you plan on showing your code to others.[/color]
I know, I do :-) It's too late to make a revolution.
[color=blue]
> --
> Contact info (decode with rot13): cebwrpg5@bcrenz nvy.pbz
> Fcnzserr! Cyrnfr qb abg hfr va choyvp zrffntrf. V ernq gur yvfg, ab arrq gb PP.
>
>
> Posted via http://dbforums.com[/color]
M-a-S <NO-MAIL@hotmail.co m> wrote:[color=blue]
> Why is there the pass statement? I think, the expression statement would be enough:[/color]
[color=blue]
> class C:
> None[/color]
[color=blue]
> while True:
> None[/color]
Because emacs python-mode knows to dedent the next line after a pass :)
"JCM" <joshway_withou t_spam@myway.ma thworks.com> wrote in message
news:bk9oel$4mu $1@ginger.mathw orks.com...[color=blue]
> M-a-S <NO-MAIL@hotmail.co m> wrote:[color=green]
> > Why is there the pass statement? I think, the expression statement[/color][/color]
would be enough:[color=blue]
>[color=green]
> > class C:
> > None[/color]
>[color=green]
> > while True:
> > None[/color]
>
> Because emacs python-mode knows to dedent the next line after a pass[/color]
:)
Nice.
pass is the guaranteed-to-do-nothing identity statement (function
operating on the interpreter state). def f(): pass generates a
*miminal* function object with a *minimal* code object. This is at
least potentially useful for testing or investigating the
implementation. The alternative of an expression statement adds code
to the code body. The alternative of a doc string generates a string
object attached somewhere to the no-longer-minimal function or code
object. Indeed, the way to test the effect of either alternative is
to start with the minimum and then define f2 and look for the
difference -- as one of the earlier posters in this thread did do
(using dis module to 'look') for the None expression.
Comment