str.format problem - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

str.format problem

gibberoshgibberosh Posts: 2Member
I have made a function that will output '{0}' when 0 is given and '{1}' for everything else.

[code]
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
[/code]
What I would like to do is offset(1).format('first', 'next') but that only outputs '1' for some reason. What can I do?
Sign In or Register to comment.