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


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

Re: intX.__str__() ??

Started byEthan Furman <ethan@stoneleaf.us>
First post2013-02-24 10:04 -0800
Last post2013-02-24 13:54 -0500
Articles 2 — 2 participants

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: intX.__str__() ?? Ethan Furman <ethan@stoneleaf.us> - 2013-02-24 10:04 -0800
    Re: intX.__str__() ?? Roy Smith <roy@panix.com> - 2013-02-24 13:54 -0500

#39769 — Re: intX.__str__() ??

FromEthan Furman <ethan@stoneleaf.us>
Date2013-02-24 10:04 -0800
SubjectRe: intX.__str__() ??
Message-ID<mailman.2422.1361730917.2939.python-list@python.org>
On 02/24/2013 09:29 AM, Michael Torrie wrote:
> On 02/24/2013 09:23 AM, Ethan Furman wrote:
>> On 02/24/2013 07: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___________________
>>
>> This is a good example of why you shouldn't program language X in language Y.
>>
>> For starters, `intX.__str__` should be written as `str(intX)`;
>>
>> For middlers, intX_asString is probably not necessary (is it being printed? then
>> do a `print intX`, or a `print "size left on disk: %d" % intX`, etc.
>>
>> For finishers, why the System Hungarian Notation?
>
> I think he's maintaining existing code.  It's unfortunate that his first
> exposure to python is code written by someone else in such a poor style,
> and in a way that definitely isn't pythonic.  No wonder he's struggling
> to like python!

On the bright side, if this is one of his 2000 line scripts, he should be able to get it down
to at least half that once he has a good feel for Python and re-writes it.


> Another way to explain the double underscore methods is that they are
> how things like operator overloading is performed.  Want to make a class
> that you can use the [index] notation on instances? Define the
> __get_attr__() method.

Actually, it's the __getitem__ method.

--
~Ethan~

[toc] | [next] | [standalone]


#39771

FromRoy Smith <roy@panix.com>
Date2013-02-24 13:54 -0500
Message-ID<roy-ECABB0.13540124022013@news.panix.com>
In reply to#39769
In article <mailman.2422.1361730917.2939.python-list@python.org>,
 Ethan Furman <ethan@stoneleaf.us> wrote:

> On the bright side, if this is one of his 2000 line scripts, he should be 
> able to get it down
> to at least half that once he has a good feel for Python and re-writes it.

I hope he doesn't get paid by the line :-)

[toc] | [prev] | [standalone]


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


csiph-web