Sublime Text 2作为一款轻量级的编辑器,特点鲜明,方便使用,愈发受到普罗大众的喜爱,我个人最近也开始用了起来。同时,我近段时间还在学习Python的相关东西,所以开始用ST2来写Python,所以把配置方法略微总结一下。

1. 在工具栏点击Preferences,打开Browse Packages。在打开的文件夹中找到Python,并打开这个文件夹。找到文件Python.sublime-build,并打开。

2. 修改以下内容:

{

"cmd": ["python", "-u", "$file"],

"path":"F:/Program Files/Python27",

"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",

"selector": "source.python"

}

把path里面的内容修改为编译器的安装目录即可。保存代码,ctrl+b便可以运行了


os.listdir()

os.path.isdir()

os.path.split() 返回一个路径的目录名和文件名

os.path.dirname()

os.system()

os.mkdir("file")

os.chdir( "C:\\123")


复制模板

import os,sys
os.chdir("f:\\51cto")
for lists in os.listdir('.'):
	if os.path.isdir(lists):
		list1="d:\\muban\\" + lists
		os.mkdir(list1)


python用paramiko模块上传本地目录到远程目录


http://wangwei007.blog.51cto.com/68019/1285412

#!/usr/bin/env python
import paramiko,datetime,os
hostname='192.168.1.100'
username='root'
password='123456'
port=22
def upload(local_dir,remote_dir):
    try:
        t=paramiko.Transport((hostname,port))
        t.connect(username=username,password=password)
        sftp=paramiko.SFTPClient.from_transport(t)
        print 'upload file start %s ' % datetime.datetime.now()
        for root,dirs,files in os.walk(local_dir):
            for filespath in files:
                local_file = os.path.join(root,filespath)
                a = local_file.replace(local_dir,'')
                remote_file = os.path.join(remote_dir,a)
                try:
                    sftp.put(local_file,remote_file)
                except Exception,e:
                    sftp.mkdir(os.path.split(remote_file)[0])
                    sftp.put(local_file,remote_file)
                print "upload %s to remote %s" % (local_file,remote_file)
            for name in dirs:
                local_path = os.path.join(root,name)
                a = local_path.replace(local_dir,'')
                remote_path = os.path.join(remote_dir,a)
                try:
                    sftp.mkdir(remote_path)
                    print "mkdir path %s" % remote_path
                except Exception,e:
                    print e
        print 'upload file success %s ' % datetime.datetime.now()
        t.close()
    except Exception,e:
        print e
if __name__=='__main__':
    local_dir='/home/soft/'
    remote_dir='/tmp/aaa/'
    upload(local_dir,remote_dir)


自己写的

import os
import datetime
def cpall(local_dir,remote_dir):
    for root, dirs, files in os.walk(local_dir):
        for name in dirs:
            local_path = os.path.join(root, name)
            a = local_path.replace(local_dir, '')
            remote_path = os.path.join(remote_dir, a)
            os.mkdir(remote_path)
if __name__=='__main__':
    local_dir="E:\\muban\\51cto\\"
    remote_dir="D:\\muban\\"
    cpall(local_dir,remote_dir)