From: Frans Klaver <fransklaver@gmail.com>
To: Sebastian Morr <sebastian@morr.cc>
Cc: git@vger.kernel.org, srabbelier@gmail.com,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: Re: [PATCH] Use Python's "print" as a function, not as a keyword
Date: Wed, 21 Dec 2011 09:43:58 +0100 [thread overview]
Message-ID: <CAH6sp9M3eMFA5a1CSidO4WsSBVkvUQCAqh1VD1S11V2RRiYHKA@mail.gmail.com> (raw)
In-Reply-To: <20111221021930.GA31364@thinkpad>
On Wed, Dec 21, 2011 at 3:19 AM, Sebastian Morr <sebastian@morr.cc> wrote:
> This has changed from Version 2.6 to Version 3.0. Replace all occurrences of
>
> print ...
>
> with
>
> print(...)
>
> and all occurrences of
>
> print >> output, ...
>
> with
>
> output.write(... + "\n")
While it's good to look forward, you shouldn't forget about testing on
python 2.6. Lots of people still stick to that and maybe even to
earlier versions.
> if len(argv) < 2:
> - print 'Usage:', argv[0], '<zipfile>...'
> + print('Usage:', argv[0], '<zipfile>...')
> exit(1)
>
Here I would use the % notation:
print('Usage: %s <zipfile>...' % argv[0])
Python 2.x would print a tuple:
>>> argv = ('import-zips.py',)
>>> print("Usage:", argv[0], '<zipfile>...')
('Usage:', 'import-zips.py', '<zipfile>...')
You could probably get away with
print('Usage: ' + argv[0] + ' <zipfile>...')
But that could probably become a readability issue. I would even
wonder if it's considered pythonic.
It happens a few times more:
> if verbose:
> - print 'tip is', tip
> + print('tip is', tip)
> @@ -176,27 +176,27 @@ for cset in range(int(tip) + 1):
> os.write(fdcomment, csetcomment)
> os.close(fdcomment)
>
> - print '-----------------------------------------'
> - print 'cset:', cset
> - print 'branch:', hgbranch[str(cset)]
> - print 'user:', user
> - print 'date:', date
> - print 'comment:', csetcomment
> + print('-----------------------------------------')
> + print('cset:', cset)
> + print('branch:', hgbranch[str(cset)])
> + print('user:', user)
> + print('date:', date)
> + print('comment:', csetcomment)
> if parent:
> - print 'parent:', parent
> + print('parent:', parent)
> if mparent:
> - print 'mparent:', mparent
> + print('mparent:', mparent)
> if tag:
> - print 'tag:', tag
> - print '-----------------------------------------'
> + print('tag:', tag)
> + print('-----------------------------------------')
>
> # checkout the parent if necessary
> if cset != 0:
> if hgbranch[str(cset)] == "branch-" + str(cset):
> - print 'creating new branch', hgbranch[str(cset)]
> + print('creating new branch', hgbranch[str(cset)])
> os.system('git checkout -b %s %s' % (hgbranch[str(cset)], hgvers[parent]))
> else:
> - print 'checking out branch', hgbranch[str(cset)]
> + print('checking out branch', hgbranch[str(cset)])
> os.system('git checkout %s' % hgbranch[str(cset)])
>
> # merge
> @@ -205,7 +205,7 @@ for cset in range(int(tip) + 1):
> otherbranch = hgbranch[mparent]
> else:
> otherbranch = hgbranch[parent]
> - print 'merging', otherbranch, 'into', hgbranch[str(cset)]
> + print('merging', otherbranch, 'into', hgbranch[str(cset)])
> os.system(getgitenv(user, date) + 'git merge --no-commit -s ours "" %s %s' % (hgbranch[str(cset)], otherbranch))
>
> # remove everything except .git and .hg directories
> @@ -229,12 +229,12 @@ for cset in range(int(tip) + 1):
>
> # delete branch if not used anymore...
> if mparent and len(hgchildren[str(cset)]):
> - print "Deleting unused branch:", otherbranch
> + print("Deleting unused branch:", otherbranch)
> os.system('git branch -d %s' % otherbranch)
>
> # retrieve and record the version
> vvv = os.popen('git show --quiet --pretty=format:%H').read()
> - print 'record', cset, '->', vvv
> + print('record', cset, '->', vvv)
> hgvers[str(cset)] = vvv
>
> if hgnewcsets >= opt_nrepack and opt_nrepack != -1:
> @@ -243,7 +243,7 @@ if hgnewcsets >= opt_nrepack and opt_nrepack != -1:
> # write the state for incrementals
> if state:
> if verbose:
> - print 'Writing state'
> + print('Writing state')
> f = open(state, 'w')
> pickle.dump(hgvers, f)
>
> diff --git a/contrib/p4import/git-p4import.py b/contrib/p4import/git-p4import.py
> index b6e534b..144fafc 100644
> --- a/contrib/p4import/git-p4import.py
> +++ b/contrib/p4import/git-p4import.py
> @@ -26,11 +26,11 @@ if s != default_int_handler:
> def die(msg, *args):
> for a in args:
> msg = "%s %s" % (msg, a)
> - print "git-p4import fatal error:", msg
> + print("git-p4import fatal error:", msg)
> sys.exit(1)
>
I think that's it for the print(...,...) stuff. I might have misssed
one or two though.
> diff --git a/git-remote-testgit.py b/git-remote-testgit.py
> index 3dc4851..9803214 100644
> --- a/git-remote-testgit.py
> +++ b/git-remote-testgit.py
> @@ -81,9 +81,9 @@ def do_capabilities(repo, args):
> """Prints the supported capabilities.
> """
>
> - print "import"
> - print "export"
> - print "refspec refs/heads/*:%s*" % repo.prefix
> + print("import")
> + print("export")
> + print("refspec refs/heads/*:%s*" % repo.prefix)
>
> dirname = repo.get_base_path(repo.gitdir)
>
> @@ -92,11 +92,11 @@ def do_capabilities(repo, args):
>
> path = os.path.join(dirname, 'testgit.marks')
>
> - print "*export-marks %s" % path
> + print("*export-marks %s" % path)
> if os.path.exists(path):
> - print "*import-marks %s" % path
> + print("*import-marks %s" % path)
>
> - print # end capabilities
> + print() # end capabilities
print("") here. 2.x:
>>> print()
()
>
>
> def do_list(repo, args):
> @@ -109,16 +109,16 @@ def do_list(repo, args):
>
> for ref in repo.revs:
> debug("? refs/heads/%s", ref)
> - print "? refs/heads/%s" % ref
> + print("? refs/heads/%s" % ref)
>
> if repo.head:
> debug("@refs/heads/%s HEAD" % repo.head)
> - print "@refs/heads/%s HEAD" % repo.head
> + print("@refs/heads/%s HEAD" % repo.head)
> else:
> debug("@refs/heads/master HEAD")
> - print "@refs/heads/master HEAD"
> + print("@refs/heads/master HEAD")
>
> - print # end list
> + print() # end list
print("")
Lots more to do, I'm afraid.
Cheers,
Frans
prev parent reply other threads:[~2011-12-21 8:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-21 2:19 [PATCH] Use Python's "print" as a function, not as a keyword Sebastian Morr
2011-12-21 2:48 ` Ævar Arnfjörð Bjarmason
2011-12-21 16:12 ` Sverre Rabbelier
2011-12-27 16:41 ` Pete Wyckoff
2011-12-21 8:43 ` Frans Klaver [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAH6sp9M3eMFA5a1CSidO4WsSBVkvUQCAqh1VD1S11V2RRiYHKA@mail.gmail.com \
--to=fransklaver@gmail.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=sebastian@morr.cc \
--cc=srabbelier@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).