Re: Assignment and comparison in one statement

2008-05-30 Thread alex23
On May 30, 7:39 pm, Lie <[EMAIL PROTECTED]> wrote: > An example is python's notion for 'for' loop, which can > only loop a list[...] Actually, the for statement steps through any object that provides an iterator interface. Lists just happen to be one such object type. -- http://mail.python.org/ma

Re: Assignment and comparison in one statement

2008-05-30 Thread Lie
On May 24, 5:59 am, Johannes Bauer <[EMAIL PROTECTED]> wrote: > Hello group, > > I'm just starting with Python and am extremely unexperienced with it so > far. Having a strong C/C++ background, I wish to do something like > > if (q = getchar()) { >         printf("%d\n", q); > > } > > or translated

Re: Assignment and comparison in one statement

2008-05-25 Thread TheSaint
On 19:14, sabato 24 maggio 2008 Johannes Bauer wrote: > Well, I do not really see your point You wrote C statements and I felt that you were trying to apply to python interpreter. I think that a minimun of knoweledge on python grammar it's the base for doing some programming. If your examples were

Re: Assignment and comparison in one statement

2008-05-24 Thread Carl Banks
On May 24, 7:12 am, Johannes Bauer <[EMAIL PROTECTED]> wrote: > Carl Banks schrieb: > > > p = myfunction() > > if p: > > print p > > > (I recommend doing it this way in C, too.) > > This is okay for if-clauses, but sucks for while-loops: > > while (fgets(buf, sizeof(buf), f)) { > printf

Re: Assignment and comparison in one statement

2008-05-24 Thread William McBrine
On Sat, 24 May 2008 13:12:13 +0200, Johannes Bauer wrote: > char *tmp; > tmp = fgets(buf, sizeof(buf), f); > while (tmp) { > printf("%s\n", buf); > tmp = fgets(buf, sizeof(buf), f); > } I think a more Pythonic way to write this, in general, would be: while (1) { char *tmp = fgets

Re: Assignment and comparison in one statement

2008-05-24 Thread Grant Edwards
On 2008-05-23, Johannes Bauer <[EMAIL PROTECTED]> wrote: > I'm just starting with Python and am extremely unexperienced with it so > far. Having a strong C/C++ background, I wish to do something like > > if (q = getchar()) { > printf("%d\n", q); > } > > or translated to Python: > > if (p =

Re: Assignment and comparison in one statement

2008-05-24 Thread Paul McGuire
On May 24, 6:12 am, Johannes Bauer <[EMAIL PROTECTED]> wrote: > Carl Banks schrieb: > > > p = myfunction() > > if p: > >     print p > > > (I recommend doing it this way in C, too.) > > This is okay for if-clauses, but sucks for while-loops: > > while (fgets(buf, sizeof(buf), f)) { >         printf

Re: Assignment and comparison in one statement

2008-05-24 Thread Jarek Zgoda
Johannes Bauer pisze: > I'm just starting with Python and am extremely unexperienced with it so > far. Having a strong C/C++ background, I wish to do something like > > if (q = getchar()) { > printf("%d\n", q); > } > > or translated to Python: > > if (p = myfunction()): > print p > > H

Re: Assignment and comparison in one statement

2008-05-24 Thread Marc 'BlackJack' Rintsch
On Sat, 24 May 2008 13:13:08 +0200, Johannes Bauer wrote: > George Sakkis schrieb: > >>> However, this "assignment and comparison" is not working. What's the >>> "Python way" of doing this kind of thing? >> >> The most obvious and readable of course: use two statements, as one >> should do regar

Re: Assignment and comparison in one statement

2008-05-24 Thread Marc 'BlackJack' Rintsch
On Sat, 24 May 2008 13:12:13 +0200, Johannes Bauer wrote: > Carl Banks schrieb: > >> p = myfunction() >> if p: >> print p >> >> (I recommend doing it this way in C, too.) > > This is okay for if-clauses, but sucks for while-loops: > > while (fgets(buf, sizeof(buf), f)) { > printf("%s

Re: Assignment and comparison in one statement

2008-05-24 Thread Johannes Bauer
TheSaint schrieb: On 06:59, sabato 24 maggio 2008 Johannes Bauer wrote: However, this "assignment and comparison" is not working. What's the "Python way" of doing this kind of thing? If you want speak a language that isn't understood mostly you'll face unexpected risults. When you got started

Re: Assignment and comparison in one statement

2008-05-24 Thread Johannes Bauer
George Sakkis schrieb: However, this "assignment and comparison" is not working. What's the "Python way" of doing this kind of thing? The most obvious and readable of course: use two statements, as one should do regardless of the language, instead of resorting to error- prone hacks. As I sai

Re: Assignment and comparison in one statement

2008-05-24 Thread Johannes Bauer
Carl Banks schrieb: p = myfunction() if p: print p (I recommend doing it this way in C, too.) This is okay for if-clauses, but sucks for while-loops: while (fgets(buf, sizeof(buf), f)) { printf("%s\n", buf); } is much shorter than char *tmp; tmp = fgets(buf, sizeof(buf), f); wh

Re: Assignment and comparison in one statement

2008-05-23 Thread TheSaint
On 06:59, sabato 24 maggio 2008 Johannes Bauer wrote: > However, this "assignment and comparison" is not working. What's the > "Python way" of doing this kind of thing? If you want speak a language that isn't understood mostly you'll face unexpected risults. When you got started with C/C++, were

Re: Assignment and comparison in one statement

2008-05-23 Thread George Sakkis
On May 23, 6:59 pm, Johannes Bauer <[EMAIL PROTECTED]> wrote: > Hello group, > > I'm just starting with Python and am extremely unexperienced with it so > far. Having a strong C/C++ background, I wish to do something like > > if (q = getchar()) { >         printf("%d\n", q); > > } > > or translated

Re: Assignment and comparison in one statement

2008-05-23 Thread Carl Banks
On May 23, 6:59 pm, Johannes Bauer <[EMAIL PROTECTED]> wrote: > Hello group, > > I'm just starting with Python and am extremely unexperienced with it so > far. Having a strong C/C++ background, I wish to do something like > > if (q = getchar()) { > printf("%d\n", q); > > } > > or translated

Assignment and comparison in one statement

2008-05-23 Thread Johannes Bauer
Hello group, I'm just starting with Python and am extremely unexperienced with it so far. Having a strong C/C++ background, I wish to do something like if (q = getchar()) { printf("%d\n", q); } or translated to Python: if (p = myfunction()): print p However, this "assignment