Python replace carriage return and tab in a string

I wrote this script to replace all carriage return and tab in my wordpress database and put it in a PHP page.
import MySQLdb
conn = MySQLdb.connect (host = “localhost”,
user = “root”,
passwd = “”,
db = “test”)
cursor = conn.cursor ()
cursor.execute (“SELECT post_title,post_content FROM wp_posts”)
rows = cursor.fetchall ()
cnt =0
for row in rows:
f = open(str(cnt)+”.php”, ‘w’)
f.write(“”);
title = row[0];
f.write(title);
f.write(“

“);
f.write(“

“);
f.write(“
“);
f.write(“

“);
f.write(title);
f.write(“

“);
post = str(row[1])
post = post.replace(“n”, “”).replace(“r”, “
“)
f.write(post)
f.write(“

“);
#print “%s %s” %(row[0],row[1])
cnt = cnt+1
#if cnt > 2:
# break
print “Number of rows returned: %d” % cursor.rowcount
cursor.close ()
conn.close ()

Leave a Reply

Your email address will not be published.