OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Initializing variable in a class __init__ [closed]

  • Thread starter Thread starter Pankaj Singh
  • Start date Start date
P

Pankaj Singh

Guest
Code:
class SomeClass( object):
    def __init__( self, number ):
        self.num = number
    INPUTS          = self.num * 2

What am I doing wrong here? I am trying to get a value to INPUTS based on how my class is initialized. it is giving me the error self is not initialized

HERE IS MY QUESTION - How do I invoke the class "SomeClass" so that I can pass a parameter "number" to it and assign that number to INPUTS

UPDATE - BEING MORE EXPLICIT

Code:
class RXPBlotterStyleCollection( object ):
    INPUTS          = _BuildBlotterStyle( _COLOR_BLUE )
    OUTPUTS         = _BuildBlotterStyle( _COLOR_GREEN)

That is the actual original code. My enhancement is to pass a variable in _BuildBlotterStyle(). I am trying to make it work like this.

Code:
class RXPBlotterStyleCollection( object ):
    def __init__( self, bolder):
        self.border = border
    INPUTS = _BuildBlotterStyle( _COLOR_BLUE, self.border )
    OUTPUTS = _BuildBlotterStyle( _COLOR_GREEN, self.border)
<pre><code>class SomeClass( object):
def __init__( self, number ):
self.num = number
INPUTS = self.num * 2
</code></pre>
<p>What am I doing wrong here? I am trying to get a value to INPUTS based on how my class is initialized. it is giving me the error self is not initialized</p>
<p>HERE IS MY QUESTION - How do I invoke the class "SomeClass" so that I can pass a parameter "number" to it and assign that number to INPUTS</p>
<p>UPDATE - BEING MORE EXPLICIT</p>
<pre><code>class RXPBlotterStyleCollection( object ):
INPUTS = _BuildBlotterStyle( _COLOR_BLUE )
OUTPUTS = _BuildBlotterStyle( _COLOR_GREEN)
</code></pre>
<p>That is the actual original code. My enhancement is to pass a variable in _BuildBlotterStyle(). I am trying to make it work like this.</p>
<pre><code>class RXPBlotterStyleCollection( object ):
def __init__( self, bolder):
self.border = border
INPUTS = _BuildBlotterStyle( _COLOR_BLUE, self.border )
OUTPUTS = _BuildBlotterStyle( _COLOR_GREEN, self.border)
</code></pre>
 
Top