Re: better way to write this function

2007-11-26 Thread Paul Hankin
for j in range(n): > rv[i][j] = lst[i * n + j] > return rv > > Thanks! Here's a terrible way to do it: def 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: A bug in Python's regular expression engine?

2007-11-27 Thread Paul Hankin
ug). Perhaps you meant this? regex = re.compile(r'(.*\\).*') This matches any number of characters followed by a backslash (group 1), 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: Hexadecimal list conversion

2007-12-20 Thread Paul Hankin
worked. Can anybody give any tips to help? Is your file utf-16 (that would explain why your file has \x00 in between every character)? 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: 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 > > s

Re: Writing Oracle Output to a File

2007-12-26 Thread Paul Hankin
tchall(): >     csvFile.write(','.join(row) + "\n") > csvFile.close As usual, the python standard library has functions that do what you want! Using the csv module will help 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://mail.python.org/mailman/listinfo/python-list

Re: getting n items at a time from a generator

2007-12-27 Thread Paul Hankin
ator rather than building a list which is probably only going to be iterated over. But if you prefer the list version, replace 'itertools.imap' with 'map'. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Taxicab Numbers

2007-12-27 Thread Paul Hankin
r-word. def cube(x): return x * x * x def taxicab(n): return [(cube(a) + cube(b), (a, b), (c, d)) for a in range(1, n + 1) for b in range(a + 1, n + 1) for c in range(a + 1, n + 1) for d 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: Fate of itertools.dropwhile() and itertools.takewhile()

2007-12-30 Thread Paul Hankin
ay it was quite readable if you're familiar with groupby. And back on topic... 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: 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: Basic inheritance question

2008-01-05 Thread Paul Hankin
t self.stopLoc = stop -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: fastest method to choose a random element

2008-01-05 Thread Paul Hankin
n = random.randint(0, len(r) - 1) r[0], r[n] = r[n], r[0] 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

Re: fastest method to choose a random element

2008-01-05 Thread Paul Hankin
xrange(n): r = random.randrange(n - i) yield x[r] 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

Re: fastest method to choose a random element

2008-01-05 Thread Paul Hankin
perty. print [random_pick(range(100), lambda x:x > 90) for i in range(999)].count(91) 929 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
stabs): r = random.randrange(L) if prop(seq[r]): return seq[r] 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

Re: how to use bool

2008-01-06 Thread Paul Hankin
ere things are used (eg. seeing where "all validation OK" is used requires you to read every line of your method). def mymethod(self): if not validateSthing(): return (False, "sthing failed") dosomeprocessing() if not validateSthingelse(): 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: Open a List of Files

2008-01-09 Thread Paul Hankin
s.path.join(host_path, '%s.txt' % fn), 'wb') >     for fn in filenames >     ] > > It becomes even more clear if you make an intermediate "opener" > function such as > >   binwriter = lambda fname: open( >       os.path.join(host_path, '%s.txt' % fname), 'wb') > >   (messages, deliveries, actions, parts, >     recipients, viruses, esp_scores) = [ >     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

Re: flatten sequences in a dictionary

2008-01-09 Thread Paul Hankin
a list of the the 3 element tuples using > 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
in deco: ... or for v, k in sorted(deco, reverse=True): ... -- 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: Generic string import like in strptime?

2008-01-16 Thread Paul Hankin
t; b = '%d\t%s-%s.%f' > >>> c = mysticalfunction(a,b) > >>> print c > > [3456,'blub','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: Loop in a loop?

2008-01-17 Thread Paul Hankin
, **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 > > [EMAIL PROTECTED]> wrote: > > > Now there are very certainly smart solut

Re: difflib confusion

2008-01-22 Thread Paul Hankin
nge. > any ideas please? Have a look at difflib in the standard library. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Increment Variable Name

2008-01-24 Thread Paul Hankin
> Do you want to do this?: > locals()['var'+str(1)] = "spam" As I recently learnt in this newsgroup, that's 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

Re: Which is more pythonic?

2008-01-25 Thread Paul Hankin
al post, and it's also a much cleaner approach. -- 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
] = getattr(app, 'TITLE', name.title()) except ImportError: pass # Remove apps with no title, ie those that didn't import. apps = [name for name in apps if apptitles.get(name)] Alternatives 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
.. but how often do you really need to do that? If I really had to modify it in place (and the condition wasn't really x == 99), how about: bad_indices = [i for i, x in enumerate(a) if x == 99] for bad_index in reversed(bad_indices): del a[bad_index] -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Elementary string-parsing

2008-02-04 Thread Paul Hankin
ime will do this! You can find the documentation 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: boolean decisions

2008-02-05 Thread Paul Hankin
that business logic EVER changes ;). I'd be tempted to include the business rule table 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: 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: 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() > >>    

Re: Recursive generator

2008-02-12 Thread Paul Hankin
def genDescendants(self): return chain([self], *[child.genDescendants() for child in self.children]) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Combinatorics

2008-02-13 Thread Paul Hankin
sian_product(*args): "Generate the cartesian product of the sequences passed in." for x in cart_lists(map(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: Simple - looking for a way to do an element exists check..

2008-02-23 Thread Paul Hankin
ing containment in a generator is better (more readable). if element[0] not in (x[0] for x in a): a.append(element) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Order of evaluation in conditionals

2008-02-25 Thread Paul Hankin
and y' first evaluates x; if x 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: extract multiple ranges from a list

2008-03-08 Thread Paul Hankin
fashion shown below > > y = [] > for i 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

Re: List as FIFO in for loop

2008-03-08 Thread Paul Hankin
    for y in process(x): >         q.append(y) Or (almost) equivalently... while q: x = q.pop(0) q.extend(process(x)) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: __iter__ yield

2008-03-09 Thread Paul Hankin
ds: >              for nn in n.__iter__(): >                  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: __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

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.pyt

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

2008-03-12 Thread Paul Hankin
gt; bit already from reading numpy 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: improve this newbie code/nested functions in Python?

2009-03-21 Thread Paul Hankin
; and set _KeepGoing. receive_message can extract the interesting bit from the socket read. Hope you get the idea. This way, you don't use the inner workings of client in the Listener and Speaker classes, and don't violate 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/listinfo/python-list

Re: The Python standard library and PEP8

2009-04-19 Thread Paul Hankin
On Apr 19, 7:37 pm, "Gabriel Genellina" 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 -- h

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

2009-05-03 Thread Paul Hankin
es to download the file? Now let's > say during those 15 minutes, the program needs to parse the data in > the existing 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: do you fail at FizzBuzz? simple prog test

2008-05-12 Thread Paul Hankin
27;) or i > > (or perhaps > > print (('' if i%3 else 'Fizz') + ('' if i%5 else 'Buzz')) or i > > to save looking up the precedence rules) ? > > Stuff clarity! How about > > for i in xrange(1, 101): > print 'FizzBuzz'[4*(i%3>0):4+4*(i%5<1)] or i for i in xrange(1, 101): print 'Fizz'*(i%3<1)+'Buzz'*(i%5<1) or i -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: ?

2008-05-17 Thread Paul Hankin
def test(iterable, value, op=operator.ne): for x in iterable: if not op(x, value): return yield x -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Misuse of list comprehensions?

2008-05-20 Thread Paul Hankin
n = set() return ''.join(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: iterate start at second row in file not first

2008-05-20 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

Re: Removing Space and "-" from a string

2008-05-20 Thread Paul Hankin
x27;858215558' > > I want to remove any spaces between string 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): retur

Re: Producing multiple items in a list comprehension

2008-05-23 Thread Paul Hankin
* i for x in xrange(4) for i in xrange(1, 3)] -- 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
line 7, in __init__ >     self.args = args > TypeError: 'NoneType' object is not iterable > > Ummm... why 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: 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: Do this as a list comprehension?

2008-06-07 Thread Paul Hankin
len(score_costs) score_costs = zip(base_scores, 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
perties of your class like this: class MyClass(object): ... add this at the end of your class definition ... def _getu(self): return self.y[1] 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: Alternative to Decimal type

2008-06-09 Thread Paul Hankin
l is complicated: it has some advanced features, but for what you seem to be doing it should be easy to replace your 'Number' with it. In fact, it makes things simpler since you don't have to worry about 'scale'. Your examples convert easily: from decimal import Decim

Re: PEP on breaking outer loops with StopIteration

2008-06-09 Thread Paul Hankin
x27; and number == 5: >                 raise letters.StopIteration() Have you checked out 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 bett

Re: Notify of change to list

2008-06-12 Thread Paul Hankin
st([1, 2, 3]) >>> x[1] = 4 setting 1 to 4 >>> x [1, 4, 3] If users of your 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: newbie question: for loop within for loop confusion

2008-06-15 Thread Paul Hankin
riginal code, but the 'else' is attached to the 'for' rather that the 'if'! Finally, in Python 2.5 you can write this: if not any(letter in word for letter in avoid): print word I think this is the best solution, as it's readable and short. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: listcomprehension, add elements?

2008-06-22 Thread Paul Hankin
ing it, what is the more pythonic > way of doing this? Use 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: The Yield statement

2008-07-07 Thread Paul Hankin
h more cleanly... def partitions(n, length): """Generate all sequences of positive numbers of the given length that sum to n.""" assert 0 < length <= n 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: formatting list -> comma separated

2008-07-09 Thread Paul Hankin
s"*(len(d)-1)) % tuple(d) > > but this fails for d = [] > > any (pythonic) options for this? print ', '.join(d) -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

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

2008-07-09 Thread Paul Hankin
count += 1 yield '\n' yield '\n' yield '\n***\n' You can make the string using ''.join: dmntString = ''.join(dmntGenerator()) 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: python scalability

2008-07-11 Thread Paul Hankin
familiar with it, rather than because of scalability problems? Perhaps using python 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: Functional/Best?

2008-07-13 Thread Paul Hankin
: >       A nice variant of this, which minimizes repetition, is to group all the factory methods together into a class, naming them the same as the keyword... class Builder(object): def SECTION(self): ... def COMPOSITION(self): ... def OBSERVATION(self): ... 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: Remove some characters from a string

2008-07-17 Thread Paul Hankin
; > >>> magic_function('[EMAIL PROTECTED]') > > str: '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 + '_'): re

Re: Is this possible ....

2008-07-23 Thread Paul Hankin
gt;   return ( version_text [0] [0] ) > > But is there a way to avoid the placing of this function "version" in > each module, > and still use a simple call like: >   .version() You could use version() instead of module.version(), and just declare 'version' in one place. Presumably 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: Searching for some kind of data type

2008-08-02 Thread Paul Hankin
ptions] perm, auth, arg, path = options assert perm is None or perm in 'ae...' assert auth is None or auth == 'A' assert arg is None or arg == 'R' assert path is None or path == 'P' ftp_commands[cmd] = CommandProperty(perm=perm, auth_required=auth, arg_required=arg, check_path=path, syntax = '%s %s' % (cmd, help)) -- 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
ime.html -- says that '%X' is the locale's appropriate time representation, so obviously gtk is adjusting your locale. Perhaps use a formatting string that doesn't depend on the locale: '%H:%M:%S' instead of '%X' seems to give your preferred format. -- 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 w

Re: regular expression extracting groups

2008-08-10 Thread Paul Hankin
t to debug. Your code 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: Efficient way of testing for substring being one of a set?

2008-04-03 Thread Paul Hankin
n the first one is found. Using 'in' rather than testing the return value of find is nicer as a substring test. Finally, using the 'else' clause lets you make it clear 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: Integer dicision

2008-04-11 Thread Paul Hankin
, -2) # (-5, -1) Both C and Python define q = a / b and r = a % b to satisfy a = q * b + r, where -abs(b) < r < abs(b). Where they differ: Python: r has the same sign of b (or 0). C99: r has the same sign as a (or 0). C89 (Standard C): It's 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: Can't do a multiline assignment!

2008-04-17 Thread Paul Hankin
header = '_'.join(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: Python Success stories

2008-04-22 Thread Paul Hankin
seful update-in-place behaviour when the left-hand- side of the += expression is a list. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: Reversing a dict?

2008-05-06 Thread Paul Hankin
t;, >        "Perl":"15th June", >        "Java":"7th June", >        "Python":"26th May", >        "Tcl":"12th July", >        "MySQL":"24th May"} > > topics = info.keys() > topics

Re: letter frequency counter / your thoughts..

2008-05-07 Thread Paul Hankin
, but here's a compact 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: simple question about Python list

2008-05-09 Thread Paul Hankin
rm list3 that contains > elements from list1 with indexes from list2, i.e. list3 = [list1[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
use it... for previous, (key, value) in iterprevious(d.iteritems()): ... In the loop, previous will either 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: Good python equivalent to C goto

2008-08-17 Thread Paul Hankin
stmt2 stmt3 stmt4 This is probably the right way to write it in C too. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list

Re: improving a huge double-for cycle

2008-09-18 Thread Paul Hankin
== IN[j].coordinates[0] and > if IN[i].coordinates[1] == IN[j].coordinates[1]: A simple O(N) algorithm: from collections import defaultdict d = defaultdict(int) 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
label) Using only a little extra storage to compute IN (but O(N log N) time complexity): import itertools 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: huh??? weird problem

2010-05-16 Thread Paul Hankin
x27;Warning!'? That's odd... :o Crazy, what am i not seeing? :( > > we're not seeing all the relevant code.  While I can ignore the missing > import, I don't see any creation of the variables WarnTimeout and > CritTimeout.  Simplest explanation that fits your sample run is that > they are not of type float. Yes, 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

<    1   2