By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,100 Members | 2,958 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,100 IT Pros & Developers. It's quick & easy.

{SOLVED} Program to print 't' and 'T' in a text file

P: 10
I got such good help here before (thank you)....thought I'd try it again.

I'm supposed to have a text file to read....I named it my_file.txt

I need to write a Python program to read the file and print every word that begins with a 't' or 'T'.

This is what I have so far:

uselessFile = open('my_file.txt', 'r')
>>> uselessList = uselessfile.readlines()
>>> uselessList


Am I on the right track or just really lost?
Nov 12 '06 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 511
one way

Expand|Select|Wrap|Line Numbers
  1. data = open("thefile").read().split()
  2. for items in data:
  3.   if items.startswith("T") or items.startswith("t"):
  4.     print items,
  5.  
Nov 12 '06 #2

P: 10
I think I'm making this much harder than it is.....what I've been working on for hours you told me in a couple of minutes....THANK YOU SO MUCH!!!!
Nov 12 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.