Re: intX.__str__() ??

Discussion in 'Python' started by Ethan Furman, Feb 24, 2013.

  1. Ethan Furman

    Ethan Furman Guest

    On 02/24/2013 07:46 AM, 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
    Ethan Furman, Feb 24, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Newton

    how to use __str__ and __repr__?

    Jim Newton, Jun 7, 2004, in forum: Python
    Replies:
    15
    Views:
    548
    Peter Maas
    Jun 9, 2004
  2. Dan Sommers
    Replies:
    3
    Views:
    302
    Serge Orlov
    Feb 19, 2005
  3. Michael Torrie

    Re: intX.__str__() ??

    Michael Torrie, Feb 24, 2013, in forum: Python
    Replies:
    0
    Views:
    111
    Michael Torrie
    Feb 24, 2013
  4. Mitya Sirenef

    Re: intX.__str__() ??

    Mitya Sirenef, Feb 24, 2013, in forum: Python
    Replies:
    2
    Views:
    114
    Mitya Sirenef
    Feb 24, 2013
  5. Ethan Furman

    Re: intX.__str__() ??

    Ethan Furman, Feb 24, 2013, in forum: Python
    Replies:
    1
    Views:
    79
    Roy Smith
    Feb 24, 2013
Loading...

Share This Page