本文整理汇总了Python中UtilFunc.fileLength方法的典型用法代码示例。如果您正苦于以下问题:Python UtilFunc.fileLength方法的具体用法?Python UtilFunc.fileLength怎么用?Python UtilFunc.fileLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UtilFunc
的用法示例。
在下文中一共展示了UtilFunc.fileLength方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pairDistance
# 需要导入模块: import UtilFunc [as 别名]
# 或者: from UtilFunc import fileLength [as 别名]
def pairDistance(fileInput, yearbookNamesFile):
#Input:
# pathInput: path of DIRECTORY with indexed list .csv files
# yearbookNamesFile: path to name reference FILE
# pathOutput: name of .csv output file
#Ouput:
# Returns a 2D list of name pairs
#Steps:
# 1) open indexedList
# 2) n^2 iterate over the list of indexed values, updating the 2D list of nameValues
# be careful not to inlude duplicate name-values and same name values
classSizeConst = 184; #need to make more general
classSize = UtilFunc.fileLength(yearbookNamesFile) - 1 # -1 for headers
if classSizeConst != classSize:
print '\n\n\n'
print 'WARNING WARNING: Class Size is {} which is not {}!!!! *****\n'.format(classSize,classSizeConst) * 3
print '\n\n'
# pairValues = [[0]*classSize]*classSize #initialize classSize x classSize list #makes an error, probably list copying :(
pairValues = [[0 for i in range(classSize)] for j in range(classSize)]
nameList = UtilFunc.parseDataFromFile(fileInput)
# with open(fileInput, 'r') as fIn:
# for index, line in enumerate(fIn):
# #Skip the heading
# if index > 0:
# (l0,l1,l2,l3,l4,l5,l6,l7) = line.replace('\r','').replace('\n','').split(',')
# nameList.append({'AlphaIndex':l0,'WrittenIndex':l1,'YearbookLast':l4,'YearbookFirst':l5})
for index1, entry1 in enumerate(nameList):
for index2, entry2 in enumerate(nameList):
if index1 != index2:
dim1 = entry1['AlphaIndex']
if dim1 == 'VERIFY':
continue
dim1 = int(dim1)
dim2 = entry2['AlphaIndex']
if dim2 == 'VERIFY':
continue
dim2 = int(dim2)
pos1 = entry1['WrittenIndex']
pos2 = entry2['WrittenIndex']
if pos1 == '-' or pos2 == '-':
continue
# if pos2 == '-':
# pos2 = classSize
pos1 = int(pos1)
pos2 = int(pos2)
pairValues[dim1][dim2] = 1/float(abs(pos1 - pos2))
# pairValues[dim2][dim1] = pairValues[dim1][dim2] #redundancy for ease of use
# print 'dim1: {}\tdim2: {}\tpairValues:{}'.format(dim1,dim2,pairValues[dim1][dim2])
return {'pairValues':pairValues}
示例2: sumPairDistance
# 需要导入模块: import UtilFunc [as 别名]
# 或者: from UtilFunc import fileLength [as 别名]
def sumPairDistance(pathInput, yearbookNamesFile):
#Input:
# pathInput: path of DIRECTORY with indexed list .csv files
# yearbookNamesFile: path to name reference FILE
# pathOutput: name of .csv output file
#Ouput:
# Returns a 2D list of name pairs
#Steps:
# 1) open indexedList
# 2) n^2 iterate over the list of indexed values, updating the 2D list of nameValues
# be careful not to inlude duplicate name-values and same name values
classSizeConst = 184; #need to make more general
classSize = UtilFunc.fileLength(yearbookNamesFile) - 1 # -1 for headers
if classSizeConst != classSize:
print '\n\n\n'
print 'WARNING WARNING: Class Size is ' + str(classSize) + ' which is not 184!!!! *****'
print 'WARNING WARNING: Class Size is ' + str(classSize) + ' which is not 184!!!! *****'
print 'WARNING WARNING: Class Size is ' + str(classSize) + ' which is not 184!!!! *****'
print '\n\n\n'
memValueSum = [{'score':0.0,'hits':0.0} for j in range(classSize)] #initialize values to zero
indexListing = os.listdir(pathInput)
participantCount = 0.0
for fileInput in indexListing:
if fileInput[0] == '.':
continue
else:
participantCount += 1
nameList = UtilFunc.parseDataFromFile(os.path.join(pathInput, fileInput))
for index1, entry1 in enumerate(nameList):
dim1 = entry1['AlphaIndex']
if dim1 == 'VERIFY':
continue
dim1 = int(dim1)
pos1 = entry1['WrittenIndex']
if pos1 == '-':
continue
pos1 = int(pos1) + 1
memValueSum[dim1]['score'] += 1/float(pos1)
memValueSum[dim1]['hits'] += 1
for index in range(len(memValueSum)):
try:
memValueSum[index]['score'] /= float(memValueSum[index]['hits'])
except ZeroDivisionError:
pass #if it's division by 0, then the score will be zero, but this is an assumption
return {'memValueSum':memValueSum}
示例3: test_fileLength_04
# 需要导入模块: import UtilFunc [as 别名]
# 或者: from UtilFunc import fileLength [as 别名]
def test_fileLength_04(self):
self.assertEqual( UtilFunc.fileLength(os.path.join(sys.path[0],'TestFiles/UtilFunc/fileLength4.txt')) , 2 )
示例4: test_fileLength_01
# 需要导入模块: import UtilFunc [as 别名]
# 或者: from UtilFunc import fileLength [as 别名]
def test_fileLength_01(self):
###TODO: determine if ending a file with '\n' means the blank line counts towards the file length
self.assertEqual( UtilFunc.fileLength(os.path.join(sys.path[0],'TestFiles/UtilFunc/fileLength1.txt')) , 5 )