我想提升课程,pathlib.Path但上面的简单例子不起作用.
from pathlib import Path
class PPath(Path):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
test = PPath("dir", "test.txt")
Run Code Online (Sandbox Code Playgroud)
这是我的错误消息.
Traceback (most recent call last):
File "/Users/projetmbc/test.py", line 14, in <module>
test = PPath("dir", "test.txt")
File "/anaconda/lib/python3.4/pathlib.py", line 907, in __new__
self = cls._from_parts(args, init=False)
File "/anaconda/lib/python3.4/pathlib.py", line 589, in _from_parts
drv, root, parts = self._parse_args(args)
File "/anaconda/lib/python3.4/pathlib.py", line 582, in _parse_args
return cls._flavour.parse_parts(parts)
AttributeError: type object 'PPath' has no attribute '_flavour'
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
以下代码不会在第一次exit 1调用时退出error_exit。我缺少什么?
#!/bin/bash
THIS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
JINJANG_DIR="$(cd "$THIS_DIR/../.." && pwd)"
DATAS_DIR="$THIS_DIR/datas"
error_exit() {
echo ""
echo "ERROR - Following command opens the file that has raised an error."
echo ""
echo " > open \"$1\""
exit 1
}
cd "$DATAS_DIR"
find . -name 'datas.*' -type f | sort | while read -r datafile
do
localdir="$(dirname $datafile)"
echo " * Testing ''$localdir''."
filename=$(basename "$datafile")
ext=${filename##*.}
if [ "$ext" == "py" ]
then
unsafe="-u"
else
unsafe="" …Run Code Online (Sandbox Code Playgroud) 该命令git log -1提供有关上次提交的信息。我只对号码 id 感兴趣。可以git 给我这个,还是我必须对输出使用基本解析(我知道该怎么做)?
> git log -1
commit abcdefgh123456789000 (HEAD -> master, origin/master)
Author: ...
...
Run Code Online (Sandbox Code Playgroud)