kilacoda / chanim

Animation engine for explanatory chemistry videos

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NameError: name 'self' is not defined

Kaffejunge opened this issue · comments

Hey I am a beginner in python and I tried your chanim library and it does not work for me. Also it compiles some of your tests as seen in the first 2 lines.
The output I get is:

[4]H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-OH
[4]H-C(-[2]H)(-[6]H)-COOH
Traceback (most recent call last):
File "C:\Users<username>\Anaconda3\envs\math_venv\lib\runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "C:\Users<username>\Anaconda3\envs\math_venv\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "D:\AutomatisierungSubgroupstuff\Python\Real_Prog\manim_projects\manim.py", line 5, in
manimlib.main()
File "D:\AutomatisierungSubgroupstuff\Python\Real_Prog\manim_projects\manimlib_init
.py", line 11, in main
config = manimlib.config.get_configuration(args)
File "D:\AutomatisierungSubgroupstuff\Python\Real_Prog\manim_projects\manimlib\config.py", line 185, in get_configuration
module = get_module(args.file)
File "D:\AutomatisierungSubgroupstuff\Python\Real_Prog\manim_projects\manimlib\config.py", line 180, in get_module
spec.loader.exec_module(module)
File "", line 728, in exec_module
File "", line 219, in _call_with_frames_removed
File "FLN_color.py", line 43, in
class Chem(Scene):
File "FLN_color.py", line 45, in Chem
self.play(Write(Ass))
NameError: name 'self' is not defined


My Code:

from manimlib.imports import *
from chanimlib.imports import *

class Chem(Scene):
test = ChemObject("A-B")
self.play(Write(test))


Also your ChemObject() class has no init() function.

Hello!

The reason you're getting the first error is because you're writing a Manim Scene wrong. You have to write it like this, with the animation code in a construct function:

class Chem(Scene):
    def construct(self):
        test=ChemObject("A-B")
        self.play(Write(test))

As for an __init__ function, the reason for that is because ChemObject inherits everything from TexMobject while changing a few properties (the CONFIG stuff) so you don't have to worry about that.

Also, that chemfig code that comes at the top shouldn't be there, sorry. That was because of me trying to provide some out of the box shorthands for common compounds. I've begun work on cleaning up this repo so you won't have to worry about that in the future.

(P.S. sorry for a late reply)