1月 152021
1月 052021
File -> Settings -> Project -> Python Interpreter -> Install -> Available Packages -> Manage Repositories https://mirrors.163.com/pypi/simple/ https://mirrors.ustc.edu.cn/pypi/web/simple https://pypi.tuna.tsinghua.edu.cn/simple https://mirrors.aliyun.com/pypi/simple/
12月 252020
Jenkins版本
Jenkins 2.263.1
Jenkins操作
SSH Server --> Test Configuration
错误提示
Failed to connect or change directory jenkins.plugins.publish_over.BapPublisherException: Failed to connect and initialize SSH connection.
默认输出key格式
[root@iZwz92yjivclsut0awv6bjZ ~]# ssh-keygen -t ecdsa -b 256 Generating public/private ecdsa key pair. Enter file in which to save the key (/root/.ssh/id_ecdsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_ecdsa. Your public key has been saved in /root/.ssh/id_ecdsa.pub. The key fingerprint is: SHA256:bG0w07gnsQlE68UytVRe+ZlD21B9EeKN+OD4wmAf7cg root@iZwz92yjivclsut0awv6bjZ The key's randomart image is: +---[ECDSA 256]---+ | .o o.. .o +=| | . = = .+ * o| | = X oo = B.| | . * X+ o * .| | .oSo+o . . | | ..=+= | | E o | | . | | | +----[SHA256]-----+ [root@iZwz92yjivclsut0awv6bjZ ~]# cat .ssh/id_ecdsa -----BEGIN OPENSSH PRIVATE KEY----- b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAaAAAABNlY2RzYS 1zaGEyLW5pc3RwMjU2AAAACG5pc3RwMjU2AAAAQQRs8Cw4Ydm7zowb4ZYpuqwqSfeaOXqw byz0iL1KAsWJyA8swh/AG2eHW3HJd1QWYExeQBKGe/9kPBpdKP+JpVcmAAAAuO37TNHt+0 zRAAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBGzwLDhh2bvOjBvh lim6rCpJ95o5erBvLPSIvUoCxYnIDyzCH8AbZ4dbccl3VBZgTF5AEoZ7/2Q8Gl0o/4mlVy YAAAAhAOEdqVnSzZwrdb0QpuT6taMnF3LrIF+Wbo4TMMVnDcJiAAAAHHJvb3RAaVp3ejky eWppdmNsc3V0MGF3djZialoBAgM= -----END OPENSSH PRIVATE KEY----- [root@iZwz92yjivclsut0awv6bjZ ~]#
指定输出key格式
[root@iZwz92yjivclsut0awv6bjZ ~]# ssh-keygen -t ecdsa -b 256 -m PEM Generating public/private ecdsa key pair. Enter file in which to save the key (/root/.ssh/id_ecdsa): /root/.ssh/id_ecdsa already exists. Overwrite (y/n)? y Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_ecdsa. Your public key has been saved in /root/.ssh/id_ecdsa.pub. The key fingerprint is: SHA256:BsVkzYf82bO5QtF1gs85DN90JvyqGFSaMD9D2+xV+fI root@iZwz92yjivclsut0awv6bjZ The key's randomart image is: +---[ECDSA 256]---+ | o++ . o .| | o+ * = +.B| | . = X X @+| | . O * & +| | S. + o O | | . . o + E| | + . . | | . o . | | . | +----[SHA256]-----+ [root@iZwz92yjivclsut0awv6bjZ ~]# cat .ssh/id_ecdsa -----BEGIN EC PRIVATE KEY----- MHcCAQEEIIPtHTiOHFbg0ib+xqpT/Ppu15gIVnnh1UGJjjZoiDr9oAoGCCqGSM49 AwEHoUQDQgAEp/PU4drzb49XzMmrnIa55Veb9K5coVX/67B6aNF3owQX3tCBSzFp Y3BwI+m5jRZ8CDRwQgItF6jW6h8snr9xeg== -----END EC PRIVATE KEY----- [root@iZwz92yjivclsut0awv6bjZ ~]#
参数描述
-m key_format Specify a key format for the -i (import) or -e (export) conversion options. The supported key formats are: “RFC4716” (RFC 4716/SSH2 public or private key), “PKCS8” (PEM PKCS8 public key) or “PEM” (PEM public key). The default conversion format is “RFC4716”.
12月 242020
https://ipinfo.io/developers
C:\Users\harveymei>curl ipinfo.io { "ip": "119.137.55.106", "city": "Shenzhen", "region": "Guangdong", "country": "CN", "loc": "22.5455,114.0683", "org": "AS4134 CHINANET-BACKBONE", "timezone": "Asia/Shanghai", "readme": "https://ipinfo.io/missingauth" } C:\Users\harveymei>
12月 212020
import time # 使用时间模块 filename = str(int(time.time())) + ".py" # 使用时间戳命名对象,拼接文件名
11月 062020
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time : 2020/11/3 14:59
# @Author : Harvey Mei <harvey.mei@msn.com>
# @FileName : base36.py
# @IDE : PyCharm
# @GitHub :https://github.com/harveymei/
import string
# base10 to base36
def encode(number):
alphabet = string.digits + string.ascii_lowercase
value = ''
while number != 0:
number, index = divmod(number, len(alphabet))
value = alphabet[index] + value
return value or '0'
# base36 to base10
def decode(value):
return int(value, 36)
# 循环,当number > 0时求商取余,将余数作为字符串切片取值
print(divmod(1024, 36))
print((string.digits + string.ascii_lowercase)[16])
# 'g' + ''
print(divmod(28, 36))
print((string.digits + string.ascii_lowercase)[28])
# 's' + 'g'
# 当number == 0时退出循环
print(divmod(0, 36))
print((string.digits + string.ascii_lowercase)[0])
10月 302020
# -*- coding:utf-8 -*-
# 类是一系列具有共同特征和行为的事物的抽象概念的总和
# 在类里面赋值的变量就是类的变量,专有术语称之为类的属性(Class Attribute)
class CocaCola: # Class names should use CamelCase convention
formula = ['caffeine', 'sugar', 'water', 'soda']
# 类的实例化
# 将类赋值给变量的过程称之为类的实例化,被实例化后的对象称之为实例
coke_for_me = CocaCola() # PEP 8: E305 expected 2 blank lines after class or function definition, found 1
coke_for_you = CocaCola()
# 类属性引用
# 在类的名字后输入.后IDE自动联想类中的属性
# 类的属性会被所有类的实例共享
print(CocaCola.formula)
print(coke_for_me.formula)
print(coke_for_you.formula)
for element in coke_for_me.formula:
print(element)
# 实例属性
coke_for_china = CocaCola()
coke_for_china.local_logo = '可口可乐'
print(coke_for_china.local_logo)
C:\Users\harveymei\PycharmProjects\mod3736\venv\Scripts\python.exe C:/Users/harveymei/PycharmProjects/mod3736/howto.py
['caffeine', 'sugar', 'water', 'soda']
['caffeine', 'sugar', 'water', 'soda']
['caffeine', 'sugar', 'water', 'soda']
caffeine
sugar
water
soda
可口可乐
Process finished with exit code 0
10月 292020
# -*- coding:utf-8 -*-
import string
# 输出所有标点符号!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
print(string.punctuation)
# https://docs.python.org/zh-cn/3/library/stdtypes.html#str.strip
# strip()方法返回原字符串的副本,移除其中的前导和末尾字符。不指定参数则移除空格。
# https://docs.python.org/zh-cn/3/library/string.html#string.punctuation
# 字符串常量,返回被视为标点符号的 ASCII 字符所组成的字符串
# https://docs.python.org/zh-cn/3/library/functions.html#func-set
# set()函数,返回集合对象。
# set()函数创建一个无序不重复元素集,可进行关系测试,删除重复数据,还可以计算交集、差集、并集等。
path = 'C:/Users/harveymei/Desktop/news.txt'
with open(path, 'r') as text:
# 循环读取分割单词赋值变量写入列表并对元素去除标点符号并转换为小写
words = [raw_word.strip(string.punctuation).lower() for raw_word in text.read().split()]
words_index = set(words) # 使用set()函数将列表中的字符去重复后赋值变量
# 循环获取列表元素作为key,并将words列表中元素计数值作为value,生成字典并赋值变量
counts_dic = {index: words.count(index) for index in words_index}
# https://docs.python.org/zh-cn/3/library/functions.html#sorted
# 根据 iterable 中的项返回一个新的已排序列表。
# 具有两个可选参数,它们都必须指定为关键字参数。
# key 指定带有单个参数的函数,用于从 iterable 的每个元素中提取用于比较的键 (例如 key=str.lower)。 默认值为 None (直接比较元素)。
# reverse 为一个布尔值。 如果设为 True,则每个列表元素将按反向顺序比较进行排序。
# https://docs.python.org/zh-cn/3/howto/sorting.html#key-functions
# key 形参用来指定在进行比较前要在每个列表元素上调用的函数(或其他可调用对象)。
# https://docs.python.org/zh-cn/3/reference/expressions.html?highlight=lambda#lambda
# lambda 表达式(有时称为 lambda 构型)被用于创建匿名函数。
for word in sorted(counts_dic, key=lambda x: counts_dic[x], reverse=True): # 循环对字典中元素按照计数值反向排序并赋值变量
print('{} -- {} times'.format(word, counts_dic[word])) # 使用格式化字符串打印单词及对应计数值
C:\Users\harveymei\PycharmProjects\mod3736\venv\Scripts\python.exe C:/Users/harveymei/PycharmProjects/mod3736/static.py
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
the -- 14 times
a -- 4 times
in -- 4 times
and -- 4 times
that -- 4 times
leads -- 2 times
created -- 2 times
practice -- 2 times
such -- 2 times
china -- 2 times
has -- 2 times
said -- 2 times
legislature -- 2 times
party -- 2 times
li -- 2 times
experience -- 2 times
process -- 2 times
is -- 2 times
adding -- 2 times
government -- 2 times
roles -- 2 times
good -- 2 times
governance -- 2 times
cpc -- 2 times
due -- 2 times
work -- 2 times
formulation -- 2 times
their -- 2 times
of -- 2 times
play -- 2 times
Process finished with exit code 0
10月 282020
# -*- coding:utf-8 -*-
lyric = 'The night begin to shine, the night begin to shine'
words = lyric.split()
print(words)
# 词频统计
# https://docs.python.org/zh-cn/3/library/stdtypes.html#str.split
# split()方法:返回一个由字符串内单词组成的列表,使用 sep 作为分隔字符串
# https://docs.python.org/zh-cn/3/library/stdtypes.html#str.count
# count()方法:返回子字符串 sub 在 [start, end] 范围内非重叠出现的次数。 可选参数 start 与 end 会被解读为切片表示法。
# https://docs.python.org/zh-cn/3/tutorial/inputoutput.html#methods-of-file-objects
# 文件对象的read()方法,读取文件内容
path = 'C:/Users/harveymei/Desktop/news.txt'
with open(path, 'r') as text: # 只读打开文件并赋值给变量text
words = text.read().split() # 读取文件内容拆分单词并赋值变量
print(words)
for word in words: # for循环遍历列表中元素并赋值给变量
print('{} -{} times'.format(word, words.count(word))) # 将元素及元素计数插入字符串
# 问题:
# 1,带标点符号的单词被单独统计
# 2,一些单词展示多次统计
# 3,首字母大写单词被单独统计
C:\Users\harveymei\PycharmProjects\mod3736\venv\Scripts\python.exe C:/Users/harveymei/PycharmProjects/mod3736/static.py
['The', 'night', 'begin', 'to', 'shine,', 'the', 'night', 'begin', 'to', 'shine']
['The', 'Party', 'leads', 'the', 'formulation', 'work,', 'and', 'the', 'government', 'and', 'the', 'legislature', 'play', 'their', 'due', 'roles', 'in', 'the', 'process,', 'Li', 'said,', 'adding', 'that', 'such', 'a', 'practice', 'is', 'a', 'good', 'experience', 'that', 'the', 'CPC', 'has', 'created', 'in', 'the', 'governance', 'of', 'China.', 'The', 'Party', 'leads', 'the', 'formulation', 'work,', 'and', 'the', 'government', 'and', 'the', 'legislature', 'play', 'their', 'due', 'roles', 'in', 'the', 'process,', 'Li', 'said,', 'adding', 'that', 'such', 'a', 'practice', 'is', 'a', 'good', 'experience', 'that', 'the', 'CPC', 'has', 'created', 'in', 'the', 'governance', 'of', 'China.']
The -2 times
Party -2 times
leads -2 times
the -12 times
formulation -2 times
work, -2 times
and -4 times
the -12 times
government -2 times
and -4 times
the -12 times
legislature -2 times
play -2 times
their -2 times
due -2 times
roles -2 times
in -4 times
the -12 times
process, -2 times
Li -2 times
said, -2 times
adding -2 times
that -4 times
such -2 times
a -4 times
practice -2 times
is -2 times
a -4 times
good -2 times
experience -2 times
that -4 times
the -12 times
CPC -2 times
has -2 times
created -2 times
in -4 times
the -12 times
governance -2 times
of -2 times
China. -2 times
The -2 times
Party -2 times
leads -2 times
the -12 times
formulation -2 times
work, -2 times
and -4 times
the -12 times
government -2 times
and -4 times
the -12 times
legislature -2 times
play -2 times
their -2 times
due -2 times
roles -2 times
in -4 times
the -12 times
process, -2 times
Li -2 times
said, -2 times
adding -2 times
that -4 times
such -2 times
a -4 times
practice -2 times
is -2 times
a -4 times
good -2 times
experience -2 times
that -4 times
the -12 times
CPC -2 times
has -2 times
created -2 times
in -4 times
the -12 times
governance -2 times
of -2 times
China. -2 times
Process finished with exit code 0
10月 282020
# -*- coding:utf-8 -*-
# 列表推导式 == 列表解析式
# list = [ item for item in iterable ]
# iterate:迭代
# 放在列表中的元素,就是后面循环的元素本身
a = [i ** 2 for i in range(1, 10)] # 将1-9的平方值依次放入列表
c = [j + 1 for j in range(1, 10)] # 将1-9分别加1的值放入列表
k = [n for n in range(1, 10) if n % 2 == 0] # 依次判断1-10中是否为偶数并将偶数值放入列表
z = [letter.lower() for letter in 'ABCEDFGHIJKLMN'] # 将字符串中的大写字母依次转换为小写并放入列表
print(a, c, k, z)
# 字典推导式
d = {i: i+1 for i in range(4)} # 将0-3依次作为key,0-3分别加1作为value,放入字典
print(d)
g = {i: j for i, j in zip(range(1, 6), 'abcde')} # 将1-5依次作为key,将字符串中字符依次作为value,放入字典
print(g)
m = {i: j.upper() for i, j in zip(range(1, 6), 'abcde')} # 将1-5依次作为key,将字符依次作为value并转换大小,放入字典
print(m)
# enumerate:枚举
# 循环列表时获取元素的索引
# 列表是有序的
# enumerate()函数,参数为可迭代对象,返回一个枚举对象。
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
for num, letter in enumerate(letters): # 返回一个包含计数值(默认从0开始)和通过迭代获得的值
print(letter, 'is', num + 1)
# 示例
print(list(enumerate(letters)))
print(list(enumerate(letters, start=1)))
C:\Users\harveymei\PycharmProjects\mod3736\venv\Scripts\python.exe C:/Users/harveymei/PycharmProjects/mod3736/news.py
[1, 4, 9, 16, 25, 36, 49, 64, 81] [2, 3, 4, 5, 6, 7, 8, 9, 10] [2, 4, 6, 8] ['a', 'b', 'c', 'e', 'd', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n']
{0: 1, 1: 2, 2: 3, 3: 4}
{1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e'}
{1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E'}
a is 1
b is 2
c is 3
d is 4
e is 5
f is 6
g is 7
[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd'), (4, 'e'), (5, 'f'), (6, 'g')]
[(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e'), (6, 'f'), (7, 'g')]
Process finished with exit code 0