当前位置: 首页>>代码示例>>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;未经允许,请勿转载。