Re: md5 strange error

2009-10-21 Thread Stephen Fairchild
or "license" for more information. >>>>> import md5 >>>>> pass = md5.new() >> File "", line 1 >> pass = md5.new() >> ^ >> SyntaxError: invalid syntax > > pass is a keyword, as in: > > def f (): >

Re: how to write a unicode string to a file ?

2009-10-16 Thread Stephen Fairchild
Instead, use a compatible character encoding. Note the explicit conversion. fh.write(line.encode('utf-8')) Alternatively, you can write sixteen bit unicode directly to a file: import codecs f = codecs.open('unicodetest.txt', mode='w', encoding='utf-16&

Re: the usage of 'yield' keyword

2009-10-14 Thread Stephen Fairchild
s two things. It states what is to be returned by the generator's next() method and it also defines g as a function that returns a generator. -- Stephen Fairchild -- http://mail.python.org/mailman/listinfo/python-list

Re: code in a module is executed twice (cyclic import problems) ?

2009-10-11 Thread Stephen Fairchild
gt;> this is the resulting output: >> >> B [3] >> B [3, 3] >> C [3, 3] >> >> Why is the B.py executed twice ? B.py is the entry point of the program and it is known internally as __main__. There is no record of a B.py. If you really must import objects from the main module you can do it like this. from __main__ import * -- Stephen Fairchild -- http://mail.python.org/mailman/listinfo/python-list

Re: run-time inclusion of files

2009-09-05 Thread Stephen Fairchild
must have been imported already Maybe use in conjunction with python-inotify and or Gamin for change detection. -- Stephen Fairchild -- http://mail.python.org/mailman/listinfo/python-list

Re: Running Sum script

2009-09-04 Thread Stephen Fairchild
ve a > running sum until the end of file. Untested: with open("numbers.txt", "r") as f: print sum(int(x) for x in f) -- Stephen Fairchild -- http://mail.python.org/mailman/listinfo/python-list

Re: File Handling Problem

2009-09-04 Thread Stephen Fairchild
; problem as I see is nicely handled in list, > > like list_one=["god","earth","sky","cloud","rain"] > list_one[0]="god" > list_one[2]="sky" > > but can it be for string and file? It's ea

Re: Select column from a list

2009-08-28 Thread Stephen Fairchild
9), (2, 6, 10), (3, 7, 11), (4, 8, 12)] cols = zip(*rows) To just get the second column: zip(*rows)[1] -- Stephen Fairchild -- http://mail.python.org/mailman/listinfo/python-list

Re: Need help with Python scoping rules

2009-08-27 Thread Stephen Fairchild
ing instance creation with class creation. -- Stephen Fairchild -- http://mail.python.org/mailman/listinfo/python-list

Re: Does Class implements Interface?

2009-08-27 Thread Stephen Fairchild
in a neat package, set of functions, recipe or pattern. http://docs.python.org/library/abc.html In particular, pay attention to the term virtual subclass and also note in the second code example the use of __subclasshook__ to define virtual subclass membership by the presence (or not) of class attrib

Re: How to unencode a string

2009-08-27 Thread Stephen Fairchild
et Word1 > Word2 Word3. Would also like to handle special characters like '",(){} > [] etc/ import urllib print urllib.unquote("Word1%20Word2%20Word3") -- Stephen Fairchild -- http://mail.python.org/mailman/listinfo/python-list

Re: Need help with Python scoping rules

2009-08-27 Thread Stephen Fairchild
... _classvar = fact(5) del fact() -- Stephen Fairchild -- http://mail.python.org/mailman/listinfo/python-list

Re: Help with arrays

2009-08-26 Thread Stephen Fairchild
Dave Angel wrote: > With this change the best solution changes from a random shuffle to a > binary search. Which is not what the OP asked for. Anyway, I think whatever solution is chosen it's probably best written as a generator. The new pushback syntax may prove useful. -- Stephe

Re: Need help with Python scoping rules

2009-08-25 Thread Stephen Fairchild
fact(5)}) Demo = Demo() d = Demo() print d._classvar# prints 120 print d.fact(7) # prints 5040 print Demo # prints -- Stephen Fairchild -- http://mail.python.org/mailman/listinfo/python-list

Re: Help with arrays

2009-08-25 Thread Stephen Fairchild
use random.shuffle() to > put them in random order and then run through the guesses one at a time. import random import time l = range(1, 10) while l: print l.pop(random.randint(0, len(l) - 1)) time.sleep(2) -- Stephen Fairchild -- http://mail.python.org/mailman/listinfo/python-list

Re: Is it a bug?

2009-08-25 Thread Stephen Fairchild
dexes and what is the syntax? For the first element: >>> words[0] > 2) I just noticed that the first and the last words in the output are > enclosed in single quotes, and the middle one is enclosed in double > quotes. Is it a bug? If not, why does the output work that way? The

Re: Items inheriting attributes from its container?

2009-08-22 Thread Stephen Fairchild
fine: > p1 = lakers[1] > print p1.kitcolor > > # However the following doesn't work: > lakers.kitcolor = 'blue' > print p1.kitcolor > > #-8<---- I hope this gives you some good ideas. http://en.wikipedia.org/wiki/Join_(SQL) I suspect you will be finding a use for the special __getattr__ method, which is called when an attribute is not found. This can be used to search on your set of joined objects. Your list of joined objects should be a set() to prevent duplicates. -- Stephen Fairchild -- http://mail.python.org/mailman/listinfo/python-list