A better way is to use .as_numer_denom(), which also works on symbolic
fractions:

In [380]: Rational(3, 4).as_numer_denom()
(3, 4)

In [381]: (x/y).as_numer_denom()
(x, y)

There's also the fraction() function, which does almost the same thing:

In [382]: fraction(Rational(3, 4))
(3, 4)

In [383]: fraction(x/y)
(x, y)

Aaron Meurer

On Tue, Feb 28, 2012 at 11:53 PM, Sean Vig <[email protected]> wrote:
> This is documented in the online docs [1] and in the docstring. If you're
> using ipython, you can use their introspection to check the docstring, for
> example, as '?Rational'. From the docstring:
>
> **Low-level**
>
> Access numerator and denominator as .p and .q:
>
>>>> r = Rational(3,4)
>>>> r
> 3/4
>>>> r.p
> 3
>>>> r.q
> 4
>
> [1] http://docs.sympy.org/0.7.1/index.html
>
> Sean
>
> On Wed, Feb 29, 2012 at 00:48, Gaurav Sathe <[email protected]>
> wrote:
>>
>> If 'f' is a fraction, can someone please tell me how to separate the
>> numerator and denominator of f????  I tried f.numerator and f.denominator
>> but it doesnt seem to work...
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "sympy" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/sympy/-/kvXX5VvGsTAJ.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/sympy?hl=en.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to