Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #69254 > unrolled thread

Re: Python language hack for C-style programmers [DO NOT USE!] :-)

Started byPeter Otten <__peter__@web.de>
First post2014-03-28 08:46 +0100
Last post2014-03-28 08:46 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Python language hack for C-style programmers [DO NOT USE!] :-) Peter Otten <__peter__@web.de> - 2014-03-28 08:46 +0100

#69254 — Re: Python language hack for C-style programmers [DO NOT USE!] :-)

FromPeter Otten <__peter__@web.de>
Date2014-03-28 08:46 +0100
SubjectRe: Python language hack for C-style programmers [DO NOT USE!] :-)
Message-ID<mailman.8658.1395992809.18130.python-list@python.org>
Chris Angelico wrote:

> On Fri, Mar 28, 2014 at 12:44 PM, Dave Angel <davea@davea.name> wrote:
>>> if (array m = Regexp.split2(some_pattern, some_string))
>>>     do_something(m);
>>>
>>
>> I don't know for certain about if, but you can declare (in C++) a
>>  new variable in for, which is a superset of if. Scope ends when
>>  the for does.
> 
> Yeah, but only a for, AFAIK. Not an if or a while.

Why would you guess if you can check? Just fire up the interactive 
interpreter^W^W compiler:

$ cat ifdecl.c
#include <stdio.h>

int main()
{
  if(int i=42)
    printf("%d\n", i);
}
$ gcc ifdecl.c
ifdecl.c: In function ‘main’:
ifdecl.c:5:6: error: expected expression before ‘int’
   if(int i=42)
      ^
ifdecl.c:6:20: error: ‘i’ undeclared (first use in this function)
     printf("%d\n", i);
                    ^
ifdecl.c:6:20: note: each undeclared identifier is reported only once for 
each function it appears in
$ g++ ifdecl.c
$ ./a.out 
42

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web