Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100063
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | "Jason Alan Smith" <Jason.Smith@qualityaddict.org> |
| Newsgroups | comp.lang.python |
| Subject | Brief Code Review Please - Learning Python |
| Date | Sat, 5 Dec 2015 13:35:04 -0600 |
| Lines | 59 |
| Message-ID | <mailman.9.1449433126.2247.python-list@python.org> (permalink) |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="US-ASCII" |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de C4RI0guF+XprpR6DcoW2Qg9hibjg9yV8azZcwhdlBOeA== |
| Return-Path | <Jason.Smith@qualityaddict.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'subject:Python': 0.05; "'')": 0.07; 'correct.': 0.07; 'tests,': 0.07; '40,': 0.09; 'meaningful': 0.09; 'spreading': 0.09; 'surrounded': 0.09; 'underscore': 0.09; 'advance': 0.10; 'python': 0.10; 'def': 0.13; 'variables': 0.15; 'guide.': 0.16; 'measures': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:Learning': 0.16; 'tabs': 0.16; 'stick': 0.18; 'tests': 0.18; 'fix': 0.21; 'aligned': 0.22; 'arguments': 0.22; 'subject:Code': 0.22; 'recognized': 0.24; "i've": 0.25; 'appreciated.': 0.27; 'skip:m 30': 0.27; 'not.': 0.27; 'question': 0.27; 'said,': 0.27; 'function': 0.28; 'skip:( 20': 0.28; 'pep': 0.29; 'received:dreamhost.com': 0.29; 'received:g.dreamhost.com': 0.29; "i'm": 0.30; 'code': 0.30; 'convention': 0.30; "i'd": 0.31; 'everyone': 0.31; 'changed': 0.33; 'class': 0.33; "i'll": 0.33; 'case,': 0.34; 'correctly': 0.34; 'editor': 0.34; 'skip:d 20': 0.34; 'list': 0.34; 'jason': 0.35; 'but': 0.36; 'skip:i 20': 0.36; 'lines': 0.36; 'beginning': 0.36; 'to:addr:python-list': 0.36; 'two': 0.37; 'charset:us-ascii': 0.37; 'brief': 0.38; 'feedback': 0.38; 'skip:p 20': 0.38; 'thank': 0.38; 'google': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'your': 0.60; 'skip:w 30': 0.64; 'below.': 0.66; 'exceed': 0.72; 'journey': 0.72 |
| DKIM-Signature | v=1; a=rsa-sha1; c=relaxed; d=qualityaddict.org; h=from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=qualityaddict.org; bh=h4kxREV/tsWN RRMHhL4z02Ejt1w=; b=WKuQ00ESomN6GxYL5/FJLIawF6naecEVfhnL9rCDVxcY gb/Z7eCTlJ9ebRINIFeaA+cxJiG7HQdXxPAEgoqMiSz7huBT4IIo43waIG77P01I R3qqh+swV+KONQkRyVbiGRt1j1kJc0pPQ6O8ZZIeKFBgUZY7o/lRGBhPIXAulE4= |
| X-Mailer | Microsoft Outlook 16.0 |
| Thread-Index | AdEvk7zhwmuC2JtyRcadGguCvqE85w== |
| Content-Language | en-us |
| X-Mailman-Approved-At | Sun, 06 Dec 2015 15:18:45 -0500 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:100063 |
Show key headers only | View raw
Hello List Members,
I am beginning to learn Python, and I've adapted some code from Google
into the function below. I'm also looking at the PEP 8 style guide. I'd
appreciate a brief code review so I can start this journey off on a solid
foundation. :)
* I've already changed my editor from tabs to 4 spaces.
* I've also set my editor to alert me at 72 characters and don't exceed
79 characters.
* I've named the function and variables with lower case, underscore
separated, and meaningful words.
* I've surrounded this function with two blank lines before and after.
* I just recognized I need to pick a quote style and stick to it so I'll
fix that (" " or ' ').
* I'm not sure about the WidthAndHeight on lines 16 and 17 regarding
capitalization.
If I understand correctly a namedtuple is a class so the CapWords
convention is correct.
* Is how I've aligned the function arguments on lines 1-4 and 22-25 good
style or \
is spreading these out onto fewer lines preferred?
* Same question as right above but with the if tests on lines 5-8.
* I've also used ( ) around the if tests, but I'm not sure if this is
good Python style or not.
1 def measure_string(desired_text,
2 desired_font_family,
3 desired_font_size,
4 is_multi_lines):
5 if (desired_text != '') and \
6 (desired_font_family != '') and \
7 (desired_font_size != '') and \
8 ((is_multi_lines == "True") or (is_multi_lines == "False")):
9 with Image(filename='wizard:') as temp_image:
10 with Drawing() as measure:
11 measure.font_family = desired_font_family
12 measure.font_size = desired_font_size
13 measures = measure.get_font_metrics(temp_image,
14 desired_text,
15
multiline=is_multi_lines)
16 WidthAndHeight = namedtuple("WidthAndHeight", "Width Height")
17 width_and_height = WidthAndHeight(measures.text_width, \
18 measures.text_height)
19 return width_and_height
20
21
22 print(measure_string("some text\na new line",
23 "Segoe UI",
24 40,
25 "True"))
Any and all feedback is much appreciated. As I said, I'm just beginning to
learn Python and want to start off with a solid foundation. Thank you to
everyone in advance for your time and thoughts.
Jason
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Brief Code Review Please - Learning Python "Jason Alan Smith" <Jason.Smith@qualityaddict.org> - 2015-12-05 13:35 -0600
csiph-web