Q:Pythonic way to create list of lists
I am just learning Python. I am trying to create a list of empty lists: [[], [], [], ...] (10 items total). What is the most Pythonic way to do this? If I use a list comprehension (as in myList = [[] for item in xrange (0, 10)]), Netbeans warns me that 'item' is never used. If I use a for-loop (as in for item in myList = []; for item in xrange (0, 10): myList.append([])), Netbeans still warns me of the same thing. If I use '*' (as myList = [[]] * 10), all of the empty lists refer to the same object; changing one changes them all. Do I have to live with the warning, or is there a "better" way? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Q: "Best" book for teaching
I am considering teaching an "introduction to programming" course for continuing education adults at a local community college. These would people with no programming experience, but I will require a reasonable facility with computers. What would be a good book to use as the text for the course? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing dynamic languages
This may be obvious but, clearly there are (at least) two general types of errors: those caused by data external to the program and those caused by bugs in the program. For all inputs coming into the program from outside, such as user inputs and data coming over a network, the inputs must be completely checked -- always assume that they will be incorrect and are intended to crash your code -- be pleasantly surprised when they are not :-). Check for all bad inputs. If the data are from inside the program, the assumption may be that they are good and if not, it was a bug. I suppose you can write unit tests on each routine to see that the methods that routine calls are with valid arguments (using mocks). I actually tried this in a Java program using JMockit; it was tedious, but it did catch a few "potential" bugs. I would love to say that I ALWAYS remember the input and output condition of every subroutine I write, but I just finished a new feature for a company project that involved 100+ routines and classes and I admit that I don't always remember which ones can return null and which always return empty arrays, for example, even though I try to write JavaDocs at the top of each routine. By mocking these routines, I can check that the caller always handles each case gracefully. -- http://mail.python.org/mailman/listinfo/python-list
Testing dynamic languages
I am a Java developer. There, I said it :-). When I am writing code, I can rely on the compiler to confirm that any methods I write will be called with parameters of the "right" type. I do not need to test that parameter #1 really is a String before I call some method on it that only works on Strings. If I am writing in Python, since it is dynamically, but strongly typed, I really should check that each parameter is of the expected type, or at least can respond to the method I plan on calling ("duck" typing). Every call should be wrapped in a try/except statement to prevent the method (and program) from crashing when my method is called with an integer instead of the expected string. Is this the experience that Python programmer (of large projects) see? Do you also write unit tests to confirm that the methods actually check for and catch "bad" parameter types? If I am writing small one- off scripts, I wouldn't worry about it, but if I am writing a large system that must have 99+% uptime without constant monitoring, this really should be verified. Up for discussion... -- http://mail.python.org/mailman/listinfo/python-list
Re: Unit testing frameworks
In unittest, has anyone used the *NIX command "find" to automatically build a test suite file of all tests under a specified directory? I generally name my tests as _Test_ORIGINAL_MODULE_NAME.py where ORIGINAL_MODULE_NAME is the obvious value. This way, I can include/ exclude them from deployments, etc. in my Makefile based on filename patterns. I was thinking of doing something with "find" to get a list of test file names and then run them through a Python script to produce a top-level suite file, probably as the first step in my Makefile test target. Any thoughts? -- http://mail.python.org/mailman/listinfo/python-list
Unit testing frameworks
I am looking for a unit testing framework for Python. I am aware of nose, but was wondering if there are any others that will automatically find and run all tests under a directory hierarchy. Thanks, Ralph -- http://mail.python.org/mailman/listinfo/python-list
Re: Preparing teaching materials
Very nice. I printed out the PDF manual for sphinx. I'll take a look at it. -- http://mail.python.org/mailman/listinfo/python-list
Preparing teaching materials
I am considering teaching a beginning programming course using Python. I would like to prepare my class handouts in such a way that I can import the Python code from real ".py" files directly into the documents. This way I can run real unit tests on the code to confirm that they work as expected. I am considering using LaTeX to write the handouts and then converting them to PDF files. I will probably use a Makefile to convert the LaTeX with embedded Python code into the PDF files using pdflatex. I will probably organize my directory structure into sub-directories py-src, py-test, doc-src, and doc-dist. I will be starting out using Windows Vista/cygwin and hopefully switch to a Macbook this summer. Any thoughts? -- http://mail.python.org/mailman/listinfo/python-list
Re: Is python worth learning as a second language?
The other day one of our developers said that he thought learning assembler language in college was a total waste of time. I can't disagree more. Even if assembler language is specific to one architecture, the principles that it teaches are universal and fundamental to all other programming languages. Besides, programming in assembler can be fun, in a sick sort of way... :-) -- http://mail.python.org/mailman/listinfo/python-list