Friday, February 19, 2010

Addicted to Binary Blobs

 The Mono folks, lead by Miguel de Icaza, released a Moonlight 3.0 Preview that actually plays Microsoft Silverlight 3 videos on my 64-bit Ubuntu Linux box. I was able to go to the NBC Olympics website ("Powered by Microsoft Silverlight") and actually watch videos on Linux. Before this did not work at all, and yes, I had Moonlight installed. It just didn't work on these videos. With the 3.0 preview installed, it just worked. (Well, it just worked after I followed the prompting to accept a license agreement and download some codecs, but that's the norm for non-free software.) When I played a video, first I am warned that I am using an unsupported operating system, and then the video plays. It plays pretty good in the small window embedded in the web page, but it seems to have problems with full screen. (That could be a problem with my network connection.) Well done, folks! Kudos!

Of course, if I go to the site for Microsoft Security Essentials and try to play the installation video, all I get is audio. Not that I could (or would) install that software on Linux, but still, the Silverlight installation video still should play. It works on Windows.

Wow. I have just now lost all my open source credibility. Umm, play ogg?


I'm a sucker for sound and video. Seriously. I listen to more music, radio and TV on my computer than I do using any other device. I probably should not be wasting so much time, but I do need to get my fix. I watch my video and listen to my music on Linux, not on Microsoft Windows or Mac OS X. It all works pretty well most of the time, but I can't do it without using non-free "binary blobs" of software. This is the norm for Windows and Mac OS X, but Linux is generally free and open source. Generally. The dirty secret of Linux is that almost everyone who plays sound and video usually does so with proprietary, non-open source software, such as MP3 or Flash. This stuff may be free as in free beer, but it is not free as in free speech. There are open source alternatives, but it can be hard to find radio stations and video sources using them. It's not pretty, but that's the way it is. You can read all about Free and Open Source Software issues at the Free Software Foundation. Play ogg, if you can. If you can't, you must make you own choices. I put the binary blobs in. You might choose to leave them out.

According to my beautiful and talented sweetie, Miss Lizzy, the most important thing my computer does it print out the day's crossword puzzle for her.  She's not very upfront about this, but that's that the way it is. She will hover around me in the morning, waiting for me to print out the crossword puzzle. (This is a good thing, because I like sugar.) This crossword puzzle in question is an Adobe Flashplayer application that runs in a web browser, usually Firefox for me. All was well until one fine day, the puzzle would not print out. Aw, snap! Dang old software upgrades.

The printer is still working fine, and I can print from any application I want, except from the Flashplayer crossword puzzle. Even the frickin' built in scanner still works. No fun here, and sugar may soon be rationed. There is a work around, but it's fugly. The work around is to tell grub to boot Windows Vista, where Firefox and Flash can print out a crossword puzzle for Lizzy. Yuck! Windows one huge non-free binary blob, and now I need it. This is killing me. Help me! Help me! Next, I'll be on TV with Bill Gates, saying "I'm a pc!" and "Bing!".

The things I do for love.
 

Thursday, February 18, 2010

Adding SDL


Now that I have the basic data structure representing the cellular automata "world", it's time to start hacking in the graphics code. I'm using Simple DirectMedia Layer (SDL) to make the magic here. Why SDL? Well, I started doing this stuff in Python, where I used pygame to make the magic, and SDL is the magic behind pygame.

SDL was the library that Loki Games used to port commercial games from Windows to Linux. I even purchased one. Sadly, Loki is gone, but SDL is still here and is even still under development. Ignorant as I am, it seems as good a choice as any.

The magic so far

The display portions of the code were copied from a demo that I found somewhere on the net. Sorry, I don't remember where.  Ask Google -- the code is out there. Most of the comments are from that source. Originally the program displayed a bitmap; I hacked it to my bidding. I won't say much more about the code, although I could go on until the cows come home.

One tweak that come to mind is to change the world vector's data type, which is currently a C++ int, which is 4 bytes on my machine. I really don't need 4294967296 different values to hold 2 states, 0 or 1. A bool would do nicely, or maybe a shorter king of unsigned integer type, if I decide to encode more information about the cell. It's on the TODO list.


#include <iostream>
#include
<vector>

#include
<cstdlib>
#include "SDL/SDL.h"


using namespace std;

const int XRES = 1024;
const int YRES = 768;
const int BLOCKSIZE = 8;
const int DELTA_T = 250;
const int FCOLOR = 0x00FF00;
const int BCOLOR = 0x000000;
const int ROWS = YRES / BLOCKSIZE;
const int COLS = XRES / BLOCKSIZE;

int randomStart(vector<SDL_Rect> & cells, vector<vector <int> > & world) {
        srand(time(NULL));

        SDL_Rect p;
        int pct;

        for (int row = 0; row < ROWS; ++row)
        {
            for (int col = 0; col < COLS; ++col)
            {
                pct  = rand() % 1000;
                if (pct < 375)
                {
                    p.x = col * BLOCKSIZE;
                    p.y = row * BLOCKSIZE;
                    p.w = BLOCKSIZE;
                    p.h = BLOCKSIZE;
                    cells.push_back(p);
                    world[row][col] = 1;
                }
                else
                    world[row][col] = 0;
            }
        }
    return 0;
}

int main() {
    vector<SDL_Rect> cells;
    vector< vector<int> > world(ROWS, vector<int>(COLS,0));

    // initialize SDL
    SDL_Init(SDL_INIT_VIDEO);

    // populate the world
    randomStart(cells, world);   // pass by reference

    // set the title bar
    SDL_WM_SetCaption("Cellular Automata", "Cellular Automata");

    // create window
    SDL_Surface* screen = SDL_SetVideoMode(XRES, YRES, 0, SDL_DOUBLEBUF);

    // Create background and block
    SDL_Surface* bg = SDL_CreateRGBSurface(SDL_SWSURFACE,XRES, YRES, 32, 0, 0, 0, 0);
    SDL_Surface* block = SDL_CreateRGBSurface(SDL_SWSURFACE, BLOCKSIZE - 2, BLOCKSIZE - 2, 32, 0, 0, 0, 0);
    SDL_FillRect(block, NULL, FCOLOR);

    // blit a block
    for (unsigned int i = 0; i < cells.size(); ++i)
        SDL_BlitSurface(block, NULL, bg, &cells[i]);

    SDL_Event event;
    bool gameover = false;

    // message pump
    while (!gameover)
    {
        // look for an event
        if (SDL_PollEvent(&event)) {
            // an event was found
            switch (event.type) {
                // close button clicked
                case SDL_QUIT:
                    gameover = true;
                    break;
                // handle the keyboard
                case SDL_KEYDOWN:
                    switch (event.key.keysym.sym) {
                        case SDLK_ESCAPE:
                        case SDLK_q:
                            gameover = true;
                            break;
                    }
                    break;
            }
        }
        // draw the background
        SDL_BlitSurface(bg, NULL, screen, NULL);

        // update the screen
        SDL_UpdateRect(screen, 0, 0, 0, 0);
    }
    // free the background surface
    SDL_FreeSurface(bg);

    // cleanup SDL
    SDL_Quit();

    return 0;
}



Wednesday, February 17, 2010

Coding in C++, or Why I like Python

I've been working on converting my cellular automata program from Python
using pygame to C++ using SDL. Now I remember why I like Python so much more than C++.

Admittedly, my C++ is rusty. I studied C++ back in the days of #include <iostream.h>, and I liked it so much that as soon as class was over, I started looking for another language to hack in. Almost anything else. Seriously. While I was away, I missed the whole namespace thing, which was just waiting to bite me.  I flirted with Java, but it reminds me way too much of C++. (I found Java to be kind of like C++, only slower and without pointers. I realize that some will take issue with the "slower" label, but that was my experience.) Then I turned to the Dark Side and used Visual Basic for a while, because I was running windows anyway on my fully operational Death Star computer. Eventually. I came to my senses and repented my sins, and switched to freeBASIC, and Ubuntu Linux, which are both pretty darn good.

Then I decided I needed to stop coding in BASIC. Cold turkey. Why? I'm not really sure. Possible reasons include:
  • My Commodore 64 is long gone. (True, but freeBasic is a long way from C64 BASIC. A very, very long way.) 
     

    (Photo by:  Bill Bertram)

    • BASIC programmers get no respect. (True that.)
      • BASIC programmers are brain dead. (OK, I am brain dead by design, not because my first programming language was BASIC. This must be a feature, and not a bug. For the record, my first programming language was FORTRAN.  I hacked code using an IBM keypunch at Oakton Community College, back when OCC was located at Oakton & Nagle. Let me tell you, IBM manufactured a solid keypunch. Hanging chad was not a problem.) 
      • There's something better out there? (Maybe. I still don't know.)
      • It's lonely out there, in BASIC but-not-Visual-Basic land. Most of the kids are playing somewhere else. Who can you plagiarize learn from? 
      • The prolix syntax of BASIC was giving me writer's cramp.

      I'm still not exactly sure why I left freeBASIC behind; I do remember that I wasn't happy with it. The grass must be greener on the other side, right? For whatever frivolous reason, I decided that I needed a new formal language, stat. I looked around, and decided on Python. I'm pretty happy with it. It's easy peasy, clean, and it generally runs fast enough. There are many people out there to learn from, although some of them speak in tongues.

      So why the return to C++?

      Well, pygame is using SDL to do its magic, and to better understand pygame I want to learn more about SDL, which "is written in C, but works with C++ natively." [1] I want to learn more about making pretty moving pictures and sound on my computer, and I want to be a bit closer to the hardware. I will be doing that, for now, using Simple DirectMedia Layer (SDL). It looks like C++ will help me with that, so it's time for me to re-confront the beast.  


      (I'm not in the mood for doing C right now, thank you very much. I did study C in my night school career. I have even written a linked list in C. I don't feel the need to do it again, unless absolutely necessary. C++ means never having to implement another list ADT again, ever.)

      The story so far:

      Once I got over the whole "now it's
      #include <iostream>
      using namespace std;
      thing" I ran smack into the I can't believe that I have forgotten the whole concept of "pass by value" vs " pass by reference" thing. How could I have forgotten what a big, fat, hairy deal it was to write beautiful code in C++? This here is one very good reason to like Python.

      In Python, if you want to pass a list to a function, you just pass the list (which is an object)  to the function. If you want to return the list after the function is done with it, you can return the list (which is still the same object, only possibly somewhat changed) from the function. This appears to be passing by reference. This makes sense, because generally you would not want to deep copy a list, which is what you would have to do to pass a list by value.  If you want to pass a 2D array to a function, well, you do the same as you would with the list, because a 2D array in Python is a list of lists.  (Unless you're using numpy. Then a 2D array is... I dunno. Beats me.) No worries, and best of all, automagically handled.

      Mind you, you have to remember which Python objects are immutable and which are mutable, but that's about it.

      For example, the Python version has this function, which updates a 2D "array" (actually, a list of lists) named "ca_matrix". I can easily pass the ca_matrix object to the function, and even easily pass it to yet another function, cellNextgen.

      def updateCA_MATRIX(ca_matrix, ruleset, mode):
          global COLS, ROWS
          tarray = makeCA_MATRIX()
          for row in range(ROWS):
              for col in range(COLS):
                  tarray[row][col] = cellNextgen(row, col, ca_matrix, ruleset, mode)
          return tarray 


      Note that I cannot change ca_matrix here because I need it unchanged to calculate the next generation's ca_matix. If you want to, you can easily pass a list to a function, modify it and the changes will be in the scope of the calling function. For example, in Python 2.6.4:

      #! /usr/bin/env python

      def change_list(s):
          s[0] = 2*s[0]

      s = [1,2,3,4]
      print s

      change_list(s)

      print s
      Gives the following output:
      [1, 2, 3, 4]
      [2, 2, 3, 4]
      No worries, just code it.

      In the C programming language, there are no lists, unless you roll your own list type. If you ever take a decent class in C programming, the teacher will make you do so. In C++, there are these list-like things called vectors , as well as lists and some various other "containers". (Alas, none of them contain beer.) You just have to learn how to use and abuse them. They seem useful.

      For the truely brave, you can also roll your list type, just like in C. Initially, I opted for vectors and a C style 2D array... and I should have been using just vectors. For the record, it was great sport, sorting out how to pass a an array by reference in C++. Now that I know how, they are gone from my code. I don't think they'll be back again, at least in my C++ stuff.

      The simple truth is that in C++ you should use C++ code, not C code; you must learn not only when you want to pass by value or pass by reference but also how to pass by value or pass by reference. C++ compilers are finicky. In Python this stuff is just not a problem.

      The C++ code so far:


      #include <iostream>
      #include <string>
      #include <vector>
      #include <cstdlib>    // for random numbers

      using namespace std;

      // Globals
      const int XRES = 1024;
      const int YRES = 768;
      const int BLOCK_SIZE = 4;
      const int DELTA_T = 250;
      const int FCOLOR = 0x00FF00;
      const int BCOLOR = 0x000000;
      const int ROWS = YRES / BLOCK_SIZE;
      const int COLS = XRES / BLOCK_SIZE;

      struct point {
              int x;
              int y;
      };

      int randomStart(vector<point> & cells, vector<vector <int> > & world) {
              srand(time(NULL));

              point p;
              int pct;

              for (int row = 0; row < ROWS; ++row)
              {
                  for (int col = 0; col < COLS; ++col)
                  {
                      pct  = rand() % 1000;
                      if (pct < 375)
                      {
                          p.x = col;
                          p.y = row;
                          cells.push_back(p);
                          world[row][col] = 1;
                      }
                      else
                      {
                          world[row][col] = 0;
                      }
                  }
              }

              cout << "During randomStart: cells.size() = " << cells.size() << endl;
          cout << "done randomStart" << endl;

          return 0;
      }
      Initially I used a vector and an array of arrays. I lost the array of arrays because arrays are are evil. I should have been using a vector of vectors instead of a C++ array of arrays. This is especially true because figuring out how to pass a 2D array to a function in C++ was painful. (References: http://www.parashift.com/c++-faq-lite/containers.html#faq-34.1, http://bytes.com/topic/c/answers/61931-passing-array-function-reference-pointers) 

      Initially I used #define for magic global values when I should have been using const. I fixed that.
          The idea here is to write C++ code using C++, not C. My goal is to write good Python code using the best Python practices; to write good C++ code using the best C++ practices.

          I'm still working on it.

          Notes:
          [1] http://www.libsdl.org/








          Tuesday, February 9, 2010

          Back to C++

          Replicators on a toroidal surface
          (Ruleset: B36/S23 "HighLife")

          Many have written cellular automaton programs.
          A cellular automaton (pl. cellular automata, abbrev. CA) is a discrete model studied in computability theory, mathematics, physics, theoretical biology and microstructure modeling. It consists of a regular grid of cells, each in one of a finite number of states, such as "On" and "Off".  [1]
          Cellular automatons are often referred to as "Conways Game of Life", which is one type of cellular automaton. For exploring cellular automatons on your computer,  I can highly recommend both Golly (runs on Windows, OS X or Linux) or Mirek's Cellebration (Windows, and wherever Java applets can run.) They're both great programs. There are others available, too. Just ask your favorite search engine. Since I want to explore writing software, and cellular automatons seem like fun, I wrote my own cellular automation program, in Python. It's now working fairly well. I just cleaned up a few bugs features and added a toroidal surface mode, which is really cool. (I got that idea from Nathaniel Johnston's blog.) Now that the program is working well enough,  I want to convert it to C++, which is one of the languages that I studied in night school. It can't be that hard, right? It might even be fun.


          I started coding in Python, because it's rather easy peasy compared to other programming languages I have used: interpreted, with a large standard library, yet still fast enough. Currently, Python is the main tool I use for programming. (I also started studying Scheme, initially to try to get a handle on recursion, later to learn functional programming. Still working on it.)

          Now it's time to use a compiled language for a while, so C++ it is. Why a compiled language? Because I fell like it. Why C++? For a most excellent reason, namely I studied a few years back in night school and I'm already somewhat familiar with it.
          `
          People tend to favor what they are already familiar with.

          I studied C++ a number of years ago, while the language standard was still evolving. I used to write C++ something like this:

          #include <iostream.h>

          void main()
          {
              cout << "Hello, world!" << endl;
             
              return 0;
          }
          And it worked just fine. (Yes, it is odd for a function that returns void returning an integer. Yet I remember this working. Go figure. Some things in life just don't make sense.)[2]

          This certainly does not work now. To be fair, the professor told us that would probably be the case, but not to worry, because it wouldn't change that much.) Well, what hat has changed? The C++ compiler I am using (GNU g++, gcc version 4.4.1), is supposed to mostly follow the current C++ standard. It supposedly is closer to the standard than many other compilers. Here's some changes that I noted: the current C++ standard now uses namespaces, iostream.h is now iostream and main must return an integer. Rewriting the code gives:
          #include <iostream>
          using namespace std;

          int main()
          {
              cout << "Hello, world!" << endl;
              return 0;
          }

          which works.
          mikey@hatshepsut:~$ g++ -o hello hello.cpp
          mikey@hatshepsut:~$ ./hello
          Hello, world!
          mikey@hatshepsut:~$
          This works, too:
          #include <iostream>

          int main()
          {
              std::cout << "Hello, world!" << std::endl;

              return 0;
          }
          Aside from this stuff, it's seems to be the same. I guess I'll find out as I go along.

          My Python program uses pygame for displaying the graphics. Pygame is built on SDL (Simple DirectMedia Layer). SDL is " a cross-platform, free and open source software multimedia library written in C that presents a simple interface to various platforms' graphics, sound, and input devices."[3]  SDL also works with C++. I used Python's built-in list data type. C++ has the Standard Template Library, which provides both a vector and a list container, either of which should work for me. That's all the magic there is, at least for this project. Let's see how it goes.

          Notes:
          [1] Wikipedia article: Cellular automaton (Tue Feb  9 10:59:37 CST 2010)
          [2] No, I am not imagining this. Track down a copy of How to think like a computer scientist  C++ Version First Edition by Allen B. Downey on the Internet if you don't believe me.
          [3] Wikipedia article: Simple DirectMedia Layer (Tue Feb  9 10:26:16 CST 2010)

          Friday, February 5, 2010

          Next on the Agenda

          A 1952 Soviet poster advertising pelmeni
           (Source: Wikipedia pelmeni article.)

          After the great success of the Tropical Vacation Lunch, I seek new culinary worlds to conquer. I've been eating lots of frozen pierogi, pelmeni and gyoza lately. I decide that it was time for me to cut out the middleman and to start rolling my own. Fortunately, the beautiful and talented Maangchi has a video on how to make the Korean version, which are called mandu. To my delight, you can buy the wrappers from a grocery store. The ingredients are in the house, and the dried shiitake mushrooms are soaking right now. Later, I'm gonna be cooking with Maangchi. Miss Lizzy will be so jealous.

          (Later, after the shiitake mushrooms have finished soaking.)

          I kept my cheatsheet handy.

          Everything went like clockwork, just like in Maangchi's video except I ran out of wrappers long before I ran out of the meat mixture. I don't really see that as a problem because I was getting tired and my back was starting to hurt. I was really glad to wrap up the remaining meat mixture and stick it in the fridge for later.  I can buy some more wrappers tomorrow. I also really wanted to eat some mandu.

          I really need to buy more wrappers!
          I think next time I make these I'm going to try to press gang Miss Lizzy into helping me, which could be fun. We can flirt around with each other as we make mandu.  I wonder if this is a world-wide problem. Are many unplanned pregnancies the result of promiscuous mandu making?

          mandu

          I'm going to do this again now that I know how easy it is.

          Lunch is served


          Wednesday, February 3, 2010

          Spam Musubi



          It's February in Skokieland, and a fresh snowfall has come, adding yet another layer of beautiful white snow. Santa has long since come and gone, leaving a nice stocking full of coal under the Hanuka  bush to keep Mike warm. It would be lovely to be somewhere warm, near the ocean, and sit and sip umbrella drinks after parasailing, but that is not in the cards for an unemployed layabout such as I. Still, the most wonderful Miss Lizzy has got a nice bunch of coconuts and a plate full of Spam musubi, made by yours truly, Mike. I call it my tropical vacation lunch. I had to roll my own Spam musubi because the 7-Eleven's of Skokieland do not carry it. The Illinois Tech 7-Eleven did (and maybe still does) carry decent pitas stuffed with felafel or chicken shawarma, and samosas with wonderful green coriander chutney but that is literally on the other side of town, over an hour away on the el. The local joints do sell mediocre po' boys featuring soft bread rolls, yellow process cheese and something like Oscar Mayer bologna sausage, but that's just not working for me today.

          Yes, I have eaten these alleged po' boys. It's one of the night school students quick meal units. We'll discuss the frozen burrito fetish later -- you need to microwave those, and often there's just not enough time or clean microwaves available.

          I never thought I would ever be eating spam, much less cooking it with teriyaki sauce, but here I am. I blame it on winter, and the general lack of good tomatoes.

          Of course, Spam musubi ain't half bad, especially  with some furikake added. Since Miss Lizzy purchased the jumbo tin of Spam, I only used half the can so far. I can see more Spam teriyaki in my near future.

          Monday, February 1, 2010

          Python 3000, or Confuse-A-Coder

           (Photo by:Matthew W. Jackson)

          So here I am, newbie pythonista. Writing code. On my computer. On other people's computers, using Portable Python. Doing new, geeky things. Impressing boring my wife. (Nitey-nite, honey.) This is truly beautiful. I now almost grok Dive Into Python, and have actually even read parts of it. I can even pick Guido van Rossum out of a police lineup, if needed.

          OK, to be honest, How To Think Like a Computer Scientist is more my speed, and I have worked through all of that. (Alas, I still think like Mike.)  I even did the entire MIT 6.00 class, (which now has video!) although I do not yet grok the dynamic programming solution to the knapsack problem. I did study electrical engineering, and even earned a BSEE, but math/CS types study some different stuff, I think. Or perhaps I was dozing through class? Either could be true, as far as I can tell.

          Things change over time. Some changes are a good thing. Isn't there anything you would like to change in your life? Wouldn't would you like a few do-overs? I sure could use a few. The Python guys seem to think so, too. Python is transitioning to Python 3, and things are bit different. Some things have been really done over. Here are some differences that I have found, explained simply.

          Print is now a function and not a keyword.
          This means you have to say:  
          print()
          instead of :
          print
          You can no longer say: 
          print 'spam spam spam',
          to suppress the newline. You now must say:
          print('spam spam spam', sep="")

          Yes, I know, this is gripping material. Apparently someone, somewhere wants to be able to redefine print to do something useful, like making spam musubi topped with foie gras, or confusing a cat. This is not possible with print defined as a keyword, so get used to the parentheses. A good way to do that is to put the following line near the top of all your Python 2 code:
          from __future__ import print_function
          This will enforce the Python 3 syntax, and you won't have to change your code if you ping-pong between Python 2 and Python 3, as I do.

          Integer division can now return a float. 
          Before Python acted like, well, the C programming language that I remember learning at night school. If you divided two integers, your result was always an integer. So 5/2 would return 2
          (Note that the sentence lacks a period because 2 is an integer, while 2. is a float. Adding a period is confusing.)

          In Python 3, if you divide two ints, you can get a float. In Python 3,  5/2 will return 2.5
          (Again, I left the period off on purpose.) This is the correct answer, after all. I think Guido van Rossum changed his mind here. No biggie, unless you do as much crap ass integer calculation that comes from working  Project Euler  problems.

          To get used to this new behavior, put  the following line near the top of all your Python 2 code:
          from __future__ import division
          If you want to use integer division, use the integer division operator  // instead of the division operator /

          If you want to work on Project Euler problems, seek professional help.

          Strings have changed.
          I've just started working with this. According to Guido,
          Python 3.0 uses the concepts of text and (binary) data instead of Unicode strings and 8-bit strings. All text is Unicode; however encoded Unicode is represented as binary data.
          I'm still sorting this out so I can't help you much here. To enforce Python 3 strings text,  put  the following line near the top of all your Python 2 code:
          from __future__ import unicode_literals

          My current project, a Python synthesizer noisemaker,  pukes and errors out  if I use this line. Works fine in Python 2.6.4 without it. I seem to be confused about using the wave and struct modules. At least I think that's the problem. I'm not using much else in the way of strings text in the program. I plan to sort this out down the road.

          A lot of functions that used to return a list now return an object that is not a list.

          Guido writes:

          Views And Iterators Instead Of Lists

          Some well-known APIs no longer return lists:
          • dict methods dict.keys(), dict.items() and dict.values() return “views” instead of lists. For example, this no longer works: k = d.keys(); k.sort(). Use k = sorted(d) instead (this works in Python 2.5 too and is just as efficient).
          • Also, the dict.iterkeys(), dict.iteritems() and dict.itervalues() methods are no longer supported.
          • map() and filter() return iterators. If you really need a list, a quick fix is e.g. list(map(...)), but a better fix is often to use a list comprehension (especially when the original code uses lambda), or rewriting the code so it doesn’t need a list at all. Particularly tricky is map() invoked for the side effects of the function; the correct transformation is to use a regular for loop (since creating a list would just be wasteful).
          • range() now behaves like xrange() used to behave, except it works with values of arbitrary size. The latter no longer exists.
          • zip() now returns an iterator.
          I grok some of this, and I have run into problems with these changes in the wild. Especially when plagiarizing copying using other people's code. You can't make lists anymore by saying things like:
          s = range(1000)
          In Python3, s is not a list. This idiom is real popular in the wild. Remember this when you use Google to find someone else's code to solve your problem. It doesn't work any more. You must explicitly create the list:
          s = list(range(1000))
          if you really want s to be a list.

          I tend to read in numeric data from text files, and it winds up as strings in a list. Being the schemer that I am (more later, maybe, on the joys and sorrows of Lisp) I would use map() to convert all the strings in a list to integers. Here's a line of code that I wrote on 13 Mar 2009:
          temp1 = map(int,data.split())
          For Python 3, you would have to say:
          temp1 = list(map(int,data.split()))
          A better solution is to stop writing Lisp code in Python and use a list comprehension, which works in both Python 2 and Python 3:
          temp1 = [int(x) for x in data.split()]
          which is much more pythonic, and cleaner once you start comprehending list comprehensions.

          There's an automagic script, 2to3, which I have never used because I feel that I am still learning Python, and I need to solve this kind of problem using my finely tuned mental machine. Or all by myself, anyway. It may be useful.

          There is a -3 switch that will warn you about things that will not work in Python 3. I am starting to use this switch, but I think that some of the results are so not my problem to fix:

           mikey@hatshepsut:~/workspace/mysynth/src$ python -3 mysynth
          /usr/lib/python2.6/site.py:1: DeprecationWarning: The 'new' module has been removed in Python 3.0; use the 'types' module instead.
            """Append module search paths for third-party packages to sys.path.

          Another problem is that many useful libraries are not yet available for Python 3. No numpy  yet, and of course nothing that depends on numpy. I think this stuff will exist in Python 3, but not yet. The best thing do right now is to stick with Python 2 if you need something that doesn't exist yet in Python 3, but use the from __future__ import statements. (I'm working on it...). Otherwise, start using Python 3. Unless you're actually paid to write Python code, and your boss says No Python 3 for you!

           At least, thats what I'm doing for now.

          Cheers!
          References:
           Whats New in Python 3.0  by Guido van Rossum
          A clear explanation of list comprehensions . by Olli
          How To Think Like a Computer Scientist  (Uses Python 2.) 
          MIT 6.00 Introduction to Computer Science and Programming (Uses Python 2.)
          Dive into Python 3  by Mark Pilgrim (A challenging read for me.)