Recent Notes

Displaying keyword search results 1 - 5
Created by Dr. Xi on August 02, 2009 02:43:13    Last update: August 30, 2010 16:08:48
os.mkdir - Create a directory. Returns None. os.mkdir(path [, mode=0777]) os.makedirs - reate a leaf directory and all intermediate ones. Returns None. os.makedirs(path [, mode=0777]) This works like mkdir, except that any intermediate path segment will be created if it does not exist.
Created by Dr. Xi on May 05, 2009 19:59:21    Last update: May 05, 2009 19:59:21
Delete a single file: >>> import os >>> file = 'myfile' >>> os.rem... Delete a directory and contents: >>> import shutil >>> dir(shutil) ['Error', ...
Created by Dr. Xi on October 06, 2008 18:39:53    Last update: October 06, 2008 18:39:53
Python modules are searched in the list of directories given by the variable sys.path which is initialized from: the directory containing the input script (or the current directory) the list of directories specified by the environment variable PYTHONPATH the installation-dependent default. peaches@bashful:~/tmp$ export PYTHONPATH=`pwd` ...
Created by Dr. Xi on December 12, 2007 20:30:01    Last update: December 12, 2007 20:32:23
This is a script to tail a log file through the web browser. It uses AJAX, apache web server, mod_python, UNIX utilities tail (requires the --lines switch) and wc . The log file may reside on the web server or any other host accessible from the web server through SSH. Although it's written in python, it should be easy to port to other languages such as Perl. Apache httpd.conf : LoadModule python_module modules/mod_python.so ... Python script: import time, os from os.path import basename ...
Created by Dr. Xi on October 07, 2007 20:54:21    Last update: October 07, 2007 21:49:14
import os # test file exist os.path.... However, os.access tests access with the real uid/gid, not the effective uid/gid. It is intended to be used by setuid apps that need to test whether the real user id has the desired access. The most direct way to see if you can do a certain operation on a file is to simply try it. If you get an error, then you can't do it. You can catch the exception and handle it appropriately.