Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Why are you putting variables in a single list attribute? Why not make them all class attributes so you can access them by name not number? E.g., <code>self.equations_data</code>, <code>self.accuracy</code>, etc?</p> <p>The problem with your nested loop is that it's too nested. You are iterating over <code>i.session_data[7]</code> n-times, where n is evidently 9, the length of session_data. You'd want something like:</p> <pre><code>for i in saved_sessions: for j in range(len(i.session_data)): if j!=7: y=i.session_data[j] # print out your elements here for x in i.session_data[7]: #print out elements </code></pre> <p><strong>BUT DON'T DO THAT.</strong> Revise your approach so that you're not saving attributes in that one list. At least store them in a dictionary so you can access them by name. Better yet, store them as attributes of the class.</p> <p>As for printing out your class, you should implement the <code>__str__(self)</code> method in <code>Session</code> to put the data in the class instance into a string per your desired format, e.g.:</p> <pre><code>class Session(object): ... def __str__(self): out = 'ID:%s\nAMOUNT:%d ... '%(self.ID, self.amount, ...) # And so on. return out </code></pre> <p>That way you can just execute:</p> <pre><code>for session in saved_sessions: print str(session) </code></pre> <p>And that's it. How pretty! (And FYI, it's more Pythonic to use descriptive words for your variable names when looping with <code>for ... in</code>.)</p> <p><strong>Other recommendations</strong></p> <ol> <li>As @David Robinson points out, your class <code>Main</code> won't run as you want it to. You should <a href="http://docs.python.org/tutorial/classes.html" rel="nofollow">read about Python classes</a> before continuing, since you're making some assumptions about them that aren't correct. You must declare methods static with <code>@staticmethod</code> if you want to access them without an instance, and I don't think this is very Pythonic.</li> </ol> <p>2&amp;3. Use <code>re</code> instead of nested <code>if</code> statements, e.g.:</p> <pre><code>if not re.search(r'[\*\-\+\/]', operation): # Invalid operation, you should raise an exception here raise ValueError </code></pre> <p>4 . Review <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">the style guide for Python</a> and format your code appropriately. It will help you start writing more Pythonically, which will make your code clearer and better.</p> <p>Those were things that caught my eye</p>
    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. 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