当前位置: 首页>>代码示例>>Python>>正文


Python FileIO类代码示例

本文整理汇总了Python中FileIO的典型用法代码示例。如果您正苦于以下问题:Python FileIO类的具体用法?Python FileIO怎么用?Python FileIO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FileIO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

def main(trainMode, binarized, testDir, resultFile):
    dir1 = r'R:\masters\fall2013\COMP579A\project\aclImdb\train\pos';
    dir2 = r'R:\masters\fall2013\COMP579A\project\aclImdb\train\neg';
    corpusName = r'corpus\binCorpus.txt';
    if(not binarized):
        corpusName = r'corpus\corpus.txt';
    if(trainMode):
        if(binarized):
            buildBinarizedCorpus(dir1, corpusName);
            buildBinarizedCorpus(dir2, corpusName);
        else:
            buildCorpus(dir1, corpusName);
            buildCorpus(dir2, corpusName);
    
    dictionary = loadCorpus(corpusName);
    testText = '';
    print('test for dir' , testDir);
    for dir_entry in os.listdir(testDir):
        if binarized:
            testText = getBinTestText(os.path.join(testDir, dir_entry));
        else:
            testText = getTestText(os.path.join(testDir, dir_entry));
        result =test(testText, dictionary);
        FileIO.wrtieToFile(resultFile, 'a' ,"The file " + os.path.join(testDir, dir_entry) + " is classified as " + result + "\n");
    print("Done....");
开发者ID:ambikab,项目名称:SentimentAnalysis,代码行数:25,代码来源:Analyzer.py

示例2: login

def login(home_path, today, file_write = 0):
	try :



		(ok, login_l, other_l) =  login_list(os.path.join(home_path,'.ac_info'))

		if not ok : return (0, home_path + '  ' + l)

		#(1, [('20051010', '20051010'), ('20051012', '20051015')], [])

		(ok, r) = _login(login_l, today)

		if not ok : 
			return (0, r)

		login_l2 =  login_format(r)

		reply = join_list(login_l2, other_l)

		i = len(login_l2) - len(login_l)
		log  = '%s %d  row added' % ( os.path.join(home_path,'.ac_info'), i)

		if( not os.path.exists(home_path)) : 
			return (0, reply, home_path + ' not exists') 

		if (file_write) :
			FileIO.write(os.path.join(home_path,'.ac_info'), reply)
			
		return (1, reply, log)
		
	except :
		t, v, tb = sys.exc_info()
		print 'login exception... (%s:%s)' % (t, v)
		return (0, log , log)
开发者ID:iloveaired,项目名称:nbviewer,代码行数:35,代码来源:AQUtil.py

示例3: FileIO_test

def FileIO_test():

	data ="1\n2\n3\n4\n"

	rt = FileIO.write('WRITE_TEST', data, 'w') 
	assert(rt == 0)


	c_list = []
	(rt, c_list) = File.read("WRITE_TEST", 3)
	assert(rt == 0)
	assert(len(c_list) == 3)

	# 0 이면 all line -> list 로
	(rt, c_list) = FileIO.read("WRITE_TEST", 0)
	assert(rt == 0)
	assert(len(c_list) == 4)

	list = []
	list.append('AA')
	list.append('BB')

	rt = FileIO.write('TEST01', list)
	assert(rt == 0)

	(rt, c_list) = FileIO.read("TEST01", 2)

	assert(rt == 0)
	assert(len(c_list) == 2)



	return
开发者ID:iloveaired,项目名称:nbviewer,代码行数:33,代码来源:lib_test.py

示例4: main

def main(*arguements):

    # --------------------------------------------------------
    # Parse command line, to fetch session input file
    # --------------------------------------------------------
    if len(sys.argv) >= 2:
        ripFilePath = sys.argv[1]

        # If user did not specify .rip file
    else:
        print "User must specify input file name (e.g., at command line type GARM.py user_input.rip)."
        sys.exit(-1)

        # If .ip file does not exist
    if not os.path.exists(ripFilePath):
        print ("Cannot find or open runtime inputs file(%s)" % (ripFilePath))
        sys.exit(-1)

    dir = "tree100perlandscape/"

    # bird_types = ['St','Mu','Gl','Cr','Ax',Sh,Tu
    # Skipped Du, Re, Ru
    bird_types = ["Ha"]
    file_types = ["_tree_100_1_10.asc", "_tree_100_1_100.asc"]
    # file_types = ['_tree_100_1_2.asc','_tree_100_1_5.asc','_tree_100_1_10.asc','_tree_100_1_100.asc']
    grid_file_out = "aus_bird_unicor.rip"
    for bird in bird_types:
        for type in file_types:
            print "now running " + bird + type
            header_dict, data = FileIO.loadFile(ripFilePath, header_lines=16)
            header_dict["XY_Filename"] = str(bird + "_XY.csv")
            header_dict["Grid_Filename"] = str(dir + bird + type)
            header_dict["Session_label"] = bird + "_type"
            FileIO.outputGrid(grid_file_out, ["null", "null"], header_dict=header_dict)
            cd_matrix = RunUNICOR(grid_file_out)
开发者ID:ComputationalEcologyLab,项目名称:UNICOR,代码行数:35,代码来源:unicor_script.py

示例5: writeCustomToFile

def writeCustomToFile(customPrograms, customName):
    '''Store custom application information'''
    tempDir = tempfile.gettempdir()
    tempLocation = os.path.join(tempDir,'AssetManagerTemp')
    tempLocation = os.path.join(tempLocation,'CustomMenuItems.ini')    
    data = '#Custom Application:'
    section = ['CustomPrograms', 'CustomName']
    key = ['Programs', '\n', 'Names']
    value = []
    for item in customPrograms:
        value.append(item)
    value.append('\n')
    for item in customName:
        value.append(item)
    data = FileIO.build(data, section, key, value)
    FileIO.write(data, tempLocation)
开发者ID:burninghelix123,项目名称:AssetManager,代码行数:16,代码来源:OpenAsset.py

示例6: ktf_notify

def ktf_notify(id) :
	try :

		
		ok , path =  home_fullpath(id)

		if not os.path.exists(os.path.join(path, '.ktf_notify')) :  return (0, '','',[])

		ok, lines = FileIO.read(os.path.join(path, '.ktf_notify'))
		if not ok : return (0, '','',[])
		
		hash = TokenList.decode(lines[0].rstrip())

		email_list = []
		for line in lines[1:] :
			email_list.append(line.rstrip())

		return (1, hash['level'],  hash['type'] , email_list) 


	except :
		t, v, tb = sys.exc_info()
		log = 'ktf_notify(%s:%s)' % (t, v)
		print log
		return (0, '','',[])
开发者ID:iloveaired,项目名称:nbviewer,代码行数:25,代码来源:KTFUtil.py

示例7: login_list

def login_list(file) :
	try :

		(ok, lines) = FileIO.read(file)
		reply = []
		other_l = []
		for line in lines :
			try :
				#NOT FOUND
				if line.find('LOGIN\t') == -1 :
					other_l.append(line.rstrip())
					continue

				# LOGIN \t A:B
				(dummy, login_date)  = line.rstrip().split('\t')

				(sdate, edate) = login_date.split(':')
				reply.append((sdate, edate))
			except :
				pass
		return (1, reply, other_l)
	except :
		t, v, tb = sys.exc_info()
		log = 'login list ex... (%s:%s)' % (t, v)
		return (0, log ,log)
开发者ID:iloveaired,项目名称:nbviewer,代码行数:25,代码来源:AQUtil.py

示例8: __init__

 def __init__(self, busName, fileBufferSize, bitResolution, upLimit=None, loLimit=None, p2pShrink=None):
     self.busName = busName
     self.fileBufferSize = fileBufferSize
     self.bitResolution = bitResolution
     self.upLimit = upLimit
     self.loLimit = loLimit
     self.p2pShrink = p2pShrink
     self.fileIO = FileIO()
开发者ID:Maxfooo,项目名称:WaveformBitVectorGen,代码行数:8,代码来源:GenerateSinusoid.py

示例9: test

def test(testText, dictionary):
    classCntTxt = FileIO.readFile('corpus\classCount.txt');
    classCnt = {};
    for line in classCntTxt.split('\n'):
        statistics = line.split('\t');
        if len(statistics) > 1:
            classCnt[statistics[0]] = statistics[1];
    return Classifier.naiveBayes(dictionary, classCnt, testText);
开发者ID:ambikab,项目名称:SentimentAnalysis,代码行数:8,代码来源:Analyzer.py

示例10: saveCenters

def saveCenters(doOnlyFulls = False, trainingFolder = '../data/nicicon/csv/train/csv/' , suffix = '_train.csv', savePath = '../data/newMethodTraining/allCentersNic.csv'):
    """This file computes representatives of classes in the nicicon database and saves it to  the ./data/csv/allCentersNic.csv"""

    files = ['accident','bomb','car','casualty','electricity','fire','firebrigade','flood','gas','injury','paramedics', 'person', 'police','roadblock']
    centerSet  = []
    my_names = []
    my_isFull = []
    f = FileIO()


    extr_train = Extractor(trainingFolder)
    train_features, \
    train_isFull, \
    train_classId, \
    train_names = extr_train.loadniciconfolders()

    for mfile in files[:]:
        #Get every instance in the given class
        names, isFull, features = f.load(trainingFolder + mfile + '/' + mfile + suffix)

        #Initialise centers as 0
        nowCenter = np.zeros(len(features[0]))

        if not doOnlyFulls:
            #Use every full and partial instance in the class and sum them
            totalNumOfInstances = len(features)
            for instance in features:
                nowCenter += instance
        else:
            #Use only full instances in the class and sum them
            totalNumOfInstances = 0
            for i in range(len(features)):
                if isFull[i] == True:#Check the prints to see if this works fine (See if the totalNumOfInstances is meaningful
                    nowCenter+=features[i]
                    totalNumOfInstances+=1

        print mfile,'Used ', totalNumOfInstances, 'of instances to find the class center'

        nowCenter = nowCenter/totalNumOfInstances

        centerSet.append(nowCenter)#Add the mean feature vector for this representative
        my_names.append(mfile)#The name of the representative
        my_isFull.append(0)#Just set anything, not necessary for class representative
    f.save(my_isFull,my_names,centerSet,savePath)
开发者ID:ozymaxx,项目名称:sketchautocompletion,代码行数:44,代码来源:centersNic.py

示例11: loadCorpus

def loadCorpus(corpusName):
    dictionary = {};
    fileText = FileIO.readFile(corpusName);   
    for line in fileText.split('\n'):
        words = line.split('\t');
        if len(words) > 2:
            if words[0] not in dictionary:
                dictionary[words[0]] = {};
            dictionary[words[0]][words[2]] = words[1];        
    return dictionary; 
开发者ID:ambikab,项目名称:SentimentAnalysis,代码行数:10,代码来源:Analyzer.py

示例12: getBinTestText

def getBinTestText(fileName) :
    fileText = FileIO.readFile(fileName); 
    tokens = Tokenizer.tokenizer(fileText);
    wordOccurence = {};
    resultTokens = "";
    for token in tokens.split("\n"):
        if token not in wordOccurence:
            wordOccurence[token] = 1;
            resultTokens = resultTokens + token + "\n";
    return resultTokens;
开发者ID:ambikab,项目名称:SentimentAnalysis,代码行数:10,代码来源:Analyzer.py

示例13: Part2

def Part2(createData):
    # optical flow and motion direction histogram calculation
    v = 100

    # mdh_all = OM.createMotionDirectionHistograms('Oberstdorf16-shots.csv', 'videos/oberstdorf16.mp4', v, False, True)
    # FileIO.save_histograms_to_file('mdh_16_' + str(v) + '.csv', mdh_all)

    if createData:
        SVM.save_shot_images('videos/oberstdorf16.mp4', SVM.SSI_CENTER, 'Oberstdorf16-shots.csv', False)

    #svm training and predicting
    mdh_training = FileIO.read_histograms_from_file('mdh_8_' + str(v) + '.csv')
    mdh_test = FileIO.read_histograms_from_file('mdh_16_' + str(v) + '.csv')
    predicted_labels = SVM.svm_use(mdh_training, mdh_test)

    stitched_shots, all_shots, outstitched_shots = SVM.get_results(
        predicted_labels, 'Oberstdorf16-shots.csv', True)


    return stitched_shots, all_shots, outstitched_shots
开发者ID:zexe,项目名称:video_ret_proj1,代码行数:20,代码来源:Part2.py

示例14: load_fasta_background

def load_fasta_background(filename, center='.'):
    fasta_list = FileIO.read_fasta(filename);
    result = fasta_to_chunks(fasta_list);
    
    if(center != '.'):
        result = filter_chunks(result, center);
        
    result = result[0:300000]; #Concatenate because I don't have enough ram    
    formA = DataManipulation.list_to_formA(result);
    
    return dict([('seq',result),
                 ('formA',formA)]);
开发者ID:deto,项目名称:KinaseBinding,代码行数:12,代码来源:ProcessBackground.py

示例15: writePRJ

 def writePRJ(self):
     if len(self.matrices.keys()) != 0:
         self.processMatrices()
     self.prjInfo['data'] = self.projPrefix
     if self.arc == 1:
         self.prjInfo['gis'] = self.projPrefix
         self.prjInfo['projection'] = self.map.projectionName
         self.setScreenInfo()
     if self.prj == 1:
         gisFile = OS.path.join(self.originalDir,self.gisFileMain+".gis")
         if self.originalPrefix != self.projPrefix:
             newGIS = OS.path.join(self.projectDir,self.projPrefix+".gis")
             self.copyFile2File(gisFile,newGIS)
         else:
             gisFile = OS.path.join(self.originalDir,self.gisFileMain+".gis")
             self.copyFile2Dir(gisFile,self.projectDir)
         self.prjInfo['gis'] = self.projPrefix
     self.prjInfo['main'] = self.createOutputFile(self.projPrefix, ".prj")
     FIO.projWriter(self.prjInfo)
开发者ID:DiFang,项目名称:stars,代码行数:19,代码来源:ProjectWorker.py


注:本文中的FileIO类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。