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

How to Ignore \n when reading in strings?

P: 1
Hi,

I am new to using python. I have a problem. I need to read in strings from a data file and only count those that are explicitly numbers. So I am using the isdigit() method.

But the problem is that the data file has multiple strings so the problem is the \n messes my code up.

My program only works on the last number because that is the end of the file and there are no more empty spaces or a return at the end of file. So it only counts the last number as being a number.

Is there anyway to ignore \n when reading in strings or does readline() and isdigit() automatically ignore this \n?

Thanks!
Jan 30 '11 #1
Share this Question
Share on Google+
1 Reply


bvdet
Expert Mod 2.5K+
P: 2,851
Use string method strip() to remove leading and trailing whitespace characters such as "\n", "\t", etc.
Jan 30 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.