IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Réseau/Web Python Discussion :

Compresser un flux d'entrée


Sujet :

Réseau/Web Python

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre expérimenté Avatar de Rupella
    Inscrit en
    Février 2005
    Messages
    286
    Détails du profil
    Informations forums :
    Inscription : Février 2005
    Messages : 286
    Par défaut Compresser un flux d'entrée
    Bonjour

    Je suis à la recherche d'éléments sur la compression de données.

    Je dois envoyer des données au travers d'un réseau sur UDP.
    Je cherche à savoir s'il est possible de compresser mes données envoyées (une chaîne de caractères), sans avoir à passer par un fichier.

    Merci pour votre aide.

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Juin 2009
    Messages
    139
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juin 2009
    Messages : 139
    Par défaut
    A premiere vu:
    http://docs.python.org/library/zlib.html
    La méthode compress fait exactement ce que tu cherche (enfin je crois)

    exemple:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    >>>a='    The attribute sys.float_info.dig needs further explanation. If s is any string representing a decimal number with at most sys.float_info.dig significant digits, then converting s to a float and back again will recover a string representing the same decimal value:    >>> import sys    >>> sys.float_info.dig    15    >>> s =  3.14159265358979     # decimal string with 15 significant digits    >>> format(float(s),  .15g )  # convert to float and back -> same value     3.14159265358979     But for strings with more than sys.float_info.dig significant digits, this isn t always true:    >>> s =  9876543211234567     # 16 significant digits is too many!    >>> format(float(s),  .16g )  # conversion changes value     9876543211234568     New in version 2.6.sys.float_repr_style¶    A string indicating how the repr() function behaves for floats. If the string has value  short  then for a finite float x, repr(x) aims to produce a short string with the property that float(repr(x)) == x. This is the usual behaviour in Python 2.7 and later. Otherwise, float_repr_style has value  legacy  and repr(x) behaves in the same way as it did in versions of Python prior to 2.7.    New in version 2.7.sys.getcheckinterval()¶    Return the interpreter s "check interval"; see setcheckinterval().    New in version 2.3.sys.getdefaultencoding()¶    Return the name of the current default string encoding used by the Unicode implementation.    New in version 2.0.sys.getdlopenflags()¶    Return the current value of the flags that are used for dlopen() calls. The flag constants are defined in the dl and DLFCN modules. Availability: Unix.    New in version 2.2.sys.getfilesystemencoding()¶    Return the name of the encoding used to convert Unicode filenames into system file names, or None if the system default encoding is used. The result value depends on the operating system:        * On Mac OS X, the encoding is  utf-8 .        * On Unix, the encoding is the user s preference according to the result of nl_langinfo(CODESET), or None if the nl_langinfo(CODESET) failed.        * On Windows NT+, file names are Unicode natively, so no conversion is performed. getfilesystemencoding() still returns  mbcs , as this is the encoding that applications should use when they explicitly want to convert Unicode strings to byte strings that are equivalent when used as file names.        * On Windows 9x, the encoding is  mbcs .    New in version 2.3.sys.getrefcount(object)¶    Return the reference count of the object. The count returned is generally one higher than you might expect, because it includes the (temporary) reference as an argument to getrefcount().sys.getrecursionlimit()¶    Return the current value of the recursion limit, the maximum depth of the Python interpreter stack. This limit prevents infinite recursion from causing an overflow of the C stack and crashing Python. It can be set by setrecursionlimit().sys.getsizeof(object[, default])¶    Return the size of an object in bytes. The object can be any type of object. All built-in objects will return correct results, but this does not have to hold true for third-party extensions as it is implementation specific.    If given, default will be returned if the object does not provide means to retrieve the size. Otherwise a TypeError will be raised.    getsizeof() calls the object s __sizeof__ method and adds an additional garbage collector overhead if the object is managed by the garbage collector.    New in version 2.6.sys._getframe([depth])¶    Return a frame object from the call stack. If optional integer depth is given, return the frame object that many calls below the top of the stack. If that is deeper than the call stack, ValueError is raised. The default for depth is zero, returning the frame at the top of the call stack.    CPython implementation detail: This function should be used for internal and specialized purposes only. It is not guaranteed to exist in all implementations of Python.sys.getprofile()¶    Get the profiler function as set by setprofile().    New in version 2.6.sys.gettrace()¶    Get the trace function as set by settrace().    CPython implementation detail: The gettrace() function is intended only for implementing debuggers, profilers, coverage tools and the like. Its behavior is part of the implementation platform, rather than part of the language definition, and thus may not be available in all Python implementations.'
     
    >>>b=zlib.compress(a)
    >>>sys.getsizeof(a)
    4468
    >>> sys.getsizeof(b)
    1780

  3. #3
    Membre expérimenté Avatar de Rupella
    Inscrit en
    Février 2005
    Messages
    286
    Détails du profil
    Informations forums :
    Inscription : Février 2005
    Messages : 286
    Par défaut
    Ben ma foi, on ne pouvait espérer mieux.
    Je m'étais perdu dans le module gzip, avec ses fonctions sur les fichiers.
    Merci !

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. flux d'entrée caractere &
    Par kassim34 dans le forum Flex
    Réponses: 1
    Dernier message: 31/07/2007, 17h02
  2. image à partir du flux d'entrée standard
    Par gege64 dans le forum Qt
    Réponses: 2
    Dernier message: 05/11/2006, 18h14
  3. Réponses: 3
    Dernier message: 08/08/2006, 02h50
  4. Compression de flux
    Par mavvv dans le forum Servlets/JSP
    Réponses: 5
    Dernier message: 17/05/2006, 10h01
  5. Envoi d'un flux audio entre 2 PC
    Par TheDarkLewis dans le forum Windows
    Réponses: 2
    Dernier message: 30/08/2004, 02h02

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo