我想了解内置函数的property工作原理.令我困惑的是,property它也可以用作装饰器,但它只在用作内置函数时才需要参数,而不是用作装饰器时.
这个例子来自文档:
class C(object):
def __init__(self):
self._x = None
def getx(self):
return self._x
def setx(self, value):
self._x = value
def delx(self):
del self._x
x = property(getx, setx, delx, "I'm the 'x' property.")
Run Code Online (Sandbox Code Playgroud)
property的论点是getx,setx,delx和文档字符串.
在下面的代码中property用作装饰器.它的对象是x函数,但在上面的代码中,参数中没有对象函数的位置.
class C(object):
def __init__(self):
self._x = None
@property
def x(self):
"""I'm the 'x' property."""
return self._x
@x.setter
def x(self, value):
self._x = value
@x.deleter
def x(self):
del self._x
Run Code Online (Sandbox Code Playgroud)
而且,如何在 …
python properties decorator python-internals python-decorators
我是Python的新手并且遵循教程.list教程中有一个例子:
example = list('easyhoss')
Run Code Online (Sandbox Code Playgroud)
现在,在教程中,example= ['e','a',...,'s'].但在我的情况下,我得到以下错误:
>>> example = list('easyhoss')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'list' object is not callable
Run Code Online (Sandbox Code Playgroud)
请告诉我我错在哪里.我搜索了这个,但它是不同的.
我正在使用Spark和PySpark.我试图实现相当于以下伪代码的结果:
df = df.withColumn('new_column',
IF fruit1 == fruit2 THEN 1, ELSE 0. IF fruit1 IS NULL OR fruit2 IS NULL 3.)
Run Code Online (Sandbox Code Playgroud)
我试图在PySpark中这样做,但我不确定语法.有什么指针吗?我调查expr()但无法让它工作.
请注意,这df是一个pyspark.sql.dataframe.DataFrame.
coinCount = [2 for i in range(4)]
total = sum(coinCount)
Run Code Online (Sandbox Code Playgroud)
这给了我
TypeError: 'int' object is not callable
Run Code Online (Sandbox Code Playgroud)
我不明白为什么因为
print type(coinCount)
Run Code Online (Sandbox Code Playgroud)
给我
type <'list'>
Run Code Online (Sandbox Code Playgroud) 我写了一个玩刽子手的程序---它还没有完成,但由于某些原因它给了我一个错误...
import turtle
n=False
y=True
list=()
print ("welcome to the hangman! you word is?")
word=raw_input()
len=len(word)
for x in range(70):
print
print "_ "*len
while n==False:
while y==True:
print "insert a letter:"
p=raw_input()
leenghthp=len(p)
if leengthp!=1:
print "you didnt give me a letter!!!"
else:
y=False
for x in range(len):
#if wo
print "done"
Run Code Online (Sandbox Code Playgroud)
错误:
leenghthp=len(p)
TypeError: 'int' object is not callable
Run Code Online (Sandbox Code Playgroud) 我想弄清楚为什么我在一个范围上使用sum函数时会出现错误.
这是代码:
data1 = range(0, 1000, 3)
data2 = range(0, 1000, 5)
data3 = list(set(data1 + data2)) # makes new list without duplicates
total = sum(data3) # calculate sum of data3 list's elements
print total
Run Code Online (Sandbox Code Playgroud)
这是错误:
line 8, in <module> total2 = sum(data3)
TypeError: 'int' object is not callable
Run Code Online (Sandbox Code Playgroud)
我找到了错误的解释:
在Python中,"可调用"通常是一个函数.该消息意味着您正在处理一个数字(>"int"),就好像它是一个函数("可调用"),因此Python不知道该怎么做,所以它>停止.
我还读到sum()能够在列表中使用,所以我想知道这里出了什么问题?
我刚刚在IDLE模块中尝试过,它工作正常.但是,它在python解释器中不起作用.关于如何做的任何想法?
这是我的代码:
import time
a = time.daylight()
print(a)
Run Code Online (Sandbox Code Playgroud)
它导致:
TypeError: 'int' object is not callable.
Run Code Online (Sandbox Code Playgroud)
问题是什么?
所以我做了我的研究,但我仍然无法弄清楚为什么我得到这个错误:
TypeError: int is not callable
继承我的代码:
count = []
for row in Matrix:
count.append(row[0][0].Value)
results = map(int, count)
print max(results)
Run Code Online (Sandbox Code Playgroud)
count列表包含一个字符串整数列表,我将这些转换为纯整数然后我想找到最大数字,但我得到了错误.
我在这里看不到什么?
顺便说一句,print min(count)工作正常....
我很抱歉问这个问题,但我找不到为什么会出现此错误,尤其是在程序运行之后。
准确地说,错误是:
>>>
Welcome! This program will convert measures for you.
Select operation.
1.Miles to Kilometers
2.Fahrenheit to Celsius
3.Gallons to liters
4.Pounds to kilograms
5.Inches to centimeters
Enter your choice by number: 1
Traceback (most recent call last):
File "C:\Users\Levhitor\Downloads\Mario_Gomez_Lab2.py", line 112, in <module>
intro()
File "C:\Users\Levhitor\Downloads\Mario_Gomez_Lab2.py", line 12, in intro
main()
File "C:\Users\Levhitor\Downloads\Mario_Gomez_Lab2.py", line 25, in main
convertMK()
File "C:\Users\Levhitor\Downloads\Mario_Gomez_Lab2.py", line 44, in convertMK
input_M = float(raw_input(("Miles: ")))
TypeError: 'int' object is not callable
Run Code Online (Sandbox Code Playgroud)
我不明白这里发生了什么事。谁能帮我?
raw_input = 0 …Run Code Online (Sandbox Code Playgroud) 所以我在python 3.2中编写了一个tic tac toe游戏,我花了一天一天的时间试图解决这个问题,并检查我的代码,脚本或任何你想要调用它的东西,这么多次仍然无法找到它.我用谷歌搜索了所有答案都令人困惑,或者这个人的脚本与我的tic tac toe游戏有所不同.请注意,我只是python的初学者.当我尝试运行它时出现错误:
Traceback (most recent call last):
File "/Users/user/Desktop/tic tac toe game.py", line 41, in <module>
input = input("Select a spot:")
TypeError: 'int' object is not callable"
Run Code Online (Sandbox Code Playgroud)
那是什么意思?这是代码,它说它有问题:
while True:
input = input("Select a spot:")
input = int(input)
Run Code Online (Sandbox Code Playgroud)
如果你能帮助我,那就意味着很多.它一直很烦人,我一直在努力解决它.
Python3:TypeError: 'int' object is not callable是因为我调用方法的.area()方式错了吗?或者是因为我说的方式.area()是错的?谢谢
class Rectangle:
def __init__ (self):
self.height = 0
self.width = 0
self.area = 0
def setData(self, height, width):
self.height = height
self.width = width
def area(self, height, width):
self.area = height * width
def __str__(self):
return "height = %i, width = %i" % (self.height, self.width)
return "area = %i" % self.area
if __name__ == "__main__":
r1 = Rectangle()
print (r1)
r1.setData(3,4)
print (r1)
Run Code Online (Sandbox Code Playgroud)
在这里我打电话.area(),我想问题来自哪里:
r1.area(3,4)
print …Run Code Online (Sandbox Code Playgroud) python ×9
list ×3
python-2.7 ×3
python-3.x ×2
typeerror ×2
apache-spark ×1
callable ×1
decorator ×1
hive ×1
hiveql ×1
input ×1
int ×1
max ×1
oop ×1
properties ×1
pygame ×1
pyspark ×1
sum ×1
tic-tac-toe ×1