Re: [Tutor] Using new style classes and __slots__

2005-09-24 Thread mailing list
Hi Kent, > > >>> class foo(object): > ... __slots__ = ['x', 'y'] > ... > >>> f=foo() > >>> f.x=1 > >>> f.y=2 > >>> f.z=3 > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: 'foo' object has no attribute 'z' > > Take a look at > http://www.python.org/2.2.3/des

[Tutor] Using new style classes and __slots__

2005-09-23 Thread mailing list
Hi all, I'm just looking for a quick runthrough on the differences between new style classes and the old ones, and how to use the new ones. Also, how exactly do you use __slots__? I've got a 6000 object collection, and apparently using __slots__ will save memory, but only those attributes specifi

Re: [Tutor] How do fix this error?

2005-09-16 Thread mailing list
raw_input takes one argument. While >>> x = 5 >>> b = 10 >>> print x, "+", b, "=", x+b will print 5 + 10 = 15, you could also have written it - >>>print str(x) + " + " + str(b) + " = " + str(x+b) Now, if I have a function - def divByTen(number): return number/10 I can call it like s

Re: [Tutor] making a table

2005-09-09 Thread mailing list
Hi Goofball223, Just a quick thing - > for i in (0,10, 20, 30, 40, 50, 60, 70, 80, 90, 100): Have you used range() before? for i in range(10): print i 0 1 2 3 4 5 6 7 8 9 It's handy for situations like yours. Also, you could use it like this - zeroToNine = range(10) print zeroToNine

[Tutor] OT - email & imaplib modules

2005-09-07 Thread mailing list
Hi all, Just musing. Even though I'm familiar with imaplib & IMAP, and most of the email modules, I still find them somewhat... obtuse to work with. The IMAP protocol is rather exposed in imaplib, and you have to read RFCs and fiddle to sort the format required for IMAP commands. For an examp

Re: [Tutor] UTf-8 to Entity

2005-08-19 Thread mailing list
You'll need the csv module. And that should be about it, I think. The rest would just be using string methods. On 8/15/05, Diaz, Wendell <[EMAIL PROTECTED]> wrote: > > > > Hey guys, > > > > Hope you can help me on this. > > > > I want to make a python program which opens an XML (U

Re: [Tutor] Sorting a list of lists aka nested lists

2005-08-19 Thread mailing list
No-one's mentioned a Schwartzian Transform yet ; ) On 8/15/05, Kent Johnson <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Note that in Python2.4+, you can use key= instead: > > > > def sortKey(lst): > > return lst[2] > > Quant.sort(key=sortKey) > > > > This is more effient than spe

[Tutor] Declaring encoding question

2005-08-19 Thread mailing list
Hi all, I've got some source code which will be handling non-ASCII chars like umlauts and what not, and I've got a testing portion stored in the code. I get this deprecation warning when I run my code - __main__:1: DeprecationWarning: Non-ASCII character '\xfc' in file C:\Python24\testit.py on

Re: [Tutor] Silly loop question

2005-08-19 Thread mailing list
Hehe, Yah, I should've read the tutorial again, I do apologise, it was a 3 in the morning-coffee not working question. Regards, Liam Clarke On 8/17/05, Alan G <[EMAIL PROTECTED]> wrote: > > changeIndex = None > > al = len(line) > > for i in range(al): > > And theres the problem. > Pythonpro

[Tutor] Silly loop question

2005-08-16 Thread mailing list
Hi all, I should know this, but it seems to elude me at present. I have a loop which is looping through a line of chars by index. So, one of these - for i in range(len(line)): Now, question is, is there a simple way to 'fast forward' index i? At the moment, I'm doing it like this - c

Re: [Tutor] Question on classes/instances

2005-08-10 Thread mailing list
Erk, I of course meant - path = os.path.join('categories', self.name) On 8/10/05, mailing list <[EMAIL PROTECTED]> wrote: > Hi Negroup, > > First off, you may want to use os.path.join to create paths - > > path = 'categories/%s' % self.name > >

Re: [Tutor] Question on classes/instances

2005-08-10 Thread mailing list
Hi Negroup, First off, you may want to use os.path.join to create paths - path = 'categories/%s' % self.name could be - path = os.path.join(categories, self.name) This will ensure minimum hassle if you ever want to use this across multiple OS. Also, it looks a little tidier, and IMAO, tidie

Re: [Tutor] help

2005-08-10 Thread mailing list
Also, you may want to consider something like easygui - http://www.ferg.org/easygui/ if all you need is simple dialogs. You may also want to consider Pythoncard - pythoncard.sourceforge.net, it's quite capable of more elaborate GUI stuff, but it's built on wxPython, which can be a little intimidat

[Tutor] references and popping, caveats?

2005-08-07 Thread mailing list
Hi all, I have the following code - >>> j = """a = { b = { c = { d = 5 e = 10 } } }""" >>> ref = [] >>> data = {} >>> ref.append(data) >>> for line in j.split('\n'): ... if "=" in line: ... (LHS, RHS) = line.split(" = ") ... if RHS == "{": ... #op