Esta tabla es muy representativa al respecto:
| Type code | C Type | Python Type | Minimum size in bytes |
|---|---|---|---|
| 'b' | signed char | int | 1 |
| 'B' | unsigned char | int | 1 |
| 'u' | Py_UNICODE | Unicode character | 2 (see note) |
| 'h' | signed short | int | 2 |
| 'H' | unsigned short | int | 2 |
| 'i' | signed int | int | 2 |
| 'I' | unsigned int | int | 2 |
| 'l' | signed long | int | 4 |
| 'L' | unsigned long | int | 4 |
| 'f' | float | float | 4 |
| 'd' | double | float | 8 |
De cara al uso de streams caben destacar dos peculiaridades:
* No existe char, es un str (string) de longitud 1.
* No existe byte, solo int.
Por tanto, cuando leemos de un Stream, se lee y escribe en modo str.
Esta situación nos lleva a una peculiaridad ya que para comparar bytes y visualizar las imágenes necesitamos int (==char), y por tanto un casting.
Pero si luego queremos guardar dichas imágenes es necesario volver a str (==char).
Estas conversiones de tipos se consiguen con ord() y char().
Páginas relevantes:
https://docs.python.org/3.1/library/array.html
http://www.tutorialspoint.com/python/python_variable_types.htm
No hay comentarios:
Publicar un comentario