如何在iPython笔记本中调用用argparse编写的模块 [英] How to call module written with argparse in iPython notebook

查看:170
本文介绍了如何在iPython笔记本中调用用argparse编写的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将BioPython序列传递给 Ilya Stepanov实施的Ukkonen后缀树算法在iPython的笔记本环境中。我在argparse组件上遇到了绊脚石。

I am trying to pass BioPython sequences to Ilya Stepanov's implementation of Ukkonen's suffix tree algorithm in iPython's notebook environment. I am stumbling on the argparse component.

我以前从未直接与argparse打过交道。如何在不重写main()的情况下使用它?

I have never had to deal directly with argparse before. How can I use this without rewriting main()?

通过by,这篇Ukkonen算法的写法很棒

推荐答案

我之前有类似的问题,但是使用 optparse 而不是 argparse

I've had a similar problem before, but using optparse instead of argparse.

您无需更改原始脚本中的任何内容,只需将新列表分配给 sys.argv ,如下所示:

You don't need to change anything in the original script, just assign a new list to sys.argv like so:

if __name__ == "__main__":
    from Bio import SeqIO
    path = '/path/to/sequences.txt'
    sequences = [str(record.seq) for record in  SeqIO.parse(path, 'fasta')]
    sys.argv = ['-f'] + sequences
    main()

这篇关于如何在iPython笔记本中调用用argparse编写的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆