首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Windows上使用python科学模块时出现属性错误

在Windows上使用python科学模块时出现属性错误
EN

Stack Overflow用户
提问于 2011-05-05 02:33:14
回答 2查看 411关注 0票数 1

当我们的程序在使用Linux2.6的Windows XP上运行时,我得到了以下错误(尽管它在ActivePerl上运行得很好)。你知道是怎么回事吗?这是模块中的错误还是我们代码的问题?

错误日志:

代码语言:javascript
复制
      File "C:\Python26\lib\site-packages\Scientific\IO\PDB.py", line 1163, in __ini
    t__
        self.parseFile(PDBFile(file_or_filename))
      File "C:\Python26\lib\site-packages\Scientific\IO\PDB.py", line 1371, in parse
    File
        type, data = file.readLine()
     File "C:\Python26\lib\site-packages\Scientific\IO\PDB.py", line 200, in readLi
   ne
        line = self.file.readline()
    AttributeError: 'unicode' object has no attribute 'readline'
    Exception AttributeError: "'unicode' object has no attribute 'close'" in <bound
    method PDBFile.__del__ of <Scientific.IO.PDB.PDBFile instance at 0x00FD0440>> ig
    nored

更新:按照Joe的建议,我得到了以下错误:

代码语言:javascript
复制
Traceback (most recent call last):
  File "NewParseV1_00.py", line 47, in <module>
    PromptUser()
  File "NewParseV1_00.py", line 45, in PromptUser
    parseGroupFile(grpfilepath, outputPPYfilepath, sorcePDBfilepath)
  File "NewParseV1_00.py", line 39, in parseGroupFile
    return GeneratePPY(LL,GRPNAME,SRCPDB,OUTPPY)
  File "NewParseV1_00.py", line 10, in __init__
    self.PDBStruct = Scientific.IO.PDB.Structure(SRCPDB)
  File "C:\Python26\lib\site-packages\Scientific\IO\PDB.py", line 1163, in __ini
t__
    self.parseFile(PDBFile(file_or_filename))
  File "C:\Python26\lib\site-packages\Scientific\IO\PDB.py", line 161, in __init
__
    if isinstance(file_or_filename, basestr):
NameError: global name 'basestr' is not defined
Exception AttributeError: "PDBFile instance has no attribute 'open'" in <bound m
ethod PDBFile.__del__ of <Scientific.IO.PDB.PDBFile instance at 0x00FDB418>> ign
ored
EN

回答 2

Stack Overflow用户

发布于 2011-05-05 06:46:29

我猜,但它看起来像是Scientific.IO.PDB中的一个bug,他们这样做:

代码语言:javascript
复制
if type(file_or_filename) == str:
    file = open(file_or_filename)
else:
    file = file_or_filename

而不是做:

代码语言:javascript
复制
if isinstance(file_or_filename, basestr):
    ...

无论出于什么原因,您似乎在Windows端传递了一个unicode文件名,在Linux端传递了一个原始字符串。

不过,我再说一次,我只是猜测。我假设这里的Scientific是这个模块?http://dirac.cnrs-orleans.fr/plone/software/scientificpython/ (我不熟悉它...)

编辑:是的!

以下是来自Scientific.IO.PDB的相关代码

代码语言:javascript
复制
class PDBFile:

    """
    X{PDB} file with access at the record level

    The low-level file access is handled by the module
    L{Scientific.IO.TextFile}, therefore compressed files and URLs
    (for reading) can be used as well.
    """

    def __init__(self, file_or_filename, mode = 'r', subformat = None):
        """
        @param file_or_filename: the name of the PDB file, or a file object
        @type file_or_filename: C{str} or C{file}
        @param mode: the file access mode, 'r' (read) or 'w' (write)
        @type mode: C{str}
        @param subformat: indicates a specific dialect of the PDB format.
                          Subformats are defined in
                          L{Scientific.IO.PDBExportFilters}; they are used
                          only when writing.
        @type subformat: C{str} or C{NoneType}
        """
        if isinstance(file_or_filename, str):
            self.file = TextFile(file_or_filename, mode)
        else:
            self.file = file_or_filename
        <snip>

它应该和将isinstance(file_or_filename, str)更改为isinstance(file_or_filename, basestr)一样简单。你可能需要提交一份错误报告...

票数 1
EN

Stack Overflow用户

发布于 2011-05-16 23:04:53

按照Joe的解释,更改Scientific.IO.PDB中的代码需要进行最后一次修改才能生效:

在第161行,将if isinstance(file_or_filename, str):更改为if isinstance(file_or_filename, basestring):

(请注意,Joe写道,第二个参数应该是basestr,但这在原始问题的更新中给出了错误。)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5888668

复制
相关文章

相似问题

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