Re: [Tutor] python and sqlite

2010-01-31 Thread Chris Fuller
Since v2.5, SQLite is included in the Standard Library. You can get docs at the Python website, or in the handy chm that comes with the Windows distribution. Cheers On Sunday 31 January 2010, Samuel de Champlain wrote: > My project is relatively light and postgresql or mysql might be overkill

Re: [Tutor] packing up python code to transfer to another machine

2010-02-10 Thread Chris Fuller
There are two obvious "gotchas". One is binary extensions. If you are using modules that are not "pure Python", you will have to find *nux versions for your target. The other problem is impossible to solve in general, but most of the time, it's less trouble than the first problem. Python is

Re: [Tutor] Compile py to exe in ubuntu

2010-02-10 Thread Chris Fuller
Using freeze or another tool of its ilk is only going to make you an executable for that platform. If you want an executable for a different platform, you need to set up a native Python environment with all the dependencies installed where Python can find them, and then use that platform's to

Re: [Tutor] recursive generator

2010-03-07 Thread Chris Fuller
Here's a (more or less) useful example. It generates the "nth triangular series" (my term), n=2 is the triangular numbers, n=3 the tetrahedral numbers (n has a correspondence to dimension). Each series is the sum of the elements of the previous one. They are also the columns of Pascal's Tria

Re: [Tutor] Linux lib path

2010-04-10 Thread Chris Fuller
I'm using Debian. Used to be etch, but I did a double dist-upgrade recently. So, whatever the current testing release is. My shell is zsh, but bash should work the same. PYTHONPATH should have worked. CLASSPATH is for Java. Here's the documentation link you want: http://docs.python.org/i

Re: [Tutor] Declaring methods in modules.

2010-04-11 Thread Chris Fuller
This actually isn't so hard with classes (not instances of the class). Just use setattr(). The first parameter of the function will be the instance, called "self" by convention. This should work with both old and new style There's stuff in the new module for adding stuff to instances, but I

Re: [Tutor] Declaring methods in modules.

2010-04-11 Thread Chris Fuller
Sorry, should have included a concrete example. Although, as the others have said, I'm not sure how it helps with what you (seem) to want to do. 0 % cat bar.py def the_answer(self): return 42 0 % cat foo.py import bar class A: pass setattr(A, '__call__', bar.the_answer) a=A() print a(

Re: [Tutor] how to do excel in python

2010-08-05 Thread Chris Fuller
There are many ways. The simplest is to export the file to CSV and load that, but you'll only get one worksheet, and it's a big hassle to update the Excel file that way. You can save the spreadsheet as an ODF file, which is a fully documented XML format that Python can read and write easily,

Re: [Tutor] Distributing Python Code for Commercial Porpoises?

2010-08-06 Thread Chris Fuller
It sounds like maybe you could use Enthought Python, which is a bundle of most of the popular numerical libraries by the scipy sponsors. Not free, however, there's a trial version. http://enthought.com/products/epd.php The problem of bundling stuff is a real thorny one and has been beaten to

Re: [Tutor] a graceful program exit

2010-08-12 Thread Chris Fuller
The preferred and most graceful way is to use neither, as others have pointed out. However, you can't return an exit code that way, and it sometimes isn't feasible to structure your code to allow it. I prefer SystemExit, because it doesn't require adding something to the namespace (the sys mo

Re: [Tutor] Plotting a Linear Equation

2010-09-25 Thread Chris Fuller
It sounds to me like you need to set a nonzero linewidth. The default is to not fill in the space between points. Check out the documentation at http://matplotlib.sourceforge.net/contents.html. It's a lot to wade through, but worth it when you learn how to unlock the power of the software.

Re: [Tutor] system()? popen2()? How to execute a command & save its output?

2010-09-29 Thread Chris Fuller
You might also consider pexpect. http://pexpect.sourceforge.net/ It's designed for interactive console applications like ftp. For popen() style access, the recommended approach is the subprocess module. You should be able to find an example in the docs to fit your application. http://docs.pyth

Re: [Tutor] Moving my C++ code to Python?

2010-10-15 Thread Chris Fuller
SWIG supports opaque pointers that you can pass into and out of Python without any problems. Working with SWIG isn't that bad for basic stuff, although it can get complicated if you need to have it interpret exotica like references, structures, or such for Python. Having a good C++ background

Re: [Tutor] variable numbers of for loops (also iteration/recursion)

2010-11-23 Thread Chris Fuller
You can always substitute Iteration for Recursion by making the stack an explicit part of your code. As an example, imagine you are traversing this directory tree: birds birds/owls birds/owls/snowy birds/owls/barn birds/owls/great-horned birds/eagles birds/eagles/golden birds/eagles/bald birds/e

Re: [Tutor] Newton–Raphson's method

2009-02-16 Thread Chris Fuller
You should look into Numpy or ScientificPython. http://numpy.scipy.org http://dirac.cnrs-orleans.fr/plone/software/scientificpython Also, the main Python Wiki has a page devoted to numeric/scientific topics: http://wiki.python.org/moin/NumericAndScientific Cheers On Monday 16 February 2009 12:3

Re: [Tutor] File locking: cross platform?

2009-02-20 Thread Chris Fuller
There's a recipe in the Python Cookbook that addresses this: http://code.activestate.com/recipes/65203/ There are probably others floating around, too. Cheers ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Converting "HH:MM:SS" to datetime

2009-03-01 Thread Chris Fuller
On Sunday 01 March 2009 12:04, Wayne Watson wrote: > Ok, how do I do what's mentioned in Subject? There's an inverse to the strftime() function, strptime(), also in the time module, that will do this. Cheers ___ Tutor maillist - Tutor@python.org htt

Re: [Tutor] Difference in minutes between two time stamps

2009-03-02 Thread Chris Fuller
Use time.strptime() to parse them into seconds since the start of epoch, and then an ordinary numeric subtraction will work. Cheers On Monday 02 March 2009 19:45, Judith Flores wrote: > Hello, > >I can't seem to figure out the syntax to calculate the difference in > minutes between two time

Re: [Tutor] wxPython vs PyQt

2009-03-04 Thread Chris Fuller
There is a not-free GUI builder, wxDesigner, that isn't too bad (except for costing money). http://www.roebling.de The GLADE GUI builder for Gtk is very nice, however. http://www.pygtk.org/ For windows: http://gladewin32.sourceforge.net/ Cheers ___

Re: [Tutor] Gtk time control and Glade

2009-03-17 Thread Chris Fuller
Make your own. You can have empty containers in glade that you fill in at runtime, or you could create the interface in glade, perhaps a couple of ComboBoxes. I would leave an empty container and create a reusable widget descended from gtk.HBox that implements validation or anything else that

Re: [Tutor] Python and Tkinter Programming by Grayson--New Version?

2009-03-17 Thread Chris Fuller
This is a super book for beginners who are new to GUI programming. Tkinter is easy to use, and comes included with Python. Serious programmers will probably want something faster, better looking, and with nicer features, but they can be tricky to figure out and install. I still prefer Tkinte

Re: [Tutor] Python and Tkinter Programming by Grayson--New Version?

2009-03-17 Thread Chris Fuller
widget), includes a set of standard data validators, etc. Cheers On Tuesday 17 March 2009 16:27, Alan Gauld wrote: > "Chris Fuller" wrote > > This book does not cover the Tix widget set, which was originally > > created for > > Tcl/Tk and later included wi

Re: [Tutor] Tkinter Geometry Management and Other Basics

2009-03-19 Thread Chris Fuller
With respect to grid and pack, all siblings must use the same manager. Do otherwise and your application will hang. Children/parents may use different managers. I don't believe there are any restrictions on place, as it doesn't do any negotiation. Cheers _

Re: [Tutor] adding dictionary values

2009-03-20 Thread Chris Fuller
You should iterate over the keys of the dictionary: for k in a.keys(): because if you iterate over the full dictionary, your items are the values, not the keys. Otherwise your code looks correct, and I don't think its terribly bad form. You could do something interesting with sets: sa = set(a.k

Re: [Tutor] adding dictionary values

2009-03-20 Thread Chris Fuller
Oops! The dictionary iterates over keys, not values as I stated (and demonstrated by your working code). Consequently, the example I gave could be more succinctly expressed by: sa = set(a) sb = set(b) Sorry for the error. Cheers ___ Tutor maillist -

Re: [Tutor] Using C in python

2009-03-25 Thread Chris Fuller
There's a section in the Python docs just on this topic: http://docs.python.org/extending/index.html There's probably also some stuff in the wiki, although I'm not familiar with anything specific: http://wiki.python.org/moin/ The SWIG documentation is extensive, and while not the user-friendl

Re: [Tutor] Functional Derivatives

2009-04-20 Thread Chris Fuller
You should look up "numerical methods" or similar. There are ways of rearranging your calculations to minimize the loss of precision. You could also try a numerical/scientific library like GMP (for integers or rational numbers). I don't know of any (Python) library for extended precision fl

Re: [Tutor] Functional Derivatives

2009-04-20 Thread Chris Fuller
His problem was composing four functions, each with a small error. The first two applications work well enough, but there is a about a percent error in the third composition. The big source of error is f(x+h)-f(x). Subtracting two floating point numbers that are nearly equal is a known source

Re: [Tutor] Number cruncher

2009-04-22 Thread Chris Fuller
Most teachers use spreadsheets for this. Is there a reason you'd like to use Python? A spreadsheet would be easier to create and less error prone. If you don't have a copy of Microsoft Orifice handy, you can use Gnumeric or Open Office. Cheers On Wednesday 22 April 2009 10:54, John Jenkinson

Re: [Tutor] split or replace

2009-06-05 Thread Chris Fuller
On Friday 05 June 2009 06:18, Norman Khine wrote: > Hello, > What is the way to group each value so that I get a list, from a string > like: > > dir = '/expert/forum/expert/expert' > list = ['/expert', '/forum', '/expert', '/expert'] > > I've tried: > >>> dir = '/expert/forum' > >>> dir.split('/')

Re: [Tutor] Best Python Editor

2009-06-13 Thread Chris Fuller
On Saturday 13 June 2009 04:44, Eddie wrote: > Hi guys, > > What would you regard as the best free Python editor to use on Windows > for a new guy? Searching Google i see that there is quite a few out > there and is "VIM" the best one to go with? > > Regards > Eddie I've tried a lot of editors, an

Re: [Tutor] distutils MANIFEST.in

2009-06-17 Thread Chris Fuller
Use os.path.walk or similar to build the file before you call setup(). Cheers ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] how to manage an encrypted file?

2009-06-19 Thread Chris Fuller
On Friday 19 June 2009 17:23, Robert Lummis wrote: > Could you recommend a module or methods I should use to manage an > encrypted text file? I want to store passwords and associated contact > information in a file and feel confident that if the file is stolen > the information couldn't be read. U

Re: [Tutor] list comprehension problem

2009-07-03 Thread Chris Fuller
On Friday 03 July 2009 15:37, Emile van Sebille wrote: > On 7/3/2009 1:21 PM Kent Johnson said... > > > On Fri, Jul 3, 2009 at 3:49 PM, Dinesh B > > > > Vadhia wrote: > >> d = [0, 8, 4, 4, 4, 7, 2, 5, 1, 1, 5, 11, 11, 1, 6, 3, 5, 6, 11, 1] > >> > >> and we want: > >> > >> [0, 8, 12, 16, 20, 27, 29,

Re: [Tutor] int to bytes and the other way around

2009-07-06 Thread Chris Fuller
The only things that matter are the arguments and the result. It sounds to me like a good case use for SWIG (http:://www.swig.org). You can do really complicated stuff with swig, and it takes a correspondingly steep learning curve to achieve, but doing simple stuff is really simple. It sounds

Re: [Tutor] segmentation fault

2009-07-12 Thread Chris Fuller
On Sunday 12 July 2009 11:09, Rick Pasotto wrote: > I've got a script that I wrote several years ago and have been happily > using daily. Suddenly when I try to run it I get a segmentation fault. > > I'm running debian testing so probably some recent update caused the > breakage. How can I find out

Re: [Tutor] how to know if process is running?

2009-07-28 Thread Chris Fuller
On Tuesday 28 July 2009 10:45, shawn bright wrote: > Hey all, > > I have an app that runs in a GUI written in pygtk. It spawns several > threads, and runs all the time. > It is mission critical that we can never have two instances of this > running at once. > > So, my question is, how can i write s

Re: [Tutor] Program to Simulate Keystrokes

2009-08-04 Thread Chris Fuller
On Tuesday 04 August 2009 12:43, Megan Land wrote: > Hi, > > I'm working on a python script to automate a program we run at work. The > program is run from one command. The only problem is that it asks you to > hit enter to continue after it runs. Is there a way I can do this? > > If at all poss

Re: [Tutor] this module

2009-08-08 Thread Chris Fuller
On Friday 07 August 2009 21:31, Mark Young wrote: > Hi, I was reading a tutorial, and it mentioned the "import this" easter > egg. I was curious, and looked up the contents of the module, and dscovered > that it had attributes c, d, i, and s. I was wondering if anyone had any > clue what these attr

Re: [Tutor] this module

2009-08-08 Thread Chris Fuller
Something else to note: you can find any module's location by looking it up in the dictionary sys.modules. For instance: Python 2.4.4 (#2, Oct 22 2008, 19:52:44) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >

Re: [Tutor] Pyduino

2009-09-07 Thread Chris Fuller
There are a few projects attempting something like this, but it is not easy to get a language like Python running on the minimalist resources found in a microcontroller. Google "python microcontroller" (without the quotes).. you could also try the plural form to see if that brings up other hits

Re: [Tutor] Wrapper of C++

2009-10-08 Thread Chris Fuller
It might also be a good application for numpy (http://www.numpy.org/) Cheers ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] cannot convert eps to png using PIL

2009-10-15 Thread Chris Fuller
It's trying to launch GhostScript, and failing. The broken pipe is a clue that its trying to communicate with external software. Most likely, you don't have ghostscript installed. Google Ghostscript and you should find instructions for installing on windows (I'm fairly sure there is a port).

Re: [Tutor] cannot convert eps to png using PIL (LL)

2009-10-17 Thread Chris Fuller
Like I said, you need to find out what's going wrong with GhostScript. Also, converting image formats is something PIL does internally, without requiring a (large) external package like GhostScript, which is an interpreter for a different language (PostScript), which your eps files are coded i

Re: [Tutor] PyGTK: is there a library for both Linux and Windows

2009-10-21 Thread Chris Fuller
The version of GTK for windows I like to use is at http://gladewin32.sourceforge.net/, but it is rather out of date. It's main advantage is everything is bundled up in a nice installer. You can also get it from the main site at ftp://ftp.gtk.org/pub/gtk, but you have to grab several files an

Re: [Tutor] PyGTK: is there a library for both Linux and Windows

2009-10-21 Thread Chris Fuller
on differences: The downloads include binaries, so there have to be distinct files for Linux and Windoze. If you download the same versions, there shouldn't be any noticeable differences, with one big exception: multithreading and PyGTK don't mix well on Windows. Your application might run

Re: [Tutor] PyQT forum?

2009-10-29 Thread Chris Fuller
Start with the main site. There are links to wikis/mailing lists/etc there. http://www.riverbankcomputing.co.uk/software/pyqt/ Also, you might be interested in the fully-free alternate, PySide, sponsored by Nokia: http://www.pyside.org/ Cheers On Wednesday 28 October 2009 11:17, Christopher S

Re: [Tutor] working with bit arrays

2009-12-02 Thread Chris Fuller
My approach has been to store it as an array and then build the integer as needed. This code requires Python 2.5 or later. def bits2int(l): return sum([2**i if j else 0 for i,j in enumerate(l)]) To convert the other way: def int2bits(m, n): return [int(bool(m&(1<>= inc return i flo

Re: [Tutor] No beep from winsound.Beep(500, 500)

2009-12-19 Thread Chris Fuller
Something to keep in mind is that the audio output of your computer and the system speaker are independent. Sometimes the BELL character (ACSII 0x07) will sound the system speaker, spending on your OS, drivers, etc. The winsound docs say it's the speaker, which is connected to the motherboard

Re: [Tutor] how to compare elements of 2 lists

2007-12-25 Thread Chris Fuller
The most concise way to do this is to transpose the list (convert a axb array to bxa), then complare the elements that are pairs of one value each of the original lists. You have two lists, a and b.  Put these into a list and you have a 2x6 2d "array". >>> [a,b] [[4, 3, 2, 6, 7, 9], [8, 6, 3, 3

Re: [Tutor] how to compare elements of 2 lists

2007-12-25 Thread Chris Fuller
I didn't think of that. But for an arbitrary 2D list, you need the asterisk syntax. On Tuesday 25 December 2007 19:00, you wrote: > Chris Fuller wrote: > >>>> zip(*[a,b]) > > > > [(4, 8), (3, 6), (2, 3), (6, 3), (7, 2), (9, 7)] >

Re: [Tutor] how to compare elements of 2 lists

2007-12-26 Thread Chris Fuller
th. On Wednesday 26 December 2007 08:51, you wrote: > Chris Fuller wrote: > > I didn't think of that. But for an arbitrary 2D list, you need the > > asterisk syntax. > > I don't know what you mean by "an arbitrary 2D list". You need the * > synta

Re: [Tutor] how to compare elements of 2 lists

2007-12-26 Thread Chris Fuller
On Wednesday 26 December 2007 10:03, Alan Gauld wrote: > I thought I was following this but now I'm not sure. > > Do you mean that if I have a list L that contains an arbitrary > > number of sublists that I can call zip using: > >>> zip(*L) > > rather than > > >>> zip(L[0],L[1],, L[n]) > > If s

Re: [Tutor] How Do I Make Imports Work

2007-12-27 Thread Chris Fuller
On Thursday 27 December 2007 08:29, [EMAIL PROTECTED] wrote: > > e = Elevator() > e.show_state() > > raw_input("\n\nPress the enter key to exit.") > Two observations: This "module-level" code that does the testing will be run when the module is imported. A more flexible approach would be to pla

Re: [Tutor] Dynamically named objects

2007-12-28 Thread Chris Fuller
You might find a dictionary useful. Each element in a dictionary is associated with a "key", which can be a string. objectlist = {} o = eval("class1" + "()") objectlist["object1"] = o o.method("hello world") Also, try to avoid using eval(), it usually makes troubleshooting and maintenance hard

Re: [Tutor] python CLI parser

2007-12-28 Thread Chris Fuller
TUGZip (www.tugzip.com) is another free (as in speech) alternative. It has a distinct interface from 7-zip that some may prefer. Cheers ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] send file/mail to imap

2007-12-28 Thread Chris Fuller
On Friday 28 December 2007 09:31, Tim Michelsen wrote: > Hello, > I have a mbox file locally on my notebook. > > I would like to send this file to my IMAP account using python. > > Does anyone know a module or tutorial which does this? > > I tried > * IMAPClient 0.3 - http://pypi.python.org/pypi/IM

Re: [Tutor] Careful Dictionary Building

2007-12-28 Thread Chris Fuller
first thing.. you are duplicating a lot of effort inside your loops. getting rid of that will speed things up: dict = {} for record in list: rid = record[0]     if rid in dict:     dict[ rid ].append( record )     else:     dict[ rid ] = [record] The other thing I see isn't a speed p

Re: [Tutor] Installing problem in matplotlib

2007-12-31 Thread Chris Fuller
Is there a reason you are building from scratch? There are binaries for win32, and most linux distributions. You will need the development packages for libpng, zlib, and freetype, and others, depending on the GUI backends you want to use. These can be configured in the setup.cfg file. See

Re: [Tutor] how to sort the data inside the file.

2007-12-31 Thread Chris Fuller
On Monday 31 December 2007 06:19, goldgod a wrote: > hello all, >             Please find the attached file. I want to sort the content > of this file based on the "bytes" in descending order. How can i do > it, any pointers to it. This is a classic case for the use of regular expressions.  A powe

Re: [Tutor] how to sort the data inside the file.

2007-12-31 Thread Chris Fuller
On Monday 31 December 2007 10:36, Chris Fuller wrote: > lin = re.findall('\s*([^\s]+)\s+([^\s]+)\s+(\d+)( [kM])?bytes', s) This is incorrect. The first version of the script I wrote split the file into records by calling split('bytes'). I erroneously assumed I would obta

Re: [Tutor] help with list permutations

2008-01-03 Thread Chris Fuller
This is a good case for recursion. My solution is in two steps. A straightforward application of recursion (I was casting about semi-randomly) yields a attractive tree structure: root a b c d e c de f f f f ff g h

Re: [Tutor] PHP & Python suggestions....

2008-02-04 Thread Chris Fuller
he and mod_python. You can use it the same way as PHP. This might not be suitable for what you need to do, but if you could do it this way, it would probably be faster. Cheers Chris Fuller ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Ending a script

2008-02-06 Thread Chris Fuller
On Wednesday 06 February 2008 09:23, Damian Archer wrote: > When I am running a script in cmd the script runs but the cmd windows > closes immediately after the script has finished. > > Is there anyway I can freeze the cmd window until a user actually closers > it?? There are numerous ways to do t

Re: [Tutor] Binary chop function - this works, but I'm not sure why

2008-02-13 Thread Chris Fuller
On Wednesday 13 February 2008 18:49, Arun Srinivasan wrote: > I'm trying to learn Python, and I decided to try kata 2 from the > CodeKate website. It's basically just a challenge to implement a binary > search in different ways. > > I wrote an implementation that works, but I'm confused as to why.

Re: [Tutor] how to display terminal messages in dialog window using tkinter

2008-02-21 Thread Chris Fuller
There's a post on this list from me, with example code, from a couple of weeks ago that solves this: http://mail.python.org/pipermail/tutor/2008-February/060025.html Cheers On Thursday 21 February 2008 11:15, brindly sujith wrote: > hi > > i m developing a application using tkinter > > i want

Re: [Tutor] file transfer through serial modem -- pythin code

2008-02-26 Thread Chris Fuller
You probably want to start with PySerial: http://pyserial.sourceforge.net/ But, the details really depend on the application.. what are you talking to at the other end? Do you need a general terminal program? You can probably find xmodem and zmodem libraries, but if you control both ends, roll

Re: [Tutor] How to open IE7 to a certain URL?

2008-02-29 Thread Chris Fuller
On Friday 29 February 2008 06:28, Dick Moores wrote: > I keep missing a certain weekly program on my local NPR station. My > idea is to record it using software I have, Easy Hi-Q Recorder. I can > set it to start recording when the program starts, 8pm, but I need to > have the program playing on my

Re: [Tutor] How to open IE7 to a certain URL?

2008-02-29 Thread Chris Fuller
On Friday 29 February 2008 18:25, Tiger12506 wrote: > time.sleep is not exactly accurate, so I would suggest that you use this > method, short 5 minutes or so and then do a sleep(10) or so in a loop to > get closer to the time. Another advantage to shorter sleeps is it reduces the latency of anyth

Re: [Tutor] How to open IE7 to a certain URL?

2008-02-29 Thread Chris Fuller
I left out the daily increment. there should be a event_time += 86400 end of the inner loop. while True: while time()http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How to open IE7 to a certain URL?

2008-02-29 Thread Chris Fuller
On Friday 29 February 2008 12:24, Dick Moores wrote: > http://www.kuow.org/real.ram . Try this to start, then turn into a service with FireDaemon, http://www.firedaemon.com/. You'll need to fill in the quit() function, and the particulars for your media player. from time import mktime, strft

Re: [Tutor] Need help with encoder & decryption keys

2008-03-01 Thread Chris Fuller
On Friday 29 February 2008 16:30, Trey Keown wrote: > Hey all, > Been away for a while. So, I'm in the process of making a program for > encrypting and decrypting strings of text. And I was wondering how it > would be possible to perhaps keep keys in a .pyc file, and keep them > from being isolat

Re: [Tutor] sorting objects on two attributes

2008-03-03 Thread Chris Fuller
Almost. And better than my original idea. You could have a hierarchical sort function: def hiersort(a,b): if a.attr1 != b.attr1: return cmp(a.attr1, b.attr1) else: if a.attr2 != b.attr2: return cmp(a.attr2, b.attr2) else: return cmp(a.attr3, b.att3) l

Re: [Tutor] Simple reg-ex syntax?

2008-03-13 Thread Chris Fuller
How I would improve this: compile the regular expression. This is more efficient. self.digit_extractor = re.compile('(\d+)') then, use the findall method: self.allNumbers = self.digit_extractor.findall(self.aString) which will even work with multiline strings, but doesn't convert to integers.

Re: [Tutor] my first project: a multiplication trainer

2008-03-15 Thread Chris Fuller
The basic approach I use in these sorts of problems is to generate the choices, remove them from a list as they are asked, and then stop when this list is empty. If you don't need the list of questions afterwards, this will work: from random import choice questions = [ [i,j] for i in range(1

Re: [Tutor] signal trapping in a class instance

2008-03-15 Thread Chris Fuller
SIGKILL is not trappable. You probably want SIGTERM. Furthermore, this signal will be sent to the process, not some thread or class instance within a process. Maybe you need some other mechanism? Is the signal going to be from the same python process? If so, just call it directly. Otherwis

Re: [Tutor] signal trapping in a class instance

2008-03-15 Thread Chris Fuller
I read your post again, and it looks as though you might want to use the atexit module.  Another idea would be to trap the SIGTERM signal and to keep a registry of instances, and then to invoke a cleanup method of each instance. Another important note: trapping signals will have no effect if yo

Re: [Tutor] my first project: a multiplication trainer

2008-03-16 Thread Chris Fuller
On Sunday 16 March 2008 08:03, Guba wrote: > Hello! > > I like the idea of retaining my original questions by creating a proxy > list, but I wasn't able to understand (find) the proxy list: > > Chris Fuller wrote: > > from random import choice > > > > quest

Re: [Tutor] my first project: a multiplication trainer

2008-03-16 Thread Chris Fuller
Oops, I based those examples on my initial solution, not the preferred one that preserved the questions. Here is some better code. They only use the shuffle method, and I've elaborated a bit on the basic solution, to illustrate some ideas for improvement. Some things you might try as an exer

Re: [Tutor] my first project: a multiplication trainer

2008-03-17 Thread Chris Fuller
You should try some of the Python tutorials out there. There's a difference between tuples and lists, and the parameter list passed to the string formatting operator must be a tuple. String formatting will also solve your second problem. Also, the library reference is your friend. I particu

Re: [Tutor] python, wxpython and postgresql

2008-03-17 Thread Chris Fuller
Unless you have a specific reason for choosing postgresql (an excellent database, just not the easiest), such as having an existing installation, desiring networked access, or nice features such as type safety, you might want to consider SQLite instead. Also, if you stick to the DB-API spec, yo

Re: [Tutor] python, wxpython and postgresql

2008-03-17 Thread Chris Fuller
There are at least a couple of python interfaces to postgresql, but psycopg follows the DB-API spec. You shouldn't have to use the postgresql engine directly. http://www.initd.org/pub/software/psycopg/ The cool bit is that the examples you see that follow DB-API will apply to postgresql, exce

Re: [Tutor] Python to C++

2008-03-20 Thread Chris Fuller
On Wednesday 19 March 2008 18:52, Dinesh B Vadhia wrote: > Say because of performance, you might want to re-write/convert Python code > to C++. What is the best way (or best practice) to do this wrt the tools > available? > > Dinesh You also might want to use some profiling tools, or skip that st

Re: [Tutor] Maybe advanced pexpect question?

2008-03-23 Thread Chris Fuller
What about Alt keys?  I was thinking terminal control voodoo.  But I don't know any.  man 5 termcap might be a start, though. Cheers On Sunday 23 March 2008 06:58, Kent Johnson wrote: > Nathan McBride wrote: > > I've used pexpect for a few projects and love it. Basically pexpect > > lets you sp

Re: [Tutor] Maybe advanced pexpect question?

2008-03-23 Thread Chris Fuller
What about Alt keys? I was thinking terminal control voodoo. But I don't know any. man 5 termcap might be a start, though. Cheers On Sunday 23 March 2008 06:58, Kent Johnson wrote: > Nathan McBride wrote: > > I've used pexpect for a few projects and love it. Basically pexpect > > lets you s

Re: [Tutor] Library for Disk Usage (UNIX)

2008-03-26 Thread Chris Fuller
On Wednesday 26 March 2008 09:11, Tom Tucker wrote: > Hello all. I'm looking for a builtin Python library capable of providing > similar output to what the unix df command provides. Obviously, I'm trying > to avoid a system call if possible. I'm looking for the following fields > at a mimimum, to

Re: [Tutor] parse emails as they come in

2008-03-28 Thread Chris Fuller
The email and mailbox modules might help you out. Multiple email messages will probably parse as an mbox format mailbox. http://docs.python.org/lib/module-email.html http://docs.python.org/lib/module-mailbox.html Cheers On Friday 28 March 2008 03:14, linuxian iandsd wrote: > good morning ever

Re: [Tutor] Setting the PC Clock to Correct Time

2008-04-19 Thread Chris Fuller
On Saturday 19 April 2008 10:45, Wayne Watson wrote: > I have a Python program that runs 24/7, but is activated around dusk and > de-activated from its task around dawn. My clock drifts about 4 sec/day. > Is there some function that will fetch the correct time from the > internet and reset the cloc

Re: [Tutor] Setting the PC Clock to Correct Time

2008-04-19 Thread Chris Fuller
I just checked my laptop (XP Pro), and you can set the time server (or use the default), but it only updates once a week. So your computer's time could be off by thirty seconds by the time of the next synchronization. It might be enough, but you also need to be aware so you aren't confused int

Re: [Tutor] Debug C library in python program

2008-04-28 Thread Chris Fuller
I expect if you take that route, you would have to compile the Python interpreter with debugging enabled, and then run that with gdb. A better idea might be to recompile your library to produce debugging output at strategic locations, and then output it to the console or a socket to some logg

Re: [Tutor] why?

2008-05-29 Thread Chris Fuller
On Wednesday 28 May 2008 20:32, bob gailer wrote: > Robert William Hanks wrote: > > Need ti find out whem a number o this form i**3+j**3+1 is acube. > > tryed a simple brute force code but, why this not work? > > > > def iscube(n): > > cubed_root = n**(1/3.0) > > if round(cubed_root)**3 =

Re: [Tutor] Controlling applications

2008-06-10 Thread Chris Fuller
On Monday 09 June 2008 14:13, Alan Gauld wrote: > You need to find an API that lets you work at the X windows > protocol level. I don;t know of one but will be surprised if > there isn't such a beast around somewhere! This made me think of Tcl's send() function. This web page has some links that

Re: [Tutor] Writing a script to interact with an interactive commandprogram

2008-06-10 Thread Chris Fuller
On the subject of controlling interactive programs and Tcl, one can hardly forget expect.. now add Python and you probably have what you want: http://www.noah.org/wiki/Pexpect Cheers ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailm

Re: [Tutor] references to containing objects

2008-06-23 Thread Chris Fuller
You can also subclass the dictionary type so that this happens transparently. You could do something similar with lists. class Container(dict): def __setitem__(self, key, value): dict.__setitem__(self, key, value) if hasattr(value, 'setParent'): if callable(value.setPare

Re: [Tutor] String concatenation too slow

2008-06-30 Thread Chris Fuller
You could try creating a list of strings, and then using a ''.join(list) to concatenate, but you are probably going to be best off using the cStringIO module (http://docs.python.org/lib/module-cStringIO.html). Try timing all three and see how they compare when joining lots of strings. The leng

Re: [Tutor] Dynamic Method Creation

2008-07-10 Thread Chris Fuller
On Thursday 10 July 2008 09:09, George Flaherty wrote: > Hello, > > I am trying to port over some old code from Ruby into Python. In my old > ruby code I had a UnitTest class that created a bunch of test methods (i.e. > def test_MyTestFunction) dynamically through the ruby method > define_method(h

Re: [Tutor] where to report a bug?

2008-07-25 Thread Chris Fuller
On Friday 25 July 2008 09:04, Rick Pasotto wrote: > I have a script that works fine on my linux machine but bombs out when > run under windows using the exact same data files. The script downloads > a file then unzips it and then scans the resulting file for certain > records. Under Windows it gets

Re: [Tutor] Memory error - how to manage large data sets?

2008-07-28 Thread Chris Fuller
On Monday 28 July 2008 10:56, Karthik wrote: > Hi, > > > > I am new to Python programming, I was trying to work out a few problems in > order to grasp the knowledge gained after going through the basic chapters > on Python programming. I got stuck with a memory error. > > > > Following is what I di

Re: [Tutor] Memory error - how to manage large data sets?

2008-07-28 Thread Chris Fuller
There's no need to keep any lists. The sum can be done on the fly, which is perhaps a bit slower, but takes a constant amount of ram. Even storing every other element (or every third, which is what he's trying to do: the elements that are even numbers, not every other element.. See his exampl

Re: [Tutor] Memory error - how to manage large data sets?

2008-07-29 Thread Chris Fuller
The original post was a little ambiguous: "I need to find the sum of all numbers at even positions in the Fibonacci series upto 2 million." But the project euler page (http://projecteuler.net/index.php?section=problems&id=2) is clear: "Find the sum of all the even-valued terms in the sequence

  1   2   >