Chinaunix首页 | 论坛 | 博客
  • 博客访问: 255502
  • 博文数量: 54
  • 博客积分: 1761
  • 博客等级: 上尉
  • 技术积分: 585
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-17 23:30
文章分类

全部博文(54)

文章存档

2013年(4)

2012年(7)

2011年(15)

2010年(28)

分类: Python/Ruby

2012-07-02 18:56:07

问题1:需要传递一个列表中的所有元素给对象或者方法作为参数?

处理datetime这类方法的时候往往非常头疼。要想生成datetime对象,往往需要传递多个参数。 而实际中的情况是你的参数保存在一个列表中。

例如

点击(此处)折叠或打开

  1. l=[2012,5,12,5,30,20]
  2. d=datetime(l[0],l[1]....)
python的apply方法可以解决这个问题。

点击(此处)折叠或打开

  1. apply(datetime,l)

  2. apply(object[, args[, kwargs]]) -> value

  3. Call a callable object with positional arguments taken from the tuple args,
  4. and keyword arguments taken from the optional dictionary kwargs.
  5. Note that classes are callable, as are instances with a __call__() method.

  6. Deprecated since release 2.3. Instead, use the extended call syntax:
  7.     function(*args, **keywords).


阅读(889) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~