【python基础--用python执行系统命令】教程文章相关的互联网学习教程文章

基于python3+opencv3图像基础IO操作【代码】【图】

环境Anaconda+python3.5.2+opencv31.先测试一下numpy的矩阵。import numpy as np import cv2img=np.zeros((3,3),dtype=np.uint8) print(img.shape) img=cv2.cvtColor(img,cv2.COLOR_GRAY2BGR) print(‘\n‘) print(img.shape) print(‘\n‘) print(img) 2.import cv2grayImage=cv2.imread(‘/home/cisco/Pictures/Webcam/ss.jpg‘,0) cv2.imwrite(‘ssgray.jpg‘,grayImage)AnyColor=cv2.imread(‘/home/cisco/Pictures/Webcam/...

python学习[第二篇] 基础二【代码】

控制结构if 语句# only if blockif condition:if_true_block# if_else blockif condition:if_true_block else:if_false_block# if_elif_else block if condition:if_true_block elif condition: elif_true_block elif condition: elif_true_block else:all_false_block # if 嵌套 blockif outer_condition:if inner_condition:inner_condition_true_blockelse:inner_condition_false_block else:outer_if_false_block while 结构#...

Python笔记_第五篇_Python数据分析基础教程_文件的读写【代码】

1. 读写文件(基本)  savetxt、loadtxti2 = np.eye(2) print(i2) np.savetxt(r"C:\Users\Thomas\Desktop\eye.txt",i2)c,v = np.loadtxt(r"C:\Users\Thomas\Desktop\data.csv",delimiter=‘,‘,usecols=(6,7),unpack=True) print(c,v) #[336.1 339.32 345.03 344.32 343.44 346.5 351.88 355.2 358.16 354.54 # 356.85 359.18 359.9 363.13 358.3 350.56 338.61 342.62 342.88 348.16 # 353.21 349.31 352.12 359.56 360. ...

python基础2

1,Pycharm 安装使用社区版专业版英文版2,格式化输出: %s %d%f 3,While 。。。Else当while 循环被break打断 ,则不走else程序4,运算符逻辑运算符 and与(与零的零) or或(或一得一) not非第一种情况逻辑运算符前后都是比较运算优先级:()> not >and > or ,同一级从左到右第二种情况逻辑运算符前后都是数字 x or y , x为真,值就是x,x为假,值是y; x and y, x为真,值是y,x为假,值是x。bool值转化Int----->bool ...

Python3 tkinter基础 Entry get 点击按钮 将输入框中文字输出到控制台【代码】【图】

???????Python : 3.7.0?????????OS : Ubuntu 18.04.1 LTS????????IDE : PyCharm 2018.2.4??????Conda : 4.5.11???typesetting : Markdowncode""" @Author : 行初心 @Date : 18-10-1 @Blog : www.cnblogs.com/xingchuxin @Gitee : gitee.com/zhichengjiu """ from tkinter import *def main():root = Tk()e = Entry(root)e.grid(row=0, column=1,padx=10, pady=10)def show():print(e.get())# 设置按钮的宽度Button(root, text...

python学习之【第八篇】:Python中的函数基础【代码】

1.前言函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段。函数能提高应用的模块性,和代码的重复利用率。2.函数的定义定义函数时需要遵守以下规则:函数代码块以 def 关键词开头,后接函数标识符名称和圆括号 ()。任何传入参数和自变量必须放在圆括号中间,圆括号之间可以用于定义参数。函数的第一行语句可以选择性地使用文档字符串—用于存放函数说明。函数内容以冒号起始,并且缩进。return [表达式] 结束函数...

python基础2【代码】

高级特性切片切片即取一个list 或者 tuple 的部分元素L= ["abc", "bcd", "efg", 123, 666]L[0 : 3] #取前3个元素,左闭右开 L[ : 3] #取前3个元素,左端索引为0可省略 L[-2 : ] #取倒数第2个一直到末尾 L[-3: -1] #取倒数第3和第2个,注意倒数第一个元素的索引是-1 L[ :10 :2] #取前10个数,每2个取1个 L[:] #原样复制一个list注:tuple也可切片,结果仍是tuple; str同理迭代迭代即便利某个list或者tuple,或者s...

《python基础教程》笔记之 基础知识【代码】

数字相关在Python程序前加上 from __future__ import division 或者在解释器里面直接执行它,或者通过命令行运行Python时使用命令开关-Qnew,会使单斜线不再整除,如>>> 1/20.5而双斜线实现整除,如>>> 1//20 输入>>> x = input(‘x:‘)模块用import导入模块,然后按照“模块.函数”的格式使用这个模块的函数,如>>> import math>>> math.floor(23.96)23.0 在使用了“form模块import函数”这种形式的import命令之后,就可以直接使用...

Python基础教程-List和Tuple【代码】

ListPython内置的一种数据类型是列表:list。list是一种有序的集合,可以随时添加和删除其中的元素。比如:>>> classmates = [‘Michael‘,‘Bob‘,‘Tracy‘]>>> classmates[‘Michael‘, ‘Bob‘, ‘Tracy‘]>>> len(classmates)3用索引来访问list中的每一个位置的元素,索引从0开始:>>> classmates[0] ‘Michael‘ >>> classmates[3]Traceback (most recent call last):File "<pyshell#4>", line 1, in <module>classmates[3] ...

Python基础篇(九)

Key Words: 文件迭代器,标准输入,GUI工具包,数据库操作SQLlite,  文件迭代器>>> f= open("some.txt","r+")>>> while True:... line = f.readline()... if not line : break... else :... print(line)... 使用文件迭代器直接可以访问文件的每一行,而不必去使用readline方法。>>> f= open("some.txt","r+")>>> for line in f:... print(line)...f.close() 标准输入sys. stdin:from sys import *for...

学习Python基础--------4【代码】

python装饰器定义:本质是函数,(装饰其他函数)就是为其他函数添加附加功能原则:1。不能修改被装饰的函数源代码   2.不能修改被装饰的函数的调用 def test1():pass def test2():pass这是两个函数想为两个函数添加打印功能,那就在写一个打印函数然后再调用def logger():print(‘logging‘)def test1():passlogger() def test2():passlogger()test1()test2() 装饰器通过@装饰器名来调用def timer(func):def warpper(*args,...

python基础知识(二)---字符串

ord(‘A‘):ascii编码转化为对应的序号chr(66):整数对应序号的ascii码string.ascii_lowercase:生成所有的小写英文字母字符串string.digits:生成所有的数字string.count(str,beg=0,end=len(string):返回str在string里面出现的次数,如果beg或者end指定下标范围string.expandtabs(tabsize=8):把字符串中的tab符号转化为空格string.find(str,beg=0,end=len(string):找到返回下标,否则返回-1string.join(seq):以指定字符串作为分隔符,将...

python基础:__init__.py和__init__函数的作用【代码】

一、__init__.py文件原来在python模块的每一个包中,都有一个__init__.py文件(这个文件定义了包的属性和方法)然后是一些模块文件和子目录,假如子目录中也有 __init__.py 那么它就是这个包的子包了。当你将一个包作为模块导入(比如从 xml 导入 dom )的时候,实际上导入了它的 __init__.py 文件。一个包是一个带有特殊文件 __init__.py 的目录。__init__.py 文件定义了包的属性和方法。其实它可以什么也不定义;可以只是一个空文...

Python3基础 json.loads 解析json格式的数据,得到一个字典【代码】

???? Python : 3.7.0?????? OS : Ubuntu 18.04.1 LTS?????? IDE : PyCharm 2018.2.4????? Conda : 4.5.11???typesetting : Markdowncode""" @Author : 行初心 @Date : 18-9-24 @Blog : www.cnblogs.com/xingchuxin @Gitee : gitee.com/zhichengjiu """import jsondef main():my_dict = {"spam": "foo", "parrot": 42}my_json = json.dumps(my_dict) # 编码数据print(type(my_json))print(my_json)print()tagert = json....

Python基础(六)——面向对象编程【代码】

(1)定义类和实例  这一部分难得和 Java 较为一致,直接写个例子:1class Stu: 2def__init__(self, name, id): # 构造方法3 self.name = name 4 self.id = id 5def test(self, name2): 6print(‘He is {}‘.format(name2)) 7 student = Stu(‘Bob‘, ‘123‘) 8print(student.name, student.id) # Bob 1239 student.test(‘LQ‘)  注意一点:类中自定义的方法一定要含有 self 参数,但是在调用的时候,无需为...