SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2010
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Python: What are each line in this code doing?

    I have been tearing this code apart and putting it back together.
    I understand some of the concept but not all of them.

    Can you please tell me what each line in this code does?

    Code:
    class Site(object):
    def __init__(self, SiteNum="0", SiteAddr="", SiteInv=0):
    self.ID=SiteNum
    self.Addr=SiteAddr
    self.__Inv=int(SiteInv)
    def getInv(self):
    return self.__Inv
    def setInv(self, items):
    self.__Inv=int(items)
    Inventory=property(getInv, setInv)
    class Store(Site):
    
    def Sale(self, items):
    itemCnt=int(items)
    self.Inventory -= itemCnt
    class Whse(Site):
    
    def Recv(self, items):
    itemCnt=int(items)
    self.Inventory += itemCnt
    store1=Store(SiteNum="001", SiteAddr="456 Elm St", SiteInv=1000)
    wh1=Whse(SiteNum="002", SiteAddr="789 Maple St", SiteInv=20000)
    Thanks everyone!

    Novice

  2. #2
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to fix the Tabs, it wont work like this

  3. #3
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im not more than a beginner in python but here's some of it (as i think it should be tabbed) if something is wrong someone else can hopefully point that out.

    Code Python:
    class Site(object):
        #Defines the __init__ method, makes you Site object be 
    able to take in a few arguments
        #Default values are set if non are supplied
        def __init__(self, SiteNum="0", SiteAddr="", SiteInv=0):
            #Sets the ID and Addr to submitted values
            self.ID=SiteNum
            self.Addr=SiteAddr
            #Sets the private variable __Inv to the supplied value of SiteInv converting it to int
            self.__Inv=int(SiteInv)
     
            #Method that returns private var __Inv
        def getInv(self):
            return self.__Inv
     
            #Method used to set the private var __Inv, takes the argument items
        def setInv(self, items):
            #Sets the variable
            self.__Inv=int(items)
     
        #Sets the property attribute, insteed of using x.getInv(), you can use x.getInv
        #[url]http://docs.python.org/library/functions.html#property[/url]
        Inventory=property(getInv, setInv)
     
    #Class 创Store创 which extends 创Site创
    class Store(Site):
     
        def Sale(self, items):
            itemCnt=int(items)
            self.Inventory -= itemCnt
     
    #Class 创Whse创 which extends 创Site创
    class Whse(Site):
        def Recv(self, items):
            itemCnt=int(items)
            self.Inventory += itemCnt
     
    #Creates a new Store object taking i initial values
    store1=Store(SiteNum="001", SiteAddr="456 Elm St", SiteInv=1000)
    wh1=Whse(SiteNum="002", SiteAddr="789 Maple St", SiteInv=20000)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •