KBD

Keith Devens .com

Saturday, May 17, 2008 Flag waving
Mistakes are as serious as the results they cause. – House (The Mistake – ep 30)

Tag: Python

Parents:

Children:

Page 1 →

Daily link icon Thursday, April 24, 2008

  1. Generator Tricks for Systems Programmers (via). Presentation on Python's generators.

       (0) Tags: [Python]

Daily link icon Wednesday, November 8, 2006

  1. IronPython. The official home page of IronPython. Google is out of date.

       (0) Tags: [IronPython]
  2. Stackless Python Continues to Amaze (via Simon).

       (0) Tags: [Python]

Daily link icon Tuesday, August 1, 2006

  1. ongoing · OSCON—Perl & Python:

    On a technical note, Python 3 will have a String type that is 100% Unicode and that’s all it is, and separately a byte-array type that lets you indulge your most squalidly-perverse bit-bashing fantasies. I approve.

       (0) Tags: [Python]

Daily link icon Thursday, July 27, 2006

Dumb substring behavior in C# (and Java)

Substring in C# (and Java) throw an exception if you take a substring and give it a length (or a starting position) that puts you after the end of the string. That's basically to ensure that you always get a string that's exactly the length you want? Rather than just being able to take a substring and not having to worry about it, you have to include code like the following around every single substring you ever take:

if (str.Length > 30){
    str = str.Substring(0, 30);
}

Typically when you take a substring you want to ensure that your string is no longer than a certain number of characters. I can't think of a situation that would it a good idea for the language to enforce that you can't get a string that's less than the maximum length you want instead of exactly the length you want.

On the other hand, most of the dynamic languages (PPPR) let you substring off the end of the string without worrying about it.

Daily link icon Thursday, June 29, 2006

  1. Peter Norvig: Solving Every Sudoku Puzzle (via Simon Willison). With code in Python.

       (0) Tags: [AI, Python, Sudoku]

Daily link icon Monday, April 3, 2006

  1. Mike Stall's .NET Debugging Blog : How to embed IronPython script support in your existing app in 10 easy steps. I don't agree with everything he did here, but it's a darn useful reference and introduction, and he has some neat tricks.

       (0) Tags: [IronPython]

Daily link icon Thursday, March 2, 2006

  1. James Manning's blog : error CS1501: No overload for method 'Base' takes '0' arguments. Why don't more languages come with 'unified constructors' like Python (and even PHP, now) does? Wouldn't that fix the problem?

       (0) Tags: [C#, OOP, PHP, Python]

Daily link icon Sunday, February 26, 2006

  1. JeffCroft.com: Django Templates: The Power of Inheritance (via Simon Willison). To read.

       (0) Tags: [Django, Templating, To Read]
  2. pyparsing -- a class library for text processing in Python. Also see the O'Reilly article about it, Building Recursive Descent Parsers with Python. I came across pyparsing the other day (don't remember where), but the O'Reilly article is via Keith Gaughan.

       (2) Tags: [Python]

Daily link icon Tuesday, February 21, 2006

  1. Keyphrene Python SSH wrapper (via). I probably could have used this earlier... though I haven't yet tried it or looked at the source (there's no documentation! Smiley)

       (1) Tags: [Python]
  2. Manning: wxPython in Action (via). A book on wxPython... rock.

       (0) Tags: [wxPython]

Daily link icon Monday, February 20, 2006

  1. ShowMeDo - training videos, for anything, online (via Sean McGrath):

    The creation of ShowMeDo was motivated by the observation that many of the web tutorials we have success with are demonstrative, exploiting the audio-visual possibilites that increasing bandwidths provide.

    Well-written textual descriptions are often quite adequate but for a wide range of activities there is no substitute for seeing it done.

    They have some Python videos.

       (0) Tags: [Python, Videos]

Daily link icon Monday, January 16, 2006

  1. Python 2.5 is getting a conditional expression (via LtU). Guido: "After a long discussion I've decided to add a shortcut conditional expression to Python 2.5." But it's ugly! The condition doesn't go first!

       (1) Tags: [Programming, Python]

Daily link icon Tuesday, January 10, 2006

  1. Guido van Rossum: Python Status Update.

       (2) Tags: [Programming, Python]

Daily link icon Saturday, December 31, 2005

  1. [IronPython] 1.0 Beta 1 is out now! (via PLNews). "We've just released the first beta of IronPython 1.0 and are entering the home stretch to a 1.0 final build." Good news!

       (1) Tags: [IronPython, Programming]

Daily link icon Wednesday, December 21, 2005

  1. Python Creator Guido van Rossum now working at Google (via Simon Willison). Rock!

       (1) Tags: [Google, Programming, Python]

Daily link icon Wednesday, December 14, 2005

Python's metaclasses

Dev Shed has an excellent introduction to Python's metaclasses (via DPU). I get it now:

  • Python's metaclasses are just normal classes that inherit from type
  • When you instantiate a metaclass the object returned is itself a class
  • To declare that a class has a given metaclass, set the __metaclass__ data member to the metaclass when declaring the class.
  • The metaclass' __init__ method is called when a class that has it as its metaclass is declared (__init__ for metaclasses takes (klass, klass_name, base_classes, dict_of_attributes) as its parameters).

And that's it (according to the article). So, it seems that Python very nearly has a prototype-based object system, but not quite. (And I ❤ prototype-based object systems.) With a prototype-based object system the distinction between metaclasses and classes (heck, and objects) goes away, so it seems to me that you could do the same thing as what Python calls metaclasses simply by overriding a particular object's clone method. Am I wrong?

Daily link icon Friday, December 9, 2005

  1. Matplotlib / pylab - matlab style python plotting (via Chris Langreiter and his description of PageRank (with code in both Python and K)). Check out the kickass screenshots. Of course, Chris recommends numarray to complement it.

       (1) Tags: [K, Matlab, Programming, Python]

Daily link icon Thursday, December 8, 2005

  1. O'Reilly Radar > Ruby Book Sales Surpass Python (via Dave Thomas). David Hansson has comments (via Sam Ruby):

    Ruby book sales have exploded. In total, Ruby is up 1,552% over last year in the same period. That's one thousand, five hundred, and fifty two percent. Holy smokes. It's insane!

    To bring that number into perspective, Ruby books are now selling better than Python books. Which of course is the first time that ever happened. And that language was not even standing still. Python is up 20% over last year. At the same time, Perl is down 3%, Java down 4%. So its no wonder we have a feeling that the duo of modern, dynamic languages are taking off. It's because they are!

       (1) Tags: [Programming, Python, Ruby]

Daily link icon Tuesday, December 6, 2005

  1. reddit just rewrote their site in Python. It was originally written in Lisp.

    Lisp is an amazing language. After spending the entire summer working entirely in Lisp, it's nearly impossible to work in another language and not say to myself, "If only this were Lisp..." Lisp has many goodies that make programming in it a joy: the REPL, macros and the lack of syntax are some. I won't go into the details, but rest assured, it's cool. People become Lisp zealots for a reason.

    So why Python?

    We were already familiar with Python. It's fast, development in Python is fast, and the code is clear. In most cases, the Lisp code translated very easily into Python. Lots of people have written web applications in Python, and there's plenty of code from which to learn. It's been fun so far, so we'll see where it takes us... I'm very pleased at the way [the rewrite] turned out... The entire task took less than a week, with 80% of the code written in a single weekend.

    I liked what Paul Graham (Lisp guru, and one of the founders of Y Combinator, the VC firm that funded reddit) said about the rewrite in Python.

       (1) Tags: [Lisp, Programming, Python]

Daily link icon Friday, December 2, 2005

Unusual Python list comprehensions

I needed to write a little code that would grab the filenames of all zip files out of a directory hierarchy. I immediately tried to write it as a big list comprehension and completely failed. So, I backed off a step to the following (some code in this post refomatted to not break my layout):

finalfiles = []
for (dir, subdirs, files) in os.walk("c:/temp/"):
    finalfiles.extend([
        os.path.join(dir, file)
        for file in files if file.lower().endswith(".zip")
    ])

I took a look at the list comprehension examples in the Python quick reference to figure out why I was having a problem. Here is their reference code (the two blocks are equivalent):

result = [expression for item1 in sequence1  if condition1
             for item2 in sequence2 ... for itemN in sequenceN
         ]

result = []
for item1 in sequence1:
    for item2 in sequence2:
        ...
        for itemN in sequenceN:
            if (condition1) and further conditions:
               result.append(expression)

So, first I converted my finalfiles.extend() to an append() form:

finalfiles = []
for (dir, subdirs, files) in os.walk("c:/temp/"):
    for file in files:
        if file.lower().endswith(".zip"):
            finalfiles.append(os.path.join(dir,file))

so that I could directly translate from the nested loop version to the list comprehension version, essentially doing textual substitution of item1, expression, and so on.

After doing the substitution, this is what you wind up with:

finalfiles = [
    os.path.join(dir,file)
    for (dir, subdirs, files) in os.walk("c:/temp/")
    for file in files if file.lower().endswith(".zip")
]

That seems backwards to my brain, which is why I didn't get it right the first time. I think this is really a case where doing a list comprehension is not clearer than doing at least part of it in a normal loop fashion.

Note: my brain feels like it should be this way:

finalfiles = [
    os.path.join(dir,file)
    for file in files if file.lower().endswith(".zip")
    for (dir, subdirs, files) in os.walk("c:/temp/")
]

which corresponds rather to:

result = [expression for item2 in sequence2
    for item1 in sequence1
]

I think that makes more sense. Which fits your brain?

Daily link icon Thursday, November 24, 2005

PLNews: IronPython Demo Video Available

PLNews: IronPython Demo Video Available. To watch. Argh, you need Internet Explorer to play it. Bah.

Oh my goodness. First time through the video IE blocked the popup the video requires half-way through. Then I temporarily enabled popups in IE, and this time around the Google toolbar bundled with my computer (never turned it off since I've only used IE once to download Firefox) blocked it. Argh! And I can't even get to the Google toolbar for this window since the window has no toolbars. They could have just done the normal thing and opened up a Windows Media Player instance and been done with it.

Hey, neat presentation so far. But why does everyone who works for Microsoft sound like they've drunk the Kool-aid?

Whoa, I didn't know you could do the following in the Python interactive shell:

>>> foo = ["foo", "bar", "baz"]
>>> foo
['foo', 'bar', 'baz']
>>> bar = _
>>> bar
['foo', 'bar', 'baz']

Very cool when he debugged Python, going through stack frames back into the C# code that called it.

Daily link icon Monday, November 7, 2005

  1. Ian Bicking: Ajaxy Exception Catching, via Ned Batchelder, who writes:

    But when I saw Ian Bicking's Ajaxy Exception Catching screencast, my mouth dropped open. He's built something (WSGI middleware, what the heck is that?) that catches exceptions in your web application, and displays a stack trace in your browser. Big deal. But you can also expand the line numbers to see context lines of code around the lines themselves. Nice. Then you can expand some more to see all of the local variables at each frame in the stack. Whoa! Then you can type arbitrary Python into an edit control and have it evaluated in the context of that frame. Magic!!

    Really was impressive. Check out the screencast.

       (0) Tags: [Ajax, Python, Web]

Daily link icon Wednesday, November 2, 2005

  1. Biopython (via Michael):

    The Biopython Project is an international association of developers of freely available Python tools for computational molecular biology.

    It is a distributed collaborative effort to develop Python libraries and applications which address the needs of current and future work in bioinformatics.

    Rock. Python has everything!

       (0) Tags: [Programming, Python]

Daily link icon Sunday, October 30, 2005

  1. PyMat -- Python to MATLAB Interface:

    NumPy is a set of numerical extensions for Python that introduces a multidimensional array type and a rich set of matrix operations and mathematical functions. Users who have MATLAB 5 installed, however, may wish to take advantage of some of MATLAB's additional functions, including the plotting interface. The PyMat module acts as an interface between NumPy arrays in Python and a MATLAB engine session, allowing arrays to be passed back and forth and arbitrary commands to be executed in the MATLAB workspace.

    Via Michael.

       (0) Tags: [Matlab, Python]

Daily link icon Wednesday, October 19, 2005

  1. Hans Nowak on Ruby vs. Python:

    After some more hacking on Ruby, it becomes all the more obvious that it's messy in many ways. And that's one of the reasons why it's going to outpace Python.

       (1) Tags: [Programming, Python, Ruby]

Daily link icon Monday, October 17, 2005

  1. PyPy:

    The PyPy project aims at producing a flexible and fast Python implementation. The guiding idea is to translate a Python-level description of the Python language itself to lower level languages.

    via dirtSimple.org: Children of a Lesser Python.

       (0) Tags: [Programming, PyPy, Python]
  2. Pyro - About:

    Pyro is short for PYthon Remote Objects. It is an advanced and powerful Distributed Object Technology system written entirely in Python, that is designed to be very easy to use. Never worry about writing network communication code again, when using Pyro you just write your Python objects like you would normally. With only a few lines of extra code, Pyro takes care of the network communication between your objects once you split them over different machines on the network. All the gory socket programming details are taken care of, you just call a method on a remote object as if it were a local object!

    via Why I ditched XMLRPC in favor of Pyro.

       (3) Tags: [Programming, Pyro, Python]

Daily link icon Saturday, October 8, 2005

  1. An Ordered Dictionary for Python, via The Farm.

       (0) Tags: [Programming, Python]
Page 1 →
May 2008
SunMonTueWedThuFriSat
 123
45678910
11121314151617
18192021222324
25262728293031



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 2 posts

Recent comments XML

new⇒Maps of Iraq

my husband is in Scania too..he​says it's not too bad..he's been at​worse...

Cristy: May 16, 3:54pm

"IMDB for music"

IMDB for Music? It looks to be a​couple of years old...​http://MusicTell.co...

Ken Empie: May 14, 9:57pm

Generated in about 0.995s.

(Used 11 db queries)