Re: Simple list problem that's defeating me!

2010-06-22 Thread Xavier Ho
On 23 June 2010 00:06, Neil Webster wrote: > Hi all, > > I've got a simple problem but it's defeated me and I was wondering if > somebody could point out where I'm going wrong or offer an alternative > solution to the problem? > > I have a list of lists such as [[a,2,3,4],[b,10,11,12], [a,2,3,4]]

Re: Persistent failure of 'break' statement ( novice )

2009-06-13 Thread Xavier Ho
erent ways of launching the program. And share with us what you did to run this to begin with, that might help as well. Best regards, Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xav

Re: class or instance method

2009-06-17 Thread Xavier Ho
I'm quite curious as to why you would like it, because: >>> MyClass (returns the MyClass class representation) >>> MyClass() (returns a instance of the MyClass class) So, are you just looking for a method that does exactly the above? Best regards, Ching-Yun "

Re: calculating a self.value, self.randomnum = normalvariate(x, y)

2009-06-20 Thread Xavier Ho
: print applicant(random.randint(0,100), random.randint(0,100)).randomnum == Or you could just use randint() if you only wanted a linear distribution. PS: Thanks, btw, new to python myself also, and looking into this was cool. :]

calculating a self.value, self.randomnum = normalvariate(x, y)

2009-06-20 Thread Xavier Ho
hat was to print out 10 random samples. If you're not sure if this is what you want, then um.. not much I can do there. What is this class originally for? If you feel the clamp is too huge, well, I'm always interested in improvements/alternatives! Best regards, Ching-Yun "Xavier"

Re: calculating a self.value, self.randomnum = normalvariate(x, y)

2009-06-20 Thread Xavier Ho
to begin? > > x = max(0, min(100, normalvariate(x, y))) > > That is an awesome way of shorthanding clamp. Best regards, Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavier

Inheritance and forward references (prototypes)

2009-06-20 Thread Xavier Ho
x27;m just getting this "necessary" step because my books say so. If anyone has a good explanation, please do tell. Best regards, Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://x

re.NONE

2009-06-22 Thread Xavier Ho
(arg, MRAB, sorry, wrong address!) Defining None to 0 is a bad idea. You'll have trouble debugging later on. Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavierho.com/ On Tu

Re: re.NONE

2009-06-22 Thread Xavier Ho
ding to mailing list for some reason. What happend to the reply-to request? =/) Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavierho.com/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Newby Windows User

2009-07-01 Thread Xavier Ho
command like this: python .py That should do the trick. Alternatively, you can type in python and start the python shell in the same folder. Then you can just do import and whatever you like. :] Best regards, Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04

Why is my code faster with append() in a loop than with a large list?

2009-07-05 Thread Xavier Ho
ing is 40x slower, and was expected. But I still can't puzzle out why his use of appending in Version B was so much faster than mine. Any insights would be welcome. I'm going on a family trip, though, so my replies may delay. Best regards, Ching-Yun "Xavier" Ho, Technical Arti

Re: Why is my code faster with append() in a loop than with a large list?

2009-07-06 Thread Xavier Ho
Thanks for the response all, I finally got my 'net working on the mountains, and I think your reasons are quite sound. I'll keep that in mind for the future. Best regards, Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID:

Re: help me to find the error

2009-07-10 Thread Xavier Ho
lines = f0.readlines()* Then in the for loop, change f1 to *f1=lines[i].split()* That may just stop it from complaining. Untested, but logically it's sound. Hope that works, Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaX

Re: simple question about Dictionary type containing List objects

2009-07-13 Thread Xavier Ho
e list mycontacts ,like > mycontacts_numbers=3 <http://mail.python.org/mailman/listinfo/python-list> > >>> len(emails['mycontacts']) 3 HTH, Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavierho.com/ -- http://mail.python.org/mailman/listinfo/python-list

Why does extend() fail in this case, and what am I doing wrong?

2009-07-14 Thread Xavier Ho
w, but I'm probably missing something. Any pointers would be great. Best regards, Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavierho.com/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Why does extend() fail in this case, and what am I doing wrong?

2009-07-14 Thread Xavier Ho
I see. Thanks! Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavierho.com/ On Tue, Jul 14, 2009 at 11:20 PM, Jochen Schulz wrote: > Xavier Ho: > > > > Why doesn

Re: using timers to force an execution time

2009-07-16 Thread Xavier Ho
see? the while body ran for about 7 seconds... i bet it has to do with the > fact that the timer does not control inner loops... any suggestion? > > I'm guessing it has to do with a sleep of 0.66 seconds x 10 times = sleep for 6.6 seconds, and then it checks for e.isSet(). Best rega

Try... except....Try again?

2009-07-16 Thread Xavier Ho
pends it into primes. This way, it keeps trying to append until the nth prime requested exist, and returns it. My problem is that it's a "While True" loop, which I get a lot of "Don't do it!" In the light of making the code better, what could I do? Best regards,

Re: Try... except....Try again?

2009-07-17 Thread Xavier Ho
, common sense. Also... "while True" has a bad reputation. But mostly outside influences. But if it's okay, it's okay by me.. I can't think of an easier way to code the "try loop" above, anyhow. Ching-Yun "Xavier" Ho, Technical Artist Contact Informa

Try... except....Try again?

2009-07-17 Thread Xavier Ho
as well as the previous version, but slightly safer on my part... and I can adapt this in my future coding habits. Thanks again. Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http

Re: Try... except....Try again?

2009-07-17 Thread Xavier Ho
erate from n=2 and on every time, which makes generation time linear. However, I just gave the link's code a quick try. It was at least 10x times faster than my code to generate 100000 prime numbers - I'll have a closer look. Thanks a great deal. Ching-Yun "Xavier" Ho, Technical

Re: Try... except....Try again?

2009-07-17 Thread Xavier Ho
gt; is not really an exceptional case. > > If you insists on using a try-except clause, use it this way: > > Well, I don't have to use try-except. I think I got another idea though. I could use an internal counter to keep track of how many prime numbers have generated, and if not eno

Try... except....Try again?

2009-07-17 Thread Xavier Ho
. Right, so for i in xrange() would be a better choice? Best regards, Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavierho.com/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Re: Changing the private variables content

2009-07-22 Thread Xavier Ho
#x27; ^ SyntaxError: invalid syntax So, uh, I'm wondering if this is a bug. And also the solution to his problem. Good luck. Any ideas appreciated. Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavierho.com/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Re: Changing the private variables content

2009-07-22 Thread Xavier Ho
> > val('self.' + attr + '=\'' + val + '\'') > Obviously that was eval, not val. Also it doesn't work without the escaped single quotes, either. -- http://mail.python.org/mailman/listinfo/python-list

Re: Re: Changing the private variables content

2009-07-22 Thread Xavier Ho
Got it: exec('self.' + attr + '=\'' + val + '\'') That worked. I think it'll do what you want now ;) Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com W

Re: Changing the private variables content

2009-07-22 Thread Xavier Ho
> What is the point of the _SetVar method? > > So you can set any variable in that class, I guess? -- http://mail.python.org/mailman/listinfo/python-list

Re: Extract images from PDF files

2009-07-28 Thread Xavier Ho
op. Either way works! Best regards, Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavierho.com/ On Wed, Jul 29, 2009 at 6:21 AM, writeson wrote: > David, > > Thanks fo

Re: merge two png pic

2009-07-28 Thread Xavier Ho
k of. It's a lot slower, but definitely more space than your RAM. Good luck, Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavierho.com/ -- http://mail.python.org/mailman/listinfo/python-list

Re: idiom for list looping

2009-07-29 Thread Xavier Ho
> > superpollo wrote: > >> >> for (i, e) in enumerate(nomi): >>print i, "-", e >> >> Just to be random: print '\n'.join(["%s - %s" % (i, e) for i, e in enumerate(nomi)]) This has one advantage: only print once. So it's slightly faster if you have a list of a large amount. -- http://mail.pyth

Re: idiom for list looping

2009-07-29 Thread Xavier Ho
On Wed, Jul 29, 2009 at 8:52 PM, MRAB wrote: > Slightly shorter: > > print '\n'.join("%s - %s" % p for p in enumerate(nomi)) > > :-) > That's cool. Does that make the "list" a tuple? (not that it matters, I'm just curious!) I just tested for a list of 1000 elements (number in letters from 1 to 1

idiom for list looping

2009-07-29 Thread Xavier Ho
Ack, sent to the wrong email again. On Wed, Jul 29, 2009 at 9:02 PM, superpollo wrote: > > >>> print '\n'.join("%s - %s" % p for p in enumerate(nomi)) > File "", line 1 >print '\n'.join("%s - %s" % p for p in enumerate(nomi)) >^ > SyntaxError: invalid syn

Re: idiom for list looping

2009-07-29 Thread Xavier Ho
On Wed, Jul 29, 2009 at 9:17 PM, MRAB wrote: > I've just replaced the list comprehension with a generator expression. > > Oh, and that isn't in Python 2.3 I see. Generators are slightly newer, eh. Thanks! -- http://mail.python.org/mailman/listinfo/python-list

Re: Particle research opens door for new technology

2009-07-29 Thread Xavier Ho
Is this a spam? Why did you have to send it 4 times, and it's already in the past (July 9 and 10) ? Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavierho.com/ -- http://

Re: problem on socket programming

2009-07-31 Thread Xavier Ho
Whoops, posted to the wrong address yet again. I deserve some punishment. On Fri, Jul 31, 2009 at 5:33 PM, Xavier Ho wrote: > On Fri, Jul 31, 2009 at 5:25 PM, MalC0de wrote: > >> >> while true : >> >> where's the problem, > > > There

Re: Confessions of a Python fanboy

2009-07-31 Thread Xavier Ho
On Fri, Jul 31, 2009 at 6:08 PM, Masklinn wrote: > ... but since Python doesn't have anonymous functions that usage > tends to be a bit too verbose ... > Sorry to interrupt, but wouldn't lambda in Python be considered as 'anonymous functions'? -- http://mail.python.org/mailman/listinfo/python-

Re: Confessions of a Python fanboy

2009-07-31 Thread Xavier Ho
On Fri, Jul 31, 2009 at 6:25 PM, Chris Rebert wrote: > I believe "full" anonymous functions was intended by the author. > lambdas are limited to a single expression. "Full" anonymous functions > would be allowed to contain multiple statements. > > Cheers, but what about this: def goBig(x):

Re: Confessions of a Python fanboy

2009-07-31 Thread Xavier Ho
On Fri, Jul 31, 2009 at 6:38 PM, Chris Rebert wrote: > No, because it has a name, namely "goBig"; this obviously prevents it > from being "anonymous". > > For comparison, note how the function in the following example is > never given a name, and is thus anonymous: > >>> (lambda x: x+5)(6) > 11 >

Re: file comparison

2009-07-31 Thread Xavier Ho
On Fri, Jul 31, 2009 at 7:25 PM, learner learner wrote: > Hi all, > > I want to compare two text files line by line and eliminate the > matching/repeated line and store the unmatched/leftout lines into a third > file or overwrite into one of them. > Sounds like homework to me. Why not look into:

Re: Seeding the rand() Generator

2009-08-04 Thread Xavier Ho
roup. Well, some people have suggested to use that inside Python. That would work, right? Although, if you're just trying to find the Python-equivalent, fair enough. Regards, Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 E

Re: merge two png pic

2009-08-04 Thread Xavier Ho
c loader, and only load pictures as relevant (i.e: visible, and next to visible) Think how Google Maps do it. They can't possibly upload 5GB of pictures every time you access Maps - that wouldn't have worked. They work with the only visible areas. If you could tell us exactly wh

Re: Obtaining Python version

2009-08-04 Thread Xavier Ho
On Tue, Aug 4, 2009 at 8:30 PM, Yinon Ehrlich wrote: > Hi, > Easy way to test for Python version: > if sys.hexversion >= 0x2060100: > pass > Great suggestion. I just tested it on my newly installed Python 3.1 (as of 3.1r31) >>> import sys >>> "%X" % sys.hexversion '30100F0' That's genius - '3

Re: Obtaining Python version

2009-08-04 Thread Xavier Ho
On Tue, Aug 4, 2009 at 9:34 PM, Xavier Ho wrote: > ... and '00F0' is r31! > Actually, 00F0 is 576 in decimal. Maybe it's the subversion? Anyhow, it's still good! -- http://mail.python.org/mailman/listinfo/python-list

Re: Obtaining Python version

2009-08-04 Thread Xavier Ho
On Wed, Aug 5, 2009 at 12:17 AM, MRAB wrote: > 0x00F0 is 240. ... Right. I wonder where my brain is. *searches pocket* So, what am I doing wrong here? >>> int(str(0x00F0), 16) 576 Cheers, -Xav -- http://mail.python.org/mailman/listinfo/python-list

Re: Obtaining Python version

2009-08-04 Thread Xavier Ho
On Wed, Aug 5, 2009 at 12:44 AM, D'Arcy J.M. Cain wrote: > On Wed, 5 Aug 2009 00:39:56 +1000 >> Xavier Ho wrote: >> > So, what am I doing wrong here? >> > >> > >>> int(str(0x00F0), 16) >> >> Look at the output of str(0x00F0) for a

Re: Datetime with float seconds

2009-08-05 Thread Xavier Ho
On Wed, Aug 5, 2009 at 10:50 PM, kpal wrote: > Hello Everybody, > > The standard datetime has 1 microsecond granularity. My application > needs finer time resolution, preferably float seconds. Is there an > alternative to the out-of-the-box datetime? Timezone support is not > essential. This is

Re: Subclassing Python's dict

2009-08-05 Thread Xavier Ho
Mapping might be of your interest. > Another guy have reported me that he experiences similar problems with > subclassing builtin 'list'. Similarly, UserList is what you should subclass. HTH, Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+6

Re: Subclassing Python's dict

2009-08-05 Thread Xavier Ho
On Thu, Aug 6, 2009 at 5:23 AM, Joshua Kugler wrote: > Are you referring to Python 3.0? Python 2.6 does not have > collections.UserDict > > j > Yes, I was sometimes it's hard to keep track what's not in 2.6 and in 3.1 for me, sorry. And thanks. The ABC MutableMapping is still valid, though.

Re: merge two png pic

2009-08-06 Thread Xavier Ho
On Thu, Aug 6, 2009 at 12:17 PM, cocobear wrote: > > I want to view image use Windows Pic View. > > If you run out of memory trying to combining those images into a 30k by 40k pixels image, the Windows Pic View isn't going to be able to display it either. Regards, Chin

Re: Subclassing Python's dict

2009-08-06 Thread Xavier Ho
On Thu, Aug 6, 2009 at 1:19 PM, alex23 wrote: > Xavier Ho wrote: > > You should subclass collections.UserDict, and not the default dict class. > > Refer to the collections module. > > Xavier, why do you think that is the correct approach? I'll be honest first and sa

Re: remove last 76 letters from string

2009-08-06 Thread Xavier Ho
# Do for New DNA Sequence # ... else: line = line[:-76] # ... Should do what you need. Best regards, Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavierho.com/ -- http://mail.python.org/mailman/listinfo/python-list

Re: www.python.org website is down?

2009-08-08 Thread Xavier Ho
Well, it's back up now. At least for me. ;) Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavierho.com/ On Sun, Aug 9, 2009 at 4:49 AM, Sharath wrote: > On Aug

Re: python.org downtime (was Re: is it possible to overload operator "^"?)

2009-08-08 Thread Xavier Ho
On Sun, Aug 9, 2009 at 6:37 AM, Aahz wrote: > www.python.org is currently having hardware problems > So what I'm seeing is an illusion? It works as of now. - Xavier -- http://mail.python.org/mailman/listinfo/python-list

Re: www.python.org website is down?

2009-08-10 Thread Xavier Ho
On Mon, Aug 10, 2009 at 10:41 PM, Christopher wrote: > > Actually, it appears to be down again. > Nope, works for me, just a little slow. -Xav -- http://mail.python.org/mailman/listinfo/python-list

Re: Any built-in function for smallest positive floating point number?

2009-08-11 Thread Xavier Ho
On Wed, Aug 12, 2009 at 3:29 AM, Maria Liukis wrote: > Hello everybody, > Is somebody aware of built-in Python's function that would return > a value for smallest positive double precision floating point number > (analogous to 'realmin' in Matlab). Python has built-in sys.maxint but I > could not

Re: Any built-in function for smallest positive floating point number?

2009-08-11 Thread Xavier Ho
I got it to work with Python 2.6.2. >>> import struct >>> struct.unpack('d', struct.pack('Q', 1))[0] 4.9406564584124654e-324 Python 3.1 will print 5e-324, which is fair enough. Cheers, Xavier -- http://mail.python.org/mailman/listinfo/python-list

Re: Any built-in function for smallest positive floating point number?

2009-08-11 Thread Xavier Ho
Actually, that was double precision. You asked for float precision. >>> struct.unpack('f', struct.pack('L', 1))[0] 1.4012984643248171e-45 which is the same as: >>> 2**-149 1.4012984643248171e-45 I think that's it. Sorry for posting to the list three times in a row. corrections welcome. -- http:

What happened to __cmp__() in Python 3.x?

2009-08-15 Thread Xavier Ho
mewhere, I apologise in advance. Already googled around but I didn't find information on this. Any replies appreciated. Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavierho.com/ -

What's a good solution to implement rich comparison for user-defined classes? (was: What happened to __cmp__() in Python 3.x?)

2009-08-15 Thread Xavier Ho
-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavierho.com/ -- http://mail.python.org/mailman/listinfo/python-list

Re: What happened to __cmp__() in Python 3.x?

2009-08-16 Thread Xavier Ho
he rich comparison special methods, etc. Also, I noticed heapq (the priority queue/heap queue module) doesn't use the natural sorting order like sorted() does. Just saying. Could someone give it a try? Regards, Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mo

Re: What happened to __cmp__() in Python 3.x?

2009-08-16 Thread Xavier Ho
give that a test tomorrow and see what I can come up with. Thanks for the quick info. Regards, Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavierho.com/ -- http://mail.python.org/mailman/listinfo/python-list

Re: What happened to __cmp__() in Python 3.x?

2009-08-17 Thread Xavier Ho
On Sun, Aug 16, 2009 at 10:33 PM, Mark Lawrence wrote: > > I wasn't discussing __cmp__, I was referring to the quote by Chris Rebert > from the Python docs regarding the rich comparison methods, a discrepancy > between the documentation and the implementation as noted in the link that I > gave, an

Re: define class over 2 files

2009-08-17 Thread Xavier Ho
On Tue, Aug 18, 2009 at 2:45 PM, naveen wrote: > Is it possible to split up a class definition over multiple files? > - Answer in short, I don't think so. Now why would you want to do that? There is another solution - have a main class for shared methods, and have other classes [in different

Re: expandtabs acts unexpectedly

2009-08-19 Thread Xavier Ho
On Wed, Aug 19, 2009 at 5:57 PM, digisat...@gmail.com wrote: > Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > [GCC 4.3.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> ' test\ttest'.expandtabs(4) > ' test test' > >>> 'test \ttest'.expandtabs(4)

Re: How to create ones own lib

2009-08-19 Thread Xavier Ho
On Wed, Aug 19, 2009 at 7:00 PM, Horst Jäger wrote: > Hi, > > I would like to create my own lib "hotte.py" which I can import like > > >import string,hotte > > . How do I do that? > 1) Have the hotte.py in the same directory of any of your other Python code that imports it, or 2) Put the

Re: Hi everyone, I get a problem when using binhex module

2009-08-20 Thread Xavier Ho
On Thu, Aug 20, 2009 at 10:07 PM, Yan Jian wrote: > > Does anyone encounter similar situation. Thank you for your help? > Yeah, in Python 3.1 I get this: Traceback (most recent call last): File "test.py", line 6, in binhex.binhex(file, sys.stdout) File "c:\Python31\lib\binhex.py", lin

Re: debugger

2009-08-22 Thread Xavier Ho
On Sat, Aug 22, 2009 at 6:17 PM, flagmino wrote: > To get familiar with the debugger, I have loaded this program: > > import math > > def s1(x, y): > a = (x + y) > print("Answer from s1"), a > return > > def s2(x, y): > b = (x - y) > print("This comes from s2"), b > #print z > print

Re: Is Python what I need?

2009-08-23 Thread Xavier Ho
On Sun, Aug 23, 2009 at 9:26 PM, newbie wrote: > Hi all > I'm interested in developing computer based, interactive programs for > students in a special school who have an aversion to pen and paper. What sort of interactive program? Would it be educational, for example? > I've searched the net

Re: Need help with Python scoping rules

2009-08-25 Thread Xavier Ho
I'm not really quite sure what voodoo I did here, but my code seems to work in Python 3.1.1 in the following way: class Demo(object): def func(self, n): return n * 5 _f = func(None, 5) d = Demo() print(d._f) print(d.func(5)) # OUTPUT 25 25 So, hmm? Regards, Ching-Yun &q

Re: Need help with Python scoping rules

2009-08-25 Thread Xavier Ho
On Wed, Aug 26, 2009 at 2:14 AM, Diez B. Roggisch wrote: > > Classes are not scopes. > > So the above doesn't work because name resolution inside functions/methods > looks for local variables first, then for the *global* scope. There is no > class-scope-lookup. Sorry, I'm coming here with sincer

Re: Overriding iadd for dictionary like objects

2009-08-26 Thread Xavier Ho
I haven't tested it, but did you encounter a problem defining __iadd__ in the class definition? See: http://docs.python.org/reference/datamodel.html#object.__iadd__ Cheers, Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaX

Re: [OT] How do I reply to a thread by sending a message to python-list@python.org

2009-08-27 Thread Xavier Ho
marks bold. Does __ mark underline? Those are cool things I never hear about. Thanks! On another tangent, I only found out the Python Wiki on the official site today (http://wiki.python.org/moin/) Does anyone actually use it, and what for? - Kind regards, Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavierho.com/ -- http://mail.python.org/mailman/listinfo/python-list

Re: List iterator thread safety

2009-08-27 Thread Xavier Ho
On Tue, Aug 25, 2009 at 3:43 AM, Emanuele D'Arrigo wrote: > Let's say I have a list accessed by two threads, one removing list > items via "del myList[index]" statement the other iterating through > the list and printing out the items via "for item in myList:" > statement. I tried something sim

Re: Need help with Python scoping rules

2009-08-27 Thread Xavier Ho
On Fri, Aug 28, 2009 at 9:49 AM, kj wrote: > > Miles Kaufmann writes: > > >...because the suite > >namespace and the class namespace would get out of sync when different > >objects were assigned to the class namespace: > > >class C: > > x = 1 > > def foo(self): > > print x > > pr

Re: Need help with Python scoping rules

2009-08-27 Thread Xavier Ho
On Fri, Aug 28, 2009 at 1:27 PM, Miles Kaufmann wrote: > You're right, of course. If I had been thinking properly, I would have > posted this: > > ... the suite namespace and the class namespace would get out of sync when > different objects were assigned to the class namespace: I'm not an exp

Re: Need help with Python scoping rules

2009-08-27 Thread Xavier Ho
On Fri, Aug 28, 2009 at 1:48 PM, Xavier Ho wrote: > > Class already provides some kind of scoping/namespace, that is the locals() > method for the class. What is pypothetical about this, if you could > elaborate? > Obviously that was supposed to be "hypotheti

Re: Transforming a str to an operator

2009-08-27 Thread Xavier Ho
On Fri, Aug 28, 2009 at 1:52 PM, Duke Normandin wrote: > How do I convert the contents of "op" from a string to an actual > arithmetic operator? eval() does not seem to be the answer. TIA! Maybe you were looking for print eval(num1 + op + num2) # it's a little ugly string concatenation. Hm? (

Re: Transforming a str to an operator

2009-08-27 Thread Xavier Ho
On Fri, Aug 28, 2009 at 2:35 PM, Ben Finney > wrote: >import operator > >op_funcs = { >'+': operator.add, >'-': operator.sub, >'*': operator.mul, >'/': operator.div, >} > >num_1 = int(raw_input('Enter the first number: ')) >num_2 = int(raw_i

Re: Select column from a list

2009-08-28 Thread Xavier Ho
On Fri, Aug 28, 2009 at 5:45 PM, hoffik wrote: > Hello, > > I'm quite new in Python and I have one question. I have a 2D matrix of > values stored in list (3 columns, many rows). I wonder if I can select one > column without having to go through the list with 'for' command. As far as I know tho

Re: [OT] How do I reply to a thread by sending a message to python-list@python.org

2009-08-28 Thread Xavier Ho
On Fri, Aug 28, 2009 at 6:18 PM, Hendrik van Rooyen wrote: > It would really be nice if the "reply" would go to the list, but for the > digest versions, at least, it does not. I'm on a few other lists. The Python ones are the only ones that I have to manually change. The Nuke-user mailing list

Re: [OT] How do I reply to a thread by sending a message to python-list@python.org

2009-08-28 Thread Xavier Ho
On Fri, Aug 28, 2009 at 6:54 PM, Ben Finney > wrote: > Fortunately, the messages that come from the list enable any mail client > to know the correct address for “reply to list”. It only remains to > choose a mail client that knows how to use it. Would you be so kind and share with us for such

Re: Executing python script stored as a string

2009-09-01 Thread Xavier Ho
I'm afraid I'm not much of a help here, but was there any reason you didn't want to wrap those "string functions" inside a function, and just call the function? Cheers, -Xav -- http://mail.python.org/mailman/listinfo/python-list

Re: Executing python script stored as a string

2009-09-01 Thread Xavier Ho
On Tue, Sep 1, 2009 at 9:29 AM, Ecir Hana wrote: > - if I understood it correctly defining a function in the string and > exec-ing it created the function in current scope. This is something I > really don't want > Oops, missed that point. May I ask what is there you don't want, and what about

Smallest float different from 0.0?

2009-09-07 Thread Xavier Ho
This topic came up before. =] See below. Not sure how 'standardised' this is, though. Double precision: >>> import struct >>> struct.unpack('d', struct.pack('Q', 1))[0] 4.9406564584124654e-324 Float precision: >>> struct.unpack('f', struct.pack('L', 1))[0] 1.4012984643248171e-45 Cheers, Xavier

Re: NameError: name '__main__' is not defined

2009-09-13 Thread Xavier Ho
Try if __name__ == '__main__' :], Xav On Mon, Sep 14, 2009 at 11:43 AM, Peng Yu wrote: > Hi, > > I try the following code. I don't quite understand why __main__ is not > defined. Could somebody let me know what I am wrong about it? > > Regards, > Peng > > $ cat test.py > #!/usr/bin/env python

Re: How to define a class that can act as dictionary key?

2009-09-15 Thread Xavier Ho
On Tue, Sep 15, 2009 at 9:47 PM, Lambda wrote: > When I run it, it says "TypeError: unhashable instance" > > I believe you need to implement __hash__() for the class. Make sure your class returns a unique identifier for a certain value. -- http://mail.python.org/mailman/listinfo/python-list

Re: str.split() with empty separator

2009-09-15 Thread Xavier Ho
On Tue, Sep 15, 2009 at 10:31 PM, Ulrich Eckhardt wrote: > "'abc'.split('')" gives me a "ValueError: empty separator". > However, "''.join(['a', 'b', 'c'])" gives me "'abc'". > > Why this asymmetry? I was under the impression that the two would be > complementary. > I'm not sure about asymmetry,

Re: easy question, how to double a variable

2009-09-20 Thread Xavier Ho
On Mon, Sep 21, 2009 at 6:27 AM, daggerdvm wrote: > Write the definition of a function twice , that receives an int > parameter and returns an int that is twice the value of the > parameter. > > how can i do this > I thought it was easier to implement this twice function than to find this ma

Re: easy question, how to double a variable

2009-09-22 Thread Xavier Ho
On Tue, Sep 22, 2009 at 11:58 PM, Mahmoud Abdelkader wrote: > hi looking for help catching up in a class and overall to get me better > than i am now. I can pay you by the week or per hour. > Wow. I'd feel guilty getting paid doing that. Sounds all too easy. I hope he is actually learning, not j

Re: Intercepting binding?

2009-09-23 Thread Xavier Ho
test() user = set(locals()) - default loc = dict(locals()) for item in loc.items(): if item[0] in user: print(item) ###output: ('a', <__main__.test object at 0x02D6A240>) ('default', {'__builtins__', '__name__', '__file__',

Re: how to truncate to get the 1st 5 chars from a string

2009-09-23 Thread Xavier Ho
On Thu, Sep 24, 2009 at 1:05 PM, MacRules wrote: > s="1234abcd" > s.range(0..4) > 1234a > > Is there a string function like this? > > Use the slice. >>> s = "1234abcd" >>> s[:5] '1234a' Cheers, Xav -- http://mail.python.org/mailman/listinfo/python-list

Re: Average of entries in a list of lists

2009-09-24 Thread Xavier Ho
On Thu, Sep 24, 2009 at 8:54 PM, Evora wrote: > > Hello, > > I'm a bit of a newbie to python, so this may very well be a basic question: > > I have a list of lists, with around 1000 lists looking like this: > ['0.000744', '0.480106', 'B']. > > I need the average of the first to entries of all the

Re: Format string with single quotes in it

2009-09-25 Thread Xavier Ho
On Fri, Sep 25, 2009 at 10:42 PM, Bahadir wrote: > Hi there, > > My question is simple, but I've been spending some hours over the web > and still struggling to get this right: How do I format a string that > contains single quotes in it? > I don't know what you're doing wrong, but I've tried bo

Re: palindrome iteration

2010-08-27 Thread Xavier Ho
One possible reason I can think of - "- exiting this loop means all compared chars were identical hence it is a palindrome and i return True" is probably incorrect reasoning. Think again. Also, you may consider posting your code in a way that preserves the whitespace characters. Cheers, Xav On

Re: meta-class troubles

2010-08-30 Thread Xavier Ho
Ethan, are you trying to write the constructor in the class statement? Cheers, Xav On 31 August 2010 00:10, Ethan Furman wrote: > Good Day! > > I am stuck... hopefully a few fresh pairs of eyes will spot what I am > missing. > > I have a metaclass, Traits, and two different testing files, test_

Re: meta-class troubles

2010-08-30 Thread Xavier Ho
Actually, scrape what I said. I think you need to have metaclass in the class statement, not just meta. -Xav On 31 August 2010 00:16, Xavier Ho wrote: > Ethan, are you trying to write the constructor in the class statement? > > Cheers, > Xav > > > On 31 August 2010 00:10

Re: Dumb Stupid Question About List and String

2010-08-31 Thread Xavier Ho
On 1 September 2010 07:57, Alban Nona wrote: > listPass = ["DIF","SPC", "RFL", "SSS", "REFR", "ALB", "AMB", "NRM", "MVE", > "DPF", "SDW", "MAT", "WPP"] > Out of curiosity, could you briefly mention what "SDW" and "WPP" passes are? I've worked out the rest, and these two are riddling my brain. (

Re: Dumb Stupid Question About List and String

2010-08-31 Thread Xavier Ho
On 1 September 2010 12:00, Alban Nona wrote: > @Xavier: ShaDoW, WorldPositionPoint (which is the same thing as > WordPointCloud passe) :) > Aha! That's what I was missing. Cheers, Xav -- http://mail.python.org/mailman/listinfo/python-list

Re: Dumb Stupid Question About List and String

2010-09-01 Thread Xavier Ho
On 2 September 2010 00:47, Alban Nona wrote: > Hello, > > So I figure out this night how to create automatically varibales via > vars(), the script seems to work, exept that where it should give me a list > like : > [ELM004_DIF,ELM004_SPC,ELM004_RFL,ELM004_SSS, ELM004_REFR, ELM004_ALB, > etc...]

Re: Dumb Stupid Question About List and String

2010-09-01 Thread Xavier Ho
On 2 September 2010 01:11, Alban Nona wrote: > Hello, > > seems to have the same error with python. > In fact I was coding within nuke, a 2d compositing software (not the best) > unfortunately, I dont see how I can use dictionnary to do what I would like > to do. > Hello Alban, The reason it's

<    1   2   3   >