By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,697 Members | 1,286 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,697 IT Pros & Developers. It's quick & easy.

TypeError: unbound method (got int instance instead)

P: 2
Hi
I am making a calendar (in Swedish): have problems with the Type Error. The problem i s that the user type in under val_1 what year he or she want to se a calendar of. The I want to send that information (val_1) up to def. valt_ar to continue calculate..

------------------------------------

Expand|Select|Wrap|Line Numbers
  1. from time import*
  2. import time
  3.  
  4.  
  5. class Kalender:
  6.     # Kalendern=objektet
  7.     def __init__(self, ar, manad):
  8.         self.ar=ar
  9.         self.manad=manad
  10.  
  11.     # Räknar ut hur många år från år 1900 samt hur många dagar det är från 1 jan
  12.     def valt_ar(ar): 
  13.         beraknat_ar=ar-1900
  14.  
  15.         beraknade_dagar=365*int(beraknat_ar)
  16.         return (beraknade_dagar)
  17.  
  18.  
  19.  
  20. # Frågar personen vilket år han/hon vill se kalendern
  21. val_1=int(input("Ange vilket år du vill titta på: " ))
  22. val_2=float(input("Ange måndad:   "))
  23.  
  24. beraknat_totalt_dagar=Kalender.valt_ar(self,valt_ar,manad)
Oct 23 '12 #1
Share this Question
Share on Google+
3 Replies

P: 2
Hi Meetee. Sorry I dont understand what you mean...
Oct 23 '12 #2

Meetee
Expert Mod 100+
P: 931
When you paste code, please click <code/> button around your code to format your post as per site policy.
Oct 23 '12 #3

Expert 100+
P: 626
You have to first create an instance of the class. You then work with the class instance as the class is just a prototype and does nothing until an instance is created. Note that valt_ar and manad have not been declared in the code you posted but you did not include the complete error message so there is no way to know if that is the Type Error or not.
Expand|Select|Wrap|Line Numbers
  1. class Kalender:
  2.      # Kalendern=objektet
  3.      def __init__(self, ar, manad):
  4.          self.ar=ar
  5.          self.manad=manad
  6.          print self.ar, self.manad
  7.  
  8.      # Räknar ut hur många år från år 1900 samt hur många dagar det är från 1 jan
  9.      def valt_ar(self): 
  10.          beraknat_ar=self.ar-1900
  11.          beraknade_dagar=365*int(beraknat_ar)
  12.          return (beraknade_dagar)
  13.  
  14.  
  15.  
  16. # Frågar personen vilket år han/hon vill se kalendern
  17. val_1=int(input("Ange vilket år du vill titta på: " ))
  18. val_2=float(input("Ange måndad:   "))
  19.  
  20. Kal=Kalender(val_1, val_2)
  21. print Kal.valt_ar() 
Oct 23 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.