Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Calling Class Error

$
0
0
Not really an error and yet an error. It doesn't seem to "break" anything or halt the program, but it appeared shortly after the defining of my UI class and prompts as soon as the program is executed. I think it may be the way I imported the graphics module or something but I'm not exactly sure what.

The error that seemingly does nothing but loudly complain.
Traceback (most recent call last):
  File "C:\Python\workbench\2D_astrophysics.py", line 33, in <module>
    class func(object):
  File "C:\Python\workbench\2D_astrophysics.py", line 53, in func
    def set_attractor(self, val = self.G):
NameError: name 'self' is not defined




What code it's complaining about.
import math
from graphics import*

class UI(object):

    def makeWin(self):
        self.win = GraphWin("Vectors", 512, 512)
        self.win.setBackground("black")

    def closeWin(self):
        self.win.close()
        
class func(object):

    def __init__(self):
        self.G = 6.67384*(10**-11)

    def set_foo(self, foo):
        self.foo = foo

    def get_foo(self):
        return self.foo

    def set_bar(self, bar):
        self.bar = bar

    def get_bar(self):
        return self.bar

    ...
    ...
    ...

    def set_attractor(self, val = self.G):
        self.G_const = val

    def get_attractor(self):
        return self.G_const
    ...
    ...
    ...



[edit:]
Actually, it does halt the second class from being operated upon.

>>> x = UI()
>>> y = func()

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    y = func()
NameError: name 'func' is not defined
>>> 


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>