diff options
Diffstat (limited to 'templates/site/tutorials/python/py-style.html')
| -rw-r--r-- | templates/site/tutorials/python/py-style.html | 27 | 
1 files changed, 15 insertions, 12 deletions
| diff --git a/templates/site/tutorials/python/py-style.html b/templates/site/tutorials/python/py-style.html index d766e39..62de1ba 100644 --- a/templates/site/tutorials/python/py-style.html +++ b/templates/site/tutorials/python/py-style.html @@ -5,20 +5,24 @@  <p>That aside, I have the following idiosyncracies:</p>  <h2 id="strings-are-double-quoted.-keys-and-chars-are-single-quoted.">1) <em>Strings</em> are <em>double-quoted</em>. <em>Keys</em> and <em>chars</em> are <em>single-quoted</em>.</h2>  <p>This is really just because I like how C does it. And Cpython’s C-based so why not?</p> -<p>Like so: <code>string = "This is a phrase"     word = "word"     cur_char = 'a'     newline = '\n' # note, two characters, but it's still ONE char in output     # keys are single-quoted to avoid confusion     dictionary = { 'key' : "1245dqw3w431", 'return': newline }</code></p> -<p>The only exception is for strings with quotes in them (anything to avoid escapes, really) <code>quoted_string = (         '"You miss 100% of the shots you don't take - Wayne Gretsky" - Michael Scott'     )</code> That brings me to my next point.</p> +<p>Like so: <code>code     string = "This is a phrase"     word = "word"     cur_char = 'a'     newline = '\n' # note, two characters, but it's still ONE char in output     # keys are single-quoted to avoid confusion     dictionary = { 'key' : "1245dqw3w431", 'return': newline }</code></p> +<p>The only exception is for strings with quotes in them (anything to avoid escapes, really) <code>code     quoted_string = (         '"You miss 100% of the shots you don't take - Wayne Gretsky" - Michael Scott'     )</code> That brings me to my next point.</p>  <h2 id="long-strings-belong-in-parentheses">2) Long strings belong in parentheses</h2> -<p>As in: ``` longboi = ( “This is a really long string usefull when making help menus. Be” “sure to leave s space at the end of each line, or add a new line” “when needed.”</p> -<pre><code>    "Try your best to keep formatting accurate like this." -) -```</code></pre> +<p>As in:</p> +<pre class="code"><code>longboi = ( +    "This is a really long string usefull when making help menus. Be\n" +    "sure to leave s space at the end of each line, or add a new line\n" +    "when needed.\n" + +    "Try your best to keep formatting accurate like this." +)</code></pre>  <h2 id="tabs-are-four-spaces-and-spaces-are-always-prefered-to-tabs">3) Tabs are four spaces and spaces are <em>ALWAYS</em> prefered to tabs</h2>  <p>Again, see PEP8.</p>  <h2 id="always-add-spaces-between-arithmetic-but-never-for-brackets">4) Always add spaces between arithmetic, but never for brackets</h2> -<p>It’s a pain to read: <code>1/(2*sqrt(pi))*exp(x**2)</code> Do this <code>1 / (2 * sqrt(pi)) * exp(x ** 2)</code> The same goes for logic operators <code>true & false ^ true</code></p> +<p>It’s a pain to read: <code>code     1/(2*sqrt(pi))*exp(x**2)</code> Do this <code>code     1 / (2 * sqrt(pi)) * exp(x ** 2)</code> The same goes for logic operators <code>code     true & false ^ true</code></p>  <h2 id="everything-should-be-snake_case">5) EVERYTHING should be snake_case</h2> -<p>This is python. Unless there’s a compatibility thing (like a library’s code was written that way, or it matches an API variable), snake_case is preferred. ```</p> -<pre><code>user_input = int(input()) # variable +<p>This is python. Unless there’s a compatibility thing (like a library’s code was written that way, or it matches an API variable), snake_case is preferred.</p> +<pre class="code"><code>user_input = int(input()) # variable  MAX_INPUT = 1000 # constant  def judge_input(_input, _max): # function      if _max > _input: @@ -26,6 +30,5 @@ def judge_input(_input, _max): # function  judge_input(user_input, MAX_INPUT  class Input_Judger: # a class -    # etc etc -```</code></pre> -<p>Example exception <code># this doesn't actually work, but you get the idea     r = requests.get("www.debian.org")     pageSize = r.json()['pageSize'] # camel case ok</code></p> +    # etc etc</code></pre> +<p>Example exception <code>code # this doesn't actually work, but you get the idea r = requests.get("www.debian.org") pageSize = r.json()['pageSize'] # camel case ok</code></p> | 
