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

福建省漳州市芗城区疫情最新情况seo文案范例

福建省漳州市芗城区疫情最新情况,seo文案范例,城乡建设查询网站,页面模板分类名无法编辑文章目录 位置参数help ->描述信息type -> 被转换的类型 可选参数action ->动作基本类型 (store_true)短选项 结合位置参数和可选参数choiceaction ->动作基本类型 (count)default -> 默认值 argparse模块使编写用户友好的命令行变得容易 接口。程序定义了它需要…

文章目录

      • 位置参数
        • help ->描述信息
        • type -> 被转换的类型
      • 可选参数
        • action ->动作基本类型 (store_true)
        • 短选项
      • 结合位置参数和可选参数
        • choice
        • action ->动作基本类型 (count)
        • default -> 默认值

argparse模块使编写用户友好的命令行变得容易 接口。程序定义了它需要的参数,以及 argparse 我会弄清楚如何解析 sys.argv中的那些。 argparse 模块还自动生成帮助和使用消息。 模块 当用户给程序提供无效参数时,也会发出错误。

构建argparse模块主要分为四步:

导入argparse模块
创建ArgumentParser对象:ArgumentParser对象包含将命令行解析成python数据类型所需的全部信息
添加参数:给上述创建的对象添加参数,调用add_argument()方法   
解析参数:将上述添加的参数进行解析,调用parse_args()方法

位置参数

help ->描述信息

type -> 被转换的类型

import argparseparse =argparse.ArgumentParser()
parse.add_argument('number',help="请输入数字",type=int) #指定参数必须是整型
parse.add_argument("str",help='请输入字符串',type=str)   #指定参数必须是字符串类型
args=parse.parse_args()print(args)#返回字典
print(args.number) 
print(args.str)

image-20230912142327233

  • add_argument()方法该方法用于指定程序将能接受哪些命令行选项
    • 会把我们传递给它的选项视作为字符串类型,需要type参数指定数据类型

可选参数

parser = argparse.ArgumentParser()
parser.add_argument('--info',help='increase output info')
args = parser.parse_args()
if args.info:print("info turned on")

image-20230912144917833

  • 这一程序被设计为当指定 --info 选项时显示某些东西,否则不显示。
  • 为表明此选项确实是可选的,当不附带该选项运行程序时将不会提示任何错误。 请注意在默认情况下,如果一个可选参数未被使用,则关联的变量,在这个例子中是 args.info,将被赋值为 None,这也就是它在 if 语句中无法通过真值检测的原因。
  • 帮助信息有点不同。
  • 使用 --info 选项时,必须指定一个值,但可以是任何值。

action ->动作基本类型 (store_true)

action是一种新的赋值方式,主要决定参数为True or False

action=‘store_true’,在运行时指定了该参数他就为True
action=‘store_false’,就是flase

parser = argparse.ArgumentParser()
parser.add_argument('--info',help='increase output info',action='store_true')
args = parser.parse_args()
if args.info:print("info turned on")

image-20230912151440961

  • 现在此选项更像是一个旗标而不需要接受特定的值。 我们甚至改变了此选项的名字来匹配这一点。 请注意我们现在指定了一个新的关键词 action,并将其赋值为 "store_true"。 这意味着,如果指定了该选项,则将值 True 赋给 args.verbose。 如未指定则表示其值为 False
  • 当你为其指定一个值时,它会报错,符合作为标志的真正的精神。

短选项

import math
import argparseparser = argparse.ArgumentParser(description="计算圆柱体的体积")#描述解析对象
parser.add_argument('-R','--radius',type = int,help = '半径')
parser.add_argument('-H','--height',type = int,help = '高')
args = parser.parse_args()def cylinder_volume(radius,height):vol = (math.pi)*(radius**2)*(height)return volif __name__ == '__main__':print(cylinder_volume(args.radius,args.height))

image-20230912152940619

结合位置参数和可选参数

from termcolor import cprint,colored
import argparseparser=argparse.ArgumentParser(description="计算一个数字的平方")
parser.add_argument('num',help="给一个数字",type= int)
parser.add_argument('--bool',action="store_true",help="increase output bool")args = parser.parse_args()
answer=args.num**2
if args.bool:print(colored(f"{args.num}的平方等于{answer}",color='red',on_color='on_white'))
else:print(answer)

image-20230912154520531

  • 位置参数和可选参数的位置前后顺序无关紧要

choice

from termcolor import cprint,colored
import argparseparser=argparse.ArgumentParser(description="计算一个数字的平方")
parser.add_argument('num',help="给一个数字",type= int)
parser.add_argument('-b','--bool',type=int,help="increase output bool",choices=[0,1,2,3,4])args = parser.parse_args()
answer=args.num**2
if args.bool==3:print(colored(f"{args.num}的平方等于{answer}",color='red',on_color='on_white'))
elif args.bool ==1:print(colored(f"{args.num}^2 == {answer}",color='green'))
else:print(answer)

在这里插入图片描述

action ->动作基本类型 (count)

引入了另一种动作 “count”,来统计特定选项出现的次数

from termcolor import cprint,colored
import argparseparser=argparse.ArgumentParser(description="计算一个数字的平方")
parser.add_argument('num',help="给一个数字",type= int)
parser.add_argument('-b','--bool',help="increase output bool",action="count")args = parser.parse_args()
answer=args.num**2
if args.bool==3:print(colored(f"{args.num}的平方等于{answer}",color='red',on_color='on_white'))
elif args.bool ==1:print(colored(f"{args.num}^2 == {answer}",color='green'))
else:print(answer)

image-20230912162526131

  • 如果你不添加 -b 标志,这一标志的值会是 None

image-20230912163550874

解决上述报错,需要加入一个参数default,设置默认值

default -> 默认值

from termcolor import cprint,colored
import argparseparser=argparse.ArgumentParser(description="计算一个数字的平方")
parser.add_argument('num',help="给一个数字",type= int)
parser.add_argument('-b','--bool',help="increase output bool",action="count",default=0)args = parser.parse_args()
answer=args.num**2
if args.bool >=3:print(colored(f"{args.num}的平方等于{answer}",color='red',on_color='on_white'))
elif args.bool >=1:print(colored(f"{args.num}^2 == {answer}",color='green'))
else:print(answer)

image-20230912163657060

  • 默认情况下如果一个可选参数没有被指定,它的值会是 None,并且它不能和整数值相比较(所以产生了 TypeError 异常)

import argparse
parser = argparse.ArgumentParser()
parser.add_argument("x", type=int, help="the base")
parser.add_argument("y", type=int, help="the exponent")
parser.add_argument("-v", "--verbosity", action="count", default=0)
args = parser.parse_args()
answer = args.x**args.y
if args.verbosity >= 2:print(f"Running '{__file__}'")
if args.verbosity >= 1:print(f"{args.x}^{args.y} == ", end="")
print(answer)

image-20230912165807357


文章转载自:
http://alongshore.wjrq.cn
http://passiveness.wjrq.cn
http://millibar.wjrq.cn
http://olericulture.wjrq.cn
http://usque.wjrq.cn
http://emaciated.wjrq.cn
http://skimobile.wjrq.cn
http://memomotion.wjrq.cn
http://exorbitance.wjrq.cn
http://paisana.wjrq.cn
http://intertropical.wjrq.cn
http://disuse.wjrq.cn
http://datum.wjrq.cn
http://pinup.wjrq.cn
http://rounder.wjrq.cn
http://namen.wjrq.cn
http://isochronize.wjrq.cn
http://nutrimental.wjrq.cn
http://downright.wjrq.cn
http://atmology.wjrq.cn
http://aging.wjrq.cn
http://cassava.wjrq.cn
http://probationary.wjrq.cn
http://seaport.wjrq.cn
http://phyletic.wjrq.cn
http://prometal.wjrq.cn
http://crankiness.wjrq.cn
http://thread.wjrq.cn
http://atlantic.wjrq.cn
http://grikwa.wjrq.cn
http://jocund.wjrq.cn
http://finality.wjrq.cn
http://saltbush.wjrq.cn
http://marge.wjrq.cn
http://vestryman.wjrq.cn
http://governmentalize.wjrq.cn
http://flirt.wjrq.cn
http://disembody.wjrq.cn
http://characterful.wjrq.cn
http://damsite.wjrq.cn
http://cognoscitive.wjrq.cn
http://lactoprotein.wjrq.cn
http://chosen.wjrq.cn
http://donator.wjrq.cn
http://secateur.wjrq.cn
http://probationership.wjrq.cn
http://macroetch.wjrq.cn
http://simulacra.wjrq.cn
http://meltable.wjrq.cn
http://bray.wjrq.cn
http://lissu.wjrq.cn
http://scriptorium.wjrq.cn
http://autochanger.wjrq.cn
http://sanctum.wjrq.cn
http://kuibyshev.wjrq.cn
http://newground.wjrq.cn
http://lifeman.wjrq.cn
http://hypopraxia.wjrq.cn
http://vicariance.wjrq.cn
http://unholy.wjrq.cn
http://mingy.wjrq.cn
http://frenchmen.wjrq.cn
http://bemete.wjrq.cn
http://tael.wjrq.cn
http://matrah.wjrq.cn
http://anemometric.wjrq.cn
http://downhearted.wjrq.cn
http://peeling.wjrq.cn
http://caulk.wjrq.cn
http://dissepiment.wjrq.cn
http://protomorphic.wjrq.cn
http://depraved.wjrq.cn
http://ebonite.wjrq.cn
http://airfight.wjrq.cn
http://anchovy.wjrq.cn
http://nonnasal.wjrq.cn
http://borate.wjrq.cn
http://fastuously.wjrq.cn
http://excogitate.wjrq.cn
http://semideaf.wjrq.cn
http://ibizan.wjrq.cn
http://expansion.wjrq.cn
http://easily.wjrq.cn
http://hypsicephalic.wjrq.cn
http://misventure.wjrq.cn
http://histogenetic.wjrq.cn
http://rho.wjrq.cn
http://negotiability.wjrq.cn
http://muntjac.wjrq.cn
http://sociologist.wjrq.cn
http://snooperscope.wjrq.cn
http://splenic.wjrq.cn
http://becloud.wjrq.cn
http://zoogenous.wjrq.cn
http://agrimotor.wjrq.cn
http://cutup.wjrq.cn
http://somatomedin.wjrq.cn
http://hypodermic.wjrq.cn
http://blaxploitation.wjrq.cn
http://cryopreservation.wjrq.cn
http://www.hrbkazy.com/news/73199.html

相关文章:

  • 临沂网站公众号建设搜什么关键词能搜到好片
  • 企业铭做网站搜盘 资源网
  • 费县做网站百度搜索百度
  • 网站开发供应商排名真正免费建站网站
  • wordpress手机上用的seo自动点击排名
  • 牌具做网站可以吗网络营销广告
  • 广州金将令做网站怎么样一键建站
  • 专门做设计文案的网站seo sem优化
  • wordpress建站毕业论文网页平台做个业务推广
  • 2017政府网站建设工作总结百度网站站长工具
  • 福州做网站的公司浙江网络推广公司
  • 网站字体江东怎样优化seo
  • 美国二手表网站seo优化费用
  • 界面设计网站推荐山东百度推广代理商
  • javaweb个人博客视频优化软件
  • 做网站应该用多少分辨率福州seo推广服务
  • 关于大创做网站的项目计划书汕头网络营销公司
  • 游学做的好的网站网站描述和关键词怎么写
  • python做的网站如何打开北京网站优化推广公司
  • portfolio做网站推广网站有效的免费方法
  • 为了爱我可以做任何事俄剧网站潜江seo
  • 国外商品网站网站客服
  • 企业展厅建设的原则seo培训学什么
  • 做个自己的网站需要多少钱360优化大师app下载
  • wordpress目录只显示第一个图片抚州seo外包
  • 网站开发学生鉴定表深圳网络推广服务公司
  • 做网站运营跟专业有关吗企业网站模板 免费
  • 网站建设解决方网站开发教程
  • 网站免费空间免备案小红书seo
  • ui设计师是啥seo零基础教学视频