模块“UseCvs”没有属性“switch”

2024-03-28 15:35:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我在“useCv.py”中写了“switch”模块,但它一直说“module'useCv'没有属性'switch”

[我的代码]

>>> import os, re, usecsv
>>> os.chdir(r'/Users/macbookrocks/Downloads/practice')
>>> total = usecsv.opencsv('popSeoul.csv')
>>> newPop = usecsv.switch(total)
Traceback (most recent call last):
File "<pyshell#33>", line 1, in <module>
newPop = usecsv.switch(total)
NameError: name 'usecsv' is not defined

----------[usecsv.py]------------

import csv, os
def opencsv(filename):
    f = open(filename, 'r')
    reader = csv.reader(f)
    output = []
    for i in reader:
        output.append(i)
    return output

def writecsv(filename, the_list):
    with open(filename, 'w' , newline = '') as f:
        a = csv.writer(f, delimiter = ',')
        a.writerows(the_list)

def switch(listName):
    for i in listName:
        for j in I:
            try:
                i[i.index(j)] = float(re.sub(',' , '' , j))
            except:
                pass
    return listName