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


Groups > comp.lang.python > #69254

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

From Peter Otten <__peter__@web.de>
Subject Re: Python language hack for C-style programmers [DO NOT USE!] :-)
Date 2014-03-28 08:46 +0100
Organization None
References <20140327110856.14991bb0@bigbox.christie.dr> <CAPTjJmoSEiBEO9fXfwM7mGywty+dT8erBqeu2mpyrxAf12udcw@mail.gmail.com> <lh2jsg$cqu$1@ger.gmane.org> <CAPTjJmoU-Aa_Y2DDHzCyzMNUfNnuV2i2gsHWZP3gKBhzrXjLzw@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.8658.1395992809.18130.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web