本办法学python 随记2

# # -*- coding:utf-8-*-


# 文件的创建 追加  读取
# import os
# def make_text_file():
# 	if os.path.isfile('test.txt'):
# 		print("tring to create a file")
# 	else:
# 		a = open('test.txt','w')
# 		a.write("where are you ")
# 		# a.close
# def add_text_file():
# 	a = open('test.txt','a')
# 	a.write("\n i am here")
# 	a.close()
# def read_text_file():
# 	a = open('test.txt','r')
# 	# 打印内容
# 	t = a.read()
# 	print(t) 
# 	# 打印每行长度
# 	text = a.readlines()
# 	for line in text:
# 		print(len(line)) 
# 	del a #删除文件
# 	a.close()#关闭文件
# # file error IOError




# # os模块可以解决不同平台之间的程序移植,但不是绝对的




# #os.path.join()可将目录名称组合成路径 sample:
# import os.path
# # print(os.path.join("snakes","python"))
# # os.path.split()将路径的最后一个组件提取出来sample:""
# # print(os.path.split("D:\\LearningPython\\FileOs.py"))
# strs = "D:\\LearningPython\\FileOs.py"
# parent_path,name = os.path.split(strs)
# print(parent_path)
# print(name)




# # 将路径完全分解为若干个目录 


# def split_fully(path):
# 	parent_path,name = os.path.split(path)
# 	if name == "":
# 		return (parent_path, )
# 	else:
# 		return split_fully(parent_path) + (name, )
# print(split_fully(strs))
# # 分解一个文件的扩展名 os.path.splitext()
# print(os.path.splitext("iamg.jpg"))
# # 提取扩展名
# extension = os.path.splitext("image.jpg")[1]
# print(extension)




# # os.path.normpath() 规范化或清理路径:
# paths = os.path.normpath(r"D:\\LearningPython\Perl\..\FileOs.py")
# print(paths)
# # os.path.abspath() :将一个相对路径转变为一个绝对路径
# print(os.path.abspath("FileOs.py"))
# # os.path.exists()判断某个路径是否存在,尽简单的返回true false
# print(os.path.exists("C:\\Windows\\FileOs"))
# print(os.path.exists("D:\\LearningPython"))
# # os.listdir()  返回一个目录下所有名称条目,包括文件和子目录等内容
# print(os.listdir("D:\\LearningPython"))




# # 列出某个目录中的内容 以完整路径展示
# import os
# def print_dir(dir_path):
# 	for name in os.listdir(dir_path):
# 		print(os.path.join(dir_path,name))


# print(print_dir("c:\\python33"))




# # 排序:sorted() 默认情况下按字母表排序  区分大小写
# print(sorted(os.listdir("c:\\python33")))




# 
# 列出桌面或主目录的内容:print_dir_by_ext()
# 查询》》》》》》》》》
# import os  
# print(os.print_dir_by_ext)
# 




# # 判断一个路径是否指向文件或目录:True false
# # os.path.isfile()       os.path.isdir()
# import os
# print(os.path.isfile("C:\\Windows"))
# print(os.path.isdir("C:\\Windows"))




# # 递归目录列表
# def print_tree(dir_path):
# 	for name in os.listdir(dir_path):
# 		full_path = os.path.join(dir_path,name)
# 		print(full_path)
# 		if os.path.isdir(full_path):
# 			print_tree(full_path)


# os.path.getsize:返回文件大小
# os.path.getmtime():返回文件上次修改时间 1970起
# time.ctime()规范时间结果格式
# import os
# import time
# mod_time = os.path.getmtime("C:\\python33")
# print(time.ctime(mod_time))




#打印条目录 而不是完整路径
# def print_dir_info(dir_path):
# 	for name in os.listdir(dir_path):
# 		full_path = os.path.join(dir_path,name)
# 		file_size = os.path.getsize(full_path)
# 		mod_time = time.ctime(os.path.getmtime(full_path))
# 		print("%-32s:%8d bytes,modified %s" %(name,file_size,mod_time))


# print_dir_info("d:\\LearningPython")




# 文件重命名\移动:shutil.move()
# import shutil
# shutil.move("test.txt","d:\\LearningPython")
# shutil.move("d:\\LearningPython\\test.txt","d:\\LearningPython\\tst.txt")


# 复制文件:shutil.copy()
# shutil.copy("d:\\LearningPython\\tst.txt","D:\\MyDrivers")
 
 #  删除文件 os.remove()  or  os.unlink()
# import os
# os.remove("d:\\MyDrivers\\tst.txt")
# os.unlink("d:\\MyDrivers\\tst.txt")


# 文件权限修改:os.chmod() 与linux的使用方式一样




# # 文件轮换,版本的更新
# import os
# import shutil


# def make_version_path(path,version):
# 	if version == 0:
# 		# No suffix for version 0,the current version
# 		return path
# 	else:
# 		# Append a suffix to indicate the older version
# 		return path + "." +str(version)
# def rotate(path,version=0):
# 	# Construct the name of the version we're rotating
# 	old_path = make_version_path(path,version)
# 	if not os.path.exists(old_path):
# 		# it doesn't exist,so complain.
# 		raise IOError("'%s' doesn't exist" % path)
# 	# Construct the new version name for this file
# 	new_path = make_version_path(path,version+1)
# 	# is there already a version with this name?
# 	if os.path.exists(new_path):
# 		# yes.Rotate it out of the way first
# 		rotate(path,version + 1)
# 	# now we can rename the version safely
# 	shutil.move(old_path,new_path)


# # 轮换可能存在的日志文件函数
# def rotate_log_file(path):
# 	if not os.path.exists(path):
# 		# the file is missing,so create it.
# 		new_file = open(path,"w")
# 		# close the new file immediately,which leaves it empty
# 		del new_file
# 	# now rotate it
# 	rotate(path)


# rotate_log_file("d:\\LearningPython\\tst.txt")
# # rotate("d:\\LearningPython\\tst.txt.1")


# 创建删除目录


# os.mkdir():创建目录 前提:父目录必须存在
# os.makedirs():可以创建不存在的父目录
import os
# os.mkdir("D:\\LearningPython\\zoo\\snakes")
# os.makedirs("D:\\LearningPython\\zoo\\snakes")


# os.rmdir():删除目录 前提:目录内容为空
# os.rmdir("D:\\LearningPython\\zoo\\snakes") #仅是删除了子目录
# shutil.rmtree():实现删除包含其他文件和子目录的目录,需谨慎使用该函数
# sample:
# shutil.rmtree("d:\\photos") :该代码会删除完整的图片集,包括zoo,snakes等




# 通配符
 # glob()可实现对目录的通配功能,glob.glob()接受模式
 # 作为输入,并返回所有匹配的文件名和路径名列表,类似于os.listdir
# sample:
import glob
# print(glob.glob("c:\\program files\\M*"))
# Python 中的glob模块在所有的平台都使用相同的语法,通配模式语法与正则表达式语法类似但不相同
# 通配符     匹配                           示例
# *        0个或多个任意字符                *.m*匹配扩展名以m开头的名称
# ?         任意单个字符                    ???匹配恰好包含3个字符的名称    
# [...]     方括号中列出的任意一个字符      [AEIOU]*匹配以大写的元音字母开头的名称
# [!...]   不在方括号中出现的任意一个字符   *[!s]匹配不以s结尾的名称
# 可在方括号之间使用某个范围内的字符,例如:
# [m-p]匹配m,n,o,p中任意一个字母
# [!0-9]匹配数字以外的任意字符


# 若删除目录d:\\source\\中所有扩展名为.bak的备份文件,可执行:
# for path in glob.glob("d:\\source\\*.bak"):
# 	os.remove(path)
# 通配符比os.listdir功能要强悍好多,因为可在目录或子目录名称中指定通配符
# 对于此模式,glob.glob可以返回多个目录下的路径。如:
# glob.glob("*\\*.txt") 可返回当前目录下所有子目录中扩展名为.txt的文件
 
# 习题1  148
# import os
# def print_dir(dir_path):
# 	for name in os.listdir(dir_path):
# 		strs = os.path.join(dir_path,name)
# 		print(strs)
# 		if(os.path.isdir(strs)):
# 			print_dir(strs)


# print(sorted(print_dir("d:\\y")))

#-*-coding:utf-8-*-
# 文件读写
# 统计文件中的字符串个数
# import re
# fp = open("d:\LearningPython\\files\\test1.txt","r")
# count = 0
# for i in fp.readlines():
# li = re.findall("hello",i)
# if len(li) > 0:
# count += len(li)


# print(count)
# fp.close()


# 文件内容替换
# 示例1:
# f1 = open("d:\LearningPython\\files\\test1.txt","r")
# f2 = open("d:\LearningPython\\files\\test2.txt","w")
# for s in f1.readlines():
# f2.write(s.replace("hello","龙龙龙"))
# f1.close()
# f2.close()


# 示例2:
# f1 = open("d:\LearningPython\\files\\test1.txt","r+")
# s = f1.read()
# f1.seek(0,0)
# f1.write(s.replace("d","华人")) 
# f1.close()




# 目录遍历
# # 示例1
# import os 
# def dirList(path):
# filelist = os.listdir(path)
# allfile = []
# for filename in filelist:
# # allfile.append(filepath+'\\'+filename)
# fp = os.path.join(path,filename)
# if(os.path.isdir(fp)):
# dirList(fp)
# allfile.append(fp)
# print(fp)


# # return allfile




# allfile = dirList('d:\LearningPython\\testdir')
# # print(allfile)


# 示例2:
# import os
# for path,d,filelist in os.walk("d:\LearningPython\\testdir"):
# for filename in filelist:
# print(os.path.join(path,filename))




# 正则表达式
import re
r = '010-\d{8}'

re.findall(r,'010-12345678')


一、sql数据库 驱动   

二、Oricle数据库 驱动

三、正则表达式

四、 Java算法

五、计算机环境变量配置:

JAVA_HOME---------jdk位置

Path   ----------------bin

CLASSPATH ----------lib

六、JDBC的四种类型的驱动程序:

----- JDBC-ODBC桥驱动程序

-----Native-API Partly-java 驱动程序

-----JDBC-Net Pure-java 驱动程序

-----Native Protocol Pure-java 驱动程序

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值