Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameError: name 'self' is not defined #4

Closed
Kaffejunge opened this issue Apr 10, 2020 · 1 comment
Closed

NameError: name 'self' is not defined #4

Kaffejunge opened this issue Apr 10, 2020 · 1 comment

Comments

@Kaffejunge
Copy link

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.

@kilacoda
Copy link
Owner

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants