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

Python Discussion :

TypeError: 'module' object is no callable


Sujet :

Python

  1. #1
    Membre régulier
    Femme Profil pro
    Étudiant
    Inscrit en
    Mai 2014
    Messages
    200
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 31
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Conseil

    Informations forums :
    Inscription : Mai 2014
    Messages : 200
    Points : 75
    Points
    75
    Par défaut TypeError: 'module' object is no callable
    Salut les dev,
    En exécutant le code ci-dessous, j'ai une erreur de type 'module' object is no callable) que j'arrive pas à gérer.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    import numpy as np
    import struct
    import string as mstring
    import cv2
    import scipy
     
    c = struct(mstring('nim'), 24, mstring('nb'), 5, mstring('CellHeightP'), 120, mstring('nCells'), 20, mstring('cpw'), 2)
    W =np.uint8(255 *np.npnpones(1, 1, 3))
    if '%'(c.nim - c.nb, 2) == 0:
        nw = (c.nim - c.nb) /2;
        WhiteSegment = np.tile(W, 1, nw)
        BlackSegment = np.tile(K, 1, c.nb)
        lineb = mcat([WhiteSegment, BlackSegment, WhiteSegment])
    else:
        nw = (c.nim - c.nb - 1) / 2
        G =np. uint8(127 * np.npones(1, 1, 3))
        WhiteSegment =np.tile(W, 1, nw)
        BlackSegment = np.tile(K, 1, c.nb - 1)
        lineb = mcat([WhiteSegment, G, BlackSegment, G, WhiteSegment])
        end
        line = scipy.mine.imresize(lineb, mcat([1, c.cpw * c.nim]), mstring('nearest'))
        Cell = np.tile(line, c.CellHeightP, 1)
        Inter = np.tile(Cell, 1, c.nCells)
    [FileName, PathName, FilterIndex] = uiputfile(mstring('*.tif'))
    imwrite(Inter, mcat([PathName, FileName]), mstring('Resolution'), mcat([100, 40]), mstring('Compression'), mstring('lzw'))
    L'erreur survient lors de lexecution de la ligne suivante:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    c = struct(mstring('nim'), 24, mstring('nb'), 5, mstring('CellHeightP'), 120, mstring('nCells'), 20, mstring('cpw'), 2)
    Je n'arrive pas à comprendre pourquoi! je suis sous python 3.7.

    Une aide svp.

    Merci d'avance.

  2. #2
    Membre averti Avatar de zancrows
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2016
    Messages
    155
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côtes d'Armor (Bretagne)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2016
    Messages : 155
    Points : 346
    Points
    346
    Par défaut
    Bonjour,

    ensuite pour l'erreur dans votre code vous avez

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    ...
    import struct
    ...
    c = struct(...)
    ici vous essayer d'utiliser un objet module comme un callable.
    ce que vous pouvez faire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    from struct import Struct
    c = Struct(...)
     
    # Ou
    import struct
    c = struct.Struct(...)
    documentation de struct -> https://docs.python.org/3.7/library/struct.html

  3. #3
    Membre régulier
    Femme Profil pro
    Étudiant
    Inscrit en
    Mai 2014
    Messages
    200
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 31
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Conseil

    Informations forums :
    Inscription : Mai 2014
    Messages : 200
    Points : 75
    Points
    75
    Par défaut
    Nom : struct.png
Affichages : 457
Taille : 153,0 Ko

    Toujours la même chose.

  4. #4
    Membre averti Avatar de zancrows
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2016
    Messages
    155
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côtes d'Armor (Bretagne)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2016
    Messages : 155
    Points : 346
    Points
    346
    Par défaut
    Effectivement mais la le problème vient de mstring ou vous utilisez aussi un objet module en tant que collable.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
     
    import string as mstring
    mstring('nim')
    >>>Traceback (most recent call last):
    >>>  File "poc.py", line 5, in <module>
    >>>    mstring('nim')
    >>>TypeError: 'module' object is not callable
    je ne sais pas ce que vous voulez faire avec string et struct mais il y a il risque d'y avoir des problèmes au vu des utilisations dans votre code.
    string module -> https://docs.python.org/fr/3.7/library/string.html

  5. #5
    Membre régulier
    Femme Profil pro
    Étudiant
    Inscrit en
    Mai 2014
    Messages
    200
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 31
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Conseil

    Informations forums :
    Inscription : Mai 2014
    Messages : 200
    Points : 75
    Points
    75
    Par défaut erreur mcat importation
    Au fait oui, finalement ça n'a pas trop d'importance la structure, j'ai carrément définit des variables.

    Mon code est le suivant:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    import numpy.matlib
    import numpy as np
    import struct
    import string as mstring
    import cv2
    import scipy
    import mcat
     
     
    nim=24;
    nb=5;
    CellHeightP=120;
    nCells=20;
    cpw=2;
    #W =np.uint8(255 *np.npones(1, 1, 3))
    W = 255 * np.ones((1, 1, 3), dtype=np.int8)
    K = np.zeros((1,1,3), dtype=np.int8);
    if (nim - nb % 2) == 0:
        nw = (nim - nb) /2;
        WhiteSegment = np.matlib.repmat(W, 1, nw)
        BlackSegment = np.tile(K, 1, nb)
        lineb = mcat([WhiteSegment, BlackSegment, WhiteSegment])
    else:
        nw = (nim - nb - 1) / 2
        G = 127 * np.ones((1, 1, 3), dtype=np.int8)
        WhiteSegment =np.tile(W, int (nw))
        BlackSegment = np.tile(K, nb - 1)
        lineb = mcat([WhiteSegment, G, BlackSegment, G, WhiteSegment])
    line = scipy.mine.imresize(lineb, mcat([1, cpw * nim]), mstring('nearest'))
    Cell = np.tile(line, CellHeightP, 1)
    Inter = np.tile(Cell, 1, nCells)
     
     
    [FileName, PathName, FilterIndex] = uiputfile(mstring('*.tif'))
    imwrite(Inter, mcat([PathName, FileName]), mstring('Resolution'), mcat([100, 40]), mstring('Compression'), mstring('lzw'))
    En exécutant, j'ai l'erreur suivante (lors de l'importation de mcat)!

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    runfile('C:/Users/media/Desktop/sanstitre5.py', wdir='C:/Users/media/Desktop')
    Traceback (most recent call last):
     
      File "C:\Users\media\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3325, in run_code
        exec(code_obj, self.user_global_ns, self.user_ns)
     
      File "<ipython-input-2-5c1635314dc6>", line 1, in <module>
        runfile('C:/Users/media/Desktop/sanstitre5.py', wdir='C:/Users/media/Desktop')
     
      File "C:\Users\media\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
        execfile(filename, namespace)
     
      File "C:\Users\media\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
        exec(compile(f.read(), filename, 'exec'), namespace)
     
      File "C:/Users/media/Desktop/sanstitre5.py", line 6, in <module>
        import mcat
     
      File "C:\Users\media\Anaconda3\lib\site-packages\mcat\__init__.py", line 49
        print colored('Cmd [%s] exited.' % cmd, 'red')
                    ^
    SyntaxError: invalid syntax

Discussions similaires

  1. [Python 3.X] TypeError: 'module' object is not callable
    Par Zyxcel314 dans le forum Tkinter
    Réponses: 2
    Dernier message: 05/07/2018, 09h22
  2. TypeError: 'module' object is not callable
    Par dedalios dans le forum Général Python
    Réponses: 1
    Dernier message: 08/09/2017, 18h41
  3. erreur python 'module' object is not callable
    Par dimele dans le forum Général Python
    Réponses: 4
    Dernier message: 03/04/2014, 08h31
  4. [THREAD] TypeError: NoneType' object is not callable
    Par flolebreton dans le forum Général Python
    Réponses: 2
    Dernier message: 24/06/2013, 14h49
  5. TypeError: 'file' object is not callable
    Par MariemEA dans le forum Général Python
    Réponses: 7
    Dernier message: 09/07/2010, 21h57

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