Franta Konopnik
Franta Konopnik

Reputation: 189

Python-read files from current folder

I write some fits viewer with matplotlib. And now I have one problem. I neen read data files with suffix .fts from current folder when I began my script. So for example

import pyfits
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Button


image_list=['sun0001.fts','sun0002.fts','sun0003.fts','sun0004.fts','sun0005.fts','sun0006.fts','sun0007.fts','Moon0005.fts']

image_list I made manually. But now I want to used some script which read automaticlly files from folder as see.

Thank for answer

Upvotes: 1

Views: 1001

Answers (1)

zhangxaochen
zhangxaochen

Reputation: 34047

use glob module, e.g., if I want to search the JPEG files in my current directory:

In [180]: from glob import glob

In [181]: glob('*.jpg')
Out[181]: 
['IMG_20130626_193201.jpg',
 'IMG_20130926_191134.jpg',
 'IMG_20130926_191143.jpg',
 'IMG_20130926_191157.jpg']

Upvotes: 3

Related Questions