pretty

Sunday, November 25, 2012

File modification time python



import os, time
(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(file)
print "last modified: %s" % time.ctime(mtime)

http://stackoverflow.com/questions/237079/how-to-get-file-creation-modification-date-times-in-python

Wednesday, November 14, 2012

Update all python pip packages


import pip
from subprocess import call

for dist in pip.get_installed_distributions():
call("pip install --upgrade " + dist.project_name, shell=True)
i use it with ipython

sudo ipython
""" Cut the code above and type
%paste

Monday, November 5, 2012

Kill process with python on linux



import os
import signal

def kill_process(processname):
for line in os.popen("ps xa"):
fields = line.split()
pid = fields[0]
process = fields[4]
print process
if process == processname:
os.kill(int(pid), signal.SIGKILL)
break
else:
pass
look here for a windows solution or google it