Skip to content

Commit 7c30942

Browse files
committed
Merge pull request #60 from nloadholtes/nloadholtes_python3
python3 compatible sample code
2 parents 47e31bb + 02c9a7d commit 7c30942

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

Diff for: samples/basic/basic.py

+23-23
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
DEFAULT_TAG = "python_sample_basic"
1414

1515
def dump_response(response):
16-
print "Upload response:"
16+
print("Upload response:")
1717
for key in sorted(response.keys()):
18-
print " %s: %s" % (key, response[key])
18+
print(" %s: %s" % (key, response[key]))
1919

2020
def upload_files():
21-
print "--- Upload a local file"
21+
print("--- Upload a local file")
2222
response = upload("pizza.jpg", tags = DEFAULT_TAG)
2323
dump_response(response)
2424
url, options = cloudinary_url(response['public_id'],
@@ -27,10 +27,10 @@ def upload_files():
2727
height = 150,
2828
crop = "fill"
2929
)
30-
print "Fill 200x150 url: " + url
31-
print
30+
print("Fill 200x150 url: " + url)
31+
print("")
3232

33-
print "--- Upload a local file with custom public ID"
33+
print("--- Upload a local file with custom public ID")
3434
response = upload("pizza.jpg",
3535
tags = DEFAULT_TAG,
3636
public_id = "custom_name",
@@ -42,10 +42,10 @@ def upload_files():
4242
height = 150,
4343
crop = "fit"
4444
)
45-
print "Fit into 200x150 url: " + url
46-
print
45+
print("Fit into 200x150 url: " + url)
46+
print("")
4747

48-
print "--- Upload a local file with eager transformation of scaling to 200x150"
48+
print("--- Upload a local file with eager transformation of scaling to 200x150")
4949
response = upload("lake.jpg",
5050
tags = DEFAULT_TAG,
5151
public_id = "eager_custom_name",
@@ -62,10 +62,10 @@ def upload_files():
6262
height = 150,
6363
crop = "scale",
6464
)
65-
print "scaling to 200x150 url: " + url
66-
print
65+
print("scaling to 200x150 url: " + url)
66+
print("")
6767

68-
print "--- Upload by fetching a remote image"
68+
print("--- Upload by fetching a remote image")
6969
response = upload("http://res.cloudinary.com/demo/image/upload/couple.jpg",
7070
tags = DEFAULT_TAG,
7171
)
@@ -77,10 +77,10 @@ def upload_files():
7777
crop = "thumb",
7878
gravity = "faces",
7979
)
80-
print "Face detection based 200x150 thumbnail url: " + url
81-
print
80+
print("Face detection based 200x150 thumbnail url: " + url)
81+
print("")
8282

83-
print "--- Fetch an uploaded remote image, fitting it into 500x500 and reducing saturation"
83+
print("--- Fetch an uploaded remote image, fitting it into 500x500 and reducing saturation")
8484
response = upload("http://res.cloudinary.com/demo/image/upload/couple.jpg",
8585
tags = DEFAULT_TAG,
8686
width = 500,
@@ -98,25 +98,25 @@ def upload_files():
9898
radius = 10,
9999
effect = "sepia",
100100
)
101-
print "Fill 200x150, round corners, apply the sepia effect, url: " + url
102-
print
101+
print("Fill 200x150, round corners, apply the sepia effect, url: " + url)
102+
print("")
103103

104104
def cleanup():
105105
response = resources_by_tag(DEFAULT_TAG)
106106
count = len(response.get('resources', []))
107107
if (count == 0):
108-
print "No images found"
108+
print("No images found")
109109
return
110-
print "Deleting %d images..." % (count,)
110+
print("Deleting %d images..." % (count,))
111111
delete_resources_by_tag(DEFAULT_TAG)
112-
print "Done!"
112+
print("Done!")
113113
pass
114114

115115
if len(sys.argv) > 1:
116116
if sys.argv[1] == 'upload': upload_files()
117117
if sys.argv[1] == 'cleanup': cleanup()
118118
else:
119-
print "--- Uploading files and then cleaning up"
120-
print " you can only one instead by passing 'upload' or 'cleanup' as an argument"
121-
print
119+
print("--- Uploading files and then cleaning up")
120+
print(" you can only one instead by passing 'upload' or 'cleanup' as an argument")
121+
print("")
122122
upload_files()

0 commit comments

Comments
 (0)