0

I need following structure in python.

public class Circle
{

    int member1;
    int member2;
    int member3;

    public Circle(member1)
    {
      this.member1 = member1;
      initializeRest();    
    }

    private intializeRest()
    {

        //do lot of computation to get result1 & result2
        this.member2 = result2;
        this.member3 = result2;

    }

}
0

2 Answers 2

7
class Circle:
   def __init__(self, member1):
      self.member1=member1
      self.rest()

   def rest(self):
      self.member2=result2
      self.member3=result2
Sign up to request clarification or add additional context in comments.

1 Comment

You could inherit from object to get a new-style class even in Python 2.x.
1

Python does not have enforced private anything; the convention for letting others know that a method/function/class/what-have-you is private is to prefix it with a single leading underscore. Third-party programs can use this, such as auto-documenting systems, and help() in IDLE, to ignore such _names.

Your code would translate like this:

class Circle(object):              # in Python 3 you don't need `object`
    member1 = None                 # not needed since all three are initialized
    member2 = None                 # in __init__, but if you had others that
    member3 = None                 # weren't this is how you would do it
    def __init__(self, member1):
        self.member1=member1
        self._rest()
    def _rest(self):
        # lots of computing....
        self.member2=result2
        self.member3=result2

Given your comments in the code, though, you would be just as well off to make _rest be part of __init__...

class Circle(object):              # in Python 3 you don't need `object`
    def __init__(self, member1):
        self.member1=member1
        # lots of computing....
        self.member2=result2
        self.member3=result2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.