Posts

Showing posts from July, 2014

Splitting python path using os.path module

Avoid using "/" at the end of the directory paths as they would generate empty filename when used with functions like os.path.split() > > > import os > > > os . path . split ( '/tmp/foo' ) ( '/tmp' , 'foo' ) > > > os . path . split ( '/tmp/foo/' ) ( '/tmp/foo' , '' ) Reference: https://docs.python.org/2/library/os.path.html

Class/Global variables vs Instance Variables ...

Class/Global variables are like CoW, only when the instances assign them values they have their own memory location allocated. For example in this case a.bar is assigned a value and hence it has different memory location allocated, but the same is not the case with b.bar >> > class Foo ( object ) : bar = None >> > repr ( Foo . bar ) 'None' >> > a = Foo ( ) >> > a . bar = 1 >> > repr ( Foo . bar ) 'None' >> > a . bar 1 >> > b = Foo ( ) >> > b . bar >> > repr ( b . bar ) 'None' >> > a . bar 1 >> > id ( Foo . bar ) 135796184 >> > id ( a . bar ) 151257264 >> > id ( b . bar ) 135796184