目前我正在为linux系统编写一个文本编辑器,它可以执行一些涉及opengl渲染的特定文本/字体突出显示.有没有人有一个c ++图形渲染库的建议,适用于linux(特别是现在的ubuntu)?
并建议从哪里开始渲染3D文本非常感谢!
编辑:只是为了澄清渲染3d文本是项目的严格要求.
我只是改进了一个必须支持切片的库的测试覆盖率,我注意到切片可以包含非整数类型:
>>> slice(1, "2", 3.0)
slice(1, '2', 3.0)
>>> sl = slice(1, "2", 3.0)
>>> [1,2,3][sl]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: slice indices must be integers or None or have an __index__ method
Run Code Online (Sandbox Code Playgroud)
这可能只是我的静态输入背景,但对我来说,似乎很奇怪__index__没有a 的内置类型可以在这里传递TypeError.为什么会这样?我是否正确假设允许任意类型以支持实现类型的鸭子类型__index__?由于最常用案例的性能原因,是否缺乏类型检查?
在PEP 357之前,示例中的切片无效吗?
我在Python 3.6.0rc1中发现了使用隐式命名空间包的奇怪行为.你能告诉我,如果我错了或是Python 3.6的错误吗?
我正在使用命名空间包marrow,它有两个独立的包marrow.util和marrow.mailer.第二个取决于第一个.
假设我们已经marrow.util安装site-packages了Python 2.7,3.5和3.6:
$ ls -la /usr/lib/python*/site-packages/marrow
/usr/lib/python2.7/site-packages/marrow:
total 24
drwxr-xr-x. 3 root root 4096 Dec 23 12:23 .
drwxr-xr-x. 196 root root 16384 Dec 23 12:23 ..
drwxr-xr-x. 3 root root 4096 Dec 23 12:23 util
/usr/lib/python3.5/site-packages/marrow:
total 12
drwxr-xr-x. 3 root root 4096 Dec 23 12:24 .
drwxr-xr-x. 99 root root 4096 Dec 23 12:24 ..
drwxr-xr-x. 4 root root 4096 Dec 23 12:24 util …Run Code Online (Sandbox Code Playgroud) 目前我正在尝试从包含一些整数的向量生成组合。现在我希望它打印出所有长度为 to_generate 的组合。我在 C++中的组合和排列中发现了这段代码,它使用 std::next_permutation 来生成组合。next_combination 代码如下:
template<class RandIt, class Compare>
bool next_combination(RandIt first, RandIt mid, RandIt last, Compare comp)
{
std::sort(mid, last, std::tr1::bind(comp, std::tr1::placeholders::_2
, std::tr1::placeholders::_1));
return std::next_permutation(first, last, comp);
}
Run Code Online (Sandbox Code Playgroud)
我试着这样称呼它:
bool mycomp (int c1, int c2)
{ return (c1)<(c2); }
void test_combos(int to_generate){
std::vector<int> combo(30);
for(int i=0;i<30;++i){
combo.push_back(i);
}
while(next_combination<std::vector<int>::iterator, bool>(combo.begin(),combo.begin()+to_generate,combo.end(),mycomp)){
for(std::vector<int>::iterator iter = combo.begin(); iter != combo.end() ; ++iter){
std::cout << *iter << " ";
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我收到一条巨大的 stl 乱码错误消息。这里有什么明显的问题吗?
我可以找到哪些标头 …
我正在尝试使用我在另一台将字符串拆分为标记的计算机上编写的代码.这段代码编译得很好.该代码也可以在其他一些计算机上运行.我已设法将代码减少到以下内容:
#include <string>
#include <boost/regex.hpp>
typedef std::vector<std::string> token_t ;
token_t generate_tokens(std::string raw_input){
//this function breaks a input string into tokens. So test 100 goes to 2 tokens "test" and "100".
boost::regex re_splitter("\\s+"); //this uses the regex \s+ to find whitespace. The + finds one or more whitespace characters.
boost::sregex_token_iterator iter(raw_input.begin(), raw_input.end(), re_splitter, -1);
//this breaks the string using the regex re_splitter to split into tokens when that is found.
boost::sregex_token_iterator j; //This is actually in the Boost examples, j is …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用gcc4.6和glibc 2.13与xubuntu上的boost 1.47相关联.到目前为止我无法编译以下简单程序main.cpp:
#include <cstdlib>
#include <boost/ref.hpp>
#include <boost/thread.hpp>
int main() {
size_t n_threads = boost::thread::hardware_concurrency();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我编译时:
g++ -lboost_thread -lboost_regex -o mc main.cpp -static -lpthread /usr/local/lib/libboost_regex.a /usr/local/lib/libboost_thread.a
Run Code Online (Sandbox Code Playgroud)
我从boost中获得了一堆类似于以下内容的错误:
/usr/local/lib/libboost_thread.a(thread.o): In function `_ZN5boost9call_onceIPFvvEEEvRNS_9once_flagET_.constprop.100':
thread.cpp:(.text+0x47): undefined reference to `pthread_mutex_lock'
thread.cpp:(.text+0x73): undefined reference to `pthread_cond_wait'
thread.cpp:(.text+0xb9): undefined reference to `pthread_mutex_unlock'
thread.cpp:(.text+0xc8): undefined reference to `pthread_key_create'
thread.cpp:(.text+0xd2): undefined reference to `pthread_mutex_lock'
thread.cpp:(.text+0xf5): undefined reference to `pthread_cond_broadcast'
thread.cpp:(.text+0x10e): undefined reference to `pthread_mutex_unlock'
Run Code Online (Sandbox Code Playgroud)
并且:
/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/libgcc_eh.a(unwind-dw2.o): In function `uw_init_context_1':
(.text+0x20bd): undefined reference to `pthread_once' …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试将一些Scala代码移植到Python项目中,我遇到了以下一些Scala代码:
lazy val numNonZero = weights.filter { case (k,w) => w > 0 }.keys
Run Code Online (Sandbox Code Playgroud)
weights是一个非常长的项目元组列表及其相关的概率加权.经常在此列表中添加和删除元素,但检查有多少元素具有非零概率是相对罕见的.在我移植的代码中有一些其他罕见但昂贵的操作,似乎从使用中受益匪浅lazy val.做与Scala类似的最惯用的Python方法是什么lazy val?
我想使用一些生成器表达式作为一些昂贵的数据计算的属性.如果可能的话,我希望能够做到这样的事情:
class Test:
def __init__(self):
self.data = []
self.evens = (i for i in self.data if i % 2 == 0)
def __main__():
t = Test()
t.data = [1,2,3,4,5,6,7,8]
for item in t.evens:
print(item)
if __name__ == '__main__':
__main__()
Run Code Online (Sandbox Code Playgroud)
我希望看到这个打印输出,2 4 6 8但这没有输出.我在这里犯了一些简单的错误吗?
我想在这里做什么可能或我需要yield用来做这个?
我目前正在处理一些代码,这些代码在使用mmap对象的进程之间共享一些状态。用例是一堆进程,这些进程可以访问共享的mmap支持的阵列中的某些只读数据。其中一部分涉及对基础内存表示进行一些算术运算,我正在使用ctypes 来获取基础内存地址,就像在这个问题中一样。
我有一种情况,希望能够打开此mmap文件,使其仅由仅读取数据的进程读取。但是,当我这样做时,我不确定在这种情况下如何获取指针地址。以下是我所能解决的最接近此问题的最小示例:
import mmap
import ctypes
filename = "test"
with open(filename, 'rb+') as fd:
buf = mmap.mmap(fd.fileno(), 0)
int_pointer = ctypes.c_int.from_buffer(buf)
with open(filename, 'rb') as fd:
test_mmap_ro = mmap.mmap(
fd.fileno(), 0, access=mmap.ACCESS_READ,
)
int_pointer2 = ctypes.c_int.from_buffer(test_mmap_ro) #fails here
Run Code Online (Sandbox Code Playgroud)
在Python3上运行,此操作将失败:
TypeError: must be read-write buffer, not mmap.mmap
Run Code Online (Sandbox Code Playgroud)
尽管Python2给出了这一点:
TypeError: mmap can't modify a readonly memory map.
Run Code Online (Sandbox Code Playgroud)
鉴于我实际上想使用只读内存映射,我该怎么做?如果需要的话,我将更改为可写的mmap,但是如果有另一种方法可以,则我不希望这样做,因此,任何建议或解决方法都将不胜感激。
我目前正在尝试安装 Python 包作为 Docker 构建的一部分。此 Python 包使用 setup.cfg 来存储其依赖项的元数据。通过requirements.txt,我可以使用以下内容来缓存依赖项的安装:
\nCOPY requirements.txt /app\nRUN pip install -r requirements.txt\nRun Code Online (Sandbox Code Playgroud)\n但这段代码是一个可通过 pip 安装的 Python 包,它将依赖信息存储在 setup.cfg 中,目录结构如下:
\ntree -L 2 .\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 mypy.ini\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 README.md\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 setup.cfg\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 setup.py\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 src\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 lib\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 tox.ini\n\nRun Code Online (Sandbox Code Playgroud)\n然后安装如下:
\nCOPY common /deps/common\nRUN pip install file:///deps/common\nRun Code Online (Sandbox Code Playgroud)\n不幸的是,这不再缓存需求的安装,因此任何代码更改现在都必须每次都获取并重新安装 python 包依赖项。如何以 docker 可以理解的方式缓存 setup.cfg 指定的依赖安装?
\n