I have a python script that reads a csv file and converts it to two new files so that my database can add new emails or update existing ones. What im trying to do now is after it has converted them for it to send me a email with how many rows it processed for both the add adn update file. I have the email part workign what has me stuck is the counting of the rows which for somereason everything i have tried returns me actual values from the files and not a number like im wanting to to. could someone please help me figure this out.

You can use

cnt = sum(1 for line in open("foo.csv"))

I have tried that but when i attempt to add the results of it to the email message i get cannot concatenate a str and int objects. How do i get it to allow the results in the message

Add str(cnt).

By the way, this is better:

with open("foo.csv") as f: cnt = sum(1 for line in f)

because the file is properly closed.

that worked great thank you so much

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.