i'm writing a program that reads the lines of a file. each line has a name and and number separated by one space. i want to split the string but i only want the number because i'm using it in calculations. i've skimmed through the python docs and i'm still not sure how to do this. any help is apprecited, thank you!
kjock002 0 Newbie Poster
Recommended Answers
Jump to PostPerhaps you should start with the output of
>>> help(str)
Jump to PostIt appears that you did not test this code as you only read the first rec. Also you can use
for rec in inFile
instead of the while loop. And string.split() is deprecated, use line.split() instead.line = inFile.readline() ##--------------------------------------------------------------- ## this is an infinite loop unless …
All 7 Replies
Gribouillis 1,391 Programming Explorer Team Colleague
zentraders 0 Newbie Poster
kjock002 0 Newbie Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
Tech B 48 Posting Whiz in Training
woooee 814 Nearly a Posting Maven
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.