[Tutor] glob in order of the file numbers
Bill Campbell
bill at celestial.net
Sat Mar 7 04:11:46 CET 2009
On Fri, Mar 06, 2009, Emad Nawfal (???? ????) wrote:
>
> Hi Tutors,
> suppose I have four files in the current directory: 1.temp, 2.temp,
> 3.temp, and 4.temp. I want to use glob, or anything else, to print the
> contents of the files in their respective orders, where the content of
> 1.temp gets printed, then 2.temp, then 3.temp, then 4.temp.
> I write the following, but it does not get me what I want:
> import glob
> for path in glob.iglob("*.temp"):
> infile = open(path)
> for line in infile:
> print line.strip()
> # This prints
> emad at emad-laptop:~/Desktop/TEMP$ python globbing.py
> This is four
> This is one
> This is two
> This is three
> Could somebody please tell me how to get the output in the right
> order?
files = glob.glob('*.temp')
files.sort()
for file in files: ...
Bill
--
INTERNET: bill at celestial.com Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way
Voice: (206) 236-1676 Mercer Island, WA 98040-0820
Fax: (206) 232-9186
The pinnacle of open systems is: when moving from vendor to vendor, the
design flaws stay the same.
More information about the Tutor
mailing list