一旦Boost库(我已经读过十个Boost库被认为是标准库的一部分)成为标准库的一部分 - 它是否会保留它的boost命名空间或代码最终会在std命名空间中?
如果是后者 - 你将如何解决代码中潜在的命名空间冲突.
干杯.
我试图在运行时确定对象的大小.sizeof不起作用,因为它在编译时返回大小.这是我的意思的一个例子:
class Foo
{
public:
Foo()
{
c = new char[1024*1024*1024];
}
~Foo()
{
delete[] c;
}
private:
char *c;
};
Run Code Online (Sandbox Code Playgroud)
在这种情况下,sizeof(Foo)
将是4个字节而不是〜1GB.如何在运行时确定Foo的大小?提前致谢.
我是蟒蛇的新人.
如果logging.info()
足以进行日志记录,为什么我们必须使用getLogger()
方法实例化记录器?
我有这个可证明的代码:
#include <cstdlib>
#include <cstdio>
int main() {
int ** matrix = NULL;
int c = 1, input = 0;
printf("Enter first row of the matrix:\n");
while (!feof(stdin)) {
input = fgetc(stdin);
matrix = (int**) realloc(matrix, 1 * sizeof (int*));
if (matrix == NULL) {
printf("Troubles with memory allocation!\n");
return 0;
}
matrix[0] = (int *) realloc(matrix[0], c * sizeof (int));
matrix[0][c-1] = (int) input;
c++;
}
free(matrix[0]);
free(matrix);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这导致Valgrind出错,但我真的不知道这是什么意思以及如何解决它......任何人都可以给我一个建议吗?
==30031== 1 errors in context 1 of …
Run Code Online (Sandbox Code Playgroud) 出于某种原因,我无法使用boost::format
的boost::lambda
.这是(希望)可编译的代码简化:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <boost/assign/list_of.hpp>
#include <boost/format.hpp>
#include <boost/lambda/lambda.hpp>
namespace bl = boost::lambda;
int main()
{
const std::vector<int> v = boost::assign::list_of(1)(2)(3);
std::for_each(v.begin(), v.end(), bl::var(std::cout) << std::setw(10) << bl::_1);
std::for_each(v.begin(), v.end(), bl::var(std::cout) << boost::format("%10d") % bl::_1);
}
Run Code Online (Sandbox Code Playgroud)
std::for_each
产生预期的输出std::for_each
只输出没有任何数字的空格这是为什么 ?我真的不熟悉boost::lambda
所以我可能会错过这里明显的.
请不要建议std::copy
基于答案:我的实际代码不起作用,std::vector
但实际上是boost::fusion::vector
(并且std::for_each
实际上是a boost::fusion::for_each
).
我需要编写一个正则表达式,只允许正数(整数或小数).我发现了这个:
/^(?!(?:0|0\.0|0\.00)$)[+]?\d+(\.\d|\.\d[0-9])?$/
Run Code Online (Sandbox Code Playgroud)
但它只接受最多2位小数.我必须做出哪些更改,以便它可以接受任意数量的小数位?
在哪里可以找到学习正则表达式的好教程.
先谢谢
最近,我发现''.format
函数非常有用,因为与%
格式化相比,它可以提高可读性.试图实现简单的字符串格式化:
data = {'year':2012, 'month':'april', 'location': 'q2dm1'}
year = 2012
month = 'april'
location = 'q2dm1'
a = "year: {year}, month: {month}, location: {location}"
print a.format(data)
print a.format(year=year, month=month, location=location)
print a.format(year, month, location)
Run Code Online (Sandbox Code Playgroud)
虽然两个第一次打印的格式符合我的预期(是的,something=something
看起来很难看,但这只是一个例子),最后一个会提高KeyError: 'year'
.在python中有没有创建字典的技巧,所以它会自动填充键和值,例如somefunc(year, month, location)
输出{'year':year, 'month': month, 'location': location}
?
我是python的新手,无法找到关于这个主题的任何信息,但是像这样的技巧会大大改善和缩小我当前的代码.
提前谢谢并原谅我的英语.
我希望post_mortem()
在遇到异常时让我的调试器运行,而不必修改我正在处理的源.我看到很多例子涉及在try/except块中包装代码,但我想让它始终运行,无论我在做什么.
我研究了一个python包装器脚本,但是它变得丑陋且几乎无法使用.
我使用pudb,它与pdb的API等价,所以pdb特定的答案很好.我在我的编辑器(vim)中运行代码,并希望在遇到异常时让pm出现.
我有一个关于引用集合子集的快速问题.考虑我有一个对象矢量.现在我想创建另一个向量,它是此向量的子集,我不想创建对象子集的副本.
我正在考虑的方法之一是创建一个vector<auto_ptr<MyClass> >
.这是一个好方法吗?如果您认为在这种情况下任何其他容器或习语或模式会有所帮助,请建议.谢谢
这是我的工作代码:
from scrapy.item import Item, Field
class Test2Item(Item):
title = Field()
from scrapy.http import Request
from scrapy.conf import settings
from scrapy.selector import HtmlXPathSelector
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.contrib.spiders import CrawlSpider, Rule
class Khmer24Spider(CrawlSpider):
name = 'khmer24'
allowed_domains = ['www.khmer24.com']
start_urls = ['http://www.khmer24.com/']
USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.97 Safari/537.22 AlexaToolbar/alxg-3.1"
DOWNLOAD_DELAY = 2
rules = (
Rule(SgmlLinkExtractor(allow=r'ad/.+/67-\d+\.html'), callback='parse_item', follow=True),
)
def parse_item(self, response):
hxs = HtmlXPathSelector(response)
i = Test2Item()
i['title'] = (hxs.select(('//div[@class="innerbox"]/h1/text()')).extract()[0]).strip(' \t\n\r') …
Run Code Online (Sandbox Code Playgroud) c++ ×5
python ×4
auto-ptr ×1
boost ×1
boost-format ×1
boost-lambda ×1
c++11 ×1
dictionary ×1
formatting ×1
logging ×1
memory ×1
pdb ×1
pudb ×1
regex ×1
runtime ×1
scrapy ×1
standards ×1
string ×1
valgrind ×1
vim ×1