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


Python Scanner.readtoken方法代码示例

本文整理汇总了Python中scanner.Scanner.readtoken方法的典型用法代码示例。如果您正苦于以下问题:Python Scanner.readtoken方法的具体用法?Python Scanner.readtoken怎么用?Python Scanner.readtoken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scanner.Scanner的用法示例。


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

示例1: buildMatrix

# 需要导入模块: from scanner import Scanner [as 别名]
# 或者: from scanner.Scanner import readtoken [as 别名]
def buildMatrix(fname, rows, cols):
   # Construct an empty matrix with specified rows and cols
   matrix = []
   for i in range(0, rows):
       matrixCols = []
       for i in range(0, cols):
           matrixCols.append(0)
       matrix.append(matrixCols)

   # Open the file using Scanner or File Pointer
   # scanner example from http://troll.cs.ua.edu/cs150/projects/practice1.html
   if (fname):
       s = Scanner(fname)
       
       # Read the data from each row into an array
       scannedArray = []
       token = s.readtoken()
       while token != '':
           scannedArray.append(token)
           token = s.readtoken()

       # Append the array onto the matrix
       for rowNumber in range(0, len(matrix)):
           for columnNumber in range(0, len(matrix[rowNumber])):
               if (len(scannedArray) > 0):
                   matrix[rowNumber][columnNumber] = scannedArray.pop(0)

       # Close the file
       s.close()

   return matrix
开发者ID:mdpatrick,项目名称:game_of_life,代码行数:33,代码来源:life.py

示例2: decode

# 需要导入模块: from scanner import Scanner [as 别名]
# 或者: from scanner.Scanner import readtoken [as 别名]
def decode(filename):
    x = Scanner(filename)
    line = x.readtoken()
    while (line != "%%"):
        line = x.readtoken()            # Skip the Header
    key = int(x.readtoken())    
    n = int(x.readtoken())              # Get the frequency and number of binary digits
    
    b_list = []
    for i in range(0,n,1):
        for j in range(0,key,1):
            line = x.readtoken()
        if int(line) % 2 == 0:           # Determine each binary digit and place it in an array   
            b_list.append(0)
        else:
            b_list.append(1)
    d_list = []    
    for i in range(0,int(n/7),1):
        s_list = []
        for j in range(0,7,1):              #split the digits into groups of seven and get their true number
            s_list.append(b_list[j])
        del b_list[0:7]
        d_list.append(binary_to_decimal(s_list))
    
    word = ''
    for i in range(0,len(d_list),1):
        d_list[i] = string.printable[d_list[i]]         # Use the numbers as an index in string.printable
        word+=d_list[i]                                 # to find the intended letter

    print("The message is: ", word)    
开发者ID:Saintroi,项目名称:CS250,代码行数:32,代码来源:Project3.py


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