`
scm002
  • 浏览: 309809 次
社区版块
存档分类
最新评论
文章列表
条件,循环和其他语句 Table of Contents 1 print和import的更多信息 1.1 使用逗号输出 1.2 把一些东东作为另一些东东导入 2 赋值魔法 2.1 序列解包 2.2 链式赋值 2.3 增量赋值 3 语句块:缩排的乐趣 4 条件和条件语句 4.1 这就是布尔变量的作用 4.2 条件执行和if语句 4.3 else子句 4.4 elif子句 4.5 嵌套代码块 4.6 更复杂的条件 4.6.1 比较运算符 4.6.2 相等运算符 4.6.3 同一性运算符 ...
字典:当索引不好用时 Table of Contents 1 字典定义: 2 字典的使用: 3 创建和使用字典 3.1 dict函数 3.2 基本字典操作 3.3 用字典格式化字符串 3.4 字典方法 3.4.1 clear 3.4.2 copy 3.4.3 fromekeys 3.4.4 get 3.4.5 has_key 3.4.6 items和iteritems 3.4.7 keys 3.4.8 pop 3.4.9 popitem 3.4.10 setdefault 3.4.11 update ...
使用字符串 Table of Contents 1 基本字符串操作 2 字符串格式化:精简版 2.1 用字符串格式化操作符 2.2 用string的Template格式化字符串 3 字符串格式化:完整版 3.1 转换说明符 3.2 简单转换 3.3 字段宽度和精度 3.4 符号,对齐和 0 填充 4 字符串方法 4.1 find 4.2 join 4.3 lower 4.4 replace 4.5 split 4.6 strip 4.7 translate 1 基本 ...
列表和元组 Table of Contents 1 序列概览 2 通用序列操作 2.1 索引 2.2 分片 2.3 序列相加 2.4 乘法 2.5 成员资格 2.6 长度,最大值,最小值 3 列表:Python的“苦力” 3.1 list 3.2 基本列表操作 3.3 列表方法 4 元组 4.1 元组定义: 4.2 tuple函数 4.3 元组的意义: 1 序列概览 说明:序列包括(列表,元组,字符串,buffer对象,xrange对象) 注意:列表可以修改,元组不能被修改。 例子: & ...
程序中出现中文,运行的时候出现如下错误:   SyntaxError: Non-UTF-8 code starting with '\xb1' in file rate.py on line 5, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details   导致出错的根源就是编码问题。 解决方案是:      在程序最上面加上:# coding=gbk 这样程序就可以正常运行了。   eg1:   #!/usr/bin/python#-*- coding:GBK -*- ...
Python模块学习——tempfile 主要有以下几个函数: tempfile.TemporaryFile 如何你的应用程序需要一个临时文件来存储数据,但不需要同其他程序共享,那么用TemporaryFile函数创建临时文件是最好的选择。其他的应用程序是无法找到或打开这个文件的,因为它并没有引用文件系统表。用这个函数创建的临时文件,关闭后会自动删除。   import os import tempfile print 'Building a file name yourself:' filename = '/tmp/guess_my_name.%s.txt' ...
文件名:change.log我想匹配到error并返回行.类似于grep error change.log用python如何实现?change.log 文件内容Please wait while, the wizard is runing now!if you arrived at this page by clicking a link, check the website address in the address bar to be sure that it is the address you were expecting.when going to a website with an ...
python print 句末会自动换行,而其它的编程语言中,如C是print 转义字符 \n 实现换行;然而有些时候并不想让它自动换行,如   for i in range(1,5)   打印 i 时,输出的结果为   1   2   3   4 但是有时候却需要 1 2 3 4 的方式; py因为python3修改了print的使用方式,python2与3的实现方式不同 python2的使用方式是在句末添加 , 符号;即 for i in range(1,5):     print i, python3的实现是在print中控制 end参数的值,即 for i ...
    Python常见文件操作示例       os.path 模块中的路径名访问函数     分隔     basename() 去掉目录路径, 返回文件名     dirname() 去掉文件名, 返回目录路径     join() 将分离的各部分组合成一个路径名     split() 返回(d ...
Python 3 教程二:文件,目录和路径   1 遍历文件夹和文件 <!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->import  osimport  os.path#  os,os.path里包含大多数文件访问的函数,所以要先引入它们. #  请按照你的实际情况修改这个路径 rootdir  =   " ...
Python 3 教程一:入门 Python已经是3.1版本了,与时俱进更新教程.(由于Django不支持python3, 所以为了你的发展潜力, 建议你学习python2.x)python 2.x教程地址: http://www.cnitblog.com/yunshichen/archive/2008/05/09/43527.html 本文适合有Java编程经验的程序员快速熟悉Python 本文程序在windows xp+python3.1a1 测试通过. 本文提到的idle指python shell,即安装python后你在菜单看到的IDLE(python gui) 在 ...
Python:文件操作技巧(File operation)   读写文件 #! /usr/bin/python #  -*- coding: utf8 -*-  spath = " D:/download/baa.txt " f = open(spath, " w " )  #  Opens file for writing.Creates this file doesn't exist. f.write( " First line 1.\n " )f.writelines( " First line 2. ...
sys.argv[]是用来获取命令行参数的,sys.argv[0]表示代码本身文件路径,所以参数从1开始,以下两个例子说明: 1.使用sys.argv[]的一简单实例: import sys, os os.system(sys.argv[]) 这个例子os.system接受命令行参数,运行参数指令,保存为sample1.py,命令行带参数运行sample1.py notepad,将打开记事本程序。 2.这个例子是简明python教程上的,明白它之后你就明白sys.argv[]了: import sys def readfile(filename): ' ...
转自: http://blog.csdn.net/whycadi/article/details/2011046   1.   Python 正则式的基本用法 1.1 基本规则 1.2 重复 1.2.1 最小匹配与精确匹配 1.3 前向界定与后向界定 1.4 组的基本知识 2.   re
The Python Standard Library Release: 3.1 Date: April 09, 2012 While The Python Language Reference describes the exact syntax and semantics of the Python language, this library reference manual describes the standard library that is distributed with Python. It also describes so ...
Global site tag (gtag.js) - Google Analytics