10 2017 档案
摘要:2013年10月10日 2015年3月30日修正坐标参考模型 1 OGR几何对象模型OGRGeometry 1.1 Geometry 几何图形,最基本的地图图形。注意:包含空间参考。 其它所有的地图图形都是由本类派生出来的。 包含了通用的属性和方法。 注意:空间操作的部分需要GEOS支持,如果没有G
阅读全文
摘要:import shutil, os, zipfile # 复制、移动、改名、删除文件与文件夹 #shutil.copy('e:\\111\\key.txt', 'd:\\111\\') # copy文件 #shutil.copytree('e:\\111', 'd:\\111\\aaa') # co
阅读全文
摘要:import pprint#格式化打印message = 'It was a bright cold day in April, and the clocks were striking thirteen.'count = {}for character in message: count.setd
阅读全文
摘要:import shelve# shelve_demo.py 持久性字典:Python对象的持久化# 键值对形式, 将内存数据通过文件持久化, 值支持任何pickle支持的Python数据格式# 与pickle的主要区别是键值对方式, 并且在目录下生成三个文件class Person(object):
阅读全文
摘要:import pickle# 序列化 用于对Python对象进行序列化和反序列化的二进制协议f = open("pickle.txt", "wb+")lists = [123, "中文", [456]]strs = "字符串"num = 123# 写入pickle.dump(lists, f) #
阅读全文
摘要:import os path = os.getcwd() # 获取当前目录print("路径: {}".format(path)) # 路径: E:\python\练习\笔记dirname = os.path.dirname(path) # 获取文件夹名print("文件夹名为: {}".forma
阅读全文
摘要:import osimport signal # 执行命令dirs = os.popen("dir").read()print(dirs)# 打印目录树dirs_info = os.scandir()for info in dirs_info: print("文件名: {}, 路径: {}, ino
阅读全文
摘要:import calendarimport timecalen_text = calendar.TextCalendar()# 打印月历calen_text.prmonth(2017, 5, w=0, l=0)# 打印年历calen_text.pryear(2017, w=2, l=1, c=6,
阅读全文
摘要:import datetime import time datetime_dt = datetime.datetime.today() # 获取当前日期和时间, 2017-10-26 10:03:28.693198datetime_str = datetime_dt.strftime("%Y/%m/
阅读全文
摘要:import timedef time_demo(): curtime = time.time() # 获取当前时间戳, 1508982743.220433 time_str = time.ctime(curtime) # 转为string格式, 'Thu Oct 26 09:52:23 2017'
阅读全文
摘要:import random # 随机数模块 lists = [1, 2, 3, 4, 5] def demo(): # 产生[0, 100]随机整数 num = random.randint(0, 100) print(num) # 产生[0, 100)随机浮点数 fnum = random.uni
阅读全文
摘要:import sys# 捕获异常 (可灵活组合) def excep(): # - try except - try: print(ex) except: # 捕获所有异常 print("捕获异常!") try: print(ex) except: # 通过函数获取异常信息 types, value
阅读全文
摘要:# 调用自定义模块 #coding=utf-8# mymodule.py 自定义模块def myfunction(): return "myFunction"# 避免外界调用函数时运行了测试代码if __name__ == "__main__": print(myfunction()) # 导入模块
阅读全文
摘要:# 函数 def function1(): # 无参函数 print("×参数 ×返回") # 无返回def function2(arg1, arg2): # 带参函数(位置参数) return "√参数 √返回" # 有返回def function2_1(arg1, arg2): return a
阅读全文
摘要:# sorted(iterable,key=None,reverse=False)# key接受一个函数,这个函数只接受一个元素,默认为None# reverse是一个布尔值。默认为False排在前,True排在后,升序,即符合条件的往后排# 按照年龄来排序students = [('john',
阅读全文
摘要:f = lambda x, y, z: x + y + zprint(f(1, 2, 3)) # 6g = lambda x, y=2, z=3: x + y + zprint(g(1, z=4, y=5)) # 10# lambda表达式常用来编写跳转表(jump table),就是行为的列表或字
阅读全文
摘要:def testenumerate(): # enumerate(iterable, start=0) # enumerate将iterable组成一个索引序列,利用它可以同时获得索引和值 # 多用于在for循环中得到计数 l = ['a', 'b', 'c'] # <class 'list'>:
阅读全文
摘要:def testzip(): # zip是将每个可迭代对象的对应位置元素打包成一个tuple组 # 操作符*与zip函数配合可以实现与zip相反的功能, 即将合并的序列拆成多个tuple # 新的序列的长度以参数中最短的序列为准 x = [1, 2, 3] y = [4, 5, 6] z = [7,
阅读全文
摘要:import osdef fun(): a1 = all([True, False]) # 与的关系,返回bool a2 = any([True, False]) # 或的关系,返回bool num = abs(-1.23) # 绝对值 num = pow(5, 3) # 幂次方 x**y =>12
阅读全文
摘要:# 集合(无重复元素的无序容器)def sets(): # 集合存放不同可哈希的对象,常用于删除重复项, 做交集 / 并集 / 差集 等数学运算 # set可变, frozenset不可变,frozenset可存入set中(所以修改方法是set特有的) # set # 创建 s = set('chs
阅读全文
摘要:from collections import deque# 双向队列[有序序列] (封装list)def deques(): # 双向队列,线程安全,队列两端添加和弹出复杂度为O(1),效率很高 # 创建 lists = ["A", "B", "C", "D", "E"] # <class 'li
阅读全文
摘要:# 字符串[有序不可变Unicode序列]def strs(): # 创建字符串 strs = "Hello World!" # 字符串用 '/ " / ''' / """ 包裹 strs = """可多行的字符串""" strs = str(123) strs = str({1, 2, 3}) #
阅读全文
摘要:# Ranges[有序不变数字序列]def ranges(): # 创建 ranges = range(10) ls = list(ranges)# <class 'list'>: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ranges = range(1, 10) ls = l
阅读全文
摘要:# 元组[有序不变序列](不可修改)def tuples(): # 元组 # 创建 (类似于列表的数据存储方式,但是不能修改) tuples = ("柳岩", 21, "女") tuples = tuple(["a", "b", "c"]) # 将 列表 转为 元组 (注:将字典转为元组会损失数据)
阅读全文
摘要:def dics(): # 字典 # 创建(由 键值对(key:value) 组成) dics = {1: "a", 2: "b", 3: "c"} dics = dict() # 创建空字典 dics = dict([(1, "a"), (2, "b")]) # (序列)转为字典 (列表序列: d
阅读全文
摘要:# 列表[有序可变序列]def lists(): # 列表 # 列表可通过 append() / pop() 方法,作为栈使用 # 列表可通过 deque() 封装,作为双向队列使用 # 创建 lists = ["a", "b", "c"] # 列表 lists = list() # 空列表 lis
阅读全文
摘要:def helloworld(): # Hello World print("Hello World!") # 字符串用`'`或者`"`包裹 print("中文") # 代码中包含中文时(包含中文注释)需要在首行添加该注释(#coding=utf-8)def explanatorynote(): #
阅读全文

浙公网安备 33010602011771号