小编Alb*_*lli的帖子

git log - 关注,gitpython方式

我试图访问单个文件的提交历史记录,如下所示:

git log --follow -- <filename>
Run Code Online (Sandbox Code Playgroud)

我必须使用gitpython,所以我现在正在做的是:

import git 
g = git.Git('repo_dir') 
hexshas = g.log('--pretty=%H','--follow','--',filename).split('\n') 
Run Code Online (Sandbox Code Playgroud)

然后我构建提交对象:

repo = git.Repo('repo_dir')
commits = [repo.rev_parse(c) for c in r]
Run Code Online (Sandbox Code Playgroud)

有没有办法以更加gitpython-ic的方式做到这一点?我都尝试commit.iter_parents()commit.iter_items(),但他们都依靠git-rev-list,所以他们没有--follow选择.

python git gitpython

33
推荐指数
2
解决办法
1万
查看次数

如何使用PetitParser解析以关键字开头的标识符?

我想使用PetitParser解析编程语言中的标识符.

其中一个要求是标识符的名称不是关键字(例如null),因此它null不是有效的标识符.

我能为这种情况考虑的最小解析器是:

identifier := ('null' asParser not,  #word asParser plus)
Run Code Online (Sandbox Code Playgroud)

但是,如果输入以关键字开头,则失败:

identifier end parse: 'nullable'
Run Code Online (Sandbox Code Playgroud)

你有什么建议可以解决这个问题吗?谢谢!

parsing smalltalk petitparser

4
推荐指数
1
解决办法
123
查看次数

python中出现意外的空格生成了字符串

我使用Python生成由很长的行组成的ASCII文件.这是一个示例行(假设文件中的第100行,'[...]'由我添加以缩短行):

{6 1,14 1,[...],264 1,270 2,274 2,[...],478 1,479 8,485 1,[...]}
Run Code Online (Sandbox Code Playgroud)

如果我打开使用ipython生成的ASCII文件:

f = open('myfile','r')
print repr(f.readlines()[99])
Run Code Online (Sandbox Code Playgroud)

我确实获得了正确打印的预期行('[...]'由我添加以缩短行):

'{6 1,14 1,[...],264 1,270 2,274 2,[...],478 1,479 8,485 1,[...]}\n'
Run Code Online (Sandbox Code Playgroud)

相反,如果我用想要读取它的程序打开这个文件,它会产生一个异常,在478之后抱怨意外的一对1.所以我试着用vim打开文件.仍然vim显示没有问题,但如果我复制vim打印的行并将其粘贴到另一个文本编辑器(在我的案例中为TextMate),这就是我获得的行('[...]'由我添加到缩短线):

{6 1,14 1,[...],264 1,270      2,274 2,[...],478 1,4     79 8,485 1,[...]}
Run Code Online (Sandbox Code Playgroud)

这一行确实在对478之后出现了问题1.我尝试以不同的方式生成我的行(连接,使用cStringIO,...),但我总是得到这个结果.例如,当使用cStringIO时,生成的行如下所示(尽管我试图改变它,但没有运气):

def _construct_arff(self,attributes,header,data_rows):
  """Create the string representation of a Weka ARFF file.
     *attributes* is a dictionary with attribute_name:attribute_type
       (e.g., 'num_of_days':'NUMERIC')
     *header* is a list of the attributes sorted
       (e.g., ['age','name','num_of_days'])
     *data_rows* is a list of …
Run Code Online (Sandbox Code Playgroud)

python formatting

1
推荐指数
1
解决办法
221
查看次数

标签 统计

python ×2

formatting ×1

git ×1

gitpython ×1

parsing ×1

petitparser ×1

smalltalk ×1