Python知识点备忘录

文件开头:

#!/usr/bin/env python
# -*- coding:utf-8 -*-
#上面一行适用于3以前的版本

当行注释:# 注释
多行注释:""" 注释 """  或  ‘‘‘注释‘‘‘

输入密码:

import getpass
pwd = getpass.getpass("请输入密码:")

模块查找路径:

import sysprint(sys.path)#[‘‘, ‘D:\\Program Files\\Python35\\python35.zip‘, ...
#空格代表与执行文件同一目录,非当前路径
#但在Python的命令行模式下,则代表当前路径

命令行参数:

import sys
print(sys.argv)

Python命令行模式下自动补全功能(linux):

#!/usr/bin/env python 
# python startup file 
import sys
import readline
import rlcompleter
import atexit
import os
# tab completion 
readline.parse_and_bind(‘tab: complete‘)
# history file 
histfile = os.path.join(os.environ[‘HOME‘], ‘.pythonhistory‘)
try:
    readline.read_history_file(histfile)
except IOError:
    pass
atexit.register(readline.write_history_file, histfile)
del os, histfile, readline, rlcompleter
时间: 2024-08-10 23:28:02

Python知识点备忘录的相关文章

python知识点 2014-07-09

迭代协议: 类实现方法__next__,则可以使用for.while来实现迭代 使用iter或者next实现手工迭代: L = [1,2,3] I = iter(L) print(I.next()) 列表推导式: L = [x + y for x in 'abc' for y in 'lmn'] print(L) ['al', 'am', 'an', 'bl', 'bm', 'bn', 'cl', 'cm', 'cn'] python知识点 2014-07-09,布布扣,bubuko.com

Python知识点:distutils常用子模块

from distutils.core import setup, Extension, Commandfrom distutils.command.build import buildfrom distutils.command.clean import cleanfrom distutils.command.sdist import sdistfrom distutils.dir_util import remove_treefrom distutils.util import get_pl

python知识点(07-08)

python: 循环else: while true: if x>1: print() break else: print() 文件循环: for line in open(‘test.txt’): print(line,end=’’) 获得enumerate: S=’spam‘ for( offset, item) in enumrate(S): print(item, ‘appear is’, offset) 备注: zip函数,使用for循环并行使用多个序列 python知识点(07-08

Python知识点: os.popen

用例:f = os.popen("%s %s %s" % ("pkg-config", " ".join(args), mod)) popen(...)    popen(command [, mode='r' [, bufsize]]) -> pipe        Open a pipe to/from a command returning a file object. Python知识点: os.popen

【Python&知识点】2个列表合成一个字典

·放一些网上的链接:https://baijiahao.baidu.com/s?id=1617397248551208688&wfr=spider&for=pc python,2列表组合成一个字典list_1 = [1,2,3,4,5,6] list_2 = ['a','b','c','d','e','f'] 方法一:dict(map(lambda x,y:[x,y],list_1,list_2)) 方法二:dict(zip(list_1,list_2)) 最简便!!! 输出:{1: 'a

计算机二级python 知识点篇(函数与代码复用)

计算机二级python 知识点篇(函数与代码复用) 全局变量 全局变量指在函数之外定义的变量, 在程序执行全过程有效. 全部变量在函数内部使用时, 需要提前使用保留字global声明, 语法形式如下: global <全局变量> >>>n = 2 #n是全局变量 >>>def multiply(x, y = 10): global n return x*y*n # 使用全局变量n >>>s = multiply(99, 2) >>

计算机二级python 知识点篇(文件和数据格式化)

计算机二级python 知识点篇(文件和数据格式化) 考纲考点 文件的使用: 文件打开. 关闭和读写 数据组织的维度: 一维数据和二维数据 一维数据的处理: 表示. 存储和处理 二维数据的处理: 表示. 存储和处理 采用CSV格式对一二维数据文件的读写 知识点1 文件包括两种类型: 文本文件和二进制文件. 二进制文件和文本文件最主要的区别在于是否有统一的字符编码 文本文件一般由单一特定编码的字符组成, 如UTF-8编码, 内容容易统一展示和阅读. 二进制文件直接由比特0和比特1组成, 文件内部数

计算机二级python 知识点篇(组合数据类型)

计算机二级python 知识点篇(组合数据类型) 集合.列表.字符串.元组.字典 集合类型 : 集合 (无序.无相同元素) 序列类型 :列表.字符串.元组 (有序.元素之间不排他) 映射类型 :字典 集合 集合概述 集合中元素不可重复, 元素类型只能是固定数据类型,例如: 整数. 浮点数. 字符串. 元组等, 列表. 字典和集合类型本身都是可变数据类型, 不能作为集合的元素出现 >>>S = {1010, "1010", 78.9} >>>type(

Python知识点总结1--函数

最近准备自己学学Python,给自己充充电,这些都是本人整理的一些Python的基本知识点,会持续更新的,希望能和大家一同交流 一.内建函数 cmp(obj1,obj2) repr(obj)            #返回一个对象的字符串表示   其实相当于 ' ' str(obj)     #同上 type(obj)     #返回对象的相应类型 x**y  与 pow(x,y)都表示x的y次方 二.类型工厂函数 int() long() float() complex() str() unic