From fbaa915332b5fa3a05cb1f064259bd24a8d06832 Mon Sep 17 00:00:00 2001 From: Brady James Garvin <bgarvin@cse.unl.edu> Date: Thu, 14 Mar 2019 13:37:59 -0500 Subject: [PATCH] Updated code for Python 3. --- diner.py | 7 +++---- diner_installer.py | 4 +--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/diner.py b/diner.py index fbd2f07..c0ad745 100644 --- a/diner.py +++ b/diner.py @@ -8,7 +8,7 @@ from sqlalchemy.orm import sessionmaker, relationship # class that we can use for objects that we want SQLAlchemy to persist in a # database. We then store that class in variable named Persisted; effectively, # we make a new class called Persisted. -Persisted = declarative_base() +Persisted = declarative_base() # pylint: disable=invalid-name class Menu(Persisted): @@ -42,8 +42,7 @@ class OrderItem(Persisted): class DinerDatabase(object): @staticmethod def construct_mysql_url(authority, port, database, username, password): - return 'mysql+mysqlconnector://{username}:{password}@{authority}:{port}/{database}' \ - .format(authority=authority, port=port, database=database, username=username, password=password) + return f'mysql+mysqlconnector://{username}:{password}@{authority}:{port}/{database}' @staticmethod def construct_in_memory_url(): @@ -51,7 +50,7 @@ class DinerDatabase(object): def __init__(self, url): self.engine = create_engine(url) # an engine is like an endpoint, something to connect to - self.Session = sessionmaker() # create a class for connections to that endpoint + self.Session = sessionmaker() # create a class for connections to that endpoint / pylint: disable=invalid-name self.Session.configure(bind=self.engine) # associate the class with the endpoint def ensure_tables_exist(self): diff --git a/diner_installer.py b/diner_installer.py index 3846cf0..4704671 100644 --- a/diner_installer.py +++ b/diner_installer.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8; -*- - from sys import stderr from sqlalchemy.exc import SQLAlchemyError @@ -34,7 +32,7 @@ def main(): print('Records created.') except SQLAlchemyError as exception: print('Database setup failed!', file=stderr) - print('Cause: {exception}'.format(exception=exception), file=stderr) + print(f'Cause: {exception}', file=stderr) exit(1) -- GitLab