Create a folder in Python of Current date format

If you'd need to create a folder for current date in format as YYMMDDHH using python - You can use below code. This will create folder with "00" in hour if the time is between 00:00 to 12:00PM and from 12PM till 00:00AM, it will created folder with "12". For 2022-06-26 09:00:00 - It will … Continue reading Create a folder in Python of Current date format

‘ascii’ codec can’t encode characters : ordinal not in range(128)

I work on a system which fetches data from a database (Postgres) using python & writes them into a csv file. Few days ago i came through an error which was showing "ascii codec can't encode characters : ordinal not in range(128)" whenever i tried to fetch data from a particular date range. Problem :  … Continue reading ‘ascii’ codec can’t encode characters : ordinal not in range(128)

Make primary key with two or more field in Django

Most of the time, people don't actually need their composite (multi-column) key to be the primary key. Django operates best with surrogate keys -  that is, it automatically defines an autoincrement field called id and sets that to be the primary key. That is suitable for almost all the users. If you then need to enforce … Continue reading Make primary key with two or more field in Django

Python Decorators

Python Conquers The Universe

In August 2009, I wrote a post titled Introduction to Python Decorators. It was an attempt to explain Python decorators in a way that I (and I hoped, others) could grok.

Recently I had occasion to re-read that post. It wasn’t a pleasant experience ? it was pretty clear to me that the attempt had failed.

That failure ? and two other things ? have prompted me to try again.

  • Matt Harrison has published an excellent e-book Guide to: Learning Python Decorators.
  • I now have a theory about why most explanations of decorators (mine included) fail, and some ideas about how better to structure an introduction to decorators.

There is an old saying to the effect that “Every stick has two ends, one by which it may be picked up, and one by which it may not.” I believe that most explanations of decorators fail because they pick…

View original post 1,457 more words