little help

Greg Fortune lists at gregfortune.com
Sun May 11 03:19:45 EDT 2003


To fix your problem, you just need to add a "print" statement after you 
retreive the two values...

Also, take this modified code as a suggestion..  You probably don't want to 
read the entire file in if you only need to first two lines

for name in filesInDir:
  inp = open(name, 'r')
  title = inp.readline().strip()
  desc = inp.readline().strip()
  print "%s: %s" % (title, desc)
  #or, if the following line is clearer, uncomment in...
  #print title + ": " + desc
  inp.close()
  


Psybar Phreak wrote:

> sorry - add this
> 
> filesInDir = os.listdir(dirpath)
> filesInDir.sort()
> 
> its supposed to go through all the files in the directory and get the
> first 2 lines out of the first file, print them, go to the next file, get
> the first 2 lines, print them, etc.
> 
> im not getting a compile error - it just aint printing anything to screen!
> 
> WEIRD!
> 
> "Psybar Phreak" <psybar_phreak at yahoo.com> wrote in message
> news:3ebdcfc9$0$16259$afc38c87 at news.optusnet.com.au...
>> would anyone know why this isn't working?
>>
>> for diaryname in filesInDir:
>>  InFile = open(diaryname, 'r')
>>  lines = InFile.readlines()
>>  InFile.close()
>>
>>  diaryTitle = lines[0].strip()
>>  diaryDesc = lines[1].strip()
>>
>>
>> thanks!
>>
>>





More information about the Python-list mailing list