Getting SQL query string from Django orm query

I often want to see the actual SQL generated by the orm query. This is important especially if you are running some DML queries like update, select etc and want to ensure that generated sql is exactly what you had in mind. If the query results in a queryset, its really straight forward. goto ./ […]

Temporary Files in Python

Let me start with an actual use case scenario. As a backend developer, I need to process the user uploaded file data all the time. Here temporary files shine. The best part about these is that they make cleanup easier. If you make a real file, you need to use some OS level utility to […]

Removing non-ascii characters from text in Python

I was handling some text scraped using Scrapy and the text had non-ascii unicode charcters like \u003e. If I did this, it didn’t work:

Here response.text is the string that contains unicode text (scrapy returns strings encoded in unicode). The html_text still had non ascii unicode characters like \u003e This worked:

Note that […]

ES6 Javascript quick recap cookbook

Working with Python lxml parser for creating XML elements

lxml parser can be a bit confusing because of the sheer range of options it offers. Here are a few cookbook style examples. XML Generation Target code:

Ok, Here is the code to generate it:

Notice the nsmap = {None: XHTML_NAMESPACE} line in etree.Element(‘root_element’, nsmap = {None: XHTML_NAMESPACE}, some_more_params=”12345-678-ABC”, yet_more_params=”POKEMON-SUCKS”). This is required […]