Re: [Tutor] clearing a text document

2007-08-30 Thread Kent Johnson
max baseman wrote: > right it's for a quick math "game" the rules are simple you start > with any number to get the next number you, a. if it's odd multiply > by 3 than add 1 or b. if it's even divide by two, the point of this > is to see how long it takes to get to one are it starts to repe

Re: [Tutor] clearing a text document

2007-08-30 Thread max baseman
cool thank you :) On Aug 29, 2007, at 11:02 PM, Luke Paireepinart wrote: > max baseman wrote: >> right it's for a quick math "game" the rules are simple you start >> with any number to get the next number you, a. if it's odd >> multiply by 3 than add 1 or b. if it's even divide by two, th

Re: [Tutor] clearing a text document

2007-08-30 Thread max baseman
thats what it does but in order to just be able to let it sit and work for as long as it can i made it a endless loop of just trying every number, for now it just displays the highest on the screen but it would be nice to get it in a text document thanks On Aug 30, 2007, at 4:53 AM, Kent Jo

[Tutor] Triangle structure for triangulation

2007-08-30 Thread János Juhász
Dear All, I have written a Delaunay triangulation 10 years ago in C based on triangle structure. It was 400 lines, so it seems to be a fine task to turn into python. My problem is the translation of the C structure and the OO thinking. I tried to draft it so. /* The triangle, its neighbours,

Re: [Tutor] Triangle structure for triangulation

2007-08-30 Thread Alan Gauld
"János Juhász" <[EMAIL PROTECTED]> wrote > ## I can translate it into python in this way > class Triangle: >def __init__(self, points, neighbours): >self.points = points >self.neighbours = neighbours > > def TOR(self, direction): >return (self, (direction+1)%3) >

Re: [Tutor] A replacement for a "for" loop

2007-08-30 Thread Scott Oertel
Terry Carroll wrote: > On Wed, 29 Aug 2007, Scott Oertel wrote: > > >> Why even have the keys variable at all.. >> >> for key in attrs: >> print 'Attribute %s has value %s' % (key, attrs[key]) >> > > In a prior email thread, the OP indicated that he needed to process the > keys in that

[Tutor] Formatting output into columns

2007-08-30 Thread Scott Oertel
Someone asked me this question the other day, and I couldn't think of any easy way of printing the output besides what I came up with pasted below. So what you have is a file with words in it as such: apple john bean joke ample python nice and you want to sort and output the text into columns as

[Tutor] Triangle structure for triangulation

2007-08-30 Thread János Juhász
Dear Allan, thanks for your coments. > > ## I can translate it into python in this way > > class Triangle: > >def __init__(self, points, neighbours): > >self.points = points > >self.neighbours = neighbours > > > > def TOR(self, direction): > >return (self, (direct

Re: [Tutor] Formatting output into columns

2007-08-30 Thread Alan Gauld
"Scott Oertel" <[EMAIL PROTECTED]> wrote > and you want to sort and output the text into columns as such: > > a p j b n > apple python john bean nice > ample joke > > and this is what works, but I would

Re: [Tutor] Formatting output into columns

2007-08-30 Thread Scott Oertel
Alan Gauld wrote: > "Scott Oertel" <[EMAIL PROTECTED]> wrote > > >> and you want to sort and output the text into columns as such: >> >> a p j b n >> apple python john bean nice >> ample joke >> >> and

Re: [Tutor] Formatting output into columns

2007-08-30 Thread Kent Johnson
Scott Oertel wrote: > #!/usr/bin/env python > > data = {} > lrgColumn = 0 > > for line in open("test.txt","r").read().splitlines(): > char = line[0].lower() > if not char in data: > data[char] = [line] > else: > data[char].append(line) I like data.setdefault(char,

Re: [Tutor] Triangle structure for triangulation

2007-08-30 Thread Alan Gauld
"János Juhász" <[EMAIL PROTECTED]> wrote >> > ## I can translate it into python in this way >> > class Triangle: >> > def __init__(self, points, neighbours): >> > def TOR(self, direction): >> > def ROT(self, direction): >> > def RIGHT(self, direction): >> and store it as an attrib

Re: [Tutor] Formatting output into columns

2007-08-30 Thread Alan Gauld
"Scott Oertel" <[EMAIL PROTECTED]> wrote >> Use format strings. You can calculate the column widths by >> analyzing >> the data then create a format string for the required number of >> columns. >> Finally insert the data on each row from a tuple. >> > Do you have any good documentation that cou

[Tutor] Variable scope for class?

2007-08-30 Thread Orest Kozyar
I'm trying to follow the example listed in the wiki at http://www.sqlalchemy.org/trac/wiki/UsageRecipes/UniqueObject regarding the use of a metaclass. What I don't understand is how the metaclass (EntitySingleton) has access to the variable ctx which is instantinated outside the scope of the cla

Re: [Tutor] Formatting output into columns

2007-08-30 Thread Kent Johnson
Alan Gauld wrote: > "Scott Oertel" <[EMAIL PROTECTED]> wrote >> Do you have any good documentation that could shed some more light >> on >> exactly how to use format strings in such a way? > > The docs contain the basic documentation http://docs.python.org/lib/typesseq-strings.html > # there's

Re: [Tutor] Variable scope for class?

2007-08-30 Thread Kent Johnson
Orest Kozyar wrote: > I'm trying to follow the example listed in the wiki at > http://www.sqlalchemy.org/trac/wiki/UsageRecipes/UniqueObject regarding the > use of a metaclass. > > What I don't understand is how the metaclass (EntitySingleton) has access to > the variable ctx which is instantina

Re: [Tutor] Variable scope for class?

2007-08-30 Thread Dave Kuhlman
On Thu, Aug 30, 2007 at 06:02:12PM -0400, Orest Kozyar wrote: > I'm trying to follow the example listed in the wiki at > http://www.sqlalchemy.org/trac/wiki/UsageRecipes/UniqueObject regarding the > use of a metaclass. > > What I don't understand is how the metaclass (EntitySingleton) has access

Re: [Tutor] Variable scope for class?

2007-08-30 Thread Kent Johnson
Dave Kuhlman wrote: > So far so good. But, here is the one I do not understand. > > G1 = 111 > class A(object): > G1 = 222 > def show(self): > print G1 > > def test(): > a = A() > a.show() > > test() > > But, when I run this I see "11

Re: [Tutor] Variable scope for class?

2007-08-30 Thread Alan Gauld
"Dave Kuhlman" <[EMAIL PROTECTED]> wrote > Actually, the particular edition of Alan's book that I have is old > enough so that it does not discuss the Enclosing namespace, which > came later to Python. The enclosing namespace not make a > difference in your example, but does in mine. The paper

Re: [Tutor] Formatting output into columns

2007-08-30 Thread Luke Paireepinart
Scott Oertel wrote: > Someone asked me this question the other day, and I couldn't think of > any easy way of printing the output besides what I came up with pasted > below. > > So what you have is a file with words in it as such: > > apple > john > bean > joke > ample > python > nice > > and you w