有人能解释为什么sys.stdout.write()在我的字符串中附加11吗?
$ python3
Python 3.4.3+ (default, Jul 28 2015, 13:17:50)
[GCC 4.9.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 'hello'
>>> y = 'world'
>>>
据我所知,在Linux中,来自硬件设备的输入可以被认为是将数据写入文件,所以我认为在不使用X的情况下向/dev/input/mice编写一些东西来模拟鼠标点击是很有可能的。
这就是我所做的:
root@linux:~$ sudo cat /dev/input/mice >> right-click
(click the right button of your mouse, and then press ctrl+c to terminate it.)
root@linux:~$ sudo cat right-click >> /dev/input/mice
我这样做是
linux命令"lsof“返回正在访问的文件,我在shell中尝试使用vi打开一个文件,用kwrite打开另一个文件,然后返回并得到vi的进程,但没有kwrite进程,如下所示
[linux@localhost shell_ex]$ lsof +d .
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bash 3458 linux cwd DIR 253,2 50 953101 .
bash 3747 linux cwd DIR 253,2 50 95
我有一个文本文件(file1.txt),它包含这样的模式。
****
****
****
****
我想用**代替它。我可以在linux中使用类似于这个sed -i 's/\*{4}/**/' file1.txt的命令来进行替换。但是我想在Windows环境中使用python脚本执行这个操作。
import re
with open ('file1.txt') as fil1:
for line in fil1:
re.sub('^\*{3}[*]*','**',line)
但是这个脚本似乎并没有将**