Skip to content

Commit

Permalink
More f-strings
Browse files Browse the repository at this point in the history
  • Loading branch information
alexprengere committed Nov 22, 2024
1 parent ccec5c9 commit 290539f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
5 changes: 2 additions & 3 deletions currency_converter/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ def main():
for currency in currencies:
first_date, last_date = c.bounds[currency]
print(
"{}: from {} to {} ({} days)".format(
currency, first_date, last_date, 1 + (last_date - first_date).days
)
f"{currency}: from {first_date} to {last_date}"
f" ({1 + (last_date - first_date).days} days)"
)
print()

Expand Down
23 changes: 8 additions & 15 deletions currency_converter/currency_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,8 @@ def _set_missing_to_none(self, currency):
missing = len([r for r in rates.values() if r is None])
if missing:
print(
"{}: {} missing rates from {} to {} ({} days)".format(
currency,
missing,
first_date,
last_date,
1 + (last_date - first_date).days,
)
f"{currency}: {missing} missing rates from {first_date} to {last_date}"
f" ({1 + (last_date - first_date).days} days)"
)

def _use_linear_interpolation(self, currency):
Expand Down Expand Up @@ -253,8 +248,8 @@ def _use_linear_interpolation(self, currency):
rates[date] = (r0 * d1 + r1 * d0) / (d0 + d1)
if self.verbose:
print(
f"{currency}: filling {date} missing rate using {r0} ({d0}d old) and "
f"{r1} ({d1}d later)"
f"{currency}: filling {date} missing rate using"
f" {r0} ({d0}d old) and {r1} ({d1}d later)"
)

def _use_last_known(self, currency):
Expand All @@ -274,9 +269,8 @@ def _use_last_known(self, currency):
rates[date] = last_rate
if self.verbose:
print(
"{}: filling {} missing rate using {} from {}".format(
currency, date, last_rate, last_date
)
f"{currency}: filling {date} missing rate using"
f" {last_rate} from {last_date}"
)

def _get_rate(self, currency, date):
Expand Down Expand Up @@ -312,9 +306,8 @@ def _get_rate(self, currency, date):

if self.verbose:
print(
r"/!\ {} not in {} bounds {}/{}, falling back to {}".format(
date, currency, first_date, last_date, fallback_date
)
rf"/!\ {date} not in {currency} bounds {first_date}/{last_date},"
f" falling back to {fallback_date}"
)

date = fallback_date
Expand Down

0 comments on commit 290539f

Please sign in to comment.