Ask Your Question
2

Code working on cocalc but not locally

asked 1 year ago

adi gravatar image

updated 1 year ago

FrédéricC gravatar image

Hello everyone. I'm trying to define a new class on sage (called 'SuperLieAlgebra', for Lie algebras with a graded bracket). The code runs fine on cocalc, but when I download it and run it on sage locally (version 10.0), I get a 'SuperLieAlgebra: Name not defined' error. Any idea why this could be? I suspect it has to do with the fact that on cocalc, I'm working on a .sagews file, but locally it's a .py file that I run-but I'm not sure how to fix this.

Preview: (hide)

Comments

Please provide a minimal code example illustrating the issue.

Max Alekseyev gravatar imageMax Alekseyev ( 1 year ago )

2 Answers

Sort by » oldest newest most voted
1

answered 1 year ago

slelievre gravatar image

Rename your file from .py to .sage.

Then it will be read with all Sage names active.

In a .py file you need to import things explicitly.

Preview: (hide)
link

Comments

The same error persists. Here is the code. Perhaps I'm missing some import?

Interestingly, I also get this error on Cocalc occasionally, but when I delete and repaste the code into the file, it starts running as usual again. I always assumed it was some cocalc-related bug, but maybe not.

adi gravatar imageadi ( 1 year ago )
1

answered 1 year ago

adi gravatar image

Figured it out, it's because I was referring back to the parent class itself when defining the element class (using class Element(SuperLieAlgebra.Element):). The funny thing is it did run on cocalc...

Preview: (hide)
link

Comments

In other words, you were trying to ue your class before defining it.

This kind of mistake is quite easy when interacting with a worksheet, which does not enforce an order of execution.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 1 year ago )

@adi -- you can accept your own answer to mark the question as solved.

slelievre gravatar imageslelievre ( 1 year ago )

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

Stats

Asked: 1 year ago

Seen: 243 times

Last updated: Aug 04 '23