Module pypol :: Class Unknown
[show private | hide private]
[frames | no frames]

Type Unknown

object --+
         |
        Unknown


Provide a class representing a monomial unknown. It has only two attributes, degree and letter.

Example:
>>> a = Unknown('x', 2)
>>> a.letter
'x'

>>> a.degree
2

>>> print a
2
x

>>> a.eval(-2)
4

>>> a.newattribute = "test"
Traceback (most recent call last):

    ...

AttributeError: 'Unknown' object has no attribute 'newattribute'

Method Summary
  __init__(self, letter, degree)
Build the unknown with two arguments, letter and degree (default is 1).
  __eq__(self, other)
Check if two Unknown instances are equal.
  __repr__(self)
Return a value that, passed to eval(), should return an Unknown instance equal to self.
  __str__(self)
Return the class instance in a human readable manner
  eval(self, value)
Return the result of value^degree.
  get_degree(self)
Return the degree of the unknown
  get_letter(self)
Return the letter of the unknown
  set_degree(self, degree)
Check if the new degree is a valid integer
  set_letter(self, letter)
Check if letter is one and only one alphabetic char and assign it to self._letter
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value

Property Summary
  degree: Integer representing unknown's degree
  letter: String representing unknown's letter

Class Variable Summary
tuple __slots__ = ('letter', '_letter', 'degree', '_degree')

Method Details

__init__(self, letter, degree=1)
(Constructor)

Build the unknown with two arguments, letter and degree (default is 1).

Example:
>>> a = Unknown('x')
>>> a.letter
'x'

>>> a.degree
1

>>> a.letter = 2
Traceback (most recent call last):

    ...

NotValidLetter: Not a valid unknown letter. It must be one
            and only one alphabetic char

>>> a.letter = "hi"
Traceback (most recent call last):

    ...

NotValidLetter: Not a valid unknown letter. It must be one
            and only one alphabetic char

>>> a.degree = -3
Traceback (most recent call last):

    ...

NotValidDegree: Degree must be a positive integer
Overrides:
__builtin__.object.__init__

__eq__(self, other)
(Equality operator)

Check if two Unknown instances are equal. To be equal they have to have the same letter and the same degree.

Example:
>>> a = Unknown('a', 2)
>>> b = Unknown('a', 1)
>>> c = Unknown('a', 2)
>>> d = Unknown('b', 2)
>>> print a == b
False

>>> print a == c
True

>>> print a == d
False

__repr__(self)
(Representation operator)

Return a value that, passed to eval(), should return an Unknown instance equal to self.

Example:
>>> a = Unknown('x', 2)
>>> b = eval(repr(a))
>>> print a == b
True
Overrides:
__builtin__.object.__repr__

__str__(self)
(Informal representation operator)

Return the class instance in a human readable manner
Overrides:
__builtin__.object.__str__

eval(self, value)

Return the result of value^degree.

Example:
>>> a = Unknown('x', 2)
>>> a.eval(-3)
9

>>> a.eval(2)
4

get_degree(self)

Return the degree of the unknown

get_letter(self)

Return the letter of the unknown

set_degree(self, degree)

Check if the new degree is a valid integer

set_letter(self, letter)

Check if letter is one and only one alphabetic char and assign it to self._letter

Property Details

degree

Integer representing unknown's degree
Get Method:
get_degree(self)
Set Method:
set_degree(self, degree)

letter

String representing unknown's letter
Get Method:
get_letter(self)
Set Method:
set_letter(self, letter)

Class Variable Details

__slots__

Type:
tuple
Value:
('letter', '_letter', 'degree', '_degree')                             

Generated by Epydoc 2.1 on Fri Aug 10 15:00:04 2007 http://epydoc.sf.net