小编sda*_*aau的帖子

在Python 3中禁止/打印没有b'前缀的字节

只是发布这个,所以我可以稍后搜索它,因为它似乎总是让我感到困惑:

$ python3.2
Python 3.2 (r32:88445, Oct 20 2012, 14:09:50) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import curses
>>> print(curses.version)
b'2.2'
>>> print(str(curses.version))
b'2.2'
>>> print(curses.version.encode('utf-8'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'bytes' object has no attribute 'encode'
>>> print(str(curses.version).encode('utf-8'))
b"b'2.2'"
Run Code Online (Sandbox Code Playgroud)

问题:如何bytes在Python 3中打印二进制()字符串,没有b'前缀?

python string python-3.x

88
推荐指数
5
解决办法
7万
查看次数

Bash:在命令行上指定echo的环境变量?

请考虑以下代码段:

$ SOMEVAR=AAA
$ echo zzz $SOMEVAR zzz
zzz AAA zzz
Run Code Online (Sandbox Code Playgroud)

在这里,我设置$SOMEVARAAA第一线-当我赞同它的第二行,我得到的AAA内容符合市场预期.

但是,如果我尝试在同一命令行上指定变量echo:

$ SOMEVAR=BBB echo zzz $SOMEVAR zzz
zzz AAA zzz
Run Code Online (Sandbox Code Playgroud)

......我没有BBB按照我的预期得到 - 我得到旧值(AAA).

这是事情应该如何?如果是这样,那么为什么你可以指定变量LD_PRELOAD=/... program args ...并让它工作?我错过了什么?

bash environment-variables echo

83
推荐指数
5
解决办法
3万
查看次数

Linux:查找给定"原始"文件的所有符号链接?(反向'readlink')

请考虑以下命令行代码段:

$ cd /tmp/
$ mkdir dirA
$ mkdir dirB
$ echo "the contents of the 'original' file" > orig.file
$ ls -la orig.file 
-rw-r--r-- 1 $USER $USER 36 2010-12-26 00:57 orig.file

# create symlinks in dirA and dirB that point to /tmp/orig.file:

$ ln -s $(pwd)/orig.file $(pwd)/dirA/
$ ln -s $(pwd)/orig.file $(pwd)/dirB/lorig.file
$ ls -la dirA/ dirB/
dirA/:
total 44
drwxr-xr-x  2 $USER $USER  4096 2010-12-26 00:57 .
drwxrwxrwt 20 root          root          36864 2010-12-26 00:57 ..
lrwxrwxrwx  1 $USER …
Run Code Online (Sandbox Code Playgroud)

linux bash symlink reverse

49
推荐指数
3
解决办法
5万
查看次数

Linux: Screen desktop video capture over network, and VNC framerate

Sorry for the wall of text - TL;DR:

  • What is the framerate of VNC connection (in frames/sec) - or rather, who determines it: client or server?
  • Any other suggestions for desktop screen capture - but "correctly timecoded"/ with unjittered framerate (with a stable period); and with possibility to obtain it as uncompressed (or lossless) image sequence?

Briefly - I have a typical problem that I am faced with: I sometimes develop hardware, and want to record a video that shows …

linux vnc frame-rate screen-capture

30
推荐指数
1
解决办法
1万
查看次数

Graphviz:如何设置'默认'箭头样式?

考虑这个dot语言代码:

digraph graphname {
    subgraph clusterA {
        node [shape=plaintext,style=filled];
        1 -> 2 [arrowhead=normal,arrowtail=dot];
        2 -> 3 -> X2 -> 5;
        6;
        7;
        label = "A";
        color=blue
    }
}
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,只有1 -> 2连接将arrowhead=normal,arrowtail=dot应用样式; 所有其他箭头将是"默认"样式.

我的问题是 - 如何设置箭头样式(对于整个子图 - 或整个图形),而不必[arrowhead=normal,arrowtail=dot];在每个边连接旁边复制粘贴" "?

编辑:仅供参考 - 杰西答案不包含任何代码; 我写了那个片段并在这里占据了这个空间 - 由于不明原因,主持人将其从这里剪掉并粘贴到Jesse的答案中.

dot graphviz

29
推荐指数
2
解决办法
2万
查看次数

Linux上的二进制grep?

假设我生成了以下二进制文件:

# generate file:
python -c 'import sys;[sys.stdout.write(chr(i)) for i in (0,0,0,0,2,4,6,8,0,1,3,0,5,20)]' > mydata.bin

# get file size in bytes
stat -c '%s' mydata.bin

# 14
Run Code Online (Sandbox Code Playgroud)

并说,我想0x00使用类似grep的语法找到所有零()的位置.

 

到目前为止,我能做的最好的事情是:

$ hexdump -v -e "1/1 \" %02x\n\"" mydata.bin | grep -n '00'

1: 00
2: 00
3: 00
4: 00
9: 00
12: 00
Run Code Online (Sandbox Code Playgroud)

但是,这会隐式地将原始二进制文件中的每个字节转换为多字节ASCII表示,并在其上grep运行; 不完全是优化的主要例子:)

是否有类似grepLinux 的二进制文件?也可能是支持正则表达式语法的东西,也支持字节"字符" - 也就是说,我可以a(\x00*)b在'a'之间编写类似' '并匹配'零或更多'字节0的出现'(' 97)和'b'(98)?

编辑:上下文是我正在研究一个驱动程序,我捕获8位数据; 数据中出现问题,可能是千字节到兆字节,我想检查特定的签名及其出现的位置.(到目前为止,我正在使用千字节片段,所以优化并不重要 - 但如果我开始在兆字节长的捕获中得到一些错误,我需要分析那些,我的猜测是我想要更优化的东西:).特别是,我想要一些东西,我可以"grep"一个字节作为一个字符 - hexdump迫使我每个字节搜索字符串)

EDIT2:同样的问题,不同的论坛:) 通过二进制文件grepping一个字节序列 …

linux binary grep

28
推荐指数
5
解决办法
3万
查看次数

如何在GDB中自动打印每条执行的行,直到达到给定的断点?

我希望能够在GDB中设置一个断点,让它运行到那一点 - 并在此过程中,打印出已经"逐步完成"的行.

这是一个例子,基于这个带有a main和a函数的简单文件,每个都有两个断点:

$ cat > test.c <<EOF
#include "stdio.h"

int count=0;

void doFunction(void) {
  // two steps forward
  count += 2;
  // one step back
  count--;
}

int main(void) {
  // some pointless init commands;
  count = 1;
  count += 2;
  count = 0;
  //main loop
  while(1) {
    doFunction();
    printf("%d\n", count);
  }
}
EOF

$ gcc -g -Wall test.c -o test.exe
$ chmod +x test.exe
$ gdb -se test.exe
...
Reading symbols from /path/to/test.exe...done.
(gdb) b …
Run Code Online (Sandbox Code Playgroud)

c debugging automation gdb

26
推荐指数
2
解决办法
1万
查看次数

将PDF转换为CMYK(识别识别CMYK)

我很难将ImageMagick identify用于识别PDF作为CMYK.

基本上,假设我正在构建此文件test.tex,使用pdflatex:

\documentclass[a4paper,12pt]{article}

%% https://tex.stackexchange.com/questions/13071
\pdfcompresslevel=0

%% http://compgroups.net/comp.text.tex/Making-a-cmyk-PDF
%% ln -s /usr/share/color/icc/sRGB.icm .
% \immediate\pdfobj stream attr{/N 4} file{sRGB.icm}
% \pdfcatalog{%
% /OutputIntents [ <<
% /Type /OutputIntent
% /S/GTS_PDFA1
% /DestOutputProfile \the\pdflastobj\space 0 R
% /OutputConditionIdentifier (sRGB IEC61966-2.1)
% /Info(sRGB IEC61966-2.1)
% >> ]
% }

%% http://latex-my.blogspot.com/2010/02/cmyk-output-for-commercial-printing.html
%% https://tex.stackexchange.com/questions/9961
\usepackage[cmyk]{xcolor}

\begin{document}
Some text here...
\end{document}
Run Code Online (Sandbox Code Playgroud)

如果我然后尝试识别生成的test.pdf文件,我将其作为RGB,无论我尝试过什么选项(至少根据源中的链接) - 然而,其中的颜色将保存为CMYK; 对于上面的来源:

$ grep -ia 'cmyk\|rgb\| k' test.pdf 
0 0 0 1 k …
Run Code Online (Sandbox Code Playgroud)

linux pdf imagemagick cmyk ghostscript

25
推荐指数
2
解决办法
3万
查看次数

更改make变量,并从同一Makefile中的配方调用另一个规则?

我已经看过如何从make目标手动调用另一个目标?,但我的问题有点不同; 考虑这个例子(注意,stackoverflow.com将选项卡更改为显示中的空格;但如果您尝试编辑,则选项卡将保留在源代码中):

TEXENGINE=pdflatex

pdflatex:
    echo the engine is $(TEXENGINE)

lualatex:
    TEXENGINE=lualatex
    echo Here I want to call the pdflatex rule, to check $(TEXENGINE) there!
Run Code Online (Sandbox Code Playgroud)

在这里,如果我运行默认目标(pdflatex),我得到预期的输出:

$ make pdflatex 
echo the engine is pdflatex
the engine is pdflatex
Run Code Online (Sandbox Code Playgroud)

但是,有了目标lualatex,我想:

  • make变量更改TEXENGINElualatex,然后
  • 调用与pdflatex(使用它)相同的代码.

我怎么能这样做?

很明显,在我的lualatex规则中,我甚至没有设法更改TEXENGINE变量,因为我在尝试时得到了这个:

$ make lualatex 
TEXENGINE=lualatex
echo Here I want to call the pdflatex rule, to check pdflatex there!
Here I want …
Run Code Online (Sandbox Code Playgroud)

makefile gnu-make

25
推荐指数
2
解决办法
1万
查看次数

调试:使用gdb单步执行Python脚本?

假设我们有以下超级简单的Python脚本:

print "Initializing"....
a=10
print "Variable value is %d" % (a)
print "All done!"
Run Code Online (Sandbox Code Playgroud)

...并且说,我想通过在线上放置一个断点来调试这个脚本a=10,然后单步调试脚本.

现在,我想使用gdb它,因为我想调试可能作为共享对象(.so)库的一部分的Python绑定- 因此,我理想地在Python代码行上放置一个断点,并且然后"进入"共享对象的C部分...(注意,DebuggingWithGdb - PythonInfo Wiki并没有真正明确说明这是可能的)

问题是:gdb它本身无法真正识别断点,放在Python脚本行上:

$ gdb python
GNU gdb (GDB) 7.3.50.20110806-cvs 
...
Reading symbols from /usr/bin/python...(no debugging symbols found)...done.
(gdb) b test.py:3
No symbol table is loaded.  Use the "file" command.
Make breakpoint pending on future shared library load? (y or [n]) y

Breakpoint 1 (test.py:3) pending.
(gdb) run test.py
Starting …
Run Code Online (Sandbox Code Playgroud)

python debugging gdb

24
推荐指数
2
解决办法
3万
查看次数