Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #39463 > unrolled thread
| Started by | Piterrr <piterrr.dolinski@gmail.com> |
|---|---|
| First post | 2013-02-21 13:26 -0800 |
| Last post | 2013-02-25 19:37 -0800 |
| Articles | 20 on this page of 161 — 34 participants |
Back to article view | Back to comp.lang.python
Python Newbie Piterrr <piterrr.dolinski@gmail.com> - 2013-02-21 13:26 -0800
Re: Python Newbie Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-21 14:54 -0700
Re: Python Newbie MRAB <python@mrabarnett.plus.com> - 2013-02-21 21:58 +0000
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-22 08:59 +1100
Re: Python Newbie Peter Pearson <ppearson@nowhere.invalid> - 2013-02-21 22:03 +0000
Re: Python Newbie Dave Angel <davea@davea.name> - 2013-02-21 17:22 -0500
Re: Python Newbie piterrr.dolinski@gmail.com - 2013-02-21 14:40 -0800
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-22 10:21 +1100
Re: Python Newbie piterrr.dolinski@gmail.com - 2013-02-21 15:34 -0800
Re: Python Newbie Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-02-21 23:48 +0000
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-22 11:32 +1100
Re: Python Newbie Michael Torrie <torriem@gmail.com> - 2013-02-23 11:58 -0700
Re: Python Newbie piterrr.dolinski@gmail.com - 2013-02-21 15:34 -0800
Re: Python Newbie Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-21 23:27 +0000
Re: Python Newbie Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-21 16:55 -0700
Re: Python Newbie rusi <rustompmody@gmail.com> - 2013-02-21 22:57 -0800
Re: Python Newbie Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-22 10:26 +0000
Re: Python Newbie Steve Simmons <square.steve@gmail.com> - 2013-02-22 12:05 +0100
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-22 22:23 +1100
Re: Python Newbie Michael Torrie <torriem@gmail.com> - 2013-02-23 16:04 -0700
Re: Python Newbie Vito De Tullio <vito.detullio@gmail.com> - 2013-02-24 09:23 +0100
Re: Python Newbie "J.R." <groups_jr-1@yahoo.com.br> - 2013-02-24 23:02 -0300
Re: Python Newbie Roy Smith <roy@panix.com> - 2013-02-24 21:03 -0500
Re: Python Newbie "J.R." <groups_jr-1@yahoo.com.br> - 2013-02-24 23:35 -0300
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-25 13:31 +1100
Re: Python Newbie Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-02-21 19:35 -0500
Re: Python Newbie Mitya Sirenef <msirenef@lightbird.net> - 2013-02-21 23:50 -0500
Re: Python Newbie Rui Maciel <rui.maciel@gmail.com> - 2013-02-22 11:58 +0000
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-22 23:12 +1100
Re: Python Newbie Rui Maciel <rui.maciel@gmail.com> - 2013-02-22 13:50 +0000
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-23 01:05 +1100
Re: Python Newbie Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-23 00:03 +0000
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-23 11:21 +1100
Re: Python Newbie Duncan Booth <duncan.booth@invalid.invalid> - 2013-02-22 14:26 +0000
Re: Python Newbie Steve Simmons <square.steve@gmail.com> - 2013-02-22 15:45 +0100
Re: Python Newbie Duncan Booth <duncan.booth@invalid.invalid> - 2013-02-22 15:02 +0000
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-23 02:06 +1100
Re: Python Newbie piterrr.dolinski@gmail.com - 2013-02-22 13:37 -0800
Re: Python Newbie Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-22 22:08 +0000
Re: Python Newbie Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-22 15:45 -0700
Re: Python Newbie piterrr.dolinski@gmail.com - 2013-02-22 15:38 -0800
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-23 11:17 +1100
Re: Python Newbie Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-02-23 13:29 -0500
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-24 08:38 +1100
Re: Python Newbie Michael Torrie <torriem@gmail.com> - 2013-02-23 15:52 -0700
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-24 10:18 +1100
Re: Python Newbie piterrr.dolinski@gmail.com - 2013-02-23 15:46 -0800
Re: Python Newbie Larry Hudson <orgnut@yahoo.com> - 2013-02-23 20:20 -0800
Re: Python Newbie Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-02-24 14:34 +0000
Re: Python Newbie piterrr.dolinski@gmail.com - 2013-02-24 07:46 -0800
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-25 02:52 +1100
Re: Python Newbie Roy Smith <roy@panix.com> - 2013-02-24 11:22 -0500
Re: Python Newbie Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-24 17:44 +0000
Re: Python Newbie piterrr.dolinski@gmail.com - 2013-02-24 11:29 -0800
Re: Python Newbie Joshua Landau <joshua.landau.ws@gmail.com> - 2013-02-24 21:35 +0000
Re: Python Newbie piterrr.dolinski@gmail.com - 2013-02-24 14:43 -0800
Re: Python Newbie Joel Goldstick <joel.goldstick@gmail.com> - 2013-02-24 18:05 -0500
Re: Python Newbie Joshua Landau <joshua.landau.ws@gmail.com> - 2013-02-24 23:13 +0000
Re: Python Newbie piterrr.dolinski@gmail.com - 2013-02-24 14:43 -0800
Re: Python Newbie Larry Hudson <orgnut@yahoo.com> - 2013-02-26 00:32 -0800
Re: Python Newbie rurpy@yahoo.com - 2013-02-26 10:23 -0800
Re: Python Newbie Ethan Furman <ethan@stoneleaf.us> - 2013-02-26 10:59 -0800
Re: Python Newbie rurpy@yahoo.com - 2013-02-26 13:30 -0800
Re: Python Newbie Michael Torrie <torriem@gmail.com> - 2013-02-24 18:31 -0700
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-25 09:08 +1100
Re: Python Newbie Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-24 23:18 +0000
Re: Python Newbie Joshua Landau <joshua.landau.ws@gmail.com> - 2013-02-24 22:51 +0000
Re: Python Newbie piterrr.dolinski@gmail.com - 2013-02-24 15:38 -0800
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-25 10:45 +1100
Re: Python Newbie Ethan Furman <ethan@stoneleaf.us> - 2013-02-24 15:53 -0800
Re: Python Newbie piterrr.dolinski@gmail.com - 2013-02-24 16:08 -0800
Re: Python Newbie Joshua Landau <joshua.landau.ws@gmail.com> - 2013-02-25 00:28 +0000
Re: Python Newbie Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-02-25 00:38 +0000
Re: Python Newbie Ethan Furman <ethan@stoneleaf.us> - 2013-02-24 16:33 -0800
Re: Python Newbie Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-25 00:45 +0000
Re: Python Newbie Roy Smith <roy@panix.com> - 2013-02-24 19:50 -0500
Re: Python Newbie Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-25 01:04 +0000
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-25 12:27 +1100
Re: Python Newbie Michael Torrie <torriem@gmail.com> - 2013-02-24 18:42 -0700
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-25 12:24 +1100
Re: Python Newbie Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-25 01:44 +0000
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-25 12:53 +1100
Re: Python Newbie MRAB <python@mrabarnett.plus.com> - 2013-02-25 02:23 +0000
Re: Python Newbie Ethan Furman <ethan@stoneleaf.us> - 2013-02-24 18:59 -0800
Re: Python Newbie piterrr.dolinski@gmail.com - 2013-02-24 16:08 -0800
Re: Python Newbie Roy Smith <roy@panix.com> - 2013-02-24 19:42 -0500
Re: Python Newbie piterrr.dolinski@gmail.com - 2013-02-24 15:38 -0800
Re: Python Newbie Joshua Landau <joshua.landau.ws@gmail.com> - 2013-02-24 23:21 +0000
Re: Python Newbie Dave Angel <davea@davea.name> - 2013-02-24 17:47 -0500
Re: Python Newbie Serhiy Storchaka <storchaka@gmail.com> - 2013-02-25 14:40 +0200
Re: Python Newbie piterrr.dolinski@gmail.com - 2013-02-24 07:46 -0800
Re: Python Newbie Michael Torrie <torriem@gmail.com> - 2013-02-23 22:23 -0700
Re: Python Newbie MRAB <python@mrabarnett.plus.com> - 2013-02-24 00:11 +0000
Re: Python Newbie Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-02-24 12:37 -0500
Re: Python Newbie Michael Torrie <torriem@gmail.com> - 2013-02-24 10:56 -0700
Re: Python Newbie Roy Smith <roy@panix.com> - 2013-02-24 13:07 -0500
Re: Python Newbie Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-02-24 21:01 -0500
Re: Python Newbie piterrr.dolinski@gmail.com - 2013-02-22 15:38 -0800
Re: Python Newbie Terry Reedy <tjreedy@udel.edu> - 2013-02-22 20:04 -0500
Re: Python Newbie rurpy@yahoo.com - 2013-02-22 18:48 -0800
Re: Python Newbie Mitya Sirenef <msirenef@lightbird.net> - 2013-02-22 20:47 -0500
Re: Python Newbie Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-23 02:02 +0000
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-23 13:18 +1100
Re: Python Newbie Grant Edwards <invalid@invalid.invalid> - 2013-02-24 18:19 +0000
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-25 07:25 +1100
Re: Python Newbie Mitya Sirenef <msirenef@lightbird.net> - 2013-02-22 21:40 -0500
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-23 13:48 +1100
Re: Python Newbie Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-02-23 02:59 +0000
Re: Python Newbie Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-02-23 13:34 -0500
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-24 08:40 +1100
Re: Python Newbie Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-02-24 12:41 -0500
Re: Python Newbie Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-23 04:13 +0000
Re: Python Newbie Serhiy Storchaka <storchaka@gmail.com> - 2013-02-23 11:48 +0200
Re: Python Newbie Rui Maciel <rui.maciel@gmail.com> - 2013-02-23 12:30 +0000
Re: Python Newbie Steve Simmons <square.steve@gmail.com> - 2013-02-23 16:43 +0100
Re: Python Newbie jmfauth <wxjmfauth@gmail.com> - 2013-02-23 10:44 -0800
Re: Python Newbie Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-23 12:13 -0700
Re: Python Newbie Ethan Furman <ethan@stoneleaf.us> - 2013-02-23 11:08 -0800
Re: Python Newbie jmfauth <wxjmfauth@gmail.com> - 2013-02-23 12:53 -0800
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-24 08:48 +1100
Re: Python Newbie Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-02-24 00:02 +0000
Re: Python Newbie Michael Torrie <torriem@gmail.com> - 2013-02-23 12:16 -0700
Re: Python Newbie Matej Cepl <mcepl@redhat.com> - 2013-02-24 00:06 +0100
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-24 02:51 +1100
Re: Python Newbie Matej Cepl <mcepl@redhat.com> - 2013-02-24 00:04 +0100
Re: Python Newbie Ethan Furman <ethan@stoneleaf.us> - 2013-02-23 08:32 -0800
Re: Python Newbie Steve Simmons <square.steve@gmail.com> - 2013-02-23 18:39 +0100
Re: Python Newbie Michael Torrie <torriem@gmail.com> - 2013-02-23 12:19 -0700
Re: Python Newbie Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-02-24 17:11 +0000
Re: Python Newbie piterrr.dolinski@gmail.com - 2013-02-24 11:40 -0800
Re: Python Newbie Mitya Sirenef <msirenef@lightbird.net> - 2013-02-24 15:06 -0500
Re: Python Newbie "Michael Ross" <gmx@ross.cx> - 2013-02-24 21:33 +0100
Re: Python Newbie MRAB <python@mrabarnett.plus.com> - 2013-02-24 20:34 +0000
Re: Python Newbie Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-02-24 20:41 +0000
Re: Python Newbie Ethan Furman <ethan@stoneleaf.us> - 2013-02-24 12:34 -0800
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-25 07:42 +1100
Re: Python Newbie Roy Smith <roy@panix.com> - 2013-02-24 15:48 -0500
Re: Python Newbie Joshua Landau <joshua.landau.ws@gmail.com> - 2013-02-24 21:58 +0000
Re: Python Newbie Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-02-24 21:08 -0500
Re: Python Newbie Joshua Landau <joshua.landau.ws@gmail.com> - 2013-02-25 02:59 +0000
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-25 07:47 +1100
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-25 07:58 +1100
Re: Python Newbie Roy Smith <roy@panix.com> - 2013-02-24 16:08 -0500
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-25 08:44 +1100
Re: Python Newbie Mitya Sirenef <msirenef@lightbird.net> - 2013-02-24 17:40 -0500
Re: Python Newbie Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-25 01:11 +0000
Re: Python Newbie Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-25 00:42 +0000
Re: Python Newbie Michael Torrie <torriem@gmail.com> - 2013-02-24 18:34 -0700
Re: Python Newbie Ethan Furman <ethan@stoneleaf.us> - 2013-02-24 14:33 -0800
Re: Python Newbie Albert Hopkins <marduk@letterboxes.org> - 2013-02-24 18:32 -0500
Re: Python Newbie Chris Angelico <rosuav@gmail.com> - 2013-02-25 10:44 +1100
Re: Python Newbie Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-25 01:06 +0000
Re: Python Newbie piterrr.dolinski@gmail.com - 2013-02-24 11:40 -0800
Re: Python Newbie piterrr.dolinski@gmail.com - 2013-02-22 13:37 -0800
Re: Python Newbie Mitya Sirenef <msirenef@lightbird.net> - 2013-02-22 20:05 -0500
Re: Python Newbie Gene Heskett <gheskett@wdtv.com> - 2013-02-23 12:32 -0500
Re: Python Newbie Steve Simmons <square.steve@gmail.com> - 2013-02-23 19:10 +0100
Re: Python Newbie Michael Torrie <torriem@gmail.com> - 2013-02-23 11:40 -0700
Re: Python Newbie Michael Torrie <torriem@gmail.com> - 2013-02-23 12:15 -0700
Re: Python Newbie Gene Heskett <gheskett@wdtv.com> - 2013-02-23 17:49 -0500
Re: Python Newbie Nick Mellor <thebalancepro@gmail.com> - 2013-02-25 19:37 -0800
Page 3 of 9 — ← Prev page 1 2 [3] 4 5 6 7 8 9 Next page →
| From | piterrr.dolinski@gmail.com |
|---|---|
| Date | 2013-02-22 15:38 -0800 |
| Message-ID | <8eadd52c-d533-4333-8c7f-7bf3a6d7b046@googlegroups.com> |
| In reply to | #39621 |
Hi Ian, Thanks for typing all this for me. Really useful. I did some googling of my own and I found that there was no concept of boolean in older versions of Python like you said. (BTW, how does this omission go well with proper language design, as Oscar seems to have hinted?) I think this obvious shortcomming is the main reason that, for example, when x holds the value of 5, x is considered to be "true". You see, I have to maintain Python files (ubuntu server scripts) which are 2000 lines long, all sequential code, no functions. While the person who wrote them should be shot :), the fact that there is inherent ambiguity with value, none, null 0, you name it, in conditional statements is not helping me understand the code, and this adds to my frustration. I messed up my if (some statement): # short form in the example I gave, but you figured exactly what I mean. Of course if the condition (some statement) is boolean there is no point adding "== true" or similar. But if (some statement) represents a value this is where I have trouble and again the origins of this date back to when Python had no boolean type. So now at least I understand it. Btw, there are still languages with no boolean type today, MySQL for one. This creates big efficiency problems when fetching data from the database into a C# program - what should be a bool is fetched as an 8-byte integer! But that's a different story. I shut up now. As I said I am new to Python, learning it, I have to get more experience with passing parameter values to functions, as I do with mostly everything else. Cheers. Peter
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-02-23 11:17 +1100 |
| Message-ID | <mailman.2315.1361578681.2939.python-list@python.org> |
| In reply to | #39627 |
On Sat, Feb 23, 2013 at 10:38 AM, <piterrr.dolinski@gmail.com> wrote:
> I think this obvious shortcomming is the main reason that, for example, when x holds the value of 5, x is considered to be "true". You see, I have to maintain Python files (ubuntu server scripts) which are 2000 lines long, all sequential code, no functions. While the person who wrote them should be shot :), the fact that there is inherent ambiguity with value, none, null 0, you name it, in conditional statements is not helping me understand the code, and this adds to my frustration.
When you want to clearly ask if something is the specific value True,
you can do that thus:
if x is True:
That's the canonical ("pythonic") way to explicitly check for a
boolean value, in the same way that PHP scripts test
strpos(...)===FALSE.
> Btw, there are still languages with no boolean type today, MySQL for one. This creates big efficiency problems when fetching data from the database into a C# program - what should be a bool is fetched as an 8-byte integer! But that's a different story. I shut up now.
It's really not that big a deal to have or not have an explicit
boolean type. Ultimately, the CPU is going to work with integers,
booleans, strings, and so on, in the same way, and that most likely
will be an integer of at least 4 bytes in size - the "machine word"
for your architecture. Asking for anything smaller comes with a
performance hit. So it's easier to store and manage booleans as 4-byte
or 8-byte integers containing either 1 or 0, than to have some kind of
"bit" type - unless we're talking about a *set* of booleans, which is
sometimes implemented as bitflags.
Really, there are worse things in the world. Don't get het up about
boolean types. :)
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2013-02-23 13:29 -0500 |
| Message-ID | <mailman.2364.1361644177.2939.python-list@python.org> |
| In reply to | #39627 |
On Fri, 22 Feb 2013 15:38:53 -0800 (PST), piterrr.dolinski@gmail.com
declaimed the following in gmane.comp.python.general:
> if (some statement): # short form
>
> in the example I gave, but you figured exactly what I mean. Of course if the condition (some statement) is boolean there is no point adding "== true" or similar. But if (some statement) represents a value this is where I have trouble and again the origins of this date back to when Python had no boolean type. So now at least I understand it.
>
Python isn't the only language that will treat non-Boolean as
Boolean, though applying it to strings, floats, other objects may be an
extension (and one which does simplify a lot of code, in my view).
Error codes under DEC VAX/VMS used odd integers for
"success/information" and even integers for "warning/error" (been too
many years, I think positive integers were success/warning, negative
integers were information/error; I could also be wrong on which set were
even... if 0 were no-info/success then odd were errors and even were
success)).
The VAX instruction set only used the least significant bit for
Boolean checks, so one could do a fast check by
if (retCode) then
#assume odd are errors
#examine for "correctible" error codes
#or dump an exception
else
#assume we don't care for specific info messages
#a la: tape already at beginning, if the operation was a rewind
#do normal processing
end if
> Btw, there are still languages with no boolean type today, MySQL for one. This creates big efficiency problems when fetching data from the database into a C# program - what should be a bool is fetched as an 8-byte integer! But that's a different story. I shut up now.
>
SQL itself did not define a Boolean type until the 1999 standard --
and in that standard, Boolean is an optional feature.
http://en.wikipedia.org/wiki/Boolean_data_type#SQL
Apparently few database engines implement a true Boolean.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-02-24 08:38 +1100 |
| Message-ID | <mailman.2378.1361655535.2939.python-list@python.org> |
| In reply to | #39627 |
On Sun, Feb 24, 2013 at 5:29 AM, Dennis Lee Bieber <wlfraed@ix.netcom.com> wrote: > Error codes under DEC VAX/VMS used odd integers for > "success/information" and even integers for "warning/error" (been too > many years, I think positive integers were success/warning, negative > integers were information/error; I could also be wrong on which set were > even... if 0 were no-info/success then odd were errors and even were > success)). Sounds like IBM DB2 and sqlca.sqlcode - 0 for success, <0 for error, >0 for warning (or in some cases "status" - an SQLCODE of 100 means "end of result set", which isn't exactly an error but you can't fetch any more from it; it's akin to Python raising StopIteration to terminate a for loop). ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2013-02-23 15:52 -0700 |
| Message-ID | <mailman.2384.1361659960.2939.python-list@python.org> |
| In reply to | #39627 |
On 02/23/2013 02:38 PM, Chris Angelico wrote: > On Sun, Feb 24, 2013 at 5:29 AM, Dennis Lee Bieber > <wlfraed@ix.netcom.com> wrote: >> Error codes under DEC VAX/VMS used odd integers for >> "success/information" and even integers for "warning/error" (been too >> many years, I think positive integers were success/warning, negative >> integers were information/error; I could also be wrong on which set were >> even... if 0 were no-info/success then odd were errors and even were >> success)). > > Sounds like IBM DB2 and sqlca.sqlcode - 0 for success, <0 for error, >> 0 for warning (or in some cases "status" - an SQLCODE of 100 means > "end of result set", which isn't exactly an error but you can't fetch > any more from it; it's akin to Python raising StopIteration to > terminate a for loop). All apps that return an error code to the operating system return 0 for success, any other value for error. All command-line utilities work this way, all shells, etc. Even Windows command-line apps work this way (errorlevel is what they call it).
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-02-24 10:18 +1100 |
| Message-ID | <mailman.2386.1361661496.2939.python-list@python.org> |
| In reply to | #39627 |
On Sun, Feb 24, 2013 at 9:52 AM, Michael Torrie <torriem@gmail.com> wrote: > On 02/23/2013 02:38 PM, Chris Angelico wrote: >> On Sun, Feb 24, 2013 at 5:29 AM, Dennis Lee Bieber >> <wlfraed@ix.netcom.com> wrote: >>> Error codes under DEC VAX/VMS used odd integers for >>> "success/information" and even integers for "warning/error" (been too >>> many years, I think positive integers were success/warning, negative >>> integers were information/error; I could also be wrong on which set were >>> even... if 0 were no-info/success then odd were errors and even were >>> success)). >> >> Sounds like IBM DB2 and sqlca.sqlcode - 0 for success, <0 for error, >>> 0 for warning (or in some cases "status" - an SQLCODE of 100 means >> "end of result set", which isn't exactly an error but you can't fetch >> any more from it; it's akin to Python raising StopIteration to >> terminate a for loop). > > All apps that return an error code to the operating system return 0 for > success, any other value for error. All command-line utilities work > this way, all shells, etc. Even Windows command-line apps work this way > (errorlevel is what they call it). Yep, the 0 = success part is pretty much universal (it's been said that the cause of the downfall of the Roman empire was that, lacking zero, they were unable to succeed at anything), but the notion of negative for errors and positive for warnings isn't as clear; errorlevels and Unix return codes are positive-only. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | piterrr.dolinski@gmail.com |
|---|---|
| Date | 2013-02-23 15:46 -0800 |
| Message-ID | <f3ee335b-4d77-467d-8194-3335ed8200d7@googlegroups.com> |
| In reply to | #39721 |
Hi all, (Ethan, I like your "resident troll" statement. Highly exit-aining!) Thanks for all the input. I did not expect to get so much constructive feedback, the more so that my initial attitude towards Python has been less than positive, diplomatically speaking. Yes, it's true that I am trying to write C# code in Python. It is not going to change any time soon, if at all - I have done too much C#ing, C++ing before that and C-ing earlier still. What surprises me a bit is that no one has said one word against C#, as a form of retaliation against me not being in love with Python. And C# does have its share of concerns, like any language. So far I like the community a lot better than Python. I am trying to learn some Python on my own (besides faffing with it on the job, to use a britishizm). I have discovered today there is no do...while type loop. [Sigh] Peter
[toc] | [prev] | [next] | [standalone]
| From | Larry Hudson <orgnut@yahoo.com> |
|---|---|
| Date | 2013-02-23 20:20 -0800 |
| Message-ID | <W8qdneRWZO-KCLTMnZ2dnUVZ_hqdnZ2d@giganews.com> |
| In reply to | #39722 |
On 02/23/2013 03:46 PM, piterrr.dolinski@gmail.com wrote:
> Hi all,
>
<snip>
> ... I have discovered today there is no do...while type loop. [Sigh]
>
No biggie. This is easily simulated with:
while True:
...
if <exit condition>:
break
Less easily simulated is the lack of a switch/case structure. This has to be done with a less
convenient extended if/elif/.../else structure.
> Peter
>
-=- Larry -=-
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2013-02-24 14:34 +0000 |
| Message-ID | <mailman.2405.1361716464.2939.python-list@python.org> |
| In reply to | #39733 |
On 24/02/2013 04:20, Larry Hudson wrote: > On 02/23/2013 03:46 PM, piterrr.dolinski@gmail.com wrote: >> Hi all, >> > <snip> >> ... I have discovered today there is no do...while type loop. [Sigh] >> > No biggie. This is easily simulated with: > > while True: > ... > if <exit condition>: > break > > Less easily simulated is the lack of a switch/case structure. This has > to be done with a less convenient extended if/elif/.../else structure. Or a dict, there are umpteen recipes showing how to do this. > >> Peter >> > > -=- Larry -=- > -- Cheers. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | piterrr.dolinski@gmail.com |
|---|---|
| Date | 2013-02-24 07:46 -0800 |
| Message-ID | <b5c95f18-fe40-4e92-8dc3-49aa0bf4ee98@googlegroups.com> |
| In reply to | #39746 |
Hi guys, Question. Have this code intX = 32 # decl + init int var intX_asString = None # decl + init with NULL string var intX_asString = intX.__str__ () # convert int to string What are these ugly underscores for? _________________str___________________ Peter
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-02-25 02:52 +1100 |
| Message-ID | <mailman.2410.1361721167.2939.python-list@python.org> |
| In reply to | #39750 |
On Mon, Feb 25, 2013 at 2:46 AM, <piterrr.dolinski@gmail.com> wrote:
> Hi guys,
>
> Question. Have this code
>
> intX = 32 # decl + init int var
> intX_asString = None # decl + init with NULL string var
>
> intX_asString = intX.__str__ () # convert int to string
>
> What are these ugly underscores for? _________________str___________________
Normally you don't need them. Write it this way:
intX_asString = str(intX)
The "dunder" methods ("d"ouble "under"score, leading and trailing),
also called "magic methods", are the implementations of various
special features. For instance, indexing foo[1] is implemented using
the __getitem__ method. Here's a list:
http://docs.python.org/3.3/reference/datamodel.html#special-method-names
You'll seldom, if ever, call these methods directly.
By the way, when you're asking a completely new question, it usually
helps to do so as a brand new thread (not a reply) and with a new
subject line. Otherwise, you risk people losing the new question among
the discussion of the old.
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Roy Smith <roy@panix.com> |
|---|---|
| Date | 2013-02-24 11:22 -0500 |
| Message-ID | <roy-7367BC.11223624022013@news.panix.com> |
| In reply to | #39752 |
In article <mailman.2410.1361721167.2939.python-list@python.org>,
Chris Angelico <rosuav@gmail.com> wrote:
> The "dunder" methods ("d"ouble "under"score, leading and trailing),
> also called "magic methods", are the implementations of various
> special features. For instance, indexing foo[1] is implemented using
> the __getitem__ method. Here's a list:
>
> http://docs.python.org/3.3/reference/datamodel.html#special-method-names
>
> You'll seldom, if ever, call these methods directly.
On the other hand, once you get into building your own classes, you will
often be *writing* them. The most common are __str__(), __repr__(), and
__unicode__(), and of course, __init__().
A quick look over my current project shows 471 classes, and I've defined:
1 __del__
1 __getattr__
1 __iter__
1 __new__
2 __cmp__
2 __len__
3 __ne__
4 __contains__
9 __eq__
14 __str__
38 __unicode__
62 __repr__
140 __init__
Not to mention the boilerplate:
if __name__ == '__main__":
which shows up all over the place.
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-02-24 17:44 +0000 |
| Message-ID | <512a5199$0$29998$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #39750 |
On Sun, 24 Feb 2013 07:46:07 -0800, piterrr.dolinski wrote:
> Hi guys,
>
> Question. Have this code
>
> intX = 32 # decl + init int var
> intX_asString = None # decl + init with NULL string var
>
> intX_asString = intX.__str__ () # convert int to string
>
> What are these ugly underscores for?
> _________________str___________________
To demonstrate that the person who wrote this code was not a good Python
programmer. I hope it wasn't you :-) This person obviously had a very
basic, and confused, understanding of Python.
And, quite frankly, was probably not a very good programmer of *any*
language:
- poor use of Hungarian notation for variable names;
- pointless pre-declaration of values;
- redundant comments that don't explain anything.
If that code came from the code-base you are maintaining, no wonder you
don't think much of Python! That looks like something I would expect to
see at the DailyWTF.
http://thedailywtf.com/
The above code is better written as:
x = 32
x_asString = str(x)
Double-underscore methods are used for operator overloading and
customizing certain operations, e.g. __add__ overloads the + operator.
You might define a class with a __str__ method to customize converting
the object to a string:
# Toy example.
class MyObject:
def __str__(self):
return "This is my object"
But you would not call the __str__ method directly. (I won't say "never",
because there are rare, advanced, uses for calling double-underscore
methods directly.) You would use a public interface, such as the str()
function.
--
Steven
[toc] | [prev] | [next] | [standalone]
| From | piterrr.dolinski@gmail.com |
|---|---|
| Date | 2013-02-24 11:29 -0800 |
| Message-ID | <5a3bf25b-a08b-4084-a940-e1fd05a1045d@googlegroups.com> |
| In reply to | #39762 |
> To demonstrate that the person who wrote this code was not a good Python > > programmer. I hope it wasn't you :-) This person obviously had a very > > basic, and confused, understanding of Python. > > > > And, quite frankly, was probably not a very good programmer of *any* > > language: > > > > - poor use of Hungarian notation for variable names; > > - pointless pre-declaration of values; > > - redundant comments that don't explain anything. > > > > If that code came from the code-base you are maintaining, no wonder you > > don't think much of Python! That looks like something I would expect to > > see at the DailyWTF. Hi. Steve, I don't know where you have been over the past couple of days but it is widely known (if the thread title is any indication) that I am indeed very new to Python, but not new to programming in general. To give a bit of background where I found __str__, I am using a Python IDE called PyScripter. Its Intellisense is full of methods starting and ending with "__", hence the question. Regarding Hungarian notation, I don't use it in any other language but Python and JS. Call it poor, but it helps me to remember what type a variable is. The redundant comments serve the same purpose. As for "pointless predeclaration", it helps me know where in the code I first started using the variable, so I know there are no references to it before then. Peter
[toc] | [prev] | [next] | [standalone]
| From | Joshua Landau <joshua.landau.ws@gmail.com> |
|---|---|
| Date | 2013-02-24 21:35 +0000 |
| Message-ID | <mailman.2441.1361741780.2939.python-list@python.org> |
| In reply to | #39777 |
[Multipart message — attachments visible in raw view] — view raw
On 24 February 2013 19:29, <piterrr.dolinski@gmail.com> wrote:
> Hi. Steve, I don't know where you have been over the past couple of days
> but it is widely known (if the thread title is any indication) that I am
> indeed very new to Python, but not new to programming in general.
>
> To give a bit of background where I found __str__, I am using a Python IDE
> called PyScripter. Its Intellisense is full of methods starting and ending
> with "__", hence the question.
>
> Regarding Hungarian notation, I don't use it in any other language but
> Python and JS. Call it poor, but it helps me to remember what type a
> variable is.
If you can't remember what type a variable is, you're doing something
incorrectly.
> The redundant comments serve the same purpose.
To help you remember the type of the variable?
> intX = 32 # decl + init int var
How is it not obvious that "intX" is an integer *without* the comment?
> X = 32
How is it not obvious that X is an integer?
> intX_asString = None # decl + init with NULL string var
How is it not obvious that intX_asString is an integer (it starts with
"int", duh"... oh wait)
The comment says it's the NULL string, so it's "". F*ck.
It's None. Why? No idea.
> intX_asString = intX.__str__ () # convert int to string
Wait. So why'd you write the previous line?
Just write:
> X_as_string = str(X)
'Cause "str" *always* returns a string. So it's a string. How is that not
obvious?
But then, what's the context?
"X" is a *useless* name. Why are you converting X to a string? I have no
idea. The problem with the code isn't that you could be overwriting "X".
The problem is that your code is contradictory, pretends it's C, has
useless names and doesn't try to be readable.
> As for "pointless predeclaration", it helps me know where in the code I
> first started using the variable, so I know there are no references to it
> before then.
>
Why? Why can't you overwrite old variables? Why can't a variable change
type? If your functions are so large that you're likely to lose track of
what's defined, you have a different problem indeed.
For example:
def floatA_floatB_floatC_to_tupleR(floatA, floatB, floatC): # decl with
floatA, floatB, floatC parameters
floatD = None # decl + init with NULL float var
floatD = ((floatB ** 2) - (4 * floatA * floatC)) # set to B² - 4AC
floatD = floatD ** 0.5 # set to √floatD
floatR1 = None # decl + init with NULL float var
floatR1 = (((- floatB) + floatD) / (2 * floatA)) # set to (-B+D)/(2A)
floatR2 = None # decl + init with NULL float var
floatR2 = (((- floatB) - floatD) / (2 * floatA)) # set to (-B-D)/(2A)
return (floatR1, floatR2)
Versus
def solve_quadratic(a, b, c):
"""Solve a quadratic equation of the form ax² + bx + c = 0
The result will be a tuple of the two results; the results can be equal if
the determinant is 0.
This supports imaginary results for if the determinant is negative."""
# The method used is the quadratic equation:
# http://en.wikipedia.org/wiki/Quadratic_equation
# b² - 4ac
determinant = b**2 - 4*a*c
# ±√(b² - 4ac)
sqrt_determinant = determinant ** 0.5
squareroots = sqrt_determinant, -sqrt_determinant
# -b ± √(b² - 4ac)
fraction_tops = [(-b + d) for d in squareroots]
results = [top/(2*a) for top in fraction_tops]
return results
Which is easier to read? Reading through it you don't just suddenly forget
what the type of "determinant" is (which must be a number because it's a
determinant) or "results" (which is a container since it's plural). The
names tell you.
The useful comments such as "The method used is..." and "±√(b² - 4ac)" give
you context, too, which is a lot more than can be said of
"floatA_floatB_floatC_to_tupleR". For that, I tried to emulate what I saw
in your code.
I'm not a good programmer. But because of that the code I write makes
sense, so I can understand it. Tell the reader what they want to know, not
what they see.
[toc] | [prev] | [next] | [standalone]
| From | piterrr.dolinski@gmail.com |
|---|---|
| Date | 2013-02-24 14:43 -0800 |
| Message-ID | <bf2150ad-93b9-4b76-821b-836ddcd522c1@googlegroups.com> |
| In reply to | #39800 |
Josh, Not thank you for your malicious post. I think you are missing the point here. My source code was just a dummy to offer context for the question I wanted to ask. Further down the line, if I ever feel I don't need to pseudo-declare variables I will stop doing it. But for the moment I am trying to imitate familiar ground. My code as written has no syntax errors, so what's the problem? It is highly unlikely you will ever read any of my Python code - no need to get excited over a few of my lines. And you don't need to answer questions which were not posed, thank you. I wanted Python to register what type of variable I'm after. So I init my vars accordingly, int might be 0, float 0.0 and string with null, err... None. In practice, I wouldn't define an intX_asString var, I would do "str (num)" every time a string representation is needed, provided it isn't a loop, as in that context the expression would probably negatively impact performance in an interpreted language. Peter
[toc] | [prev] | [next] | [standalone]
| From | Joel Goldstick <joel.goldstick@gmail.com> |
|---|---|
| Date | 2013-02-24 18:05 -0500 |
| Message-ID | <mailman.2451.1361747134.2939.python-list@python.org> |
| In reply to | #39808 |
[Multipart message — attachments visible in raw view] — view raw
On Sun, Feb 24, 2013 at 5:43 PM, <piterrr.dolinski@gmail.com> wrote: > Josh, > > Not thank you for your malicious post. > I think you are missing the point here. > > My source code was just a dummy to offer context for the question I wanted > to ask. Further down the line, if I ever feel I don't need to > pseudo-declare variables I will stop doing it. But for the moment I am > trying to imitate familiar ground. > > My code as written has no syntax errors, so what's the problem? It is > highly unlikely you will ever read any of my Python code - no need to get > excited over a few of my lines. > > And you don't need to answer questions which were not posed, thank you. > > I wanted Python to register what type of variable I'm after. So I init my > vars accordingly, int might be 0, float 0.0 and string with null, err... > None. > In a language that defines Names that are bound to objects, there can't be a 'type' inferred. In C or similar, when you delcair the variable you are setting aside the memory to hold something of that type. This is compile time typing. That isn't how python works, so naming something an int will never make it an int. intMe = 'Joel' is totally valid in python. Sticking to ideas like this will hinder understanding of how python works. I suggest taking two hours to study the python documentation at python.org. I don't speak Chinese, but I know that I can't just use a dictionary of English to Chinese and use the same syntax. It won't be Chinese. Get over your prejudice and learn the new language.... or don't, but trying to shoe horn python into the concepts of another language won't help you understand python, it will produce ugly, messy, unsupportable code. > > In practice, I wouldn't define an intX_asString var, I would do "str > (num)" every time a string representation is needed, provided it isn't a > loop, as in that context the expression would probably negatively impact > performance in an interpreted language. > > Peter > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com
[toc] | [prev] | [next] | [standalone]
| From | Joshua Landau <joshua.landau.ws@gmail.com> |
|---|---|
| Date | 2013-02-24 23:13 +0000 |
| Message-ID | <mailman.2452.1361747665.2939.python-list@python.org> |
| In reply to | #39808 |
[Multipart message — attachments visible in raw view] — view raw
On 24 February 2013 22:43, <piterrr.dolinski@gmail.com> wrote: > Josh, > > Not thank you for your malicious post. > Be careful, us programmers do *eventually* catch on to who is a troll, and if you say things like that we may eventually mark you off as just to hostile. I *honestly* meant no malice or insult. If you can't take my word, you can point out what I said that was otherwise. (Then again, you'll have about a week before we really start to notice :P) > I think you are missing the point here. > > My source code was just a dummy to offer context for the question I wanted > to ask. Further down the line, if I ever feel I don't need to > pseudo-declare variables I will stop doing it. But for the moment I am > trying to imitate familiar ground. > > My code as written has no syntax errors, so what's the problem? It is > highly unlikely you will ever read any of my Python code - no need to get > excited over a few of my lines. > You said "Any comments on this before I quit my job?". I commented on how I think you should approach Python in order to appreciate its virtues rather than get stuck in its differences. Again, I am no good programmer, but I think these methods will help you. > And you don't need to answer questions which were not posed, thank you. > Nor do I need to answer questions which were posed. > I wanted Python to register what type of variable I'm after. So I init my > vars accordingly, int might be 0, float 0.0 and string with null, err... > None. > You seem to think that a "null" version of a type is the falsy version. Then: int -> 0 float -> 0. tuple -> () list -> [] And then (*dun dun duuun!*): str -> "" (NOT None, which is a different type) Other people have commented on whether this is a good idea (it's not), so I'll suggest you read those, too. In practice, I wouldn't define an intX_asString var, I would do "str (num)" > every time a string representation is needed, provided it isn't a loop, as > in that context the expression would probably negatively impact performance > in an interpreted language. PS: Guess what str(None) is.
[toc] | [prev] | [next] | [standalone]
| From | piterrr.dolinski@gmail.com |
|---|---|
| Date | 2013-02-24 14:43 -0800 |
| Message-ID | <mailman.2448.1361745810.2939.python-list@python.org> |
| In reply to | #39800 |
Josh, Not thank you for your malicious post. I think you are missing the point here. My source code was just a dummy to offer context for the question I wanted to ask. Further down the line, if I ever feel I don't need to pseudo-declare variables I will stop doing it. But for the moment I am trying to imitate familiar ground. My code as written has no syntax errors, so what's the problem? It is highly unlikely you will ever read any of my Python code - no need to get excited over a few of my lines. And you don't need to answer questions which were not posed, thank you. I wanted Python to register what type of variable I'm after. So I init my vars accordingly, int might be 0, float 0.0 and string with null, err... None. In practice, I wouldn't define an intX_asString var, I would do "str (num)" every time a string representation is needed, provided it isn't a loop, as in that context the expression would probably negatively impact performance in an interpreted language. Peter
[toc] | [prev] | [next] | [standalone]
| From | Larry Hudson <orgnut@yahoo.com> |
|---|---|
| Date | 2013-02-26 00:32 -0800 |
| Message-ID | <_bydnXYqUoiw7rHMnZ2dnUVZ_judnZ2d@giganews.com> |
| In reply to | #39809 |
On 02/24/2013 02:43 PM, piterrr.dolinski@gmail.com wrote:
<snip>
> ... But for the moment I am trying to imitate familiar ground.
<snip>
This is EXACTLY why you're having trouble grasping Python. Python is a different language and
requires a different mind-set and different approach. In this, it is NO different from ANY
other new (to you) programming language.
Of course, don't forget general programming principles -- how to approach a problem, how to
select algorithms, and such. These apply to any language, but the details of syntax and such
ARE different in different languages. Trying to apply these old details to a new language only
hinders your learning process, it definitely does NOT help.
Actually, your comments and questions make me wonder HOW you are trying to learn Python. All
the things you're asking about are clearly and completely discussed in any decent book or
tutorial. It makes me speculate that you're simply trying to use a Python reference instead of
something that actually teaches anything. A reference may give you the rules and syntax, but
not much about how to apply them properly.
Please think about finding some better fundamental material -- there is a LOT available. And
please quit trying to force Python to be something it isn't. That is never going to be
effective and definitely harmful to your learning.
<snip>
> I wanted Python to register what type of variable I'm after...
Python variables do NOT have any data type. The objects they reference have data types.
Variables can be assigned and RE-assigned to any data type at any time. Again, I emphasize,
QUIT THINKING IN ANOTHER LANGUAGE, it simply doesn't work. You might like it if it were so, but
it simply does not match reality.
-=- Larry -=-
[toc] | [prev] | [next] | [standalone]
Page 3 of 9 — ← Prev page 1 2 [3] 4 5 6 7 8 9 Next page →
Back to top | Article view | comp.lang.python
csiph-web