Sep 7, 2010

Python librarys

OS library - This will provide many number of functons which will interact with the operating system.
>>>import os # import the os library.
>>>dir(os) # can get a list of all module
# functions in the os module
>>>help(os) # will give the man page of os # module

Some important things from os module.

os.chdir('path') - change the current directory
os.chmod('path', 0777) - change the mode
os.chown('path',user_id,group_id) - change owner'path', flag, 0755) open or create file
this will return a file descripter.
os.close(fd) - close the opend file according to the file descripter.
os.execl('file', *args) - excecute a file
os.fork() - make a chiled process
os.fstat(fd) - get stat of the file descripter
os.mkdir('path', 0644) - create a directiory
os.pipe(read,write) - pipe,buffersize)
os.remove('path') - remove file
os.rename(old , new) - rename files

shutil module - THis will do the file management tasks.

import shutil
shutil.move('source','destination') - recursivly move file or directory to another location
shutil.copytree(src,dst,symlinks=False) - recursivly copy a directory
shutil.rmtree(path, ignore_errors=False,onerror=None) -
shutil.recursivly remove files in a direstory

glob - provide wildcard search
import glob

sys.argv - give the command line arguments
sys.exit - directly exit from a script

re module - this provide reguler expresion for python
math module - this provide mathematical functioons defined by the C standards.
random module - this provide randome selection

No comments:

Post a Comment

Your comments are always welcome ...