Re: [Tutor] Splitting long string into same len parts

2006-02-08 Thread Victor Bouffier
Hi Emile and John, Thanks a lot for your insight. There is always a better way, or at least a more pythonic one. Take care. Victor. On Wed, 2006-02-08 at 22:36 -0800, Emile van Sebille wrote: > "Andre Roberge" <[EMAIL PROTECTED]> wrote in message > > > There's a tongue-in-cheek quote that I rea

Re: [Tutor] Splitting long string into same len parts

2006-02-08 Thread Emile van Sebille
"Andre Roberge" <[EMAIL PROTECTED]> wrote in message > There's a tongue-in-cheek quote that I really like: > "Sometimes you have a programming problem and it seems like the best > solution is to use regular expressions; now you have two problems." +1 -- There are some things re is good for, but

Re: [Tutor] Time to Use a Global Variable?

2006-02-08 Thread Rich Shepard
On Wed, 8 Feb 2006, Kent Johnson wrote: > OK. Suppose I have Sigh. I was going too fast and, of course, I got ahead of myself. > To use this class, I have to instantiate it: > myDb = DB() Yes, that's all in the example's __main__ and I didn't put it in my application. Will do so right a

Re: [Tutor] Splitting long string into same len parts

2006-02-08 Thread Andre Roberge
On 2/8/06, Danny Yoo <[EMAIL PROTECTED]> wrote: > > > On Wed, 8 Feb 2006, Victor Bouffier wrote: > > > Hi to all, > > > > I'd like to split a long string into equally long strings (len(str) = > > 3). I did the following using regexes: > > > > >>> n = 'xb1jyzqnd1eenkokqnhep6vp692qi9tmag3owzqw0sdq3zj

Re: [Tutor] Splitting long string into same len parts

2006-02-08 Thread Danny Yoo
On Wed, 8 Feb 2006, Victor Bouffier wrote: > Hi to all, > > I'd like to split a long string into equally long strings (len(str) = > 3). I did the following using regexes: > > >>> n = 'xb1jyzqnd1eenkokqnhep6vp692qi9tmag3owzqw0sdq3zjf' > >>> o = re.split(r'(...)', n) > >>> print o > ['', 'xb1', ''

Re: [Tutor] Time to Use a Global Variable?

2006-02-08 Thread Kent Johnson
Rich Shepard wrote: > On Wed, 8 Feb 2006, Kent Johnson wrote: > >> Evidently closeDb is an instance method of some class you don't show >> here. >> Does DBinterface create and maintain a single instance of this class? or >> some other code creates an instance? > > > Kent, > > closeDB() is de

Re: [Tutor] quirky multiple inheritance example!?

2006-02-08 Thread Kent Johnson
Alan Gauld wrote: > The problem is that super appears to only work with single inheritance. > There may be a way to makle it work for multiple inheritance by changing > the second parameter but the documentration is a bit thin!! That's ironic - super() is intended to ease some of the problems wit

Re: [Tutor] Splitting long string into same len parts

2006-02-08 Thread John Fouhy
On 09/02/06, Victor Bouffier <[EMAIL PROTECTED]> wrote: > I'd like to split a long string into equally long strings (len(str) = > 3). I did the following using regexes: Remember that a string is just like a list (except that you can't modify it). So, for instance: >>> n = 'xb1jyzqnd1eenkokqnhep6

[Tutor] Splitting long string into same len parts

2006-02-08 Thread Victor Bouffier
Hi to all, I'd like to split a long string into equally long strings (len(str) = 3). I did the following using regexes: >>> n = 'xb1jyzqnd1eenkokqnhep6vp692qi9tmag3owzqw0sdq3zjf' >>> o = re.split(r'(...)', n) >>> print o ['', 'xb1', '', 'jyz', '', 'qnd', '', '1ee', '', 'nko', '', 'kqn', '', 'hep'

Re: [Tutor] python help

2006-02-08 Thread Danny Yoo
> I realise teachers have to test mastery of certain techniques, but they > seem to lack the imagination. I agree; the problem here, I think, is that these homework questions often focus WAY too much on Python-specific features, rather than on fundamental issues, and so the questions end up feel

Re: [Tutor] Finding bottom level directories, and command-line arguments

2006-02-08 Thread Simon Gerber
Hi Danny, > That web site (http://thedailywtf.com) is amusing in its way, but my > problem with it is that so many of the people there enjoy mocking others > in a mean-spirited and immature way. Programming well is a hard thing. > The adolescent posturing I see there isn't admirable to me. It's a

Re: [Tutor] python help

2006-02-08 Thread Ben Vinger
Why are these homework programming challenges so recognisable? It boils down to: Write a function that that uses X and Y techniques. The function may be hard and challenging to write but doesn't ever do anything interesting or anything that is useful and complete on its own. I realise teachers ha

Re: [Tutor] Time to Use a Global Variable?

2006-02-08 Thread Rich Shepard
On Wed, 8 Feb 2006, Kent Johnson wrote: > Evidently closeDb is an instance method of some class you don't show here. > Does DBinterface create and maintain a single instance of this class? or > some other code creates an instance? Kent, closeDB() is defined in the class DBinterface. That's th

Re: [Tutor] quirky multiple inheritance example!?

2006-02-08 Thread Alan Gauld
# This *FAILS* with AttributeError: 'FancyPublisher' # object has no attribute 'listeners' class FancyPublisher(threading.Thread, Publisher): def __init__(self): super(FancyPublisher, self).__init__() F = FancyPublisher() F.register('me', None) --- The problem is that su

Re: [Tutor] Time to Use a Global Variable?

2006-02-08 Thread Kent Johnson
Rich Shepard wrote: >In my wxPython application the UI is run out of class MyFrame. The method > associated with File->Quit is called OnFileQuit. All the code for pysqlite is > in another class called DBinterface, and that has a method closeDB(): > >def closeDb(self): > """ > Clo

Re: [Tutor] quirky multiple inheritance example!?

2006-02-08 Thread Kent Johnson
Marcus Goldfish wrote: > Hi, > > I ran across a strange problem using mulitple inheritance that I hope > someone can explain. Basically, I am implementing a Publisher pattern, > and when I try to add threading, the order I list Base classes matters! > Here is the short sample code-- all help

Re: [Tutor] soundfile picker & rating system

2006-02-08 Thread John Fouhy
On 09/02/06, kevin parks <[EMAIL PROTECTED]> wrote: > And i am not sure i want to have to go through what will be hundreds of > sound files and scale their ratings by hand so that they all add up to > 100%. I just want to have a long list that i can add too whenever i > want, and assign it a grade/

[Tutor] soundfile picker & rating system

2006-02-08 Thread kevin parks
I am a little bit stuck I want to play a bunch of soundfiles randomly, but i want to give each soundfile a rating (say 0-100) and have the likelihood that the file be chosen be tied to its rating so that the higher the rating the more likely a file is to be chosen. Then i need some addit

Re: [Tutor] Syntax Question

2006-02-08 Thread Alan Gauld
> There must be something that I'm missing here. Triuple quoted strings :-) Take a look at my Databases topic for examples using SqlLite and triple quotes for the queries. Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld . __

Re: [Tutor] Changing instance attributes in different threads

2006-02-08 Thread Kent Johnson
Michael Lange wrote: > Sorry, I missed to insert the time.sleep(0.1) I used in my original while > loop into the example above. > The reason for using time.sleep() is that I need to avoid lots of loops over > an empty buffer. > The amount of time until the producer thread reads a new data fragmen

Re: [Tutor] Finding bottom level directories, and command-line arguments

2006-02-08 Thread Danny Yoo
> I've got this: > > --- > def isBottomDir(path): > for item in os.listdir(path): > if os.path.isdir(os.path.join(path,item)): > return False > return True > --- > > Is that an acceptable way of doing this? Hi Simon, Your code looks good to me! > I've been

[Tutor] Time to Use a Global Variable?

2006-02-08 Thread Rich Shepard
In my wxPython application the UI is run out of class MyFrame. The method associated with File->Quit is called OnFileQuit. All the code for pysqlite is in another class called DBinterface, and that has a method closeDB(): def closeDb(self): """ Closes the database connection explic

Re: [Tutor] python help

2006-02-08 Thread Alan Gauld
> I have a few doubts in python programming. C if any of u can help me out. Have no doubts - Python can do all of this. > In a file called string_stuff.py i have to write a function called > frequencies > that takes a string as a parameter and returns a dictionary where the keys > are the char

[Tutor] quirky multiple inheritance example!?

2006-02-08 Thread Marcus Goldfish
Hi,   I ran across a strange problem using mulitple inheritance that I hope someone can explain.  Basically, I am implementing a Publisher pattern, and when I try to add threading, the order I list Base classes matters!  Here is the short sample code-- all help explaining this is appreciated!   Th

Re: [Tutor] Syntax Question

2006-02-08 Thread John Fouhy
On 09/02/06, Rich Shepard <[EMAIL PROTECTED]> wrote: > self.cur.execute("CREATE TRIGGER fki_comp_cat BEFORE INSERT ON component > FOR EACH ROW BEGIN SELECT RAISE(ROLLBACK, 'insert on table "category" > violates foreign key constraint "fk_comp_cat"') WHERE NEW.comp_cat IS NOT > NULL AND (SELECT

Re: [Tutor] Changing instance attributes in different threads

2006-02-08 Thread Michael Lange
On Wed, 08 Feb 2006 13:47:39 -0500 Kent Johnson <[EMAIL PROTECTED]> wrote: > > while self.recording: > > data = [] > > while not self.rec_queue.empty(): > > try: > >data.append(self.rec_queue.get(block=0)) > > except Queue.Empty: > >

Re: [Tutor] Syntax Question

2006-02-08 Thread Rich Shepard
On Wed, 8 Feb 2006, Danny Yoo wrote: > Odd. Can you show us that complaint? Show us the error string. There are > several possibilities here, but I hate guessing. *grin* Show us the exact > error message you're getting, and that'll hint at what's really going on. > > Normal string literals can'

Re: [Tutor] Syntax Question

2006-02-08 Thread Danny Yoo
On Wed, 8 Feb 2006, Rich Shepard wrote: >I'm trying to understand how to write SQL statements using pysqlite. > The problem is that if I use newlines to format the SQL statements as I > would with straight SQLite or PostgreSQL, python complains because it > sees the newline before the end of

Re: [Tutor] python help

2006-02-08 Thread Danny Yoo
> These sound like homework questions, in which case it would not be right > for us to just give you the answer (and it would not be right for you to > ask for it). Agreed; these are not small questions at all. Natasha, if you're having trouble, please be more specific about what you're getting

[Tutor] Syntax Question

2006-02-08 Thread Rich Shepard
I'm trying to understand how to write SQL statements using pysqlite. The problem is that if I use newlines to format the SQL statements as I would with straight SQLite or PostgreSQL, python complains because it sees the newline before the end of the quoted string. So, I make the CREATE TABLE

Re: [Tutor] distutils and record-rpm not recognized

2006-02-08 Thread Danny Yoo
On Wed, 8 Feb 2006, le dahut wrote: > I've Python 2.4.1 installed and 'setup.py' doesn't recognize the > '--record-rpm' option : > "error: option --record-rpm not recognized" > > The patch including this feature is available since a long time so > what's happening ? Hi Le Dahut, You may be bet

Re: [Tutor] [Python-Dev] small floating point number problem

2006-02-08 Thread Tim Peters
[Raymond Hettinger] > ... > The asymmetric handling of denormals by the atof() and ftoa() functions is > why you see a difference. A consequence of that asymmetry is the breakdown > of the expected eval(repr(f))==f invariant: Just noting that such behavior is a violation of the 754 standard for s

Re: [Tutor] Changing instance attributes in different threads

2006-02-08 Thread Kent Johnson
Michael Lange wrote: > On Wed, 08 Feb 2006 08:37:18 -0500 > Kent Johnson <[EMAIL PROTECTED]> wrote: >>child thread 2: >> >> while self.recording: >> data = self.rec_queue.get() >> for d in data: >> self._waveobj.writeframesraw(d)# write data to file >

Re: [Tutor] Changing instance attributes in different threads

2006-02-08 Thread Michael Lange
On Wed, 08 Feb 2006 08:37:18 -0500 Kent Johnson <[EMAIL PROTECTED]> wrote: > Another architecture you might consider is to have thread 1 put the > actual acquired buffers into two Queues that are read by the two > consumer threads. This would save you a lot of copying and give you a > cleaner i

Re: [Tutor] python help

2006-02-08 Thread Matthew Webber
These sound like homework questions, in which case it would not be right for us to just give you the answer (and it would not be right for you to ask for it). If you can show us what you have tried so far, maybe we can give you some hints ... From: [EMAIL

[Tutor] python help

2006-02-08 Thread Natasha Menon
Hi,   I have a few doubts in python programming. C if any of u can help me out.   1. In a file called string_stuff.py i have to write a function called frequencies that takes a string as a parameter and returns a dictionary where the keys are the characters from the string and each value is

Re: [Tutor] Changing instance attributes in different threads

2006-02-08 Thread Kent Johnson
Michael Lange wrote: > On Tue, 7 Feb 2006 23:31:06 +0100 > Michael Lange <[EMAIL PROTECTED]> wrote: > > >>So I think I need two Condition objects here; it is most important here that >>thread 1 does not >>block to minimize the risk of recording buffer overruns, but from reading the >>docs I am

Re: [Tutor] Finding bottom level directories, and command-line arguments

2006-02-08 Thread Kent Johnson
Simon Gerber wrote: > I've got this: > > --- > def isBottomDir(path): > for item in os.listdir(path): > if os.path.isdir(os.path.join(path,item)): > return False > return True > --- > > Is that an acceptable way of doing this? I've been reading > http://thedail

[Tutor] distutils and record-rpm not recognized

2006-02-08 Thread le dahut
I've Python 2.4.1 installed and 'setup.py' doesn't recognize the '--record-rpm' option : "error: option --record-rpm not recognized" The patch including this feature is available since a long time so what's happening ? K. ___ Tutor maillist - Tutor

Re: [Tutor] Changing instance attributes in different threads

2006-02-08 Thread Michael Lange
On Tue, 7 Feb 2006 23:31:06 +0100 Michael Lange <[EMAIL PROTECTED]> wrote: > > So I think I need two Condition objects here; it is most important here that > thread 1 does not > block to minimize the risk of recording buffer overruns, but from reading the > docs I am > not sure about the correc

Re: [Tutor] I would like to learn python ASAP

2006-02-08 Thread Kent Johnson
guy wrote: > I would like to understand how one can right unit test cases using python > and how to utilize them on a giving application. There are several Python packages that help to automate Windows GUI applications. These could be used to write tests. winguiauto has the basics http://www.br

Re: [Tutor] [Python-Dev] small floating point number problem

2006-02-08 Thread Raymond Hettinger
[Smith] >I just ran into a curious behavior with small floating points, trying to >find the limits of them on my machine (XP). Does anyone know why the '0.0' >is showing up for one case below but not for the other? According to my >tests, the smallest representable float on my machine is much sm

[Tutor] Gaussian integer values

2006-02-08 Thread kevin parks
hi all. I am working with a list and would like to choose from the list randomly but not uniformly. I am interested in several distributions but the first one i looked at is Gaussian. which you call like so: random.gauss(mean, dev) You can try this code courtesy of effbot (http://effbot.org