Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #98504

using binary in python

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From kent nyberg <kent@z-sverige.nu>
Newsgroups comp.lang.python
Subject using binary in python
Date Sun, 8 Nov 2015 16:27:06 -0500
Lines 24
Message-ID <mailman.164.1447060794.16136.python-list@python.org> (permalink)
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Trace news.uni-berlin.de H/ht7h3XYARVbV+mfqTQfgbGi3v5sTilMv8sIPeHD1qg==
Return-Path <kent@z-sverige.nu>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'binary': 0.05; 'converts': 0.07; 'integers': 0.09; 'subject:using': 0.09; 'python': 0.10; 'assume': 0.11; 'python.': 0.11; 'files.': 0.13; 'question.': 0.13; 'subject:python': 0.14; 'file,': 0.15; 'variables': 0.15; 'ascii,': 0.16; 'binary.': 0.16; 'file?': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'why,': 0.16; 'written.': 0.16; 'integer': 0.18; 'linux,': 0.18; 'of.': 0.18; 'python?': 0.18; 'variable': 0.18; 'language': 0.19; 'ok.': 0.22; 'struct': 0.22; 'file.': 0.22; 'sort': 0.25; 'wondering': 0.25; "i've": 0.25; 'header:User-Agent:1': 0.26; 'example': 0.26; 'command': 0.26; 'converting': 0.27; 'forgive': 0.27; 'function': 0.28; 'asks': 0.29; 'convert': 0.29; 'non': 0.32; 'run': 0.33; 'lets': 0.33; 'right?': 0.33; 'file': 0.34; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'possible': 0.36; 'to:addr:python- list': 0.36; 'really': 0.37; 'there,': 0.37; 'say': 0.37; 'thanks': 0.37; 'charset:us-ascii': 0.37; 'files': 0.38; 'data': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'some': 0.40; 'hang': 0.60; 'matter': 0.63; 'strange': 0.63; 'letters': 0.67; 'feeling': 0.72; 'received:178': 0.72
Content-Disposition inline
User-Agent Mutt/1.5.23 (2014-03-12)
X-Mailman-Approved-At Mon, 09 Nov 2015 04:19:53 -0500
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:98504

Show key headers only | View raw


Hi there,
Lets say I want to play around with binary files in python.
Opening and using files in python is something that I think I've sort of got the hang of.
The thing im wondering about is binary files.
While searching for binary and python I started reading about bin().
I can use bin() to convert integers to binary. 
Now, I thought..  some way it should be possible to write "binary" files.
That is, non ascii-files.  For example, on Linux, if I run the command 'less' on a binary;
for example /bin/ls, then the command asks me if I really want to do it, since its a binary file.
I know why, since the non ascii-stuff messes up the terminal, and most likely since you rarely want to
look at a binary file with less. 
Well, lets assume I want to write and read binary.  How is it done?
The built in bin() function only converts integers to binary but the variable or return is still just letters right?
Converting the integer '1' to binary with bin() return 0b1. Which is ok. Its the binary representation of integer 1. 
But since.. there is files which contains data that is not representable as ascii, then I assume it can be written.
But can it by Python?

Ok, I get the feeling now that its hard to understand my question. I assume in the C language its just matter of 
writing a complex struct with strange variables and just write it to a file. But in python..?

Can some one give a short explenation of a python write to file, that makes it a binary file?

Thanks alot,  and forgive me for my stupid questions. :)
/Kent Nyberg

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

using binary in python kent nyberg <kent@z-sverige.nu> - 2015-11-08 16:27 -0500
  Re: using binary in python Jussi Piitulainen <harvesting@makes.email.invalid> - 2015-11-09 11:58 +0200
  Re: using binary in python Larry Hudson <orgnut@yahoo.com> - 2015-11-09 22:20 -0800
    Re: using binary in python Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-11-10 15:14 -0500
      Re: using binary in python mm0fmf <none@mailinator.com> - 2015-11-10 20:36 +0000
        Re: using binary in python Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-11-10 16:02 -0500
          OT: Re: using binary in python mm0fmf <none@mailinator.com> - 2015-11-10 22:17 +0000
        Re: using binary in python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-11-10 21:22 +0000
        Re: using binary in python Random832 <random832@fastmail.com> - 2015-11-10 19:03 -0500
        Re: using binary in python Random832 <random832@fastmail.com> - 2015-11-10 19:04 -0500
      Re: using binary in python Larry Hudson <orgnut@yahoo.com> - 2015-11-10 19:53 -0800
    Re: using binary in python Random832 <random832@fastmail.com> - 2015-11-10 15:44 -0500
    Re: using binary in python kent nyberg <kent@z-sverige.nu> - 2015-11-10 16:29 -0500
      Re: using binary in python Christian Gollwitzer <auriocus@gmx.de> - 2015-11-11 22:32 +0100
    Re: using binary in python Michael Torrie <torriem@gmail.com> - 2015-11-10 17:19 -0700

csiph-web