Re: huh??? weird problem

2010-05-16 Thread Paul Hankin
, and most likely str. A good debugging tip is to use repr rather than str to print out debugging messages. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Is it better to use threads or fork in the following case

2009-05-03 Thread Paul Hankin
file. If your modem is going at full speed for those 15 minutes, you'll have around 6.3Mb of data. Even after decompressing, and unless the data is in some quite difficult to parse format, it'll take seconds to process. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: The Python standard library and PEP8

2009-04-19 Thread Paul Hankin
On Apr 19, 7:37 pm, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: The threading module has such aliases, but there are no plans for mass   renaming all the stdlib that I know of. You'll have to live with this   inconsistency. It's been fixed in Python 3.0! -- Paul Hankin -- http

Re: improve this newbie code/nested functions in Python?

2009-03-21 Thread Paul Hankin
the 'law of demeter'. If nothing else, it makes the speaker and listener much easier to read. If you later want to test these classes, you'll find it a ton easier, since you can mock the client class.. but perhaps that's a little too advanced. HTH -- Paul Hankin -- http://mail.python.org/mailman

Re: improving a huge double-for cycle

2008-09-18 Thread Paul Hankin
) for x in IN: d[x] += 1 SN = [x for (x, c) in d.iteritems() if c 1] -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: improving a huge double-for cycle

2008-09-18 Thread Paul Hankin
IN.sort() SN = [k for k, v in itertools.groupby(IN) if len(list(v)) 1] -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Good python equivalent to C goto

2008-08-17 Thread Paul Hankin
. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: regular expression extracting groups

2008-08-10 Thread Paul Hankin
is well written, and you've already reached the limits of the power of regexps, and it's difficult to read. Have a look at pyparsing for a simple solution to your problem. http://pyparsing.wikispaces.com/ -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: why goes the time change after import statement ?

2008-08-03 Thread Paul Hankin
On Aug 3, 8:12 am, binaryjesus [EMAIL PROTECTED] wrote: On Aug 3, 1:46 am, Paul Hankin [EMAIL PROTECTED] wrote: On Aug 2, 10:35 pm, binaryjesus [EMAIL PROTECTED] wrote: hi i am working on a S3 project and facing a really weird problem! take a look at the following import statements

Re: Searching for some kind of data type

2008-08-02 Thread Paul Hankin
)) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: why goes the time change after import statement ?

2008-08-02 Thread Paul Hankin
preferred format. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Is this possible ....

2008-07-23 Thread Paul Hankin
you already have a module for getting the metadata out of one of your modules; perhaps it could go in there? def version(module): return getattr(module, 'Version_Text')[0][0] -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Remove some characters from a string

2008-07-17 Thread Paul Hankin
: 'si_98udasgf' For speed, you can use 'string.translate', but simplest is to use a comprehension: import string def magic_function(s, keep=string.ascii_letters + string.digits + '_'): return ''.join(c for c in s if c in keep) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Functional/Best?

2008-07-13 Thread Paul Hankin
): ... def ITEM_TREE(self): ... builder = Builder() for word in parse_list: item = getattr(builder, word)() ... -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: python scalability

2008-07-12 Thread Paul Hankin
is actually a competitive advantage for your company? Have you seen this? http://www.paulgraham.com/pypar.html -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: formatting list - comma separated

2008-07-09 Thread Paul Hankin
On Jul 9, 8:23 pm, Robert [EMAIL PROTECTED] wrote: given d: d = [soep, reeds, ook] I want it to print like soep, reeds, ook I've come up with : print (%s+, %s*(len(d)-1)) % tuple(d) but this fails for d = [] any (pythonic) options for this? print ', '.join(d) -- Paul Hankin

Re: Anyone happen to have optimization hints for this loop?

2008-07-09 Thread Paul Hankin
()) But if you don't need the string, just write straight to the file: for part in dmntGenerator(): dmntFile.write(part) This is likely to be a lot faster as no large string is produced. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: The Yield statement

2008-07-07 Thread Paul Hankin
if length == 1: yield [n] return for i in xrange(1, n + 2 - length): for p in partitions(n - i, length - 1): yield [i] + p -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: listcomprehension, add elements?

2008-06-22 Thread Paul Hankin
the builtin 'sum' function. sum(a + b for a, b in zip(xrange(1, 51), xrange(50, 0, -1))) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie question: for loop within for loop confusion

2008-06-16 Thread Paul Hankin
solution, as it's readable and short. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Notify of change to list

2008-06-12 Thread Paul Hankin
class are allowed to replace attributes with their own lists, you'll have to catch these and convert to NotifyingLists; and it may be somewhat messy. I hope this is useful to you. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Alternative to Decimal type

2008-06-09 Thread Paul Hankin
things simpler since you don't have to worry about 'scale'. Your examples convert easily: from decimal import Decimal qty = Decimal('12.5') price = Decimal('123.45') print price * qty print qty * price print (qty * price).quantize(Decimal('0.01')) -- Paul Hankin -- http://mail.python.org/mailman

Re: PEP on breaking outer loops with StopIteration

2008-06-09 Thread Paul Hankin
http://www.python.org/dev/peps/pep-3136/ It contains exactly this idea, but using 'break letters' rather than 'raise letters.StopIteration()'. I think I like the PEP's syntax better than yours, but anyway, it was rejected. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Do this as a list comprehension?

2008-06-07 Thread Paul Hankin
, score_costs) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Macro like functionality for shorthand variable names

2008-06-07 Thread Paul Hankin
] def _setu(self, u): self.y[1] = u u = property(_getu, _setu) ... and similarly for du, V Using these two tricks, your code line would be: s.du = s.a * (s.b * s.V - s.u) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: A quick question

2008-05-28 Thread Paul Hankin
On May 28, 11:25 am, James [EMAIL PROTECTED] wrote: word = raw_input(Type a word:) start = len(word) for letter in range(start, 0, -1): print letter Hi James, for letter in reversed(word): print letter -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Weird exception in my, um, exception class constructor

2008-05-27 Thread Paul Hankin
should 'args' have to be iterable anyway?  I don't understand what's going on here?  Could someone help me with this? Did you actually write self,args = args? -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Producing multiple items in a list comprehension

2008-05-23 Thread Paul Hankin
)] -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: iterate start at second row in file not first

2008-05-21 Thread Paul Hankin
On May 20, 7:34 pm, [EMAIL PROTECTED] wrote: i have a big file with sentences, the first file of each sentence contains a colon(:) somewher eon that line i want to jump past that sentence. if all(x != ':' for x in line): this way i  can check but i dont want to check for every line in the

Re: Removing Space and - from a string

2008-05-21 Thread Paul Hankin
and any dashes between strings. I could do it in access manually but want to do from python script 'filter' returns a string if it's argument is a string, so works nicely here. def cleanup(s): return filter(lambda x: x not in ' -', s) -- Paul Hankin -- http://mail.python.org/mailman/listinfo

Re: Misuse of list comprehensions?

2008-05-20 Thread Paul Hankin
(seen.add(c) or c for c in s if c not in seen) I wouldn't write it this way though :) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: ?

2008-05-17 Thread Paul Hankin
This is better written using takewhile... itertools.takewhile(lambda x: x != value, iterable) But if you really need to reinvent the wheel, perhaps this is simpler? def test(iterable, value, op=operator.ne): for x in iterable: if not op(x, value): return yield x -- Paul

Re: do you fail at FizzBuzz? simple prog test

2008-05-12 Thread Paul Hankin
): print 'FizzBuzz'[4*(i%30):4+4*(i%51)] or i for i in xrange(1, 101): print 'Fizz'*(i%31)+'Buzz'*(i%51) or i -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: simple question about Python list

2008-05-09 Thread Paul Hankin
[i] for i in list2] -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Grabbing previous iteration in a dict

2008-05-09 Thread Paul Hankin
be None if we're on the first element, otherwise (previous_key, previous_value). -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: letter frequency counter / your thoughts..

2008-05-07 Thread Paul Hankin
way to write what you want. import heapq def mostfreq(message): return heapq.nlargest(3, set(message), key=message.count) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Reversing a dict?

2008-05-06 Thread Paul Hankin
in topics:    print Next,topic,course starts,info[topic] Better: for topic, when in sorted(topics.iteritems(), reverse=True): print 'Next %s course starts %s' % (topic, when) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Success stories

2008-04-22 Thread Paul Hankin
. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Can't do a multiline assignment!

2008-04-17 Thread Paul Hankin
(x.capitalize() for x in header.split('-')) setattr(self, header, value) You may want to add some error checking though! -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Integer dicision

2008-04-11 Thread Paul Hankin
implementation defined what sign r has if either a or b is negative. This means python already has C-like behaviour... it's compatible with standard C, although not with C99. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Efficient way of testing for substring being one of a set?

2008-04-03 Thread Paul Hankin
that answer is set to the empty string when no match is found. for answer in l: if str in answer: break else: answer = '' -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: frequency count or number of occurences of a number in an array

2008-03-12 Thread Paul Hankin
module. What I want to know is how to get the number of occurences of numeric element in an array. Say, Something like this should do the job: histogram = [0] * 256 for x in my_array: histogram[x] += 1 -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: rmdir problem

2008-03-11 Thread Paul Hankin
On Mar 11, 10:35 am, royG [EMAIL PROTECTED] wrote: i am checking if a directory exists and if it does i want to delete it and its contents.then i want to create the directory before creating files in it. Have a look at shutil.rmtree -- Paul Hankin -- http://mail.python.org/mailman/listinfo

Re: __iter__ yield

2008-03-10 Thread Paul Hankin
On Mar 10, 3:12 am, George Sakkis [EMAIL PROTECTED] wrote: On Mar 9, 7:37 pm, Paul Hankin [EMAIL PROTECTED] wrote: On Mar 9, 8:58 pm, duccio [EMAIL PROTECTED] wrote: Someone knows if it's possible to make this __iter__ function with just one 'yield' intead of two? ...      def

Re: __iter__ yield

2008-03-09 Thread Paul Hankin
():                  yield nn #2 Only one yield and shorter (but not really any simpler): from itertools import chain class Node: ... def __iter__(self): for x in chain([self], *self.childs): yield x -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: extract multiple ranges from a list

2008-03-08 Thread Paul Hankin
in range(0, width*height, width*2):     for j in range(0,width):         y.append(Y[i+j]) There's nothing really wrong with your code. Maybe it's a little nicer written like this: y = [] for i in range(0, height, 2): y.extend(Y[i * width + j] for j in range(width)) -- Paul Hankin -- http

Re: List as FIFO in for loop

2008-03-08 Thread Paul Hankin
()     #process x to get zero or more y's     #for each y:     q.put(y) Why not just do it like that?  With a few changes it'll work fine: while q:     x = q.pop(0)     for y in process(x):         q.append(y) Or (almost) equivalently... while q: x = q.pop(0) q.extend(process(x)) -- Paul

Re: Order of evaluation in conditionals

2008-02-25 Thread Paul Hankin
is false, its value is returned; otherwise, y is evaluated and the resulting value is returned. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Simple - looking for a way to do an element exists check..

2008-02-23 Thread Paul Hankin
(element) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Combinatorics

2008-02-13 Thread Paul Hankin
(list, args), len(args), [None] * len(args)): yield tuple(x) print list(cartesian_product('ab', 'cd', xrange(3))) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Recursive generator

2008-02-12 Thread Paul Hankin
On Feb 12, 10:17 pm, Ben C [EMAIL PROTECTED] wrote: On 2008-02-12, Paul Rubin wrote: Paul Hankin [EMAIL PROTECTED] writes: def genDescendants(self):     return chain([self], *[child.genDescendants()         for child in self.children]) That is scary.  It generates an in-memory list

Re: Recursive generator

2008-02-12 Thread Paul Hankin
() for child in self.children]) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: are elements of a list in sequence in list b

2008-02-08 Thread Paul Hankin
[EMAIL PROTECTED] wrote: I need to search list a for the sequence of list b def list_contains(a, b): return any(a[i:i+len(b)] == b for i in range(len(a) - len(b) + 1)) list_contains(range(1, 7), [2, 3, 4]) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: boolean decisions

2008-02-05 Thread Paul Hankin
as a text file or string, and parse it at program startup to build the hashtable. That way anyone can look at or modify the table, even if they know nothing about python or coding. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Elementary string-parsing

2008-02-04 Thread Paul Hankin
at http://docs.python.org/lib/module-time.html Untested: time.strptime(my_date, '%d %b %y %H:%M:%S %Z') -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Removal of element from list while traversing causes the next element to be skipped

2008-01-29 Thread Paul Hankin
for the last line would be 'apps = filter(apptitles.get, apps)' or 'apps = apptitles.keys()'. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Removal of element from list while traversing causes the next element to be skipped

2008-01-29 Thread Paul Hankin
in reversed(bad_indices): del a[bad_index] -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Which is more pythonic?

2008-01-25 Thread Paul Hankin
a much cleaner approach. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Increment Variable Name

2008-01-24 Thread Paul Hankin
not guaranteed to work. From http://docs.python.org/lib/built-in-funcs.html Warning: The contents of this dictionary should not be modified; changes may not affect the values of local variables used by the interpreter. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: difflib confusion

2008-01-22 Thread Paul Hankin
library. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Loop in a loop?

2008-01-17 Thread Paul Hankin
(*xs, **kw): pad = kw.get('padding', None) maxlen = max(len(x) for x in xs) return islice(izip(*[chain(x, repeat(pad)) for x in xs]), maxlen) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Loop in a loop?

2008-01-17 Thread Paul Hankin
On Jan 17, 7:02 pm, George Sakkis [EMAIL PROTECTED] wrote: On Jan 17, 12:25 pm, Paul Hankin [EMAIL PROTECTED] wrote: On Jan 17, 4:38 pm, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: Now there are very certainly smart solutions using itertools, but the one I cooked is way too

Re: Generic string import like in strptime?

2008-01-16 Thread Paul Hankin
','blib',0.9] Use regular expressions: see http://docs.python.org/lib/node49.html -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: ucs2 or ucs4?

2008-01-14 Thread Paul Hankin
On Jan 14, 12:56 pm, Neal Becker [EMAIL PROTECTED] wrote: How do I tell if my python-2.5 is build with ucs2 or ucs4? See if unichr(0x1) raises ValueError: if it does, you're ucs2. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Open a List of Files

2008-01-09 Thread Paul Hankin
) = [     binwriter(fn) for fn in filenames] This can be more cleanly written using locals() for fn in filenames: locals()[fn] = open(os.path.join(host_path, fname + '.txt', 'wb') -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Open a List of Files

2008-01-09 Thread Paul Hankin
On Jan 9, 10:02 am, Fredrik Lundh [EMAIL PROTECTED] wrote: Paul Hankin wrote: This can be more cleanly written using locals() for fn in filenames: locals()[fn] = open(os.path.join(host_path, fname + '.txt', 'wb') from the reference manual: locals() Update and return

Re: flatten sequences in a dictionary

2008-01-09 Thread Paul Hankin
itertools (just for a bit of fun). I'm trying this: list(itertools.chain(testDict.itervalues()) Close! Try: list(itertools.chain(*testDict.itervalues()) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Learning Python via a little word frequency program

2008-01-09 Thread Paul Hankin
=True): ... -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: how to use bool

2008-01-06 Thread Paul Hankin
(): return (False, sthingelse failed) domoreprocessing() ... return (True, all validation OK) Isn't that a lot more readable? -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Basic inheritance question

2008-01-05 Thread Paul Hankin
-- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: fastest method to choose a random element

2008-01-05 Thread Paul Hankin
] return x # Nothing in the list passes the 'prop' test. return None # Example: pick 100 odd integers from 0 to 1000. a = RandomPicker(xrange(1000), lambda x: x % 2 == 1) print [a.pick() for i in xrange(100)] -- Paul Hankin -- http://mail.python.org/mailman/listinfo

Re: fastest method to choose a random element

2008-01-05 Thread Paul Hankin
] x[r] = x[n - i - 1] def shuffled(seq): Generate the elements of seq in a random order return (seq[i] for i in randxrange(len(seq))) def pick_random(seq, prop): return itertools.ifilter(prop, shuffled(seq)).next() -- Paul Hankin -- http://mail.python.org/mailman/listinfo

Re: fastest method to choose a random element

2008-01-05 Thread Paul Hankin
If it were uniform, it should be around 111. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: fastest method to choose a random element

2008-01-05 Thread Paul Hankin
] random.shuffle(seq) return itertools.ifilter(prop, seq).next() I've used 5 'stabs' here. Perhaps it should be a function of L, but I suppose you can tune it for your data. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: fastest method to choose a random element

2008-01-05 Thread Paul Hankin
On Jan 5, 5:12 pm, Paul Hankin [EMAIL PROTECTED] wrote: On Jan 5, 4:14 pm, [EMAIL PROTECTED] wrote: On Jan 5, 5:07 pm, [EMAIL PROTECTED] wrote: Hello, Paul and Arnaud. While I think about your answers: do you think there is any way to avoid shuffle? It may take unnecessary long

Re: Treating a unicode string as latin-1

2008-01-03 Thread Paul Hankin
On Jan 3, 1:31 pm, Simon Willison [EMAIL PROTECTED] wrote: How can I tell Python I know this says it's a unicode string, but I need you to treat it like a bytestring? u'Bob\x92s Breakfast'.encode('latin-1') -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Fate of itertools.dropwhile() and itertools.takewhile()

2007-12-30 Thread Paul Hankin
... I use itertools regularly (and have a functional background), but have never needed takewhile or dropwhile. I'd be happy to see them deprecated. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: getting n items at a time from a generator

2007-12-27 Thread Paul Hankin
'. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Taxicab Numbers

2007-12-27 Thread Paul Hankin
in range(c + 1, n + 1) if cube(a) + cube(b) == cube(c) + cube(d)] for n in (10, 12, 20): print list(taxicab(n)) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: OMG please help

2007-12-26 Thread Paul Hankin
On Dec 26, 1:09 am, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Mon, 24 Dec 2007 17:14:58 +0100, Martin P. Hellwig wrote: As Dennis already pointed out I like to use dictionaries in these cases, so I would use sand = dict() instead of sands = list() and would do sand[i] =

Re: Writing Oracle Output to a File

2007-12-26 Thread Paul Hankin
you avoid trouble when your data contains commas or control characters such as newlines. import csv help(csv) Suggests this code: import csv csv_file = open('output.csv', 'w') csv_writer = csv.writer(csvFile) csv_writer.writerows(cursor.fetchall()) csv_file.close() -- Paul Hankin -- http

Re: Hexadecimal list conversion

2007-12-20 Thread Paul Hankin
)? If so, use codecs.open to read it, and you won't get the \x00's (you'll get a unicode string). Or you can remove them using replace: a = a.replace('\x00', '') HTH -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: A bug in Python's regular expression engine?

2007-11-27 Thread Paul Hankin
), and then any number of characters. If you're using this for path splitting filenames under Windows, you should look at os.path.split instead of writing your own. HTH -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: better way to write this function

2007-11-26 Thread Paul Hankin
divide_list(lst, n): return zip(*[lst[i::n] for i in range(n)]) [It produces a list of tuples rather than a list of lists, but it usually won't matter]. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: simple question on persisting variable values in a list

2007-11-20 Thread Paul Hankin
) templine = '' else: templine += char No need for all that code, because you're reimplementing the 'split' method of strings: x = 'blah\nblah\n' lst = x.split('\n')[:-1] -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Moving from java to python.

2007-11-12 Thread Paul Hankin
, self.weights) The 'uid' business makes me suspicious: what's it for? If you need it, you probably need to initialise with an explicit test for None rather than just 'if uid' which will be wrong if you use a uid of 0... self.id = uid if uid is not None else id(self) HTH -- Paul Hankin -- http

Re: Avoid newline at the end

2007-11-11 Thread Paul Hankin
in ('access.log', 'error.log'): logs += ['/home/%s/%s/log/%s' % (row[1], row[0], name)] logs = '\n'.join(logs) Or equivalently using a list comprehension... logs = '\n'.join('/home/%s/%s/log/%s' % (row[1], row[0], name) for row in resultSet for name in ('access.log', 'error.log')) -- Paul

Re: Closure/binding problem or misunderstanding

2007-11-09 Thread Paul Hankin
(): def getpath(path=path): return path setattr(self, name, getpath) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Need help writing coroutine

2007-11-07 Thread Paul Hankin
coroutines? def parser(score): for i in xrange(1, 6): yield i if score(i): print %d passed! % i def is_odd(n): return n % 2 def m(): for i in parser(is_odd): # Presumably do something here... pass -- Paul Hankin -- http://mail.python.org/mailman

Re: Trouble with for loop

2007-11-06 Thread Paul Hankin
): Or all the same? for a in range(1, 10): b = c = d = e = f = a Whatever you're doing though, there's almost certainly a better way. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: List to Tuple and Tuple to List?

2007-11-06 Thread Paul Hankin
list2tuple(source): return transform(source, list, tuple) def tuple2list(source): return transform(source, tuple, list) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Trouble with for loop

2007-11-06 Thread Paul Hankin
like this is probably what you want... for n in range(10 ** 5, 10 ** 6): digits = map(int, str(n)) ... test digits -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: regular expressions

2007-11-06 Thread Paul Hankin
come up with so far? Have you looked at the 're' module? -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: problem with iteration

2007-11-03 Thread Paul Hankin
is created (with a re.match call) to see why your expectation differs from what happened. Perhaps you could add more print statements to the loops to see what values 'files' and 'name' take. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: python newbie

2007-11-03 Thread Paul Hankin
, thanks, I'll have to file that one away, and use it now and then. I'm intrigued - when would you want a callable module? -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Sub-sort after sort

2007-11-02 Thread Paul Hankin
Smith', 'location': 'CA',},{'name': 'John Smith', 'location': 'AZ',},] I would want to sort by name first, then sub sort by location. Any ideas? Thanks! test.sort(key=lambda x:(x['name'], x['location'])) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: help on dictionary

2007-11-01 Thread Paul Hankin
(words, key=lambda word: model.get(word, 1)) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: 3 number and dot..

2007-10-31 Thread Paul Hankin
-mindedly... def conv(x, sep='.'): x, y = str(x), [] while x: y.append(x[-3:]) x = x[:-3] return sep.join(reversed(y)) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Method needed for skipping lines

2007-10-31 Thread Paul Hankin
(filename, 'r'))) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: a few questions.

2007-10-31 Thread Paul Hankin
% (i + 1, '*' * hundreds) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

  1   2   >