当前位置: 首页 > news >正文

Python学习笔记

通过mod_wsgi模块,Apache可以运行用Python编写的Web程序

使用Python语言编写的 Gunicorn作为Web服务器,也能够运行Python语言编写的Web程序

Web框架,如Django、Pyramid、TurboGears、web2py、Zope、Flask、tornoda

gevent这个流行的第三方库,同样能够支持高性能高并发的网络开发。

爬虫相关的库有lxml、re、urllib2、BeautifulSoup、scrapy等

Python本身包含的Tkinter库能够支持简单的GUI开发,但是越来越多的Python程序员选择wxPython或者PyQt来开发跨平台的桌面软件。使用它们开发的桌面软件运行速度快,与用户的桌面环境相契合。通过PyInstaller还能将程序发布为独立的安装程序包。

Python的性能测试库multi-mechanize和locustio、funkload等模块具备强大的编程能力,通常扩展性和执行效率远强于Loadrunner和Jmeter。

 

python requests实现windows身份验证登录

来源:https://www.cnblogs.com/xbzhu/p/7743584.html 

1.安装ntlm  https://github.com/requests/requests-ntlm

pip install requests_ntlm

2.使用

import requests
from requests_ntlm import HttpNtlmAuth

requests.get("http://ntlm_protected_site.com",auth=HttpNtlmAuth('domain\\username','password'))

 implement a difference function, which subtracts one list from another and returns the result.

It should remove all values from list a, which are present in list b.

def array_diff(a, b): return [x for x in a if x not in b]

 

Take 2 strings s1 and s2 including only letters from ato z. Return a new sorted string, the longest possible, containing distinct letters,

  • each taken only once - coming from s1 or s2. #Examples: ``` a = "xyaabbbccccdefww" b = "xxxxyyyyabklmopq" longest(a, b) -> "abcdefklmopqwxy"

a = "abcdefghijklmnopqrstuvwxyz" longest(a, a) -> "abcdefghijklmnopqrstuvwxyz" ```

Test.describe("longest")
Test.it("Basic tests")
Test.assert_equals(longest("aretheyhere", "yestheyarehere"), "aehrsty")
Test.assert_equals(longest("loopingisfunbutdangerous", "lessdangerousthancoding"), "abcdefghilnoprstu")
Test.assert_equals(longest("inmanylanguages", "theresapairoffunctions"), "acefghilmnoprstuy")

def longest(s1, s2):
#print(sorted(s1+s2))
return(''.join(sorted([ x for x in set(s1)|set(s2)])))

 

def longest(a1, a2): return "".join(sorted(set(a1 + a2)))

 

Given two arrays a and b write a function comp(a, b) (compSame(a, b) in Clojure) that checks whether the two arrays have the "same" elements, with the same multiplicities. "Same" means, here, that the elements in b are the elements in a squared, regardless of the order.

Examples

Valid arrays

a = [121, 144, 19, 161, 19, 144, 19, 11]  
b = [121, 14641, 20736, 361, 25921, 361, 20736, 361]

comp(a, b) returns true because in b 121 is the square of 11, 14641 is the square of 121, 20736 the square of 144, 361 the square of 19, 25921 the square of 161, and so on. It gets obvious if we write b's elements in terms of squares:

a = [121, 144, 19, 161, 19, 144, 19, 11] 
b = [11*11, 121*121, 144*144, 19*19, 161*161, 19*19, 144*144, 19*19]

Invalid arrays

If we change the first number to something else, comp may not return true anymore:

a = [121, 144, 19, 161, 19, 144, 19, 11]  
b = [132, 14641, 20736, 361, 25921, 361, 20736, 361]

comp(a,b) returns false because in b 132 is not the square of any number of a.

a = [121, 144, 19, 161, 19, 144, 19, 11]  
b = [121, 14641, 20736, 36100, 25921, 361, 20736, 361]

comp(a,b) returns false because in b 36100 is not the square of any number of a.

Remarks

a or b might be [] (all languages except R, Shell). a or b might be nil or null or None or nothing (except in Haskell, Elixir, C++, Rust, R, Shell).

If a or b are nil (or null or None), the problem doesn't make sense so return false.

If a or b are empty the result is evident by itself.

 

Best Pracice:

def comp(array1, array2): try: return sorted([i ** 2 for i in array1]) == sorted(array2) except: return False

 

this time we want to write calculations using functions and get the results. Let's have a look at some examples:

JavaScript:

seven(times(five())); // must return 35
four(plus(nine())); // must return 13
eight(minus(three())); // must return 5
six(dividedBy(two())); // must return 3

Ruby:

seven(times(five)) # must return 35
four(plus(nine)) # must return 13
eight(minus(three)) # must return 5
six(divided_by(two)) # must return 3

Requirements:

  • There must be a function for each number from 0 ("zero") to 9 ("nine")
  • There must be a function for each of the following mathematical operations: plus, minus, times, dividedBy (divided_by in Ruby)
  • Each calculation consist of exactly one operation and two numbers
  • The most outer function represents the left operand, the most inner function represents the right operand
  • Divison should be integer division, e.g eight(dividedBy(three()))/eight(divided_by(three)) should return 2, not 2.666666...

Best Practice

def zero(f = None): return 0 if not f else f(0)

def one(f = None): return 1 if not f else f(1)

def two(f = None): return 2 if not f else f(2)

def three(f = None): return 3 if not f else f(3)

def four(f = None): return 4 if not f else f(4)

def five(f = None): return 5 if not f else f(5)

def six(f = None): return 6 if not f else f(6)

def seven(f = None): return 7 if not f else f(7)

def eight(f = None): return 8 if not f else f(8)

def nine(f = None): return 9 if not f else f(9)

 

def plus(y): return lambda x: x+y

def minus(y): return lambda x: x-y

def times(y): return lambda x: x*y

def divided_by(y): return lambda x: x/y

 

 

Build Tower

Build Tower by the following given argument:
number of floors (integer and always greater than 0).

Tower block is represented as *

  • Python: return a list;
  • JavaScript: returns an Array;
  • C#: returns a string[];
  • PHP: returns an array;
  • C++: returns a vector<string>;
  • Haskell: returns a [String];
  • Ruby: returns an Array;

Have fun!


for example, a tower of 3 floors looks like below

[
  '  *  ', 
  ' *** ', 
  '*****'
]

and a tower of 6 floors looks like below

[
  '     *     ', 
  '    ***    ', 
  '   *****   ', 
  '  *******  ', 
  ' ********* ', 
  '***********'
]

Best Practice:
def tower_builder(n): return [("*" * (i*2-1)).center(n*2-1) for i in range(1, n+1)]




Given: an array containing hashes of names

Return: a string formatted as a list of names separated by commas except for the last two names, which should be separated by an ampersand.

Example:

namelist([ {'name': 'Bart'}, {'name': 'Lisa'}, {'name': 'Maggie'} ]) # returns 'Bart, Lisa & Maggie' namelist([ {'name': 'Bart'}, {'name': 'Lisa'} ]) # returns 'Bart & Lisa' namelist([ {'name': 'Bart'} ]) # returns 'Bart' namelist([]) # returns '' 

Note: all the hashes are pre-validated and will only contain A-Z, a-z, '-' and '.'.

 

Best Practice:

def namelist(names): if len(names) > 1: return '{} & {}'.format(', '.join(name['name'] for name in names[:-1]), names[-1]['name']) elif names: return names[0]['name'] else: return ''

 

 


转载于:https://www.cnblogs.com/jdjh/p/10094879.html

相关文章:

  • 基于DevExpress的Winform程序安装包的制作
  • RocketMQ 基本概念
  • 学习设计接口api(转)
  • 【刘文彬】EOS技术研究:合约与数据库交互
  • Altium Designer 8.0不为人知的27个技巧
  • React-redux的原理以及使用
  • Spring MVC JSP页面加载不完全的问题
  • 工程师笔记|浅析AI平台的架构设计
  • Spark 1.0.0 横空出世 Spark on Yarn 部署(Hadoop 2.4)
  • 使用docker遇到的问题
  • 武汉区块链软件技术公司:区块链将如何优化产业链?
  • echarts简单使用
  • .NET项目中存在多个web.config文件时的加载顺序
  • Linux工具性能调优系列三:swap问题定位
  • Ubuntu 12.04 root账户开启及密码重设
  • 08.Android之View事件问题
  • Angular Elements 及其运作原理
  • ESLint简单操作
  • HTTP请求重发
  • in typeof instanceof ===这些运算符有什么作用
  • Odoo domain写法及运用
  • PHP的类修饰符与访问修饰符
  • 力扣(LeetCode)56
  • 什么是Javascript函数节流?
  • 我有几个粽子,和一个故事
  • 在Docker Swarm上部署Apache Storm:第1部分
  • 国内唯一,阿里云入选全球区块链云服务报告,领先AWS、Google ...
  • (js)循环条件满足时终止循环
  • (差分)胡桃爱原石
  • (十七)Flask之大型项目目录结构示例【二扣蓝图】
  • (四) Graphivz 颜色选择
  • (转)EOS中账户、钱包和密钥的关系
  • (转)h264中avc和flv数据的解析
  • (转)ORM
  • ... fatal error LINK1120:1个无法解析的外部命令 的解决办法
  • ..thread“main“ com.fasterxml.jackson.databind.JsonMappingException: Jackson version is too old 2.3.1
  • .bat批处理(一):@echo off
  • .NET Framework 4.6.2改进了WPF和安全性
  • .NET教程 - 字符串 编码 正则表达式(String Encoding Regular Express)
  • .NET学习教程二——.net基础定义+VS常用设置
  • @Async注解的坑,小心
  • [2009][note]构成理想导体超材料的有源THz欺骗表面等离子激元开关——
  • [2021ICPC济南 L] Strange Series (Bell 数 多项式exp)
  • [Angular] 笔记 20:NgContent
  • [AX]AX2012 AIF(四):文档服务应用实例
  • [C++] new和delete
  • [C++]高精度 bign (重载运算符版本)
  • [cogs2652]秘术「天文密葬法」
  • [fsevents@^2.1.2] optional install error: Package require os(darwin) not compatible with your platfo
  • [IE9] 解决了傲游、搜狗浏览器在IE9下网页截图的问题
  • [iOS]-NSTimer与循环引用的理解
  • [Oh My C++ Diary]函数重载
  • [one_demo_4]不使用第3个变量交换两个变量的值
  • [one_demo_5]命令行输入输出
  • [Python]list.append字典的时候,修改字典会导致list内容变化的问题