本文整理匯總了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)
示例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
'''
示例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
'''
示例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))
示例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=""
示例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()
示例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)
示例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()
示例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
示例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
示例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
示例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!")
示例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())
示例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__
示例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()=="}":