我已经是一名Python程序员已有近两年了,我习惯于编写小脚本来自动执行我在办公室必须完成的一些重复性任务.现在,显然我的同事注意到了这一点,他们也想要这些脚本.
其中一些有Mac,有些是Windows; 我在windows上做了这些.我调查了使用py2exe甚至py2app来制作我的脚本的原生的可能性,但他们从未满足我......
我开始知道他们所有人都在他们的系统上有JVM,所以我可以使用像Jython这样的东西给他们一个可执行的JAR文件吗?
这有多可行......我的意思是,我不知道如何为Jython编写脚本,在我写这些脚本时我也不关心它......它会给出什么样的问题?
我有代码打开并从二进制文件中读取文件.
with open (file, mode="rb") as myfile:
message_string=myfile.read()
myfile.close
Run Code Online (Sandbox Code Playgroud)
我现在需要从stdin读取相同的内容.但我无法弄清楚如何阅读二进制文件.
该错误仅表示字节字符串.
有什么建议?
我有16位PGM图像,我试图用Python阅读.似乎(?)像PIL不支持这种格式?
import Image
im = Image.open('test.pgm')
im.show()
Run Code Online (Sandbox Code Playgroud)
大致显示图像,但它不对.整个都有暗带,据报道img有mode=L.我认为这与我早期关于16位TIFF文件的问题有关.PIL只是不支持它的16位是罕见的吗?有什么建议我如何使用PIL或其他标准库或本土代码读取Python中的16位PGM文件?
我正在将一些主要的十六进制输入读取到 Python3 脚本中。但是,系统设置为使用UTF-8,当从 Bash shell 管道传输到脚本时,我不断收到以下UnicodeDecodeError 错误:
UnicodeDecodeError: ('utf-8' codec can't decode byte 0xed in position 0: invalid continuation byte)
sys.stdin.read()根据其他 SO 答案,我在 Python3 中使用来读取管道输入,如下所示:
import sys
...
isPipe = 0
if not sys.stdin.isatty() :
isPipe = 1
try:
inpipe = sys.stdin.read().strip()
except UnicodeDecodeError as e:
err_unicode(e)
...
Run Code Online (Sandbox Code Playgroud)
它在使用这种方式管道时起作用:
# echo "\xed\xff\xff\x0b\x04\x00\xa0\xe1" | some.py
<output all ok!>
Run Code Online (Sandbox Code Playgroud)
但是,使用原始格式不会:
# echo -en "\xed\xff\xff\x0b\x04\x00\xa0\xe1"
???
??
# echo -en "\xed\xff\xff\x0b\x04\x00\xa0\xe1" | some.py
UnicodeDecodeError: ('utf-8' codec can't decode …Run Code Online (Sandbox Code Playgroud)