python can't print unpacked floats from network
Question: I try to get floats from an UDP datagram and to print them to verify:

    
    
    import socket
    from struct import *
    
    socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    socket.bind( ('127.0.0.1', 2416) )
    msg = bytearray( 4*1024 ) 
    f1 = 0.0
    f2 = 0.0
    f3 = 0.0
    while True:
        nBytes = socket.recv_into( msg )
        print( '%d bytes received' % nBytes )
        (f1) = unpack_from( '!f', msg, 0 )
        (f2) = unpack_from( '!f', msg, 4 )
        (f3) = unpack_from( '!f', msg, 8 )
        print( '%f, %f, %f received' % ( f1, f2, f3 ))
    

The following error is raised:

    
    
    $ python Server.py
    12 bytes received
    Traceback (most recent call last):
      File "Server.py", line 13, in <module>
        print( '%f, %f, %f received' % ( f1, f2, f3 ))
    TypeError: a float is required
    

The expected output is `1.2, 3.4, 5.6 received`.

Context:

    
    
    Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)] on win32
    

For information the Java UDP sender (client):

    
    
    import java.io.IOException;
    import java.net.DatagramPacket;
    import java.net.DatagramSocket;
    import java.net.InetAddress;
    import java.nio.ByteBuffer;
    
    public class Client {
    
       public static void main( String[] args ) throws Exception {
          try( DatagramSocket clientSocket = new DatagramSocket()) {
             InetAddress target = InetAddress.getByName( "localhost" );
             ByteBuffer msg = ByteBuffer.allocate( 4*1024 );
             for(;;) {
                msg.clear();
                msg.putFloat(   1.20f );
                msg.putFloat(   3.40f );
                msg.putFloat(   5.60f );
                msg.putDouble(  7.80  );
                msg.putDouble(  9.10  );
                msg.putDouble( 11.120 );
                msg.flip();
                clientSocket.send(
                   new DatagramPacket( msg.array(), msg.limit(), target, 2416 ));
                Thread.sleep( 2000 );
             }
          }
       }
    }
    


Answer: This line is the problem:

    
    
    (f1) = unpack_from( '!f', msg, 0 )
    

Try

    
    
    (f1,) = unpack_from( '!f', msg, 0 )
    

Note the additional comma. Similarly for the other two lines.

As you mentioned, `unpack_from` returns a tuple. `(f1)` is not a tuple, it is
a single value. `(f1,)` is a tuple containing one element.

