小编af3*_*3ld的帖子

访问传递给argparser参数的选项?

是否有可能访问传递给参数的选择元组?如果是这样,我该怎么做呢

例如,如果我有

parser = argparse.ArgumentParser(description='choose location')
parser.add_argument(
    "--location",
    choices=('here', 'there', 'anywhere')
)
args = parser.parse_args()
Run Code Online (Sandbox Code Playgroud)

我可以访问元组('here', 'there', 'anywhere')吗?

python argparse

7
推荐指数
1
解决办法
394
查看次数

Python:在doctests中接受unicode字符串作为常规字符串

编写doctests,用于通过在原始字典的键中搜索传递的关键字来缩写字典,并返回新的缩写字典.我的docstring看起来如下:

def abbreviate_dict(key_word, original_dict):
    """
    >>> orig_dict = {apple_stems: 2, apple_cores: 5, apple_seeds: 3}
    >>> abbreviate_dict('apple', orig_dict)
    {'cores': 5, 'seeds': 3, 'stems': 2}
    """
   etc.
   return new_dict
Run Code Online (Sandbox Code Playgroud)

该函数有效,但是当我运行py.test的doctest时,该函数未通过测试,因为它将字符串作为unicode返回.我没有以编程方式将字符串切换到我的函数中的unicode,但我知道python 2.7在unicode中返回.

Expected:
    {'cores': 5, 'seeds': 3, 'stems': 2}
Got:
    {u'cores': 5, u'seeds': 3, u'stems': 2}
Run Code Online (Sandbox Code Playgroud)

我怎样才能获得doctest以确认unicode和常规字符串输出是否相同?

python testing doctest pytest python-2.7

6
推荐指数
1
解决办法
147
查看次数

Python:获取智能表单的最佳方式

我想通过Smartsheet api找到一张纸,我所拥有的就是纸张的名称.我现在正在解决这个问题

sheet_name = 'The sheet I have the name of'
sheets = ss_client.Sheets.list_sheets(include_all=True).data
sheet_id = next(sheet.id for sheet in sheets if sheet.name == sheet_name)

sheet_that_I_want = ss_client.Sheets.get_sheet(sheet_id)
Run Code Online (Sandbox Code Playgroud)

有一个get_sheet方法,但它基于工作表的id.我觉得必须有更直接的方法来做到这一点,但我不确定它会是什么.

python smartsheet-api

1
推荐指数
1
解决办法
207
查看次数

为什么我的sizeof(arr)/ sizeof(arr [0])= 1?

typedef struct {
  double *x;
  int points;
} Polygon;



polygon[cc].points = readobject(polygon[cc].file); //lets say equals 15
polygon[cc].x = (double *) malloc(polygon[cc].points * sizeof(double));

printf("%d\n", sizeof(polygon[cc].x) / sizeof(polygon[cc].x[0]));
//This prints out on 1
Run Code Online (Sandbox Code Playgroud)

我测试初始化xx[100],然后它工作,但不应该malloc()调用设置结构的数组x[15]?它只是测量两个doubles 的字节吗?

c arrays malloc struct pointers

0
推荐指数
1
解决办法
97
查看次数