运行此代码时出现错误。
func changeFilename() {
file, err := os.Open(".")
if err != nil {
log.Fatalf("failed opening directory: %s", err)
}
defer file.Close()
oldNames, _ := file.Readdirnames(0)
for _, i := range oldNames {
var s string
for _, j := range i {
if j != '-' {
s += string(j)
} else {
break
}
}
err := os.Rename(i, s)
if err != nil {
log.Fatal("failed to rename: %s", err)
}
}
}
成功返回一个import_csv
。问题出在<_csv.reader object at 0x10e1f8f50>
上,甚至无法使用文件。
有人看到我的代码有问题吗?
exclude_regex_users(name_entries)
这是我得到的错误:
def import_csv(csv_file):
with open(csv_file) as csvfile:
name_entries = csv.reader(csvfile)
return name_entries
def exclude_regex_users(name_entries):
pulled_names = []
r = re.compile(r'\w+\+\d+@trellis\.law')
for name in name_entries:
n = r.match(name)
if n:
pulled_names.append(n.group())
print(pulled_names)
def main():
name_entries = import_csv('users.csv')
exclude_regex_users(name_entries)