Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li><p>Never check <code>type(x) == foo</code>, use <code>isinstance(x, foo)</code> — the former will break if there is a subclass, for instance.</p></li> <li><p>You appear to be maintaining parallel lists. If the order matters, it might make more sense to use a list of tuples instead, so <code>self.values.append((name, description))</code>. If the order does not matter, a dictionary would be better: <code>self.values[name] = description</code> (with the assumption that you don't want duplicate names).</p></li> <li><p>Single letter variables are a no-no.</p></li> <li><p>If you want to call <code>newO</code> with a string or a list, what would the disadvantage be of splitting it into two functions? Perhaps (and I might be wrong) you come from a language with compile-time polymorphism, where a string and a list would be dispatched differently. In reality they are treated as different functions, so in a dynamic language you might split them up like this:</p> <pre><code>def add(self, name, description): ... def add_many(self, name_list, description): for name in name_list: self.add(name, description) </code></pre> <p>It's possible that you don't know a priori whether you have a string or a list, but I hope that's not the case.</p></li> <li><p>Is the case of a single string really different from the case of a list of strings? Why not just use a one-element list, to remove the conditional? You could use varargs as well, to make the syntax more bulletproof:</p> <pre><code>def add_names(self, description, *name_list): for name in name_list: self.add(name, description) </code></pre></li> </ol>
    singulars
    1. This table or related slice is empty.
    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