From cdb41e48819d4246ecd177b312ff61094c870741 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 7 Mar 2025 19:23:22 -0500 Subject: [PATCH] Add some notes about using multi-ine strings instead of `print()`s --- examples/max_pain.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/examples/max_pain.py b/examples/max_pain.py index 456101f0..82908163 100755 --- a/examples/max_pain.py +++ b/examples/max_pain.py @@ -18,6 +18,8 @@ import pyqtgraph as pg from PyQt6 import QtCore from pyqtgraph import ScatterPlotItem, InfiniteLine from PyQt6.QtWidgets import QApplication +# XXX, use 2 newlines between top level LOC (even between these +# imports and the next function line ;) def check_if_complete( oi: dict[str, dict[str, Decimal | None]] @@ -50,6 +52,7 @@ async def max_pain_daemon( expiry_date = input('Please enter a valid expiration date: ').upper() print('Starting little daemon...') + # maybe move this type annot down to the assignment line? oi_by_strikes: dict[str, dict[str, Decimal]] instruments = await client.get_instruments( expiry_date=expiry_date, @@ -260,6 +263,28 @@ async def max_pain_daemon( # graph here plot_graph(oi_by_strikes, plot) + # TODO, use a single multiline string with `()` + # and drop the multiple `print()` calls (this + # should be done elsewhere in this file as well! + # + # As per the docs, + # https://docs.python.org/3/reference/lexical_analysis.html#string-literal-concatenation + # you could instead do, + # print( + # '-----------------------------------------------\n' + # f'timestamp: {datetime.fromtimestamp(max_pain['timestamp'])}\n' + # ) + # WHY? + # |_ less ctx-switches/calls to `print()` + # |_ the `str` can then be modified / passed + # around as a variable more easily if needed in + # the future ;) + # + # ALSO, i believe there already is a stdlib + # module to do "alignment" of text which you + # could try for doing the right-side alignment, + # https://docs.python.org/3/library/textwrap.html#textwrap.indent + # print('-----------------------------------------------') print(f'timestamp: {datetime.fromtimestamp(max_pain['timestamp'])}') print(f'expiry_date: {max_pain['expiry_date']}')