The below code gives me the error, other than changing the module that plays the (winsound) sound, this worked fine on Python2.6 on Windows. Not sure where I have gone wrong on this one. This is being run on a Linux box, previously on a Windows machine. The version on Windows was 2.6 and version on Linux is 2.7.3.
下面的代码给了我错误,除了更改播放(winsound)声音的模块,这在Windows上的Python2.6上运行良好。不确定我在这个问题上出了什么问题。这是在以前在Windows机器上的Linux机器上运行的。 Windows上的版本是2.6,Linux上的版本是2.7.3。
Traceback (most recent call last): File "CallsWaiting.py", line 9, in first_time = time.time() AttributeError: 'int' object has no attribute 'time'
回溯(最近一次调用最后一次):文件“CallsWaiting.py”,第9行,在first_time = time.time()属性错误:'int'对象没有属性'time'
import _mysql
import sys
import time
import os
import pygame
pygame.init()
time = 3
first_time = time.time()
last_time = first_time
while True:
pass
new_time = time.time()
if new_time - last_time > timeout:
last_time = new_time
os.system('cls')
iswaiting = 0
print "Calls Waiting: "
con = _mysql.connect(host='oip-prod', port=3308, user='admin', passwd='1234', db='axpdb')
con.query("select callswaiting from callcenterinformation where date - date(now()) and skillid = 2 order by time desc limit 1;")
result = con.user_result()
iswaiting = int('',join(result.fetch_row() [0]))
print "%s" % \
iswaiting
if iswaiting > 0:
print "Calls are waiting!"
pygame.mixer.init()
sounda = pygame.mixer,Sound("ring2.wav")
sounda.play()
3 个解决方案
#1
7
As time = 3
is declared as an integer, time.time
doesn't have any sense since time is int
variable (that isn't a class but a primitive data type). I suppose that you expected to call time
(module) writing time
but, since you're redefining it as an integer, this last definition shadows the time
module
当time = 3被声明为整数时,time.time没有任何意义,因为time是int变量(不是类而是基本数据类型)。我想你期望调用时间(模块)写入时间,但是,因为你将它重新定义为一个整数,所以最后一个定义会影响时间模块
Change time
variable name to something else, like myTime
将时间变量名称更改为其他名称,例如myTime
Error messages are usefull, you should read them. Often the answer is contained directly into this errors/warning messages
#2
0
You have variable time:
你有可变的时间:
time = 3
and you have previously imported package time:
并且您之前导入了包裹时间:
import time
When you try to do
当你尝试做的时候
time.time()
it seems that you try to call method time() of variable time (that contains int).
看来你试着调用可变时间的方法time()(包含int)。
You should rename it and it will figure out conflicts with package name.
您应该重命名它,它将找出与包名称的冲突。
#3
0
You declare time
variable. While time
is module imported from import
statement. So when you access time.x
its try to access variable instead of module
.
你声明时间变量。虽然时间是从import语句导入的模块。因此,当您访问time.x时,它会尝试访问变量而不是模块。
Change variable name or import module time
as another name.
将变量名称或导入模块时间更改为另一个名称。
#1
7
As time = 3
is declared as an integer, time.time
doesn't have any sense since time is int
variable (that isn't a class but a primitive data type). I suppose that you expected to call time
(module) writing time
but, since you're redefining it as an integer, this last definition shadows the time
module
当time = 3被声明为整数时,time.time没有任何意义,因为time是int变量(不是类而是基本数据类型)。我想你期望调用时间(模块)写入时间,但是,因为你将它重新定义为一个整数,所以最后一个定义会影响时间模块
Change time
variable name to something else, like myTime
将时间变量名称更改为其他名称,例如myTime
Error messages are usefull, you should read them. Often the answer is contained directly into this errors/warning messages
#2
0
You have variable time:
你有可变的时间:
time = 3
and you have previously imported package time:
并且您之前导入了包裹时间:
import time
When you try to do
当你尝试做的时候
time.time()
it seems that you try to call method time() of variable time (that contains int).
看来你试着调用可变时间的方法time()(包含int)。
You should rename it and it will figure out conflicts with package name.
您应该重命名它,它将找出与包名称的冲突。
#3
0
You declare time
variable. While time
is module imported from import
statement. So when you access time.x
its try to access variable instead of module
.
你声明时间变量。虽然时间是从import语句导入的模块。因此,当您访问time.x时,它会尝试访问变量而不是模块。
Change variable name or import module time
as another name.
将变量名称或导入模块时间更改为另一个名称。