
Python
hanruikai
aaa
展开
-
Hello Python
My first Python demo >>> movies=["a","b","c"] >>> print(movies[0]) a >>> print(movies[1]) b >>> >>> print(movies) ['a', 'b', 'c'] >>> print(len(movies)) 3 >>> Python 的变量标示符没有类型原创 2013-02-05 17:29:48 · 530 阅读 · 0 评论 -
创建一个可执行的python脚本
其实和shell方式一样 vi helloworld.py 写逻辑代码,文件头: #!/bin/python chmod +x python helloworld.py原创 2015-01-12 15:33:12 · 3140 阅读 · 0 评论 -
高级特性-面向对象部分
1. 类的定义使用 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #!/bin/python class Employee: def __init__(self,name):原创 2015-01-12 15:27:34 · 638 阅读 · 0 评论 -
高级特性-操作数据库
1,import MySQLdb module 2. 打开连接 db =MySQLdb.connect("localhost","testuser","test123","TESTDB" ) 3. 打开游标 cursor = db.cursor() 4. 执行sql cursor.execute("SELECT VERSION()") 5.原创 2015-01-12 15:24:07 · 644 阅读 · 0 评论 -
高级特性-多线程,GUI
创建线程两种方式 第一种,导入improt thread 模块,thread.start_new_thread(功能函数名称,(参数1,参数2...)) 后面参数为功能函数的参数 第二个方式类似于java,导入threading模块,继承threading.Thread类,重写__init__和run方法。start启动线程 GUI功能需要安装Tkinter 线程同原创 2015-01-12 15:22:51 · 649 阅读 · 0 评论 -
函数定义与使用
函数定义 你可以定义一个由自己想要功能的函数,以下是简单的规则: 函数代码块以def关键词开头,后接函数标识符名称和圆括号()。 任何传入参数和自变量必须放在圆括号中间。圆括号之间可以用于定义参数。 函数的第一行语句可以选择性地使用文档字符串—用于存放函数说明。 函数内容以冒号起始,并且缩进。 Return[expression]结束原创 2015-01-12 15:29:17 · 827 阅读 · 0 评论 -
Python数据类型和语法
基本数据类型 Python有五个标准的数据类型: Numbers(数字) String(字符串) List(列表) Tuple(元组) Dictionary(字典) shell好像无明显的数据类型区分 Python支持四种不同的数值类型: int(有符号整型) long(长整型[也可以代表八进制原创 2015-01-12 15:32:20 · 753 阅读 · 0 评论 -
日期时间
获取时间 ? 1 2 3 4 5 6 7 8 9 >>> import time >>> ticks=time.time() >>> print(ticks) 1415277557.990928 >>> localtime=time.localtime(ticks)原创 2015-01-12 15:30:28 · 474 阅读 · 0 评论 -
高级特性-正则表达式
re.search(pattern,string,flag) 与re.match()不同,匹配整个字符串,match如果开始不匹配则返回none 2. re.sub替换 re.sub(pattern,replace,string) ? 1 2 3 4 5 6 7 8 9 1原创 2015-01-12 15:25:02 · 655 阅读 · 0 评论 -
Python条件语句和运算符
if else形式 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 [nxu原创 2015-01-12 15:30:35 · 778 阅读 · 0 评论 -
持久存储
1、输出到文件 try: out=open("a.txt","w") w或者a+或者w+,分别为清除重写,追加,不清除进行读和写 print("aaaaaa",file=out) out.close() except IOError: print("io error") 2、出现异常时,减少数据破坏性,如下改进: try: out=open("a.txt",原创 2013-02-18 12:39:51 · 682 阅读 · 0 评论 -
理解数据
1、排序 sort: 原地排序sorted(data):复制排序 2、推导列表,支持函数编程概念 函数式编程详见: http://www.cnblogs.com/kym/archive/2011/03/07/1976519.html 如何从一个列表转换为另外一个列表: 常规做法: clean_mikey=[] fo原创 2013-02-20 13:24:29 · 410 阅读 · 0 评论 -
定制数据对象
1、创建字典 Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> cheese={} >>> type(chee原创 2013-02-22 12:21:37 · 452 阅读 · 0 评论 -
文件读取与异常
1、文件读取 import osdata=open(finename)print(data.readline());data.close() 2、异常管理 try: 你的代码逻辑 except: 异常处理逻辑 try: 你的代码逻辑 except IOError: 异常处理逻辑原创 2013-02-17 16:52:50 · 770 阅读 · 0 评论 -
在列表中嵌套列表
1、创建嵌套列表 >>> movies=["a","b","c",["aa","bb","cc",["aaa","bbb","ccc"]]] >>> print(movies) ['a', 'b', 'c', ['aa', 'bb', 'cc', ['aaa', 'bbb', 'ccc']]] >>> print(movies[3][3][2]) ccc >>> for item in原创 2013-02-17 10:58:06 · 2497 阅读 · 0 评论 -
Python 一个简单的读取excel例子
1 准备环境1.1 安装pythonmac上的python默认版本是python2,如下:hanruikaideMacBook-Pro:local hanruikai$ python Python 2.7.10 (default, Feb 7 2017, 00:08:15) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on ...原创 2018-04-12 16:47:28 · 40568 阅读 · 0 评论