相关疑难解决方法(0)

如何在python 3中将二进制数据写入stdout?

在python 2.x中,我可以这样做:

import sys, array
a = array.array('B', range(100))
a.tofile(sys.stdout)
Run Code Online (Sandbox Code Playgroud)

然而,现在,我得到了一个TypeError: can't write bytes to text stream.我应该使用一些秘密编码吗?

python python-3.x

88
推荐指数
3
解决办法
4万
查看次数

C和ncurses中的ANSI颜色

我知道我可以做的attron,并attroff与我选择的颜色,但是,我想知道是否有可能与ncurses的内ANSI颜色转义符来做到这一点:

#include <stdio.h>
#include <ncurses.h>

int main()
{
   initscr();
   char *s2 = NULL;
   const char *s1 = "World";
   int n = 10; 

   // What would be a good way to colour %d?
   // seems it is not safe to us the ANSI color escape in here...
   s2 = malloc (snprintf (NULL, 0, "Hello %s \033[22;31m%d", s1, n) + 2); 
   sprintf (s2, "Hello %s \033[22;31m%d", s1, n); 
   printw("%s", s2);
   refresh();
   getch();
   endwin();

   return 0;
}
Run Code Online (Sandbox Code Playgroud)

与...联系 -lncurses …

c colors ncurses

5
推荐指数
1
解决办法
2899
查看次数

标签 统计

c ×1

colors ×1

ncurses ×1

python ×1

python-3.x ×1