Linked Questions

16 questions linked to/from Reading binary data from stdin
59 votes
1 answer
49k views

I have code that opens and reads a file from binary. with open (file, mode="rb") as myfile: message_string=myfile.read() myfile.close I now need to do the same thing reading from stdin. But ...
BeMy Friend's user avatar
5 votes
3 answers
6k views

I am reading some mainly HEX input into a Python3 script. However, the system is set to use UTF-8 and when piping from Bash shell into the script, I keep getting the following UnicodeDecodeError ...
61 votes
4 answers
60k views

I have been a Python programmer for almost two years, and I am used to writing small scripts to automate some repetitive tasks I had to do at the office. Now, apparently my colleagues noticed this, ...
5 votes
3 answers
8k views

I have 16-bit PGM images that I am trying to read in Python. It seems (?) like PIL does not support this format? import Image im = Image.open('test.pgm') im.show() Shows roughly the image, but it isn'...
3 votes
2 answers
4k views

So I've been pigeon-holed into writing some Jython code. I've been using the latest version of Eclipse IDE with the PyDev plugin for development. Up until now, things have been moderately tolerable. ...
2 votes
1 answer
2k views

I have many files which are encoded with UTF-8 or GBK. My system encoding is UTF-8 (LANG=zh_CN.UTF-8), so I can read files encoded with UTF-8 easily. But I must read file encoding with GBK as well. I'...
1 vote
1 answer
2k views

I'd like to be able to read binary data from stdin with python. However, when I use input = sys.stdin.buffer.read(), I get the error that AttributeError: 'file' object has no attribute 'buffer'. ...
2 votes
3 answers
467 views

In an attempt to create a simple cat clone in python, sys.stdout.write(sys.stdin.read()) I noticed that this fails horribly for binary files (i.e. python cat.py < binaryfile > supposed_copy) ...
0 votes
1 answer
1k views

I am writing a Python script that will take STDIN from TextWrangler and do something to it on a line by line basis. In Textwrangler, I combine multiple text files using drag and drop. Problem is ...
1 vote
3 answers
1k views

I posted a similar question about an hour ago, but have since deleted it after realising I was asking the wrong question. I have the following pickled defaultdict: ccollections defaultdict p0 (...
1 vote
1 answer
1k views

What do I need do to make sure the data is read as binary and not text when i do cat binfile | myscript.py reads as text mode I need binary mode? data = sys.stdin.read
moimoi's user avatar
  • 211
2 votes
3 answers
521 views

I am trying to pipe the output of xz to a custom python script: xz -cd file.pcap.xz | myscripy.py However, I get an error when the script attempts to run this line: #!/usr/bin/env python2.7 from ...
Ilia's user avatar
  • 554
1 vote
0 answers
1k views

I am trying to port a piece of python2 code to python3. The code works perfectly in python2, but fails in python3. In the original python2 code, data is being compressed into a tarfile as follows: ...
3 votes
0 answers
415 views

I'd like to be able to read binary data from stdin and have it preserved as binary data (i.e. no coercion to string as sys.stdin.read does). How can I do this with Python 2.7? Edit: The answers ...
2 votes
1 answer
312 views

I have the following two programs written in Python # cat.py import sys filename = sys.argv[1] with open(filename, "rb") as f: while c := f.read(1024 * 1024): sys.stdout.buffer....
Har's user avatar
  • 3,978

15 30 50 per page
1
2