From b00bf3b561dafc7c076a139a8997cd9d28fa8b8b Mon Sep 17 00:00:00 2001 From: jtrain Date: Mon, 12 Jun 2017 13:54:26 +1000 Subject: [PATCH] Avoid use of __future__ import `print_function` isn't a callable on Python 2.7 Correct usage would have been `print(...)` However, since all output is sent via `self.stdout`, re-use that output inside the delete line function. --- reset_migrations/management/commands/reset_migrations.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/reset_migrations/management/commands/reset_migrations.py b/reset_migrations/management/commands/reset_migrations.py index f0e819e..330c58a 100644 --- a/reset_migrations/management/commands/reset_migrations.py +++ b/reset_migrations/management/commands/reset_migrations.py @@ -1,5 +1,3 @@ -from __future__ import print_function - from django.core.management import BaseCommand from django.core.management import call_command from django.db import connection @@ -8,13 +6,13 @@ import re import tempfile -def delete_line(filename, pattern): +def delete_line(filename, pattern, stdout): pattern_compiled = re.compile(pattern) with tempfile.NamedTemporaryFile(mode='w', delete=False) as tmp_file: with open(filename) as src_file: for line in src_file: if pattern_compiled.findall(line): - print_function('Deleting line in %s' % filename) + stdout.write('Deleting line in %s' % filename) continue tmp_file.write(line) @@ -64,7 +62,7 @@ def delete_dependence_app(self, app): continue if '.py' in file_name: regex = r'\(\'%s\'' % app - delete_line(file_name, regex) + delete_line(file_name, regex, self.stdout) def handle(self, *args, **options): apps = options['apps']