You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by aa...@apache.org on 2021/02/20 10:16:29 UTC

[hadoop] branch branch-3.1 updated: HADOOP-16764. Rewrite Python example codes using Python3 (#1762)

This is an automated email from the ASF dual-hosted git repository.

aajisaka pushed a commit to branch branch-3.1
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/branch-3.1 by this push:
     new 7bcb1a8  HADOOP-16764. Rewrite Python example codes using Python3 (#1762)
7bcb1a8 is described below

commit 7bcb1a83a37cec84180ab7e549a300b056b2669f
Author: Kengo Seki <se...@apache.org>
AuthorDate: Mon Dec 16 11:04:20 2019 +0900

    HADOOP-16764. Rewrite Python example codes using Python3 (#1762)
    
    (cherry picked from commit fd7de2b82a6b9d600b43909a0770a6b0afea899a)
---
 .../hadoop-common/src/site/markdown/RackAwareness.md    |  6 +++---
 .../src/site/markdown/HadoopStreaming.md.vm             | 17 +++++++++--------
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/hadoop-common-project/hadoop-common/src/site/markdown/RackAwareness.md b/hadoop-common-project/hadoop-common/src/site/markdown/RackAwareness.md
index 89946d1..9b3b1d7 100644
--- a/hadoop-common-project/hadoop-common/src/site/markdown/RackAwareness.md
+++ b/hadoop-common-project/hadoop-common/src/site/markdown/RackAwareness.md
@@ -64,7 +64,7 @@ rack and is unable to do so as there is only a single rack named
 python Example
 --------------
 ```python
-#!/usr/bin/python
+#!/usr/bin/python3
 # this script makes assumptions about the physical environment.
 #  1) each rack is its own layer 3 network with a /24 subnet, which
 # could be typical where each rack has its own
@@ -94,9 +94,9 @@ for ip in sys.argv:                                              # loop over lis
     address = '{0}/{1}'.format(ip, netmask)                      # format address string so it looks like 'ip/netmask' to make netaddr work
     try:
         network_address = netaddr.IPNetwork(address).network     # calculate and print network address
-        print "/{0}".format(network_address)
+        print("/{0}".format(network_address))
     except:
-        print "/rack-unknown"                                    # print catch-all value if unable to calculate network address
+        print("/rack-unknown")                                   # print catch-all value if unable to calculate network address
 ```
 
 bash Example
diff --git a/hadoop-tools/hadoop-streaming/src/site/markdown/HadoopStreaming.md.vm b/hadoop-tools/hadoop-streaming/src/site/markdown/HadoopStreaming.md.vm
index 072a68b..f125b63 100644
--- a/hadoop-tools/hadoop-streaming/src/site/markdown/HadoopStreaming.md.vm
+++ b/hadoop-tools/hadoop-streaming/src/site/markdown/HadoopStreaming.md.vm
@@ -416,27 +416,28 @@ To use Aggregate, simply specify "-reducer aggregate":
       -output myOutputDir \
       -mapper myAggregatorForKeyCount.py \
       -reducer aggregate \
-      -file myAggregatorForKeyCount.py \
+      -file myAggregatorForKeyCount.py
 
 The python program myAggregatorForKeyCount.py looks like:
 
-    #!/usr/bin/python
+    #!/usr/bin/python3
 
-    import sys;
+    import sys
 
     def generateLongCountToken(id):
         return "LongValueSum:" + id + "\t" + "1"
 
     def main(argv):
-        line = sys.stdin.readline();
+        line = sys.stdin.readline()
         try:
             while line:
-                line = line&#91;:-1];
-                fields = line.split("\t");
-                print generateLongCountToken(fields&#91;0]);
-                line = sys.stdin.readline();
+                line = line[:-1]
+                fields = line.split("\t")
+                print(generateLongCountToken(fields[0]))
+                line = sys.stdin.readline()
         except "end of file":
             return None
+
     if __name__ == "__main__":
          main(sys.argv)
 


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org