Search This Blog

Thursday, June 18, 2009

Python sys, os, input/output, subprocess

import glob
glob.glob('*.html')

import subprocess
p = subprocess.Popen("ls -l", shell=True, stdout=subprocess.PIPE)
out = p.stdout.read
#p342, python essential reference


file = open('spam.txt', 'rwb')
file.write('stuff')
file.close()
text = file.read()


reply = raw_input('please input something')

import os
os.system('ls')
os.listdir('.')
os.path.walk
dir = os.walk('.') #is a generator,
dir.next()

os.getpid()
os.getcwd()
os.chdir('new_dir')

os.path.isdir('dir')
os.path.exists('file')
os.path.getsize('file')
os.path.abspath('file')

os.environ
os.fork
os.pipe
os.execl
os.spawnv
os.open
os.mkdir
os.stat
os.remove
os.path.walk, os.walk

for f in (sys.stdin, sys.stdout, sys.stderr): print f

import webbrowser
webbrowser.open('page.html')


No comments: