Skip to content

Commit 5f969ce

Browse files
sekiknaajisaka
authored andcommitted
HADOOP-16764. Rewrite Python example codes using Python3 (#1762)
(cherry picked from commit fd7de2b)
1 parent 7363e6e commit 5f969ce

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

hadoop-common-project/hadoop-common/src/site/markdown/RackAwareness.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ rack and is unable to do so as there is only a single rack named
6464
python Example
6565
--------------
6666
```python
67-
#!/usr/bin/python
67+
#!/usr/bin/python3
6868
# this script makes assumptions about the physical environment.
6969
# 1) each rack is its own layer 3 network with a /24 subnet, which
7070
# could be typical where each rack has its own
@@ -94,9 +94,9 @@ for ip in sys.argv: # loop over lis
9494
address = '{0}/{1}'.format(ip, netmask) # format address string so it looks like 'ip/netmask' to make netaddr work
9595
try:
9696
network_address = netaddr.IPNetwork(address).network # calculate and print network address
97-
print "/{0}".format(network_address)
97+
print("/{0}".format(network_address))
9898
except:
99-
print "/rack-unknown" # print catch-all value if unable to calculate network address
99+
print("/rack-unknown") # print catch-all value if unable to calculate network address
100100
```
101101

102102
bash Example

hadoop-tools/hadoop-streaming/src/site/markdown/HadoopStreaming.md.vm

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -416,27 +416,28 @@ To use Aggregate, simply specify "-reducer aggregate":
416416
-output myOutputDir \
417417
-mapper myAggregatorForKeyCount.py \
418418
-reducer aggregate \
419-
-file myAggregatorForKeyCount.py \
419+
-file myAggregatorForKeyCount.py
420420

421421
The python program myAggregatorForKeyCount.py looks like:
422422

423-
#!/usr/bin/python
423+
#!/usr/bin/python3
424424

425-
import sys;
425+
import sys
426426

427427
def generateLongCountToken(id):
428428
return "LongValueSum:" + id + "\t" + "1"
429429

430430
def main(argv):
431-
line = sys.stdin.readline();
431+
line = sys.stdin.readline()
432432
try:
433433
while line:
434-
line = line[:-1];
435-
fields = line.split("\t");
436-
print generateLongCountToken(fields[0]);
437-
line = sys.stdin.readline();
434+
line = line[:-1]
435+
fields = line.split("\t")
436+
print(generateLongCountToken(fields[0]))
437+
line = sys.stdin.readline()
438438
except "end of file":
439439
return None
440+
440441
if __name__ == "__main__":
441442
main(sys.argv)
442443

0 commit comments

Comments
 (0)