
Python
文章平均质量分 54
那闯
这个作者很懒,什么都没留下…
展开
-
Python 基础笔记(1)
编码: # coding=GBK or # -*- coding: GBK -*- 源码使用GBK编码 # coding=UTF-8 or # -*- coding: UTF-8 -*- 源码使用UTF-8编码 string.encode('GBK/UTF-8') 将string转换成bytes bytes.decode('GBK/UTF-8') 将bytes转换成string原创 2013-04-15 14:19:52 · 1202 阅读 · 0 评论 -
Python 基础(3)
输入: >>get_input = raw_input("string:") string: abc >>print get_input abc原创 2014-02-26 18:47:34 · 797 阅读 · 0 评论 -
Python File I/O
File I/O: file = open(filename, 'mode') mode包括 'r' , 'r+' , 'w' , 'w+' , 'a' , 'a+'等 file.close() file.readline() 读一行 file.readlines() 按行读入所有的内容 file.writeline() file.writelines()原创 2013-11-25 05:55:27 · 1259 阅读 · 0 评论 -
Python 基础笔记(2)
list与string相互转换: mylist = list(str) str = ''.join(mylist) 字典: dict = {},dict = {'key1': value1, 'key2': value2, ... } 遍历: for key in dict: print 'key = %s, value = %s' % (key, dict[key]) Pyt原创 2013-06-17 16:19:52 · 858 阅读 · 0 评论 -
Python 3.x与2.x 差异笔记
1. print "str" 这种没有括号的语法,在3.x下不支持,3.x只支持print ("str")。另外,print希望不换行在最后加一个“,”,在3.x中不适用了,3.x中可以这样去除换行print("str",end='') 2. import urllib2发现有错 ImportError: No module named urllib2 官网:The urllib2 modu原创 2013-04-15 12:45:29 · 5195 阅读 · 0 评论 -
Python 使用Cookie访问
例子: 访问http://www.towords.com/网站,抽出一共掌握的单词。 # coding=GBK import urllib, urllib2, cookielib import re, sys def LogInByCookie(): cookie = {"toWords_sId": "84bffb5f172f1a9539bda7e7606d6d7f"}原创 2013-05-24 09:59:18 · 2265 阅读 · 0 评论 -
Python对Excel的操作 pyExcelerator
pyExcelerator的安装: pyExcelerator下载地址:https://pypi.python.org/pypi/pyExcelerator/ 解压安装包执行python setup.py install (注意:目前版本不支持python3) 一个简单的例子: from pyExcelerator import * def main(): book = Workbo原创 2013-04-26 10:03:07 · 4179 阅读 · 1 评论 -
Python, Shell 遍历文件
Shell #!/bin/sh TraverseDirectory() { echo "---------------------------- Next ----------------------------------" echo -n "Root: " echo -n "$2$1" echo cd $1 dirs=`ls -al | grep '^d' |原创 2013-04-24 11:19:44 · 1168 阅读 · 0 评论 -
Python JSON decode和encode
Python: Decode和Encode JSON import json, dumps encode数据,loads decode数据。 def DecodingJson(json_file): dic = {} jfile = open(json_file) while True: line = jfile.readline()原创 2014-03-12 16:50:21 · 5557 阅读 · 0 评论