Skip to main content

Posts

Showing posts with the label Python

Iron Languages on DLR

The "Iron" languages that run on the .NET DLR (Dynamic Language Runtime) are making progress. I just noticed that IronRuby has a release on RubyForge . To be honest though, I have moved to Python as my script language of choice, with Perl as the ever-present fallback. Iron Python seems like it is coming along nicely. Iron Python 2 can even host itself . I can't wait for MonoDevelop or SharpDevelop to support IronPython on Windows.

PdfPoster - a simple fix for Windows

I have tried a couple of times over the last 3 months to use PdfPoster on some Erwin documents. Unfortunately, I am using Windows XP on my work PC. It was clearly documented that I needed to install PyPdf 1.11 or higher, so I did easy_setup to install 1.12. Recently, I tried "C:\test>pdfposter -vvv -s 2.0 SCHEDULING.pdf scheduling_2x.pdf" ... and received a nice traceback (see below). This led me on a wild goose chase, under the assumption that my PyPDF library was not installed correctly. After a while, I decided to start python in immediate mode and just exercise PyPdf. It worked fine, but I noticed that the example opened a file using "rb" mode (read only, binary). So, I opened pdfposter/__init__.py under my site library directory, scrolled down to the bottom and changed the 3rd line of "def main" from "inpdf = PdfFileReader(open(infilename))" to "inpdf = PdfFileReader(open(infilename, "rb" ))". Problem solved!...

Python Turtle and Links

I just discovered the Turtle graphics module for Python 2.5 using the Tk graphics library. It is very "kid friendly", and it sets up a screen when you make your first function call. This was very fun, just like when I first played with LOGO on my Commodore 64! >>> from turtle import * >>> clear() >>> down() >>> goto(66,66) >>> for step in range(24): ... right(105) ... forward(100) ... >>> up() >>> goto(0,0) >>> color("red") >>> write("Done!") >>> exit() Seen on the Web in August 2008 Iron Python on ASP.Net http://ironpythonresource.com/post/2008/08/03/Beginning-IronPython-Creating-a-basic-ASPNET-Form-(Part-1).aspx Connecting to a database http://ironpythonresource.com/post/2008/08/09/Connecting-to-a-database-and-using-the-gridview.aspx Creating a class http://ironpythonresource.com/post/2008/08/10/Beginning-IronPython-Creating-a-class.aspx Creating an updat...

Python 2.6 beta 1 and 3.0 beta 1

Python is sticking pretty close to their release schedule for Python 2.6 and 3.0 as documented in PEP 361 . They released Python 2.6 beta 1 and 3.0 beta 1 today. If you&apos're curious about their progress, check the 2.6 release notes . By the way, I noticed that they fixed a problem with one of the rotating log handlers - it was using a simple filename instead of the full file path when deleting old log files. I have been wanting to check my code in both 2.6 and 3.0 latest releases. Now that it is in beta, I should be able to get a pretty good idea of what has changed. All I want is for it to "feel" like python.

Custom Python Logging Handler

Python has some nice basic logging facilities, but I really wanted a rotating logger that would rotate on each execution. I tried the obvious - just specifying class=MyModule.MyClassName, but I received a NameError exception for my trouble. After some hacking on /python25/lib/logging (a big no-no!), I did another google search and discovered that I could just import the class in my application, and set a reference to my custom class. Hard-coding a logging handler doesn't feel very dynamic, but at least I did't have to hack any more. from MyCustomHandlers import SessionRotatingFileHandler logging.SessionRotatingFileHandler = SessionRotatingFileHandler logfile_name = "test.l4p" logging.config.fileConfig(logfile_name) This allows me to place my custom log handler in my application directory. I still need to figure out how to add things to site-packages.

Perl or Python?

Recently at work, we have been discussing the question of Perl versus Python for file copy, ftp, email and other daily, weekly or monthly automation / integration tasks. We considered Perl because some existing tasks had already been written in it, and Perl has a reputation as the System Admin's language of choice. I took a task that needed automated and wrote it in Perl 5.8, then refined it using CPAN (sweet CPAN) for ArgvFile, Log4Perl, Carp, and Date::Calc. I find Perl to be very functional and completely able to meet my needs, but very quirky or perhaps unsettling. You see, I have been an object oriented programmer for a while now, and Perl's class system just feels "bolted on" to me. And I really had to jump through hoops to do a try/catch, but using eval with a return flag and an END block to test the return worked acceptably. I didn't test the exception module, as I did not discover it in time. Next I tried Python 2.5. After a quick brush-up on the...