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?

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 2016-06-11 18:18 +0000
Message-ID <mailman.2.1465669098.2288.python-list@python.org> (permalink)
References (1 earlier) <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>

Show all headers | 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