This is the place for queries that don't fit in any of the other categories.
Hi, so I've read in a file using:
- Code: Select all
with open(sys.argv, 'rb') as f:
contents = f.read()
How do I convert this whole binary value to a string? I need this because I am taking a file (PDF for example) and wanting to check what PDF version it is by examining the header.
- Posts: 1
- Joined: Mon Jun 09, 2014 1:58 pm
If you are using python 2, contents already is a string.
In python 3, it is a bytes object, which should allow you to do any checking you want.
Do you have an actual problem? You should show us your failing code (and full error traceback, if you get one.)
Friendship is magic!
R.I.P. Tracy M. You will be missed.
- Posts: 1475
- Joined: Thu Feb 07, 2013 3:42 pm
Return to General Coding Help
Who is online
Users browsing this forum: Bing [Bot], Majestic-12 [Bot], Ofnuts, Skaperen, Yahoo [Bot] and 5 guests