Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #109825

Re: i'm a python newbie & wrote my first script, can someone critique it?

Path csiph.com!news.mixmin.net!news2.arglkargh.de!news.karotte.org!fu-berlin.de!uni-berlin.de!not-for-mail
From Marc Brooks <marcwbrooks@gmail.com>
Newsgroups comp.lang.python
Subject Re: i'm a python newbie & wrote my first script, can someone critique it?
Date Sat, 11 Jun 2016 18:18:05 +0000
Lines 106
Message-ID <mailman.2.1465669098.2288.python-list@python.org> (permalink)
References <d7259e19-2c36-4282-9f57-bc46a6d5d641@googlegroups.com> <CAG93HwH4nKuqTkPBabxhbXMD3-FaZNcy140So+xaDgwG7UHYZQ@mail.gmail.com> <mailman.149.1465619818.2306.python-list@python.org> <486c9a97-4faa-42a1-8f44-e67d6b0a120a@googlegroups.com> <804a90c3-dab2-4cea-b591-06401c055e37@googlegroups.com> <CAN+KW4oSg+xdpCLrce5RZD=Rzp1cGCjZNNVuKs3Sm_gdj=Sh_w@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de QhQUPtnZ69A2ozfOOssN9g28M2x/zQOR30m4UT0zpEHg==
Return-Path <marcwbrooks@gmail.com>
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; 'sys': 0.05; '__name__': 0.07; 'main()': 0.07; '"in': 0.09; 'dict': 0.09; 'errno': 0.09; 'exception:': 0.09; 'oserror': 0.09; 'subject:script': 0.09; 'sys.argv[0]': 0.09; 'received:209.85.218': 0.10; 'python': 0.10; '"this': 0.13; 'output': 0.13; 'def': 0.13; 'subject:python': 0.14; '"created': 0.16; '"python': 0.16; '"wrong': 0.16; '&quot;in': 0.16; "'__main__':": 0.16; '1):': 0.16; '2016': 0.16; 'comments:': 0.16; 'main():': 0.16; 'numbered': 0.16; 'readable': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'scientist': 0.16; 'skip:p 90': 0.16; 'wrote:': 0.16; 'try:': 0.18; 'creates': 0.18; 'email addr:gmail.com&gt;': 0.18; 'to:2**1': 0.21; '3.x': 0.22; 'location,': 0.22; 'sat,': 0.23; 'import': 0.24; 'header:In- Reply-To:1': 0.24; 'script': 0.25; 'skip:" 20': 0.26; 'message- id:@mail.gmail.com': 0.27; 'disk': 0.27; 'function': 0.28; 'values': 0.28; '&quot;': 0.29; 'raise': 0.29; 'url:mailman': 0.30; 'code': 0.30; 'folder': 0.30; 'skip:& 30': 0.30; 'skip:s 30': 0.31; 'run': 0.33; 'url:python': 0.33; '"")': 0.33; 'url:listinfo': 0.34; 'except': 0.34; 'skip:& 20': 0.35; 'received:google.com': 0.35; 'false': 0.35; 'skip:e 40': 0.35; 'should': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'skip:{ 10': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'skip:& 10': 0.37; 'desired': 0.37; 'version': 0.38; 'received:209': 0.38; 'names': 0.38; 'skip:s 40': 0.38; 'skip:p 20': 0.38; 'skip:o 20': 0.38; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'your': 0.60; 'more': 0.63; 'here': 0.66; 'subject: & ': 0.74; 'docstrings.': 0.84; 'skip:p 80': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=s1tiUpzgxv4+qChVaoQ0e8K76CnhIue0Pby568/d4W0=; b=wVF+0mSiS0kgMFEM0OBIJYYDWR0ziOLAlSzccN1Vh88uyAVTqRzJdRygidmh3xBYOm qttSvwP7SXbvjInkAae9kWXnd4P7ygTC2KinvkPWqk+YmXmNe7uSavQR5NxiUx/fFKQt aeTk7Oa0oCDcVYWP+sXa9RgNTALZhOYevGf44g18CjO+zX/jvGfuQRp6B82Y8ZTgwLNe JxJv39Y7+UEiTmg7ePT3rwVzQe2sVikm/t5LrWZBRirdAThG6vRZuJL4uqOME3hSnn1S pvnfM6eJgN2fqrxWKbEkvHRohsCAv/YzHHQ00P2p9iGAUQySWoXFLR2TBdajAgWNAoqv LaqA==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=s1tiUpzgxv4+qChVaoQ0e8K76CnhIue0Pby568/d4W0=; b=i4D5g2alVd4K9gUmKdjw9BFxrBfyb41ps0YYcDNTmxkZ8BdTo1WjgQP2g+7jqsHhI6 s44ZHVYU9Zbw5Q4Q/gLTVO83gYv9B+dV6B8jqLf4L9Hvh/J4/N7frUaP6O9/WQWnvfFi bYtf1RYZUMndAEE/86d7qFh2BxvGkfRggML/ZzJMIqw4qp2Hv8iA/P7KSlVDWxSLT4pK 7nhLk6HogCOM6n6+2I0UGlAaHQBFJz1Cbtrfkod8e+Ugj2Qq2TkgmeCCSIcC212kD4dn quyfhHMpqLXGxnTNVIbhT5v6Lp5/PSzMSr16TbZiRqt34ZWBENS4bjAVBy5ZQkcRScLq TOtQ==
X-Gm-Message-State ALyK8tIKkdVyabiSoE96mUsjKBgymvX3ioCSA+rrcevi42jjnGNGaOd64Aa026Jlum3rqx/1JizktKbQS01aFA==
X-Received by 10.202.89.11 with SMTP id n11mr1044588oib.113.1465669095305; Sat, 11 Jun 2016 11:18:15 -0700 (PDT)
In-Reply-To <804a90c3-dab2-4cea-b591-06401c055e37@googlegroups.com>
X-Content-Filtered-By Mailman/MimeDel 2.1.22
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
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>
X-Mailman-Original-Message-ID <CAN+KW4oSg+xdpCLrce5RZD=Rzp1cGCjZNNVuKs3Sm_gdj=Sh_w@mail.gmail.com>
X-Mailman-Original-References <d7259e19-2c36-4282-9f57-bc46a6d5d641@googlegroups.com> <CAG93HwH4nKuqTkPBabxhbXMD3-FaZNcy140So+xaDgwG7UHYZQ@mail.gmail.com> <mailman.149.1465619818.2306.python-list@python.org> <486c9a97-4faa-42a1-8f44-e67d6b0a120a@googlegroups.com> <804a90c3-dab2-4cea-b591-06401c055e37@googlegroups.com>
Xref csiph.com comp.lang.python:109825

Show key headers only | View raw


Look into docstrings. They will make your code much more readable to a
Python reader.
On Sat, Jun 11, 2016 at 2:16 PM mad scientist jr <mad.scientist.jr@gmail.com>
wrote:

> For those who don't want to have to wade through comments, here is a
> version without so many comments:
>
> # For Python 3.x
> # This script creates multiple numbered empty folders
> # in the desired location. To change the folder names
> # or location, edit function get_default_options.
>
> import datetime
> import os
> import errno
> import sys
>
>
> ###############################################################################
> # EDIT VALUES HERE TO CUSTOMIZE THE OUTPUT
> def get_default_options():
>     dict = {
>         "s_for_python_version": "3",
>         "s_folder_path_template": "C:/temp/test/MP3 Disk {count:03}",
>         "i_from_count": 3,
>         "i_to_count": 7,
>         }
>     return dict
>
> ###############################################################################
>
> def get_exact_python_version():
>     s_version = ".".join(map(str, sys.version_info[:3]))
>     s_version = s_version.strip()
>     return s_version
>
> def get_general_python_version():
>     s_version = get_exact_python_version()
>     return s_version[0]
>
> def exit_if_wrong_python_version(s_right_version):
>     s_current_version = get_general_python_version()
>     if (s_current_version != s_right_version):
>         print(
>             "Wrong Python version ({}), "
>             "this script should be run using "
>             "Python {}.x,  Exiting..."
>             "".format(s_current_version, s_right_version))
>         sys.exit()
>
> def get_script_filename():
>     return sys.argv[0]
>
> def get_timestamp():
>     return datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d
> %H:%M:%S')
>
> def create_folder(s_path):
>     try:
>         os.makedirs(s_path, exist_ok=True)
>     except (FileExistsError, IsADirectoryError) as e:
>         print("FileExistsError IN makedirs")
>         raise
>         return False
>     except OSError as exception:
>         print("ERROR #" + str(exception.errno) + "IN makedirs")
>         raise
>         return False
>     print("" + get_timestamp() + " " + "Created folder: " + s_path + "")
>
> def create_folders(
>         s_folder_path_template:str="",
>         i_from_count:int=1,
>         i_to_count:int=0
>         ):
>     i_count=0
>     for i_loop in range(i_from_count, i_to_count + 1):
>         create_folder(s_folder_path_template.format(count=i_loop))
>         i_count += 1
>
>     return i_count
>
> def main():
>     options_dict = get_default_options()
>     exit_if_wrong_python_version(options_dict["s_for_python_version"])
>
>
> print("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
>     print("" + get_timestamp() + " " + get_script_filename() + " started.")
>
>     i_total_created = create_folders(
>         options_dict["s_folder_path_template"],
>         options_dict["i_from_count"],
>         options_dict["i_to_count"])
>
>     print("" + get_timestamp() + " " + str(i_total_created) + " folders
> created.")
>     print("" + get_timestamp() + " " + get_script_filename() + "
> finished.")
>
> if __name__ == '__main__':
>     main()
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

i'm a python newbie & wrote my first script, can someone critique it? mad scientist jr <mad.scientist.jr@gmail.com> - 2016-06-10 15:52 -0700
  Re: i'm a python newbie & wrote my first script, can someone critique it? Christopher Reimer <christopher_reimer@icloud.com> - 2016-06-10 16:05 -0700
  Re: i'm a python newbie & wrote my first script, can someone critique it? Marc Brooks <marcwbrooks@gmail.com> - 2016-06-10 20:51 -0400
  Re: i'm a python newbie & wrote my first script, can someone critique it? Joel Goldstick <joel.goldstick@gmail.com> - 2016-06-10 21:02 -0400
  Re: i'm a python newbie & wrote my first script, can someone critique it? Larry Hudson <orgnut@yahoo.com> - 2016-06-10 21:00 -0700
  Re: i'm a python newbie & wrote my first script, can someone critique it? Matt Wheeler <m@funkyhat.org> - 2016-06-11 04:28 +0000
    Re: i'm a python newbie & wrote my first script, can someone critique it? mad scientist jr <mad.scientist.jr@gmail.com> - 2016-06-11 10:59 -0700
      Re: i'm a python newbie & wrote my first script, can someone critique it? mad scientist jr <mad.scientist.jr@gmail.com> - 2016-06-11 11:14 -0700
        Re: i'm a python newbie & wrote my first script, can someone critique it? Marc Brooks <marcwbrooks@gmail.com> - 2016-06-11 18:18 +0000
      Re: i'm a python newbie & wrote my first script, can someone critique it? MRAB <python@mrabarnett.plus.com> - 2016-06-11 19:41 +0100
        Re: i'm a python newbie & wrote my first script, can someone critique it? mad scientist jr <mad.scientist.jr@gmail.com> - 2016-06-12 09:04 -0700

csiph-web