Re: Need to parse python dictionaries into xml

2010-06-16 Thread Stefan Behnel
abhijeet thatte, 16.06.2010 20:41: On Wed, Jun 16, 2010 at 10:57 AM, Stefan Behnel wrote: You should start by writing down the XML structure that you want to build for the above dict. That will make it clear what needs to be done

Re: Need to parse python dictionaries into xml

2010-06-16 Thread Stefan Behnel
Hi, please avoid top-posting. abhijeet thatte, 16.06.2010 18:46: On Tue, Jun 15, 2010 at 11:09 PM, Stefan Behnel wrote: abhijeet thatte, 16.06.2010 03:05: I am a novice Python user. I am using Python to parse some hardware specifications and create xml files from them. I generate dict of

Re: pythonize this!

2010-06-16 Thread Stefan Behnel
Jussi Piitulainen, 16.06.2010 13:10: Lie Ryan writes: On 06/15/10 21:49, superpollo wrote: goal (from e.c.m.): evaluate 1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three consecutive + must be followed by two - (^ meaning ** in this context) [...] Probably bending the rule

Re: Need to parse python dictionaries into xml

2010-06-15 Thread Stefan Behnel
abhijeet thatte, 16.06.2010 03:05: I am a novice Python user. I am using Python to parse some hardware specifications and create xml files from them. I generate dict of really huge sizes. (I am parsing some 10,000 register definitions.) Why do you need these intermediate dicts? So, it looks

Re: Readability (html purifier) in Python

2010-06-15 Thread Stefan Behnel
Дамјан Георгиевски, 15.06.2010 17:44: http://lab.arc90.com/experiments/readability/ Readability is a javascript bookmarklet that "makes reading on the Web more enjoyable by removing the clutter around what you're reading." Does anyone know of something similar in Python? Well, that sounds lik

Re: pythonize this!

2010-06-15 Thread Stefan Behnel
superpollo, 15.06.2010 14:55: Peter Otten ha scritto: superpollo wrote: goal (from e.c.m.): evaluate 1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three consecutive + must be followed by two - (^ meaning ** in this context) from itertools import cycle, izip sum(sign*i*i fo

Re: pythonize this!

2010-06-15 Thread Stefan Behnel
Stefan Behnel, 15.06.2010 14:23: superpollo, 15.06.2010 13:49: goal (from e.c.m.): evaluate 1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three consecutive + must be followed by two - (^ meaning ** in this context) my solution: >>> s = 0 >>> for i in ran

Re: pythonize this!

2010-06-15 Thread Stefan Behnel
superpollo, 15.06.2010 13:49: goal (from e.c.m.): evaluate 1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three consecutive + must be followed by two - (^ meaning ** in this context) my solution: >>> s = 0 >>> for i in range(1, 2011): ... s += i**2 ... if not (i+1)%5: ... s -

Re: efficiently create and fill array.array from C code?

2010-06-13 Thread Stefan Behnel
Stephen Hansen, 13.06.2010 21:05: On 6/13/10 11:41 AM, Stefan Behnel wrote: Take a look at a) NumPy and b) Cython. You can also use Cython with the array module, but NumPy is a much more common way to deal with "number crunching routines", especially multi-dimentional arrays. D

Re: efficiently create and fill array.array from C code?

2010-06-13 Thread Stefan Behnel
Thomas Jollans, 13.06.2010 19:15: I'm writing some buffer-centric number-crunching routines in C for Python code that uses array.array objects for storing/manipulating data. I would like to: 1. allocate a buffer of a certain size 2. fill it 3. return it as an array. Take a look at a) NumPy and

Re: Issue with xml iterparse

2010-06-13 Thread Stefan Behnel
bfrederi, 03.06.2010 22:44: I am using lxml iterparse and running into a very obscure error. When I run iterparse on a file, it will occasionally return an element that has a element.text == None when the element clearly has text in it. I assume you are referring to the 'start' event here, righ

Re: What's a good XSL to translate xmlrunner.py output into a test report?

2010-06-13 Thread Stefan Behnel
Phlip, 06.06.2010 19:12: Here's xmlrunner.py: http://www.rittau.org/python/xmlrunner.py you attach it to your developer tests, and it emits a file called "TEST-unittest.TestSuite.xml", containing auspicious wackiness like this: Bump? Anyone reporting on their unit tests here?

Re: plac, the easiest command line arguments parser in the world

2010-06-02 Thread Stefan Behnel
Paul Rubin, 02.06.2010 10:43: Tim Golden writes: pattern, which provides a minimally semi-self-documenting approach for positional args, but I've always found the existing offerings just a little too much work to bother with. I'll give plac a run and see how it behaves. After using optparse a

Re: Python Forum

2010-06-02 Thread Stefan Behnel
pyDev, 02.06.2010 10:04: I would like to let the community know that there is a new web-based forum for Python enthusiasts over at PythonForum.org (http:// pythonforum.org). Web-based forums is a preferred method by Python newcomers to get help in exploring the world of Python and programming ove

Re: signed vs unsigned int

2010-06-02 Thread Stefan Behnel
johnty, 02.06.2010 08:43: i'm reading bytes from a serial port, and storing it into an array. each byte represents a signed 8-bit int. currently, the code i'm looking at converts them to an unsigned int by doing ord(array[i]). however, what i'd like is to get the _signed_ integer value. whats t

Re: expat parsing error

2010-06-01 Thread Stefan Behnel
kak...@gmail.com, 01.06.2010 16:00: how can i fix it, how to "ignore" the headers and parse only the XML? Consider reading the answers you got in the last thread that you opened with exactly this question. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Omit the headers from XML message

2010-05-28 Thread Stefan Behnel
kak...@gmail.com, 28.05.2010 17:24: Hi i have the following xml message i want to omit the headers, any hints? POST /test/pcp/Listener HTTP/1.1 User-Agent: Jakarta Commons-HttpClient/3.1 Host: 127.0.0.1:50002 Content-Length: 547 http://demo.com/demo";> scvdcvsdv

Re: Sockets and xml problem

2010-05-28 Thread Stefan Behnel
kak...@gmail.com, 28.05.2010 13:50: Hi in the following code class MyClientHandler(SocketServer.BaseRequestHandler): def handle(self): print self.client_address, now( ) time.sleep(5) while True: xmltxt = self.request.recv(1024)<--is this ok - enough?

Re: Fastest way to apply a function to an iterable

2010-05-26 Thread Stefan Behnel
Shashank Singh, 26.05.2010 23:16: > I probably didn't state the problem properly. I was assuming the > availability of a static method that could be passed on to map based > solution (or imap for that matter). > > The question was, if one wants to apply a function on each member of list > and dis

Re: Fastest way to apply a function to an iterable

2010-05-26 Thread Stefan Behnel
Shashank Singh, 26.05.2010 21:48: What is the most efficient way of applying a function to all the elements of an iterable while discarding the result (i.e. operations are done only for side-effects). For example if I want to save all elements in a list of items (and am not interested in what sa

Re: speed up a numpy code with huge array

2010-05-25 Thread Stefan Behnel
Alexzive, 25.05.2010 21:05: is there a way to improve the performance of the attached code ? it takes about 5 h on a dual-core (using only one core) when len(V) ~1MIL. V is an array which is supposed to store all the volumes of tetrahedral elements of a grid whose coord. are stored in NN (accesse

Re: [ANN] oStri: Cython optimized String object

2010-05-21 Thread Stefan Behnel
Mike 'Fuzzy' Partin, 21.05.2010 08:37: Optimized String-like Object is kind of a misnomer in that, the object provided is a subclass of the base str type, adding optimized (Cython bindings to the standard (POSIX) libc regex and string functions) match() and sub() methods. Hi, could you give an

Re: url fetching from xml depending upon selection

2010-05-18 Thread Stefan Behnel
shanti bhushan, 18.05.2010 10:08: On May 18, 12:04 pm, Stefan Behnel wrote: shanti bhushan, 18.05.2010 07:18: >>> [...] http://first.co.jp"; /> http://www.google.com"; /> http://www.epaper.times.india.com"; /> ht

Re: url fetching from xml depending upon selection

2010-05-18 Thread Stefan Behnel
shanti bhushan, 18.05.2010 07:18: I have a sample.XML file the code is like this My Podcasts Sun, 07 Mar 2010 15:53:26 GMT Sun, 07 Mar 2010 15:53:26 GMT http://first.co.jp"; /> http://www.google.com"; /> http://www.epaper.times.india.com"; />

Re: url fetching from xml depending upon selection

2010-05-18 Thread Stefan Behnel
shanti bhushan, 18.05.2010 07:18: I have a sample.XML file the code is like this My Podcasts Sun, 07 Mar 2010 15:53:26 GMT Sun, 07 Mar 2010 15:53:26 GMT http://first.co.jp"; /> http://www.google.com"; /> http://www.epaper.times.india.com"; />

Re: Issue with PyUnicodeObject type variables

2010-05-17 Thread Stefan Behnel
mathan kumar, 17.05.2010 12:16: From: Stefan Behnel Doesn't surprise me at all. Could you make sure this is the code you are using? Especially the names 'p' and 'path'? And that you are initialising neither of the two in your code? Tat was a typo mistake instead of

Re: reading XML file using python

2010-05-17 Thread Stefan Behnel
superpollo, 17.05.2010 11:24: Simon Brunning ha scritto: On 17 May 2010 09:34:51 UTC+1, shanti bhushan wrote: i am new to python.i want to read the XML file using python it ,by using DOm or SAX any of them. I want to read the http://www.google.com(any hyper text) from XML and print that. please

Re: Issue with PyUnicodeObject type variables

2010-05-17 Thread Stefan Behnel
gmail, 17.05.2010 11:24: A variable whose data type is PyUnicodeObject checked whether it is a UnicodeObject type. Got output as false example : PyUnicodeObject *p; if (PyUnicode_Check(path)) { printf("\nTrue.\n"); } else { printf("\nfalse.\n"); } output: false Doesn't su

Re: reading XML file using python

2010-05-17 Thread Stefan Behnel
shanti bhushan, 17.05.2010 10:34: i am new to python.i want to read the XML file using python it ,by using DOm or SAX any of them. I want to read the http://www.google.com (any hyper text) from XML and print that. Note that web sites usually are HTML, not XML. Are you sure you want to read XML

Re: Reading XML namespaces

2010-05-16 Thread Stefan Behnel
Martin v. Loewis, 16.05.2010 11:05: Maybe true technically, but false in practice. If I receive XML data from source XYZ or service XYZ the use of namespaces and their prefixes is extremely consistent [in practice] and very customary (for example: I've never seen the DSML namespace abbreviated a

Re: parsing XML

2010-05-16 Thread Stefan Behnel
Jake b, 16.05.2010 09:40: Check out Amara: http://www.xml3k.org/Amara/QuickRef It looks promising. For a pythonic solution over sax / dom. >>> Iter(doc.team.player) # or >>> doc.team.player[0].name Ah, right, and there's also lxml.objectify: from lxml.objectify import parse root = p

Re: Reading XML namespaces

2010-05-16 Thread Stefan Behnel
Martin v. Loewis, 16.05.2010 09:07: the approach that the OP is apparently trying to follow is clearly misguided. I completely agree. However, I recommend that we let him find out on his own. I suspect he has some idiomatic usage of XML, perhaps with all namespace prefixes defined in the root

Re: Reading XML namespaces

2010-05-16 Thread Stefan Behnel
Adam Tauno Williams, 15.05.2010 23:04: On Sat, 2010-05-15 at 22:58 +0200, Stefan Behnel wrote: Adam Tauno Williams, 15.05.2010 22:40: On Sat, 2010-05-15 at 22:29 +0200, Stefan Behnel wrote: Adam Tauno Williams, 15.05.2010 20:37: Say I have an XML document that begins with: http

Re: Reading XML namespaces

2010-05-16 Thread Stefan Behnel
Adam Tauno Williams, 16.05.2010 06:00: Given that XML documents can be very large I'd rather avoid a parsing of the document [beyond what lxml/etree] has already done] just to retrieve the namespaces and their prefixes. In order to find out which prefixes are used in the document and which set

Re: Reading XML namespaces

2010-05-15 Thread Stefan Behnel
Martin v. Loewis, 15.05.2010 23:37: BTW, I'm still not sure I understand your problem. Could you provide some more details? Wouldn't it be easier if you told the OP how to access the prefix mappings in lxml etree, or, if this was actually not possible, admitted that it is actually not possible?

Re: Reading XML namespaces

2010-05-15 Thread Stefan Behnel
Adam Tauno Williams, 15.05.2010 23:04: On Sat, 2010-05-15 at 22:58 +0200, Stefan Behnel wrote: Adam Tauno Williams, 15.05.2010 22:40: On Sat, 2010-05-15 at 22:29 +0200, Stefan Behnel wrote: Adam Tauno Williams, 15.05.2010 20:37: Say I have an XML document that begins with: http

Re: Reading XML namespaces

2010-05-15 Thread Stefan Behnel
Adam Tauno Williams, 15.05.2010 22:40: On Sat, 2010-05-15 at 22:29 +0200, Stefan Behnel wrote: Adam Tauno Williams, 15.05.2010 20:37: Say I have an XML document that begins with: http://www.dsml.org/DSML";> How can one access the namespaces define in this node? I've done a fair

Re: Reading XML namespaces

2010-05-15 Thread Stefan Behnel
Adam Tauno Williams, 15.05.2010 20:37: Say I have an XML document that begins with: http://www.dsml.org/DSML";> ... How can one access the namespaces define in this node? I've done a fair amount of XML in Python, but haven't been able to uncover the call to enumerate the namespaces. Primaril

Re: Picking a license

2010-05-14 Thread Stefan Behnel
a...@pythoncraft.com (Aahz) writes: Which license you use depends partly on your political philosophy. Did they close down debian-legal, or why is this thread growing so long? Ah, I forgot - Friday ... Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: parsing XML

2010-05-14 Thread Stefan Behnel
Martin v. Loewis, 14.05.2010 17:15: kak...@gmail.com wrote: Hi to all, let's say we have the following Xml 17.1 6.4 15.5 7.8 How can i get the players name, age and height? DOM or SAX and how Homework? I would hope that every school teacher who teaches

Re: parsing XML

2010-05-14 Thread Stefan Behnel
kak...@gmail.com, 14.05.2010 16:57: Hi to all, let's say we have the following Xml 17.1 6.4 15.5 7.8 How can i get the players name, age and height? Here's an overly complicated solution, but I thought that an object oriented design would help here.

Re: cmd app and xml

2010-05-14 Thread Stefan Behnel
kak...@gmail.com, 14.05.2010 12:46: Hi there, i'm writing a console app using the cmd library. I also use xml.dom.minidom to parse an xml file that i get as a response to an HTTP Post request. with data = response.read() i get the xml response from the server. i then feed the parser with that dat

Re: indexing lists/arrays question

2010-05-13 Thread Stefan Behnel
a, 13.05.2010 16:36: this must be easy but its taken me a couple of hours already i have a=[2,3,3,4,5,6] i want to know the indices where a==3 (ie 1 and 2) indices = [ i for i,item in enumerate(a) if item == 3 ] then i want to reference these in a print [ a[i] for i in indices ] St

Re: Extract all words that begin with x

2010-05-12 Thread Stefan Behnel
Aahz, 12.05.2010 17:33: Stefan Behnel wrote: superpollo, 11.05.2010 17:03: Aahz ha scritto: In article, Terry Reedy wrote: On 5/10/2010 5:35 AM, James Mills wrote: On Mon, May 10, 2010 at 6:50 PM, Xavier Ho wrote: Have I missed something, or wouldn't this work just as

Re: Extract all words that begin with x

2010-05-12 Thread Stefan Behnel
superpollo, 11.05.2010 17:03: Aahz ha scritto: In article , Terry Reedy wrote: On 5/10/2010 5:35 AM, James Mills wrote: On Mon, May 10, 2010 at 6:50 PM, Xavier Ho wrote: Have I missed something, or wouldn't this work just as well: list_of_strings = ['2', 'awes', '3465sdg', 'dbsdf', 'asdgas

Re: open(False) in python3

2010-05-12 Thread Stefan Behnel
Johan Förberg, 12.05.2010 10:05: On Tue, 11 May 2010 19:27:37 -0300, Gabriel Genellina wrote: so open(False) is the same as open(0), and 0 is the file descriptor associated to standard input. The program isn't hung, it's just waiting for you to type some text That's interesting. Are there any

Re: Extract all words that begin with x

2010-05-12 Thread Stefan Behnel
Bryan, 12.05.2010 08:55: Now back to the arguably-interesting issue of speed in the particular problem here: 'Superpollo' had suggested another variant, which I appended to my timeit targets, resulting in: [s for s in strs if s.startswith('a')] took: 5.68393977159 [s for s in strs if s[:1] ==

Re: unable to get Hudson to run unit tests

2010-05-11 Thread Stefan Behnel
j vickroy, 11.05.2010 17:42: Here are the Hudson job | Configure | Execute shell | Command inputs: -- cd level-1 dir nosetests.exe --with-xunit --xunit-file=nosetests.xml --verbose ---

Re: unable to get Hudson to run unit tests

2010-05-11 Thread Stefan Behnel
j vickroy, 11.05.2010 16:46: > Stefan Behnel wrote: No, what Hudson actually does, is, it writes your command(s) into a text file and runs it with the system's shell interpreter (which, unless otherwise configured, is "cmd.exe" on Windows). This is not the behavior I am

Re: Is Python a functional programming language?

2010-05-11 Thread Stefan Behnel
Lawrence D'Oliveiro, 11.05.2010 13:13: Stefan Behnel wrote: But the beauty is that Python is multi-paradigm ... The trouble with “multi-paradigm” is that it offends the zealots on all sides. It’s like saying that, to effect a compromise among multiple conflicting monotheistic religion

Re: unable to get Hudson to run unit tests

2010-05-10 Thread Stefan Behnel
j vickroy, 10.05.2010 17:39: Unfortunately, when "Hudson Build now" is performed, the Hudson Console output, for this job, is: Started by user anonymous Updating svn://vm-svn/GOES data processing/trunk/GOES/13,14,15/SXI/level-1 At revi

Re: Is Python a functional programming language?

2010-05-10 Thread Stefan Behnel
Samuel Williams, 10.05.2010 14:24: Is Python a functional programming language? No. Python is a multi-paradigm language. But it does have functions (and methods) as first-class objects. Is this a paradigm that is well supported by both the language syntax and the general programming APIs?

Re: Fastest way to calculate leading whitespace

2010-05-10 Thread Stefan Behnel
Stefan Behnel, 10.05.2010 08:54: dasacc22, 08.05.2010 19:19: This is a simple question. I'm looking for the fastest way to calculate the leading whitespace (as a string, ie ' '). Here is an (untested) Cython 0.13 solution: from cpython.unicode cimport Py_UNICODE_I

Re: Fastest way to calculate leading whitespace

2010-05-09 Thread Stefan Behnel
dasacc22, 08.05.2010 19:19: This is a simple question. I'm looking for the fastest way to calculate the leading whitespace (as a string, ie ''). Here is an (untested) Cython 0.13 solution: from cpython.unicode cimport Py_UNICODE_ISSPACE def leading_whitespace(unicode ustring):

Re: unable to get Hudson to run unit tests

2010-05-07 Thread Stefan Behnel
j vickroy, 07.05.2010 20:44: I apologize if this is not the appropriate forum for a question about Hudson (http://hudson-ci.org/), but I did not know where else to ask and my web searches have not been fruitful. Certainly nice to read something about Hudson in this forum, which is rare enough.

Re: Teaching Programming

2010-05-04 Thread Stefan Behnel
superpollo, 04.05.2010 17:55: since i have some kind of computer literacy (as opposed to most of my colleagues), some years ago i was kindly asked to try and solve a "simple" particular problem, that is to write a program that generates math exercises (q+a) from an example taken from the textbook

Re: Teaching Programming

2010-05-04 Thread Stefan Behnel
Ed Keith, 04.05.2010 17:43: The PITA is having to keep track of the indentation of each embedded chunk and summing it for each level of indentation. This requires a fair amount of bookkeeping that would not otherwise be necessary. The original prototype simply replaced each embedded chunk with t

Re: How to get xml.etree.ElementTree not bomb on invalid characters in XML file ?

2010-05-04 Thread Stefan Behnel
Barak, Ron, 04.05.2010 16:11: I'm parsing XML files using ElementTree from xml.etree (see code below (and attached xml_parse_example.py)). However, I'm coming across input XML files (attached an example: tmp.xml) which include invalid characters, that produce the following traceback: $ python

Re: Teaching Programming

2010-05-04 Thread Stefan Behnel
Ed Keith, 04.05.2010 15:19: --- On Tue, 5/4/10, Stefan Behnel wrote: Ed Keith, 04.05.2010 14:15: Python is a great language to write in (although I do wish it did a better job with closures). But it is a PITA to generate code for! Interesting. Could you elaborate a bit? Could you give a

Re: Teaching Programming

2010-05-04 Thread Stefan Behnel
superpollo, 04.05.2010 14:46: my template system wants the input to generate the code to stay on a single line ( don't ask :-( ) I hope you don't mind if I still ask. What are you generating and for what templating system? Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Teaching Programming

2010-05-04 Thread Stefan Behnel
Ed Keith, 04.05.2010 14:15: I wrote AsciiLitProg (http://asciilitprog.berlios.de/) in Python. It is a literate programming tool. It generates code from a document. It can generate code in any language the author wants. It would have been a LOT easier to write if it did not generate Python code.

Re: Teaching Programming

2010-05-04 Thread Stefan Behnel
superpollo, 04.05.2010 13:56: Stefan Behnel ha scritto: The question is: why do you have to generate the above code in the first place? Isn't a function enough that does the above? of course! *but* if i must generate on-the-fly python code that defines a function [...] Well, coul

Re: Teaching Programming

2010-05-04 Thread Stefan Behnel
superpollo, 04.05.2010 13:23: Stefan Behnel ha scritto: the main reason why this problem doesn't hurt much in Python is that Python is a dynamic language that can get you extremely far without generating code. It's simply not necessary in most cases, so people don't run into p

Re: Teaching Programming

2010-05-04 Thread Stefan Behnel
superpollo, 04.05.2010 12:28: i think there is an issue if you -- say -- produce python code, from within another programming environment, to be executed on the fly, at least in some instances. there might be problems if for example you generate code from a one-line template. There are a couple

Re: How to get xml.etree.ElementTree not bomb on invalid characters in XML file ?

2010-05-04 Thread Stefan Behnel
Barak, Ron, 04.05.2010 09:01: I'm parsing XML files using ElementTree from xml.etree (see code below (and attached xml_parse_example.py)). However, I'm coming across input XML files (attached an example: tmp.xml) which include invalid characters, that produce the following traceback: $ python

Re: new extension generator for C++

2010-05-04 Thread Stefan Behnel
Rouslan Korneychuk, 03.05.2010 22:44: The only issue is it will not use keyword arguments for overloaded functions (I don't know if that can even be done reliably *and* efficiently. I would need to give it more thought). You should look at the argument unpacking code that Cython generates. It

Re: new extension generator for C++

2010-05-03 Thread Stefan Behnel
Rouslan Korneychuk, 03.05.2010 22:44: So I looked for other solutions and noticed that Py++ (which simply generates Boost.Python code for you) was based on a seperate program called GCCXML. I figured I could use GCCXML and generate code however I wanted. So I did. My program generates human-read

Re: Parser

2010-05-02 Thread Stefan Behnel
dmtr, 03.05.2010 07:39: ANTLR I don't know if it's that easy to get started with though. The companion for-pay book is *most excellent*, but it seems to have been written to the detriment of the normal online docs. IMO ANTLR is much easier to use compared to any other tool simply because it h

Re: [capi-sig] SWIG + expy

2010-05-01 Thread Stefan Behnel
Jack Jansen, 01.05.2010 23:40: I would be very interested in a universal intermediate format for all the interface generators. I'm still using a version of Guido's old bgen, now grudgingly extended to handle C++ and do bidirectional bridging between Python and C++, and while I love and cherish th

Re: Python dot-equals (syntax proposal)

2010-05-01 Thread Stefan Behnel
Tim Chase, 01.05.2010 14:13: On 05/01/2010 12:08 AM, Patrick Maupin wrote: +=, -=, /=, *=, etc. conceptually (and, if lhs object supports in- place operator methods, actually) *modify* the lhs object. Your proposed .= syntax conceptually *replaces* the lhs object (actually, rebinds the lhs symb

Re: matching strings in a large set of strings

2010-05-01 Thread Stefan Behnel
Duncan Booth, 30.04.2010 10:20: So more than 3GB just for the strings (and that's for Python 2.x on Python 3.x you'll need nearly 5GB). Running on a 64 bit version of Python should be fine, but for a 32 bit system a naive approach just isn't going to work. Option 1: use a trie. That should redu

Re: Ignoring XML Namespaces with cElementTree

2010-05-01 Thread Stefan Behnel
Carl Banks, 01.05.2010 12:33: On Apr 29, 10:12 pm, Stefan Behnel wrote: dmtr, 30.04.2010 04:57: I don't want these "{http://www.very_long_url.com}"; in front of my tags. They create performance disaster on large files I seriously doubt that they do. I don't know what k

Re: Ignoring XML Namespaces with cElementTree

2010-04-30 Thread Stefan Behnel
dmtr, 30.04.2010 23:59: I think that's your main mistake: don't remove them. Instead, use the fully qualified names when comparing. Yes. That's what I'm forced to do. Pre-calculating tags like tagChild = "{%s}child" % uri and using them instead of "child". Exactly. Keeps you from introducing

Re: Python dot-equals (syntax proposal)

2010-04-30 Thread Stefan Behnel
J. Cliff Dyer, 30.04.2010 18:20: On Fri, 2010-04-30 at 09:04 -0700, Jabapyth wrote: At least a few times a day I wish python had the following shortcut syntax: vbl.=func(args) this would be equivalent to vbl = vbl.func(args) example: foo = "Hello world" foo.=split(" ") print foo # ['Hello',

Re: replacing words in HTML file

2010-04-29 Thread Stefan Behnel
Cameron Simpson, 30.04.2010 00:47: Here's a function from a script I wrote to bulk edit a web site. I was replacing OBJECT and EMBED nodes with modern versions: def recurse(node): global didmod [...] didmod=True continue recurse(O) > The calling end

Re: Ignoring XML Namespaces with cElementTree

2010-04-29 Thread Stefan Behnel
dmtr, 30.04.2010 04:57: I'm referring to xmlns/URI prefixes. Here's a code example: from xml.etree.cElementTree import iterparse from cStringIO import StringIO xml = """http://www.very_long_url.com";>""" for event, elem in iterparse(StringIO(xml)): print event, elem The output is: endh

Re: matching strings in a large set of strings

2010-04-29 Thread Stefan Behnel
Karin Lagesen, 29.04.2010 11:38: I have approx 83 million strings, all 14 characters long. I need to be able to take another string and find out whether this one is present within the 83 million strings. Now, I have tried storing these strings as a list, a set and a dictionary. I know that findi

Re: Ignoring XML Namespaces with cElementTree

2010-04-28 Thread Stefan Behnel
dmtr, 28.04.2010 03:42: Is there any way to configure cElementTree to ignore the XML root namespace? Default cElementTree (Python 2.6.4) appears to add the XML root namespace URI to _every_ single tag. Certainly not in the serialised XML. Are you referring to the qualified names it uses? St

Re: SWIG + expy

2010-04-27 Thread Stefan Behnel
Yingjie Lan, 28.04.2010 05:53: From: Stefan Behnel Yingjie Lan, 27.04.2010 08:30: Is it possible to use SWIG to parse C/C++, and provide an interface for me to generate some code? I thought it might be good to have SWIG help generate expy files, then generate the python extension via expy

Re: Python 2.X vs. 3.X - level of acceptance?

2010-04-27 Thread Stefan Behnel
Stephan Schulz, 27.04.2010 12:57: I've been using Python for a long while (certainly since it was 1.X), and I've taught some aspects of it in my lectures. I'm now thinking of preparing a new lecture where some of the theoretical concepts will be illustrated by implementations of e.g. automata and

Re: SWIG + expy

2010-04-27 Thread Stefan Behnel
Yingjie Lan, 27.04.2010 08:30: Is it possible to use SWIG to parse C/C++, and provide an interface for me to generate some code? I thought it might be good to have SWIG help generate expy files, then generate the python extension via expy. There have been similar discussions on the Cython maili

Re: Need help with basic DOM XML tree traversing

2010-04-25 Thread Stefan Behnel
Barak, Ron, 25.04.2010 17:06: This is my first try at XML with Python, and though I tried to read on the web, I'm unable to traverse a DOM tree, as my top element seems to be DOCUMENT_NODE and I cannot find a way to get to the nodes below it. You might find the xml.etree.ElementTree package a

Re: [Python3] Reading a binary file and wrtiting the bytes verbatim in an utf-8 file

2010-04-24 Thread Stefan Behnel
Antoine Pitrou, 25.04.2010 02:16: Another possibility is to open the file in binary mode and do the encoding yourself when writing text. This might actually be a better solution, since I'm not sure RTF uses utf-8 by default. That's a lot cleaner as it doesn't use two interfaces to write to the

Re: a.extend(b) better than a+=b ?

2010-04-22 Thread Stefan Behnel
candide, 22.04.2010 09:10: Suppose a and b are lists. What is more efficient in order to extend the list a by appending all the items in the list b ? I imagine a.extend(b)to be more efficient for only appendinding the items from b while a+=b creates a copy of a before appending, right ? Wrong

Re: xml.dom.minidom character encoding

2010-04-21 Thread Stefan Behnel
C. Benson Manica, 21.04.2010 19:19: I have the following simple script running on 2.5.2 on a machine where the default character encoding is "ascii": #!/usr/bin/env python #coding: utf-8 import xml.dom.minidom import codecs str=u"" doc=xml.dom.minidom.parseString( str ) xml=doc.toxml( encoding

Re: Code redundancy

2010-04-20 Thread Stefan Behnel
Alan Harris-Reid, 20.04.2010 15:43: During my Python (3.1) programming I often find myself having to repeat code such as... class1.attr1 = 1 class1.attr2 = 2 class1.attr3 = 3 class1.attr4 = 4 etc. Is there any way to achieve the same result without having to repeat the class1 prefix? Before Pyt

Re: Usable street address parser in Python?

2010-04-18 Thread Stefan Behnel
John Nagle, 17.04.2010 21:23: Is there a usable street address parser available? What kind of street address are you talking about? Only US-American ones? Because street addresses are spelled differently all over the world. Some have house numbers, some use letters or a combination, some ha

Re: extract substring by regex from a text file

2010-04-17 Thread Stefan Behnel
Alessio, 17.04.2010 10:19: I used readlines() to read my text file, then with a for cicle I extract line by line the substrings I need by regular expressions (re.findall()) Note that it's usually more efficient to just run the for-loop over the file object, rather than using readlines() first.

Re: Reactive programming in Python ?

2010-04-16 Thread Stefan Behnel
pca, 16.04.2010 22:02: On Apr 16, 8:28 pm, Stefan Behnel wrote: pca, 16.04.2010 17:18: In fact, I have seeded an open-source project, Yoopf, that enables programming by formula within Python, with the goal of dramatically accelerating the development of the model view in the MVC model

Re: Reactive programming in Python ?

2010-04-16 Thread Stefan Behnel
pca, 16.04.2010 17:18: > In fact, I have seeded an open-source project, Yoopf, that enables > programming by formula within Python, with the goal of dramatically > accelerating the development of the model view in the MVC model. Looks like the example on the main page would work better with the "a

Re: Hi, Everyone: what's the most popular xml parser module on python?

2010-04-15 Thread Stefan Behnel
Jo Chan, 15.04.2010 10:52: > I just want to get the content from a XML. That's not a very specific description of what you want to do. What's "the content"? The plain text content? Or do you care about the structure? And what parts of the structure? > I learn that there are two > modules in pyth

Re: Hi, Everyone: what's the most popular xml parser module on python?

2010-04-15 Thread Stefan Behnel
Shashwat Anand, 15.04.2010 12:29: On Thu, Apr 15, 2010 at 3:50 PM, Stefan Behnel wrote: Shashwat Anand, 15.04.2010 11:55: BeautifulSoup The OP asked for an XML parser. BeatifulSoup can be used as one IMO But it is not an XML parser according to the XML spec. So giving the impression

Re: Hi, Everyone: what's the most popular xml parser module on python?

2010-04-15 Thread Stefan Behnel
Shashwat Anand, 15.04.2010 11:55: > BeautifulSoup The OP asked for an XML parser. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Hi, Everyone: what's the most popular xml parser module on python?

2010-04-15 Thread Stefan Behnel
Jo Chan, 14.04.2010 15:28: Hi, everyone~~~ I am new. What is the most popular xml parser module used on python? Thanks for answering... Why do you want to know? Just out of curiosity, or are you looking for a tool that you can use to get a specific job done? If it's the latter, you may want

Re: how to get text from a html file?

2010-04-14 Thread Stefan Behnel
Emile van Sebille, 14.04.2010 15:24: On 4/13/2010 11:43 PM Stefan Behnel said... rake, 14.04.2010 02:45: On Apr 13, 2:12 pm, Chris Colbert wrote: You should look into beautiful soup http://www.crummy.com/software/BeautifulSoup/ For more complex parsing beautiful soup is definitely the way

Re: how to get text from a html file?

2010-04-13 Thread Stefan Behnel
rake, 14.04.2010 02:45: On Apr 13, 2:12 pm, Chris Colbert wrote: You should look into beautiful soup http://www.crummy.com/software/BeautifulSoup/ For more complex parsing beautiful soup is definitely the way to go. Why would a library that even the author has lost interest in be "the way

Re: how to get text from a html file?

2010-04-13 Thread Stefan Behnel
varnikat t, 13.04.2010 19:58: Can anyone tell me how to get text from a html file?I am trying to display the text of an html file in textview(of glade).If i directly display the file,it shows with html tags and attributes, etc. in textview.I don't want that.I just want the text. Can someone help

Re: Handling quotes in xml.dom text nodes

2010-04-13 Thread Stefan Behnel
Chaim Krause, 13.04.2010 17:26: I am building a web page (HTML 4.01 Transitional) using xml.dom.minidom. I have created a

Re: HTMLParser can't read japanese

2010-04-13 Thread Stefan Behnel
Dodo, 13.04.2010 13:40: Here's a small script to generate again the error running windows 7 with python 3.1 FILE : parseShift.py import urllib.request as url from html.parser import HTMLParser class myParser(HTMLParser): def handle_starttag(self, tag, attrs): print("Start of %s tag : %s"

Re: Write web apps in Python?

2010-04-12 Thread Stefan Behnel
Gilles Ganault, 12.04.2010 11:57: I'd like to make sure I understand what the options are to write web applications in Python: - à la PHP, using Apache's mod_python - using eg. Lighttpd and configuring it to load the Python interpreter every time a Python script is called (www.jakehilton.com/?q

<    3   4   5   6   7   8   9   10   11   12   >