'Returns the order of the expression.
The order is determined either from the O(...) term. If there
is no O(...) term, it returns None.
Examples
>>> from sympy import O
>>> from sympy.abc import x
>>> (1 + x + O(x**2)).getn()
2
>>> (1 + x).getn()'

def getn(self):

    from sympy import Dummy, Symbol
    o = self.getO()
    if (o is None):
        return None
    elif o.is_Order:
        o = o.expr
        if (o is S.One):
            return S.Zero
        if o.is_Symbol:
            return S.One
        if o.is_Pow:
            return o.args[1]
        if o.is_Mul:
            for oi in o.args:
                if oi.is_Symbol:
                    return S.One
                if oi.is_Pow:
                    syms = oi.atoms(Symbol)
                    if (len(syms) == 1):
                        x = syms.pop()
                        oi = oi.subs(x, Dummy('x', positive=True))
                        if (oi.base.is_Symbol and oi.exp.is_Rational):
                            return abs(oi.exp)
    raise NotImplementedError(('not    sure    of    order    of    %s' % o))
