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


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

Re: intX.__str__() ??

Started byEthan Furman <ethan@stoneleaf.us>
First post2013-02-24 08:23 -0800
Last post2013-02-24 08:23 -0800
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  Re: intX.__str__() ?? Ethan Furman <ethan@stoneleaf.us> - 2013-02-24 08:23 -0800

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

FromEthan Furman <ethan@stoneleaf.us>
Date2013-02-24 08:23 -0800
SubjectRe: intX.__str__() ??
Message-ID<mailman.2412.1361723520.2939.python-list@python.org>
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?

     intLength1 = 5   # feet
     intLength2 = 13  # centimeters
     .
     .
     .
     intLength1  + intLength2   # oops!

vs

     ftLength1 = 5
     cmLength2 = 13
     .
     .
     .
     ftLength1 + cmLength2  # hey, that's wrong! better throw in a conversion

--
~Ethan~

[toc] | [standalone]


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


csiph-web