摘要: import shutil import os import os.path src = " d:\\download\\test\\myfile1.txt " dst = " d:\\download\\test\\myfile2.txt " dst2 = " d:/download/test/测 阅读全文
posted @ 2019-07-25 14:10 樊伟胜 阅读(512) 评论(0) 推荐(0) 编辑
摘要: import os.path # 常用函数有三种:分隔路径,找出文件名.找出盘符(windows系统),找出文件的扩展名. # 根据你机器的实际情况修改下面参数. spath = " D:/download/repository.7z " # case 1: p,f = os.path.split( 阅读全文
posted @ 2019-07-25 14:09 樊伟胜 阅读(10211) 评论(0) 推荐(0) 编辑
摘要: import os import os.path # os,os.path里包含大多数文件访问的函数,所以要先引入它们. # 请按照你的实际情况修改这个路径 rootdir = " d:/download " for parent, dirnames, filenames in os.walk(ro 阅读全文
posted @ 2019-07-25 14:07 樊伟胜 阅读(577) 评论(0) 推荐(0) 编辑
摘要: 每一个.py文件称为一个module,module之间可以互相导入.请参看以下例子: # a.py def add_func(a,b): return a+b # b.py from a import add_func # Also can be : import a print ("Import  阅读全文
posted @ 2019-07-25 14:06 樊伟胜 阅读(201) 评论(0) 推荐(0) 编辑
摘要: class Base: def __init__(self): self.data = [] def add(self, x): self.data.append(x) def addtwice(self, x): self.add(x) self.add(x) # Child extends Ba 阅读全文
posted @ 2019-07-25 14:05 樊伟胜 阅读(222) 评论(0) 推荐(0) 编辑
摘要: #! /usr/bin/python s=input("Input your age:") if s =="": raise Exception("Input must no be empty.") try: i=int(s) except Exception as err: print(err) 阅读全文
posted @ 2019-07-25 14:04 樊伟胜 阅读(483) 评论(0) 推荐(0) 编辑
摘要: 对比Java,python的文本处理再次让人感动 #! /usr/bin/python spath="D:/download/baa.txt" f=open(spath,"w") # Opens file for writing.Creates this file doesn't exist. f. 阅读全文
posted @ 2019-07-25 14:04 樊伟胜 阅读(350) 评论(0) 推荐(0) 编辑
摘要: #! /usr/bin/python # -*- coding: utf8 -*- def sum(a,b): return a+b func = sum r = func(5,6) print (r) # 提供默认值 def add(a,b=2): return a+b r=add(1) prin 阅读全文
posted @ 2019-07-25 14:03 樊伟胜 阅读(349) 评论(0) 推荐(0) 编辑
摘要: 比起C/C++,Python处理字符串的方式实在太让人感动了.把字符串当列表来用吧. #! /usr/bin/python word="abcdefg" a=word[2] print ("a is: "+a) b=word[1:3] print ("b is: "+b) # index 1 and 阅读全文
posted @ 2019-07-25 14:02 樊伟胜 阅读(560) 评论(0) 推荐(0) 编辑
摘要: #! /usr/bin/python #条件和循环语句 x=int(input("Please enter an integer:")) if x<0: x=0 print ("Negative changed to zero") elif x==0: print ("Zero") else: pr 阅读全文
posted @ 2019-07-25 14:02 樊伟胜 阅读(233) 评论(0) 推荐(0) 编辑
摘要: #! /usr/bin/python x={'a':'aaa','b':'bbb','c':12} print (x['a']) print (x['b']) print (x['c']) for key in x: print ("Key is %s and value is %s" %  阅读全文
posted @ 2019-07-25 14:01 樊伟胜 阅读(462) 评论(0) 推荐(0) 编辑
摘要: #! /usr/bin/python # -*- coding: utf8 -*- #列表类似Javascript的数组,方便易用 #定义元组 word=['a','b','c','d','e','f','g'] #如何通过索引访问元组里的元素 a=word[2] print ("a is: "+a 阅读全文
posted @ 2019-07-25 14:00 樊伟胜 阅读(530) 评论(0) 推荐(0) 编辑
摘要: #打开新窗口,输入: #! /usr/bin/python # -*- coding: utf8 -*- s1=input("Input your name:") print("你好,%s" % s1) ''' 知识点: * input("某字符串")函数:显示"某字符串",并等待用户输入. * p 阅读全文
posted @ 2019-07-25 13:59 樊伟胜 阅读(1892) 评论(0) 推荐(0) 编辑
摘要: 但有趣的是,在javascript里我们会理想当然的将字符串和数字连接,因为是动态语言嘛.但在Python里有点诡异,如下: #! /usr/bin/python a=2 b="test" c=a+b 运行这行程序会出错,提示你字符串和数字不能连接,于是只好用内置函数进行转换 #! /usr/bin 阅读全文
posted @ 2019-07-25 13:59 樊伟胜 阅读(13710) 评论(0) 推荐(0) 编辑