随笔分类 - python学习
个人学习使用,所有收集仅供参考。
摘要:import shutil import os import os.path src = " d:\\download\\test\\myfile1.txt " dst = " d:\\download\\test\\myfile2.txt " dst2 = " d:/download/test/测
阅读全文
摘要:import os.path # 常用函数有三种:分隔路径,找出文件名.找出盘符(windows系统),找出文件的扩展名. # 根据你机器的实际情况修改下面参数. spath = " D:/download/repository.7z " # case 1: p,f = os.path.split(
阅读全文
摘要:import os import os.path # os,os.path里包含大多数文件访问的函数,所以要先引入它们. # 请按照你的实际情况修改这个路径 rootdir = " d:/download " for parent, dirnames, filenames in os.walk(ro
阅读全文
摘要:每一个.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
阅读全文
摘要: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
阅读全文
摘要:#! /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)
阅读全文
摘要:对比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.
阅读全文
摘要:#! /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
阅读全文
摘要:比起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
阅读全文
摘要:#! /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
阅读全文