首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何阻止Python2.7 RawConfigParser在标签上抛出ParsingError?

如何阻止Python2.7 RawConfigParser在标签上抛出ParsingError?
EN

Stack Overflow用户
提问于 2017-07-31 20:14:04
回答 1查看 381关注 0票数 2

我正在编写一个与Python 2.7.13Python 3.3兼容的包,并使用以下代码:

代码语言:javascript
复制
try:
    import configparser
except:
    from six.moves import configparser

但是当我在Python 2.7上加载我的.gitmodules文件时

代码语言:javascript
复制
    configParser   = configparser.RawConfigParser( allow_no_value=True )
    configFilePath = os.path.join( current_directory, '.gitmodules' )

    configParser.read( configFilePath )

它抛出错误:

代码语言:javascript
复制
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "update.py", line 122, in run
    self.create_backstroke_pulls()
  File "update.py", line 132, in create_backstroke_pulls
    configParser.read( configFilePath )
  File "/usr/lib/python2.7/ConfigParser.py", line 305, in read
    self._read(fp, filename)
  File "/usr/lib/python2.7/ConfigParser.py", line 546, in _read
    raise e
ParsingError: File contains parsing errors: /cygdrive/d/.gitmodules
        [line  2]: '\tpath = .versioning\n'
        [line  3]: '\turl = https://github.com/user/repo\n'

但是如果我从.gitmodules文件中删除选项卡,它就能正常工作。在Python 3.3上,它可以与选项卡一起工作,但在Python 2.7.13上,它不能与选项卡一起工作。我怎样才能让它在不移除标签的情况下工作?

这些选项卡是在我添加新的子模块时由git原生放置的,所以我绝对不会从原始文件中删除它们。我一直在想,我可以在删除标签的同时复制文件。但是,为了与Python兼容,是否有成本较低的操作

相关问题:

  1. How can I remove the white characters from configuration file?
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45415684

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档