5

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.

Traceback (most recent call last): File "CallsWaiting.py", line 9, in first_time = time.time() AttributeError: 'int' object has no attribute '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()
user2659890
  • 75
  • 1
  • 1
  • 6

3 Answers3

15

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

Change time variable name to something else, like myTime

Error messages are usefull, you should read them. Often the answer is contained directly into this errors/warning messages

DonCallisto
  • 29,419
  • 9
  • 72
  • 100
  • @user2659890: don't worry but before posting please explore if other users already asked something similar (this probably isn't the case as it is such a basic question) or read some documentation on the internet. Cheers and enjoy S.O. :) – DonCallisto Feb 27 '14 at 11:08
1

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).

You should rename it and it will figure out conflicts with package name.

Andrii Rusanov
  • 4,405
  • 2
  • 34
  • 54
1

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.

Change variable name or import module time as another name.

Nilesh
  • 20,521
  • 16
  • 92
  • 148