问题描述
我在Python中打开FITS文件时遇到问题.我收到以下错误消息:
I have problem in opening FITS file in Python. I get following error-message:
File "G:\Anaconda\lib\site-packages\pyfits\file.py", line 416, in _open_filelike % self.mode)
IOError: File-like object does not have a 'write' method, required for mode 'ostream'
在hdulist = pft.open(path)
行(我确实将pyfits
导入为pft
).
at hdulist = pft.open(path)
line (I did import pyfits
as pft
).
我检查了两次路径-正确.
在使用PyFITS的情况下,我找不到与该错误有关的任何参考,对于任何帮助,我将不胜感激.
I checked the path twice - it's correct.
I'm not able to find any reference to this error in context of using PyFITS and I will be gratefull for any help.
更新:
我错过了一些细节,对此我感到抱歉.
首先:我正在Windows的Anaconda发行版下使用PyFITS 3.3(Windows XP 32位).
您可以在以下链接找到整个窗口小部件的代码:
FileView
简而言之-我正在为文件系统做一个简单的资源管理器,只是为了让用户导航到包含FITS文件的文件夹并从文件夹中读取它.所有项目都在PyQT4下.
UPDATE:
I missed some details and I'm sorry for it.
First of all: I'm using PyFITS 3.3 under Anaconda distribution for Windows (Windows XP 32-bit).
Code of whole widget you can find at this link:
FileView
In a short - I'm making simple explorer for filesystem, just to let user navigate to folder with FITS files and read it from folder. All project is under PyQT4.
推荐答案
很明显,您的path
不是basestring
的子类(我想您使用的是Python 2.7),正如PyFITS所期望的那样.实际上,path
是QString
实例,您必须首先转换为unicode
.
Obviously your path
is not a subclass of basestring
(I suppose you use Python 2.7) as it is expected by PyFITS. In fact path
is a QString
instance and you have to convert to unicode
first.
所以替换您的行
hdulist = pft.open(path)
使用
hdulist = pft.open(unicode(path.toUtf8(), encoding="UTF-8"))
这篇关于Python,PyFITS,无法打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!