相关疑难解决方法(0)

TypeError:'str'对象不可调用(Python)

码:

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 …
Run Code Online (Sandbox Code Playgroud)

python

59
推荐指数
10
解决办法
48万
查看次数

如何恢复我意外覆盖的内置?

set在交互式python会话中使用它作为变量名称而意外地覆盖了 - 有没有什么办法可以在set不重新启动会话的情况下访问原始函数?

(我在那个会话中有很多东西,我宁愿不必这样做,虽然我当然可以在必要的时候.)

python built-in

26
推荐指数
2
解决办法
7289
查看次数

使用内置名称作为局部变量,也作为内置变量

我有以下功能:

def x():
    print(min(0, 1))
    min = 7
    print(min)
Run Code Online (Sandbox Code Playgroud)

在它的面前(天真),它应打印0,然后7.实际上它引发了一个错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in x
UnboundLocalError: local variable 'min' referenced before assignment
Run Code Online (Sandbox Code Playgroud)

定义min为局部变量如何min = 7防止它被用作手中的内置?Python是否__slots__在编译函数时构建局部变量列表(类似于类)?

python python-3.x

-2
推荐指数
1
解决办法
258
查看次数

标签 统计

python ×3

built-in ×1

python-3.x ×1