Python,PyFITS,无法打开文件 [英] Python, PyFITS, cannot open file

查看:158
本文介绍了Python,PyFITS,无法打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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所期望的那样.实际上,pathQString实例,您必须首先转换为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,无法打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆