ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 30 Oct 2014 19:45:47 +0100Change output to numerical values globallyhttps://ask.sagemath.org/question/24712/change-output-to-numerical-values-globally/ I know how to make sage to output numerical results as described in http://ask.sagemath.org/question/8150/how-to-tell-sage-to-give-numeric-result/
However is there a magic line, a global variable or something like that to make sage output the numerical result directly in the following lines?
For example I don't want to type in
`n(sin(100))`
to get
`-0.506365641109`
or
`n(sqrt(pi()*2))`
to get
`2.50662827463100`
I just want to type `sin(100)` or `sqrt(pi()*2)` to get the numerical result.sagefanThu, 30 Oct 2014 19:45:47 +0100https://ask.sagemath.org/question/24712/injecting names into global namespace doesn't work with doctesthttps://ask.sagemath.org/question/10423/injecting-names-into-global-namespace-doesnt-work-with-doctest/Here is a minimal example of the problem I am running into. I have a file "MyClass.py":
class MyClass(object):
def __init__(self,subscript):
self.subscript = subscript
def __repr__(self):
return "MyClass " + str(self.subscript)
def make_MyClass(n):
"""
Creates n MyClass instances and assigns them to to variables A0, ..., A(n-1).
Examples::
sage: make_MyClass(3)
sage: A0
MyClass 0
sage: A2
MyClass 2
sage: A1.subscript
1
"""
for i in range(n):
globals()["A" + str(i)] = MyClass(i)
If I doctest it, I get `NameError: name 'A0' is not defined`, but if I just load the file and type in the commands, it works how I want it to. It must be something about how globals() interacts with doctest.
I know it is possible to make this work, because for example the function var does something like this. I tried looking at the var.pyx source, but it looks like they are doing the same thing as me. (There is a comment about globals() being the reason that it had to be Cython. I tried making the example above a pyx, but that didn't seem to help.)paragonMon, 12 Aug 2013 17:39:10 +0200https://ask.sagemath.org/question/10423/global variableshttps://ask.sagemath.org/question/8838/global-variables/If I have a global variable N, how can i set N = smth inside of defined function?
def foo()
N = 10
doesn't change global N, because Sage makes N local variable.
MbochkWed, 04 Apr 2012 08:37:24 +0200https://ask.sagemath.org/question/8838/