Re: Code generator and visitor pattern

2010-07-15 Thread Stefan Behnel
Karsten Wutzke, 15.07.2010 21:00: Yes, typo, I meant strictly. Damn, I mean strongly. At least not for identifying which methods to call depending on the type/s. I think you meant "statically typed". http://c2.com/cgi-bin/wiki?StronglyTyped http://www.c2.com/cgi/wiki?StaticTypi

Re: Code generator and visitor pattern

2010-07-15 Thread Stefan Behnel
MRAB, 15.07.2010 21:33: Stefan Behnel wrote: Karsten Wutzke, 15.07.2010 20:45: Well, I'm most experienced in OO, so writing OO in Python seems like the way to start with Python. The visitor pattern uses single- dispatch, that is, it determines which method to call be the type of object p

Re: Code generator and visitor pattern

2010-07-15 Thread Stefan Behnel
ave to spill the type specific parts all over your code. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Code generator and visitor pattern

2010-07-16 Thread Stefan Behnel
Carl Banks, 16.07.2010 07:50: On Jul 15, 8:33 pm, Stefan Behnel wrote: The code I referenced is from the Cython compiler, and we use it to "do stuff" with the AST. The visitor pattern is actually a pretty common way to bind code in a single place that does a certain thing to differen

Re: improvement for copy.deepcopy : no memo for immutable types

2010-07-16 Thread Stefan Behnel
, and be easy to add. and - have you tried it? Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: any issues with long running python apps?

2010-07-16 Thread Stefan Behnel
Les Schaffer, 16.07.2010 15:07: agree with all the other suggestions: multiple threads for data and GUI, The way I read it, the suggestion was to use separate processes, not multiple threads. That's a pretty important difference. Stefan -- http://mail.python.org/mailman/listinfo/p

Re: [ANN] inflect.py: generate plurals, ordinals, numbers to words...

2010-07-16 Thread Stefan Behnel
he/she is Australian (or British or South African or something else), assuming that they are Europeans will hit the nail on the head :) :) I'm happy to see that the good old clichés still work in all directions. Makes the world so easy. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: decimal.Decimal formatting

2010-07-19 Thread Stefan Krah
1e-6 and 1e-7. Try: >>> format(Decimal("0"), ".11f") '0.000' Stefan Krah -- http://mail.python.org/mailman/listinfo/python-list

Re: [ANN] Lupa 0.6 - Lua in Python

2010-07-20 Thread Stefan Behnel
don't have any direct use for it, so this is mainly a fun project to see how well I can get it integrated and how fast I can get it. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Compile python executable only for package deployment on Linux

2010-07-20 Thread Stefan Behnel
os import math ... Note that the file must have the executable bit set. Search for "shebang", which is the spelled-out name for the "#!" special file prefix. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Exposing buffer interface for non-extension types?

2010-07-20 Thread Stefan Behnel
ds added in from the extension module. Try using Cython instead, it has native support for the buffer protocol. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Exposing buffer interface for non-extension types?

2010-07-21 Thread Stefan Behnel
n to wrap that and to implement the buffer interface and all the other wrapper code. C++ support by itself is pretty good in Cython 0.13. (to be released soon, get it from here: http://hg.cython.org/cython-closures ) Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Sorting a list created from a parsed xml message

2010-07-21 Thread Stefan Behnel
gument (see the sort() method and the operator module). Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Sorting a list created from a parsed xml message

2010-07-21 Thread Stefan Behnel
kak...@gmail.com, 21.07.2010 15:38: On Jul 21, 9:04 am, "kak...@gmail.com" wrote: On Jul 21, 8:58 am, Stefan Behnel wrote: kak...@gmail.com, 21.07.2010 14:36: From the subject of my message it's clear that i get an xml message from a socket, Not at all, but now

Re: Change Encoding in Py 2.5

2010-07-23 Thread Stefan Behnel
Girish, 23.07.2010 08:54: Is ter a way to change default encoding in py 2.5 ? Yes, but it's highly discouraged. If you tell us why you want to do it, we may be able to point to a better way to get what you want. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Change Encoding in Py 2.5

2010-07-23 Thread Stefan Behnel
t the engine run better with sugar. [1] "Did you blow up your car testing that out?" - "No, I just read comp.lang.python." Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: parsing different xml messages

2010-07-27 Thread Stefan Behnel
application level protocol? Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Accumulate function in python

2010-07-27 Thread Stefan Behnel
ture in what both builtins are targeted to provide. Just use one of the map-reduce frameworks that are out there if you need concurrency in one way or another. Special needs are not what builtins are there for. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: parsing different xml messages

2010-07-27 Thread Stefan Behnel
kak...@gmail.com, 27.07.2010 13:58: On Jul 27, 6:30 am, Stefan Behnel wrote: kak...@gmail.com, 27.07.2010 12:17: I receive the following different Xml Messages from a socket: From a bare socket? TCP? UDP? Or what else? Which is the best way to make a distinction between them so that

Re: parsing different xml messages

2010-07-27 Thread Stefan Behnel
kak...@gmail.com, 27.07.2010 14:26: On Jul 27, 8:14 am, Stefan Behnel wrote: kak...@gmail.com, 27.07.2010 13:58: On Jul 27, 6:30 am, Stefan Behnel wrote: kak...@gmail.com, 27.07.2010 12:17: I receive the following different Xml Messages from a socket: From a bare socket? TCP? UDP

Re: parsing different xml messages

2010-07-27 Thread Stefan Behnel
kak...@gmail.com, 27.07.2010 14:43: On Jul 27, 8:41 am, Stefan Behnel wrote: kak...@gmail.com, 27.07.2010 14:26: On Jul 27, 8:14 am, Stefan Behnel wrote: kak...@gmail.com, 27.07.2010 13:58: On Jul 27, 6:30 am, Stefan Behnel wrote: kak...@gmail.com, 27.07.2010 12:17: I receive the

Re: Python parsing XML file problem with SAX

2010-07-28 Thread Stefan Behnel
SAX. Again: using ElementTree instead of SAX will avoid this kind of problem. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: write xml to txt encoding

2010-07-29 Thread Stefan Behnel
ts own encoding) and thus fails to decode it? Stefan -- http://mail.python.org/mailman/listinfo/python-list

[ANN] Websourcebrowser 0.4a released

2010-08-04 Thread Stefan Schwarzer
to log in as user wsbuser with password wsb . *** Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: __init__ as a lambda

2010-08-04 Thread Stefan Schwarzer
an assignment there which isn't an expression in Python but a statement. For example, you can use f = lambda x: sys.stdout.write(str(x)) (sys.stdout.write(str(x)) is an expression) but not f = lambda x: print x (print x is a statement in Python versions < 3) Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: simple integer subclass

2010-08-05 Thread Stefan Schwarzer
ion is for, i. e. if it's really a level offset calculation or something else. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: easy question on parsing python: "is not None"

2010-08-06 Thread Stefan Schwarzer
one works well, because I believe there will > always only be 1 None object. Yes, and it avoids subtle bugs if someone overwrites `__eq__` in some class: >>> class AlwaysEqual(object): ... def __eq__(self, other): ... return True ... >>> always_eq

Re: easy question on parsing python: "is not None"

2010-08-06 Thread Stefan Schwarzer
Hello Peter, On 2010-08-06 19:20, Peter Pearson wrote: > On Fri, 06 Aug 2010 15:37:04 +0200, Stefan Schwarzer wrote: > [snip] >> I can imagine a case where you might want to compare a >> string with `is`: >> >> FORWARD = "forward" >> BACKWARD

Re: easy question on parsing python: "is not None"

2010-08-07 Thread Stefan Schwarzer
Hi Steven, On 2010-08-07 00:28, Steven D'Aprano wrote: > On Fri, 06 Aug 2010 15:37:04 +0200, Stefan Schwarzer wrote: >>> Plus, I believe the >>> "==" operator will check if the variables point to the same object. >> >> No, that's what `is` is

Re: default behavior

2010-08-07 Thread Stefan Schwarzer
airs added _after_ the "cast" aren't included in the new dict: >>> y[2] = 17 >>> y {1: [1, 42], 2: 17} >>> x defaultdict(, {1: [1, 42]}) Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem with Elementtree and XMLSchem instance type

2010-08-07 Thread Stefan Behnel
oes that. There are two ways to work around this: recent ET versions support explicitly defining namespace-prefix mappings at a module global level (IIRC, starting with ET 1.3/Py2.7/Py3.2), so you can provide a fixed prefix if you know what's coming in. Failing that, you can switch to

Re: easy question on parsing python: "is not None"

2010-08-08 Thread Stefan Schwarzer
x27;s a bit more obvious that these are just "magic numbers", so presumably the constant names should be used instead. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Python -Vs- Ruby: A regexp match to the death!

2010-08-09 Thread Stefan Schwarzer
In [2]: %paste at the prompt it gives me (before I pasted anything) In [2]: %paste File "", line 1 http://pypi.python.org/pypi/ipython/0.10 ^ SyntaxError: invalid syntax So far, I couldn't find anything on the net on this. [1] http://pypi.python.org/pypi/ipython Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Python parsing XML file problem with SAX

2010-08-09 Thread Stefan Behnel
Aahz, 09.08.2010 18:52: In article, Stefan Behnel wrote: First of all: don't use SAX. Use ElementTree's iterparse() function. That will shrink you code down to a simple loop in a few lines. Unless I'm missing something, that only helps if the final tree fits into memory. What

Re: Python -Vs- Ruby: A regexp match to the death!

2010-08-09 Thread Stefan Schwarzer
Hi Robert, On 2010-08-09 22:23, Robert Kern wrote: > On 2010-08-09 06:42 , Stefan Schwarzer wrote: >> Unfortunatey, when I enter >> >>In [2]: %paste >> >> at the prompt it gives me (before I pasted

Re: Python -Vs- Ruby: A regexp match to the death!

2010-08-09 Thread Stefan Schwarzer
On 2010-08-09 23:43, Stefan Schwarzer wrote: > I got that traceback as soon as I typed in "%paste" and > pressed enter, without pasting anything in the terminal. > I had assumed it works like :paste in Vim, activating a I meant ":set paste" of course. Stefan -- h

Re: Python parsing XML file problem with SAX

2010-08-09 Thread Stefan Behnel
hat's also a huge advantage over SAX: iterparse code is much easier to tune into a streamlined loop body when you need it. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Microsoft lessening commitment to IronPython and IronRuby

2010-08-10 Thread Stefan Behnel
ne creative thing which was ever done in Dotnet. Erm, this is Microsoft. It's not about being creative, it's about selling stuff to users. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Microsoft lessening commitment to IronPython and IronRuby

2010-08-10 Thread Stefan Behnel
this is supposed to run on a server, it means that it will always suffer from the "headless click-here-to-continue" problem. It might not be too hard to port the app to Mono, but the rather explicit claim above doesn't make me feel very comfortable about that upgrade path... St

Re: Weird Python behaviour

2010-08-10 Thread Stefan Schwarzer
you're referring to, but I only recently gave a beginners' talk at EuroPython: http://sschwarzer.com/download/robust_python_programs_europython2010.pdf The topic of identity and assignments starts on slide 7, nice graphics start on slide 10. ;-) Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: urgent requirement at Hyderabad

2010-08-11 Thread Stefan Behnel
In case anyone wondered: Hyderabad is likely referring to some place in Asia: http://en.wikipedia.org/wiki/Hyderabad_%28disambiguation%29 Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Beyond the moratorium

2010-08-12 Thread Stefan Behnel
that your examples above span both the language and the stdlib, which are put under different constraints by the moratorium. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: __class__ of what

2010-08-12 Thread Stefan Schwarzer
here?), but >>> dict(D.__dict__) {'__doc__': None, '__module__': '__main__'} indicates that D doesn't contain n. But C does: >>> dict(C.__dict__) {'__dict__': , '__doc__': None, '__init__': , '__module__': '__main__', '__weakref__': , 'n': 1} I hope everything I wrote above is valid. If not, please correct me. :-) Anyway, depending on what you want, either of the two variants might be ok. In any case I'd include a meaningful comment on why you actually wrote what you wrote. :-) Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I get number of files in a particular directory.

2010-08-13 Thread Stefan Schwarzer
urns a list of names. What you named `files` should actually be `filename`. What you got printed in the loop are the lengths of each filename. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Help to convert Number to String

2010-08-13 Thread Stefan Schwarzer
ute filenames appropriate for my system, everything works. Maybe the code you included in this post isn't the same which led to the error? Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Python XML and tables using math

2010-08-15 Thread Stefan Behnel
tions have been coming up every couple of weeks. The responses often include mostly complete implementations that you can borrow from. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: [Q] How far can stack [LIFO] solve do automatic garbage collection and prevent memory leak ?

2010-08-16 Thread Stefan Behnel
Standish P, 16.08.2010 09:20: We envisage an exogenous stack which has malloc() associated with a push and free() associated with a pop. What's your use case? Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Opposite of split

2010-08-17 Thread Stefan Schwarzer
b.join([lines[index][wn][2] for index in range(5)]) Moreover, the repetition of this line looks as if you wanted to put the right hand sides of the assignments in a list, instead of assigning to distinct names (`vf` etc.). By the way, you use the number 5 a lot. I guess this should be a constant, too. | alf.write(tp+'\t'+vf+'\t'+vq+'\t'+al+'\t'+bt+'\t'+vs+'\n') Suggestion: Use tab.join([tp, vf, vq, al, bt, vs]) + "\n" Again, not using distinct variables would have an advantage here. | alf.close() | print "Done" Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: 79 chars or more?

2010-08-17 Thread Stefan Schwarzer
'%Y-%m-%d', '%m%d%Y') or even self.expiration_date = translate_date( find(response, 'MPNExpirationDate').text, '%Y-%m-%d', '%m%d%Y') for consistency. This not only limits the width but also makes the nesting of the calls more visible. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: 79 chars or more?

2010-08-17 Thread Stefan Schwarzer
On 2010-08-17 17:44, AK wrote: > On 08/17/2010 10:28 AM, Stefan Schwarzer wrote: >> I'd probably reformat this to >> >>self.expiration_date = translate_date( >> find(response, 'MPNExpirationDate').text, >>

Re: 79 chars or more?

2010-08-17 Thread Stefan Schwarzer
ght here; you should keep the overall readability or (maintainability on the whole) in mind. I agree with Neil that good refactoring can _improve_ the understandability of the code, and it won't necessarily require you to look up the code of the extracted function or method. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Call Java Code from python

2010-08-18 Thread Stefan Schwarzer
ht help: http://www.slideshare.net/onyame/mixing-python-and-java Personally, I've used JCC for accessing Lucene (a search engine framework implemented in Java). It was a bit rough in some places, but overall quite usable. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: 79 chars or more?

2010-08-18 Thread Stefan Schwarzer
t;> But.. why horizontal scrolling, isn't autowrap much better than that? > > Do you seriously use autowrapper when writing code? I think he means wrapping on the screen, not actually inserting line breaks. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: String substitution VS proper mysql escaping

2010-08-19 Thread Stefan Schwarzer
e parentheses are also used to group expressions. For example, >>> 2 * (1+2) 6 If it were as you would like, the result would have been (3, 3) So because inside parentheses already denotes an expression you have to add a comma to distinguish a one-element tuple from an expression. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: A question to experienced Pythoneers

2010-08-20 Thread Stefan Schwarzer
ug.co.nz> I can't get the page; all I get is an error message: """ Not Found The requested message, i4ku71$fd...@lust.ihug.co.nz, could not be found. """ Can you please give a part of the message to search for or even better, an URL that works? :-) Thanks, Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: A question to experienced Pythoneers

2010-08-20 Thread Stefan Schwarzer
l Rapid Development http://www.amazon.com/x/dp/0072850604/ Tom DeMarco, Timothy Lister Waltzing With Bears: Managing Risk on Software Projects http://www.amazon.com/x/dp/0932633609/ Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Open a command pipe for reading

2010-08-23 Thread Stefan Schwarzer
eads the whole file at once and returns a list of the lines (including line end characters, by the way). What you probably want is for line in pipe: print line, which reads and prints the file contents line by line. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating a PYD file

2010-08-23 Thread Stefan Behnel
can try to compile it using Cython. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating a PYD file

2010-08-23 Thread Stefan Behnel
the maintenance cost will always be the dominating factor anyway. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: DDE Module for Python 3.1.2

2010-08-23 Thread Stefan Behnel
link to the module, so that we know what module you are actually talking about? Also, if the project that provides the module has a mailing list, you might want to ask there. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: ftplib limitations?

2010-08-24 Thread Stefan Schwarzer
The `print` statement after the `retrbinary` call? > Some error I got, but this was in yesterday, I don't remember the text > of the error. Can't you reproduce the error by executing the script once more? Can you copy the file to another server and see if the problem shows up there,

Re: equivalent of source in python?

2010-08-24 Thread Stefan Schwarzer
't look as if they were the purpose of the program, but rather mostly some preparation/setup before solving the actual problem. Maybe it's more helpful to tell us what you want to achieve in the end and we might be able to make suggestions on that. How long is the shell script and what's your Python code so far? Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: ftplib limitations?

2010-08-24 Thread Stefan Schwarzer
Hi durumdara, On 2010-08-24 16:29, Stefan Schwarzer wrote: >> I experienced some problem. >> The server is Windows and FileZilla, the client is Win7 and Python2.6. >> When I got a file with size 1 303 318 662 byte, python is halt on >> "retrbinary" line

Re: ftplib limitations?

2010-08-25 Thread Stefan Schwarzer
ommand for the file that troubles you. I'm the maintainer of ftputil and if you get the same or similar error here, I may find a workaround for ftputil. As it happens, someone reported a similar problem (_if_ it's the same problem in your case) just a few days ago. [2] [1] http://ftputil.sschwarzer.net [2] http://www.mail-archive.com/ftpu...@codespeak.net/msg00141.html Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: ftplib limitations?

2010-08-25 Thread Stefan Schwarzer
Hi durumdara, On 2010-08-25 11:18, durumdara wrote: > On aug. 25, 08:07, Stefan Schwarzer wrote: >> >> The file is 2 GB in size and is fully transferred, without >> blocking or an error message. The status message from the >> server is '226-File successfully tr

Re: How *build* new elements and *replace* elements with xml.dom.minidom ?

2009-06-10 Thread Stefan Behnel
http://...', ...] from lxml.html.builder import A for td in td_list: index = int(td.text) a = A("some text", href=links[index]) td.getparent().replace(td, a) Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: xml.dom.minidom losing the XML document type attribute

2009-06-10 Thread Stefan Behnel
Johannes Bauer wrote: > when I read in a XML document with the xml.dom.minidom parser and write > it out again, an attribute is lost: > > Input: > > > [...] > > Output: > > > How can I fix this? You don't have to. UTF-8 is the default encoding, so th

Re: unladen swallow: python and llvm

2009-06-11 Thread Stefan Behnel
Python compiles Python code to *byte-code* and then *interprets* that in a virtual machine (which happens to be written in C, hence the name). Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: unladen swallow: python and llvm

2009-06-11 Thread Stefan Behnel
bvious, as it contains lots of runtime type specialisations and optimisations. But that's the price you pay for fast code. And you can make Cython leave out most of the duplicated code (i.e. the pessimistic fallbacks) by adding type hints to your code. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: xml.dom.minidom losing the XML document type attribute

2009-06-11 Thread Stefan Behnel
Johannes Bauer wrote: > Stefan Behnel schrieb: >> Johannes Bauer wrote: >>> when I read in a XML document with the xml.dom.minidom parser and write >>> it out again, an attribute is lost: >>> >>> Input: >>> >>> >>> [...] >

Re: xml.dom.minidom losing the XML document type attribute

2009-06-11 Thread Stefan Behnel
Johannes Bauer wrote: > Stefan Behnel schrieb: > >>> Can I somehow force Python to generate it anyways? >> Did you try passing encoding='UTF-8' on serialisation? > > Uhm... nope - how can I do that? Well, depends on what your code currently does

Re: How *build* new elements and *replace* elements with xml.dom.minidom ?

2009-06-11 Thread Stefan Behnel
Johannes Bauer wrote: > Stefan Behnel schrieb: > >>> So I need to build hyperlinks (a elements) with href attribute and >>> replace the text elements (numbers) somehow. >> Try lxml.html instead. It makes it really easy to do these things. For >> example, you c

Re: Different types of dicts with letter before the curly braces.

2009-06-14 Thread Stefan Behnel
Hi, this kind of stuff is commonly discussed on the python-ideas mailing list. You might want to search that list and/or repost this over there. Stefan kindly wrote: > I am sure people have thought of this before, but I cant find where. > I think that python should adapt a way of de

Re: etree, lxml unexpected behaviour

2009-06-17 Thread Stefan Behnel
amespace, just > like the elements? There isn't, because this is the correct behaviour according to the spec. http://www.w3.org/TR/REC-xml-names/#defaulting """ A default namespace declaration applies to all unprefixed element names within its scope. Default namespace declarations do not apply directly to attribute names; the interpretation of unprefixed attributes is determined by the element on which they appear. """ Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Status of Python threading support (GIL removal)?

2009-06-19 Thread Stefan Behnel
-2006-1.pdf and then decide to switch to an appropriate concurrency model for your use case. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Status of Python threading support (GIL removal)?

2009-06-20 Thread Stefan Behnel
opriate' programming language. Matter of available skills, mostly. There's usually a lot less code to be written that deals with concurrency than code that implements what the person paying you makes money with, so learning a new library may be worth it, while learning a new language may not. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Status of Python threading support (GIL removal)?

2009-06-21 Thread Stefan Behnel
es every problem perfectly. At some point you need a > different tool to get the raw power of your machine. C (and perhaps > Fortran) are the weapons of choice for number crunching. Well, and there's always Cython to the rescue when you need it. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Status of Python threading support (GIL removal)?

2009-06-21 Thread Stefan Behnel
re not (or likely not) benefit from multiple-cores. Claiming that "pure Python code does not free the GIL" in the context of CPython when you define "pure Python code" as code that does not depend on C code is plain flawed. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working

2009-06-25 Thread Stefan Behnel
mplete document (represented in ET as an ElementTree object), fromstring() and especially the 'literal wrapper' XML() are made for parsing strings, which (most?) often only contain XML fragments. With a fragment, you normally want to continue doing things like inserting it into another tree,

Re: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working

2009-06-25 Thread Stefan Behnel
Carl Banks wrote: > On Jun 25, 10:11 pm, Stefan Behnel wrote: >> Carl Banks wrote: >>>> Why isn't et.parse the only way to do this? Why have XML or fromstring >>>> at all? >>> Because Fredrick Lundh wanted it that way. Unlike most Python >&g

Re: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working

2009-06-25 Thread Stefan Behnel
the XML must not have an encoding declaration (which would render it non well-formed). This is convenient for parsing HTML, it's less convenient for XML usually. If what you meant is actually parsing from a byte string, this is easily done using BytesIO(), or StringIO() in Py2.x (x<6). Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: No trees in the stdlib?

2009-06-25 Thread Stefan Behnel
ugh practicality beats purity, sometimes... ;) Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: No trees in the stdlib?

2009-06-26 Thread Stefan Behnel
Paul Rubin wrote: > Stefan Behnel writes: >>> Besides some interface glitches, like returning None >>> on delete if I recall correctly. >> That's actually not /that/ uncommon. Operations that change an object are >> not (side-effect free) functions, so

Re: Py 3 slower than Py 2. Towers of Hanoi implementation

2009-06-26 Thread Stefan Behnel
> What happened to Python? Have you tried Python 3.1? Have you made sure that both Python interpreters were build with the same compiler arguments and that none of them is a debug build? Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: No trees in the stdlib?

2009-06-26 Thread Stefan Behnel
Hallvard B Furuseth wrote: > Stefan Behnel writes: >> João Valverde wrote: >>> Besides some interface glitches, like returning None >>> on delete if I recall correctly. >> That's actually not /that/ uncommon. Operations that change an object are >> no

Re: No trees in the stdlib?

2009-06-26 Thread Stefan Behnel
n of them will do just fine. And if you find a case where those just don't fit, you may need a database anyway. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: No trees in the stdlib?

2009-06-26 Thread Stefan Behnel
João Valverde wrote: > I wouldn't consider anything other than C for such a module on > efficiency alone, unless it was a prototype of course. But I have little > knowledge about the Python C API. Cython is your true friend, if only for rapid prototyping. http://cython.org/ S

Re: ElementTree.XML(string XML) and ElementTree.fromstring(string XML) not working

2009-06-26 Thread Stefan Behnel
Kee Nethery wrote: > On Jun 25, 2009, at 11:39 PM, Stefan Behnel wrote: >> parsing a >> document from a string does not have its own function, because it is >> trivial to write >> >> tree = parse(BytesIO(some_byte_string)) > > :-) Trivial for someone f

Re: Multi thread reading a file

2009-07-01 Thread Stefan Behnel
t slow, and then check what to do about the real problem. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Multi thread reading a file

2009-07-01 Thread Stefan Behnel
totally non-obvious to me. > #15 columns > if len(row) != 15: >break > > t[s%bufsize] = tuple(row) > > #Do this all the way at the end for flushing. > if (s%bufsize != 0): >dset[(s//bufsize)*bufsize:s]=t[0:s%bufsize] If you *really* think your code is no

Re: logging of strings with broken encoding

2009-07-02 Thread Stefan Behnel
meant by passing that byte string in the first place? And where is the difference between accidentally passing a byte string and accidentally passing another non-printable object? Handling this "better" may simply hide the bugs in your code, I don't find that's a

Re: Code that ought to run fast, but can't due to Python limitations.

2009-07-05 Thread Stefan Behnel
ey only test a single int/char variable, even when you write things like "elif x in [1,5,9,12]". This works in Cython, because we know that the comparison to a C int/char is side-effect free. It may not always be side-effect free in Python, so this won't work in general. It wo

Re: Code that ought to run fast, but can't due to Python limitations.

2009-07-05 Thread Stefan Behnel
lags["CDATA"], contentModelFlags["RCDATA"]) constant? If that is the case, I'd cut it out into a class member (or module-local variable) first thing in the morning. And I'd definitely keep the result of the "in" test in a local variable for reuse, seeing how

Re: Code that ought to run fast, but can't due to Python limitations.

2009-07-05 Thread Stefan Behnel
nsive. Did you implement this and prove your claim in benchmarks? Taking a look at the current implementation, I'm pretty sure a dict-based implementation would outrun it in your first try. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Code that ought to run fast, but can't due to Python limitations.

2009-07-05 Thread Stefan Behnel
Stefan Behnel wrote: > John Nagle wrote: >>Here's some actual code, from "tokenizer.py". This is called once >> for each character in an HTML document, when in "data" state (outside >> a tag). It's straightforward code, but look at all t

Re: Code that ought to run fast, but can't due to Python limitations.

2009-07-05 Thread Stefan Behnel
thin the Python bytecode for the big function. Hmm, yes, the actual code inside the conditionals is pretty short, so the call overhead might hurt here. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Code that ought to run fast, but can't due to Python limitations.

2009-07-05 Thread Stefan Behnel
Paul Rubin wrote: > Stefan Behnel writes: >>> The series of tests is written that way because there is no case >>> statement available. It is essentially switching on a bunch of >>> character constants and then doing some additional tests in each >>> bran

Re: Code that ought to run fast, but can't due to Python limitations.

2009-07-05 Thread Stefan Behnel
Paul Rubin wrote: > Stefan Behnel writes: >>> # Keep a charbuffer to handle the escapeFlag >>> if self.contentModelFlag in\ >>> (contentModelFlags["CDATA"], contentModelFlags["RCDATA"]): >> Is the tuple >&g

Re: Code that ought to run fast, but can't due to Python limitations.

2009-07-05 Thread Stefan Behnel
Paul Rubin wrote: > Stefan Behnel writes: >> You may notice that the creation of this exact tuple appears in almost all >> if the conditionals of this method. So it is part of the bottleneck. > > I don't think so. The tuple is only created when the character has >

Re: Code that ought to run fast, but can't due to Python limitations.

2009-07-05 Thread Stefan Behnel
ars}) > self.lastFourChars += chars[-4:] > self.lastFourChars = self.lastFourChars[-4:] > return True Giving this some more thought, I'd also try is to split the huge if-elif-else block like this: if data in string_with_all_special_characters: if data == '&' ...: ... else: ... So there are three things to improve: - eliminate common subexpressions which you know are constant - split the large conditional sequence as shown above - use separate dataState() methods when inside and outside of CDATA/RCDATA blocks and (maybe) escaped blocks Stefan -- http://mail.python.org/mailman/listinfo/python-list

<    15   16   17   18   19   20   21   22   23   >