當前位置: 首頁>>代碼示例>>Python>>正文


Python Class類代碼示例

本文整理匯總了Python中Class的典型用法代碼示例。如果您正苦於以下問題:Python Class類的具體用法?Python Class怎麽用?Python Class使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Class類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: addClass

    def addClass(self,courseName,courseNumber,sessionNumber,credits,type,section, professorName,days,lecTime,roomNumber,campus,prereqs):
        #change parameters courseName & courseNumber to courseCode (basically fusing them together)
        #Type contains LEC,TUT,LAB/

        #incomplete

        classTime = self.convertTime(lecTime)
        name = str(courseName)+" "+str(courseNumber) #Ex. Concatenates ENGR + " " + 371 .
        newClass = Class(name,sessionNumber,type,section, professorName,days,classTime[0],classTime[1],roomNumber,campus,[])
        
        classNameArray = newClass.get_name().split(" ")
        courseList = self.courseMap.get(courseName)
       
        if(len(courseList)==0):
            self.courseMap.get(courseName).append(Course("Course Code",name,credits,prereqs,[newClass]))
            
        else:
            for i in xrange(0,len(courseList)):
                if(name == courseList[i].getCourseName()):
                    #Hit found in course list ("ENGR 371" == "ENGR 371"), therefore course exists.
                    #Proceed to appropriate tut or lab, or append new lecture to course
                    if(newClass.get_type() == "LEC"):
                        courseList[i].addClass(newClass)


                    if(newClass.get_type() == "TUT"):
                        #Will appropriate the tutorial to the correct lecture
                        #Compare the first letter of the lecture section to the first of the tut
                        # If they are the same, tutorial is appended to the lecture
                        lectureList = courseList[i].get_lectures()
                        for j in xrange(0,len(lectureList)):
                            if(lectureList[j].get_name()==classNameArray[0]):
                                lectureList[j].addClass(newClass)
                    if(newClass.get_type() == "LAB"):
                        lectureList = courseList[i].get_lectures()
                        for j in xrange(0,len(lectureList)):
                            lectureName = lectureList[j].get_name()
                            if(lectureName == classNameArray[0]):
                                if(lectureList[j].hasTutorial()==False):
                                    #Lecture doesn't have any tutorials, therefore lab is added
                                    #This situation doesn't happen often
                                    lectureList[j].addClass(newClass)
                                else:
                                    tutList = lectureList[j].get_section()
                                    for k in xrange(0,len(tutList)):
                                        tutName = tutList[k].get_name().split(" ")
                                        if(tutName[1] == classNameArray[1]):
                                            tutList[k].addClass(newClass)

                elif(i==(len(courseList)-1)):
                    #create Course and add it to map containing newClass
                    newCourse = Course("Course Code",name,credits,prereqs,[newClass])
                    self.courseMap.get(courseName).append(newCourse)
開發者ID:kazo0,項目名稱:SOEN341-Scheduler,代碼行數:53,代碼來源:CourseContainer.py

示例2: cost

def cost():  # minimize this
    result = 0

    for droppedClass in droppedClasses:
        result += droppedClass.getSize()
        
    for room in rooms:
        for key,Class in room.getClasses().items():
            overflow = (Class.getSize() - room.getSize()) * (Class.getLength() + 1)
            result += max(0, overflow) # add the number of students that don't fit, if any
    return result
    
    '''
開發者ID:tupl,項目名稱:classOpt,代碼行數:13,代碼來源:ICS169Proj.py

示例3: numConflicts

def numConflicts(): # meaningful objective function
    result = 0

    for droppedClass in droppedClasses:
        result += droppedClass.getSize()
        
    for room in rooms:
        for key,Class in room.getClasses().items():
            overflow = (Class.getSize() - room.getSize()) * Class.getLength()
            result += max(0, overflow) # add the number of students that don't fit, if any
    return result

    #pre class cost
    '''
開發者ID:tupl,項目名稱:classOpt,代碼行數:14,代碼來源:ICS169Proj.py

示例4: dumpQ

def dumpQ(u):
    qname, qtype, qclass = u.getQuestion()
    print
    'qname=%s, qtype=%d(%s), qclass=%d(%s)' \
    % (qname,
       qtype, Type.typestr(qtype),
       qclass, Class.classstr(qclass))
開發者ID:alanchavez88,項目名稱:theHarvester,代碼行數:7,代碼來源:Lib.py

示例5: __init__

 def __init__(self,charName,charRace,charClass):
     '''
     Creates the char and adopts race and class from
     the other objects
     '''
     self.charName=charName
     self.charRace=race(charRace)
     self.charClass=Class(charClass)
     self.charDescr=""
開發者ID:XarisA,項目名稱:myRPG,代碼行數:9,代碼來源:character.py

示例6: readHeader

def readHeader(header):
    file = open(header, "r")
    parsed_line = {}
    find_class = False

    for line in file.readlines():

        class_name = getClassName(line)
        if class_name:
            main_class = Class(header, class_name)
            find_class = True

        dic_method = parseLine(line)
        if dic_method and find_class:
            main_class.additem(Method(dic_method, main_class.name))

    if find_class:
        print("*" + "-" * 50 + "*")
        main_class.display()

    file.close()
開發者ID:vlnk,項目名稱:alienvspredator,代碼行數:21,代碼來源:functions.py

示例7: dumpRR

def dumpRR(u):
    name, type, klass, ttl, rdlength = u.getRRheader()
    typename = Type.typestr(type)
    print 'name=%s, type=%d(%s), class=%d(%s), ttl=%d' \
              % (name,
                 type, typename,
                 klass, Class.classstr(klass),
                 ttl)
    mname = 'get%sdata' % typename
    if hasattr(u, mname):
        print '  formatted rdata:', getattr(u, mname)()
    else:
        print '  binary rdata:', u.getbytes(rdlength)
開發者ID:tvelazquez,項目名稱:theharvester,代碼行數:13,代碼來源:Lib.py

示例8: map

	def map(self):
		import User
		User.init_db()
		import Campus
		Campus.init()
		import Class
		Class.init()
		import ClassRoom
		ClassRoom.init()
		import Course
		Course.init()
		import Cursus
		Cursus.init()
		import Event
		Event.init()
		import Period
		Period.init()
		import Planning
		Planning.init()
		import Settings
		Settings.init()
		import University
		University.init()
開發者ID:SBillion,項目名稱:timetableasy,代碼行數:23,代碼來源:db.py

示例9: storeRR

 def storeRR(self,u):
     r={}
     r['name'],r['type'],r['class'],r['ttl'],r['rdlength'] = u.getRRheader()
     r['typename'] = Type.typestr(r['type'])
     r['classstr'] = Class.classstr(r['class'])
     #print 'name=%s, type=%d(%s), class=%d(%s), ttl=%d' \
     #      % (name,
     #        type, typename,
     #        klass, Class.classstr(class),
     #        ttl)
     mname = 'get%sdata' % r['typename']
     if hasattr(u, mname):
         r['data']=getattr(u, mname)()
     else:
         r['data']=u.getbytes(r['rdlength'])
     return r
開發者ID:tvelazquez,項目名稱:theharvester,代碼行數:16,代碼來源:Lib.py

示例10: storeQ

 def storeQ(self,u):
     q={}
     q['qname'], q['qtype'], q['qclass'] = u.getQuestion()
     q['qtypestr']=Type.typestr(q['qtype'])
     q['qclassstr']=Class.classstr(q['qclass'])
     return q
開發者ID:tvelazquez,項目名稱:theharvester,代碼行數:6,代碼來源:Lib.py

示例11: load_class

def load_class(name):   #load class function creates a new class object and then loads all applicable students
    c = Class(name)    #instantiate class object
    c.students = list_users_array(name) # assign array of student names as strings to class object's 'students' attribute
    return c            #return class object with all applicable users - used in Console.py
開發者ID:av8ramit,項目名稱:excelerate,代碼行數:4,代碼來源:Commands.py

示例12: swap

                    swap((slotOrder1[slotIndex], roomOrder1[roomIndex]), (slotOrder2[slotIndex], roomOrder2[roomIndex]))
                else:
                    currentCost = newCost  # take it
                    if(currentCost < currentMin):
                        currentMin = currentCost
                        currentMinVector = copy.deepcopy(schedule)
                        '''
    # modify temp
    temp *= tempLoss

    # heartbeat
    # print(schedule)
    # printSchedule(rooms)
    print(currentCost, " : ", temp)

t1 = time.time()
printSchedule(rooms)
print(currentCost)
print("num conflicts: " + str(numConflicts()))
print("num dropped classes: " + str(len(droppedClasses)))
print("time: " + str(t1-t0))
for Class in droppedClasses:
    print(str(Class.getSize()) + " : " + str(Class.getLength()))


print("Lowest value reached (for debugging/testing):")

print(currentMin)

print("DONE!")
開發者ID:tupl,項目名稱:classOpt,代碼行數:30,代碼來源:ICS169Proj.py

示例13:

#!/bin/python3.5

import sys
sys.path.append('../class')
import Class


stone = Class.stone("pedone", 0x01, "file.grafic", "withe", "front", 0x02)
stone.display()

print (stone.move_stone())
開發者ID:killer11269,項目名稱:Shogi,代碼行數:11,代碼來源:main.py

示例14: list

#!/usr/bin/env python
#! -*- coding: utf-8 -*-
import math
print math.sin(0)
#導入模塊會相應地執行其中的代碼,同時模塊隻有在第一次導入的過程中才會被執行
import sys;sys.path.append('/Users/wangshaoyu/python/learn');import Class;
nested=[[1,2],[3,4],[5,6]]
#如何調用模塊中的方法,使用module.way
print list(Class.flatten(nested))
#__name__在主程序中__name__的值是__main__,而在模塊中,這個名字是模塊名如Class就是 Class
print __name__
#可以格式化的輸出,如果數據結構過大,不能一行打印完,可以使用pprint模塊中的pprint函數替代普通的print語句,
import pprint ;pprint.pprint(sys.path)
#解釋器在列表中查找需要的模塊,一開始sys.path就應該包含正確的目錄,有兩種方法可以保證係統搜索到你的目錄:
#第一種方法是將你的代碼放到合適的根目錄的位置,第二種方法是告訴解釋器去哪裏查找需要的模塊。
#標準的實現方法是在PYTHONPATH環境變量中包含模塊所在的目錄

#模塊的三種導入方式
#import drawing 這一條語句之後,__init__模塊的內容是可用的,
#import drawing.colors 這一條語句之後,可以通過全名drawing.colors來使用,
#from drawing import shapes 這一條語句之後,可以通過短名來使用 shapes
import copy
#print dir(copy) 
#可以使用dir來查看模塊中所有的函數、類、變量
print [n for n in dir(copy) if not n.startswith('_')]
#copy 包中可以使用的所有特性__all__
print copy.__all__
#help(copy.copy)
#查看模塊文檔 print copy.__doc__
#快速查找到源代碼的路徑 print copy.__file__
開發者ID:haidenayitou,項目名稱:knowledge,代碼行數:30,代碼來源:module.py

示例15: enumerate

prog.close()
newProg = []

mainBlock,mainClassBlock = Global.generate("main",code)

quote = False
func = False
clas = False
switch = False
Loop = False
Do = False
mainCode = []
for lineNum,line in enumerate(code):
    if lineNum==mainClassBlock[0]:
        clas = True
        funcNames = Class.generate("function names",code[lineNum+2:],Global.newClass().findName(line))
    elif lineNum==mainClassBlock[1]:
        newProg += [line for line in mainCode]
        clas = False
    elif lineNum==mainBlock[0]:
        func = True
    elif lineNum==mainBlock[1]:
        func = False
    else:
        if line[len(line)-1]=='\n':
            line = line[:len(line)-1]
        if quote:
            pass
        elif switch:
            if line.lstrip()=="{": pass
            elif line.lstrip()=="}":
開發者ID:Auzzy,項目名稱:personal,代碼行數:31,代碼來源:java2jy.py


注:本文中的Class類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。