def main(): loginTime=0 #登陆次数计数 print "请选择你要登陆的用户" result = input("1:老师\t2:学生\t3:管理员\n您是:") while not login(result): loginTime = loginTime+1 if loginTime>3: #超过3次就退出 print "您输入错误的次数大于3次," input("按任意键退出") exit(0) Interface() #界面函数
def download_tract_data(state_id, puma_id, output_dir, census_api_key, puma_tract_mappings, households_data, persons_data): '''Download tract data from the US Census' API. Initilize an allocator, capable of allocating PUMS households as best as possible based on marginal census (currently tract) data using a cvx-solver. Args: state_id: 2-digit state fips code puma_id: 5-digit puma code output_dir: dir to write outWriter the generated bayesian nets to census_api_key: key used to download data from the U.S. Census puma_tract_mappings: filepath to the puma-tract mappings households_data: pums households data frame persons_data: pums persons data frame Returns: An allocator described above. ''' marginal_path = os.path.join( output_dir, FILE_PATTERN.format(state_id, puma_id, 'marginals.csv')) try: # Already have marginals file marginals = Marginals.from_csv(marginal_path) except Exception: # Download marginal data from the Census API with builtins.open(puma_tract_mappings) as csv_file: csv_reader = csv.DictReader(csv_file) marginals = Marginals.from_census_data(csv_reader, census_api_key, state=state_id, pumas=puma_id) if len(marginals.data) <= 1: logging.exception( 'Couldn\'t fetch data from the census. Check your API key') raise CensusFetchException() else: logging.info( 'Writing outWriter marginal file for state: %s, puma: %s', state_id, puma_id) marginals.write(marginal_path) '''With the above marginal controls (tract data), the methods in allocation.py allocate discrete PUMS households to the subject PUMA.''' try: allocator = HouseholdAllocator.from_cleaned_data( marginals=marginals, households_data=households_data, persons_data=persons_data) except Exception as e: logging.exception('Error Allocating state: %s, puma: %s\n%s', state_id, puma_id, e) __builtin__.exit() return marginals, allocator
def visualize_tree(tree, feature_names): """Create tree png using graphviz. Args ---- tree -- scikit-learn DecsisionTree. feature_names -- list of feature names. """ with open("dt.dot", 'w') as f: export_graphviz(tree, out_file=f, feature_names=feature_names) command = ["dot", "-Tpng", "dt.dot", "-o", "dt.png"] try: subprocess.check_call(command) except: exit("Could not run dot, ie graphviz, to produce visualization")
try: if sys.platform.startswith('win32'): libEDK = cdll.LoadLibrary("../../bin/win64/edk.dll") elif sys.platform.startswith('linux'): srcDir = os.getcwd() if platform.machine().startswith('arm'): libPath = srcDir + "/../../bin/armhf/libedk.so" else: libPath = srcDir + "/../../bin/linux64/libedk.so" libEDK = CDLL(libPath) else: raise Exception('System not supported.') except Exception as e: print 'Error: cannot load EDK lib:', e exit() global arrayFinalPerformance global arrayFinalPowerBand global tipoEstudio global arrayData global v global animationBandpower global animationPerformance global contadorPowerBand global fig global fig1 global ax1 global ax2 global line global root
try: if sys.platform.startswith('win32'): libEDK = cdll.LoadLibrary("../../bin/win32/edk.dll") elif sys.platform.startswith('linux'): srcDir = os.getcwd() if platform.machine().startswith('arm'): libPath = srcDir + "/../../bin/armhf/libedk.so" else: libPath = srcDir + "/../../bin/linux64/libedk.so" libEDK = CDLL(libPath) else: raise Exception('System not supported.') except Exception as e: print 'Error: cannot load EDK lib:', e exit() IEE_EmoEngineEventCreate = libEDK.IEE_EmoEngineEventCreate IEE_EmoEngineEventCreate.restype = c_void_p eEvent = IEE_EmoEngineEventCreate() IEE_EmoEngineEventGetEmoState = libEDK.IEE_EmoEngineEventGetEmoState IEE_EmoEngineEventGetEmoState.argtypes = [c_void_p, c_void_p] IEE_EmoEngineEventGetEmoState.restype = c_int IEE_EmoStateCreate = libEDK.IEE_EmoStateCreate IEE_EmoStateCreate.restype = c_void_p eState = IEE_EmoStateCreate() userID = c_uint(0) user = pointer(userID)
def ok_print(self, format, *args, **kargs): print self.OK+format.format(*args,**kargs)+self.ENDC def warn_print(self, format, *args, **kargs): print self.WARNING+format.format(*args,**kargs)+self.ENDC def fail_print(self, format, *args, **kargs): print self.FAIL+format.format(*args,**kargs)+self.ENDC class Main(object): def __init__(self,args=None): op = optparse.OptionParser( usage="%prog [options] input+") op.add_option( '--output', help="type of output to generate" ) ( opt, inputs ) = op.parse_args(args) bop = BuildOutputProcessor(inputs) output = None if opt.output == 'console': output = BuildConsoleSummaryReport(bop, opt) if output: output.generate() self.failed = output.failed if __name__ == '__main__': m = Main() if m.failed: exit(-1)
from __builtin__ import AssertionError from __builtin__ import exit from __builtin__ import int from __builtin__ import ord from __builtin__ import range from __builtin__ import tuple from pyparse.parser import ParserSkeleton from pyparse.util import IndexToAttrMixin from pyparse.util import println try: assert False # assert must work println( 'the assert statement does not work, disable optimizations to fix this' ) exit(1) except AssertionError: pass class Utf8Parser(ParserSkeleton): """ Parse utf8 bytes. codepoints - yields codepoints from bytes TODO what to do with multiple representions of the same codepoint? TODO graphemes? """ HIGH_0 = int('00000000', 2) HIGH_1 = int('10000000', 2)
# ******************************************************** #Receive MIDI print '[ImageSource] Using receiveDatabySize to receive: '+midi_data[1]+' bytes of '+midi_data[0] data_received = tcpServer.receiveDataBySize(int(midi_data[1])) f = open(midi_data[0],"w") f.write(data_received) f.close() print '[ImageSource] Created file '+midi_data[0]+' with the data received by TCP.' # ******************************************************** #Close TCP socket tcpServer.closeTCPServer() print '[ImageSource] TCPServer closed' # ******************************************************** #If transfer has finished, Close TCP socket else: print >>sys.stderr,'[ImageSource] Server did not receive image data. It returned: ',ret except: print sys.exc_info()[0] finally: print >>sys.stderr, '[ImageSource] Exiting Program' try: udpClient.closeUDPclient() tcpClient.closeTCPclient() tcpServer.closeTCPServer() except: print sys.exc_info()[0] exit()
Created on 19/08/2014 @author: jacekrad ''' from sequence import * from prob import * from __builtin__ import exit from sys import stderr from spred import slidewin prot = readFastaFile('prot2.fa', Protein_Alphabet) sstr = readFastaFile('sstr3.fa', DSSP3_Alphabet) if len(prot) != len(sstr): stderr.write("prot2.fa contains different number of sequences than sstr3.fa\n") exit(1) # index i = 0 for protein in prot: secondary_structure = sstr[i] i += 1 # make sure the name is the same for both protein # and its secondary structure entry if protein.name != secondary_structure.name: stderr.write(protein.name + " and " + secondary_structure.name \ + " are not the same where they should be\n") # check each amino acid and the corresponding secondary structure if len(protein.sequence) != len(secondary_structure.sequence): stderr.write(protein.name + " and it's secondary structure sequence " + " differ in length: " + str(len(protein.sequence)) \
tcpClient = TCPClient(imageSource_addr[0],TCP_PORT,BUFFER_SIZE) tcpClient.connectTCP() print '[MidiSource] TCP Client ready to send the MIDI' #tcpClient.sendFileByNameAndClose(imgname) # ******************************************************** #Send Image tcpClient.sendDataBySize(midi.read(), size) # ******************************************************** #Close TCP socket tcpClient.closeTCPclient() print '[MidiSource] TCPClient closed' # ******************************************************** #Send MIDI # ******************************************************** #If transfer has finished, Close TCP socket except: print sys.exc_info()[0] #raise finally: print >>sys.stderr, '[MidiSource] Exiting Program' try: udpServer.closeUDPserver() tcpServer.closeTCPServer() tcpClient.closeTCPclient() except: print sys.exc_info()[0] #raise exit(0)