Progress Bar for Console Programs as Iterator (Python) Leave a comment Read more »

Progress Bar for Console Programs as Iterator (Python)

A small proxy iterator showing a progress bar on the console. Only works with iterators that provide a length (i.e.len(iterator) must be defined). ## {{{ http://code.activestate.com/recipes/576986/ (r6) import sys def progressbar(it, prefix = “”, size = 60): count = len(it) def _show(_i): x = int(size*_i/count)…


Mass image resizing (with progress bar and details in console) [Python] Leave a comment Read more »

Mass image resizing (with progress bar and details in console) [Python]

Ok so I found this script on this site and it’s rely useful so I decided to share it with you all. Here we go : This script uses the Python Imaging libraries to resize images in a folder and its sub-folders iteratively. The details…


Read more »

Python script to extract all email addresses from bulk text

This script will open a file with email addresses in it, then extract # this script will open a file with email addresses in it, then extract # those address and write them to a new file import os import re # vars for filenames…


Leave a comment Read more »

Python: OS module

http://snipplr.com/view/25249/python-os-module/ ## The os module provides a portable platform-independent interface to access common operating services, allowing you to add OS-level support to your programs. The following examples illustrate some of the most common uses of the os module. ## The os.path.abspath(path) function of the os…


Leave a comment Read more »

Opening a file on python

Link : http://snipplr.com/view/25277/opening-a-file/ Python uses the simple open(path [,mode [,buffersize]]) call to open files for both reading and writing. The path is a path string pointing to the file. The mode determines what mode the file will be opened in. The optional buffersize argument specifies…


Leave a comment Read more »

Sockets on Python

# Client program from socket import * # Set the socket parameters host = “localhost” port = 21567 buf = 1024 addr = (host,port) # Create socket UDPSock = socket(AF_INET,SOCK_DGRAM) def_msg = “===Enter message to send to server===”; print “\n”,def_msg # Send messages while (1):…


Leave a comment Read more »

create a zipfile from an input file

import zlib, zipfile, os def zipme (inputFilename): fileName = os.path.basename(inputFilename) zipFileName = os.path.basename (os.path.splitext(fileName)[0]) + ‘.zip’ zipFilePath = os.path.dirname (inputFilename) zFile = zipfile.ZipFile(zipFilePath + ‘/’ + zipFileName ,’w') zFile.write (inputFilename, fileName, zipfile.ZIP_DEFLATED) zFile.close() if os.stat(zipFileName): print ‘zipfile created : %s’ % (zipFileName) return 1 else…


Leave a comment Read more »

List all directories in a path and save the information to a text file

#################################################### ## ## Prints a dir structure to a text file ## ## Usage : python printdir.py [path ala z:/mypath or /mypath/foo ## #################################################### import os, sys dir = sys.argv[1] outName = ‘dirpaths.txt’ f = open(outName,’w') # write initial dir for reference f.write (dir +…


Linux is changing the world

Login



Optimized by SEO Ultimate