I have a simple (and maybe silly) question about binary data files. If a simple type is used (int/float/..) it is easy to imagine the structure of the binary file (a sequence of floats, with each float written using a fixed number of bytes). But what about structures, objects and functions ? Is there some kind of convension for each language with regards to the order in which the variables names / attributes / methods are written, and if so, can this order be changed and cusotomized ? otherwise, is there some kind of header that describes the format used in each file ?
I'm mostly interested in python and C/C++. When I use a pickled (or gzipped) file for example, python "knows" whether the original object has a certain method or attribute without me casting the unpickled object or indicating its type and I've always wondered how is that implemented. I didn't know how to look this up on Google because it may have something to do with how these languages are designed in the first place. Any pointers would be much appreciated.
Binary files contain data.  
There are a plethora of data layouts of binary files.  Some examples are JPEG, Executables, Word Processor, Raw Text and archive files.  
A file may have an extension that may indicate the layout.  For example, a ".png" would would most likely follow the PNG format.  A "bin" or "dat" extension is to generic.  One could zip up files and name the archive with a "png" extension.  
If there is no file extension or the OS doesn't store the type of a file, then the format of the file is based on discovery (or trying random formats).  Some file formats have integrity values in them to help verify correctness.  Knowing the integrity value and how it was calculated, can assist in classify the format type.  Again, there is no guarantee.
BTW, file formats are independent of the language to used to read them.  One could read a gzipped file using FORTRAN or BASIC.
Binary files structure for objects and structs in C++/Python