Thread: Map() Function?

    #1
  1. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    155

    Map() Function?


    I have some code here and it goes in a new parse_data code that someone gave me. I can't find out what causes the problem though.
    Code:
    def dataArrival(data):
           tmpStr = s.recv(data)
           s.recv(data)
           parse_data(tmpStr)
    Code:
    def parse_data(d):
         map(handle_event, d.split("\r\n"))
         parse_data = lambda d: map(handle_event, d.split("\r\n"))
    First of all, I'm not even sure if that dataArrival is correct but I'm pretty sure it is. I used try and except for every line to find the exact problem, it brought up map(handle_event, d.split("\r\n")). Is there something wrong with that code?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    35
    First of all, I'm not even sure if that dataArrival is correct but I'm pretty sure it is.
    It isn't, because you've switched it back to VB-style.

    Code:
    def dataArrival(data):
           tmpStr = s.recv(data)
           s.recv(data)
    tmpStr = s.recv(data) is meaningless as recv can only take one parameter - the amount of data to receive. You can't tell it what to receive.

    Calling s.recv() again without storing the return value takes some random amount of data and throws it away, which is probably not the right thing to do.

    Code:
    def parse_data(d):
         map(handle_event, d.split("\r\n"))
         parse_data = lambda d: map(handle_event, d.split("\r\n"))
    Is there something wrong with that code?
    Not with the map() call, as long as handle_event is available.
    The last line, though, probably shouldn't be there. It does exactly the same as the first two lines:

    Code:
    def parse_data(d):
         map(handle_event, d.split("\r\n"))
    and

    Code:
    parse_data = lambda d: map(handle_event, d.split("\r\n"))
    Do the same thing.

IMN logo majestic logo threadwatch logo seochat tools logo