os 모듈#
샘플소스
print '############# os module';
import os;
print os.getcwd();
print os.listdir(os.getcwd());
os.rename('test.txt', 'TEST.txt');
print os.listdir(os.getcwd());
|
실행결과
############# os module
/home/fromm0/python
['condition.py', 'variable.py', 'types.py', 'modules.py', 'test.txt']
['condition.py', 'TEST.txt', 'variable.py', 'types.py', 'modules.py']
|
string모듈#
샘플소스
print '########## string module';
import string;
print string.capitalize('test');
print string.replace('simple', 'i', 'a');
print string.split('break into word');
|
실행결과
########## string module
Test
sample
['break', 'into', 'word']
|
정규표현식 모듈#
샘플소스
print '########## Regex module';
import re, glob;
p=re.compile('.*p.*n.*');
for i in glob.glob('*'):
m=p.match(i);
if m:
print m.group();
|
실행결과
웹브라우저 모듈#
샘플소스
print '########## webbrowser module';
import webbrowser;
url = 'http://openframework.or.kr/';
#webbrowser.open(url);
|
실행결과
########## webbrowser module
|
웹브라우저 모듈#
샘플소스
print '########## random module';
import random;
for i in range(1,10):
print random.random();
for i in range(1,6):
print random.randrange(1,6);
list = ['a', 'b', 'c', 'd'];
print random.shuffle(list);
print random.choice(list);
|
실행결과
########## random module
0.135566930706
0.532723011734
0.317244262385
0.236457081391
0.301902953634
0.580148646058
0.241545397656
0.838296187545
0.730686900942
3
4
5
2
5
None
a
|
Add new attachment
Only authorized users are allowed to upload new attachments.
«
This page (revision-5) was last changed on
04-Oct-2008 16:11 by DongGukLee