Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Instead of:</p> <pre><code> i=0 end=20 last_id=0 data=[] while(i&lt;=end): i = i + 1 ... </code></pre> <p>code:</p> <pre><code> last_id=0 data=[] for i in xrange(1, 22): ... </code></pre> <p>Same semantics, more compact and Pythonic.</p> <p>Instead of</p> <pre><code>if not last or last == None: </code></pre> <p>do just</p> <pre><code>if not last: </code></pre> <p>since <code>None</code> is false-ish anyway (so <code>not last</code> is <code>True</code> when <code>last</code> is <code>None). In general, when you want to check if something is</code>None<code>, code</code>is None<code>, not</code>== None`.</p> <p>In</p> <pre><code> if(j['id'] &lt;&gt; last_id): </code></pre> <p>lose the redundant parentheses and the obsolete <code>&lt;&gt;</code> operator and code instead</p> <pre><code> if j['id'] != last_id: </code></pre> <p>and also remove the redundant parentheses from other <code>if</code> statements.</p> <p>Instead of:</p> <pre><code> if len(data) == 0: </code></pre> <p>code:</p> <pre><code> if not data: </code></pre> <p>since any empty container is false-ish.</p> <p>In</p> <pre><code>hash_str = str(hash.hexdigest()) </code></pre> <p>code instead</p> <pre><code>hash_str = hash.hexdigest() </code></pre> <p>since the method already returns a string, making the <code>str</code> call redundant.</p> <p>Instead of:</p> <pre><code> for item in data: writer.writerow(item) </code></pre> <p>use</p> <pre><code> writer.writerows(data) </code></pre> <p>which does the loop on your behalf.</p> <p>Instead of</p> <pre><code> ofile = open('tmp/'+file_name, mode='ab') ... ofile.close() </code></pre> <p>use (in Python 2.6 or better, or in 2.5 by starting the module with</p> <pre><code> from __future__ import with_statement </code></pre> <p>to "import from the future" the <code>with</code> statement feature):</p> <pre><code> with open('tmp/'+file_name, mode='ab') as ofile: ... </code></pre> <p>which guarantees to do the close for you (including in cases where an exception might be raised).</p> <p>Instead of</p> <pre><code>print "Upload Error: "+uploadr[0] </code></pre> <p>use</p> <pre><code>print "Upload Error:", uploadr[0] </code></pre> <p>and similarly for other <code>print</code> statements -- the comma inserts a space for you.</p> <p>I'm sure there are more such little things, but these are a few that "jumped to the eye" as I was scanning your code.</p>
    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