>> import shutil
>> import os
>> os.chdir('C:\')
>> shutil.copy('C:\spam.txt', 'C:\delicious')
'C:\delicious\spam.txt'
>> shutil.copy('eggs.txt', 'C:\delicious\eggs2.txt')
'C:\delicious\eggs2.txt'
from shutil import *
from glob import glob
print 'BEFORE:', glob('huanhuan.*')
copyfile('huanhuan.txt', 'huanhuan.txt.copy')
print 'AFTER:', glob('huanhuan.*')
>>> ================================ RESTART ================================ >>> BEFORE: ['huanhuan.txt'] AFTER: ['huanhuan.txt', 'huanhuan.txt.copy']
from shutil import *
import os
from StringIO import StringIO
import sys
class VerboseStringIO(StringIO):
def read(self, n=-1):
next = StringIO.read(self, n)
print 'read(%d) bytes' % n
return next
lorem_ipsum = '''This makes the dependency explicit, limits the scope to the current file and provides faster access to the bit.* functions, too.
It's good programming practice not to rely on the global variable bit being set (assuming some other part of your application has already loaded the module).
The require function ensures the module is only loaded once, in any case.'''
print 'Defalut:'
input = VerboseStringIO(lorem_ipsum)
output = StringIO()
copyfileobj(input, output)
print
print 'All at once:'
input = VerboseStringIO(lorem_ipsum)
output = StringIO()
copyfileobj(input, output, -1)
print
print 'Blocks of 256:'
input = VerboseStringIO(lorem_ipsum)
output = StringIO()
copyfileobj(input, output, 256)
>>> ================================ RESTART ================================ >>> Defalut: read(16384) bytes read(16384) bytes All at once: read(-1) bytes read(-1) bytes Blocks of 256: read(256) bytes read(256) bytes read(256) bytes
from shutil import *
import os
dir = os.getcwd()
if not os.path.exists('%s\example' % dir):
os.mkdir('%s\example' % dir)
print 'BEFORE:', os.listdir('example')
copy('huanhuan.txt', 'example')
print 'AFTER:', os.listdir('example')
>>> ================================ RESTART ================================ >>> BEFORE: [] AFTER: ['huanhuan.txt']
from shutil import *
import os
import time
dir = os.getcwd()
if not os.path.exists('%s\example' % dir):
os.mkdir('%s\example' % dir)
def show_file_info(filename):
stat_info = os.stat(filename)
print 'tMode :', stat_info.st_mode
print 'tCreated :', time.ctime(stat_info.st_ctime)
print 'tAccessed:', time.ctime(stat_info.st_atime)
print 'tModified:', time.ctime(stat_info.st_mtime)
print 'SOURCE:'
show_file_info('huanhuan.txt')
copy2('huanhuan.txt', 'example')
print 'DEST:'
show_file_info('%s\example\huanhuan.txt' % dir)
>>> ================================ RESTART ================================ >>> SOURCE: Mode : 33206 Created : Thu Feb 13 17:42:46 2014 Accessed: Thu Feb 13 17:42:46 2014 Modified: Thu Feb 13 17:42:46 2014 DEST: Mode : 33206 Created : Thu Feb 13 18:29:14 2014 Accessed: Thu Feb 13 17:42:46 2014 Modified: Thu Feb 13 17:42:46 2014
from shutil import *
import os
from commands import *
with open('file_to_change.txt', 'wt') as f:
f.write('i love you')
os.chmod('file_to_change.txt', 0444)
print 'BEFORE:'
print getstatus('file_to_change.txt')
copymode('shutil_copymode.py', 'file_to_change.txt')
print 'AFTER:'
print getstatus('file_to_change.txt')
from shutil import *
import os
import time
def show_file_info(filename):
stat_info = os.stat(filename)
print 'tMode :', stat_info.st_mode
print 'tCreated :', time.ctime(stat_info.st_ctime)
print 'tAccessed :', time.ctime(stat_info.st_atime)
print 'tModified :', time.ctime(stat_info.st_mtime)
with open('file_to_change.txt', 'wt') as f:
f.write('i love you')
os.chmod('file_to_Change.txt', 0444)
print 'BEFORE:'
show_file_info('file_to_Change.txt')
copystat('shutil_copystat.py', 'file_to_Change.txt')
print 'AFTER:'
show_file_info('file_to_Change.txt')
from shutil import *
from commands import *
print 'BEFORE:'
print getoutput('ls -rlast /tmp/example')
copytree('../shutil', '/tmp/example')
print 'nAFTER:'
print getoutput('ls -rlast /tmp/example')
from shutil import *
from commands import *
print 'BEFORE:'
print getoutput('ls -rlast /tmp/example')
rmtree('/tmp/example')
print 'nAFTER:'
print getoutput('ls -rlast /tmp/example')
from shutil import *
from glob import glob
with open('example.txt', 'wt') as f:
f.write('i love you')
print 'BEFORE: ', glob('example*')
move('example.txt', 'example.out')
print 'AFTER: ',glob('example*')
>>> ================================ RESTART ================================ >>> BEFORE: ['example', 'example.txt'] AFTER: ['example', 'example.out']
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有