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


Groups > de.comp.lang.python > #5381

Re: [Python-de] IFF Format: Dict?

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Thomas Güttler <guettliml@thomas-guettler.de>
Newsgroups de.comp.lang.python
Subject Re: [Python-de] IFF Format: Dict?
Date Fri, 4 Jan 2019 14:31:06 +0100
Lines 95
Message-ID <mailman.54.1546609254.4816.python-de@python.org> (permalink)
References <16bf5ba5-26db-dddf-0a42-ddc61670a4ae@thomas-guettler.de> <mailman.4.1543506244.25456.python-de@python.org> <hmj5df-kdq.ln1@gate.homenet> <0e512eb9-3a48-7f63-b2d5-6f6acfa48da3@thomas-guettler.de> <2141174c-1718-f16e-f056-15af93d0b918@sschwarzer.net> <IFF-20181213160443@ram.dialup.fu-berlin.de> <b806481f-5860-f65a-67a6-66681c878747@thomas-guettler.de> <mailman.47.1544774642.2771.python-de@python.org> <string-20181214220559@ram.dialup.fu-berlin.de> <adfe9583-ac85-cbfd-7512-8c88ef468ba4@thomas-guettler.de>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 8bit
X-Trace news.uni-berlin.de JPM0fM9NByc1IHI/augpsga/nilToRChgVvKmWr16/lg==
Return-Path <guettliml@thomas-guettler.de>
X-Original-To python-de@python.org
Delivered-To python-de@mail.python.org
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1
In-Reply-To <string-20181214220559@ram.dialup.fu-berlin.de>
Content-Language de-DE
X-BeenThere python-de@python.org
X-Mailman-Version 2.1.29
Precedence list
List-Id Die Deutsche Python Mailingliste <python-de.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-de>, <mailto:python-de-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-de/>
List-Post <mailto:python-de@python.org>
List-Help <mailto:python-de-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-de>, <mailto:python-de-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <adfe9583-ac85-cbfd-7512-8c88ef468ba4@thomas-guettler.de>
X-Mailman-Original-References <16bf5ba5-26db-dddf-0a42-ddc61670a4ae@thomas-guettler.de> <mailman.4.1543506244.25456.python-de@python.org> <hmj5df-kdq.ln1@gate.homenet> <0e512eb9-3a48-7f63-b2d5-6f6acfa48da3@thomas-guettler.de> <2141174c-1718-f16e-f056-15af93d0b918@sschwarzer.net> <IFF-20181213160443@ram.dialup.fu-berlin.de> <b806481f-5860-f65a-67a6-66681c878747@thomas-guettler.de> <mailman.47.1544774642.2771.python-de@python.org> <string-20181214220559@ram.dialup.fu-berlin.de>
Xref csiph.com de.comp.lang.python:5381

Show key headers only | View raw


Noch mal kurz langsam.
Dieser Thread geht um ein passendes Datenformat. Sicherlich
kann man da nun ganz viel programmieren, aber das will ich ganz
bewusst nicht tun. Wenn ich für die Lösung programmieren muss,
dann muss es wohl auch der Empfänger der Daten.
Das würde ich gerne vermeiden.

Gruß,
   Thomas

Am 14.12.18 um 22:10 schrieb Stefan Ram:
> =?UTF-8?Q?Thomas_G=c3=bcttler?= <guettliml@thomas-guettler.de> writes:
>> Wie kann man ein Python Dictionary in IFF speichern/laden?
> 
>    Ich habe mal angefangen, als Beispiel eine Methode
>    »write_CHRS« zu schreiben, die einen Python-String
>    als CHRS-Chunk in eine Datei schreibt. Danach lese
>    ich diesen wieder mit dem Modul "chunk" ein.
> 
>    Ich weiß aber nicht, ob ich jemals dazu komme, jetzt
>    noch darauf aufbauend das für ein Dictionary zu schreiben.
> 
>    main.py
> 
> class chunk():
>        def __init__( my, type=None, size=None ):
>            my.type = type
>            my.size = size
> 
> class chunk_CHRS( chunk ):
> 
>        class size_too_large( Exception ):
>              pass
> 
>        class unprepared_write_attempt( Exception ):
>              pass
> 
>        class no_text_given( Exception ):
>              pass
> 
>        def __init__( my, text=None ):
>            chunk.__init__( my, b'CHRS', None )
>            my.set_text( text )
> 
>        def set_text( my, text=None ):
>            my.text = text
>            my.data = None
>            my.prepared = False
> 
>        def prepare_for_writing( my ):
>            if my.text == None: raise no_text_given()
>            my.data = my.text.encode( 'utf-8' )
>            l = len( my.data )
>            if l > 2**32-1: raise size_too_large()
>            my.size = l
>            my.prepared = True
> 
>        def write_to_file( my, file ):
>            if not my.prepared: raise unprepared_write_attempt()
>            if my.size > 2**32-1: raise size_too_large()
>            file.write( my.type )
>            file.write( my.size.to_bytes( 4, byteorder='big', signed=False ))
>            file.write( my.data )
> 
> def write_CHRS( file, text ):
>      chunk = chunk_CHRS( text )
>      chunk.prepare_for_writing()
>      chunk.write_to_file( file )
> 
> with open( 'test20181214215507.txt', 'wb' ) as file:
>       write_CHRS( file, 'example' )
> 
> import chunk
> 
> with open( 'test20181214215507.txt', 'rb' ) as file:
>       c = chunk.Chunk( file )
>       print( c.getname() )
>       print( c.getsize() )
>       print( c.read( c.getsize() ))
>       c.close()
> 
>    transcript
> 
> b'CHRS'
> 7
> b'example'
> 
> _______________________________________________
> python-de maillist  -  python-de@python.org
> https://mail.python.org/mailman/listinfo/python-de
> 

-- 
Thomas Guettler http://www.thomas-guettler.de/
I am looking for feedback: https://github.com/guettli/programming-guidelines

Back to de.comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

[Python-de] Binärdaten in JSON Thomas Güttler <guettliml@thomas-guettler.de> - 2018-11-29 16:36 +0100
  Re: [Python-de] Binärdaten in JSON Thomas Orgelmacher <trash@odbs.org> - 2018-11-29 18:19 +0100
    Re: [Python-de] Binärdaten in JSON Arnold Krille <arnold@arnoldarts.de> - 2018-11-29 19:46 +0100
    Re: [Python-de] Binärdaten in JSON Thomas Güttler <guettliml@thomas-guettler.de> - 2018-11-30 09:48 +0100
      Re: [Python-de] Binärdaten in JSON Thomas Orgelmacher <trash@odbs.org> - 2018-11-30 19:24 +0100
      Re: [Python-de] Binärdaten in JSON Thomas Orgelmacher <trash@odbs.org> - 2018-11-30 19:37 +0100
    Re: [Python-de] Binärdaten in JSON Stefan Schwarzer <sschwarzer@sschwarzer.net> - 2018-11-30 11:27 +0100
    Re: [Python-de] Binärdaten in JSON Hardy Erlinger <hardy.erlinger@posteo.de> - 2018-11-30 11:40 +0100
    Re: [Python-de] Binärdaten in JSON Thomas Güttler <guettliml@thomas-guettler.de> - 2018-11-30 15:01 +0100
    Re: [Python-de] Binärdaten in JSON Thomas Jollans <tjol@tjol.eu> - 2018-12-03 10:21 +0100
    Re: [Python-de] Binärdaten in JSON Thomas Güttler <guettliml@thomas-guettler.de> - 2018-12-04 10:25 +0100
      Re: [Python-de] Binärdaten in JSON Thomas Güttler <guettliml@thomas-guettler.de> - 2018-12-13 12:14 +0100
        [Python-de] IFF Format: Dict? Thomas Güttler <guettliml@thomas-guettler.de> - 2018-12-14 09:04 +0100
          Re: [Python-de] IFF Format: Dict? Thomas Güttler <guettliml@thomas-guettler.de> - 2019-01-04 14:31 +0100
            Re: [Python-de] IFF Format: Dict? Thomas Orgelmacher <trash@odbs.org> - 2019-01-05 20:58 +0100
        Re: [Python-de] IFF Format: Dict? Armin Stross-Radschinski <developer@acsr.de> - 2018-12-14 10:31 +0100
        [Python-de] IFF Format Verwendung Christopher Arndt <chris@chrisarndt.de> - 2018-12-14 14:53 +0100
    Re: [Python-de] Binärdaten in JSON Stefan Behnel <python-de@behnel.de> - 2018-12-06 09:51 +0100

csiph-web