是否可以在列表中传递"__ contains __"函数多个参数?我想检查列表中至少有一个项目是否存在于不同的列表中.
例如:[0,1,4,8,87,6,4,7,5,'a','f','er','fa','vz']
我想检查其中一个项目(8,5,'f')是否在该列表中.
我该怎么做?
我有以下logger类(作为logger.py):
import logging, logging.handlers
import config
log = logging.getLogger('myLog')
def start():
"Function sets up the logging environment."
log.setLevel(logging.DEBUG)
formatter = logging.Formatter(fmt='%(asctime)s [%(levelname)s] %(message)s', datefmt='%d-%m-%y %H:%M:%S')
if config.logfile_enable:
filehandler = logging.handlers.RotatingFileHandler(config.logfile_name, maxBytes=config.logfile_maxsize,backupCount=config.logfile_backupCount)
filehandler.setLevel(logging.DEBUG)
filehandler.setFormatter(formatter)
log.addHandler(filehandler)
console = logging.StreamHandler()
console.setLevel(logging.DEBUG)
console.setFormatter(logging.Formatter('[%(levelname)s] %(message)s')) # nicer format for console
log.addHandler(console)
# Levels are: debug, info, warning, error, critical.
log.debug("Started logging to %s [maxBytes: %d, backupCount: %d]" % (config.logfile_name, config.logfile_maxsize, config.logfile_backupCount))
def stop():
"Function closes and cleans up the logging environment."
logging.shutdown()
Run Code Online (Sandbox Code Playgroud)
对于日志记录,我启动 …
这真的不应该这么难,但由于某种原因我似乎无法得到它.
我试图在我的查询上运行一个过滤器,用于比较今天和明年第一天之间的日期范围.
今天获得是没有问题的,但我似乎无法在明年的第一天获得.我希望能够为自己提供2013年1月1日
到目前为止,这是我的过滤器:
cur_il = Investment.objects.all().filter(plan = plan).order_by('financial_institution').filter(maturity_date__range=[now, nextyear])
Run Code Online (Sandbox Code Playgroud)
显然我用它来得到今天的日期:
now = datetime.now()
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得下一次约会?
假设我有这两个正则表达式:
id=123456discography=True如何在不事先知道输入中这些字符串的顺序的情况下检查它们是否都匹配正则表达式?
我的实际例子比较复杂,所以我将这个概念简化为一个简单的例子:
l = [1,2,3,4,5,6,7,8]
for number in l:
calc = number*10
print calc
Run Code Online (Sandbox Code Playgroud)
对于我的循环的每次迭代,我最终得到一个变量(calc)我想用来填充一个新的列表.我的实际过程涉及的不仅仅是乘以值10,因此我希望能够通过此方法设置新列表中的每个值.新代码可能如下所示:
l = [1,2,3,4,5,6,7,8]
for number in l:
calc = number*10
set calc as x'th entry in a new list called l2 (x = iteration cycle)
print l2
Run Code Online (Sandbox Code Playgroud)
然后它将打印新列表: [10,20,30,40,...]
让我们假设我们有以下代码:
abstract class Base1 {
protected int num;
}
class Der1:Base1 {
protected Color color;
protected string name;
}
class Der2:Base1 {
protected DateTime dthen;
}
Run Code Online (Sandbox Code Playgroud)
等等.base1存在一个类型数组,包括从派生自的类创建的许多对象base1.
是否可以toString()仅在基类中定义方法?就像是:
public override string toString()
{
if (this is Der1)
return "num = " + this.num + "color = " + this.color.toString() + " name = " this.name;
if (this is Der2)
return "num = " + this.num + "dthen = " + this.dthen.toString();
// and so …Run Code Online (Sandbox Code Playgroud) 我想运行几个接收器,它们将在不同的端口接收数据,但基本相同.什么更适合性能方面 - 多线程或多处理?
我有一个列表,看起来像这样:
data = [
[u'2012-10-31', '20', 9801, '0', '0', '0', '0'],
[u'2012-10-31', '21', 9266, '0', '0', '0', '0'],
[u'2012-10-31', '22', 10526, '0', '0', '0', '0'],
[u'2012-10-31', '23', 9570, '0', '0', '0', '0'],
[u'2012-10-31', '1', 5256, '0', '0', '0', '0'],
[u'2012-10-31', '0', 5020, '0', '0', '0', '0'],
# and so on...
]
Run Code Online (Sandbox Code Playgroud)
我需要先按日期排序,这是索引0和小时是索引1.如何在python中进行排序?