Python adds undesired tabs to string -


i'm using script captures html elements html files , sends them mysql db. use

title = line.replace("<!--h1-->",'').replace("<h1>",'').replace("</h1>",'')

for capturing h1. now, if run

print title

everything fine. however, if run

print 'post_title = %(title)s'%locals()

then python consistently seems add 2 tabs start of title.

does know what's causing , how can prevent this?

call strip() on title string:

title = line.replace("<!--h1-->",'').replace("<h1>",'').replace("</h1>",'').strip() print 'post_title = %(title)s' % locals() 

it's not necessary use locals() in way; have required variable, so:

print 'post_title = %s' % title 

or

print 'post_title = {}'.format(title) 

would preferable.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -