Posts

Showing posts from May, 2013

Python code: TypeError: 'str' object is not callable

Missing % can cause chaos with string expansions, Sometime the print/logging statement become too huge to verify where the string is coming from. For example in this case you might be looking for string that is used as callable forever, if you dont look at the actual string thats being expanded. Input: def foo1(x):     return str(x) foo2 = lambda x: None if x is None else str(x) def myprint(x):     print x x = 5 myprint("x=%s, foo1(x)=%s, foo2(x)=%s" %         (str(x), foo1(x), foo2(x))) myprint("x=%s, foo1(x)=%s, foo2(x)=%s"         (str(x), foo1(x), foo2(x))) Output: x=5, foo1(x)=5, foo2(x)=5 Traceback (most recent call last):   File "a.py", line 15, in <module>     (x, foo1(x), foo2(x))) TypeError: 'str' object is not callable

FD column in linux command lsof means a lot ....

lsof gives a ton of information about the files and devices that are open on a system. FD has always wondered me with some wierd numbers/characters. Atlast I bothered to look at it for knowing whether tcpdump has started or not to sniff the device and realized it gives details about the what kind of device/file is opened and the permissions etc. From the man page,        FD         is the File Descriptor number of the file or:                        cwd  current working directory;                        Lnn  library references (AIX);                        err  FD information error (see NAME column);                        jld  jail directory (FreeBSD);                        ltx  shared library text (code and data);                        Mxx  hex memory-mapped type number xx.                        m86  DOS Merge mapped file;                        mem  memory-mapped file;                        mmap memory-mapped device;                        pd   parent directory;    

Want a fast and temporary file system on linux?

Just use a tmpfs/ramfs and a cron job continously backing up data from  this to a non-volatile storage. mount -t tmpfs -o size=1024m tmpfs /tmp Generally, I use this for logs on virtual machines, as sometimes the  disk is very slow due to multiple VMs running off the same disk. Also,  this has the advantage of not wearing out the disk, which might have  more important/persistent data.