Skip to content

{ Category Archives } python

create zip files under python

#!/usr/bin/python import os, os.path, glob, zipfile DIR=”/home/kraneis/” # change to directory os.chdir(DIR) # read a content fList=glob.glob(‘pythonbsp/test/*’) print “It exist ” + str(len(fList))+ ” files” filelist = [ fn for fn in fList if os.path.isfile(fn)] print “here are the files” print filelist z=zipfile.ZipFile(“/tmp/test.zip”,’w’,zipfile.ZIP_DEFLATED) print “the methods for z objects” print [s for s in dir(z) […]

Tagged

Backup MySQL with Python

#!/usr/bin/python #purpose: backup mysql database usin mysqldump # date: 05.07.2009 # S.Kraneis import os import time DESTDIR=’/home/kraneis/python/backup/’ USERNAME=’root’ PASSWORD=’testpw’ DATE= time.strftime(“%Y-%m-%d”) DBLIST = [“testdb”] def DUMP_CMD(x): # cmd = “mysqldump –add-drop-table -u %s -p%s %s > %s%s-%s.sql” % (USERNAME,PASSWORD,x,DESTDIR,x,DATE) cmd1 = “mysqldump –add-drop-table -u ” + USERNAME + ” -p” + PASSWORD + ” ” […]

Tagged ,

List all Directories and file in Python

I want list all directories and files in python. here is short code: #!/usr/bin/python import os COUNT=0 for root, dirs, files in os.walk(‘/home/kraneis/python/’): for name in files: filename = os.path.join(root,name) print filename COUNT +=1 TOTAL=COUNT print “Es gibt insgesamt ” + str(TOTAL) + ” files” …. …. /home/kraneis/python/examples/xml/languages.xml /home/kraneis/python/examples/numbers/decimal_localcontext.py /home/kraneis/python/examples/numbers/get_sample_naive.py /home/kraneis/python/examples/lists/allindex.py /home/kraneis/python/examples/lists/listsortci.py Es gibt insgesamt […]

Tagged