Skip to main content

Create nicely formatted comment strings to be used as headers/seperators in your code.

Project description

Comment Header Creator

Create a "header" for separating/describing sections of your Python code.

I don't know about you but I like to "organize" my Python methods and functions by putting some sort of comment seperator between them. This helps me when scrolling through my code to find particular categories of routines.

There are basically 2 main methods: Basic or Fancy

  • Basic (the uniline() method) returns a formatted string that is a single line with the 'title' centered.
  • Fancy (the multiline() method) returns a formatted string that is 3 lines long with the 'title' centered in the center line.

There is a "hidden" function, _generate_line(), is the secret sauce to generating the lines. You can call this directly but bear in mind it returns a Tuple (string and a boolean).

Installation

For some reason that I cannot figure out PyPi changes "comment_header_creator" into "comment-header-creator". This causes issues in that you have to use "dashes" to pip install but then use "underscores" to import. pip install comment-header-creator

Example Uses

See example.py for how to use or:

  • Create a single-line header but input title from user input:
import comment_header_creator as chc
print(chc.uniline())

yields:

Enter Title: title of section
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- TITLE OF SECTION -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
  • Create a multi-line header but input title from user input:
import comment_header_creator as chc
print(chc.multiline())

yields:

Enter Title: Another Section
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ANOTHER SECTION -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
  • Create a single-line (or multi-line) header by passing title in function call:
import comment_header_creator as chc
print(chc.uniline(title='Greatest Hits'))

yields:

# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- GREATEST HITS -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
  • You can also set your own 'expander' string:
import comment_header_creator as chc
chc.uniline(title="it's a flesh wound", expander='0i')
"# i0i0i0i0i0i0i0i0i0i0i0i0i0i0i0i0i0i0i0i0i0i0i0i IT'S A FLESH WOUND i0i0i0i0i0i0i0i0i0i0i0i0i0i0i0i0i0i0i0i0i0i0i0i #"

NOTE: In the previous example notice that we didn't use the print() function. This will return a string, which you then need to "strip" the quotes off the front and end. Thus, I suggest print()'ing your outputs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

comment_header_creator-20210909.0.tar.gz (15.8 kB view details)

Uploaded Source

File details

Details for the file comment_header_creator-20210909.0.tar.gz.

File metadata

  • Download URL: comment_header_creator-20210909.0.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for comment_header_creator-20210909.0.tar.gz
Algorithm Hash digest
SHA256 f9f7cb6cbfa82ce97b23e9bd77efee5905d44f9fc8ff7bc6064d942b591b243d
MD5 4c8813b79b79b4b3206cfec660b1e67c
BLAKE2b-256 d63f99e0cbbd570cbd92b652d4da2baca518c018ab6ccf1c31ce659444b72b2e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page