>>>print('You say:{0:r}'.format("i love you"))
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
print('You say:{0:r}'.format("i love you"))
ValueError: Unknown format code 'r' for object of type 'str'
Run Code Online (Sandbox Code Playgroud)
我只是%r(repr())在python2中使用,它应该在python3.5中工作.为什么?
此外,我应该使用什么格式?
我正在编写自己的 unix 脚本,因此我想为 Bash 添加一个新目录。我在 .bash_profile 中添加了这样的内容。
PATH="~/Documents:${PATH}"
export PATH
Run Code Online (Sandbox Code Playgroud)
在我的〜/ Documents中,有一个名为test的文件,其内容是
#!/usr/bin/env python3.5
print("hahahhah")
Run Code Online (Sandbox Code Playgroud)
我也用过
chmod 755 test
Run Code Online (Sandbox Code Playgroud)
使其可执行。
但我无法直接在终端中调用它。./test照常工作。什么地方出了错?
当我更改为
PATH="$HOME/Documents:${PATH}"
export PATH
Run Code Online (Sandbox Code Playgroud)
什么都没发生。
FDSM_lhn@9-53:~/Documents$ test
FDSM_lhn@9-53:~/Documents$ ./test
hahahhah
Run Code Online (Sandbox Code Playgroud)
解决方案:根本原因是我有一个与默认命令同名的命令,所以它无论如何都不起作用!改个名字就够了!