Tumblelog by Soup.io
Newer posts are loading.
You are at the newest post.
Click here to check if anything new just came in.
xenplex
17:46

Gray Hat Python - Summary 1

This is my summary of the first Chapter of "Gray Hat Python".
Note that this is not meant as a tutorial, more like a personal notebook fo mine and to give you some keywords of what you find in the book.

* ctypes library enables to call functions in dynamically linked libraries (on Windows this would be the .DLL files)
* complex c datatypes
*low-level memory manipulation

On Windows the C runtime is msvcrt

byref() function is for passing parameters by reference
   function_main(byref(parameter))

=> Defining Structures and Unions
structure = a group of variables, same or different types in C:

struct beer_recipe
{
   int amt_barley;
   int amt_water;
};

in Python:

class beer_recipe (Structure):
   __fields__ = [
      ("amt_barley", c_int),
      ("amt_water", c_int)
   ]

union = variables share same memory location

in C:

union {
   long barley_long;
   int barley_int;
   char barley_char[8];
} barley_amount;

in Python:

class barley_amount (Union):
   __fields__ = [
      ("barley_long", c_long),
      ("barley_int", c_int),
      ("barley_char", c_char * 8),
   ]

Don't be the product, buy the product!

Schweinderl