CEMETECH
Leading The Way To The Future
Login [Register]
Username:
Password:
Autologin:

Don't have an account? Register now to chat, post, use our tools, and much more.
Latest Headlines
Online Users
There are 91 users online: 7 members, 60 guests and 24 bots.
Members: 16aroth6, Ashbad, chris1729, Link, Piguy-3.14, zeldaking.
Bots: VoilaBot (1), Spinn3r (1), Magpie Crawler (3), Googlebot (19).
RSS & Social Media
SAX
You must log in to view the SAX chat widget
    » Goto page Previous  1, 2
» View previous topic :: View next topic  
Author Message
Kllrnohj


/=\ PH34R |\/|3


Joined: 24 May 2005
Posts: 8189

Posted: 06 Mar 2009 09:29:13 pm    Post subject:

elfprince13 wrote:
Razz so you *do* still have to tell it what kind of formatting you want. granted, being able to pass in an object is a cool, but I'm having trouble envisioning a situation where that would be more useful than the old way of doing it.


Yes, but you don't have to specify the *TYPE* of the object. That is the point. Formatting stays the same regardless of the number's TYPE (indeed, regardless of the object type - classes can handle the format string however they want). The old way requires you to know the type.

Old busted way is basically sprintf - everything breaks if the type is wrong.

And honestly, who wants to remember if they are supposed to use %s or %d or %f or is it %F etc.... Especially in a language like Python where you never care what the type is - right up until you want to print it. I can't tell you how many times I've just done


Code:
print 'blah blah: %s' % str(some_argument)


because I didn't know what the type would be.
_________________
There are only two kinds of programming languages: those people always bitch about and those nobody uses. (Bjarne Stroustrup)
Back to top
elfprince13


OVER NINE THOUSAND!


Joined: 23 May 2005
Posts: 10224
Location: A galaxy far far away......

Posted: 06 Mar 2009 11:17:20 pm    Post subject:

on that note....the only thing that irks me about python occasionally is that when you print an object or try to concatenate it to a string it doesn't automatically call __str__() on the object.
_________________
StickFigure Graphic Productions || VSHI: Vermont Sustainable Heating Initiative


Back to top
calc84maniac


Epic z80 roflpwner


Joined: 01 Aug 2006
Posts: 1503
Location: The ex-planet Pluto

Posted: 06 Mar 2009 11:19:07 pm    Post subject:

It doesn't? O_o That's a new one on me.
_________________
~calc84maniac has spoken.

Projects:
TI-Boy SE
F-Zero
Super Mario (aka Project M)
Back to top
elfprince13


OVER NINE THOUSAND!


Joined: 23 May 2005
Posts: 10224
Location: A galaxy far far away......

Posted: 07 Mar 2009 02:06:46 am    Post subject:

calc84maniac wrote:
It doesn't? O_o That's a new one on me.


nope, or at least not always. For example.


Code:
>>> print sabacc.players
[<sabacc.SabaccPlayer instance at 0x8e698>, <sabacc.SabaccPlayer instance at 0x8e6c0>, <sabacc.SabaccPlayer instance at 0x8e6e8>, <sabacc.SabaccPlayer instance at 0x8e710>]
>>> print [player.__str__() for player in sabacc.players]
['Name: Bob\tCredits: 189', 'Name: Fred\tCredits: 276', 'Name: Sally\tCredits: 335', 'Name: Harold\tCredits: 350']
>>> print sabacc.players[0]
Name: Bob       Credits: 189

_________________
StickFigure Graphic Productions || VSHI: Vermont Sustainable Heating Initiative


Back to top
Kllrnohj


/=\ PH34R |\/|3


Joined: 24 May 2005
Posts: 8189

Posted: 07 Mar 2009 04:08:02 am    Post subject:

elfprince13 wrote:
on that note....the only thing that irks me about python occasionally is that when you print an object or try to concatenate it to a string it doesn't automatically call __str__() on the object.


Of course it doesn't. It calls repr() on it, which in turn invokes the class's __repr__() method.


Code:
>>> class foo:
...     def __repr__(self):
...             return "see?"
...
>>> class bar:
...     def __str__(self):
...             return 'heh'
...
>>> foo()
see?
>>> bar()
<__main__.bar object at 0x027C20B0>
>>> print(foo())
see?
>>> print(bar())
heh
>>>

_________________
There are only two kinds of programming languages: those people always bitch about and those nobody uses. (Bjarne Stroustrup)
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    » Goto page Previous  1, 2
» View previous topic :: View next topic  
Page 2 of 2 » All times are GMT - 5 Hours

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© Copyright 2000-2013 Cemetech & Kerm Martian :: Page Execution Time: 0.026222 seconds.