Python PHP date() class

I haven’t been doing much PHP as of late, at least nothing special. I’ve been studying for my A+ Certification, working on Python/Django, and doing 3d modeling (With 3ds max), so I’ve had very little time to play around with PHP.

For Python however, I was unhappy with the date formatting functions available so I decided to write my own. It’s in the form of a class which uses PHP style date formatting with almost all of the PHP date() options (prefixed by a % though). I’ve attached the source code.

You just have to import my class, make an instance and call the desired function. Example:

from my.project.includes import pytime

pytime = PyTime()

print pytime.get_datetime(format="%l, %F %j%S, %Y at %H:%i") # Results with something similar to "Friday, June 4th, 2010 at 11:24"

Download my Python date formatting class now!

Python Global Vars are Persistent

I was working on my new Python project, a wiki, and was having problems where my code wasn’t being interpreted more than once, or so I thought. I had a menu that changes depending on if the user is authenticated or not, except it never changed. I was on FreeNode IRC’s Django support channel (#django) and was informed that variables declared in the global scope are persistent across requests, as well as exhibiting other quirky behavior. Just thought I’d share this with everyone else in case you ever have this issue.

Python and Django

I’ve been busy learning Python and Django lately. Python is a great language, and Django is an excellent framework. I still enjoy PHP, especially for scripting, but I also see that it has certain pitfalls that Python doesn’t (And vice versa). Django is a framework for web development, and a good one at that. It supports a lot of abstraction and it has a high level of security from the get go using it’s Models implementation for SQL/Databases (Which also supports database abstraction meaning multidatabase support). It has a higher level of security for people starting out, as novice PHP programmers often make numerous security mistakes.

Python is fast and great at rapid prototyping. I’m actually studying it for a job I’d like to apply for towards the end of June. I’ll be posting code examples, fixes, and other Python related material here as well as my normal material! My first project is a Python based wiki application, similar in functionality to MediaWiki and already well on it’s way. Once complete (Or ready for a first release), I’ll publish it here.