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 > > However, this "assignment and comparison" is not working. What's the > "Python way" of doing this kind of thing?
Assignment operation (or, as we prefer calling: "binding value to name") has no boolean value, because it succeeds always. While call to myfunction can return any value, binding it to name p has no value at all. Tell us your objective, so we could show you "proper way" (tm). ;) -- Jarek Zgoda http://zgodowie.org/ "We read Knuth so you don't have to" - Tim Peters -- http://mail.python.org/mailman/listinfo/python-list