From 1c403904e57a9b2f9c83d51740003e183a598183 Mon Sep 17 00:00:00 2001 From: Peter Schmidbauer Date: Fri, 1 Nov 2019 10:37:12 +0100 Subject: [PATCH] fstring wip --- jrnl/DayOneJournal.py | 2 +- jrnl/Journal.py | 2 +- jrnl/cli.py | 2 +- jrnl/plugins/markdown_exporter.py | 12 ++++-------- jrnl/plugins/template_exporter.py | 2 +- jrnl/plugins/text_exporter.py | 4 ++-- jrnl/util.py | 2 +- 7 files changed, 11 insertions(+), 15 deletions(-) diff --git a/jrnl/DayOneJournal.py b/jrnl/DayOneJournal.py index ccec528a..30846f71 100644 --- a/jrnl/DayOneJournal.py +++ b/jrnl/DayOneJournal.py @@ -82,7 +82,7 @@ class DayOne(Journal.Journal): def editable_str(self): """Turns the journal into a string of entries that can be edited manually and later be parsed with eslf.parse_editable_str.""" - return "\n".join(["# {0}\n{1}".format(e.uuid, str(e)) for e in self.entries]) + return "\n".join([f"# {e.uuid}\n{str(e)}" for e in self.entries]) def parse_editable_str(self, edited): """Parses the output of self.editable_str and updates its entries.""" diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 35ae801e..aeab7385 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -23,7 +23,7 @@ class Tag: return self.name def __repr__(self): - return "".format(self.name) + return f"" class Journal: diff --git a/jrnl/cli.py b/jrnl/cli.py index 1bcdbae6..464c8c39 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -144,7 +144,7 @@ def run(manual_args=None): try: config = install.load_or_install_jrnl() except UserAbort as err: - print("\n{}".format(err), file=sys.stderr) + print(f"\n{err}", file=sys.stderr) sys.exit(1) if args.ls: diff --git a/jrnl/plugins/markdown_exporter.py b/jrnl/plugins/markdown_exporter.py index 0452a5f8..da2b5748 100644 --- a/jrnl/plugins/markdown_exporter.py +++ b/jrnl/plugins/markdown_exporter.py @@ -50,15 +50,11 @@ class MarkdownExporter(TextExporter): newbody = newbody + previous_line # add very last line if warn_on_heading_level is True: - print("{}WARNING{}: Headings increased past H6 on export - {} {}".format(WARNING_COLOR, RESET_COLOR, date_str, entry.title), file=sys.stderr) + print(f"{WARNING_COLOR}WARNING{RESET_COLOR}: " + f"Headings increased past H6 on export - {date_str} {entry.title}", + file=sys.stderr) - return "{md} {date} {title}\n{body} {space}".format( - md=heading, - date=date_str, - title=entry.title, - body=newbody, - space="" - ) + return f"{heading} {date_str} {entry.title}\n{newbody} " @classmethod def export_journal(cls, journal): diff --git a/jrnl/plugins/template_exporter.py b/jrnl/plugins/template_exporter.py index ecb9ac87..4ae618ba 100644 --- a/jrnl/plugins/template_exporter.py +++ b/jrnl/plugins/template_exporter.py @@ -34,7 +34,7 @@ def __exporter_from_file(template_file): """Create a template class from a file""" name = os.path.basename(template_file).replace(".template", "") template = Template.from_file(template_file) - return type(str("{}Exporter".format(name.title())), (GenericTemplateExporter, ), { + return type(str(f"{name.title(}Exporter")), (GenericTemplateExporter, ), { "names": [name], "extension": template.extension, "template": template diff --git a/jrnl/plugins/text_exporter.py b/jrnl/plugins/text_exporter.py index f8ade519..c72e8d93 100644 --- a/jrnl/plugins/text_exporter.py +++ b/jrnl/plugins/text_exporter.py @@ -28,9 +28,9 @@ class TextExporter: try: with codecs.open(path, "w", "utf-8") as f: f.write(cls.export_journal(journal)) - return "[Journal exported to {0}]".format(path) + return f"[Journal exported to {path}]" except IOError as e: - return "[{2}ERROR{3}: {0} {1}]".format(e.filename, e.strerror, ERROR_COLOR, RESET_COLOR) + return f"[{ERROR_COLOR}ERROR{RESET_COLOR}: {e.filename} {e.strerror}]" @classmethod def make_filename(cls, entry): diff --git a/jrnl/util.py b/jrnl/util.py index 7b5e2b5c..52f7e4c4 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -125,7 +125,7 @@ def get_text_from_editor(config, template=""): def colorize(string): """Returns the string wrapped in cyan ANSI escape""" - return u"\033[36m{}\033[39m".format(string) + return f"\033[36m{string}\033[39m" def slugify(string):