Chinaunix首页 | 论坛 | 博客
  • 博客访问: 21054
  • 博文数量: 27
  • 博客积分: 585
  • 博客等级: 中士
  • 技术积分: 270
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-20 17:11
文章分类

全部博文(27)

文章存档

2013年(1)

2012年(26)

我的朋友
最近访客

分类: Python/Ruby

2012-12-27 10:41:09

二十一、使用函数*

lambda语句被用来创建新的函数对象,并且在运行时返回它们

 

def make_repeater(n):

    return lambda s: s*n          #这个最他妈重要

twice = make_repeater(2)

print twice('word')

print twice(5)

 

---------------------------

结果

wordword

10

 

二十二、直接使用input键盘输入

可以直接使用input直接在键盘输入一个整数

 

intNum = int(input('input_intNum:'))

print intNum

 

二十三、python中添加中文注释

在代码的最上面添加

# coding=gbk

 

二十四、将数字转换成字符

str(i),i表示的是数字

 

二十五、python与Linux交互

 

 

#coding:gbk

# filename: ssh_chen.py

import paramiko

class ssh_chen:

    def __init__(self,ip='129.99.106.94',username='root',password='huawei'):

        self.ip = ip

        self.port = 22

        self.username = username

        self.password = password

 

        self.client = paramiko.SSHClient()

        self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

       

    def execcmd_forCreateDre(self,filename):

        self.client.connect(self.ip, self.port, self.username, self.password, timeout=4)

        for i in range(1,5):

            cmd = 'cd /home/chenlei;mkdir '+filename+str(i)

            print cmd

            self.client.exec_command(cmd)

        self.client.close()

if __name__=='__main__':

    a = ssh_chen()

a.execcmd_forCreateDre('cao')

 

二十六、使用函数查看文件的全路径

 

import sys

print 'The command line arguments are:'

for i in sys.argv:

    print i

print '\n\nThe PYTHONPATH is', sys.path, '\n'

 

 

 

执行结果:

The command line arguments are:

D:\LTestV100R001C00B017\LTest\bin\LTestProjects\chentest\src\test\21_user_sys_.py

 

 

The PYTHONPATH is ['D:\\LTestV100R001C00B017\\LTest\\bin\\LTestProjects\\chentest\\src\\test', 'D:\\LTestV100R001C00B017\\LTest\\bin\\LTestProjects\\chentest\\src', 'C:\\Python27\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\win32', 'C:\\Python27\\lib\\site-packages\\win32\\lib', 'C:\\Python27\\lib\\site-packages\\Pythonwin', 'C:\\Python27\\lib\\site-packages\\wx-2.8-msw-unicode']

 

 

阅读(163) | 评论(0) | 转发(0) |
0

上一篇:python--part5

下一篇:python--part7

给主人留下些什么吧!~~