![](/img/trans.png)
[英]How to create a command line prompt that displays options next to integers and allows choosing an option using integer input?
[英]Printing options of the function in the command prompt line
我在知道我在哪個選項中運行函數時遇到了幾個問題,並且我想以某種方式實現該函數打印自己的參數。 我發現此問題相關,但是我嘗試了但沒有成功。 我試過的代碼:
def SharedData(list1, list2, list3, list4, list5, remove=False):
"""Do some magic"""
sets=list1[:]
#Magic happens
print len(sets) / float(len(list1)) * 100, "% of genes start are equal between the predictors from", *list1
使用此代碼,我想打印第一個參數的名稱。 因此,在命令行中,我知道如何應用此功能。 在運行此功能SharedData(glimmer, easygene, genemark, augustus, prodigal)
我想在終端提示符下閱讀如下內容:
30,000000 % of genes start are equal between the predictors from glimmer
我該如何實現?
您總是可以做兩件事:
就像是:
def printkwargs(func):
@functools.wraps(func)
def wrapper(**kwargs):
ret = func(**kwargs)
print ret, kwargs
return wrapper
@printkwargs
def SharedData(...):...
我沒有對此進行測試,但是應該可以
更新為包括* args:
def printkwargs(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
ret = func(*args, **kwargs)
print ret, args, kwargs
return wrapper
通過抓住當地人字典:
from copy import copy
def f(a, b, c):
l = copy(locals())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.