我的团队开始使用 doxygen 记录我们的 C 代码,特别关注我们的公共 API 标头。doxygen 中似乎有很多灵活性和不同的特殊命令,这很棒,但如果没有反复试验,就不清楚什么是好事,什么是坏事。
您最喜欢的标记代码的方式是什么?您必须做什么和不应该做什么?
请提供您的重要提示,每个答案一个,以方便投票。
我希望定义 API 文档的整个方法,包括提供一个模板来让团队的其他成员开始。到目前为止我有这样的事情:
/**
* @file example_action.h
* @Author Me (me@example.com)
* @date September, 2008
* @brief Brief description of file.
*
* Detailed description of file.
*/
/**
* @name Example API Actions
* @brief Example actions available.
* @ingroup example
*
* This API provides certain actions as an example.
*
* @param [in] repeat Number of times to do nothing.
*
* @retval TRUE Successfully did nothing. …Run Code Online (Sandbox Code Playgroud) 我不理解pep-0404的以下内容
在Python 3中,包中的隐式相对导入不再可用 - 仅支持绝对导入和显式相对导入.此外,星型导入(例如来自x import*)仅允许在模块级代码中使用.
什么是相对进口?在python2中允许星形导入的其他地方?请举例说明.
如何创建适合在坩埚中检查的补丁?
git diff branch master --no-prefix > patch
Run Code Online (Sandbox Code Playgroud)
这只产生3行上下文.所以我做了以下几点
git diff --unified=2000 branch master --no-prefix > patch
Run Code Online (Sandbox Code Playgroud)
希望所有文件都少于2000行.有没有办法告诉git包含补丁文件中的所有行而不必指定最大行?
我有一个像下面的装饰.
def myDecorator(test_func):
return callSomeWrapper(test_func)
def callSomeWrapper(test_func):
return test_func
@myDecorator
def someFunc():
print 'hello'
Run Code Online (Sandbox Code Playgroud)
我想增强这个装饰器来接受另一个如下所示的参数
def myDecorator(test_func,logIt):
if logIt:
print "Calling Function: " + test_func.__name__
return callSomeWrapper(test_func)
@myDecorator(False)
def someFunc():
print 'Hello'
Run Code Online (Sandbox Code Playgroud)
但是这段代码给出了错误,
TypeError:myDecorator()只需要2个参数(给定1个)
为什么函数不会自动通过?如何将函数显式传递给装饰器函数?
考虑以下python2代码
In [5]: points = [ (1,2), (2,3)]
In [6]: min(points, key=lambda (x, y): (x*x + y*y))
Out[6]: (1, 2)
Run Code Online (Sandbox Code Playgroud)
这在python3中不受支持,我必须执行以下操作:
>>> min(points, key=lambda p: p[0]*p[0] + p[1]*p[1])
(1, 2)
Run Code Online (Sandbox Code Playgroud)
这非常难看.如果lambda是一个函数,我可以做
def some_name_to_think_of(p):
x, y = p
return x*x + y*y
Run Code Online (Sandbox Code Playgroud)
在python3中删除此功能会强制代码执行丑陋的方式(使用魔术索引)或创建不必要的函数(最令人烦恼的部分是为这些不必要的函数考虑好名称)
我认为该功能至少应该添加到lambdas中.有没有好的选择?
更新:我正在使用以下助手扩展答案中的想法
def star(f):
return lambda args: f(*args)
min(points, key=star(lambda x,y: (x*x + y*y))
Run Code Online (Sandbox Code Playgroud)
Update2:更清洁版star
import functools
def star(f):
@functools.wraps(f):
def f_inner(args):
return f(*args)
return f_inner
Run Code Online (Sandbox Code Playgroud) 我看到python 3.2在functools库中有memoization作为装饰器. http://docs.python.org/py3k/library/functools.html#functools.lru_cache
不幸的是,它尚未向后移植到2.7.是否有任何具体原因导致它在2.7中不可用?是否有任何第三方图书馆提供相同的功能,还是应该自己编写?
我使用vim进行编码.当我必须编译当前文件时,目前我使用:!g++ % && ./a.out或:make.当我按回车键并返回文件时,显示的错误/输出消失了.我希望错误和输出显示在旁边的垂直分割中.如果输出和错误流在不同的缓冲区中会很好.如何才能做到这一点?我再次编译时应该更新错误和输出缓冲区,它不应该创建新的缓冲区.怎么办呢?一些vim插件/功能?还是一个oneliner:P?
[me@hostname python]$ cat hello_world.cc
#include <string>
#include <Python.h>
#include <boost/python.hpp>
namespace {
std::string greet() { return "Helloworld"; }
}
using namespace boost::python;
BOOST_PYTHON_MODULE(hello_world)
{
def("greet",greet);
}
[me@hostnmae python]$ g++ -c -fPIC hello_world.cc -I/path/to/boost/headers -I/path/to/python/headers -o hello_world.o
[me@hostname python]$ g++ -shared -Wl,-soname,libhello_world.so -o libhello_world.so hello_world.o
[me@hostname python]$ python
Python 2.7.1 (r271:86832, Jan 10 2011, 09:46:57)
[GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append('.')
>>> import hello_world
Traceback …Run Code Online (Sandbox Code Playgroud) 我想传递类似于成员函数指针的东西.我尝试了以下内容.
class dummy:
def func1(self,name):
print 'hello %s' % name
def func2(self,name):
print 'hi %s' % name
def greet(f,name):
d = getSomeDummy()
d.f(name)
greet(dummy.func1,'Bala')
Run Code Online (Sandbox Code Playgroud)
预期的产出是 hello Bala
考虑以下列表理解
[ (x,f(x)) for x in iterable if f(x) ]
Run Code Online (Sandbox Code Playgroud)
这将根据条件过滤可迭代f并返回对x,f(x).这种方法的问题f(x)是计算两次.如果我们可以这样写,那就太好了
[ (x,fx) for x in iterable if fx where fx = f(x) ]
or
[ (x,fx) for x in iterable if fx with f(x) as fx ]
Run Code Online (Sandbox Code Playgroud)
但是在python中我们必须使用嵌套的理解来编写,以避免重复调用f(x),这使得理解看起来不那么清晰
[ (x,fx) for x,fx in ( (y,f(y) for y in iterable ) if fx ]
Run Code Online (Sandbox Code Playgroud)
有没有其他方法可以使它更加pythonic和可读?
更新
即将推出的python 3.8!PEP
# Share a subexpression between a comprehension filter clause and its output
filtered_data = [y …Run Code Online (Sandbox Code Playgroud) python list-comprehension python-3.x python-3.8 python-assignment-expression
python ×7
python-2.7 ×3
python-3.x ×3
c++ ×2
boost-python ×1
c ×1
diff ×1
doxygen ×1
git ×1
git-diff ×1
ide ×1
memoization ×1
python-3.8 ×1
python-assignment-expression ×1
vim ×1