python基本语法

在工作中,要用到Python写几个脚本文件,以下为用到几个字段,特记录如下:

1、in

字符串包含关系,用in

if "hello" in "hello world":

//include

2、if

if True:

pass//待实现的内容

3、ftplib

ftp上传、下载

from ftplib import FTP
import os

ip = "127.0.0.1"

def ftp_down(filename = "fileName"): 
  ftp=FTP() 
  ftp.set_debuglevel(2) 
  ftp.connect(ip,'21') 
  ftp.login(user, password) 
  #print ftp.getwelcome()
  bufsize = 1024
  file_handler = open(filename,'wb').write
  
  ftp.retrbinary('RETR %s' % os.path.basename(filename),file_handler,bufsize)
  
  ftp.set_debuglevel(0) 
  #file_handler.close() 
  ftp.quit()
  print "ftp down OK"


def ftp_up(filename = "fileName"): 
    ftp=FTP() 
    ftp.set_debuglevel(2)
    ftp.connect(ip,'21')
    ftp.login(user, password)
    bufsize = 1024
    file_handler = open(filename,'rb')
    ftp.storbinary('STOR %s' % os.path.basename(filename),file_handler,bufsize)
    ftp.set_debuglevel(0) 
    file_handler.close() 
    ftp.quit() 
    print "ftp up OK" 

4、sys.argv

sys.argv[0]:脚本本身的名称

sys.argv[1]:脚本执行时传的第一个参数,如:test.py firstParam

len(sys.argv):计算参数个数

5、os.system

执行shell命令,如:os.system("ls -l ")

6、os.chdir

切换目录命令,等同于 shell下的cd命令

os.chdir("/usr/local")

7、print

打印命令,打印字符串

print "hello world"


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值