Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
understand function
#3
I have two files, from which I need to get ip and port information or more generally find what is equal or what is different using mrjob. The following code is a draft of what I'm trying to do.
from mrjob.job import MRJob
import csv
cols='ipv,vvv.vvv.vvv'.split(',') 

def parse_line(line_str):
    return dict(zip(cols,[a.strip() for a in csv.reader([line_str]).next()]))

def parse_ip_address(ip_str):
    ip=ip_str;
    return ip

def parse_port(p_str):
    port=p_str;
    return (port)

class Myclass(MRJob):
    def mapper(self, _, line):
        #parse the line from current CVS form
        p1=parse_line(line)
        #get ip
        ip_address=parse_ip_address(p1['vvv.vvv.vvv'])
        #get port
        port=parse_port(p1['ipv'])
        #yield a key and a value
        yield port,ip_address

    #reducer function
    def reducer(self, key, values):
        yield key

if __name__ == '__main__':
    Myclass.run()
Reply


Messages In This Thread
understand function - by hermann - Sep-01-2017, 10:37 AM
RE: understand function - by buran - Sep-01-2017, 11:34 AM
RE: understand function - by hermann - Sep-01-2017, 02:05 PM
RE: understand function - by hermann - Sep-06-2017, 10:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Don't Understand Recursive Function muzikman 9 3,773 Dec-03-2020, 05:10 PM
Last Post: muzikman
  Need to understand the way enumerate() function works abhishekambastha 2 2,512 Sep-16-2018, 08:21 PM
Last Post: snippsat
  i don't understand how to use a variable outside of a function? Rius2 6 5,369 Oct-04-2017, 06:31 PM
Last Post: wavic
  Can't understand the output of this recursion function bigmit37 5 4,025 Apr-04-2017, 11:15 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020