comp.lang.python - 25 new messages in 13 topics - digest
comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en
comp.lang.python@googlegroups.com
Today's topics:
* Can I specify regex group to return float or int instead of string? - 1
messages, 1 author
http://groups.google.com/group/comp.lang.python/t/309d80104afdb1c9?hl=en
* os.pipe() + os.fork() - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/9ce4bc0256f8c3d7?hl=en
* Pure virtual functions in Python? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/4bd25966f9a57f3e?hl=en
* Docstrings considered too complicated - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/dea5c94f3d058e26?hl=en
* scope of generators, class variables, resulting in global na - 1 messages, 1
author
http://groups.google.com/group/comp.lang.python/t/b1ff4d23cb5ec32c?hl=en
* compiling python question - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/bf3208bc8356ae64?hl=en
* Renaming identifiers & debugging - 7 messages, 4 authors
http://groups.google.com/group/comp.lang.python/t/6309428c87eb6ee9?hl=en
* Compiling and running 32-bit Python on 64-bit server? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/850bfbf99b17dabd?hl=en
* When will Java go mainstream like Python? - 5 messages, 4 authors
http://groups.google.com/group/comp.lang.python/t/1675ca5386896fa5?hl=en
* taking python enterprise level?... - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/3dca28b82d10655c?hl=en
* why (1, 2, 3) > [1, 2, 3] is true? - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/f3e711f277930813?hl=en
* How would I do a continuous write over a pipe in the following code... - 1
messages, 1 author
http://groups.google.com/group/comp.lang.python/t/1e98b0eea56a215a?hl=en
* Executable problem - socket? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/309c6b71dfd15f1b?hl=en
==============================================================================
TOPIC: Can I specify regex group to return float or int instead of string?
http://groups.google.com/group/comp.lang.python/t/309d80104afdb1c9?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Feb 25 2010 12:09 pm
From: nn
On Feb 25, 12:20 pm, Steven D'Aprano <st...@REMOVE-THIS-
cybersource.com.au> wrote:
> On Thu, 25 Feb 2010 09:00:07 -0800, Jeremy wrote:
> > On Feb 25, 9:41 am, Steven D'Aprano <st...@REMOVE-THIS-
> > cybersource.com.au> wrote:
> >> On Thu, 25 Feb 2010 07:48:44 -0800, Jeremy wrote:
> >> > I have a regular expression that searches for some numbers and puts
> >> > them into a dictionary, i.e.
>
> >> > '(?P<integer>\d+)\s+(?P<float>\d+\.\d+)'
>
> >> > Is it possible to have the results of the matches returned as int or
> >> > float objects instead of strings?
>
> >> No. Just convert the match with int() or float() before storing it in
> >> the dictionary. That is, instead of:
>
> >> d[key] = match
>
> >> use
>
> >> d[key] = float(match)
>
> >> or similar.
>
> > I was afraid that was the only option. Oh well, thought I'd ask anyway.
>
> Why "afraid"? What's the problem with calling int or float on the match?
>
> --
> Steven
He must not be Dutch
:-) SCNR
==============================================================================
TOPIC: os.pipe() + os.fork()
http://groups.google.com/group/comp.lang.python/t/9ce4bc0256f8c3d7?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Feb 25 2010 12:23 pm
From: aahz@pythoncraft.com (Aahz)
In article <256926de-e175-4fa2-aa24-dbd5f96756ef@u20g2000yqu.googlegroups.com>,
sebastian.noack@googlemail.com <sebastian.noack@googlemail.com> wrote:
>On Feb 20, 8:13=A0pm, Gary Herron <gher...@islandtraining.com> wrote:
>>
>> Here's a thought: =A0Consider the subprocess module. =A0 It can do thefor=
>k
>> and any necessary pipes and can do so in an OS independent way. =A0 It
>> might make you life much easier.
>
>As far as i know the subprocess module provides only functionality for
>running any program as subprocess. But I just want to fork the current
>process without putting some code in an external python script.
Then try multiprocessing
--
Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/
"Many customs in this life persist because they ease friction and promote
productivity as a result of universal agreement, and whether they are
precisely the optimal choices is much less important." --Henry Spencer
==============================================================================
TOPIC: Pure virtual functions in Python?
http://groups.google.com/group/comp.lang.python/t/4bd25966f9a57f3e?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Feb 25 2010 12:32 pm
From: aahz@pythoncraft.com (Aahz)
In article <38ddd614-583c-430d-b998-214bd6360eb2@b2g2000yqi.googlegroups.com>,
lallous <elias.bachaalany@gmail.com> wrote:
>On Feb 22, 12:42=A0am, Gregory Ewing <greg.ew...@canterbury.ac.nz>
>wrote:
>> lallouswrote:
>>>
>>> If the base defines the method and it was empty, then my C++ code
>>> would still call the function. This is not optimal because I don't
>>> want to go from C++ to Python if the _derived_ class does not
>>> implement the cb.
>>
>> I would simply not implement the method at all in the base
>> class. Then the C++ code can do an attribute lookup for
>> the method, and if it's not found, do nothing.
>
>That is what I currently do. But if I comment out the implementations
>(empty ones) then the documentation generation tool will not document
>the callbacks.
Maybe deleting the method after the class would work.
--
Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/
"Many customs in this life persist because they ease friction and promote
productivity as a result of universal agreement, and whether they are
precisely the optimal choices is much less important." --Henry Spencer
==============================================================================
TOPIC: Docstrings considered too complicated
http://groups.google.com/group/comp.lang.python/t/dea5c94f3d058e26?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Feb 25 2010 12:51 pm
From: John Roth
On Feb 24, 1:23 pm, Andreas Waldenburger <use...@geekmail.INVALID>
wrote:
> Hi all,
>
> a company that works with my company writes a lot of of their code in
> Python (lucky jerks). I've seen their code and it basically looks like
> this:
>
> """Function that does stuff"""
> def doStuff():
> while not wise(up):
> yield scorn
>
> Now my question is this: How do I kill these people without the
> authorities thinking they didn't deserve it?
>
> /W
>
> --
> INVALID? DE!
Is the problem that they've got the docstring in the wrong place,
or that the comment isn't saying anything that can't be read in
the method name?
The first is easily fixable with a bit of tutorial about how
a properly placed docstring prints out in various contexts, plus
a quick script to move the suckers.
The second is going to take more work to get the point across
that comments that reproduce what the method name says are waste.
John Roth
==============================================================================
TOPIC: scope of generators, class variables, resulting in global na
http://groups.google.com/group/comp.lang.python/t/b1ff4d23cb5ec32c?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Feb 25 2010 2:02 pm
From: dontspamleo
Hi Arnaud et al,
Here is the link to the bug report from which the discussion in PEP
289 was extracted:
http://bugs.python.org/issue872326
It looks like they were fixing a bunch of bugs and that this
discussion was one of the many in that thread.
Here is another post which points to the core of the issue: early/late
binding. It is also pointed to in PEP 289.
http://mail.python.org/pipermail/python-dev/2004-April/044555.html
Here is Guido's rationale (his text is the items (a) and (b) below. My
comments follow.
(a) I find it hard to defend automatic variable capture given Python's
general late-binding semantics
MY COMMENTS: That is a good point. There are however exceptions to the
"general late-binding semantics" (GLBS) in Python. The outer loop does
bind early in this case in fact. A point to consider along with GLBS
is the unintuitive early bind of the external iterator vs late bind of
the internal iterator. That is a function not of early vs. late
binding, but of the current translation of generator expressions to
generator functions. Using Arnaud's approach would fix that and make
the code IMO so more pythonic.
(b) I believe that use cases needing early binding are uncommon and
strained: they all involve creating a list of generator
expressions, which IMO is a pretty unusual thing to do
MY COMMENTS: This is actually a pretty common use case. Any iteration
over objects of arity 2 or greater (A matrix, a table, a tree searched
breadthwise under some data structures, etc.) can conveniently and
cleanly be expressed using a generator expression.
I'd also add that perhaps the title of Guido's post: "Generator
Expressions - Let's Move Forward" may have unintentionally discouraged
people from reexamining the issue.
I would like to see this decision revisited. Obviously before spending
any time on this I'd like to gauge if there is further interest. Am I
off the mark? Maybe there is a technical misunderstanding on my part.
If there are more people affected (Since the last week I found some
other postings here and on other lists and blogs) who can make a clear
case, then what is the next step?
Cheers,
Leo.
==============================================================================
TOPIC: compiling python question
http://groups.google.com/group/comp.lang.python/t/bf3208bc8356ae64?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Feb 25 2010 2:28 pm
From: "Diez B. Roggisch"
Am 25.02.10 01:55, schrieb Mag Gam:
> sorry for the vague answer.
>
> Its Linux.
>
> The configure build does not say anything actually. This is for SAGE.
> I managed to have it pick it up by compiling/installing tcl and tk and
> then recompile python
Then most probably installing the tk-dev packages would have been
sufficient.
diez
==============================================================================
TOPIC: Renaming identifiers & debugging
http://groups.google.com/group/comp.lang.python/t/6309428c87eb6ee9?hl=en
==============================================================================
== 1 of 7 ==
Date: Thurs, Feb 25 2010 3:08 pm
From: Luca
Diez B. Roggisch wrote:
> You could use import-hooks for importing your code. There was a
> python-magazine article a while ago that showed how to use that + a
> parser to import seamlessly a DSL.
I will look into this, right now i don't know what import-hooks are nor
if i can use them from embedded python.
> Using pyparsing to write a python-grammar on the fly that simply
> exchanges the keywords before passing it to the interpreter is also easy.
This could be an easy solution yes... unfortunately this makes other
problems arise... for instance... if i have an IDE that shows the
translated language and i want to debug it step by step... would it be
easy for me to map the english version (the one that python sees) with
the translated version? I still have to look at this and how to run the
debugger from the application that is "hosting" python so for now the
answer is "i don't know".
Right now, by simply changing the file Python-3.1.1/Grammar/Grammar i
could obtain this (with "if" translated in "se"):
Python 3.1.1 (r311:74480, Feb 25 2010, 22:44:50)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> Vero = True
>>> stampa = print
>>>
>>> se Vero:
... stampa("Ciao")
...
Ciao
>>>
Which seems to work, but requires to manually change the source code and
it is way too complex for someone that has zero knowledge about the
internals of python (like myself). Besides... it is a very ugly hack IMO.
> But to be honest: I doubt it's worth the effort. Really. Teaching people
> how to code, but in something that is *not* the "real" language is of
> little, if any, benefit.
>
> And also I don't think that your concerns are valid in general. Keywords
> are like brandnames or other things - the stand for a concept, and
> people immediatly accept them when they want them.
Maybe you are right, but being italian myself i can remember when i was
a middle schooler (no computer before that) and the hours spent on my
MSX figuring out how the thing worked. I learned all the commands as
"brandnames" without really understanding them. I had _no_ idea that
"if" meant... if, or that "print" meant to print. I had zero knowledge
of english and for this reason most of these commands were meaningless
to me, i didn't even suspect they had a meaning in an existing language,
i just thought that was the way computers talked. When several years
later, in High School, i learned English it was a real surprise for me
to find out that the commands i had learned by heart as "magical words"
actually had a precise meaning in "human language" and i think this
would have helped me to figure out several things that instead took
hours or days to understand.
Now kids have internet, they study english from the kindergarten, they
have a huge quantity of manuals and books freely available, so maybe you
are right and i am just over-worrying. But still, i think it would be
nice to use a language familiar to the kid (especially very young ones),
it would make the learning process faster (no need to learn new words)
and it would make the computer feel almost like a virtual "friend".
> Much, much, much more important would - if anything - be a
> standard-library, or a wrapper for that, e.g. for turtle-graphics, that
> was written in terms of your desired language.
I already made some tests with turtle-graphics and it seems to work. My
next problem was to translate the language.
http://img192.imageshack.us/img192/3093/zzz5.png
[Btw... i took too much time to write this post so the ladybug fell
asleep...]
Thanx,
Luca
== 2 of 7 ==
Date: Thurs, Feb 25 2010 3:09 pm
From: News123
Hi Luca,
Luca wrote:
> Hello, i am trying to develop an application to teach programming to
> young kids in a similar way as Logo did in the past. I would like to use
> an embedded Python as underlying language but this raises a problem.
>
> The target of my app are very young kids that might be unfamiliar with
> english, so i am wondering if there is a way to rename/redefine
> identifiers and messages in the language of the kid.
>
> In UCB-Logo this is very easy with the command
> COPYDEF "newidentifier "oldidentifier
> so all you have to do is setup a startup script to redefine all the
> identifiers to the language of the user.
>
> Is there anything similar for python? Since python would be embedded it
> would not be a problem for me to do it through some API.
>
a pragmatic approach might be to preprocess the source code
and keep the original version as comments above the translated line.
(for debugging)
or to preprecess the input line before the 'exec'.
It might be, that kids are flexible enough to use English words without
understanding them.
My younger brother could write Pascal before he learnt any English and
he never cared, what 'if' 'then' 'else' 'for', etc. meant.
It might be useful though to internationalize the python errror messages
if that's not something already done.
bye
N
== 3 of 7 ==
Date: Thurs, Feb 25 2010 3:41 pm
From: Luca
MRAB wrote:
> Perhaps you could use a different extension, eg ".pyn", so existing
> ".py" files are handled as-is but ".pyn" files are read through a
> translator.
This could be a good idea... especially since i could make my own
extension since we are talking of a special-purpose application that
only incorporates python as a library.
Thanx,
Luca
== 4 of 7 ==
Date: Thurs, Feb 25 2010 4:05 pm
From: "Diez B. Roggisch"
>> And also I don't think that your concerns are valid in general.
>> Keywords are like brandnames or other things - the stand for a
>> concept, and people immediatly accept them when they want them.
>
> Maybe you are right, but being italian myself i can remember when i was
> a middle schooler (no computer before that) and the hours spent on my
> MSX figuring out how the thing worked. I learned all the commands as
> "brandnames" without really understanding them. I had _no_ idea that
> "if" meant... if, or that "print" meant to print. I had zero knowledge
> of english and for this reason most of these commands were meaningless
> to me, i didn't even suspect they had a meaning in an existing language,
> i just thought that was the way computers talked. When several years
> later, in High School, i learned English it was a real surprise for me
> to find out that the commands i had learned by heart as "magical words"
> actually had a precise meaning in "human language" and i think this
> would have helped me to figure out several things that instead took
> hours or days to understand.
> Now kids have internet, they study english from the kindergarten, they
> have a huge quantity of manuals and books freely available, so maybe you
> are right and i am just over-worrying. But still, i think it would be
> nice to use a language familiar to the kid (especially very young ones),
> it would make the learning process faster (no need to learn new words)
> and it would make the computer feel almost like a virtual "friend".
I can't argue this from a technical point of view. Nor from a personal,
as when I was first exposed to programming, I already new a few bits &
pieces of english (leaving highschool with an E grade though....)
However, I'm pretty sure what held me back most was the lack of
(affordable, tuned to the younger audience) course material, and
exchange with peers. Both which has *massively* changed with the
internet available even in rather rural aereas of the world.
Now under the assumption that you are right here, if keywords are what
children keeps from learning programming - then your approach stops much
to early. I already mentioned the standard-library, but of course much
more important are the builtins. What's an int? Hell, I've been using
the term integer for decades now, but actually don't really know if it
really stands for "ganzzahl", the german word for what it is.
And once they learned the language from whatever course material you
prepared for them, they'd take a look outside - and find *nothing*. No
code snippet to re-use without error-prone rewriting. Lack of
understanding because of unfamiliar words. And so on.
All this with a rather high cost on your side to prepare & and maintain
a programming environment based upon a patched, potentially buggy
interpreter + assorted course material.
I really think you should instead focus on creating an environtment
similar to what squeak offers, something integrated with easy access to
graphics and sounds, that create amazement in the children and makes
them want to code to realize their dreams. And of course natively named
libraries, plus course-material. I didn't measure it, but by
guesstimation, the ratio between keywords & other literals in python
should be around the range of 1/10.
Finally - well, if I'd were to learn italian, I'd rather not have my
teacher translate all the nice italian words to german in my textbook...
;) It *is*, after all, learning a language we are talking here. It is
alien. Even python :)
Diez
== 5 of 7 ==
Date: Thurs, Feb 25 2010 4:06 pm
From: Luca
News123 wrote:
> a pragmatic approach might be to preprocess the source code
> and keep the original version as comments above the translated line.
> (for debugging)
Not very nice to see though. This change should be transparent to the
kid, he/she should not be aware of this "translation".
> or to preprecess the input line before the 'exec'.
This could be a solution, yes, but then i would also need to figure out
a way to show the original line when debugging (still, i know nothing
about pdb, maybe it is possible in a easy way).
> It might be, that kids are flexible enough to use English words without
> understanding them.
>
> My younger brother could write Pascal before he learnt any English and
> he never cared, what 'if' 'then' 'else' 'for', etc. meant.
I had a similar experience. When i was a middle schooler i knew nothing
about English and so i learned Basic and then Pascal without actually
knowing that those words had a meaning at all. For me they were just
kind of "magical words" that i could use to tell the computer what to
do. So i know for sure that this is possible. But... imagine the use of
this language in a elementary school. Some kids, like me or you or your
brother would be interested enough to find it easy to learn the new
words. For others it would only be a pain. Another lesson among others
that to them makes no sense at all. If we could make it easier for them
to understand the words used in the language the teacher would have an
easier time to explain some concepts and maybe even these kids could
have fun and begin to love it.
I understand that this "breaks" the language, that it would be better if
they would just learn the "original" language... but most teachers would
ask "then why not use Logo instead? it is already in our language..."
I have nothing against logo of course, i have learned it myself even
before Pascal and i had lots of fun with it. But python is much more
widespread than logo and i think in some ways it makes "more sense" than
logo and it is not much harder. The only problem that i see is that Logo
does have its commands translated while python doesn't nor, it seems,
there is an easy way to add this functionality.
> It might be useful though to internationalize the python errror messages
> if that's not something already done.
Yes, this would be very important... but still, it should be easy for
the teacher to translate the messages to make them more understandable
to the kids.
For instance...
* Python:
>>> draw
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'draw' is not defined
* Logo:
? draw
I don't know how to draw
Logo's message, while maybe too simple for a professional developer, is
certainly much more easy for a kid. So you see, it is not just a matter
of internationalization... it is also a matter of users-target. If i am
talking to a young kid i should use words and concepts that are easy for
him/her to understand... so, for my target, it would be very important
not only a correct translation in my language, but also the use of words
and concepts that are familiar to a kid.
Thanx,
Luca
== 6 of 7 ==
Date: Thurs, Feb 25 2010 4:08 pm
From: "Diez B. Roggisch"
On a related note, did you investigate SUGAR of the OLPC? I'd say these
guys certainly tried to create something that appealed to children, and
AFAIK it comes with a Python interpreter. I'm don't know anything about
that, nor if it comes with learning material. Might be worth checking out.
Diez
== 7 of 7 ==
Date: Thurs, Feb 25 2010 4:34 pm
From: Ethan Furman
Luca wrote:
[snippety]
> Maybe you are right, but being italian myself i can remember when i was
> a middle schooler (no computer before that) and the hours spent on my
> MSX figuring out how the thing worked. I learned all the commands as
> "brandnames" without really understanding them. I had _no_ idea that
> "if" meant... if, or that "print" meant to print. I had zero knowledge
> of english and for this reason most of these commands were meaningless
> to me, i didn't even suspect they had a meaning in an existing language,
> i just thought that was the way computers talked.
[more snippety]
Perhaps the lesson to learn from this is that as *you* teach programming
to non-english speakers you take the time to say "'if' means 'se',
'print' means 'stampa'", etc. I suspect your early years would have
been much easier with those bits of knowledge. :)
~Ethan~
==============================================================================
TOPIC: Compiling and running 32-bit Python on 64-bit server?
http://groups.google.com/group/comp.lang.python/t/850bfbf99b17dabd?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Feb 25 2010 4:10 pm
From: aahz@pythoncraft.com (Aahz)
In article <d5f0a586-6548-4f25-92ab-e723b6313b2b@q29g2000yqn.googlegroups.com>,
Mikko Ohtamaa <mikko@redinnovation.com> wrote:
>
>How one could create 32-bit Python run-time enviroment, preferable
>virtualenv, on 64-bit Linux (VPS), reducing memory usage? This
>environment could actually beat 64-bit in performance, due to better
>memory cache use.
>
>I assume this involves having lib32 libs and compiling Python with
>some magical switches.
The simplest approach would probably be to do the compilation on a 32-bit
system and just install it on 64-bit. There are some magic flags, yes;
you'll need to Google using e.g. "linux force 32-bit compile".
--
Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/
"Many customs in this life persist because they ease friction and promote
productivity as a result of universal agreement, and whether they are
precisely the optimal choices is much less important." --Henry Spencer
==============================================================================
TOPIC: When will Java go mainstream like Python?
http://groups.google.com/group/comp.lang.python/t/1675ca5386896fa5?hl=en
==============================================================================
== 1 of 5 ==
Date: Thurs, Feb 25 2010 4:11 pm
From: Chris Gray
Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> writes:
> In message <op.u8nfpex8y5e8ok@laptopwanja>, Wanja Gayk wrote:
>
> > Reference counting is about the worst technique for garbage collection.
>
> It avoids the need for garbage collection. It means I can write things like
I'm by no means an expert, but how does reference counting deal with
arbitrary long cycles of references (btw I've *written* a simple
reference counter for a programming language)?
When I asked someone whose knowlege of Java I trust, he said that modern
Java's do both reference counting and garbage collection. That was 2 or 3
years ago. I would have guessed that Python was the same.
--
Experience should guide us, not rule us.
Chris Gray
== 2 of 5 ==
Date: Thurs, Feb 25 2010 4:41 pm
From: "Alf P. Steinbach"
* Chris Gray:
> Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> writes:
>
>> In message <op.u8nfpex8y5e8ok@laptopwanja>, Wanja Gayk wrote:
>>
>>> Reference counting is about the worst technique for garbage collection.
>> It avoids the need for garbage collection. It means I can write things like
>
> I'm by no means an expert, but how does reference counting deal with
> arbitrary long cycles of references (btw I've *written* a simple
> reference counter for a programming language)?
Generally it doesn't. Some solutions have however been proposed for
std::shared_ptr in C++. None have made it to any noteworthy status, but they
demonstrate that there are more or less practical solutions for the most common
cases.
Currently the upshot is that if you need the kind of self-referential spaghetti
structure (no offense) created by mathematical expressions that refer to each
other, then you've passed beyond what can be handled practically by reference
counting alone or even in combination with cycle handling techniques.
For that you're better off with some functional language, or Python... ;-)
> When I asked someone whose knowlege of Java I trust, he said that modern
> Java's do both reference counting and garbage collection. That was 2 or 3
> years ago. I would have guessed that Python was the same.
Yes, Python adds general garbage collection to deal with cycles.
Essentially the reference counting deals efficiently and immediately with
objects created by expression evaluation, while the general garbage collection
deals with cyclic structures.
But there's no magic: in particular in Java, Python and like languages you must
still remember to remove references installed in singletons and globals (e.g.
for event notifications), otherwise objects will still be referenced and thus
not garbage collected, causing a memory leak.
Cheers & hth.,
- Alf
== 3 of 5 ==
Date: Thurs, Feb 25 2010 4:58 pm
From: Steven D'Aprano
On Thu, 25 Feb 2010 17:11:32 -0700, Chris Gray wrote:
> I'm by no means an expert, but how does reference counting deal with
> arbitrary long cycles of references (btw I've *written* a simple
> reference counter for a programming language)?
It doesn't, or at least the CPython one doesn't.
In CPython, even a short reference cycle defeats it, which is why CPython
also uses a second garbage collector. If we turn that off, we can see how
even a one-element cycle defeats reference counting:
>>> import gc
>>> gc.disable()
>>>
>>> class K:
... def __del__(self):
... print "Bye now"
...
>>> k = K()
>>> del k # Test it works as expected.
Bye now
>>>
>>> k = K() # Now try with a cycle.
>>> k.attr = k
>>> del k
>>>
>>>
Normally, you would clear the ref cycle this way:
>>> gc.collect()
2
But in this case it doesn't work because the object in the cycle has a
__del__ method, and Python can't predict a safe order to run the __del__
method. (I'm surprised that this is an issue with a single object, but
what do I know?) So we have to inspect the list of garbage, manually
break the cycle, clear new references we've created, and then it will be
garbage collected:
>>> gc.garbage[0].attr = None # Break the cycle
>>> del gc.garbage[:]
Bye now
This is one reason why __del__ methods are not recommended.
> When I asked someone whose knowlege of Java I trust, he said that modern
> Java's do both reference counting and garbage collection. That was 2 or
> 3 years ago. I would have guessed that Python was the same.
CPython has both now. Jython uses whatever the Java implementation uses,
and IronPython uses .Net's memory management scheme. Other Pythons do
whatever they like :)
Some interesting information here:
http://www.digi.com/wiki/developer/index.php/Python_Garbage_Collection
--
Steven
== 4 of 5 ==
Date: Thurs, Feb 25 2010 5:00 pm
From: Mensanator
On Feb 25, 6:41 pm, "Alf P. Steinbach" <al...@start.no> wrote:
> * Chris Gray:
>
> > Lawrence D'Oliveiro <l...@geek-central.gen.new_zealand> writes:
>
> >> In message <op.u8nfpex8y5e8ok@laptopwanja>, Wanja Gayk wrote:
>
> >>> Reference counting is about the worst technique for garbage collection.
> >> It avoids the need for garbage collection. It means I can write things like
>
> > I'm by no means an expert, but how does reference counting deal with
> > arbitrary long cycles of references (btw I've *written* a simple
> > reference counter for a programming language)?
>
> Generally it doesn't. Some solutions have however been proposed for
> std::shared_ptr in C++. None have made it to any noteworthy status, but they
> demonstrate that there are more or less practical solutions for the most common
> cases.
>
> Currently the upshot is that if you need the kind of self-referential spaghetti
> structure (no offense) created by mathematical expressions that refer to each
> other, then you've passed beyond what can be handled practically by reference
> counting alone or even in combination with cycle handling techniques.
>
> For that you're better off with some functional language, or Python... ;-)
>
> > When I asked someone whose knowlege of Java I trust, he said that modern
> > Java's do both reference counting and garbage collection. That was 2 or 3
> > years ago. I would have guessed that Python was the same.
>
> Yes, Python adds general garbage collection to deal with cycles.
>
> Essentially the reference counting deals efficiently and immediately with
> objects created by expression evaluation, while the general garbage collection
> deals with cyclic structures.
>
> But there's no magic: in particular in Java, Python and like languages you must
> still remember to remove references installed in singletons and globals (e.g.
> for event notifications), otherwise objects will still be referenced and thus
> not garbage collected, causing a memory leak.
Is that really considered a leak, a single instance
of an uncollected global as opposed to a function
that is called millions of times, and each time
it's called creates uncollected temporary variables?
>
> Cheers & hth.,
>
> - Alf
== 5 of 5 ==
Date: Thurs, Feb 25 2010 5:06 pm
From: Steven D'Aprano
On Thu, 25 Feb 2010 17:00:32 -0800, Mensanator wrote:
> Is that really considered a leak, a single instance of an uncollected
> global as opposed to a function that is called millions of times, and
> each time it's called creates uncollected temporary variables?
I think it's generally called "garbage". When the amount of garbage
grows, or *could* grow, it is called a leak. But nobody is going to slap
you for calling a single instance of an uncollectable object a leak.
--
Steven
==============================================================================
TOPIC: taking python enterprise level?...
http://groups.google.com/group/comp.lang.python/t/3dca28b82d10655c?hl=en
==============================================================================
== 1 of 2 ==
Date: Thurs, Feb 25 2010 4:12 pm
From: "Diez B. Roggisch"
> That better way turned out to asynchronous update transactions. All we
> did was keep feeding updates to the remote site and forget about ACKS.
> We then had a second process which handled ACKS and tracked which
> packets had been properly transferred. The system had IDs on each
> update and retries happened if ACKS didn't happen soon enough.
> Naturally we ignored ACKS that we had already processed.
sounds like using UDP to me, of course with a protocol on top (namely
the one you implemented).
Any reason you sticked to TCP instead?
Diez
== 2 of 2 ==
Date: Thurs, Feb 25 2010 8:01 pm
From: "D'Arcy J.M. Cain"
On Fri, 26 Feb 2010 01:12:00 +0100
"Diez B. Roggisch" <deets@nospam.web.de> wrote:
> > That better way turned out to asynchronous update transactions. All we
> > did was keep feeding updates to the remote site and forget about ACKS.
> > We then had a second process which handled ACKS and tracked which
> > packets had been properly transferred. The system had IDs on each
> > update and retries happened if ACKS didn't happen soon enough.
> > Naturally we ignored ACKS that we had already processed.
>
> sounds like using UDP to me, of course with a protocol on top (namely
> the one you implemented).
>
> Any reason you sticked to TCP instead?
TCP does a great job of delivering a stream of data in order and
handling the retries. The app really was connection oriented and we
saw no reason to emulate that over an unconnected protocol. There were
other wheels to reinvent that were more important.
--
D'Arcy J.M. Cain <darcy@druid.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
==============================================================================
TOPIC: why (1, 2, 3) > [1, 2, 3] is true?
http://groups.google.com/group/comp.lang.python/t/f3e711f277930813?hl=en
==============================================================================
== 1 of 2 ==
Date: Thurs, Feb 25 2010 4:29 pm
From: r
On Feb 25, 7:00 am, fat bold cyclop <fat.bold.cyc...@gmail.com> wrote:
> why (1, 2, 3) > [1, 2, 3] is true?
It's simple, Everything must have a value!
== 2 of 2 ==
Date: Thurs, Feb 25 2010 4:42 pm
From: Robert Kern
On 2010-02-25 18:29 PM, r wrote:
> On Feb 25, 7:00 am, fat bold cyclop<fat.bold.cyc...@gmail.com> wrote:
>> why (1, 2, 3)> [1, 2, 3] is true?
>
> It's simple, Everything must have a value!
That is not at all an explanation, much less a true one. Please read the other
posts in this thread; they have explained the situation rather well.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
==============================================================================
TOPIC: How would I do a continuous write over a pipe in the following code...
http://groups.google.com/group/comp.lang.python/t/1e98b0eea56a215a?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Feb 25 2010 4:51 pm
From: aahz@pythoncraft.com (Aahz)
In article <9d0f6456-97c7-4bde-8e07-9576b02f91f9@t31g2000prh.googlegroups.com>,
chad <cdalten@gmail.com> wrote:
>
>import subprocess as s
>
>broadcast = s.Popen("echo test | wall", shell=True,stdout=s.PIPE)
>
>out = broadcast.stdout
>while 1:
> out
> broadcast.wait()
>
>broadcast.stdout.close()
>
>
>The code only executes once. What I want to do is be able to
>continuously write over the pipe once it is open. I could put
>s.Popen() inside the while loop, but that seems a bit too messy. So is
>there some way to just open the pipe once, and once it is open, just
>continuously write over it vs just opening and closing the pipe every
>time?
You really should do this instead, untested:
broadcast = s.Popen(['wall'], stdin=s.PIPE)
while 1:
broadcast.write('test\n')
time.sleep(1)
--
Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/
"Many customs in this life persist because they ease friction and promote
productivity as a result of universal agreement, and whether they are
precisely the optimal choices is much less important." --Henry Spencer
==============================================================================
TOPIC: Executable problem - socket?
http://groups.google.com/group/comp.lang.python/t/309c6b71dfd15f1b?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Feb 25 2010 6:14 pm
From: Gib Bogle
MRAB wrote:
> You could try Dependency Walker: http://dependencywalker.com/
>
I have (belatedly) read the py2exe tutorial:
http://www.py2exe.org/index.cgi/Tutorial#Step522
and learned about the msvcr90.dll issue. I haven't finished sorting this out
yet, but I did find that running vcredist_x86.exe (the right version!) on box 1
fixed things there. I also tried (naively) manually adding
dist\Microsoft.VC90.CRT with the manifest file and msvcr90.dll, but this doesn't
seem to work - it seems that p2exe must do the file copying.
==============================================================================
You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.
To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en
To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com
To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en
To report abuse, send email explaining the problem to abuse@googlegroups.com
==============================================================================
Google Groups: http://groups.google.com/?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home