Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that you're defining defining <code>vis</code> and <code>bags</code> as part of the class (as "attribute references"), instead of in the constructor. Try this instead:</p> <pre><code>class bfs: def __init__(self, x): self.vis = [] self.bags = [] # etc. </code></pre> <p>The <a href="http://docs.python.org/3/tutorial/classes.html#class-objects" rel="nofollow">documentation for class objects</a> may help:</p> <blockquote> <p>Attribute references use the standard syntax used for all attribute references in Python: obj.name. Valid attribute names are all the names that were in the class’s namespace when the class object was created. So, if the class definition looked like this:</p> <pre><code>class MyClass: """A simple example class""" i = 12345 def f(self): return 'hello world' </code></pre> <p>then MyClass.i and MyClass.f are valid attribute references, returning an integer and a function object, respectively. Class attributes can also be assigned to, so you can change the value of MyClass.i by assignment.</p> </blockquote> <p>There's also a <a href="http://www.diveintopython.net/object_oriented_framework/class_attributes.html" rel="nofollow">Dive Into Python page</a> about this:</p> <blockquote> <p>Class attributes are available both through direct reference to the class and through any instance of the class.</p> <p>Note: In Java, both static variables (called class attributes in Python) and instance variables (called data attributes in Python) are defined immediately after the class definition (one with the static keyword, one without). <strong>In Python, only class attributes can be defined here; data attributes are defined in the <code>__init__</code> method.</strong></p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload