Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use print() function in both Python 2 and Python 3 #722

Merged
merged 3 commits into from Jul 22, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -20,6 +20,7 @@
The documentation is generated from a combination of the discovery document and
the generated API surface itself.
"""
from __future__ import print_function

__author__ = 'jcgregorio@google.com (Joe Gregorio)'

@@ -354,7 +355,7 @@ def document_api(name, version):
try:
service = build(name, version)
except UnknownApiNameOrVersion as e:
print 'Warning: {} {} found but could not be built.'.format(name, version)
print('Warning: {} {} found but could not be built.'.format(name, version))
return

http = build_http()
@@ -156,7 +156,7 @@ def _retry_request(http, num_retries, req_type, sleep, rand, uri, method, *args,
LOGGER.warning(
'Sleeping %.2f seconds before retry %d of %d for %s: %s %s, after %s',
sleep_time, retry_num, num_retries, req_type, method, uri,
resp.status if resp else exception)
resp.status if resp else Exception)

This comment has been minimized.

Copy link
@tseaver

tseaver Jul 22, 2019

Collaborator

This change loses the re-bound exception below, which means it loses information about the actual cause.

sleep(sleep_time)

try:
@@ -38,6 +38,7 @@
__author__ = 'rahulpaul@google.com (Rahul Paul)'

import pprint
import re
import sys

from oauth2client import client
@@ -92,7 +92,7 @@ def main(argv):

pprint.pprint(update_result)

except AccessTokenRefreshError as e:
except client.AccessTokenRefreshError as e:
print ('The credentials have been revoked or expired, please re-run'
'the application to re-authorize')

@@ -34,6 +34,7 @@
$ python search_analytics_api_sample.py 'https://www.example.com/' '2015-05-01' '2015-05-30'
"""
from __future__ import print_function

import argparse
import sys
@@ -176,22 +177,22 @@ def print_table(response, title):
response: The server response to be printed as a table.
title: The title of the table.
"""
print '\n --' + title + ':'

print('\n --' + title + ':')
if 'rows' not in response:
print 'Empty response'
print('Empty response')
return

rows = response['rows']
row_format = '{:<20}' + '{:>20}' * 4
print row_format.format('Keys', 'Clicks', 'Impressions', 'CTR', 'Position')
print(row_format.format('Keys', 'Clicks', 'Impressions', 'CTR', 'Position'))
for row in rows:
keys = ''
# Keys are returned only if one or more dimensions are requested.
if 'keys' in row:
keys = u','.join(row['keys']).encode('utf-8')
print row_format.format(
keys, row['clicks'], row['impressions'], row['ctr'], row['position'])
print(row_format.format(
keys, row['clicks'], row['impressions'], row['ctr'], row['position']))

if __name__ == '__main__':
main(sys.argv)
@@ -9,6 +9,11 @@

from googleapiclient.discovery import build

try:
input = raw_input
except NameError:
pass


SHOPPING_API_VERSION = 'v1'
DEVELOPER_KEY = 'AIzaSyACZJW4JwcWwz5taR2gjIMNQrtgDLfILPc'
@@ -30,8 +35,8 @@ def main():
itemsPerPage = response['itemsPerPage']
totalItems = response['totalItems']
for i in range(1, totalItems, itemsPerPage):
answer = raw_input('About to display results from %s to %s, y/(n)? ' %
(i, i + itemsPerPage))
answer = input('About to display results from %s to %s, y/(n)? ' %
(i, i + itemsPerPage))
if answer.strip().lower().startswith('n'):
# Stop if the user has had enough
break
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.