coding

Python学习一基础数据类型及赋值操作

核能气质少年 提交于 2019-12-07 21:05:53
一、变量赋值 单个变理赋值 参数名称 = 变量值如下 #!/usr/bin/python # -*- coding: UTF-8 -*- counter = 100 # 赋值整型变量 miles = 1000.0 # 浮点型 name = "John" # 字符串 print counter print miles print name 二、多外变量赋值 1.给多个变量赋同一个值 参数名 = 参数名 = 参数名。。。=参数值如下 #!/usr/bin/python # -*- coding: UTF-8 -*- a = b = c = 1 print a print b print c 2.给多个变量赋不同的值 参数名,参数名,参数名 = 参数值,参数值,参数值 #!/usr/bin/python # -*- coding: UTF-8 -*- a , b, c = 1,2,3 print a print b print c 三、标准数据类型 1、数字类型 Python支持四种不同的数字类型: int(有符号整型) long(长整型[也可以代表八进制和十六进制]) float(浮点型) complex(复数) 2、字符串 字符串或串(String)是由数字、字母、下划线组成的一串字串,一些简单的操作如下 #!/usr/bin/python # -*- coding: UTF-8 -

pyhon基础变量之print和input函数

大城市里の小女人 提交于 2019-12-07 16:25:49
1、python的基础可以分为:数据 函数 控制流 数据包括数据类型、变量、编码、类与对象; 函数包括:print() input len() type() str() int() str() float() exit()等; 而常见的数据类型有:字符串 整数 浮点数 布尔值 空值 列表 词典; 首先了解整数和字符串; 整数:即数学里面的数字;比如 1 2 45 等; 字符串:表示汉字; 注释 :在引用 字符串 时需要用 单引号 括起来;如: print('hello word') 如下图:第三行表示字符串; 第四行表示整数; [root@localhost_002 py]# cat 22.py #!/usr/bin/env python # -*- coding:utf-8 -*- print('hello word') #表示字符串 print(32) #表示数字 [root@localhost_002 py]# python 22.py hello word 32 2、变量:变量时没有固定的数,可以改变的一个数值,而在计算机中,会有很多很多的数据,那么怎么去寻找这些数据呢,首先会给这些数据分类,然后放在不同的盒子中,这个盒子就是python中的变量(变量就是一个带标签和盒子,你可以把数据放在盒子里去); 如: a=1 #则表示给变量赋予值为1; [root@localhost

redis 的发布订阅

南楼画角 提交于 2019-12-06 21:58:26
Redis 订阅者 #-*- coding: utf8 -*- import redis r = redis.Redis() # 获取订阅对象 pub = r.pubsub() pub.subscribe("104.5fm") # pub.parse_response() while True: msg = pub.parse_response() print(msg)   Redis 发布者 #!/usr/bin/env python #-*- coding: utf8 -*- import redis r=redis.Redis() r.publish("104.5fm","666")    来源: https://www.cnblogs.com/eliwen/p/11998921.html

python类之特殊属性和魔术方法

一曲冷凌霜 提交于 2019-12-06 21:19:07
一 python特殊属性 1 总述 属性 含义 _ name_ 类,函数,方法等的名字 _ module_ 类定义所现在的模块名 _ class_ 对象或类所属的类 _ bases_ 类的基类的元素,顺序为他们在基类列表中出现的顺序 _ doc_ 类/函数的文档字符传,如果没有定义则为None _ mro_ 类的mro,class.mro()返回 _ dict_ 类或实例的属性,可写的字典 _ dir_ 返回了类或者对象所有成员列表,dir()函数调用的是_ dir_ (),如果提供了_ dir_ (),则返回属性列表,否则尽可能从__dict__属性中收集信息 2 name 获取类和函数的名字 #!/usr/local/bin/python3.6 #coding:utf-8 class A: pass class B(A): pass def C(): pass print (A.__name__,B.__name__,C.__name__,sep='\n') 3 module 类定义所在的模块名 #!/usr/local/bin/python3.6 #coding:utf-8 class A: pass class B: pass print (A.__module__,B.__module__) #!/usr/local/bin/python3.6 #coding:utf-8

一些app的源代码

别来无恙 提交于 2019-12-06 21:16:30
1:Coding.net客户端 地址:https://coding.net/u/coding/p/Coding-iOS/git 2:高仿美团iOS版 地址:https://github.com/lookingstars/meituan 3:模仿网易新闻做的精仿网易新闻 地址:https://github.com/dsxNiubility/SXNews 4:支付宝高仿版 地址:https://github.com/gsdios/GSD_ZHIFUBAO 5:高仿百度传课iOS版 地址:https://github.com/lookingstars/chuanke 6:模仿一元云购 地址:https://github.com/JxbSir/YiYuanYunGou 7:wordpress源代码 地址:https://github.com/wordpress-mobile/WordPress-iOS 8:v2ex源代码(文章类型,若报SVProgressHUD错,则把Podfile中的SVProgressHUD移除) 地址:https://github.com/singro/v2ex 9:PHPHub客户端(IOS8.0以上) 地址:https://github.com/Aufree/phphub-ios 10:快速搭建项目源代码 地址:https://github.com

python爬虫之Scrapy框架

我只是一个虾纸丫 提交于 2019-12-06 16:13:11
Scrapy是用python实现的一个为了爬取网站数据,提取结构性数据而编写的应用框架。使用Twisted高效异步网络框架来处理网络通信。 Scrapy架构: ScrapyEngine:引擎。负责控制数据流在系统中所有组件中流动,并在相应动作发生时触发事件。 此组件相当于爬虫的“大脑”,是 整个爬虫的调度中心。 Schedule:调度器。接收从引擎发过来的requests,并将他们入队。初始爬取url和后续在页面里爬到的待爬取url放入调度器中,等待被爬取。调度器会自动去掉重复的url。 Downloader:下载器。负责获取页面数据,并提供给引擎,而后提供给spider。 Spider:爬虫。用户编些用于分析response并提取item和额外跟进的url。将额外跟进的url提交给ScrapyEngine,加入到Schedule中。将每个spider负责处理一个特定(或 一些)网站。 ItemPipeline:负责处理被spider提取出来的item。当页面被爬虫解析所需的数据存入Item后,将被发送到Pipeline,并经过设置好次序 DownloaderMiddlewares:下载中间件。是在引擎和下载器之间的特定钩子(specific hook),处理它们之间的请求(request)和响应(response)。提供了一个简单的机制,通过插入自定义代码来扩展Scrapy功能

[Daily Coding Problem] Find the total number of solutions of a linear equation of n variables

痴心易碎 提交于 2019-12-06 13:12:09
Given a linear equation of n variables, find the total number of non-negative integer solutions of it. All coefficients are positive. Example: input: x + 2 * y = 5 output: 3, the 3 possible integer solutions are x = 1, y = 2; x = 3, y = 1; x = 5, y = 0. This problem can be simply thought as a coin change problem. You are given coins of different denominations and a total amount of money. Write a function to compute the number of combinations that make up that amount. You may assume that you have infinite number of each kind of coin. rhs is the sum. coeffients are the coin denominations. each

How to do Offline Coding & Programming with DAS for MB SD Connect C4/C5 Star Diagnostic Tool?

匆匆过客 提交于 2019-12-06 12:32:02
Offline coding: SCN or CVN coding was added to the cars back in 2003 if not earlier . The idea of OFFLINE coding was to be able to make SCN codings when you don’t have an internet connection at your workshop to be able to perform this online. In both cases an SCN or CVN coding was required. Let’s not confuse OFFLINE coding with simple CODINGS ! Codings can be done with regular DAS or Developer DAS more deeply. Coding does not imply that you have to replace your unit software completely. If you have to make an Offline coding this implies to flash your unit with an updated software version or at

Ruby 中文编码

馋奶兔 提交于 2019-12-06 11:43:05
Ruby 中文编码 前面章节中我们已经学会了如何用 Ruby 输出 "Hello, World!",英文没有问题,但是如果你输出中文字符"你好,世界"就有可能会碰到中文编码问题。 Ruby 文件中如果未指定编码,在执行过程会出现报错: #!/usr/bin/ruby -w puts "你好,世界!"; 以上程序执行输出结果为: invalid multibyte char (US-ASCII) 以上出错信息显示了 Ruby 使用用 ASCII 编码来读源码,中文会出现乱码,解决方法为只要在文件开头加入 # - - coding: UTF-8 - -(EMAC写法) 或者 #coding=utf-8 就行了。 实例 #!/usr/bin/ruby -w # -*- coding: UTF-8 -*- puts "你好,世界!"; 输出结果为: 你好,世界! 所以如果大家再学习过程中,源代码文件中,若包含中文编码,则需要注意两点: 必须在首行添加 # - - coding: UTF-8 - -,告诉解释器使用utf-8来解析源码。 必须设置编辑器保存文件的编码为utf-8。 本文转自; http://codingdict.com/article/6829 来源: https://www.cnblogs.com/bczd/p/11980953.html

Python——装饰器(Decorator)

≯℡__Kan透↙ 提交于 2019-12-06 10:19:31
1.什么是装饰器? 装饰器放在一个函数开始定义的地方,它就像一顶帽子一样戴在这个函数的头上。和这个函数绑定在一起。在我们调用这个函数的时候,第一件事并不是执行这个函数,而是将这个函数做为参数传入它头顶上这顶帽子,这顶帽子我们称之为装饰器 。 2.装饰器的使用方法 @ 符号是装饰器的语法糖,一般情况下我们使用@函数名或者@类名来使用装饰器。 3.函数装饰器 函数装饰器 = 高阶函数 + 嵌套函数 + 闭包 • 高阶函数:外层函数可以接收内层函数作为参数 • 函数嵌套 :将某函数作为另一函数的参数使用 • 闭包 :能够使用外部函数的自由变量的函数 (1)不带参数的函数装饰器(日志打印器) 实现的功能是:在函数执行前,先打印一行日志“before”,在函数执行完,再打印一行日志“after”。 代码如下: 1 #coding=utf-8 2 # -*- coding=utf-8 -*- 3 #不带参数装饰器 4 def dec1_outer(func): 5 6 def dec1_inner(): 7 print("Before") 8 #函数真正执行的地方 9 func() 10 print("After") 11 12 return dec1_inner 13 14 @dec1_outer 15 def func(): 16 print('func') 17 18 func()