Re: OT: Binary tree logarithms properties

2008-12-18 Thread Mr . SpOOn
2008/12/17 Terry Reedy tjre...@udel.edu: Nodes only have single number indexes if you arrange them linearly. Then the index depends on how you arrange them, whether you start the array indexes with 0 or 1, and whether you start the level numbers with 0 or 1. Call the breadth-first sequence

OT: Binary tree logarithms properties

2008-12-17 Thread Mr . SpOOn
Hi, I'm searching for a clear explanation of binary tree properties, expecially the ones related to logarithms. For example, I know that in a tree with 2n-1 nodes, we have log(n) levels, from 0 to log(n). So, if k is the level, the nodes on a level have indexes between 2^k and 2^(k+1)-1. For k=0

Re: Free place to host python files?

2008-12-16 Thread Mr . SpOOn
2008/12/16 feba feb...@gmail.com: Stuff like code.google, sf.net, are more oriented towards serious development, not just holding random apps, aren't they? Anyway, I found MediaFire, which looks like it will suffice for now. Take a look to Dropbox (http://www.getdropbox.com/). You can use it

Re: matching exactly a 4 digit number in python

2008-11-21 Thread Mr . SpOOn
2008/11/21 harijay [EMAIL PROTECTED]: Hi I am a few months new into python. I have used regexps before in perl and java but am a little confused with this problem. I want to parse a number of strings and extract only those that contain a 4 digit number anywhere inside a string However the

strange permission issue with nosetests

2008-11-20 Thread Mr . SpOOn
Hi, I'm trying the nose testing package. I've just started reading the tutorial and I had a problem with the first simple example. This is the test: def test_b(): assert 'b' == 'b' In the same directory I gave the command nosetests and it runs the test. Then I try with nosetests -v, but it

Re: strange permission issue with nosetests

2008-11-20 Thread Mr . SpOOn
On Thu, Nov 20, 2008 at 13:34, Ben Finney [EMAIL PROTECTED] wrote: Mr.SpOOn [EMAIL PROTECTED] writes: Searching on google I found this: http://www.siafoo.net/article/61 He had the same issue and said to change permission of the file to 664. Unit test modules, which are primarily meant to be

Re: Programming exercises/challenges

2008-11-19 Thread Mr . SpOOn
On Wed, Nov 19, 2008 at 1:50 PM, Jeremiah Dodds [EMAIL PROTECTED] wrote: If you need to do it on the extremely cheap, you can host on your own machine on a port other than 80, make sure your router / firewall is forwarding the port to your machine, and use dyndns (http://dyndns.com) to give

Re: Programming exercises/challenges

2008-11-19 Thread Mr . SpOOn
On Wed, Nov 19, 2008 at 1:35 PM, Jeremiah Dodds [EMAIL PROTECTED] wrote: Personally, I prefer a host that gives me root on a box (or virtual machine). I've had a great time with slicehost (http://slicehost.com). Yes, I knew about slicehost, but it is expensive for what I need to do, that is

Re: Programming exercises/challenges

2008-11-19 Thread Mr . SpOOn
On Wed, Nov 19, 2008 at 2:39 AM, Mensanator [EMAIL PROTECTED] wrote: Another hobby I have is tracking movie box-office receipts (where you can make interesting graphs comparing Titanic to Harry Potter or how well the various sequels do, if Pierce Brosnan saved the James Bond franchise, what

Re: Programming exercises/challenges

2008-11-19 Thread Mr . SpOOn
On Wed, Nov 19, 2008 at 3:41 PM, Philip Semanchuk [EMAIL PROTECTED] wrote: I'm not sure why you'd need to host the Python code anywhere other than your home computer. If you wanted to pull thousands of pages from a site like that, you'd need to respect their robots.txt file. Don't forget to

Re: Building musical chords starting from (a lot of) rules

2008-11-19 Thread Mr . SpOOn
I think I've found a nice way to represent and build chords. At least, at the moment it satisfy me, maybe later I'll understand how it sucks. I'm using two separate classes: one represent a chord and is implemented as a set of Notes; the other represents the structure (type) of the chord and is a

Re: Customizing sequence types

2008-11-18 Thread Mr . SpOOn
On Tue, Nov 18, 2008 at 1:59 AM, Gabriel Genellina [EMAIL PROTECTED] wrote: Yes, __cmp__ is gone in 3.0 You said you wrote __cmp__ the same as __eq__ and that's wrong, they return different results. Try something like this (untested): class X: def __init__(self, a): self.a = a def

Re: Customizing sequence types

2008-11-17 Thread Mr . SpOOn
It seems that I solved my main problem, but I still have some doubt. I'll make an example: class foo: ...def __init__(self, a): ...self.a = a ... f = foo(1) f2 = foo(2) f3 = foo(3) f1 = foo(1) s = set() s.add(f) s set([__main__.foo instance at 0x8311fac]) s.add(f2)

Re: Customizing sequence types

2008-11-17 Thread Mr . SpOOn
On Mon, Nov 17, 2008 at 8:30 PM, Terry Reedy [EMAIL PROTECTED] wrote: Sets and dicts use __hash__ and __eq__ together, as documented. If a class does not define an __eq__() method it should not define a __hash__() operation either; (3.0 manual, but same earlier). Well, maybe, but in the docs,

Re: Building musical chords starting from (a lot of) rules

2008-11-16 Thread Mr . SpOOn
On Sun, Nov 16, 2008 at 7:21 AM, Lawrence D'Oliveiro [EMAIL PROTECTED] wrote: In message [EMAIL PROTECTED], Mr.SpOOn wrote: C 9 is a base chord plus a the ninth note, but this implies the presence of the seventh too, so it results in: C E G B D I don't recall such meanings in the chord

Customizing sequence types

2008-11-16 Thread Mr . SpOOn
Hi, I'm trying to create a class which inherit a list to change some behavior. This list should contain other instance objects and has to manage these instances in a particular way. 1) I need to sort this elements in this list, but they must be sorted using an instance variable. What does Python

Re: Customizing sequence types

2008-11-16 Thread Mr . SpOOn
On Sun, Nov 16, 2008 at 7:15 PM, Arnaud Delobelle [EMAIL PROTECTED] wrote: Mr.SpOOn [EMAIL PROTECTED] writes: Hi, I'm trying to create a class which inherit a list to change some behavior. This list should contain other instance objects and has to manage these instances in a particular way.

Regular expression and exception

2008-11-15 Thread Mr . SpOOn
Hi, I've never used exception before, but I think now it's time to start. I've seen that there is a list of the built-in exceptions in the Python docs, but this explains the meaning of every exception. Does exist an inverted list? I mean, how may I know what kind of exception is going to raise

Building musical chords starting from (a lot of) rules

2008-11-14 Thread Mr . SpOOn
Hi, I'm writing a method to create musical chords. This method must follow a specific set of syntax rules. At least, this is my idea, but maybe there's a better way. Anyway, in the code I have class Chord which is a set. The costrunction of a chord is based on a root note and a structure, so by

Re: wildcard match with list.index()

2008-11-11 Thread Mr . SpOOn
Thanks, I just have to choose which one to use :) -- http://mail.python.org/mailman/listinfo/python-list

wildcard match with list.index()

2008-11-10 Thread Mr . SpOOn
Hi, is there any way to search elements in a list using wildcards? I have a list of various elements and I need to search for elements starting with 'no', extract them and put in a new list. I was thinking about something like: mylist.index('no*') Of course this doesn't work. --

Re: is there really no good gui builder

2008-11-09 Thread Mr . SpOOn
On Sun, Nov 9, 2008 at 12:29 AM, Stef Mientki [EMAIL PROTECTED] wrote: Qt seems to be good, but I don't like their licence. What's the problem with qt licence? -- http://mail.python.org/mailman/listinfo/python-list

Re: More __init__ methods

2008-11-07 Thread Mr . SpOOn
On Thu, Nov 6, 2008 at 11:00 PM, Ben Finney [EMAIL PROTECTED] wrote: Yes, the main reason is that it kills duck typing. The initialiser should *use* the parameters passed, and allow exceptions to propagate back to the caller if the parameters don't behave as expected. Another good reason to

Re: More __init__ methods

2008-11-07 Thread Mr . SpOOn
On Fri, Nov 7, 2008 at 4:16 PM, Duncan Booth [EMAIL PROTECTED] wrote: There is a really big advantage to being explicit in this situation: you no longer have to make sure that all your constructors use a unique set of types. Consider: class Location(object): def __init__(self, lat, long):

Re: More __init__ methods

2008-11-07 Thread Mr . SpOOn
On Thu, Nov 6, 2008 at 11:00 PM, Ben Finney [EMAIL PROTECTED] wrote: Yes, the main reason is that it kills duck typing. The initialiser should *use* the parameters passed, and allow exceptions to propagate back to the caller if the parameters don't behave as expected. Another good reason to

Re: More __init__ methods

2008-11-07 Thread Mr . SpOOn
On Fri, Nov 7, 2008 at 7:02 PM, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: What if I need the parse method to be called in other parts of the program? I don't understand!? Then you call it from those other parts. Yes, you're right. Don't know why, but I was thinking to use

Re: Ordering python sets

2008-11-06 Thread Mr . SpOOn
On Wed, Nov 5, 2008 at 10:03 PM, Arnaud Delobelle [EMAIL PROTECTED] wrote: Only hashable objects can go in a set. By default a class you define is not hashable (unless it descends from a hashable class). To remedy this you can define a __hash__ method in your class. IIRC the only

More __init__ methods

2008-11-06 Thread Mr . SpOOn
Hi, I know there can be only one __init__ method (at least, I think). Often I need an object to be created in different ways, for example passing a string as argument, or an integer, or another object. To achieve this I put the default value of the arguments to None and then I some if...elif

Re: More __init__ methods

2008-11-06 Thread Mr . SpOOn
On Thu, Nov 6, 2008 at 4:59 PM, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: class A(object): def __init__(self, a, b, c): self.a = a # ... @classmethod def from_string(cls, s): # ... return cls(a, b, c) Thanks. I think it's time to study

Re: More __init__ methods

2008-11-06 Thread Mr . SpOOn
On Thu, Nov 6, 2008 at 7:44 PM, Tim Golden [EMAIL PROTECTED] wrote: While that's no bad thing, you don't really need to do that simply to understand these examples: they're just saying do whatever you need to to make these method class methods, not instance methods. Yes. I think this changes

Inheritance problem

2008-11-05 Thread Mr . SpOOn
Hi, I have a problem with this piece of code: class NoteSet(OrderedSet): def has_pitch(self): pass def has_note(self): pass class Scale(NoteSet): def __init__(self, root, type): self.append(root) self.type = type ScaleType(scale=self)

Re: Inheritance problem

2008-11-05 Thread Mr . SpOOn
On Wed, Nov 5, 2008 at 6:59 PM, Diez B. Roggisch [EMAIL PROTECTED] wrote: You need to call the __init__ of NoteSet inside Scale, as otherwise the instance isn't properly initialized. Thanks, solved. -- http://mail.python.org/mailman/listinfo/python-list

Re: Ordering python sets

2008-11-05 Thread Mr . SpOOn
The discussion's gone a bit off topic so I don't know if it is a good idea to continue here. I'll try. My first question was about a way to order a python set. Someone suggested to try this module: http://code.activestate.com/recipes/528878/ It seemed pretty good, but I've tried it just today

Re: locating the chorus in a MIDI song?

2008-11-04 Thread Mr . SpOOn
On Tue, Nov 4, 2008 at 5:20 AM, Joe Strout [EMAIL PROTECTED] wrote: We've got a need to generate short samples of songs that are in MIDI format, to provide a preview function in a web app. We'd like to do something more clever than just taking the middle 20 seconds (or whatever) of the song

Re: Exact match with regular expression

2008-11-03 Thread Mr . SpOOn
On Sat, Nov 1, 2008 at 1:57 AM, Lawrence D'Oliveiro [EMAIL PROTECTED] wrote: In message [EMAIL PROTECTED], Rob Williscroft wrote: Read (and bookmark) this: http://www.python.org/doc/2.5.2/lib/re-syntax.html Funny how you never get a thank-you when you tell people to RTFM. My fault :\ I

Exact match with regular expression

2008-10-26 Thread Mr . SpOOn
Hi, I'd like to use regular expressions to parse a string and accept only valid strings. What I mean is the possibility to check if the whole string matches the regex. So if I have: p = re.compile('a*b*') I can match this: 'aabbb' m = p.match('aabbb') m.group() 'aabbb' But I'd

Re: Web crawler on python

2008-10-26 Thread Mr . SpOOn
On Sun, Oct 26, 2008 at 9:54 PM, sonich [EMAIL PROTECTED] wrote: I need simple web crawler, I found Ruya, but it's seems not currently maintained. Does anybody know good web crawler on python or with python interface? What about BeautifulSoup? http://www.crummy.com/software/BeautifulSoup/ --

Global dictionary or class variables

2008-10-24 Thread Mr . SpOOn
Hi, in an application I have to use some variables with fixed valuse. For example, I'm working with musical notes, so I have a global dictionary like this: natural_notes = {'C': 0, 'D': 2, 'E': 4 } This actually works fine. I was just thinking if it wasn't better to use class variables.

Ordering python sets

2008-10-22 Thread Mr . SpOOn
Hi, I need a structure to represent a set of integers. I also need to perform on this set some basic set operations, such as adding or removing elements, joining with other sets and checking for the presence of specific elements. I think that using Python sets would be the best choice, but I also

Re: Ordering python sets

2008-10-22 Thread Mr . SpOOn
On Wed, Oct 22, 2008 at 3:37 PM, Peter Otten [EMAIL PROTECTED] wrote: Tim Chase wrote: Though for each test, in 2.3, 2.4, and 2.5 that I've got installed on my local machine, they each printed s in-order, and the iteration occurred in-order as well, even without the added sorted(list(s))

Re: Ordering python sets

2008-10-22 Thread Mr . SpOOn
On Wed, Oct 22, 2008 at 4:30 PM, Roy Smith [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], Mr.SpOOn [EMAIL PROTECTED] wrote: It seems to me that it orders elements when you add using the add() method, but if you create a set starting from a list, it may result unordered.

Re: Overloading operators

2008-10-16 Thread Mr . SpOOn
Thanks for the suggestion. I think I'm gonna try the multimethods way, that I didn't know about it. -- http://mail.python.org/mailman/listinfo/python-list

Re: Overloading operators

2008-10-16 Thread Mr . SpOOn
On Thu, Oct 16, 2008 at 10:54 PM, Lie Ryan [EMAIL PROTECTED] wrote: On Wed, 15 Oct 2008 14:34:14 +0200, Mr.SpOOn wrote: Something that is more pythonic is something that doesn't use multimethods. It's just an elaborated way to do type checking. In python, you usually avoid type checking and

Overloading operators

2008-10-15 Thread Mr . SpOOn
Hi, in a project I'm overloading a lot of comparison and arithmetic operators to make them working with more complex classes that I defined. Sometimes I need a different behavior of the operator depending on the argument. For example, if I compare a object with an int, I get a result, but if I

Weirdness comparing strings

2008-09-30 Thread Mr . SpOOn
Hi, I have this piece of code: class Note(): ... ... def has_the_same_name(self, note): return self == note def __str__(self): return self.note_name + accidentals[self.accidentals] __repr__ = __str__ if __name__ == '__main__': n = Note('B')

Re: Weirdness comparing strings

2008-09-30 Thread Mr . SpOOn
On Tue, Sep 30, 2008 at 12:55 PM, Ken Seehart [EMAIL PROTECTED] wrote: Instance comparison is not necessarily the same as string comparison. Neither __str__ nor __repr__ are implicitly used at all for comparison. Ok, I see. In fact, by default a pair of instances are not equal unless they