Re: range() vs xrange() Python2|3 issues for performance

2011-08-02 Thread Stefan Behnel
harrismh777, 02.08.2011 09:12: With Python2 you basically have two ways to get a range of numbers: range() , which returns a list, and xrange() , which returns an iterator. With Python3 you must use range(), which produces an iterator; while xrange() does not exist at all (at least not on 3.2).

Re: Early binding as an option

2011-08-03 Thread Stefan Behnel
Chris Angelico, 03.08.2011 00:08: So... Would this potentially produce wrong results? Would it be of any use, or would its benefit be only valued in times when the whole function needs to be redone in C? Note that, in most cases, you do not need to "redo the whole function in C". You can just

Re: Early binding as an option

2011-08-03 Thread Stefan Behnel
Thomas Jollans, 03.08.2011 12:00: JavaScript JITs are smart enough, so a good Python JIT could be as well. Why "could"? There's PyPy if you need it. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: parsing function parameters

2011-08-03 Thread Stefan Behnel
Lee Harr, 03.08.2011 18:02: I am trying to get some information about a function before (and without) calling it. Here is what I have so far. I chose to go with a regular expression, so now I have 2 problems :o) Can't you just use runtime introspection? Take a look at the inspect module. Stef

Re: making my extensions work together

2011-08-03 Thread Stefan Behnel
Mathew, 04.08.2011 03:19: This isn't exactly a Python question but maybe someone here has run into this. I have 2 extensions With "extensions", I assume you mean extension modules for the CPython runtime that are written in C? It would help if you were more specific in your problem descripti

Re: Need help with Python to C code compiler

2011-08-09 Thread Stefan Behnel
Vijay Anantha Murthy, 09.08.2011 07:37: Is there any compiler which will help me convert my python code to proper C code? In my python code I am using the XML.dom.minidom module to parse an xml and process the results obtained by ElementsByTagName. I don't know of any such compiler which will hel

Re: String concatenation - which is the fastest way ?

2011-08-10 Thread Stefan Behnel
przemol...@poczta.fm, 10.08.2011 15:31: On Wed, Aug 10, 2011 at 01:32:06PM +0100, Chris Angelico wrote: On Wed, Aug 10, 2011 at 12:17 PM, wrote: I'd like to write a python (2.6/2.7) script which connects to database, fetches hundreds of thousands of rows, concat them (basically: create XML) an

Re: String concatenation - which is the fastest way ?

2011-08-11 Thread Stefan Behnel
Chris Angelico, 11.08.2011 12:59: On Thu, Aug 11, 2011 at 7:40 AM, wrote: I am not a database developer so I don't want to change the whole process of data flow between applications in my company. Another process is reading this XML from particular Oracle table so I have to put the final XML t

Re: String concatenation - which is the fastest way ?

2011-08-12 Thread Stefan Behnel
przemol...@poczta.fm, 11.08.2011 16:39: On Thu, Aug 11, 2011 at 02:48:43PM +0100, Chris Angelico wrote: On Thu, Aug 11, 2011 at 2:46 PM, wrote: This is the way I am going to use. But what is the best data type to hold so many rows and then operate on them ? List of strings. Take it straight

surprising interaction between function scope and class namespace

2011-08-15 Thread Stefan Behnel
Hi, I just stumbled over this: >>> A = 1 >>> def foo(x): ... A = x ... class X: ... a = A ... return X ... >>> foo(2).a 2 >>> def foo(x): ... A = x ... class X: ... A = A ... return X ... >>> foo(2).A 1 Works that way in

Re: surprising interaction between function scope and class namespace

2011-08-15 Thread Stefan Behnel
Stefan Behnel, 15.08.2011 11:33: I just stumbled over this: >>> A = 1 >>> def foo(x): ... A = x ... class X: ... a = A ... return X ... >>> foo(2).a 2 >>> def foo(x): ... A = x ... class X: ... A = A ... r

Re: Help needed with using SWIG wrapped code in Python

2011-08-15 Thread Stefan Behnel
Vipul Raheja, 15.08.2011 10:08: I have wrapped a library from C++ to Python using SWIG. But I am facing problems while importing and using it in Python. $ python >>> import pyossimtest >>> import pyossim >>> a = ["Image1.png","Image2.png"] >>> b = pyossimtest.Info() >>> b.initialize(len(a),a) Tr

Re: OT

2011-08-19 Thread Stefan Behnel
Daniel Fetchinson, 19.08.2011 10:17: I'll be 59 in a couple of months. That's actually more on topic for one of the alt.test newsgroups. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Design principles: no bool arguments

2011-08-25 Thread Stefan Behnel
Maarten, 25.08.2011 09:52: On Aug 25, 9:13 am, Steven D'Aprano wrote: One design principle often mentioned here (with a certain degree of disagreement[1]) is the idea that as a general rule, you shouldn't write functions that take a bool argument to switch between two slightly different behaviou

Re: Design principles: no bool arguments

2011-08-25 Thread Stefan Behnel
Thomas 'PointedEars' Lahn, 25.08.2011 11:29: Stefan Behnel wrote: It's totally unreadable to find this in the code: data1.merge_with(data2, true); Requires you to either a) know the underlying signature by heart, or b) look it up before understanding the code. It&#x

Re: [ANN]VTD-XML 2.10

2011-02-28 Thread Stefan Behnel
pyt...@bdurham.com, 27.02.2011 13:52: How does VTD-XML compare to XML tools in the stdlib or to 3rd party alternatives like lxml? For one, I'm not aware of any Python wrappers for vtd-xml, despite having seen lots of announcements by Jimmy on this list already (not the python-announce list, *

Re: Idea for removing the GIL...

2011-02-28 Thread Stefan Behnel
Aahz, 01.03.2011 03:02: Carl Banks wrote: The real reason they never replaced the GIL is that fine-grained locking is expensive with reference counting. The only way the cost of finer-grained locking would be acceptable, then, is if they got rid of the reference counting altogether, and that w

Re: Python 3.2 is excellent, but

2011-03-01 Thread Stefan Behnel
jmfauth, 01.03.2011 11:40: __pycache__, no, not for me. This has been discussed before. The 'argument' you presented is usually due to a misunderstanding of how __pycache__ works. Consider reading the PEP. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: I cant import my function from compiled cython module.

2011-03-01 Thread Stefan Behnel
Hi, note that the cython-users mailing list, where you cross-posted this, is the right place to ask. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Checking against NULL will be eliminated?

2011-03-02 Thread Stefan Behnel
Claudiu Popa, 02.03.2011 14:51: Hello Python-list, I don't know how to call it, but the following Python 3.2 code seems to raise a FutureWarning. def func(root=None): nonlocal arg if root: arg += 1 The warning is "FutureWarning: The behavior of this method will change in

Re: python data types in c++ code

2011-03-06 Thread Stefan Behnel
Arthur Mc Coy, 06.03.2011 17:40: Ok, I managed to work with c++ data types in python and can store serialize c++ objects to store in json. Now the task is backward. I wrote a c++ code to get the list of objects using again python interface. The list of objects is returned. PyList. But I can't s

Re: python data types in c++ code

2011-03-06 Thread Stefan Behnel
Arthur Mc Coy, 06.03.2011 19:07: Stephan, you are lead developer over there :))) It's marketing, Let's say, as a core developer of Cython, I'm well aware of it's virtues, and I can tell you that my suggestion is actually well backed by the user feedback we get. You will find some of it on the

Re: python data types in c++ code

2011-03-07 Thread Stefan Behnel
Dan Stromberg, 07.03.2011 03:47: On Sun, Mar 6, 2011 at 10:07 AM, Arthur Mc Coy wrote: You know, they are still using SVN, they are very loosely coupled to the past. about SVN: I'm not sure it's really dying. I hope it will. Yes, a lot of distributed development has moved off of SVN, and

Re: required help in manual sort

2011-03-07 Thread Stefan Behnel
Manjunath N, 07.03.2011 09:48: I'm quite new to python programming. I need help in manually sorting a list which is shuffled. Why do you want to do that? Is this a homework assignment, or are you just looking for an example task to get used to the language? The usual way to sort a lis

Re: SCM

2011-03-08 Thread Stefan Behnel
Cliff Scherer, 08.03.2011 12:42: I am looking for a Python library, which can handle the modelling of material flows in Supply Chains. Note that TLAs do not always uniquely identify a subject. "SCM" is easily read as "source code management" or "software configuration management" on a progra

Re: Is there any python library that parse c++ source code statically

2011-03-13 Thread Stefan Behnel
Francesco Bochicchio, 13.03.2011 10:37: On 13 Mar, 10:14, kuangye wrote: Hi, all. I need to generate other programming language source code from C++ source code for a project. To achieve this, the first step is to "understand" the c++ source code at least in formally. Thus is there any library

Re: Guido rethinking removal of cmp from sort method

2011-03-14 Thread Stefan Behnel
Steven D'Aprano, 13.03.2011 13:59: The removal of cmp from the sort method of lists is probably the most disliked change in Python 3. On the python-dev mailing list at the moment, Guido is considering whether or not it was a mistake. If anyone has any use-cases for sorting with a comparison func

Re: Guido rethinking removal of cmp from sort method

2011-03-15 Thread Stefan Behnel
Paul Rubin, 15.03.2011 09:00: Ian Kelly writes: I would think that you can sort them with key as long as none of the sequences are equal (which would result in an infinite loop using either method). Why not this? Yes you can do something like that, but look how ugly it is compared with using

Re: C++ object in PyObject*?

2011-03-15 Thread Stefan Behnel
Richard, 15.03.2011 16:16: I am wondering, what is the best way to write a Python module as an interface to a C++ class? Cython. http://cython.org Here are a couple of tutorials for your use case: http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html http://docs.cython.org/src/tutori

Re: value of pi and 22/7

2011-03-18 Thread Stefan Behnel
Neil Cerutti, 18.03.2011 13:17: On 2011-03-18, peter wrote: The Old Testament (1 Kings 7,23) says ... "And he made a molten sea, ten cubits from the one brim to the other: it was round all about, and his height was five cubits: and a line of thirty cubits did compass it round about. ". So pi=3

Re: value of pi and 22/7

2011-03-18 Thread Stefan Behnel
Sherm Pendley, 18.03.2011 14:46: Stefan Behnel writes: Neil Cerutti, 18.03.2011 13:17: On 2011-03-18, peter wrote: The Old Testament (1 Kings 7,23) says ... "And he made a molten sea, ten cubits from the one brim to the other: it was round all about, and his height was five cubits:

Re: Calling C++ Modules in Python

2011-03-22 Thread Stefan Behnel
zxpat...@gmail.com, 11.03.2011 23:16: On Mar 11, 2011 4:59pm, Dan Stromberg wrote: On Fri, Mar 11, 2011 at 1:15 PM, Patrick wrote: I saw in the Beginner document that "•Is easily extended by adding new modules implemented in a compiled language such as C or C++. ". While to my investigation, it

Re: Guido rethinking removal of cmp from sort method

2011-03-23 Thread Stefan Behnel
Antoon Pardon, 23.03.2011 14:53: On Sun, Mar 13, 2011 at 12:59:55PM +, Steven D'Aprano wrote: The removal of cmp from the sort method of lists is probably the most disliked change in Python 3. On the python-dev mailing list at the moment, Guido is considering whether or not it was a mistake.

Re: Guido rethinking removal of cmp from sort method

2011-03-23 Thread Stefan Behnel
Antoon Pardon, 23.03.2011 16:14: On Wed, Mar 23, 2011 at 02:59:09PM +0100, Stefan Behnel wrote: Antoon Pardon, 23.03.2011 14:53: On Sun, Mar 13, 2011 at 12:59:55PM +, Steven D'Aprano wrote: The removal of cmp from the sort method of lists is probably the most disliked change in Pyt

Re: Guido rethinking removal of cmp from sort method

2011-03-23 Thread Stefan Behnel
Carl Banks, 23.03.2011 18:23: On Mar 23, 6:59 am, Stefan Behnel wrote: Antoon Pardon, 23.03.2011 14:53: On Sun, Mar 13, 2011 at 12:59:55PM +, Steven D'Aprano wrote: The removal of cmp from the sort method of lists is probably the most disliked change in Python 3. On the pytho

Re: why memoizing is faster

2011-03-24 Thread Stefan Behnel
Andrea Crotti, 24.03.2011 14:48: I was showing a nice memoize decorator to a friend using the classic fibonacci problem. --8<---cut here---start->8--- def memoize(f, cache={}): def g(*args, **kwargs): # first must create a key to store the

Re: Guido rethinking removal of cmp from sort method

2011-03-24 Thread Stefan Behnel
Steven D'Aprano, 25.03.2011 06:46: On Thu, 24 Mar 2011 18:32:11 -0700, Carl Banks wrote: It's probably the least justified builtin other than pow. I don't know about that. Correctly, efficiently and *quickly* implementing the three-argument version of pow is exactly the sort of thing that sho

Re: why memoizing is faster

2011-03-25 Thread Stefan Behnel
Andrea Crotti, 25.03.2011 09:49: Terry Reedy writes: For the reason Stefan explained and hinted above. Try the following instead: def fib_iter(n, _cache = [1,1]): k = len(_cache) if n>= k: for i in range(k, n+1): _cache.append(_cache[i-2] + _cache[i-1]) return _cache[n]

Re: Guido rethinking removal of cmp from sort method

2011-03-25 Thread Stefan Behnel
Antoon Pardon, 25.03.2011 10:21: On Thu, Mar 24, 2011 at 11:49:53PM +, Steven D'Aprano wrote: On Thu, 24 Mar 2011 17:47:05 +0100, Antoon Pardon wrote: However since that seems to be a problem for you I will be more detailed. The original poster didn't ask for cases in which cmp was necessa

Re: Guido rethinking removal of cmp from sort method

2011-03-25 Thread Stefan Behnel
Westley Martínez, 25.03.2011 14:39: On Fri, 2011-03-25 at 07:11 +0100, Stefan Behnel wrote: Steven D'Aprano, 25.03.2011 06:46: On Thu, 24 Mar 2011 18:32:11 -0700, Carl Banks wrote: It's probably the least justified builtin other than pow. I don't know about that. Correctly,

Re: why memoizing is faster

2011-03-25 Thread Stefan Behnel
Terry Reedy, 25.03.2011 21:18: On 3/25/2011 5:16 AM, Stefan Behnel wrote: Terry's version is playing with the fact that default arguments are only instantiated once, i.e. (unless overridden by passing an explicit argument) the "_cache" is shared over all calls to the function.

Re: a basic bytecode to machine code compiler

2011-03-31 Thread Stefan Behnel
Rouslan Korneychuk, 01.04.2011 00:33: I was looking at the list of bytecode instructions that Python uses and I noticed how much it looked like assembly. So I figured it can't be to hard to convert this to actual machine code, to get at least a small boost in speed. I think I recall having read

Re: a basic bytecode to machine code compiler

2011-04-01 Thread Stefan Behnel
Steven D'Aprano, 01.04.2011 14:57: I suggest you check out the competitors: Shedskin is a Python to C++ compiler; Psyco is a JIT specialising compiler; Nuitka claims to be a C++ implementation that compiles to machine code; Berp claims to be a Haskell implementation that does the same; Compyler

Re: Python CPU

2011-04-01 Thread Stefan Behnel
Nobody, 01.04.2011 18:52: Java is a statically-typed language which makes a distinction between primitive types (bool, int, double, etc) and objects. Python is a dynamically-typed language which makes no such distinction. Even something as simple as "a + b" can be a primitive addition, a bigint a

Re: a basic bytecode to machine code compiler

2011-04-02 Thread Stefan Behnel
Steven D'Aprano, 02.04.2011 12:04: On Fri, 01 Apr 2011 17:45:39 +0200, Stefan Behnel wrote: Steven D'Aprano, 01.04.2011 14:57: I suggest you check out the competitors: Shedskin is a Python to C++ compiler; Psyco is a JIT specialising compiler; Nuitka claims to be a C++ implement

Re: XML header with lxml

2011-04-05 Thread Stefan Behnel
Jabba Laci, 04.04.2011 18:54: I want to construct an XML file with lxml but I don't find how to add the '' header. This is not required. According to the XML spec, the default is: So, unless you diverge from these values, you do not need an XML declaration in your file. If you want to out

Re: XML header with lxml

2011-04-05 Thread Stefan Behnel
Chroma Key, 04.04.2011 21:49: On 2011-04-04 18:54:40 +0200, Jabba Laci said: I want to construct an XML file with lxml but I don't find how to add the '' header. from lxml import etree as ET html = ET.Element("html") print ET.tostring(html) Add the "xml_declaration=True" as an argument of e

Re: Teaching Python

2011-04-20 Thread Stefan Behnel
Ben Finney, 20.04.2011 02:06: Dan Stromberg writes: On Tue, Apr 19, 2011 at 4:03 PM, geremy condra wrote: When you say 'hacking', you mean ? Presumably he meant the real meaning of the word, not what the press made up and ran with. To be fair, the press already had its own pejorative m

Re: About threads in python

2011-04-21 Thread Stefan Behnel
dutche, 21.04.2011 15:19: Here's the thing...I had to make a program with threads and after finished, I found some posts and articles in Google about Python and threads, raising the question about if it really implements thread programming or not, because of GIL and the way Python needs to lock s

Re: Snowball to Python compiler

2011-04-22 Thread Stefan Behnel
Terry Reedy, 22.04.2011 05:48: On 4/21/2011 8:25 PM, Paul Rubin wrote: Matt Chaput writes: I'm looking for some code that will take a Snowball program and compile it into a Python script. Or, less ideally, a Snowball interpreter written in Python. (http://snowball.tartarus.org/) Anyone heard

Re: ctypes for AIX

2011-04-22 Thread Stefan Behnel
sjw, 22.04.2011 15:26: I need to!But ctypes can't work on AIX... Need help.. What are you trying to do, and why do you need ctypes for it? Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Py_INCREF() incomprehension

2011-04-26 Thread Stefan Behnel
Ervin Hegedüs, 26.04.2011 11:48: Hello Python users, I'm working on a Python module in C - that's a cryptographic module, which uses a 3rd-party lib from a provider (a bank). This module will encrypt and decrypt the messages for the provider web service. Here is a part of source: static PyObje

Re: ElementTree XML parsing problem

2011-04-27 Thread Stefan Behnel
Hegedüs Ervin, 27.04.2011 21:33: hello, I'm using ElementTree to parse an XML file, but it stops at the second record (id = 002), which contains a non-standard ascii character, ä. Here's the XML: The complaint offered up by the parser is I've checked this xml with your script, I thi

Re: Py_INCREF() incomprehension

2011-05-02 Thread Stefan Behnel
Hegedüs, Ervin, 02.05.2011 08:41: Thomas, I guess this is the point where yo should start printf programing. oh', already done :) FWIW, Cython 0.14+ has special support for gdb now, so, in addition to print and printf debugging, you can also use gdb to explore the state of your application

Re: setup.py rebuilds EVERYTHING on windows?

2011-05-02 Thread Stefan Behnel
Mathew, 02.05.2011 18:45: I'm trying to build an extension (spice-0.12) on windows. Whenever I change a single file, everything gets rebuilt. Did you report this to the authors? I suppose there's a project mailing list? Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Coolest Python recipe of all time

2011-05-02 Thread Stefan Behnel
David Monaghan, 02.05.2011 23:45: On Mon, 2 May 2011 14:58:50 -0600, Ian Kelly wrote: On Mon, May 2, 2011 at 2:48 PM, David Monaghan wrote: On Mon, 2 May 2011 10:33:31 -0700 (PDT), Raymond Hettinger wrote: I think it is time to give some visibility to some of the instructive and very cool re

Re: Coolest Python recipe of all time

2011-05-02 Thread Stefan Behnel
Terry Reedy, 03.05.2011 08:00: On 5/3/2011 1:04 AM, Stefan Behnel wrote: The bad thing about this recipe is that it requires quite a bit of background knowledge in order to infer that the code the developer is looking at is actually correct. The main math knowledge needed is the trivial fact

Re: avro slow?

2011-05-05 Thread Stefan Behnel
Dan Stromberg, 06.05.2011 00:36: Python is often more about programmer efficiency than machine efficiency. With cost per MIPS going down and the price of programmer time going up, it seems a good idea. Especially when you also count the MIPS improvement during the time it takes to write the c

Re: 回复: Re: BeautifulSoup import error

2011-05-05 Thread Stefan Behnel
1011_wxy, 06.05.2011 04:29: 发件人: James Mills On Fri, May 6, 2011 at 11:37 AM, 1011_wxy wrote: I got a import error when I use Python 3.2 to import BeautifulSoup 3.2.0 . Is there any differences between Python 3.2 and other version? This is my first time to use Python3.2 . And the error message

Re: Trying to understand html.parser.HTMLParser

2011-05-18 Thread Stefan Behnel
Andrew Berg, 17.05.2011 03:05: lxml looks promising, but it doesn't say anywhere whether it'll work on Python 3 or not Well, it pretty clearly states that on the PyPI page, but I also added it to the project home page now. lxml 2.3 works with any CPython version from 2.3 to 3.2. Stefan --

Re: Trying to understand html.parser.HTMLParser

2011-05-18 Thread Stefan Behnel
Andrew Berg, 19.05.2011 02:39: On 2011.05.18 03:30 AM, Stefan Behnel wrote: Well, it pretty clearly states that on the PyPI page, but I also added it to the project home page now. lxml 2.3 works with any CPython version from 2.3 to 3.2. Thank you. I never would've looked at PyPI for info

Re: Abandoning Python

2011-05-22 Thread Stefan Behnel
John J Lee, 22.05.2011 17:58: Daniel Kluev writes: Also, most of these complaints could be solved by using correct python dialect for particular task - RPython, Cython and so on. Different topic. Why? Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Why did Quora choose Python for its development?

2011-05-23 Thread Stefan Behnel
Beliavsky, 20.05.2011 18:39: I thought this essay on why one startup chose Python was interesting. Since everyone seems to be hot flaming at their pet languages in this thread, let me quickly say this: Thanks for sharing the link. Stefan -- http://mail.python.org/mailman/listinfo/python-li

Re: bug in str.startswith() and str.endswith()

2011-05-26 Thread Stefan Behnel
Roy Smith, 27.05.2011 03:13: Ethan Furman wrote: --> 'this is a test'.startswith('this') True --> 'this is a test'.startswith('this', None, None) Traceback (most recent call last): File "", line 1, in TypeError: slice indices must be integers or None or have an __index__ method [...]

Re: Python's super() considered super!

2011-05-27 Thread Stefan Behnel
Steven D'Aprano, 27.05.2011 18:06: On Fri, 27 May 2011 08:31:40 -0700, sturlamolden wrote: On 27 Mai, 17:05, Duncan Booth wrote: Oops. There's a reason why Python 2 requires you to be explicit about the class; you simply cannot work it out automatically at run time. Python 3 fixes this by wo

Re: Case-insensitive string equality

2017-09-05 Thread Stefan Behnel
Steve D'Aprano schrieb am 02.09.2017 um 02:31: > - the German eszett, ß, which has two official[1] uppercase forms: 'SS' > and an uppercase eszett I wonder if there is an equivalent to Godwin's Law with respect to character case related discussions and the German ß. Stefan -- https://mail.pytho

Re: Stdlib, what's in, what's out

2017-09-19 Thread Stefan Behnel
John Ladasky schrieb am 19.09.2017 um 08:54: > I have come to understand from your other posts that adding something to > the stdlib imposes significant constraints on the release schedules of > those modules. I can appreciate the hassle that might cause. Still, > now I wonder what I might be mis

Re: Even Older Man Yells At Whippersnappers

2017-09-19 Thread Stefan Behnel
Stefan Ram schrieb am 19.09.2017 um 17:00: > D'Arcy Cain writes: >> of course, I use calculators and computers but I still understand the >> theory behind what I am doing. > > I started out programming in BASIC. Today, I use Python, > the BASIC of the 21st century. Python has no GOTO, but wh

Re: How does CPython build it's NEWS or changelog?

2017-09-21 Thread Stefan Behnel
Hartmut Goebel schrieb am 21.09.2017 um 10:59: > I just discovered that CPython now uses Misc/NEWS.d/next to collect > changes an there are a lot of Misc/NEWS/*.rst files for the respective > released version. I'm investigating whether to adopt this for PyInstaller. > > What is the tooling for thi

Re: Parentheses (as after "print")

2017-09-26 Thread Stefan Behnel
Stefan Ram schrieb am 26.09.2017 um 17:56: > Why do we newbies write »print 2«? Here's another hint. > This is an original transcript of what happened to me today: > > |>>> import( operator ) > | File "", line 1 > |import( operator ) > | ^ > |SyntaxError: invalid syntax > | > |>>

Re: Return str to a callback raise a segfault if used in string formating

2017-10-14 Thread Stefan Behnel
Vincent Vande Vyvre schrieb am 13.10.2017 um 13:18: > Le 13/10/17 à 12:39, Paul Moore a écrit : >> As a specific suggestion, I assume the name of the created file is a >> string object constructed in the C extension code, somehow. The fact >> that you're getting the segfault with some uses of that

Re: c code generator from python

2018-02-19 Thread Stefan Behnel
bhattacharya.kush...@gmail.com schrieb am 17.01.2018 um 12:03: > Is there any python framework or any tool as which can generate C code from > python code as it is . http://cython.org/ Stefan -- https://mail.python.org/mailman/listinfo/python-list

Re: Help on convert PyObject to string (c) Python 3.6

2018-02-19 Thread Stefan Behnel
Jason Qian via Python-list schrieb am 04.02.2018 um 17:52: >This is the case of calling python from c and the python function will > return a string. Hi Jason, I noticed that you ran into a couple of problems using the C-API, so I suggest looking into Cython instead. It basically translates

Re: How to make Python run as fast (or faster) than Julia

2018-02-23 Thread Stefan Behnel
Steven D'Aprano schrieb am 22.02.2018 um 11:59: > https://www.ibm.com/developerworks/community/blogs/jfp/entry/Python_Meets_Julia_Micro_Performance?lang=en Thanks for sharing, Steven. While it was already suggested between the lines in some of the replies, I'd like to emphasise that the combinati

The Cython compiler is 20 years old today !

2022-04-04 Thread Stefan Behnel
Dear Python community, it's now 20 years since Greg Ewing posted his first announcement of Pyrex, the tool that is now known and used under the name Cython. https://mail.python.org/pipermail/python-list/2002-April/126661.html It was a long way, and I've written up some of it in a blog post:

Re: PEP suggestion: Uniform way to indicate Python language version

2016-08-21 Thread Stefan Behnel
Steven D'Aprano schrieb am 22.08.2016 um 07:35: > if sys.version < '3': > import mymodule2 as mymodule > else: > import mymodule3 as mymodule This condition is going to fail when Python 30.0 comes out. Stefan -- https://mail.python.org/mailman/listinfo/python-list

Re: PEP suggestion: Uniform way to indicate Python language version

2016-08-21 Thread Stefan Behnel
Stefan Behnel schrieb am 22.08.2016 um 08:03: > Steven D'Aprano schrieb am 22.08.2016 um 07:35: >> if sys.version < '3': >> import mymodule2 as mymodule >> else: >> import mymodule3 as mymodule > > This condition is going to fail when P

Re: Helloworld with Python C extension

2016-08-29 Thread Stefan Behnel
Ganesh Pal schrieb am 29.08.2016 um 19:30: > I need you input on the below hello world program. I a m trying to add a > python binding which will return the character for the given index . I am > on Python 2.7 and linux > > Example : > >>> string ='helloworld' > >>> dda_hello(5) > >>> 'w' >

Re: C Python extension to export an Function

2016-09-01 Thread Stefan Behnel
Ganesh Pal schrieb am 01.09.2016 um 14:30: > On Thu, Sep 1, 2016 at 12:32 PM, dieter wrote: >> Ganesh Pal writes: >>> Iam pretty new to C Python extension , I was able to export few simple >>> modules to python and it look like the cool thing to do ... >> >> Maybe, it is a good idea to have a look

Re: C Python extension to export an Function

2016-09-01 Thread Stefan Behnel
Ganesh Pal schrieb am 01.09.2016 um 17:24: > Thanks stefan and Gollwitzer , good to know there are many ways to do this > i.e via cython or SWIG but the C/Python API > is probably the most widely used method It certainly was, years ago, but I honestly doubt

Re: Cython taking more time than regular Python

2016-09-19 Thread Stefan Behnel
Peter Otten schrieb am 19.09.2016 um 14:55: > In [7]: %%cython > def omega(int n): > cdef long i > cdef long result = 0 > for i in range(n): result += i > return result >...: > > In [8]: %timeit omega(10) > 1 loops, best of 3: 91.6 µs per loop Note that this is the wo

Re: windows utf8 & lxml

2016-12-26 Thread Stefan Behnel
Hi! Sayth Renshaw schrieb am 20.12.2016 um 12:53: > I have been trying to get a script to work on windows that works on mint. The > key blocker has been utf8 errors, most of which I have solved. > > Now however the last error I am trying to overcome, the solution appears to > be to use the .dec

Re: LXML: can't register namespace

2018-03-09 Thread Stefan Behnel
Andrew Z schrieb am 07.03.2018 um 05:03: > Hello, > with 3.6 and latest greatest lxml: > > from lxml import etree > > tree = etree.parse('Sample.xml') > etree.register_namespace('','http://www.example.com') The default namespace prefix is spelled None (because there is no prefix for it) and not

Re: LXML: can't register namespace

2018-03-09 Thread Stefan Behnel
Steven D'Aprano schrieb am 09.03.2018 um 12:41: > On Fri, 09 Mar 2018 10:22:23 +0100, Stefan Behnel wrote: > >> Andrew Z schrieb am 07.03.2018 um 05:03: >>> Hello, >>> with 3.6 and latest greatest lxml: >>> >>> from lxm

Re: LXML: can't register namespace

2018-03-09 Thread Stefan Behnel
Peter Otten schrieb am 09.03.2018 um 14:11: > Stefan Behnel wrote: > >> Andrew Z schrieb am 07.03.2018 um 05:03: >>> Hello, >>> with 3.6 and latest greatest lxml: >>> >>> from lxml import etree >>> >>> tree = etree.parse(&#x

Re: Writing a C extension - borrowed references

2018-03-21 Thread Stefan Behnel
Tom Evans via Python-list schrieb am 20.03.2018 um 18:03: > On Tue, Mar 20, 2018 at 4:38 PM, Chris Angelico wrote: >> BTW, have you looked into Cython? It's smart enough to take care of a >> lot of this sort of thing for you. > > I did a bit; this work is to replace our old python 2 SAML client, >

Re: Getting Unicode decode error using lxml.iterparse

2018-05-23 Thread Stefan Behnel
dieter schrieb am 23.05.2018 um 08:25: > If the encoding is not specified, "lxml" will try to determine it > and finally defaults to "utf-8" (which seems to be the correct encoding > for your case). Being an XML parser, it does not do that. XML parsers are designed to reject non-wellformed content

Re: Getting Unicode decode error using lxml.iterparse

2018-05-23 Thread Stefan Behnel
digi...@gmail.com schrieb am 23.05.2018 um 00:56: > I'm trying to read my iTunes library in Python using iterparse. My current > stub is: > > Snip > > import sys > import datetime > import xml.etree.ElementTree as ET > import argparse > import re > > class Library: > > unmars

Re: List replication operator

2018-05-24 Thread Stefan Behnel
Steven D'Aprano schrieb am 25.05.2018 um 04:25: > On Thu, 24 May 2018 15:12:09 -0400, Ned Batchelder wrote: > >> On 5/24/18 2:17 PM, Steven D'Aprano wrote: > [...] >>> But what do people think about proposing a new list replication with >>> copy operator? >>> >>> [[]]**5 >>> >>> would return

Re: List replication operator

2018-05-25 Thread Stefan Behnel
Peter Otten schrieb am 25.05.2018 um 09:28: > Steven D'Aprano wrote: > >> But what do people think about proposing a new list replication with copy >> operator? >> >> [[]]**5 >> >> would return a new list consisting of five shallow copies of the inner >> list. > > Yet another arcanum to learn

Re: Looking for a recent quote about dynamic typing, possibly on this list

2018-07-07 Thread Stefan Behnel
Ben Finney schrieb am 07.07.2018 um 03:38: > Steven D'Aprano writes: > >> Somebody gave a quote about dynamic typing, along the lines of >> >> "Just because a language allows a lot of dynamic features, doesn't mean >> people's code uses a lot of dynamism." > > You did refer us to http://lambda-

Re: Thread-safe way to add a key to a dict only if it isn't already there?

2018-07-07 Thread Stefan Behnel
Marko Rauhamaa schrieb am 07.07.2018 um 15:41: > Steven D'Aprano : >> On Sat, 07 Jul 2018 02:51:41 +0900, INADA Naoki wrote: >>> D.setdefault('c', None) >> >> Oh that's clever! > > Is that guaranteed to be thread-safe? The documentation ( s://docs.python.org/3/library/stdtypes.html#dict.setdefault

Re: Tracking a memory leak in C extension - interpreting the output of PYTHONMALLOCSTATS

2018-07-28 Thread Stefan Behnel
Bartosz Golaszewski schrieb am 24.07.2018 um 13:05: > Ok I've found the problem and it's my fault. From tp_dealloc's documentation: > > --- > The destructor function should free all references which the instance > owns, free all memory buffers owned by the instance (using the freeing > function co

Re: lxml namespace as an attribute

2018-08-17 Thread Stefan Behnel
Skip Montanaro schrieb am 15.08.2018 um 23:25: > Much of XML makes no sense to me. Namespaces are one thing. If I'm > parsing a document where namespaces are defined at the top level, then > adding namespaces=root.nsmap works when calling the xpath method. I > more-or-less get that. > > What I don

Re: Calling an unbound method in C using the Public API

2018-08-29 Thread Stefan Behnel
Matthieu Dartiailh schrieb am 29.08.2018 um 16:33: > I am one of the maintainer of the atom library > (https://github.com/nucleic/atom ). This > library provides low-memory footprint Python objects, descriptors and > containers enforcing type validation, implemen

Re: I'd like to add -march=native to my pip builds

2016-04-08 Thread Stefan Behnel
Neal Becker schrieb am 08.04.2016 um 15:27: > I'd like to add -march=native to my pip builds. How can I do this? First of all, make sure you don't install binary packages and wheels. Changing the C compiler flags will require source builds. Then, it should be enough to set the CFLAGS environment

Re: How are you supposed to define subclasses in C?

2016-04-21 Thread Stefan Behnel
Random832 schrieb am 21.04.2016 um 18:35: > I was trying to write a proof of concept on including descriptors (e.g. > a "sys.recursionlimit" instead of set/get methods) in the sys module, > and couldn't figure out how to "properly" define a type using > PyType_FromSpecWithBases. Everything I tried

Re: Which one is the best XML-parser?

2016-07-02 Thread Stefan Behnel
Random832 schrieb am 24.06.2016 um 15:09: > On Fri, Jun 24, 2016, at 02:39, dieter wrote: >> You want an incremental parser if the XML documents are so huge that >> you must process them incrementally rather than have a data structure >> representing the whole document (in memory). Incremental pars

Re: Quick poll: gmean or geometric_mean

2016-07-09 Thread Stefan Behnel
Ethan Furman schrieb am 09.07.2016 um 08:27: > On 07/08/2016 10:49 PM, Random832 wrote: >> On Sat, Jul 9, 2016, at 01:26, Steven D'Aprano wrote: > >>> hmean and gmean >>> >>> harmonic_mean and geometric_mean >> >> The latter, definitely. > > My preference is also for the latter. However, if the

Re: usage of functools.partial in in parallelism

2016-07-31 Thread Stefan Behnel
Sivan Greenberg schrieb am 30.07.2016 um 23:15: > I'm wondering about the use of partial in writing parallel code. Is is it > quicker than re-evaluating arguments for a multiple session.get()'s method > with different , for example (of requests) ? > > Or maybe it is used to make sure the argumen

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