Re: __dict__ attribute for built-in types

2011-10-27 Thread Steven D'Aprano
On Fri, 28 Oct 2011 01:36:41 +0200, candide wrote: > Le 28/10/2011 00:57, Hrvoje Niksic a écrit : > >> was used at class definition time to suppress it. Built-in and >> extension types can choose whether to implement __dict__. >> >> > Is it possible in the CPython implementation to write somethi

Re: __dict__ attribute for built-in types

2011-10-27 Thread Nobody
On Thu, 27 Oct 2011 12:08:45 +0200, candide wrote: > I realize that built-in types objects don't provide a __dict__ attribute > and thereby i can't set an attribute to a such object, for instance Note that possession or absence of a __dict__ attribute doesn't necessarily mean that you can or can

Re: Presenting recursive dict (json_diff)

2011-10-27 Thread Terry Reedy
On 10/27/2011 4:58 PM, Matej Cepl wrote: Dne 27.10.2011 21:49, Terry Reedy napsal(a): Use '_append', etc, much like namedtuple does, for the same reason. Right, done. What about the presentation issue? Any ideas? No. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list

Re: Need Windows user / developer to help with Pynguin

2011-10-27 Thread Terry Reedy
On 10/27/2011 3:38 PM, Lee Harr wrote: I develop the free python-based turtle graphics application pynguin. http://pynguin.googlecode.com/ Lately I have been getting a lot of positive comments from people who use the program, but I am also getting a lot of feedback from people on Windows (mos

Re: Dynamically creating properties?

2011-10-27 Thread Lie Ryan
On 10/28/2011 08:48 AM, DevPlayer wrote: On Oct 27, 3:59 pm, Andy Dingley wrote: I have some XML, with a variable and somewhat unknown structure. I'd like to encapsulate this in a Python class and expose the text of the elements within as properties. How can I dynamically generate properties (

Re: Unicode literals and byte string interpretation.

2011-10-27 Thread Chris Angelico
On Fri, Oct 28, 2011 at 2:05 PM, Fletcher Johnson wrote: > If I create a new Unicode object u'\x82\xb1\x82\xea\x82\xcd' how does > this creation process interpret the bytes in the byte string? Does it > assume the string represents a utf-16 encoding, at utf-8 encoding, > etc...? > > For reference

Re: Unicode literals and byte string interpretation.

2011-10-27 Thread David Riley
On Oct 27, 2011, at 11:05 PM, Fletcher Johnson wrote: > If I create a new Unicode object u'\x82\xb1\x82\xea\x82\xcd' how does > this creation process interpret the bytes in the byte string? Does it > assume the string represents a utf-16 encoding, at utf-8 encoding, > etc...? > > For reference th

Re: Assigning generator expressions to ctype arrays

2011-10-27 Thread Terry Reedy
On 10/27/2011 8:09 PM, Patrick Maupin wrote: > x[:] = (x for x in xrange(32)) This translates to s.__setitem__(slice(None,None), generator_object) where 'generator_object' is completely opaque, except that it will yield 0 to infinity objects in response to next() before raising StopIteration.

Unicode literals and byte string interpretation.

2011-10-27 Thread Fletcher Johnson
If I create a new Unicode object u'\x82\xb1\x82\xea\x82\xcd' how does this creation process interpret the bytes in the byte string? Does it assume the string represents a utf-16 encoding, at utf-8 encoding, etc...? For reference the string is これは in the 'shift-jis' encoding. -- http://mail.python

Re: __dict__ attribute for built-in types

2011-10-27 Thread Patrick Maupin
On Oct 27, 9:46 pm, candide wrote: > Le 28/10/2011 02:02, MRAB a crit : > > > > > No, built-in classes written in C have certain limitations, but why > > would you want to do that anyway? > > Mainly for learning purpose and Python better understanding. > > Actually, I have a class of mine for draw

Re: __dict__ attribute for built-in types

2011-10-27 Thread alex23
On Oct 28, 8:52 am, candide wrote: > No but I'm expecting from Python documentation to mention the laws of > Python ... It's not a "law", it's an _implementation detail_. The docs don't tend to mention every such decision made because that's what the source is for. > But beside this, how to reco

Re: __dict__ attribute for built-in types

2011-10-27 Thread candide
Le 28/10/2011 02:02, MRAB a écrit : No, built-in classes written in C have certain limitations, but why would you want to do that anyway? Mainly for learning purpose and Python better understanding. Actually, I have a class of mine for drawing graphs with the Graphviz software. The nodes

Re: __dict__ attribute for built-in types

2011-10-27 Thread Terry Reedy
On 10/27/2011 6:52 PM, candide wrote: No but I'm expecting from Python documentation to mention the laws of Python ... The details of CPython builtin classes are not laws of Python. It *is* a 'law of Python' that classes can use 'slots = ' to restrict the attributes of instances. By implicat

Re: Problem using execvp

2011-10-27 Thread Nobody
On Thu, 27 Oct 2011 01:57:55 -0700, faucheuse wrote: > I get this error : OSError : [Errno 8] Exec format error. The most likely reason for this error is a missing or invalid shebang, e.g.: #!/usr/bin/python or: #!/usr/bin/env python The "#!" must be the first two bytes in the f

NLTK and package structure

2011-10-27 Thread Steven Bird
The Natural Language Toolkit (NLTK) is a suite of open source Python packages for natural language processing, available at http://nltk.org/, together with an O'Reilly book which is available online for free. Development is now hosted at http://github.com/nltk -- get it here: g...@github.com:nltk/

Re: Dynamically creating properties?

2011-10-27 Thread DevPlayer
Second error def isvalid_named_reference( astring ): # "varible name" is really a named_reference import __builtin__# add line -- http://mail.python.org/mailman/listinfo/python-list

Re: Assigning generator expressions to ctype arrays

2011-10-27 Thread Patrick Maupin
On Oct 27, 5:31 pm, Steven D'Aprano wrote: > From the outside, you can't tell how big a generator expression is. It has no > length: I understand that. > Since the array object has no way of telling whether the generator will have > the correct size, it refuses to guess. It doesn't have to gu

Re: __dict__ attribute for built-in types

2011-10-27 Thread MRAB
On 28/10/2011 00:36, candide wrote: Le 28/10/2011 00:57, Hrvoje Niksic a écrit : was used at class definition time to suppress it. Built-in and extension types can choose whether to implement __dict__. Is it possible in the CPython implementation to write something like this : "foo".bar = 4

Re: __dict__ attribute for built-in types

2011-10-27 Thread candide
Le 28/10/2011 00:57, Hrvoje Niksic a écrit : was used at class definition time to suppress it. Built-in and extension types can choose whether to implement __dict__. Is it possible in the CPython implementation to write something like this : "foo".bar = 42 without raising an attribute erro

Re: Dynamically creating properties?

2011-10-27 Thread DevPlayer
At least one error: change: > for astr in dir(__builtins__): to: for astr in __builtins__.__dict__: -- http://mail.python.org/mailman/listinfo/python-list

Re: Dynamically creating properties?

2011-10-27 Thread DevPlayer
Personally I like to use this function instead of a "try: except:" because try-except will allow names like __metaclass__. Remember, setattr(obj, attr_name, value) allows attr_name to be any valid str(). For example: '!@kdafk11', or '1_1', '1e-20', '0.0', '*one', '\n%%', etc. def isvalid_named_re

Re: __dict__ attribute for built-in types

2011-10-27 Thread Hrvoje Niksic
candide writes: > But beside this, how to recognise classes whose object doesn't have a > __dict__ attribute ? str, list and others aren't classes, they are types. While all (new-style) classes are types, not all types are classes. It's instances of classes (types created by executing the "cla

Re: __dict__ attribute for built-in types

2011-10-27 Thread candide
Le 28/10/2011 00:19, Steven D'Aprano a écrit : What, you think it goes against the laws of physics that nobody thought to mention it in the docs? No but I'm expecting from Python documentation to mention the laws of Python ... But beside this, how to recognise classes whose object does

Re: __dict__ attribute for built-in types

2011-10-27 Thread Chris Angelico
On Fri, Oct 28, 2011 at 1:36 AM, Duncan Booth wrote: > Try thinking that one through. Imagine you could set up a dictionary the > way you describe > > A dict with itself as its own __dict__ becomes like a javascript object > where subscripting and attribute access are mostly interchangeable. Yeah

Re: Assigning generator expressions to ctype arrays

2011-10-27 Thread Steven D'Aprano
On Thu, 27 Oct 2011 13:34:28 -0700, Patrick Maupin wrote: > Bug or misunderstanding? > > Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) [GCC 4.5.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. x = 32 * [0] x[:] = (x for x in xrange(32)) from

Re: __dict__ attribute for built-in types

2011-10-27 Thread Steven D'Aprano
On Thu, 27 Oct 2011 16:01:25 +0200, candide wrote: > OK, thanks for the information abouts the slots. Nevertheless, this > cannot answer completely my question. Some builtin types like string, > lists, integer, float, dictionaries, etc have the property that > instances of those types don't provid

Re: Dynamically creating properties?

2011-10-27 Thread DevPlayer
On Oct 27, 3:59 pm, Andy Dingley wrote: > I have some XML, with a variable and somewhat unknown structure. I'd > like to encapsulate this in a Python class and expose the text of the > elements within as properties. > > How can I dynamically generate properties (or methods) and add them to > my cl

Re: Presenting recursive dict (json_diff)

2011-10-27 Thread Matej Cepl
Dne 27.10.2011 21:49, Terry Reedy napsal(a): Use '_append', etc, much like namedtuple does, for the same reason. Right, done. What about the presentation issue? Any ideas? Best, Matěj -- http://mail.python.org/mailman/listinfo/python-list

Assigning generator expressions to ctype arrays

2011-10-27 Thread Patrick Maupin
Bug or misunderstanding? Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x = 32 * [0] >>> x[:] = (x for x in xrange(32)) >>> from ctypes import c_uint >>> x = (32 * c_uint)() >>> x[:] = xrange(32) >>

Re: Dynamically creating properties?

2011-10-27 Thread John Gordon
In Andy Dingley writes: > How can I dynamically generate properties (or methods) and add them to > my class? I can easily produce a dictionary of the required element > names and their text values, but how do I create new properties at run > time? You can set dynamic attributes on class objec

Dynamically creating properties?

2011-10-27 Thread Andy Dingley
I have some XML, with a variable and somewhat unknown structure. I'd like to encapsulate this in a Python class and expose the text of the elements within as properties. How can I dynamically generate properties (or methods) and add them to my class? I can easily produce a dictionary of the requi

Re: spawnl issues with Win 7 access rights

2011-10-27 Thread Terry Reedy
On 10/27/2011 6:36 AM, Tim Golden wrote: On 27/10/2011 11:27, Propad wrote: the suggestion to add the optional second parameter fixed the problem, spawnl now works on the Win 7 computer I'm responsible for (with Python 2.2). So the suggested cause seems to be right. FWIW, although it's not obv

Re: Presenting recursive dict (json_diff)

2011-10-27 Thread Terry Reedy
On 10/27/2011 4:50 AM, mcepl wrote: Hi, I have here a simple script (https://gitorious.org/json_diff/mainline) which makes a diff between two JSON files. So for JSON objects { "a": 1, "b": 2, "son": { "name": "Janošek" } } and { "a": 2, "c": 3, "dau

Re: Need Windows user / developer to help with Pynguin

2011-10-27 Thread Andrew Berg
On 10/27/2011 2:38 PM, Lee Harr wrote: > I am hoping someone can look at what is there and come up with a > reliable method or a simple set of steps that people can follow to get > up and running. Hopefully without having to resort to the command > prompt. > > I started a wiki page here: > http://

Need Windows user / developer to help with Pynguin

2011-10-27 Thread Lee Harr
I develop the free python-based turtle graphics application pynguin. http://pynguin.googlecode.com/ Lately I have been getting a lot of positive comments from people who use the program, but I am also getting a lot of feedback from people on Windows (mostly beginners) who are having trouble get

Re: python logging multiple processes to one file (via socket server)

2011-10-27 Thread 88888 Dihedral
Well, please check the byte code compiled results. This is useful. I know that a lot people are working on increasing the speed of execution scripts written in python, say, psyco, pyrex for packages released! -- http://mail.python.org/mailman/listinfo/python-list

Re: python logging multiple processes to one file (via socket server)

2011-10-27 Thread bobicanprogram
On Oct 27, 6:09 am, Gelonida N wrote: > Hi, > > I have a rather 'simple' problem. > Logging from multiple processes to the same file AND be sure, that no > log message is lost, > > 1.) Log multiple processes to one file: > -- > > I have a python program, whi

xmlrpclib threadsafe?

2011-10-27 Thread quarterlife
I need to talk to an xmlrpc server. I open one connection and then create a pile of threads communicating to that server. Based on some limited testing, it seems to work really well. The next step is to turn it into a pool. But before I continue, the question is: Does anyone know if the xmlrpcl

Re: python logging multiple processes to one file (via socket server)

2011-10-27 Thread Vinay Sajip
On Oct 27, 11:09 am, Gelonida N wrote: > "The following section documents this approach in more detail and > includes a working socket receiver which can be used as a starting point > for you to adapt in your own applications." > > Somehow I have a mental block though and fail to see the 'followin

Re: __dict__ attribute for built-in types

2011-10-27 Thread Amirouche Boubekki
> But beside this, how to recognise classes whose object doesn't have a > __dict__ attribute ? > Why do you need to access __dict__ ? maybe dir is enough see the other message -- http://mail.python.org/mailman/listinfo/python-list

Re: __dict__ attribute for built-in types

2011-10-27 Thread Amirouche Boubekki
2011/10/27 candide > I realize that built-in types objects don't provide a __dict__ attribute > and thereby i can't set an attribute to a such object, for instance > > > >>> a=[42,421] > >>> a.foo="bar" > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'list' object h

Re: Philosophical Python: 2*b or not 2*b

2011-10-27 Thread John Ladasky
On Oct 27, 1:11 am, Andreas Neudecker wrote: > Any more philsophical Python code out there? That is the question. -- http://mail.python.org/mailman/listinfo/python-list

Re: Forking simplejson

2011-10-27 Thread Amirouche Boubekki
2011/10/27 Chris Rebert > On Wed, Oct 26, 2011 at 2:14 AM, Amirouche Boubekki > wrote: > > Héllo, > > > > I would like to fork simplejson [1] and implement serialization rules > based > > on protocols instead of types [2], plus special cases for protocol free > > objects, that breaks compatibili

Re: __dict__ attribute for built-in types

2011-10-27 Thread Duncan Booth
Chris Angelico wrote: > On Thu, Oct 27, 2011 at 10:03 PM, Duncan Booth > wrote: >> Types without a __dict__ use less memory. Also, if you couldn't have a >> type that didn't have a `__dict__` then any `dict` would also need its >> own `__dict__` which would either result in infinite memory use or

Re: inserting \ in regular expressions

2011-10-27 Thread John Roth
On Oct 26, 2:47 pm, Dave Angel wrote: > On 10/26/2011 03:48 PM, Ross Boylan wrote: > > > > > > > > > I want to replace every \ and " (the two characters for backslash and > > double quotes) with a \ and the same character, i.e., > > \ ->  \\ > > " ->  \" > > > I have not been able to figure out ho

Re: Forking simplejson

2011-10-27 Thread Chris Rebert
On Wed, Oct 26, 2011 at 2:14 AM, Amirouche Boubekki wrote: > Héllo, > > I would like to fork simplejson [1] and implement serialization rules based > on protocols instead of types [2], plus special cases for protocol free > objects, that breaks compatibility. The benefit will be a better API for >

Re: Forking simplejson

2011-10-27 Thread Chris Rebert
On Thu, Oct 27, 2011 at 6:55 AM, Amirouche Boubekki wrote: > >>> +---+---+ >>> | Python protocol | JSON | >>> | or special case | | >>> +===+===+ >>> | (ø) __json__ | see (ø) | >>> +---+---| >>>      | map        

Re: __dict__ attribute for built-in types

2011-10-27 Thread candide
Le 27/10/2011 13:03, Duncan Booth a écrit : -- where the official documentation refers to this point ? See http://docs.python.org/reference/datamodel.html for the docs about __slots__ There is also the API documentation which describes at a low level how to control whether or not instances

[ANN] pyKook 0.6.0 - task automation tool for Python, similar to Rake or Ant

2011-10-27 Thread Makoto Kuwata
Hi, I have released pyKook 0.6.0. http://pypi.python.org/pypi/Kook/0.6.0 http://www.kuwata-lab.com/kook/ http://www.kuwata-lab.com/kook/pykook-users-guide.html In this release, a lot of enhancements are introduced. pyKook Overview --- pyKook is a task automation tool for Python, si

Re: Forking simplejson

2011-10-27 Thread Amirouche Boubekki
> +---+---+ >> | Python protocol | JSON | >> | or special case | | >> +===+=**==+ >> | (ø) __json__ | see (ø) | >> +---+-**--| >> | map | object| >> > > I am curious what you mean by the '

Re: __dict__ attribute for built-in types

2011-10-27 Thread Chris Angelico
On Thu, Oct 27, 2011 at 10:03 PM, Duncan Booth wrote: > Types without a __dict__ use less memory. Also, if you couldn't have a > type that didn't have a `__dict__` then any `dict` would also need its > own `__dict__` which would either result in infinite memory use or > recursive dictionaries. >

Re: Forking simplejson

2011-10-27 Thread Paul Kölle
Am 26.10.2011 19:34, schrieb Nathan Rice: Since this happily went off to the wrong recipient the first time... The python json module/simpljson are badly in need of an architecture update. The fact that you can't override the encode method of JSONEncoder and have it work reliably without monkey

Re: __dict__ attribute for built-in types

2011-10-27 Thread Duncan Booth
candide wrote: > I realize that built-in types objects don't provide a __dict__ attribute > and thereby i can't set an attribute to a such object, for instance > > > >>> a=[42,421] > >>> a.foo="bar" > Traceback (most recent call last): >File "", line 1, in > AttributeError: 'list' object

Re: __dict__ attribute for built-in types

2011-10-27 Thread Arnaud Delobelle
On 27 October 2011 11:08, candide wrote: > I realize that built-in types objects don't provide a __dict__ attribute and > thereby i can't set an attribute to a such object, for instance > > a=[42,421] a.foo="bar" > Traceback (most recent call last): >  File "", line 1, in > AttributeErr

Re: Problem using execvp

2011-10-27 Thread James Housden
On Oct 27, 11:27 am, Hans Mulder wrote: > On 27/10/11 10:57:55, faucheuse wrote: > > > I'm trying to launch my python program with another process name than > > "python.exe". > > Which version of Python are you using? > Which version of which operating system? > > > In order to do that I'm trying

Re: spawnl issues with Win 7 access rights

2011-10-27 Thread Tim Golden
On 27/10/2011 11:27, Propad wrote: the suggestion to add the optional second parameter fixed the problem, spawnl now works on the Win 7 computer I'm responsible for (with Python 2.2). So the suggested cause seems to be right. FWIW, although it's not obvious, the args parameter to spawnl is inte

Re: spawnl issues with Win 7 access rights

2011-10-27 Thread Propad
Hello Gentelmen, the suggestion to add the optional second parameter fixed the problem, spawnl now works on the Win 7 computer I'm responsible for (with Python 2.2). So the suggested cause seems to be right. Thank you for the great help! Cheers, Nenad On 26 Okt., 21:20, Terry Reedy wrote: >

__dict__ attribute for built-in types

2011-10-27 Thread candide
I realize that built-in types objects don't provide a __dict__ attribute and thereby i can't set an attribute to a such object, for instance >>> a=[42,421] >>> a.foo="bar" Traceback (most recent call last): File "", line 1, in AttributeError: 'list' object has no attribute 'foo' >>> a.__dict

python logging multiple processes to one file (via socket server)

2011-10-27 Thread Gelonida N
Hi, I have a rather 'simple' problem. Logging from multiple processes to the same file AND be sure, that no log message is lost, 1.) Log multiple processes to one file: -- I have a python program, which I want to log, but which forks several times. Due

Re: Problem using execvp

2011-10-27 Thread Hans Mulder
On 27/10/11 10:57:55, faucheuse wrote: I'm trying to launch my python program with another process name than "python.exe". Which version of Python are you using? Which version of which operating system? In order to do that I'm trying to use the os.execvp function : os.execvp("./Launch.py", [

Re: Presenting recursive dict (json_diff)

2011-10-27 Thread mcepl
On 27 říj, 10:50, mcepl wrote: > Hi, > > I have here a simple script (https://gitorious.org/json_diff/mainline) > which makes a diff between two JSON files. So for JSON objects and I have completely burried to lead on this. The point is that the resulting object can be endlessly recursively neste

Presenting recursive dict (json_diff)

2011-10-27 Thread mcepl
Hi, I have here a simple script (https://gitorious.org/json_diff/mainline) which makes a diff between two JSON files. So for JSON objects { "a": 1, "b": 2, "son": { "name": "Janošek" } } and { "a": 2, "c": 3, "daughter": { "name": "Maruška" } } i

Problem using execvp

2011-10-27 Thread faucheuse
Hi, I'm trying to launch my python program with another process name than "python.exe". In order to do that I'm trying to use the os.execvp function : os.execvp("./Launch.py", ["ProcessName"]) Launch.py is the file that Launch the program and ProcessName is the ... Process Name ^^ I get this er

Genehmigt vom Ministerium für alberne Gangarten

2011-10-27 Thread Andreas Neudecker
http://blog.stuttgarter-zeitung.de/fundstucke/2011/10/27/genehmigt-vom-ministerium-fur-alberne-gangarten/ -- http://mail.python.org/mailman/listinfo/python-list

Philosophical Python: 2*b or not 2*b

2011-10-27 Thread Andreas Neudecker
Not the answers I expected: ;-) >>> b = True >>> 2*b or not 2*b 2 >>> b = False >>> 2*b or not 2*b True It all becomes clear when you look at: >>> b = False >>> 2*b 0 >>> b = True >>> 2*b 2 No surprise there really. But fun anyway. Any more philsophical Python code out there? -- http://ma