Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e6afea5

Browse files
committed
Convert print statements to print function calls
libmodernize.fixes.fix_print
1 parent 5489179 commit e6afea5

53 files changed

Lines changed: 344 additions & 291 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

IPython/config/application.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Brian Granger
88
* Min RK
99
"""
10+
from __future__ import print_function
1011

1112
#-----------------------------------------------------------------------------
1213
# Copyright (C) 2008-2011 The IPython Development Team
@@ -286,7 +287,7 @@ def print_alias_help(self):
286287
help[0] = help[0].replace('--%s='%alias, '-%s '%alias)
287288
lines.extend(help)
288289
# lines.append('')
289-
print os.linesep.join(lines)
290+
print(os.linesep.join(lines))
290291

291292
def print_flag_help(self):
292293
"""Print the flag part of the help."""
@@ -299,7 +300,7 @@ def print_flag_help(self):
299300
lines.append(prefix+m)
300301
lines.append(indent(dedent(help.strip())))
301302
# lines.append('')
302-
print os.linesep.join(lines)
303+
print(os.linesep.join(lines))
303304

304305
def print_options(self):
305306
if not self.flags and not self.aliases:
@@ -310,10 +311,10 @@ def print_options(self):
310311
for p in wrap_paragraphs(self.option_description):
311312
lines.append(p)
312313
lines.append('')
313-
print os.linesep.join(lines)
314+
print(os.linesep.join(lines))
314315
self.print_flag_help()
315316
self.print_alias_help()
316-
print
317+
print()
317318

318319
def print_subcommands(self):
319320
"""Print the subcommand part of the help."""
@@ -331,7 +332,7 @@ def print_subcommands(self):
331332
if help:
332333
lines.append(indent(dedent(help.strip())))
333334
lines.append('')
334-
print os.linesep.join(lines)
335+
print(os.linesep.join(lines))
335336

336337
def print_help(self, classes=False):
337338
"""Print the help for each Configurable class in self.classes.
@@ -344,28 +345,28 @@ def print_help(self, classes=False):
344345

345346
if classes:
346347
if self.classes:
347-
print "Class parameters"
348-
print "----------------"
349-
print
348+
print("Class parameters")
349+
print("----------------")
350+
print()
350351
for p in wrap_paragraphs(self.keyvalue_description):
351-
print p
352-
print
352+
print(p)
353+
print()
353354

354355
for cls in self.classes:
355356
cls.class_print_help()
356-
print
357+
print()
357358
else:
358-
print "To see all available configurables, use `--help-all`"
359-
print
359+
print("To see all available configurables, use `--help-all`")
360+
print()
360361

361362
self.print_examples()
362363

363364

364365
def print_description(self):
365366
"""Print the application description."""
366367
for p in wrap_paragraphs(self.description):
367-
print p
368-
print
368+
print(p)
369+
print()
369370

370371
def print_examples(self):
371372
"""Print usage and examples.
@@ -374,15 +375,15 @@ def print_examples(self):
374375
and should contain examples of the application's usage.
375376
"""
376377
if self.examples:
377-
print "Examples"
378-
print "--------"
379-
print
380-
print indent(dedent(self.examples.strip()))
381-
print
378+
print("Examples")
379+
print("--------")
380+
print()
381+
print(indent(dedent(self.examples.strip())))
382+
print()
382383

383384
def print_version(self):
384385
"""Print the version string."""
385-
print self.version
386+
print(self.version)
386387

387388
def update_config(self, config):
388389
"""Fire the traits events when the config is updated."""

IPython/config/configurable.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Fernando Perez
1414
* Min RK
1515
"""
16+
from __future__ import print_function
1617

1718
#-----------------------------------------------------------------------------
1819
# Copyright (C) 2008-2011 The IPython Development Team
@@ -236,7 +237,7 @@ def class_get_trait_help(cls, trait, inst=None):
236237
@classmethod
237238
def class_print_help(cls, inst=None):
238239
"""Get the help string for a single trait and print it."""
239-
print cls.class_get_help(inst)
240+
print(cls.class_get_help(inst))
240241

241242
@classmethod
242243
def class_config_section(cls):

IPython/core/logger.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Logger class for IPython's logging facilities.
22
"""
3+
from __future__ import print_function
34

45
#*****************************************************************************
56
# Copyright (C) 2001 Janko Hauser <[email protected]> and
@@ -137,33 +138,33 @@ def switch_log(self,val):
137138
label = {0:'OFF',1:'ON',False:'OFF',True:'ON'}
138139

139140
if self.logfile is None:
140-
print """
141+
print("""
141142
Logging hasn't been started yet (use logstart for that).
142143
143144
%logon/%logoff are for temporarily starting and stopping logging for a logfile
144145
which already exists. But you must first start the logging process with
145-
%logstart (optionally giving a logfile name)."""
146+
%logstart (optionally giving a logfile name).""")
146147

147148
else:
148149
if self.log_active == val:
149-
print 'Logging is already',label[val]
150+
print('Logging is already',label[val])
150151
else:
151-
print 'Switching logging',label[val]
152+
print('Switching logging',label[val])
152153
self.log_active = not self.log_active
153154
self.log_active_out = self.log_active
154155

155156
def logstate(self):
156157
"""Print a status message about the logger."""
157158
if self.logfile is None:
158-
print 'Logging has not been activated.'
159+
print('Logging has not been activated.')
159160
else:
160161
state = self.log_active and 'active' or 'temporarily suspended'
161-
print 'Filename :',self.logfname
162-
print 'Mode :',self.logmode
163-
print 'Output logging :',self.log_output
164-
print 'Raw input log :',self.log_raw_input
165-
print 'Timestamping :',self.timestamp
166-
print 'State :',state
162+
print('Filename :',self.logfname)
163+
print('Mode :',self.logmode)
164+
print('Output logging :',self.log_output)
165+
print('Raw input log :',self.log_raw_input)
166+
print('Timestamping :',self.timestamp)
167+
print('State :',state)
167168

168169
def log(self, line_mod, line_ori):
169170
"""Write the sources to a log.
@@ -213,7 +214,7 @@ def logstop(self):
213214
self.logfile.close()
214215
self.logfile = None
215216
else:
216-
print "Logging hadn't been started."
217+
print("Logging hadn't been started.")
217218
self.log_active = False
218219

219220
# For backwards compatibility, in case anyone was using this.

IPython/core/magic.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# encoding: utf-8
22
"""Magic functions for InteractiveShell.
33
"""
4+
from __future__ import print_function
45

56
#-----------------------------------------------------------------------------
67
# Copyright (C) 2001 Janko Hauser <[email protected]> and
@@ -544,8 +545,8 @@ def __init__(self, shell=None, **kwargs):
544545

545546
def arg_err(self,func):
546547
"""Print docstring if incorrect arguments were passed"""
547-
print 'Error in arguments:'
548-
print oinspect.getdoc(func)
548+
print('Error in arguments:')
549+
print(oinspect.getdoc(func))
549550

550551
def format_latex(self, strng):
551552
"""Format a string for latex inclusion."""

IPython/core/magics/auto.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Implementation of magic functions that control various automatic behaviors.
22
"""
3+
from __future__ import print_function
34
#-----------------------------------------------------------------------------
45
# Copyright (c) 2012 The IPython Development Team.
56
#
@@ -57,7 +58,7 @@ def automagic(self, parameter_s=''):
5758
else:
5859
val = not mman.auto_magic
5960
mman.auto_magic = val
60-
print '\n' + self.shell.magics_manager.auto_status()
61+
print('\n' + self.shell.magics_manager.auto_status())
6162

6263
@skip_doctest
6364
@line_magic
@@ -125,4 +126,4 @@ def autocall(self, parameter_s=''):
125126
except AttributeError:
126127
self.shell.autocall = self._magic_state.autocall_save = 1
127128

128-
print "Automatic calling is:",['OFF','Smart','Full'][self.shell.autocall]
129+
print("Automatic calling is:",['OFF','Smart','Full'][self.shell.autocall])

IPython/core/magics/code.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Implementation of code management magic functions.
22
"""
3+
from __future__ import print_function
34
#-----------------------------------------------------------------------------
45
# Copyright (c) 2012 The IPython Development Team.
56
#
@@ -189,15 +190,15 @@ def save(self, parameter_s=''):
189190
try:
190191
overwrite = self.shell.ask_yes_no('File `%s` exists. Overwrite (y/[N])? ' % fname, default='n')
191192
except StdinNotImplementedError:
192-
print "File `%s` exists. Use `%%save -f %s` to force overwrite" % (fname, parameter_s)
193+
print("File `%s` exists. Use `%%save -f %s` to force overwrite" % (fname, parameter_s))
193194
return
194195
if not overwrite :
195-
print 'Operation cancelled.'
196+
print('Operation cancelled.')
196197
return
197198
try:
198199
cmds = self.shell.find_user_code(codefrom,raw)
199200
except (TypeError, ValueError) as e:
200-
print e.args[0]
201+
print(e.args[0])
201202
return
202203
out = py3compat.cast_unicode(cmds)
203204
with io.open(fname, mode, encoding="utf-8") as f:
@@ -207,8 +208,8 @@ def save(self, parameter_s=''):
207208
# make sure we end on a newline
208209
if not out.endswith(u'\n'):
209210
f.write(u'\n')
210-
print 'The following commands were written to file `%s`:' % fname
211-
print cmds
211+
print('The following commands were written to file `%s`:' % fname)
212+
print(cmds)
212213

213214
@line_magic
214215
def pastebin(self, parameter_s=''):
@@ -230,7 +231,7 @@ def pastebin(self, parameter_s=''):
230231
try:
231232
code = self.shell.find_user_code(args)
232233
except (ValueError, TypeError) as e:
233-
print e.args[0]
234+
print(e.args[0])
234235
return
235236

236237
from urllib2 import urlopen # Deferred import
@@ -337,7 +338,7 @@ def load(self, arg_s):
337338
ans = True
338339

339340
if ans is False :
340-
print 'Operation cancelled.'
341+
print('Operation cancelled.')
341342
return
342343

343344
self.shell.set_next_input(contents)
@@ -459,7 +460,7 @@ class DataIsObject(Exception): pass
459460

460461
if use_temp:
461462
filename = shell.mktempfile(data)
462-
print 'IPython will make a temporary file named:',filename
463+
print('IPython will make a temporary file named:',filename)
463464

464465
# use last_call to remember the state of the previous call, but don't
465466
# let it be clobbered by successive '-p' calls.
@@ -637,7 +638,7 @@ def edit(self, parameter_s='',last_call=['','']):
637638
self._edit_macro(args, e.args[0])
638639
return
639640
except InteractivelyDefined as e:
640-
print "Editing In[%i]" % e.index
641+
print("Editing In[%i]" % e.index)
641642
args = str(e.index)
642643
filename, lineno, is_temp = self._find_edit_target(self.shell,
643644
args, opts, last_call)
@@ -647,7 +648,7 @@ def edit(self, parameter_s='',last_call=['','']):
647648
return
648649

649650
# do actual editing here
650-
print 'Editing...',
651+
print('Editing...', end=' ')
651652
sys.stdout.flush()
652653
try:
653654
# Quote filenames that may have spaces in them
@@ -665,9 +666,9 @@ def edit(self, parameter_s='',last_call=['','']):
665666
self.shell.user_ns['pasted_block'] = f.read()
666667

667668
if 'x' in opts: # -x prevents actual execution
668-
print
669+
print()
669670
else:
670-
print 'done. Executing edited code...'
671+
print('done. Executing edited code...')
671672
with preserve_keys(self.shell.user_ns, '__file__'):
672673
if not is_temp:
673674
self.shell.user_ns['__file__'] = filename

IPython/core/magics/config.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Implementation of configuration-related magic functions.
22
"""
3+
from __future__ import print_function
34
#-----------------------------------------------------------------------------
45
# Copyright (c) 2012 The IPython Development Team.
56
#
@@ -116,9 +117,9 @@ def config(self, s):
116117
line = s.strip()
117118
if not line:
118119
# print available configurable names
119-
print "Available objects for config:"
120+
print("Available objects for config:")
120121
for name in classnames:
121-
print " ", name
122+
print(" ", name)
122123
return
123124
elif line in classnames:
124125
# `%config TerminalInteractiveShell` will print trait info for
@@ -128,7 +129,7 @@ def config(self, s):
128129
help = cls.class_get_help(c)
129130
# strip leading '--' from cl-args:
130131
help = re.sub(re.compile(r'^--', re.MULTILINE), '', help)
131-
print help
132+
print(help)
132133
return
133134
elif reg.match(line):
134135
cls, attr = line.split('.')

IPython/core/magics/deprecated.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Deprecated Magic functions.
22
"""
3+
from __future__ import print_function
34
#-----------------------------------------------------------------------------
45
# Copyright (c) 2012 The IPython Development Team.
56
#
@@ -26,20 +27,20 @@ class DeprecatedMagics(Magics):
2627
@line_magic
2728
def install_profiles(self, parameter_s=''):
2829
"""%install_profiles has been deprecated."""
29-
print '\n'.join([
30+
print('\n'.join([
3031
"%install_profiles has been deprecated.",
3132
"Use `ipython profile list` to view available profiles.",
3233
"Requesting a profile with `ipython profile create <name>`",
3334
"or `ipython --profile=<name>` will start with the bundled",
3435
"profile of that name if it exists."
35-
])
36+
]))
3637

3738
@line_magic
3839
def install_default_config(self, parameter_s=''):
3940
"""%install_default_config has been deprecated."""
40-
print '\n'.join([
41+
print('\n'.join([
4142
"%install_default_config has been deprecated.",
4243
"Use `ipython profile create <name>` to initialize a profile",
4344
"with the default config files.",
4445
"Add `--reset` to overwrite already existing config files with defaults."
45-
])
46+
]))

0 commit comments

Comments
 (0)