in

TypeError: el objeto ‘str’ no es invocable (Python)

apple touch icon@2

Código:

import urllib2 as u
import os as o
inn = 'dword.txt'
w = open(inn)
z = w.readline()
b = w.readline()
c = w.readline()
x = w.readline()
m = w.readline()
def Dict(Let, Mod):
    global str
    inn = 'dword.txt'
    den = 'definitions.txt'

    print 'reading definitions...'

    dell =open(den, 'w')

    print 'getting source code...'
    f = u.urlopen('http://dictionary.reference.com/browse/' + Let)
    a = f.read(800)

    print 'writing source code to file...'
    f = open("dic1.txt", "w")
    f.write(a)
    f.close()

    j = open('defs.txt', 'w')

    print 'finding definition is source code'
    for line in open("dic1.txt"):
        if '<meta name="description" content=" in line:
           j.write(line)

    j.close()

    te = open("defs.txt', 'r').read().split()
    sto = open('remove.txt', 'r').read().split()

    print 'skimming down the definition...'
    mar = []
    for t in te:
        if t.lower() in sto:
            mar.append('')
        else: 
            mar.append
    print mar
    str = str(mar)
    str="".join([ c for c in str if c not in (",", "'", '[', ']', '')])

    defin = open(den, Mod)
    defin.write(str)
    defin.write('                 ')
    defin.close()

    print 'cleaning up...'
    o.system('del dic1.txt')
    o.system('del defs.txt')
Dict(z, 'w')
Dict(b, 'a')
Dict(c, 'a')
Dict(x, 'a')
Dict(m, 'a')
print 'all of the definitions are in definitions.txt'

El primero Dict(z, 'w') funciona y luego la segunda vez aparece un error:

Traceback (most recent call last):
  File "C:Userstest.py", line 64, in <module>
    Dict(b, 'a')
  File "C:Userstest.py", line 52, in Dict
    str = str(mar)
TypeError: 'str' object is not callable

¿Alguien sabe a que se debe esto?

@ Greg Hewgill:

Ya lo intenté y me sale el error:

Traceback (most recent call last):
 File "C:Userstest.py", line 63, in <module>
    Dict(z, 'w')
  File "C:Userstest.py", line 53, in Dict
   strr="".join([ c for c in str if c not in (",", "'", '[', ']', '')])
TypeError: 'type' object is not iterable

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

SOAP – Ejemplos

vZYT9RYcW8RBeHgVqyqq5f 1200 80

Star Trek: Picard temporada 2: todo lo que sabemos sobre el regreso del programa