Python

Moderators: None (Apply to moderate this forum)
Number of threads: 400
Number of posts: 1055

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
str.format problem Posted by gibberosh on 22 Dec 2009 at 8:59 AM
I have made a function that will output '{0}' when 0 is given and '{1}' for everything else.

class offset(str):
    def __init__(self,x):
        self.x=x
    def __repr__(self):
        return repr(str({int(bool(self.x))}))
    
    def end(self,end_of_loop):
    #Ignore this def it works how I want it to.
        if self.x==end_of_loop:
            return '{2}'
        else:
            return self

What I would like to do is offset(1).format('first', 'next') but that only outputs '1' for some reason. What can I do?



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.