<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel rdf:about="https://eblog.ink/feed/rss/category/%E7%BC%96%E7%A8%8B-%E8%84%9A%E6%9C%AC/">
<title>Eric&#039;s Blog - 编程&amp;脚本</title>
<link>https://eblog.ink/category/%E7%BC%96%E7%A8%8B-%E8%84%9A%E6%9C%AC/</link>
<description></description>
<items>
<rdf:Seq>
<rdf:li resource="https://eblog.ink/archives/325/"/>
<rdf:li resource="https://eblog.ink/archives/315/"/>
<rdf:li resource="https://eblog.ink/archives/278/"/>
<rdf:li resource="https://eblog.ink/archives/273/"/>
<rdf:li resource="https://eblog.ink/archives/242/"/>
<rdf:li resource="https://eblog.ink/archives/314/"/>
<rdf:li resource="https://eblog.ink/archives/207/"/>
<rdf:li resource="https://eblog.ink/archives/205/"/>
<rdf:li resource="https://eblog.ink/archives/204/"/>
<rdf:li resource="https://eblog.ink/archives/203/"/>
</rdf:Seq>
</items>
</channel>
<item rdf:about="https://eblog.ink/archives/325/">
<title>【Python】程序提取视频中的声音</title>
<link>https://eblog.ink/archives/325/</link>
<dc:date>2022-12-09T08:49:00+00:00</dc:date>
<description>安装依赖pip install multiprocessing
pip install moviepy.editor
Python代码from multiprocessing import Pool
from moviepy.editor import AudioFileClip
import os
def p(path,path1, item):
    new_name = item.split(&#039;.&#039;)[0]+&#039;.mp3&#039;
    my_audio_clip = AudioFileClip(path+&#039;\\&#039;+item)
    my_audio_clip.write_audiofile(path1+&#039;\\&#039;+new_name)
if __name__ == &#039;__main__&#039;:
    p = input(&quot;请输入路径：&quot;)
    path = r&#039;/rooot/mp4&#039;
    path1 = path + &#039;\已处理&#039;
    os.mkdir(path1)
    list1 = [files for root, dirs, files in os.walk(path)][0]
    num_of_processes = 10
    outcome = 6
    po = Pool(num_of_processes)
    for item in list1:
        po.apply_async(p, (path,path1,item,))

    po.close()
    po.join()</description>
</item>
<item rdf:about="https://eblog.ink/archives/315/">
<title>Python pyPdf2&amp;amp;pyPdf 多页PDF文档处理报错</title>
<link>https://eblog.ink/archives/315/</link>
<dc:date>2022-04-22T09:02:30+00:00</dc:date>
<description>当一个pdf文件有多page的时候，它将出来见你！偷笑方法是取直接修改那个文件generic.py(1)pyPdf路径大约在这里：/usr/lib/python2.7/site-packages/pyPdf/generic.pyif data.has_key(key):
      # multiple definitions of key not permitted
      raise utils.PdfReadError, &quot;multiple definitions in dictionary&quot;
data[key] = value

大约在532--536行将它修改为：if not data.get(key):
 
    data[key] = value

（2）pyPdf2路径大约在：/usr/lib/python2.7/site-packages/PyPDF2/generic.py        if not data.get(key):
            data[key] = value
        elif pdf.strict:
            # multiple definitions of key not permitted
            raise PdfReadError(
                &quot;Multiple definitions in dictionary at byte %s for key %s&quot; \
                % (utils.hexStr(stream.tell()), key))
        else:
            warnings.warn(
                &quot;Multiple definitions in dictionary at byte %s for key %s&quot; \
                % (utils.hexStr(stream.tell()), key), PdfReadWarning)
修改为：            if not data.get(key):
                data[key] = value
#            elif pdf.strict:
#                # multiple definitions of key not permitted
#                raise PdfReadError(
#                    &quot;Multiple definitions in dictionary at byte %s for key %s&quot; \
#                    % (utils.hexStr(stream.tell()), key))
#            else:
#                warnings.warn(
#                    &quot;Multiple definitions in dictionary at byte %s for key %s&quot; \
#                    % (utils.hexStr(stream.tell()), key), PdfReadWarning)

</description>
</item>
<item rdf:about="https://eblog.ink/archives/278/">
<title>github同步仓库（非Fork）</title>
<link>https://eblog.ink/archives/278/</link>
<dc:date>2021-05-27T03:37:37+00:00</dc:date>
<description>1.新建仓库2.点击Action3.复制复制代码修改# File: .github/workflows/repo-sync.yml
name: 自动同步
on:
  schedule:
    - cron: &#039;0 4,16  * * *&#039;
  workflow_dispatch:
  watch:
    types: started
  repository_dispatch:
    types: repo-sync
jobs:
  repo-sync:
    env:
      PAT: ${{ github.event.client_payload.PAT || secrets.PAT }} #此处PAT需要申请，教程详见：https://www.jianshu.com/p/bb82b3ad1d11
      dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} # 我自己同步到gitee使用，其他人可忽略
    runs-on: ubuntu-latest
    if: github.event.repository.owner.id == github.event.sender.id
    steps:
      - uses: actions/checkout@v2
        with:
          persist-credentials: false

      - name: 开始A自动同步
        uses: repo-sync/github-sync@v2
        if: env.PAT
        with:
          source_repo: &quot;https://github.com/shuye73/MyActions.git&quot;   #此处修改
          source_branch: &quot;main&quot;
          destination_branch: &quot;main&quot;
          github_token: ${{ github.event.client_payload.PAT || secrets.PAT }}

4.申请Tokenhttps://github.com/settings/appsPersonal access tokens  -- Generate new tokenNote 随便输入（方便辨别的）勾选：repo  workflow5.进入Settings--secrets 新建 New repository secretName 输入PATValue输入申请的token</description>
</item>
<item rdf:about="https://eblog.ink/archives/273/">
<title>Github  使用git将项目上传到github（最简单方法）</title>
<link>https://eblog.ink/archives/273/</link>
<dc:date>2021-03-16T07:41:45+00:00</dc:date>
<description>首先你需要一个github账号，所有还没有的话先去注册吧！https://github.com/我们使用git需要先安装git工具，这里给出下载地址，下载后一路直接安装即可：https://git-for-windows.github.io/1.进入Github首页，点击New repository新建一个项目2.填写相应信息后点击create即可 Repository name: 仓库名称Description(可选): 仓库描述介绍Public, Private : 仓库权限（公开共享，私有或指定合作者）Initialize this repository with a README: 添加一个README.mdgitignore: 不需要进行版本管理的仓库类型，对应生成文件.gitignorelicense: 证书类型，对应生成文件LICENSE3.点击Clone or dowload会出现一个地址，copy这个地址备用。4.接下来就到本地操作了，首先右键你的项目，如果你之前安装git成功的话，右键会出现两个新选项，分别为Git Gui Here,Git Bash Here,这里我们选择Git Bash Here，进入如下界面，Test_Bluetooth即为我的项目名。5.接下来输入如下代码（关键步骤），把github上面的仓库克隆到本地git clone https://github.com/CKTim/BlueTooth.git（https://github.com/CKTim/BlueTooth.git替换成你之前复制的地址）
6.这个步骤以后你的本地项目文件夹下面就会多出个文件夹，该文件夹名即为你github上面的项目名，如图我多出了个Test文件夹，我们把本地项目文件夹下的所有文件（除了新多出的那个文件夹不用），其余都复制到那个新多出的文件夹下，7.接着继续输入命令 cd Test，进入Test文件夹8.接下来依次输入以下代码即可完成其他剩余操作：git add .        （注：别忘记后面的.，此操作是把Test文件夹下面的文件都添加进来）git commit  -m  &quot;提交信息&quot;  （注：“提交信息”里面换成你需要，如“first commit”）git push -u origin master   （注：此操作目的是把本地仓库push到github上面，此步骤需要你输入帐号和密码）</description>
</item>
<item rdf:about="https://eblog.ink/archives/242/">
<title>mysql 如何清除binlog</title>
<link>https://eblog.ink/archives/242/</link>
<dc:date>2020-08-26T09:58:00+00:00</dc:date>
<description>1）：执行“reset master;”命令，该命令将删除bai所有二进制du日志，新日志的编号从“000001”开始，命令如zhi下Mysql&gt;reset master;
（2）：执行“Purge master logs to ‘mysql-bin.’”命令，该命令将删除“”编号之前的所有日志，下列中删除了“mysql-bin之前编号的所有日志Mysql&gt;purge master logs to ‘mysql-bin.000015;
从结果中发现，编号000015之前的所有日志都已经删除（3）：执行“purge master logs before ‘yyyy-mm-dd hh24:min:ss’”命令，该命令将删除日期为“yyyy-mm-dd hh24:mi:ss”之前产生的所有日志，下列中删除了日期在“2010-05-22 01:00:之前的所有日志Mysql&gt;purge master logs before ‘ 01:00:’;
（4）：设置参数—expire_logs_days=#(days)，此参数的含义是设置日志的过期天数，过来指定的天数后日志将会被自动删除，这样将有利于减少DBA管理日志的工作量。vim /etc/my.cnf

[mysqld]
--expire_logs_days=3
这样，3天前的日志都会被删除，系统自动删除</description>
</item>
<item rdf:about="https://eblog.ink/archives/314/">
<title>Python pyinstaller 参数</title>
<link>https://eblog.ink/archives/314/</link>
<dc:date>2019-07-16T16:00:00+00:00</dc:date>
<description>可选参数 说明-F dist文件夹中生成一个程序demo.exe文件，适用于一个模块没有多依赖.py文件-D 默认选项，除了主程序demo.exe外，还会在在dist文件夹中生成很多依赖文件，推荐使用这个-c 默认选项，只对windows有效，使用控制台-w 只对windows有效，不使用控制台-p 设置导入路径-i 给生成的demo.exe文件设置一个自定义的图标--key 后面接加密参数使用 Pipenv减小打包文件的大小1.安装 Pipenvpip install pipenv

2.pipenv install --python 3.9
(版本为已安装的版本)3.在命令行下激活环境pipenv shell
4.在虚拟环境下安装 Pyinstaller 和你自己的脚本依赖的第三方库pipenv install pyinstaller
pipenv install pyqt5
....
pipenv install -i https://pypi.tuna.tsinghua.edu.cn/simple5.常用指令创建环境： pipenv install激活环境： pipenv shell退出环境： exit删除环境： pipenv --rm安装依赖安装依赖到虚拟环境pipenv install [package]或者pip install -r requirements.txt查看虚拟环境中的所有安装的包如果没有进入虚拟环境中，则需要先使用pipenv shell进入虚拟环境。然后使用pip list查看，或者使用pip freeze &gt; requirements.txt导出所有安装的包。删除/清空环境的依赖删除指定的包：pipenv uninstall [package]清空：pipenv uninstall --all或pipenv uninstall --all-dev</description>
</item>
<item rdf:about="https://eblog.ink/archives/207/">
<title>Python  模式表达与正则表达式</title>
<link>https://eblog.ink/archives/207/</link>
<dc:date>2019-07-16T09:12:00+00:00</dc:date>
<description>1.国外手机判断def iphonenum(txt):
    if len(txt) != 12:
        return False
    for i in range(3):
        if not txt[i].isdecimal():
            return False
    if txt[3] != &#039;-&#039;:
        return False
    for j in range(4, 7):
        if not txt[j].isdecimal():
            return False
    if txt[7] != &#039;-&#039;:
        return False
    for l in range(8, 12):
        if not txt[l].isdecimal():
            return False
    return True

print(&#039;请输入手机号码：&#039;, end=&#039;&#039;)
k =input()
print(&#039;判断是否为手机号码：&#039;, iphonenum(k))
2.查找文本中的手机号码def iphonenum(txt):
    if len(txt) != 12:
        return False
    for i in range(3):
        if not txt[i].isdecimal():
            return False
    if txt[3] != &#039;-&#039;:
        return False
    for j in range(4, 7):
        if not txt[j].isdecimal():
            return False
    if txt[7] != &#039;-&#039;:
        return False
    for l in range(8, 12):
        if not txt[l].isdecimal():
            return False
    return True

mes=&#039;Call me at 415-555-1101 tomorrow.415-666-7845 is my office.&#039;
for m in range(len(mes)):
    n = mes[m:m+12]
    if iphonenum(n):
        print(&#039;找到的电话号码是：&#039;, n)
print(&#039;查找完成&#039;)3.判断国内手机号码def iphonenum(txt):
    if len(txt) != 11:
        return False
    for i in range(11):
        if not txt[i].isdecimal():
            return False
    return True

print(&#039;请输入手机号码：&#039;, end=&#039;&#039;)
k =input()
print(&#039;判断是否为手机号码：&#039;, iphonenum(k))
4.正则表达式例一：import re
phonenum = re.compile(r&#039;\d\d\d-\d\d\d-\d\d\d\d&#039;)
k = &#039;my phone Number is 400-410-8888, and my office number is 411-808-9999·&#039;
mo = phonenum.search(k)
print(&#039;打印出找到的电话号码：&#039;, mo.group())
print(mo.groups())
例二：import re
phonenum = re.compile(r&#039;(\d\d\d)-(\d\d\d-\d\d\d\d)&#039;)
k = &#039;my phone Number is 400-410-8888, and my office number is 411-808-9999&#039;
mo = phonenum.search(k)
print(&#039;1：&#039;, mo.group())
print(&#039;2：&#039;, mo.group(1))
print(&#039;3：&#039;, mo.group(2))
print(&#039;4：&#039;, mo.groups())
j,  l = mo.groups()
print(&#039;5：&#039;, j)
print(&#039;6：&#039;, l)
m = mo.groups()
n=list(m)
print(&#039;7：&#039;, n)
o=tuple(n)
print(&#039;8：&#039;, o)
p=&#039;-&#039;.join(o)
print(&#039;9：&#039;, p)
5.用管道匹配分组import re
ph = re.compile(r&#039;Batman|Tina Fey&#039;)
a = &quot;Batman and Tina Fey&quot;
b = &quot;Tina Fey and Batman&quot;
mo1 = ph.search(a)
mo2 = ph.search(b)
print(&#039;1：&#039;, mo1.group())
print(&#039;2：&#039;, mo2.group())

phx = re.compile(r&#039;Bat(man|mil|cop|kk)&#039;)
c = &quot;Batman and Batmil and Batcop and Tina&quot;
mo3 = phx.search(c)
print(&#039;3：&#039;, mo3.group())
print(&#039;4：&#039;, mo3.groups())
print(&#039;5：&#039;, mo3.group(1))
print(&#039;&#039;&#039; ////////以下是4和5转换为的列表&#039;&#039;&#039;&#039;&#039;)
d =list(mo3.groups())
print(&#039;6：&#039;,d)
e =mo3.group(1)
f = e.split()
print(&#039;7：&#039;, f)
6.问号实现可选匹配import re
px = re.compile(r&#039;Bat(wo)?man&#039;)
z = &#039;The Adventures of Batman&#039;
x = &#039;The Adventures of Batwoman&#039;
c = &#039;The Adventures of Batwowoman Batman&#039;
mo1 = px.search(z)
print(&#039;1：&#039;, mo1.group())
print(&#039;1：&#039;, mo1.groups())
print(&#039;1：&#039;, mo1.group(1))
mo2 = px.search(x)
print(&#039;2：&#039;, mo2.group())
print(&#039;2：&#039;, mo2.groups())
print(&#039;2：&#039;, mo2.group(1))
mo3 = px.search(c)
print(&#039;3：&#039;, mo3.group())
print(&#039;3：&#039;, mo3.groups())
print(&#039;3：&#039;, mo3.group(1))7.星号实现0个或多个匹配import re
px = re.compile(r&#039;Bat(wo)*man&#039;)
z = &#039;The Adventures of Batman&#039;
x = &#039;The Adventures of Batwoman&#039;
c = &#039;The Adventures of Batwowoman Batman&#039;
mo1 = px.search(z)
print(&#039;1：&#039;, mo1.group())
print(&#039;1：&#039;, mo1.groups())
print(&#039;1：&#039;, mo1.group(1))
mo2 = px.search(x)
print(&#039;2：&#039;, mo2.group())
print(&#039;2：&#039;, mo2.groups())
print(&#039;2：&#039;, mo2.group(1))
mo3 = px.search(c)
print(&#039;3：&#039;, mo3.group())
print(&#039;3：&#039;, mo3.groups())
print(&#039;3：&#039;, mo3.group(1))
8.加号实现一个或多个匹配import re
px = re.compile(r&#039;Bat(wo)+man&#039;)
x = &#039;The Adventures of Batwoman&#039;
c = &#039;The Adventures of Batwowoman Batman&#039;
mo2 = px.search(x)
print(&#039;2：&#039;, mo2.group())
print(&#039;2：&#039;, mo2.groups())
print(&#039;2：&#039;, mo2.group(1))
mo3 = px.search(c)
print(&#039;3：&#039;, mo3.group())
print(&#039;3：&#039;, mo3.groups())
print(&#039;3：&#039;, mo3.group(1))
9.花括号实现特定次数匹配import re
px = re.compile(r&#039;Bat(wo){3,5}man&#039;)
x = &#039;The Adventures of Batwowowoman&#039;
c = &#039;The Adventures of Batwowowowoman Batman&#039;
mo2 = px.search(x)
print(&#039;2：&#039;, mo2.group())
print(&#039;2：&#039;, mo2.groups())
print(&#039;2：&#039;, mo2.group(1))
mo3 = px.search(c)
print(&#039;3：&#039;, mo3.group())
print(&#039;3：&#039;, mo3.groups())
print(&#039;3：&#039;, mo3.group(1))
print(&#039;Python正则表达式默认是贪心的，在有二义的情况匹配最长字符 &#039;)
10.findall()使用方法
import re
phonenum = re.compile(r&#039;\d\d\d-\d\d\d-\d\d\d\d&#039;)
k = &#039;my phone Number is 400-410-8888, and my office number is 411-808-9999·411-785-1360,361-879-1360&#039;
mo = phonenum.findall(k)
for i in range(len(mo)):
    k =mo[i]
    print(&#039;打印出找到的第&#039;+str(i+1)+&#039;个电话号码：&#039;, k)
10.字符分类&#039;&#039;&#039;
\d   0-9的数字
\D   除0-9以外的数字
\w   任何数字字母或下划线字符（匹配单词字符）
\W   除字母，数字和下划线以外的任何字符
\s    空格，制表符，换行符（匹配空白字符）
\S    除空格，制表符，换行符以外的任何字符
&#039;&#039;&#039;
print(
&#039;&#039;&#039;
\d   0-9的数字
\D   除0-9以外的数字
\w   任何数字字母或下划线字符（匹配单词字符）
\W   除字母，数字和下划线以外的任何字符
\s    空格，制表符，换行符（匹配空白字符）
\S    除空格，制表符，换行符以外的任何字符
&#039;&#039;&#039;)
import re
ce =re.compile(r&#039;\d+\s+\w&#039;)
le = re.compile(r&#039;\d+\s&#039;)
qe = re.compile(r&#039;\d+&#039;)
ke=&#039;11 text,23 your,89 kill&#039;
ve =ce.findall(ke)
print(&#039;输出第一次从字符串中提取的列表：&#039;, ve)
be = &#039; &#039;.join(ve)
print(&#039;把列表转换为字符串：&#039;, be)
ne =le.findall(be)
print(&#039;输出第二次从字符串中提取的列表：&#039;, ne)
me =[]
for i in range(len(ne)):
    o =ne[i]
    p = o.strip()
    me.append(p)
print(&#039;输出去空格过后的数字列表：&#039;, me)
tuple1 = tuple(me)
print(&#039;输出转换的元组：&#039;, tuple1)
str2=&#039; &#039;.join(tuple1)
print(&#039;输出字符串：&#039;, str2)
we = qe.findall(str2)
print(&#039;再次转换为列表：&#039;, we)
ee = &#039;&#039;.join(we)
print(&#039;把所有数字链接：&#039;, ee)11.建立自己的字符分类#建立 自己的字符分类
import re
vowe =re.compile(r&#039;[aeirAidR]&#039;)
ve = &#039;Administrator,try agin&#039;
ce = vowe.findall(ve)
print(ce)
12.插入字符和美元字符import re
ne = re.compile(r&#039;\d$&#039;)
ve = re.compile(r&#039;^Hello&#039;)
ce = &#039;Hello World!&#039;
me = &quot;my number is 42&quot;
be =ne.search(me)
ae = ne.findall(me)
print(be)
print(ae)
xe = ve.search(ce)
ze= ve.findall(ce)
print(xe)
print(ze)
13.通配字符import re
me = re.compile(r&#039;.at&#039;)
ne = &#039;the cat in the hat.sat on the flat mat&#039;
be = me.findall(ne)
k =input(&#039;请加入一个以at结尾的单词：&#039;)
be.append(k)
print(be)
ve =&#039; &#039;.join(be)
ce=&#039;&#039;.join(be)
print(ve)
print(ce)
14.用点-星匹配所有字符import re
me = re.compile(r&#039;First Name:(.*) Last Name:(.*)&#039;)
ne = &#039;My First Name:Eric Last Name:Qiu&#039;
be =me.search(ne)
print(be)
print(be.group())
print(be.groups())
print(be.group(1))
print(be.group(2))15句点字符匹配换行import re
me = re.compile(r&#039;.*&#039;)
ve =re.compile(r&#039;.*&#039;, re.DOTALL)
ne = &#039;My First Name:Eric \nLast Name:Qiu&#039;
be = me.search(ne)
ce = ve.search(ne)
print(be.group())
print(ce.group())16.不区分大小写import re
me1 = re.compile(&#039;RoboCop&#039;)
me1 = re.compile(&#039;RObOCOP&#039;)
me1 = re.compile(&#039;robOcop&#039;)
me1 = re.compile(&#039;RobocOp&#039;)
ne = re.compile(r&#039;robocop&#039;, re.I)
be = &quot;RoboCop is part man.part machine,all cop&quot;
ve = ne.search(be)
print(ve.group())
17.使用sub()方法替换替换字符import re
ne = re.compile(r&#039;Agent \w+&#039;)
ve = ne.sub(&#039;CENSORED&#039;,&#039;Agent gave is part man.part machine,all cop&#039;)
print(ve)

</description>
</item>
<item rdf:about="https://eblog.ink/archives/205/">
<title>Python 字符串操作</title>
<link>https://eblog.ink/archives/205/</link>
<dc:date>2019-07-11T08:57:00+00:00</dc:date>
<description>1.转义符\&#039;        单引号
\&quot;        双引号
\t        制表符
\n        换行符
\\        倒斜杠2.原始字符串在前面加上r例子：&gt;print(r&quot;my \name is Bob&quot;)
my \name is Bob
&gt;print(&quot;my \name is Bob&quot;)
my 
ame is Bob3.三重引号的多行字符串&gt;print(&#039;&#039;&#039;my
name
is
Bob
&#039;&#039;&#039;)输出的结果为：my
name
is
Bob
4，多行注释#表示这一行注释
&quot;&quot;&quot;This
is
python
&quot;&quot;&quot;

def he():
    &quot;&quot;&quot;This is 
        Python
        &quot;&quot;&quot;
    print(&#039;Hello!&#039;)
he()输出的结果为：Hello!5.字符串下标和切片&gt;spam = &#039;Hello World!&#039;
&gt;spam[0]
&#039;H&#039;
&gt;spam[0:5]
&#039;Hello&#039;6.字符串的in和not in&gt;spam = &#039;Hello World!&#039;
&gt;&#039;Hello&#039; in &#039;Hello world&#039;
True
&gt;&#039;HELLO&#039; in &#039;Hello world&#039;
False
&gt;&#039; &#039; in spam
True
&gt;&#039;cat&#039; not in spam
True7.字符串方法upper()&lower()&isupper()&islower()upper()&lower()字符串小大写转换，返回的也是字符串：&gt;spam = &#039;Hello&#039;
&gt;spam.upper()
&gt;print(spam)
&#039;HELLO&#039;
&gt;spam.lower()
&gt;print(spam)
hello
isupper()&islower()字符串的大小写判断,返回的值为布尔值：&gt;spam = &#039;Hello&#039;
&gt;spam.isupper()
False
&gt;spam.islower()
False8.isX字符串方法除上面的isupper&islower以外，还有一下isalpha()   如果字符串只包含字母，并且非空  返回True
isalnum()   如果字符串包含字母或数字，并且非空  返回True
isdecimal() 如果字符串只包含数字字符，并且非空  返回True
isspace()   如果字符串只包含空格，制表符和换行，并且非空 返回True
istitle()   如果字符串仅包含以大写字母开头，后面都是小写的单词 返回True例子：while True:
    print(&#039;请输入你的年龄: &#039;, end=&#039;&#039;)
    age=input()
    if age.isdecimal():
        break
    elif age.isalpha():
        print(&#039;&#039;&#039;
        你输入的年龄是字符!
        年龄错误!
        请再次重试.&#039;&#039;&#039;)
    elif age.isalnum():
        print(&#039;你输入的年龄包含数字和字母!请再次重试.&#039;)
    else:
        print(&#039;未知的格式！请再次重试&#039;)
print(&#039;你的年龄是：&#039;+age)
9.startswith()&endswith()的使用方法验证开头和结尾是否为对应的值，返回的也是布尔值：&gt;spam = &#039;Hello World!&#039;
&gt;spam.startswith(&#039;Hello&#039;)
True
&gt;spam.endswith(&#039;World!&#039;)
True
&gt;spam.endswith(&#039;Hello&#039;)
False10.join()和split()的使用方法join()使列表通过某一个字符分开变为字符串例子：spam = [&#039;my&#039;, &#039;name&#039;, &#039;is&#039;, &#039;Eric&#039;]
k =&#039; &#039;.join(spam)
print(k)输出的结果为my name is Ericsplit()使字符串通过某一字符分开变为列表例子：spam = &#039;my name is Eric&#039;
j =spam.split()
print(j)输出的结果为[&#039;my&#039;, &#039;name&#039;, &#039;is&#039;, &#039;Eric&#039;]10.rjust()&ljust()&center()对齐的使用spam = &#039;my name is Eric&#039;
k = spam.rjust(30)
print(&#039;输出k的值（右对齐30个字符）：&#039;, k)
j = spam.ljust(30)
print(&#039;输出j的值（左对齐30个字符）：&#039;, j)
i = spam.center(30)
print(&#039;输出i的值（居中对齐30个字符）：&#039;,i)
k = spam.rjust(30, &#039;#&#039;)
print(&#039;输出k的值（右对齐30个字符）：&#039;, k)
j = spam.ljust(30, &#039;*&#039;)
print(&#039;输出j的值（左对齐30个字符）：&#039;, j)
i = spam.center(30, &#039;-&#039;)
print(&#039;输出i的值（居中对齐30个字符）：&#039;,i)11.strip()&rstrip()&lstrip()去除空格使用spam = &#039; Hello World! &#039;
i = spam.strip()
print(&#039;使用strip()后的值：&#039;)
print(i)
j = spam.rstrip()
print(&#039;使用rstrip()后的值：&#039;)
print(j)
k = spam.lstrip()
print(&#039;使用lstrip()后的值：&#039;)
print(k)12.pyperclip模块复制粘贴字符串#使用前确保已经安装pyperclip模块
import pyperclip
spam = &#039; Hello World! &#039;
pyperclip.copy(spam)
print(pyperclip.paste())
</description>
</item>
<item rdf:about="https://eblog.ink/archives/204/">
<title>Python 字典</title>
<link>https://eblog.ink/archives/204/</link>
<dc:date>2019-07-11T08:32:00+00:00</dc:date>
<description>1.字典和数据类型mycat ={&#039;size&#039;:&#039;fat&#039;, &#039;name&#039;:&#039;Vice&#039;, &#039;color&#039;:&#039;gray&#039;}
print(&quot;输出猫的名字为：&quot;, mycat[&#039;name&#039;])
print(&#039;my cat name is &#039;+mycat[&#039;name&#039;])
2.字典与列表spam=[&#039;dogs&#039;,&#039;cat&#039;,&#039;pig&#039;]
bacon = [&#039;pig&#039;,&#039;cat&#039;,&#039;dogs&#039;]
print(&quot;spam=[&#039;dogs&#039;,&#039;cat&#039;,&#039;pig&#039;]&quot;)
print(&quot;bacon = [&#039;pig&#039;,&#039;cat&#039;,&#039;dogs&#039;]&quot;)
if spam == bacon:
    print(&quot;True&quot;)
else:
    print(&#039;False&#039;)
    
egg = {&#039;name&#039;:&#039;jim&#039;, &#039;color&#039;:&#039;gray&#039;}
ham = {&#039;color&#039;:&#039;gray&#039;, &#039;name&#039;:&#039;jim&#039;}
print(&quot;egg = {&#039;name&#039;:&#039;jim&#039;, &#039;color&#039;:&#039;gray&#039;}&quot;)
print(&quot;ham = {&#039;color&#039;:&#039;gray&#039;, &#039;name&#039;:&#039;jim&#039;}&quot;)
if egg == ham:
    print(&#039;True&#039;)
else:
    print(&#039;False&#039;)
while True:
    print(&#039;请输入egg中的值：&#039;,end=&#039; &#039;)
    k = input()
    try:
        print(egg[k])
        break
    except KeyError:
        print(&#039;输入的字典中没有&#039;)
3.keys()&values&items()使用方法egg = {&#039;name&#039;:&#039;jim&#039;, &#039;color&#039;:&#039;gray&#039;}
for v in egg.values():
    print(&quot;打印出值：&quot;, v)
    
print(&quot;\n&quot;)
for k in egg.keys():
    print(&quot;打印出键：&quot;, k)
print(&quot;\n&quot;)

for i in egg.items():
    print(&quot;打印出键-值：&quot;, i)
    
4.检查字典中的键或值egg = {&#039;name&#039;:&#039;jim&#039;, &#039;color&#039;:&#039;gray&#039;}
&quot;name&quot; in egg.keys()
&#039;gray&#039; in egg.values()
5.get()使用spam={&#039;name&#039;:&#039;jim&#039;, &#039;color&#039;:&#039;gray&#039;}
print(&#039;获取Name的值：&#039;, spam.get(&#039;name&#039;, 0))
print(&#039;输入需要查找的键：&#039;, end=&#039; &#039;)
j = input()
k =spam.get(j, 0)
if k == 0:
    print(&#039;字典中没有&#039;+str(j)+&#039;的值&#039;)
else:
    print(&#039;键&#039;+str(j)+&#039;的值为：&#039;, k)
6.setdefault()使用：1：spam={&#039;name&#039;:&#039;jim&#039;, &#039;color&#039;:&#039;gray&#039;}
while True:
    print(&#039;输入需要查找的键：&#039;, end=&#039; &#039;)
    j = input()
    k =spam.get(j, 0)
    if k == 0:
        print(&#039;字典中没有&#039;+str(j)+&#039;的值&#039;)
        print(&#039;输入&#039;+str(j)+&#039;的值：&#039;, end=&#039;&#039;)
        i =input()
        spam.setdefault(j, i)
        print(&#039;输出字典spam：&#039;, spam)
    else:
        print(&#039;键&#039;+str(j)+&#039;的值为：&#039;, k)
        break
2：message = &quot;John Smith was a good math student at a high school. He loved his computer. He came home early every day. Then he worked with it till midnight. But John was not a good English student, not good at all. He got an F in his English class. One day after school, John joined his computer to the computer in his high school office. The school office computer had the grades of all the students: the math grades, the science grades, the grades in arts and music, and grades in English. He found his English grade. An F! John changed his English grade from F to A. John’s parents looked at his report card. They were very happy. &quot;
count={}
for char in message:
    count.setdefault(char, 0)
    count[char] = count[char]+1
print(count)
7.漂亮的打印pprintimport pprint
v = &quot;John Smith was a good math student at a high school. He loved his computer. He came home early every day. Then he worked with it till midnight. But John was not a good English student, not good at all. He got an F in his English class. One day after school, John joined his computer to the computer in his high school office. The school office computer had the grades of all the students: the math grades, the science grades, the grades in arts and music, and grades in English. He found his English grade. An F! John changed his English grade from F to A. John’s parents looked at his report card. They were very happy. &quot;
count={}
for char in v:
    count.setdefault(char, 0)
    count[char] = count[char]+1
pprint.pprint(count)
8.#字棋the = {&#039;top-L&#039;:&#039;&#039;,&#039;top-M&#039;:&#039; &#039;,&#039;top-R&#039;:&#039; &#039;,
&#039;mid-L&#039;:&#039; &#039;,&#039;mid-M&#039;:&#039;&#039;,&#039;mid-R&#039;:&#039; &#039;,
&#039;low-L&#039;:&#039; &#039;,&#039;low-M&#039;:&#039; &#039;,&#039;low-R&#039;:&#039;&#039;}
print(the)

def bord(eh):
    print(eh[&#039;top-L&#039;]+&#039;|&#039;+eh[&#039;top-M&#039;]+&#039;|&#039;+eh[&#039;top-R&#039;])
    print(&#039;-+-+-&#039;)
    print(eh[&#039;mid-L&#039;]+&#039;|&#039;+eh[&#039;mid-M&#039;]+&#039;|&#039;+eh[&#039;mid-R&#039;])
    print(&#039;-+-+-&#039;)
    print(eh[&#039;low-L&#039;]+&#039;|&#039;+eh[&#039;low-M&#039;]+&#039;|&#039;+eh[&#039;low-R&#039;])
turn = &quot;X&quot;
for i in range(9):
    bord(the)
    print(&#039;Turn for &#039; + turn+&#039; . Move on which space?&#039;)
    move =input()
    the[move]= turn
    if turn == &#039;X&#039;:
        turn = &quot;O&quot;
    else:
        turn = &quot;X&quot;
bord(the)
9.嵌套字典列表the = {&#039;Alice&#039;:{&#039;apples&#039;:5, &#039;pies&#039;:12}, 
&#039;Bob&#039;:{&#039;cup&#039;:3, &#039;apples&#039;:2}, 
&#039;Jim&#039;:{&#039;cup&#039;:6, &#039;pies&#039;:7}
}

def  tho(guess, item):
    num = 0
    for k, v in the.items():
        num += v.get(item, 0)
        print(&#039;k的值:&#039;, k)
        print(&quot;v的值:&quot;, v)
    return num

print(&#039;Number of things being brought:&#039;)
print(&#039;- apples &#039;+str(tho(the, &#039;apples&#039;)))
print(&#039;- cup &#039; +str(tho(the, &#039;cup&#039;)))
print(&#039;- pies &#039;+str(tho(the, &#039;pies&#039;)))

</description>
</item>
<item rdf:about="https://eblog.ink/archives/203/">
<title>Python 列表</title>
<link>https://eblog.ink/archives/203/</link>
<dc:date>2019-07-10T02:18:00+00:00</dc:date>
<description>列表应用例子：1.打印出家里所有猫的名字catname=[]
while True:
    print(&quot;输入第&quot;+str(len(catname)+1)+&#039;只猫的名字&#039;+&#039;(或者不输入直接回车结束.)：&#039;)
    name = input()
    if name == &quot;&quot;:
        break
    catname = catname+[name]
print(&quot;The cat names are：&quot; ,name)
i=0
for name in catname:
    i+=1
    print(&#039;第&#039;+str(i) +&quot;只猫的名字是：&quot;+name)
2.用循环列表打印出：for i in [1,2,3,4,5]:
    print(i)
3.列表中in的使用spam = [&#039;a&#039;,&#039;b&#039;,&#039;c&#039;,&#039;d&#039;]
while True:
    print(&#039;输入字母：&#039;)
    name = input()
    if name in spam:
        print(&quot;你输入的字母在列表中为：&quot;,name)
        break
    else:
        print(&#039;你输入的字母不在列表中。&#039;)
4.列表中not in的使用spam = [&#039;a&#039;,&#039;b&#039;,&#039;c&#039;,&#039;d&#039;]
i=0
while True:
    i+=1
    print(&#039;输入字母：&#039;)
    name = input()
    if name not in spam:
        print(&#039;你输入的字母不在列表中&#039;)
        continue
    else:
        print(&#039;你输入的字母在列表中为：&#039;,name)
        break
print(&#039;您使用了&#039;+str(i)+&#039;次猜中了列表中数字&#039;)
5.增强赋值for i in range(5):
    i +=1
    print(i)
    k=7
    k -=1
    print(k)
    j =2
    j +=1
    j*=2
    print(j)
    l=10
    l +=1
    l /=2
    print(l)
    m=15
    m +=1
    m%=2
    print(m)
    print(&#039;\n&#039;)
6.列表中index查找索引位置spam = [&#039;a&#039;,&#039;b&#039;,&#039;c&#039;,&#039;d&#039;]
for i in range(1, 7):
    print(&#039;输入26个字母中的1个：&#039;)
    mu = input()
    if mu in spam:
        print(&#039;您输入的&#039;+mu+&#039;在列表中的&#039;+str(spam.index(mu)+1)+&quot;位置&quot;)
        break
    else:
        print(&quot;您输入的字母不在列表中&quot;)
if 0&lt;i&lt;6:
    print(&#039;您使用了&#039;+str(i)+&#039;次机会&#039;)
else:
    print(&#039;您的6次机会已使用完&#039;)
7.列表append添加值spam = [&#039;a&#039;,&#039;b&#039;,&#039;c&#039;,&#039;d&#039;]
for i in range(len(spam)):
    print(&#039;请输入第&#039;+str(i+1)+&#039;次需要添加的字母：&#039;,end=&#039; &#039;)
    mu = input()
    if mu != &quot;j&quot;:
        spam.append(mu)
    elif mu == &#039;j&#039;:
        print(&#039;输入了错误的J&#039;)
        break
print(spam)
8.insert指定位置插入import random
spam = [&#039;a&#039;,&#039;b&#039;,&#039;c&#039;,&#039;d&#039;]
i = 1
while True:
    if i &lt; 11:
        k = random.randint(0,4)
        print(&quot;输出第&quot;+str(i)+&quot;次k的值：&quot;,k)
        mu = input(&#039;请输入需要添加的字母：&#039;)
        spam.insert(k,mu)
        
    else:
        break
    i +=1
print(&quot;打印出现在的spam：&quot;,spam)

9.remove()删除列表中的元素
spam = [&#039;a&#039;,&#039;b&#039;,&#039;c&#039;,&#039;d&#039;,&#039;a&#039;,&#039;b&#039;,&#039;c&#039;,&#039;d&#039;,&#039;a&#039;]
print(&quot;打印出现在的spam值：&quot;,spam)
for i in range(10):
    k=input(&#039;请输入需要删除的abcd中的一个字母&#039;)
    try:
        spam.remove(k)
        print(&quot;打印出删除过后的spam的值：&quot;,spam)
    except ValueError:
        print(&#039;列表中没有该元素了。&#039;,spam)
10.sort对列表排序spam = []
for i in range(7):
    print(&#039;请给列表添加数字：&#039;,end=&#039;&#039;)
    j = int(input())
    if j != 99:
        spam.append(j)
    elif j == 99:
        print(&#039;输入了错误的数字：99&#039;)
        break
try:
    print(&quot;打印出已知的列表&quot;,spam)
    spam.sort(reverse=False)
    print(&#039;输出升序值&#039;,spam)
    spam.sort(reverse=True)
    print(&#039;输入降序值&#039;,spam)
except TypeError:
    print(&quot;你的列表是数字和字母混合，不能排序&quot;)
11.可变和不可变的数据类型name = &#039;Zophie a cat&#039;
print(&#039;输出name：&#039;,name)
newname =name[0:7]+&#039;the&#039;+name[8:12]
print(&quot;newname =name[0:7]+&#039;the&#039;+name[8:12]&quot;)
print(&#039;输出newname：&#039;,newname)

print(&#039;改变id&#039;)
eggs=[1,2,3]
print(id(eggs))
eggs=[4,5,6]
print(id(eggs))

print(&#039;不改变id&#039;)
egg=[1,2,3]
print(id(egg))
del egg[2]
del egg[1]
del egg[0]
egg.append(4)
egg.append(5)
egg.append(6)
print(id(egg))
12.元组数据类型eggs = (&#039;hello&#039;,42,0.5)
print(&#039;输出eggs[ 0]：&#039;,eggs[0])
print(&#039;输出eggs[1:3]：&#039;,eggs[1:3])
print(&#039;计算eggs的长度：&#039;,len(eggs))
13.list,tuple数据类型的相互转换
tuple1=(1,2,4,6)
list1 =[4,5,6,7]

print(&#039;打印转换前的tuple1：&#039;,tuple1)
print(&#039;打印转换后的tuple1：&#039;,list(tuple1))
print(&#039;打印转换前的list1：&#039;,list1)
print(&#039;打印转换前的list1：&#039;,tuple(list1))
14.引用s = 42
while True:
    c=s
    s = 100
    print(&quot;输出s：&quot;,s,id(s))
    print(&quot;输出c：&quot;,c,id(c))
    break

sp = [0,1,2,3,4]
che =sp

print(&#039;sp的值为：&#039;,sp)
print(&#039;che的值为：&#039;,che)
while True:
    print(&#039;输入判断值0或者1：&#039;,end=&#039; &#039;)
    j = int(input())
    if j == 0:
        k =input(&#039;输出需要改变的值：&#039;)
        che[0]=k
        print(&#039;输出修改che[0]后che的值：&#039;,che,id(che))
        print(&#039;输出修改che[0]后sp的值：&#039;,sp,id(sp))
        break
    elif j == 1:
        k =input(&#039;输出需要改变的值：&#039;)
        sp[0]=k
        print(&#039;输出修改che[0]后che的值：&#039;,che,id(che))
        print(&#039;输出修改che[0]后sp的值：&#039;,sp,id(sp))
        break
    else:
        print(&#039;请输入0或者1&#039;)
        continue
15.传递引用def egg(some):
    some.append(&#039;hello&#039;)
spam = [1,2,3,4]
egg(spam)
print(spam)
16.copy模块import copy
spam= [1,&#039;A&#039;,3,4,5]
cheese = copy.copy(spam)
cheese[1] = 2
print(&#039;输出spam的列表和ID：&#039;,spam,id(spam))
print(&#039;输出cheese的列表和ID：&#039;,cheese,id(cheese))



</description>
</item>
</rdf:RDF>