Ask Your Question
2

Code working on cocalc but not locally

asked 2023-07-28 21:25:32 +0200

adi gravatar image

updated 2023-08-01 08:42:52 +0200

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.

edit retag flag offensive close merge delete

Comments

Please provide a minimal code example illustrating the issue.

Max Alekseyev gravatar imageMax Alekseyev ( 2023-07-29 01:05:20 +0200 )edit

2 Answers

Sort by » oldest newest most voted
1

answered 2023-07-29 23:43:14 +0200

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.

edit flag offensive delete link more

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 ( 2023-07-31 05:31:15 +0200 )edit
1

answered 2023-08-04 21:42:34 +0200

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...

edit flag offensive delete link more

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 ( 2023-08-05 07:41:48 +0200 )edit

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

slelievre gravatar imageslelievre ( 2023-08-05 15:48:07 +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

Stats

Asked: 2023-07-28 21:25:32 +0200

Seen: 164 times

Last updated: Aug 04 '23