我很高兴这个问题已被问过多次,但没有一个答案能够帮助我。
我是终端工作新手,正在尝试在 MacOS Catalina 上使用 nvm 安装节点。我使用“brew install nvm”成功安装了 nvm,但是当我尝试运行“nvm install 10.15.0”时,出现错误“zsh:找不到命令:nvm”。
运行“brew info nvm”给了我这个:
You should create NVM's working directory if it doesn't exist:
mkdir ~/.nvm
Add the following to ~/.zshrc or your desired shell
configuration file:
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" # This loads nvm
[ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
You can set $NVM_DIR to any location, but leaving it unchanged from
/usr/local/opt/nvm will destroy any nvm-installed …Run Code Online (Sandbox Code Playgroud) 我正在尝试将管道分隔的文本文件转换为 CSV 文件,然后迭代并打印 CSV 文件。这是我的代码:
with open("...somefile.txt", "r") as text_file:
text_reader = csv.reader(text_file, delimiter='|')
with open("...somefile.csv", 'w') as csv_file:
csv_writer = csv.writer(csv_file, delimiter=',')
csv_writer.writerows(text_reader)
with open (csv_file, 'r') as f:
reader = csv.reader (f, delimiter=',')
for row in reader:
print(row)
Run Code Online (Sandbox Code Playgroud)
但是,我收到此错误消息:
----> 9 with open (csv_file, 'r') as f:
10 reader = csv.reader (f, delimiter=',')
11 for row in reader:
TypeError: expected str, bytes or os.PathLike object, not _io.TextIOWrapper
Run Code Online (Sandbox Code Playgroud)
谁能解释一下这是什么意思?
另外,如果我要把它变成一个函数,我怎样才能将文件名作为输入,然后更改文件以在转换为 csv 文件时添加 .csv 扩展名?
谢谢