首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UnboundLocalError:在赋值fetchProcess错误之前引用了局部变量'ext‘

UnboundLocalError:在赋值fetchProcess错误之前引用了局部变量'ext‘
EN

Stack Overflow用户
提问于 2019-10-24 08:54:07
回答 1查看 55关注 0票数 0

我正在尝试获取和处理数据,我创建了两个函数fetch(),fetchProcess() fetch()如下所示

代码语言:javascript
复制
def fetch():
    root= tk.Tk()
    root.withdraw()
    filepath =filedialog.askopenfilename(filetypes = (("trace files","*.din"),("out files",".out")))
    file=open(filepath)
    file_path = file.name
    ext= os.path.splitext(file_path)
    print(ext[1])
    readData=file.readlines()
    print("Enter the inputs in following order: cache size only integer(no kb),block size, associativity, cache type=1 for combined and 0 for split,prefetcher buffer size,confidence")
    print("for example: python main.py 32 8 1 0 1 2")
    cacheSize= int(sys.argv[1]) #multiply by 1024 to convert into KB
    cacheSize = cacheSize*1024
    blockSize = int(sys.argv[2]) #For block size
    associativity= int(sys.argv[3]) #for associativity
    cacheType= int(sys.argv[4]) #for cache type 1 for combined and 0 for split
    prefetchBuffer= float(sys.argv[5])
    prefetchBuffer=prefetchBuffer*1024
    confidence= int(sys.argv[6])

    # read line and split data and other intialization
    cacheArray = [[0] * associativity] * int(cacheSize / (blockSize * associativity))  #declaring list for cache array 
    lruArray = [[0] * associativity] * int(cacheSize / (blockSize * associativity))  # declaring list for lru
    instr=[] # declaring list for seperate instruction and data cache
    data=[]
    combined=[] # declaring list for combined cache
    prefetch=[]*int(prefetchBuffer) # declaring list for prefetch buffer
    missData =[]
    return ext,readData,cacheSize,blockSize,associativity,cacheType,prefetchBuffer,confidence,cacheArray,lruArray,instr,data,combined,prefetch,missData

fetchProcess代码如下:

代码语言:javascript
复制
def fetchProcess():
    ext,readData,cacheSize,blockSize,associativity,cacheType,prefetchBuffer,confidence,cacheArray,lruArray,instr,data,combined,prefetch,missData=fetch(ext,readData,cacheSize,blockSize,associativity,cacheType,prefetchBuffer,confidence,cacheArray,lruArray,instr,data,combined,prefetch,missData)
    for read in readData:
        split = read.split(' ')
    if ext[1] ==".din":
        label = int(split[0], 10) 
        addr = int(split[1], 16) # convert hexadecimal to decimal
        switch(label)

        return addr
    else:
        addr = int(data[2], 16)
        data.append(addr)
        return addr
        # if count == 4000000:  # limiting the iteration to 4 million as mentioned in the question
        #     # break

最后,我逐个调用fetch()等函数,然后调用fetchProcess();但它给我的错误是UnboundLocalError:在赋值之前引用的局部变量'ext‘。我是python新手,有人能帮我改正错误吗?谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-24 11:44:19

fetchProcess函数中,您需要调用

ext,readData,cacheSize,blockSize,associativity,cacheType,prefetchBuffer,confidence,cacheArray,lruArray,instr,data,combined,prefetch,missData=fetch()

ext,readData,cacheSize,blockSize,associativity,cacheType,prefetchBuffer,confidence,cacheArray,lruArray,instr,data,combined,prefetch,missData=fetch(ext,readData,cacheSize,blockSize,associativity,cacheType,prefetchBuffer,confidence,cacheArray,lruArray,instr,data,combined,prefetch,missData)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58532711

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档