Re: Happy Christmas Pythoneers

2007-12-28 Thread Marc 'BlackJack7; Rintsch
and connected with the caller's history of `champagne.drink()` calls. The `person.is_pretty` property is most definitely linked to that call history in many instances. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Passing by reference

2007-12-23 Thread Marc 'BlackJack7; Rintsch
e other program will say: > tok = Toker( text_array ) > tokens = tok.tokenize() > > So how does the constructor make the array of strings available to the > tokenize() method? Assuming the `__init__()` above belongs to the `Toker` class then the `tokenize()` method can access it via `self.text`

Re: checking for negative values in a list

2007-12-17 Thread Marc 'BlackJack7; Rintsch
On Mon, 17 Dec 2007 06:20:23 -0800, vimal wrote: >i have a list of numbers > > say a = [1,-1,3,-2,4,-6] > > how should i check for negative values in the list In [6]: a = [1, -1, 3, -2, 4, -6] In [7]: any(n < 0 for n in a) Out[7]: True Ciao, Marc 'Blac

Re: Is Python really a scripting language?

2007-12-15 Thread Marc &#x27;BlackJack7; Rintsch
arBasic for the conversion. Full story: http://www.xml.com/pub/a/2006/01/11/from-microsoft-to-openoffice.html Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Compressing a text file using count of continous characters

2007-12-14 Thread Marc &#x27;BlackJack7; Rintsch
implement it. :-) `itertools.groupby()` might be handy. And you have to think about digits in the source if that's allowed. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: RegExp Help

2007-12-14 Thread Marc &#x27;BlackJack7; Rintsch
tarting to parse XML with regular expressions you are making the very same mistake. XML may look somewhat simple but producing correct XML and parsing it isn't. Sooner or later you stumble across something that breaks producing or parsing the "naive" way. Ciao, Marc &#x

Re: Dynamic or not?

2007-12-13 Thread Marc &#x27;BlackJack7; Rintsch
= [do_something(item) for item in old] Or: new = map(do_something, old) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: determining bytes read from a file.

2007-12-13 Thread Marc &#x27;BlackJack7; Rintsch
rst > '\0' are counted. If you want to deal with bytes better open the file in binary mode. Windows alters line endings and stops at a specific byte (forgot the value) otherwise. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Is anyone happy with csv module?

2007-12-12 Thread Marc &#x27;BlackJack7; Rintsch
On Tue, 11 Dec 2007 20:08:21 -0300, Gabriel Genellina wrote: > data = [row for row in csv.reader(..)] A bit shorter:: data = list(csv.reader(..)) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Text widget updates only after calling method exits (threading issue?)

2007-12-12 Thread Marc &#x27;BlackJack7; Rintsch
On Tue, 11 Dec 2007 17:58:37 -0800, mariox19 wrote: > If I am supposed to send messages to Tkinter objects only from the > main thread, how can I get the letters to appear 1 per second? Take a look at the `after()` method on widgets. Ciao, Marc 'BlackJack'

Re: dictionary of dictionaries

2007-12-11 Thread Marc &#x27;BlackJack7; Rintsch
ful than the real default. What is the > reasoning behind NOT using this as the default implementation for a > dict in python? How's that more useful in the general case? Maybe if you come from a language where some default value pops up if the key is not present you are used to write code in a way that exploits this fact. But in the general case!? I need `defaultdict` not very often but want to know if a key is not present in a dictionary. Because most of the time that's a special condition or error that has to be handled or signaled up the call chain. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Dumb newbie back in shell

2007-12-10 Thread Marc &#x27;BlackJack7; Rintsch
s no effect. IMHO that should emit at least a warning… Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Best way to protect my new commercial software.

2007-12-10 Thread Marc &#x27;BlackJack7; Rintsch
ke it as ugly and unusable as you can. Spend the time you planned for writing documentation for this task. ;-) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Distinguishing attributes and methods

2007-12-09 Thread Marc &#x27;BlackJack7; Rintsch
In [469]: a = collections.defaultdict(int) In [470]: callable(a.default_factory) Out[470]: True In [471]: a.default_factory(42) Out[471]: 42 `a.default_factory` is callable but hardly a method of `a` or `defaultdict` but a "data attribute" that happens to be callable. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: dictionary of dictionaries

2007-12-09 Thread Marc &#x27;BlackJack7; Rintsch
; dictionary with a tuple of both as keys: data = dict(((i, j), randint(0, 10)) for i in xrange(11) for j in xrange(11)) And just for completeness: The given data in the example can be stored in a list of lists of course: data = [[randint(0, 10) for dummy in xrange(11)] for dummy in xrange(11)]

Re: auto-increment operator - why no syntax error?

2007-12-08 Thread Marc &#x27;BlackJack7; Rintsch
>>>> n += 1 >>>> n > 2 >>>> ++n > 2 There is no syntax error. It is just some unary pluses "chained". Maybe unexpected but no syntax error. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Distinguishing attributes and methods

2007-12-08 Thread Marc &#x27;BlackJack7; Rintsch
object bindings and methods are objects. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Distinguishing attributes and methods

2007-12-08 Thread Marc &#x27;BlackJack7; Rintsch
On Sat, 08 Dec 2007 00:34:06 -0800, MonkeeSage wrote: > I think he means callable attributes (methods) and non-callable > attributes (variables). But not every callable attribute is a method. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Calculate an age

2007-12-08 Thread Marc &#x27;BlackJack7; Rintsch
er it's easy but providing functions in the standard library for arbitrary date calculation involving years is not so easy. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Distinguishing attributes and methods

2007-12-08 Thread Marc &#x27;BlackJack7; Rintsch
he decision is easy -- everything on an object is an attribute. ;-) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: File to dict

2007-12-07 Thread Marc &#x27;BlackJack7; Rintsch
turn item... > > Yuck. I guess Duncan's point wasn't the construction of the dictionary but the throw it away part. If you don't keep it, the loop above is even more efficient than building a dictionary with *all* lines of the file, just to pick one value afterwards. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Tkinter Newbie Question

2007-12-06 Thread Marc &#x27;BlackJack7; Rintsch
re's an alternative way with the `functools.partial()` function: from functools import partial # ... msg = Button(win, text='Write Something', command=partial(salutation, tree)) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: "Python" is not a good name, should rename to "Athon"

2007-12-04 Thread Marc &#x27;BlackJack7; Rintsch
! >> >>Wasn't Ra the Sun god? >> > > He meant quetzatcoatl. We could rename the language. That name is already taken in the programming language domain. There's a Tiny C compiler for 6510 based targets: http://www.kdef.com/geek/vic/quetz.html Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Oh no, my code is being published ... help!

2007-11-30 Thread Marc &#x27;BlackJack7; Rintsch
e time. If the function looking style would be adopted for 2.x, do *you* want to explain confused newbies why they can write:: print('hello!') but this acts "strange": print('hello, my name is ', name) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: How to Split a String

2007-11-30 Thread Marc &#x27;BlackJack7; Rintsch
plit function, but this mini-monster wouldn't properly get > split up due to those random quotations postgresql returns to me. I hope you don't use Python to access the database, get a tuple back, convert it to a string and then try to break up that string into a list!? Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are class methods not classmethods?

2007-11-27 Thread Marc &#x27;BlackJack7; Rintsch
Out[83]: > In [84]: type(Parrot.cmethod) Out[84]: In [85]: Parrot.__dict__['cmethod'] Out[85]: In [86]: type(Parrot.__dict__['cmethod']) Out[86]: Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: How to display unicode with the CGI module?

2007-11-24 Thread Marc &#x27;BlackJack7; Rintsch
rings. If you don't do this explicitly Python tries to encode as ASCII and fails if there's anything non-ASCII in the string. The `encode()` method is your friend. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: the annoying, verbose self

2007-11-24 Thread Marc &#x27;BlackJack7; Rintsch
On Sat, 24 Nov 2007 08:27:56 -0800, samwyse wrote: > On Nov 24, 7:50 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> On Sat, 24 Nov 2007 02:54:27 -0800, samwyse wrote: >> > On Nov 24, 4:07 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]&g

Re: the annoying, verbose self

2007-11-24 Thread Marc &#x27;BlackJack7; Rintsch
On Sat, 24 Nov 2007 14:09:04 +0100, Ton van Vliet wrote: > On 24 Nov 2007 08:48:30 GMT, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> > wrote: > >>On Sat, 24 Nov 2007 09:12:34 +0100, Ton van Vliet wrote: >> >>> Just bringing up something I sometimes m

Re: the annoying, verbose self

2007-11-24 Thread Marc &#x27;BlackJack7; Rintsch
On Sat, 24 Nov 2007 02:54:27 -0800, samwyse wrote: > On Nov 24, 4:07 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> On Sat, 24 Nov 2007 01:55:38 -0800, samwyse wrote: >> > I've had the same thought, along with another. You see, on of my pet

Re: How can I create customized classes that have similar properties as 'str'?

2007-11-24 Thread Marc &#x27;BlackJack7; Rintsch
erhaps there is a Python > Elder here that knows? AFAIK strings of length 1 and strings that would be valid Python identifiers are treated this way. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: the annoying, verbose self

2007-11-24 Thread Marc &#x27;BlackJack7; Rintsch
> dog = 'rover' > def example(): > global cat, dog # not always required, but frequently needed > return ', '.join((cat, dog)) Ouch that's bad design IMHO. The need to use ``global`` is a design smell, if needed *frequently* it starts to stink. Ciao, M

Re: the annoying, verbose self

2007-11-24 Thread Marc &#x27;BlackJack7; Rintsch
a record definition to make that decision. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: the annoying, verbose self

2007-11-23 Thread Marc &#x27;BlackJack7; Rintsch
> expands to > > def abs(self): > x, y, z = self.__unpack__("x","y","z") > return math.sqrt(x**2 + y**2 + z**2) What about ``from`` instead of ``by``? That's already a keyword so we don't have to add a new one. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I convert escaped HTML into a string?

2007-11-23 Thread Marc &#x27;BlackJack7; Rintsch
ook like if whitespace is preserved. What matters is the actual text in the source, not the formatting. That's left to the browser. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: foldr function in Python

2007-11-23 Thread Marc &#x27;BlackJack7; Rintsch
ic" way to define `comma_separate()` is:: comma_separate = ','.join Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: why it is invalid syntax?

2007-11-21 Thread Marc &#x27;BlackJack7; Rintsch
which ``if`` does the ``else`` belong to here? :: if 1: print 1 if: 1 print 1 else: print 1 Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: pydoc - how to generate documentation for an entire package?

2007-11-19 Thread Marc &#x27;BlackJack7; Rintsch
On Mon, 19 Nov 2007 10:50:28 -0800, Jens wrote: > Generating documentation form code is a nice thing, but this pydoc.py > is driving me insane - isn't there are better way? Epydoc!? Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Tkinter Problem?

2007-11-19 Thread Marc &#x27;BlackJack7; Rintsch
UpKey(self,event): > self.canv.move(tagOrId,xAmount=0,yAmount=10) Where's `tagOrId` coming from? That's a `NameError` here. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: How to add a Decorator to a Class Method

2007-11-19 Thread Marc &#x27;BlackJack7; Rintsch
rgs) return new_func class A(object): @pre def func(self, a, b): print a + b a = A() a.func(3, 5) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding lowest value in dictionary of objects, how?

2007-11-19 Thread Marc &#x27;BlackJack7; Rintsch
gt; > This one returns the lowest value Object, but not the lowest value of > age in all the Objects of the table. In the example `min()` finds the object with the lowest `id()`. To change that you can implement the `__cmp__()` method on your `Block` objects. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: list of class initiations ?

2007-11-16 Thread Marc &#x27;BlackJack7; Rintsch
o build something with those functions. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Using Python To Change The World :)

2007-11-14 Thread Marc &#x27;BlackJack7; Rintsch
gt; Of course if you want to have more or less realistic imaging for whatever > purpose, 3D is the way to go. If you are after traffic-simulations, it's > unneeded complexity. Not if their solution includes flying buses and taxis. Or this pneumatic delivery system for people from `Fut

Re: referencing a subhash for generalized ngram counting

2007-11-13 Thread Marc &#x27;BlackJack7; Rintsch
ct. Changing the dictionary bound to `h` changes it:: h = orig['ca'] h['adanac'] = 69 > Yet since names are not exactly references, something else is needed > for generalized ngram multi-level counting hash -- what? Names *are* implemented as references to objects, but binding the name to a different object has no effect on the object bound to that name before. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: reading file objects in chunks

2007-11-12 Thread Marc &#x27;BlackJack7; Rintsch
f.read(chunksize) > > I just don't feel comfortable with it for some reason I can't explain... chunksize = 26 f = open('datafile.dat', 'rb') for chunk in iter(lambda: f.read(chunksize), ''): compute_data(chunk) f.close() Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: regex that is equivalent to perl's syntax

2007-11-12 Thread Marc &#x27;BlackJack7; Rintsch
#x27;s > equivalent to the following perl's search string? > m/^\S{1,8}\.\S{0,3}/ It is ``re.match(r'\S{1,8}\.\S{0,3}', string)``. There's something called "documentation"… Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Using python as primary language

2007-11-12 Thread Marc &#x27;BlackJack7; Rintsch
tion between processes. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: how to know if folder contents have changed

2007-11-11 Thread Marc &#x27;BlackJack7; Rintsch
erations to easily find out the differences between two set of names and the `pickle` module to store Python objects in files. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Populating a dictionary, fast

2007-11-11 Thread Marc &#x27;BlackJack7; Rintsch
{} > for line in open('keys.txt'): > v[long(line.strip())] = True Takes about 40 seconds here. [EMAIL PROTECTED]:~$ time python test.py real 0m38.758s user0m25.290s sys 0m1.580s Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Global variables within classes.

2007-11-10 Thread Marc &#x27;BlackJack7; Rintsch
On Sat, 10 Nov 2007 17:39:04 +, Marc 'BlackJack' Rintsch wrote: > On Sat, 10 Nov 2007 18:53:08 +0200, Donn Ingle wrote: >>>> print b.ref.attribute # print "haschanged" >>>> >>>> print j.ref.attribute #prints "original

Re: Coding Help

2007-11-10 Thread Marc &#x27;BlackJack7; Rintsch
] ││ >│ │ [S2] [S3] └┬┘│ >│ │││┌─< C4 >─┐│ >│ │││ [S4] ││ >│ │││└───┬┘│ >│ └───┬┴┴┘ │ >│ [S5] │ >│ └───

Re: Global variables within classes.

2007-11-10 Thread Marc &#x27;BlackJack7; Rintsch
his is kind of weird. It's not clear like Python usually is. Is this > something intentional or did it 'fall through the cracks'? I mean, can one > rely on it or will it be 'fixed'? Don't think so. It's a surprise for many but then class attributes are not that common in code or they even use this "gotcha" for immutable default values. As long a the value isn't changed the default value is just referenced from the class then and not every instance. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: String/Decimal issues

2007-11-10 Thread Marc &#x27;BlackJack7; Rintsch
mbers that you are adding and not strings or something!? Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Global variables within classes.

2007-11-10 Thread Marc &#x27;BlackJack7; Rintsch
nd setBlah for every little thing? Good $GOD no! He's talking about the `__get__` method on properties. Read the docs for the built in `property()` function. It's a nice mechanism to actually avoid all those getters and setters because you can turn "simple" attributes into "computed" attributes without changing the API of the objects. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Some "pythonic" suggestions for Python

2007-11-09 Thread Marc &#x27;BlackJack7; Rintsch
on names in tracebacks? What about nesting these anonymous multiline functions? What about the impact on the grammar? Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: [OT] Stupid email disclaimers

2007-11-09 Thread Marc &#x27;BlackJack7; Rintsch
der ? And if so, how could > I *then* notify her ?-) Ask a medium? Use a crystal ball for the very long distance call? Call Dr. Frankenstein for help? =:o) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: parallel csv-file processing

2007-11-09 Thread Marc &#x27;BlackJack7; Rintsch
On Fri, 09 Nov 2007 02:51:10 -0800, Michel Albert wrote: > Obviously this won't work as you cannot access a slice of a csv-file. > Would it be possible to subclass the csv.reader class in a way that > you can somewhat efficiently access a slice? An arbitrary slice? I guess not as all records bef

Re: operator overloading on built-ins

2007-11-08 Thread Marc &#x27;BlackJack7; Rintsch
On Thu, 08 Nov 2007 22:53:16 -0800, r.grimm wrote: >>>> (1).__cmp__(10) > -1 As the dot is an operator like ``+`` or ``/`` you can also add spaces to avoid the ambiguity: In [493]: 1 . __cmp__(10) Out[493]: -1 In [494]: 1 .__cmp__(10) Out[494]: -1 Ciao, Marc 

Re: os.popen does not seem to catch stdout

2007-11-07 Thread Marc &#x27;BlackJack7; Rintsch
On Wed, 07 Nov 2007 18:35:51 +, kyosohma wrote: > I've never had to put the command into a list or tuple...but you're > welcome to try it that way. You don't *have* to but if you do the module takes care of quoting the arguments if necessary. Ciao, Marc 'B

Re: Deep comparison of sets?

2007-11-07 Thread Marc &#x27;BlackJack7; Rintsch
return cmp(self.value, other.value) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Insane crazy question - printing commands

2007-11-06 Thread Marc &#x27;BlackJack7; Rintsch
in a module named `inspect.py` that is definitely not the one from the standard libarary. If that module has an ``import inspect`` it imports *itself*! Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: how to filter files by creation date

2007-11-06 Thread Marc &#x27;BlackJack7; Rintsch
; > Could you explain a little more because I am new in scripting? >> >> Not really. I showed you the call I made and the result I got. How can I >> be more clear and precise!? > > Ok but I run in Windows and I cannot understand your '!touch test.py' Ah, sorry t

Re: how to filter files by creation date

2007-11-06 Thread Marc &#x27;BlackJack7; Rintsch
On Tue, 06 Nov 2007 01:45:02 -0800, awel wrote: > On 6 nov, 09:00, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> On Mon, 05 Nov 2007 23:33:16 -0800, awel wrote: >> > I am trying to to make a script to move all the files that has been >> >

Re: how to filter files by creation date

2007-11-06 Thread Marc &#x27;BlackJack7; Rintsch
one that I receive from the 'datetime.date.today()'. Build a `datetime.date` object from the timestamp you get from the stat call: In [438]: !touch test.py In [439]: datetime.date.fromtimestamp(os.stat('/home/bj/test.py').st_ctime) Out[439]: datetime.date(2007, 11, 6)

Re: modify a file

2007-11-04 Thread Marc &#x27;BlackJack7; Rintsch
a 3.5G file that may be broken. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: raw_input() and utf-8 formatted chars

2007-11-02 Thread Marc &#x27;BlackJack7; Rintsch
hat UTF-8 encoded 'Ä' and shows it. If you expected the output '\xc3\x84' then remember that you ask the soup object for its representation and not a string. The object itself decides what `repr(obj)` returns. Soup objects represent themselves as UTF-8 encoded strings. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Is pyparsing really a recursive descent parser?

2007-11-02 Thread Marc &#x27;BlackJack7; Rintsch
re(Word(alphas))`` part "eats" the 'end' and when it can't get more, the parser moves to the ``Literal('end')`` part which fails because the 'end' is already gone. > Is there a way to get pyparsing to parse a grammar like this? Negative lookahead

Re: XML DOM, but in chunks

2007-10-31 Thread Marc &#x27;BlackJack7; Rintsch
ee read only one record of the data at a time? Have you tried `iterparse()`? Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Method needed for skipping lines

2007-10-31 Thread Marc &#x27;BlackJack7; Rintsch
t; return rows > > How would you modify this to exclude lines between "Begin VB.Form" and > "End" as described above? Introduce the flag and look up the docs for the `startswith()` method on strings. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: shouldn't 'string'.find('ugh') return 0, not -1 ?

2007-10-31 Thread Marc &#x27;BlackJack7; Rintsch
> > idiom, which is a bit of a pity I think. And what should ``'string'.find('str')`` return? How do you distinguish the not found at all case from the found at the very beginning case!? The simple test you want can be written this way: if 'something' in chec

Re: jpeg image read class

2007-10-31 Thread Marc &#x27;BlackJack7; Rintsch
te over `something` directly. That loop can be written as: for pixval in data: rgb = pixval2rgb(pixval) rgbs.append(rgb) Or even shorter in one line: rgbs = map(pixval2rgb, data) If the `numpy` array is what you want/need it might be more efficient to do the RGB to "pixval" conversion with `numpy`. It should be faster to shift and "or" a whole array instead of every pixel one by one in pure Python. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Parsing xml file in python

2007-10-30 Thread Marc &#x27;BlackJack7; Rintsch
") …this line will raise an exception. `file.write()` takes just one argument, not three as in this call. If you don't get an exception maybe you have other places with a bare ``except`` like in the snippet above. Don't do that. Catch the specific exception you want to handle with an ``except`` and not simply *all*. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: A Python 3000 Question

2007-10-30 Thread Marc &#x27;BlackJack7; Rintsch
(). >> >> But consider rewriting the following: >> >> def table(func, seq): >> return zip(seq, map(func,seq)) >> >> table(len, ('', (), [])) > > table(lambda x:x.__len__(), ('',[],())) > > What was the point again ? Beauti

Re: Built-in functions and keyword arguments

2007-10-30 Thread Marc &#x27;BlackJack7; Rintsch
misunderstand his intention. He wanted to give the optional third argument of `getattr()` as keyword argument. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: A Python 3000 Question

2007-10-29 Thread Marc &#x27;BlackJack7; Rintsch
to stuff them as static methods into classes or even uglier you see code like ``Spam().spammify(eggs)`` instead of a plain function call. And functions are first class objects in Python. That sounds quite OO to me. You can think of a module with functions as a singleton. Ciao, Marc &#x

Re: statvfs

2007-10-29 Thread Marc &#x27;BlackJack7; Rintsch
blocksize * number of blocks math to get > the % of used space. Just go ahead and do it: In [185]: stat = os.statvfs('/') In [186]: stat.f_bsize Out[186]: 4096 In [187]: stat.f_blocks Out[187]: 2622526L In [188]: stat.f_bsize * stat.f_blocks Out[188]: 10741866496L Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Built-in functions and keyword arguments

2007-10-29 Thread Marc &#x27;BlackJack7; Rintsch
e issues aside, I > think it would be a good idea if built-in functions behaved exactly > the same as normal functions. As Steven D'Aprano showed they behave like normal functions. Even pure Python functions can have arguments without names: def spam(*args): pass Ciao, Mar

Re: sharing vars with different functions

2007-10-29 Thread Marc &#x27;BlackJack7; Rintsch
ass the other local to the function. > Any examples?? def something(lines): for line in lines: print lines And the call it with the object. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Which index can i use ?

2007-10-28 Thread Marc &#x27;BlackJack7; Rintsch
) > CREATE INDEX ind3 ON test USING btree (id2) > CREATE INDEX ind4 ON test USING btree (w) > CREATE INDEX ind5 ON test USING btree (d) This isn't a Python question. You'll get more and probably better feedback in a group, mailing list or forum dealing with PostgreSQL. Ciao,

Re: insert string problems..

2007-10-28 Thread Marc &#x27;BlackJack7; Rintsch
erting the *value* '019'. Starting to number tables and the need to dynamically create table names is usually sign of a bad schema design BTW. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Proposal: Decimal literals in Python.

2007-10-27 Thread Marc &#x27;BlackJack7; Rintsch
OK | os.W_OK | os.X_OK) > > which explicitly (rather than implicitly) spells it out? And the equivalent of ``os.chmod(filename, 0777)`` looks like what!? Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: xmpfilter-a-like for python (code annotation)

2007-10-27 Thread Marc &#x27;BlackJack7; Rintsch
On Sat, 27 Oct 2007 17:57:06 +, [EMAIL PROTECTED] wrote: > On Oct 27, 6:27 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> On Sat, 27 Oct 2007 17:10:13 +, [EMAIL PROTECTED] wrote: >> >http://eigenclass.org/hiki/xmpfilter >> > look

Re: os.walk and recursive deletion

2007-10-27 Thread Marc &#x27;BlackJack7; Rintsch
) > del_tree(subdir) …and here you are calling the your function recursively which then calls again `os.walk()` on that subdirectory. That's a little bit too much. Just use `os.listdir()` (and `os.path.isdir()`) in your recursive function. >#os.rmdir(path) >print "Removing: %s" % (path, ) > #--snap Or `shutil.rmtree()`. :-) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: xmpfilter-a-like for python (code annotation)

2007-10-27 Thread Marc &#x27;BlackJack7; Rintsch
tual code, i.e. if the code is wrong it nonetheless adds assertions that don't fail. I always thought one writes assertions to test what the code should do and not what it actually does!? Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: simple question on dictionary usage

2007-10-27 Thread Marc &#x27;BlackJack7; Rintsch
while the latter raises an `IndexError`. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Proposal: Decimal literals in Python.

2007-10-26 Thread Marc &#x27;BlackJack7; Rintsch
> Python 3.0a1 (py3k:57844, Aug 31 2007, 16:54:27) [MSC v.1310 32 bit > (Intel)] on win32 > >>>> type(0b1) > >>>> type(0o1) > >>>> type(0x1) > >>>> assert 0b1 is 0x1 >>>> That this doesn't raise `Assertion

Re: tuples within tuples

2007-10-26 Thread Marc &#x27;BlackJack7; Rintsch
#x27;tagA', None, [('tagB', None, ['bobloblaw], None)], None)... > > Fact is that my xml is much more deep... and I'm not sure how to > resolve it Resolve *what*? The problem isn't clear yet; at least to me. Above you say what you get. What exactly do you want? Examples please. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: elementtree w/utf8

2007-10-25 Thread Marc &#x27;BlackJack7; Rintsch
ong? Thanks in advance. You feed decoded data to `TidyHTMLTreeBuilder`. As the `encoding` argument suggests this class wants bytes not unicode. Decoding twice doesn't work. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: about functions question

2007-10-24 Thread Marc &#x27;BlackJack7; Rintsch
defined so it should working. Or at least it's not the problem you think it is. The code above, the dots replaced with nothing, will of course run "forever" until the stack limit is reached. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expression question

2007-10-24 Thread Marc &#x27;BlackJack7; Rintsch
iterate over the text file line by line and match or search within the line? Untested: needle = re.compile(r'create\s+or\s+replace\s+package(\s+body)?\s+', re.IGNORECASE) for i, line in enumerate(lines): if needle.match(line): print 'match in line %d' % (i + 1) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Better writing in python

2007-10-24 Thread Marc &#x27;BlackJack7; Rintsch
f `int` with the values 1 and 0 it's possible to replace the dictionary by a list: tmp = [[], []] for arg in cls.arguments: tmp[bool(arg)].append(arg) return tmp[1], tmp[0] Maybe that's nicer. Maybe not. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: How to find out which functions exist?

2007-10-24 Thread Marc &#x27;BlackJack7; Rintsch
itertools import ifilter classes = set(ifilter(isclass, globals().itervalues())) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Better writing in python

2007-10-24 Thread Marc &#x27;BlackJack7; Rintsch
e: > lOptional.append(arg) > return (lMandatory, lOptional) > > I think there is a better way, but I can't see how... Drop the prefixes. `l` is for list? `d` is for what!? Can't be dictionary because the code doesn't make much sense. Where is `cls` coming from? Ciao,

Re: How to find out which functions exist?

2007-10-23 Thread Marc &#x27;BlackJack7; Rintsch
On Tue, 23 Oct 2007 21:51:20 +, mrstephengross wrote: > Ok, I see how to use issubclass(). How can I get a list of classes > present in the file? import module from inspect import getmembers, isclass classes = getmembers(module, isclass) Ciao, Marc 'BlackJack'

Re: How to find out which functions exist?

2007-10-23 Thread Marc &#x27;BlackJack7; Rintsch
e a way I can find out the classes that have been derived from > Base? Take a look at the `issubclass()` function. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Can't refer to base class attribute?

2007-10-23 Thread Marc &#x27;BlackJack7; Rintsch
; class Base: > def __init__ (self): > self.foo = Foo() `Base` has no `foo` attribute but *instances* of `Base` have. > class Derived(Base): > def __init__(self): > Base.__init__(self) > Base.foo.x = 5 Instances of `Derived` have a `foo` attribute inherited from

Re: greatest and least of these...

2007-10-23 Thread Marc &#x27;BlackJack7; Rintsch
d before assignment. > Isn't the if statement supposed to keep python from going there since if > they didn't enter any input, the length of the list should just be zero. Which list? If the branch for ``choice == 1`` isn't executed then the list will never be created an the name `nums` doesn't exist. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: How to implement function like this?

2007-10-23 Thread Marc &#x27;BlackJack7; Rintsch
On Tue, 23 Oct 2007 11:48:08 +0200, Loic Mahe wrote: > even shorter: > > def funcA(tarray): > s = min(len(tarray), 3) > return [2, 3, 4][0:s] + [e for e in funcB(3-s)[0:3-s]] Why the list comprehension!? Ciao, Marc 'Blackjack' Rintsch -- http:

Re: How to implement function like this?

2007-10-23 Thread Marc &#x27;BlackJack7; Rintsch
t_array_length = len(t_array) remaining_length = len(result) - t_array_length if t_array_length < len(result): result = (result[:t_array_length] + func_b(remaining_length)[:remaining_length]) return tuple(result) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list

Re: Automatic Generation of Python Class Files

2007-10-23 Thread Marc &#x27;BlackJack7; Rintsch
say `is_active`, and a wrapper that has a property with the same name that returns the value of the wrapped objects attribute. Or lazy computation of an attribute. Breaks expectations for the first access -- long calculation for simple attribute access -- but meets it for every subsequent access.

<    1   2   3   4   5   6   7   8   9   10   >