python外部命令传参(笔记)

方法一:命令行的参数是不可或缺的,之前在paddle的代码里看到python的命令行参数的自定义,通过click的import,Click 支持对 command 方法添加自定义的参数,由 option() 和 argument() 装饰器实现。先记下这个笔记,方便未来使用。

方法二:通过sys.argv[],从外部传参,可以从外部取得的多个参数,所以获得的是一个列表(list),也就是说sys.argv其实可以看作是一个列表,所以才能用[]提取其中的元素。其第一个元素是程序本身,随后才依次是外部给予的参数。


## Loading data ......
try:
    edges_file = sys.argv[1]  # enter the path of the edges
    community_file = sys.argv[2]  # enter  the path of the community
    topk=sys.argv[3]               # enter the top depand what you need
except :
    print("Please enter the args when you run it,which has to contain the path of edges and community and the topk,then try again~")


A_mat = load_adj_matrix(edges_file)              #######
gdclus, cluster_dict = load_labels(community_file)          #######
ground_truth_labels = list(gdclus.values())

## Algorithm: Harmonic Modularity (HAM)
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值