Re: [Tutor] character encoding

2008-07-08 Thread wesley chun
> > Hi, I'm puzzled by the character encodings which I get when I use Python > > with IDLE. The string '\xf6' represents a letter in the Swedish alphabet > > when coded with utf8. On our computer with MacOSX this gets coded as > > '\xc3\xb6' which is a string of length 2. I have configured IDLE

[Tutor] (no subject)

2008-07-08 Thread Akanskha Kumar
how to make a game tree for a tic tac toe game ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] character encoding

2008-07-08 Thread Eric Abrahamsen
As for other resources, I recently came across this: http://farmdev.com/talks/unicode/ This was the first explanation that really made me understand the difference between Unicode and utf-8 (and realize that I'd been using the terms 'encode' and 'decode' backwards!). Anyway, just one more r

Re: [Tutor] line class

2008-07-08 Thread John Fouhy
On 09/07/2008, Paul McGuire <[EMAIL PROTECTED]> wrote: > > def length(self): > > dx,dy = self.p1 - self.p2 > > return (dx**2 + dy **2) ** 0.5 > > How about: > > def length(self): > return math.hypot( *(self.p1 - self.p2) ) > > Compiled C code will be much faster than squaring and

Re: [Tutor] line class

2008-07-08 Thread Paul McGuire
> def length(self): > dx,dy = self.p1 - self.p2 > return (dx**2 + dy **2) ** 0.5 How about: def length(self): return math.hypot( *(self.p1 - self.p2) ) Compiled C code will be much faster than squaring and square rooting. -- Paul ___ T

Re: [Tutor] line class

2008-07-08 Thread Kent Johnson
On Tue, Jul 8, 2008 at 6:29 PM, Christopher Spears <[EMAIL PROTECTED]> wrote: > I have been reading everyone's comments on my line class. I have decided to > implement some of the suggestions. Someone suggested that I create a > Point.__cmp__ method. Here is what I have so far: > > def __cmp__

Re: [Tutor] build list of non-empty variables

2008-07-08 Thread John Fouhy
On 09/07/2008, bob gailer <[EMAIL PROTECTED]> wrote: > or just [ x for x in LIST if x ] or filter(None, LIST). But that's a bit obscure. (fractionally faster, though, according to my brief experiment with timeit) -- John. ___ Tutor maillist - Tuto

Re: [Tutor] build list of non-empty variables

2008-07-08 Thread Kent Johnson
On Tue, Jul 8, 2008 at 6:35 PM, Don Jennings <[EMAIL PROTECTED]> wrote: > def __unicode__(self): > l=[self.first_name, self.last_name, self.email, self.phone] > res=[] > > for x in l: > if x != '': > res.append(x) > > return ';'.join(

Re: [Tutor] character encoding

2008-07-08 Thread Kent Johnson
On Tue, Jul 8, 2008 at 5:19 PM, Robert Johansson <[EMAIL PROTECTED]> wrote: > Hi, I'm puzzled by the character encodings which I get when I use Python > with IDLE. The string '\xf6' represents a letter in the Swedish alphabet > when coded with utf8. On our computer with MacOSX this gets coded as >

Re: [Tutor] build list of non-empty variables

2008-07-08 Thread Don Jennings
("Duh! Code would be good," says newbie to himself.) Here's an example from django which I am using, but I asked on this list since it seems more related to python than the web framework: class Contact(models.Model): first_name = models.CharField(max_length=30, blank=True) last_name = mod

[Tutor] character encoding

2008-07-08 Thread Robert Johansson
Hi, I'm puzzled by the character encodings which I get when I use Python with IDLE. The string '\xf6' represents a letter in the Swedish alphabet when coded with utf8. On our computer with MacOSX this gets coded as '\xc3\xb6' which is a string of length 2. I have configured IDLE to encode utf8 but

Re: [Tutor] How to create array of variants?

2008-07-08 Thread John Fouhy
On 09/07/2008, Kelie <[EMAIL PROTECTED]> wrote: > I think comtypes or pywin32 do take care of some conversion between Python > types and VB types. But they don't work with AutoCAD. Hi Kelie, This is a short excerpt from _Python Programming on Win32_: """In many cases, PythonCOM can translate be

Re: [Tutor] How to create array of variants?

2008-07-08 Thread Kelie
Alan Gauld btinternet.com> writes: > So if you pass in two Python lists containing: > > DataType = [1001,1070] > Data = ["Test_Application", 600] > > Does it work? > > If not what error do you get? (The full text please) > Thanks Alan. This is the error I got: Traceback (most recent call las

Re: [Tutor] line class

2008-07-08 Thread Marc Tompkins
On Tue, Jul 8, 2008 at 3:29 PM, Christopher Spears <[EMAIL PROTECTED]> wrote: > I have been reading everyone's comments on my line class. I have decided > to implement some of the suggestions. Someone suggested that I create a > Point.__cmp__ method. Here is what I have so far: > > def __cmp__(

[Tutor] line class

2008-07-08 Thread Christopher Spears
I have been reading everyone's comments on my line class. I have decided to implement some of the suggestions. Someone suggested that I create a Point.__cmp__ method. Here is what I have so far: def __cmp__(self, other): if self.x == other.x and self.y == other.y: return 0

Re: [Tutor] build list of non-empty variables

2008-07-08 Thread bob gailer
Monika Jisswel wrote: list comprehention : [ x for x in LIST if x != '' ] or just [ x for x in LIST if x ] -- Bob Gailer 919-636-4239 Chapel Hill, NC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How to create array of variants?

2008-07-08 Thread Alan Gauld
"Kelie" <[EMAIL PROTECTED]> wrote I'm trying to translate the following VB code into Python and not sure how to create an array of variants. An array of variants in Python is a list. But I'm not sure why you think you need one? VB Code: Sub SetXdata() Dim lineObj As AcadLine Set line

Re: [Tutor] Inheritance help

2008-07-08 Thread Jeff Younker
Hmm. I don't understand the LSP to make any requirements on the constructors. It says that instances of a subclass should be substitutable for instances of the base class, it doesn't say anthing how the instances are created. Constructors as a separate language entity is an idea born of C++, Jav

Re: [Tutor] build list of non-empty variables

2008-07-08 Thread Monika Jisswel
list comprehention : [ x for x in LIST if x != '' ] ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How to create array of variants?

2008-07-08 Thread Kelie
Andre Engels gmail.com> writes: > > So what does the code of line.SetXData(dataType, dataValue) look like? > >From that code you should be able to discern what argument type is > wanted. > Thanks Andre. I don't know how the correct code should look like in Python. In VB, I've posted the code in

Re: [Tutor] line class

2008-07-08 Thread Alan Gauld
"Christopher Spears" <[EMAIL PROTECTED]> wrote class Point(object): def __init__(self, x=0.0,y=0.0): self.x = float(x) self.y = float(y) def __repr__(self): coord = (self.x,self.y) return coord You could add a couple of methods here to get deltaX and deltaY values Or ev

Re: [Tutor] build list of non-empty variables

2008-07-08 Thread Kent Johnson
On Tue, Jul 8, 2008 at 9:14 AM, Don Jennings <[EMAIL PROTECTED]> wrote: > Hi, folks. > > From within a class, I want to return a string with data from non-empty > variables in a class. > > I could create a list of all the variables and then iterate over them, > dropping the ones which are empty, th

Re: [Tutor] Unzipping a list

2008-07-08 Thread Alan Gauld
"Faheem" <[EMAIL PROTECTED]> wrote If anyone is interested I found this while googling answers= ['ask'.'tell','repeat','sell'] def unzip(answers): unzipped = "".join(answers) # if all items are strings unzipped = ", ".join(map(str, answers)) unzipped = " ".join(str(v) for v in answers i

Re: [Tutor] line class

2008-07-08 Thread Paul McGuire
> > > def __init__(self,p1,p2): > > self.p1 = p1 > > self.p2 = p2 > > > > And since a line should not have zero length (although you might argue > > with that!) you could also check if > > p1==p2 > > In this case he should define Point.__cmp__() so the comparison is by value rather than iden

[Tutor] build list of non-empty variables

2008-07-08 Thread Don Jennings
Hi, folks. >From within a class, I want to return a string with data from non-empty variables in a class. I could create a list of all the variables and then iterate over them, dropping the ones which are empty, then join() and return them; however, I am guessing there is another way to get that

Re: [Tutor] Exploring the Standard Library

2008-07-08 Thread Tim Golden
Hansen, Mike wrote: [mailto:[EMAIL PROTECTED] On Behalf Of Nathan Farrar Sent: Saturday, July 05, 2008 12:24 PM To: Python Tutor Subject: [Tutor] Exploring the Standard Library I'd like to spend some time exploring the standard library. I'm running python on Ubuntu. How would I find the locat

Re: [Tutor] New to pythong

2008-07-08 Thread Hansen, Mike
>Subject: Re: [Tutor] New to pythong >Hello everybody: > >I am new to this mailing list, and it said that i could the simplest of questions. So i was wondering if anyone could be so kind as to e-mail me a project idea or something to go out an learn to do in python. I don't know any languages, b

Re: [Tutor] Exploring the Standard Library

2008-07-08 Thread Hansen, Mike
> [mailto:[EMAIL PROTECTED] On Behalf Of Nathan Farrar > Sent: Saturday, July 05, 2008 12:24 PM > To: Python Tutor > Subject: [Tutor] Exploring the Standard Library > > I'd like to spend some time exploring the standard library. > I'm running python on Ubuntu. How would I find the location > o

Re: [Tutor] Tutor Digest, Vol 53, Issue 13

2008-07-08 Thread Kent Johnson
On Sun, Jul 6, 2008 at 5:09 AM, Lie Ryan <[EMAIL PROTECTED]> wrote: > The string implicit string concatenation exist for things like verbose > re (regular expression): > > import re > re.compile( > '<' # Start opening tag > '\s*' # Arbitrary whitespace > '(.*?)' # tagname > '\s*' # Arbitr

Re: [Tutor] How to create array of variants?

2008-07-08 Thread Monika Jisswel
Comment : I never did any VB so I am not sure if I understand you. supposing your data comes like this : python code : Data = ( ('A', 1), ('B', 2), ('C', 3), ('D', 4) ) > #you can create a list of the items like this : > > List_Letters = [ x[0] for x in Data] > List_Numbers = [ x[1] for x in Dat

Re: [Tutor] Tutor Digest, Vol 53, Issue 13

2008-07-08 Thread Lie Ryan
> Message: 5 > Date: Fri, 04 Jul 2008 00:29:03 +0800 > From: Dong Li <[EMAIL PROTECTED]> > Subject: Re: [Tutor] Question about string > To: tutor@python.org > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain > > > > Date: Thu, 3 Jul 2008 10:18:23 +0100 > > From: "Alan Gauld" <[EMAIL PRO

Re: [Tutor] line class

2008-07-08 Thread Kent Johnson
On Tue, Jul 8, 2008 at 4:01 AM, Alan Gauld <[EMAIL PROTECTED]> wrote: > def __init__(self,p1,p2): > self.p1 = p1 > self.p2 = p2 > > And since a line should not have zero length (although > you might argue with that!) you could also check if > p1==p2 In this case he should define Point.__cmp__

Re: [Tutor] line class

2008-07-08 Thread Kent Johnson
On Tue, Jul 8, 2008 at 12:52 AM, Christopher Spears <[EMAIL PROTECTED]> wrote: > For problem 13-6 out of Core Python Programming, I created a line class that > consists of two points. The line class has the following methods: __repr__, > length, and slope. Here is the code: >def __repr__(s

Re: [Tutor] How to create array of variants?

2008-07-08 Thread Andre Engels
On Tue, Jul 8, 2008 at 11:00 AM, Kelie <[EMAIL PROTECTED]> wrote: > John, > > Thanks for your reply. I'm aware of list, tuple, sets, etc. and have tried > them, > which results in an error: Invalid argument type in SetXData method. My > understanding is that I do need an array here. Just don't kno

Re: [Tutor] How to create array of variants?

2008-07-08 Thread Kelie
John, Thanks for your reply. I'm aware of list, tuple, sets, etc. and have tried them, which results in an error: Invalid argument type in SetXData method. My understanding is that I do need an array here. Just don't know the correct way of doing it. __

Re: [Tutor] line class

2008-07-08 Thread Alan Gauld
"Christopher Spears" <[EMAIL PROTECTED]> wrote class Point(object): def __init__(self, x=0.0,y=0.0): class Line(object): def __init__(self, p1, p2): self.p1 = Point(x1,y1) self.p2 = Point(x2,y2) This is wrong I suspect. You are passing two point objects into the constructor b

Re: [Tutor] Unzipping a list

2008-07-08 Thread Faheem
Hey all, If anyone is interested I found this while googling answers= ['ask'.'tell','repeat','sell'] def unzip(answers): unzipped = "".join(answers) # if all items are strings unzipped = ", ".join(map(str, answers)) unzipped = " ".join(str(v) for v in answers if v > 0) return unzipped