Need Help comparing dates

Tim Chase python.list at tim.thechases.com
Sat Jun 17 08:40:23 EDT 2006


> I will try to work through Tim's response. I tried using it
> yesterday but I was really confused on what I was doing.

I'll put my plug in for entering the code directly at the shell 
prompt while you're trying to grok new code or toy with an idea. 
  It makes it much easier to see what is going on as you enter 
it.  You can ask for any variables' value at any time.  It's a 
small pain when you're entering some nested code, and biff up on 
the interior of it (throwing an exception, and having to restart 
the function-definition/loop/class-definition statement all 
over), but it certainly has its advantages for learning the language.

On top of that, you can usually ask for help on any object, so if 
you wanted to know about the datetime module or the date object 
in the datetime module, you can just use

	>>> import datetime
	>>> help(datetime)
	>>> help(datetime.date)

which will give you all sorts of documentation on a date object. 
  I'm also partial to learning about what methods the object 
exposes via the dir() function:

	>>> dir(datetime.date)
or
	>>> print "\n".join(dir(datetime.date))

IMHO, help() and dir() at the command-line combine to make one of 
Python's best selling points...ease of learning.  I understand 
Perl and Ruby might have something similar, but I've never liked 
their idioms.  Java/C/C++, you have the edit/compile/run cycle, 
so if you just want to explore some simple code ideas, you've got 
a 3-step process, not just a simple "try it out right here and 
now" method.

I even stopped using "bc" as my command-line calculator, 
preferring the power of command-line python. :)

Just a few thoughts on what made learning python easier for me.

Again, if you have questions, and can't figure out the answers by 
stepping through the code in the command shell (or some 
strategically placed print statements), this is certainly the 
forum for asking those questions.  It's full of smart and helpful 
folks.

-tkc








More information about the Python-list mailing list