how to remove comma while using split() function?

scn regnivon at netscape.net
Fri May 23 14:09:04 EDT 2003


hello. 
i wrote a program to extract first and last names from a flat file and
populate a mysql database.  It worked the first time, belive it or
not. however, the comma after the first name is in the "firstname"
record and i'd like to understand in my "line.split()" function how to
remove the comma before populating the database.  thanks for your
help.

the following are snippets from my program:

<snip>
# open a file for reading
# this file contains a list of first and last names, separated by a
comma
# example 'firstname1, lastname1'
input = open('c:/python22/programs/database stuff/names.txt', 'r')

<snip>
# loop directly on the file open for reading - xreadlines is
obsolescent
for line in input:
    # split selectivley so most whitespaces in the line's not
disturbed
    firstname, lastname = line.split(None, 1)
    tuple = (firstname, lastname)
    # and append to data[] list
    data.append(tuple)




More information about the Python-list mailing list