Ask Your Question

How to specify the value of variables in a file to be loaded

asked 2020-02-27 07:12:05 +0200

mcmug gravatar image


I encountered the following problem. When I a write a file test.sage with one line:

print a

in the terminal I define a function,

def test2():

When I run test2() in the terminal, I get the error message

NameError: name 'a' is not defined

My question is, how do I specify the value of a in test.sage when I load it?

Thanks in advance!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-02-27 18:03:32 +0200

Juanjo gravatar image

You can declare a as a global variable:

def test2():
    global a

Remember that SageMath now is based on Python 3, so you should write print(a) if you use SageMath 9.0.

edit flag offensive delete link more


thank you <3

mcmug gravatar imagemcmug ( 2020-02-28 03:39:18 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-02-27 07:12:05 +0200

Seen: 429 times

Last updated: Feb 27 '20