Re: pytz has so many timezones!

2007-10-09 Thread Nicholas Bastin
On 10/9/07, Sanjay <[EMAIL PROTECTED]> wrote:
> > It's not clear at all from the OPs post exactly what functionality he
> > is trying to derive from the timezone. Since timezones (obviously)
> > contain more information than just the GMT offset (otherwise we
> > wouldn't even have them), he may very well want to use the timezone
> > given by the user to display correct local time to them. In this case,
> > the actual, correct, political timezone is important, not just the GMT
> > offset.
>
> I am developing a website which would be accessed by members all over
> the world. They can exchange data having some time fields, say
> 'schedule for next meeting'. Whenever somebody feeds some time field,
> my application converts it to UTC and stores in the database. Later,
> when the data is to be displayed to some member, the application
> converts it to his local time, and displays the data.

Yeah, you are, unfortunately, probably going to have to deal with the
entirety of this time zone data in this case.  You can obviously elide
some information for countries you don't intend to support, but
there's no particular reason to exclude a potential market.

I would say the easiest way to get people to choose their own time
zone is to ask them their country, and then filter their choices by
that.  (That would get you down to less than a dozen choices in almost
every country in the world).

--
Nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The fundamental concept of continuations

2007-10-09 Thread Bakul Shah
[EMAIL PROTECTED] wrote:
> On Oct 8, 11:07 pm, Bakul Shah <[EMAIL PROTECTED]> wrote:
...
>> You might like this one:
>>
>> http://www.intertwingly.net/blog/2005/04/13/Continuations-for-Curmudg...
> 
> thanks for the link but can you plz upload the paper so we can also
> get it.

You will have to get it yourself or explain why this is an
impossibility for you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-10-09 Thread Klaus Schilling
George Neuner  writes:
>
> Or, how about politics?  Another example from the Judeo-Christian
> Bible (that is, from the Old Testament), politicking was the sin that
> resulted in Lucifer's fall from God's grace.

that's not a God, but an inferior demiurge, 
as correctly figured by Marcion

> [Yeah, I know the official story is that Lucifer's sin was envy.

the official story is thoroughly flawed.
of course Lucifer means carrier of light,
and thus has nothing to do with sin.
but the contrary.
Lucifer brings enlightenment to those people
who are enchained in the darkness of oppression and stupor
the demiurge imposed upon them.
Thus it's Plato who equalled the situation of
unenlightened mankind with that of prisoners in a dark cave.
Sin is the rejection of the light brought by 
the carrier of light.
Same goes for those who have once seen the light of
the Symbolic Expressions, but continue rejoycing in
infix Syntax. 

Klaus Schilling
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: generator_tools-0.1 released

2007-10-09 Thread Kay Schluehr
Originally I came up with the idea of a pure Python implementation for
copyable generators as an ActiveState Python Cookbook recipe. Too bad,
it was badly broken as Klaus Müller from the SimPy project pointed
out. Two weeks and lots of tests later I got finally a running version
that works not only in the very most simple use cases. As the code
size increased it turned out to not really fit anymore into the
"recipe" category and I created a package called "generator_tools".

generator_tools-0.1 is available for both Python 2.5 and Python 3.0
(!)

The generator_tools package can be downloaded from PyPI

http://pypi.python.org/pypi/generator_tools/0.1

More information is presented on my project homepage

http://www.fiber-space.de

Documentation is also included in the distribution.

Usage:
--

from generator_tools.copygenerators import*
from generator_tools.picklegenerators import*

def f(start):
i = start
while i>> f_gen = f(5)
>>> f_gen.next()   # or next(f_gen) in Python 3.0
5
>>> f_gen.next()
6
>>> g_gen = copy_generator(f_gen)
>>> h_gen = copy_generator(f_gen)
>>> g_gen.next()
7
>>> h_gen.next()
7
>>> pickler = GeneratorPickler("test.pkl")
>>> pickler.pickle_generator(g_gen)
>>> k_gen = pickler.unpickle_generator()
>>> list(g_gen) == list(k_gen)
True

-- 
http://mail.python.org/mailman/listinfo/python-list


Accessing 'Package Data'

2007-10-09 Thread Stefan Arentz

At http://docs.python.org/dist/node12.html it is described how to add
package data to a module. This was pretty easy to do, but now how do I
access this data from my module? Is there an API to load a 'package
resource' ala Java's classloader?

 S.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python and UML

2007-10-09 Thread aine_canby
Hi,

I'm working with Python2.5 and pythonWin.

I'd like to start working with and learning more with UML. Can anyone
suggest any freeware design software that I might use to do this? I
also have
Visio installed on my computer if thats of any use...

Thanks,

Aine

-- 
http://mail.python.org/mailman/listinfo/python-list


RE: NUCULAR fielded text searchable indexing

2007-10-09 Thread Delaney, Timothy (Tim)
[EMAIL PROTECTED] wrote:

> ANNOUNCE:
>   NUCULAR fielded text searchable indexing

Does "NUCULAR" stand for anything? The (apparent) misspelling of
"nuclear" has already turned me off wanting to find out more about it.

Tim Delaney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pytz has so many timezones!

2007-10-09 Thread J. Cliff Dyer
Nicholas Bastin wrote:
>
> There is no central authority which defines global time zones.  The
> functional definition of a time zone is merely a geographical area of
> the earth that has adopted the same local time rules.
>

In fact, even the authorities who do define time zones don't always
have the final say.  In Xinjiang province in Western China, the
official time zone is the same as Beijing, even though Xinjiang is
about as far west of Beijing as Nevada is from DC, so the sun comes up
around "noon" and sets around "midnight."  So many people set their
clocks to unofficial Xinjiang time, three hours offset from Beijing.

In offering a "Xinjiang" timezone set to the unofficial time, you
might win some customers who see you as being on their side.  Xinjiang
is a muslim country, so you might also score points with muslims
elsewhere in the world who see their minority Uighur brethren as
oppressed by the authorities of Beijing.  On the other hand, you might
annoy the authorities in Beijing.  Which is just to say that choice of
time zone is not just a geographic issue.  There are political,
diplomatic issues to weigh as well.

Cheers,
Cliff


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embedding python..

2007-10-09 Thread [EMAIL PROTECTED]
That sounds to easy I will give it a shot..

On Oct 6, 11:08 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Fri, 05 Oct 2007 20:40:40 -0300, [EMAIL PROTECTED]  
> <[EMAIL PROTECTED]> escribi?:
>
> >  I compiled the c program that is supposed to allow you to call a
> > procedure from the command line promt..  (it is from the embeding
> > example)..  I am a little confused as to what all I am supposed to
> > distribute to make it work..  Do I just need the python .dll for the
> > version I compiled or is it working with the installed version of
> > python.. (I don't want to start deleting stuff to find out)..  Any
> > help on this question would be apreaceated..
>
> If you only provide pythonXX.dll (and probably msvcr71.dll), any Python  
> code that tries to import any module apart from builtin modules will fail.  
> If you provide the Python standard library in full, almost any program  
> could be run.
> It's up to you to decide how much you require/allow/want to provide.
>
> --
> Gabriel Genellina


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to create a file on users XP desktop

2007-10-09 Thread Tim Golden
>> On Oct 8, 9:19 am, goldtech <[EMAIL PROTECTED]> wrote:
>>> How did you learn Win32com?
>>>
>>> Other than the O'Reilly book, I've never found a lot of
>>> documentation.
>>>
>>> Trying to browse COM in PythonWin is tough - there's tons of stuff in
>>> there. I've never been able to find the Win32com classes, methods,
>>> usage examples when I browse COM in PythonWin.
>>>
>>> For example where is, shell.SHGetFolderPath and shellcon.CSIDL_DESKTOP
>>> officially documented?

Tim Golden wrote:
> FWIW, the pywin32 distribution itself also comes with a local
> .chm file. But aside from that, there have been several abortive
> attempts -- including by Mike & myself! -- to get some kind of
> online help going for pywin32, but nothing's really gained traction,
> and we've all got more interesting things to be doing...

To show willing :) I've added a howto on this subject to my
occasionally-updated list of Python win32 howto-s:

   http://timgolden.me.uk/python/win32_how_do_i/get-the-desktop-folder.html

and a bonus, also from the shell area:

   http://timgolden.me.uk/python/win32_how_do_i/browse-for-a-folder.html

I usually manage to do a few of these at one go once I gather
momentum, so hopefully I'll add a few more in today or tomorrow.

TJG
-- 
http://mail.python.org/mailman/listinfo/python-list


python bytecode questions.

2007-10-09 Thread warhero
First question, I can't seem to get any python bytecode to be
produced. I've tried different techniques from chapter 30.8 to chapter
31 of the python guide.. I was under the assumption that after
compiling a file, it would output a pyc file, but where does it go?
Any help would be appreciated.

Second, Are there any other projects out for bundling python bytecode
files, making it able to use a couple files to distribute an entire
app??  I saw one of the effbot site but it's old as it was written for
1.4..

Third, can distributing code in pyc files, speed up the application?
Or would speed increases only be seen upon application initialization?
As an example, let's say I'm running an application server, would
distributing the source in some pyc files with a bootstrapper be any
faster overall, or just on init??

Thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Query

2007-10-09 Thread Ameet Nanda

Hi,
I am a Py Newbie. I am learning to write python scripts on Linux , I
want to know what to do in order to get the executable file as a binary.
Because now I run it by simply using the python compiler every time to
run the scripts

$> python scriptfile.py

I want to make a binary file , which would execute on it's own.

-Nax0r



The information contained in this electronic message and any attachments to 
this message are intended for the exclusive use of the addressee(s) and may 
contain proprietary, confidential or privileged information. If you are not the 
intended recipient, you should not disseminate, distribute or copy this e-mail. 
Please notify the sender immediately and destroy all copies of this message and 
any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should 
check this email and any attachments for the presence of viruses. The company 
accepts no liability for any damage caused by any virus transmitted by this 
email.
 
www.wipro.com-- 
http://mail.python.org/mailman/listinfo/python-list

Re: python bytecode questions.

2007-10-09 Thread Duncan Booth
warhero <[EMAIL PROTECTED]> wrote:

> First question, I can't seem to get any python bytecode to be
> produced. I've tried different techniques from chapter 30.8 to chapter
> 31 of the python guide.. I was under the assumption that after
> compiling a file, it would output a pyc file, but where does it go?
> Any help would be appreciated.

Any time you import a python file it will be compiled (if it hasn't already 
been compiled) and a .pyc file will be generated in the same directory as 
the source file (so long as you can write a file to that directory).

N.B. This only happens when you import a module: when you run a .py file as 
a script it is still compiled, but no .pyc is output. If this worries you 
then write a very short .py file which just imports the main program 
module and calls some startup function.

> 
> Second, Are there any other projects out for bundling python bytecode
> files, making it able to use a couple files to distribute an entire
> app??  I saw one of the effbot site but it's old as it was written for
> 1.4..

For Windows you can make standalone executables with py2exe 
(http://www.py2exe.org/)

More generally, assuming that Python is already installed, the trend seems 
to be for packaging your code as a Python egg 
(http://peak.telecommunity.com/DevCenter/PythonEggs).

> Third, can distributing code in pyc files, speed up the application?
> Or would speed increases only be seen upon application initialization?
> As an example, let's say I'm running an application server, would
> distributing the source in some pyc files with a bootstrapper be any
> faster overall, or just on init??
> 
No, the only gain is that you save the initial compile.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pytz has so many timezones!

2007-10-09 Thread Nicholas Bastin
On 10/9/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> On Oct 8, 8:27?pm, "Nicholas Bastin" <[EMAIL PROTECTED]> wrote:
> > On 10/8/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > > Because they publish maps?
> >
> > I'm not sure what this has to do with it.
>
> Maybe you've never had to navigate?

I don't often find the need to navigate by time zone.  Nor do
cartographers consider themselves experts on time, but rather
geography.

> WHY must we accomodate the ignorant? Why not cut them off
> from the Internet until they get their act together? Don't
> people get mad at Microsoft for breaking standards? People like
> you are to blame for accomodating broken standards. "Oh, no,
> we can't afford to lose those three potential customers who
> live on an island in Kiribati!"

There's no broken standard here.  I'd advise you to refrain from
painting other people with your own ignorant brush.

> > If I schedule a meeting with someone in Indiana, and I'm in Ohio,
> > they're in the same military time zone, but they don't observe
> > daylight savings time, so in fact our times are different.  Users
> > probably want our applications to handle these problems.
>
> Isn't that what they call a "locale"?

No.  If we spoke a different language or used a different script,
that'd be a different locale.  Of course, we might still be in the
same time zone.

> > > > Since timezones (obviously)
> > > > contain more information than just the GMT offset
> >
> > > Of course. But the GMT offset could be used to filter his list
> > > of 400 choices, couldn't it?
> >
> > Sortof.  First, your user has to understand what GMT is,
>
> And you start that education by learning the 25 timezones.
> Then when you understand that, you can then learn about locales.

Just because NATO thinks there's 25 time zones doesn't mean that
they're any more correct than all of the local entities which have
defined their own time zones.   And again, your usage of the word
'locale' bears no relationship to the actual definition, in computer
science terms.

> > so that's
> > already going to cause problems.   Secondly, you need to handle time
> > zones which drift from different GMT offsets depending on the time of
> > year.
>
> It helps to know what you're drifting from.

You're drifting from UTC.  UTC which has no bearing nor controlling
influence on time zone definitions.  Just because government entities
reference +/- UTC in time zone definitions does not mean that they're
substantially related.

> > At the very least your algorithm needs to be greedy.
>
> How good an algorithm do you think the OP will come up
> with if he doesn't understand why his list has 400 items
> or has any clue how to reduce it?

I didn't presume the OP was an idiot.  I felt that it was much more
reasonable to explain how the 400 differed then to paint for him a
fairy tale of 25 magical time zones, which had no bearing on his
application.  There are many ways to filter the 400 based on the needs
of each application, and I leave it as an exercise to the OP to either
deduce the appropriate ones, or ask more questions.

> > > Why not teach him the truth, starting from the top level? Shouldn't
> > > you teach him to fish rather than just give him one?
> >
> > Because the truth is that there are upwards of 400 different time
> > zones,
>
> Locales.

No, locale has already been defined by the computer science community,
and it doesn't involve time zones.  There are, realistically, less
than 400 locales.  Do not confuse the two.  (Locales can be consistent
across many time zones - see en_US for a trivial example).  Locales
are coded by language, script, country, and a variant, and do not
contain time zone information.

> > There is no central authority which defines global time zones.  The
> > functional definition of a time zone is merely a geographical area of
> > the earth that has adopted the same local time rules.
>
> So, you can live your life with functional definations,
> never bothering to learn any theory? Is code monkey all you
> aspire to?

Well, I certainly don't aspire to be a stuck up ass, which is
apparently what you've been working towards.

There is no magical theory behind time zones.  There is no one truth,
and there is no controlling global regulation.  Does NATO have a
simple time zone implementation?  Absolutely.  Is that relevant to
most consumer applications?  Absolutely not.

When you write applications for the military, feel free to adhere to
their standards.  When you write applications for an international
community, you might want to put the bigotry aside and cater to their
actual needs.

--
Nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python bytecode questions.

2007-10-09 Thread Kay Schluehr
On Oct 9, 10:20 am, warhero <[EMAIL PROTECTED]> wrote:

> First question, I can't seem to get any python bytecode to be
> produced. I've tried different techniques from chapter 30.8 to chapter
> 31 of the python guide.. I was under the assumption that after
> compiling a file, it would output a pyc file, but where does it go?
> Any help would be appreciated.

You might take a look at the source of lib/compiler/pycodegen.py

> Second, Are there any other projects out for bundling python bytecode
> files, making it able to use a couple files to distribute an entire
> app??  I saw one of the effbot site but it's old as it was written for
> 1.4..

Not sure what you are after. Do you want something lile PyInstaller

http://pyinstaller.python-hosting.com/

or eggs as in setuptools?

http://peak.telecommunity.com/DevCenter/setuptools

>
> Third, can distributing code in pyc files, speed up the application?
> Or would speed increases only be seen upon application initialization?
> As an example, let's say I'm running an application server, would
> distributing the source in some pyc files with a bootstrapper be any
> faster overall, or just on init??
>
> Thanks

The compilation overhead is neglectable. Unless you change the source
again the server will load the *.pyc file anyway. No significant
speedup has to be expected by not delivering the source.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Accessing 'Package Data'

2007-10-09 Thread Diez B. Roggisch
Stefan Arentz wrote:

> 
> At http://docs.python.org/dist/node12.html it is described how to add
> package data to a module. This was pretty easy to do, but now how do I
> access this data from my module? Is there an API to load a 'package
> resource' ala Java's classloader?

You can always use os.path + the __file__-attribute of the containing
package.

And there is the 3rd-party pkg_resources, part of setuptools:

 http://peak.telecommunity.com/DevCenter/PkgResources

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: toprettyxml messes up with whitespaces

2007-10-09 Thread Jorgen Bodde
Dear list,

Thanks for the suggestions and clarification. After playing with XML
for a while I noticed whitespaces can indeed be more important then I
thought. I did came to the following conclusions;

1. Removing whitespaces was done by my code, not by the
xml.dom.minidom so I regret the fact I said that it removed
whitespaces automatically
2. toprettyxml() should however be smarter with outputting the XML. If
it adds whitespaces in the sake of formatting, it should check how
many of the whitespaces are already there. Consecutive read / modify /
write actions should not cause an explosive growth of whitespaces.
When I use toprettyxml() I am obviously not interested in whitespaces
in front of the text in the nodes, or else I would have outputted it
differently.

Thanks all for the feedback,
- Jorgen
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The fundamental concept of continuations

2007-10-09 Thread Tim Bradshaw
On Oct 9, 7:34 am, [EMAIL PROTECTED] wrote:

> which lambda paper ?

Are you Ilias?  I think you probably are.

-- 
http://mail.python.org/mailman/listinfo/python-list


PyDev 1.3.9 code compleition trouble

2007-10-09 Thread Vyacheslav Maslov
Hi!

I use Pydev 1.3.9 and notice issue related to code completion. I give an 
example

BaseClass.py:

class BaseClass:
 def someMethod(x):
 return x+x

DerivedClass.py:

import BaseClass

class DerivedClass(BaseClass.BaseClass):
 def newMethod(self):
 print self.someMethod(4)


I try to use code completion in class DerivedClass inside method 
"newMethod", after typing "self." and pushing ctrl+space completion 
dialog propose substitution only for method "newMethod". However, i 
expect that method defined in BaseClass called "someMethod" should be 
proposed also as well. Why this doesn't work?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and UML

2007-10-09 Thread Andrzej S.
[EMAIL PROTECTED] wrote:
> I'd like to start working with and learning more with UML. Can anyone
> suggest any freeware design software that I might use to do this? I
> also have
> Visio installed on my computer if thats of any use...


Does not Visio meet your requirements? It's quite powerfull UML design 
  tool.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get rgbdata

2007-10-09 Thread Diez B. Roggisch
 [EMAIL PROTECTED] wrote:

> Hi i am a newbie to python and PIL. can anyone tell me how to get
> rgbdata from a jpeg image using PIL
> as a double[] . is there an equiv method to java's
> BufferedImage.getRGB(0,0,width,height,rgbdata,0,width) ?

The docs of PIL are quite good. And there you find the method

Image.getdata()

that does what you want. At least in a way, as it returns a slightly
different format (tuples of ints istead of floats), but I presume you can
convert that by yourself.

http://www.pythonware.com/library/pil/handbook/image.htm


Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The fundamental concept of continuations

2007-10-09 Thread Diez B. Roggisch
Tim Bradshaw wrote:

> On Oct 9, 7:34 am, [EMAIL PROTECTED] wrote:
> 
>> which lambda paper ?
> 
> Are you Ilias?  I think you probably are.

He certainly isn't, but you are right that he smells like he's been living
under a bridge for quite a time...

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and UML

2007-10-09 Thread Diez B. Roggisch
 [EMAIL PROTECTED] wrote:

> Hi,
> 
> I'm working with Python2.5 and pythonWin.
> 
> I'd like to start working with and learning more with UML. Can anyone
> suggest any freeware design software that I might use to do this? I
> also have
> Visio installed on my computer if thats of any use...

ArgoUML as modelling tool. The python-IDE eric also generates UML from
class-hierarchies.

IMHO UML is ... crap, at least when it comes to actual developing. But apart
from that very personal opinion, the non-static-typedness of Python makes
it hard to bring UML to it's full (however small that is in my POV) power.

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and UML

2007-10-09 Thread aine_canby
On 9 Okt, 12:15, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>  [EMAIL PROTECTED] wrote:
> > Hi,
>
> > I'm working with Python2.5 and pythonWin.
>
> > I'd like to start working with and learning more with UML. Can anyone
> > suggest any freeware design software that I might use to do this? I
> > also have
> > Visio installed on my computer if thats of any use...
>
> ArgoUML as modelling tool. The python-IDE eric also generates UML from
> class-hierarchies.
>
> IMHO UML is ... crap, at least when it comes to actual developing. But apart
> from that very personal opinion, the non-static-typedness of Python makes
> it hard to bring UML to it's full (however small that is in my POV) power.
>
> Diez

>> IMHO UML is ... crap, at least when it comes to actual developing. But apart
from that very personal opinion, the non-static-typedness of Python
makes
it hard to bring UML to it's full (however small that is in my POV)
power.

What alternatives are there?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and UML

2007-10-09 Thread Stefan Behnel
[EMAIL PROTECTED] wrote:
> On 9 Okt, 12:15, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>>> IMHO UML is ... crap, at least when it comes to actual developing.
> 
> What alternatives are there?

What's your use case?

Stefan
-- 
http://mail.python.org/mailman/listinfo/python-list


embedding error in python example

2007-10-09 Thread [EMAIL PROTECTED]
I compiled the comand line example and I am getting an error when I
try to use the program when the program is cleaning up (I don't know
that it would prevent the program from running though I will run more
tests)...  ebedpython test testt
result of call: -1
exception exceptions.TypeError: 'an integer is required' in ' 'garbage
collection' ignored
Fatal Python error: unexpected exception during garbage collection...

the program is just
test.py

def testt():
 x = 'test'

doesn't realy do anything it was my first test of the program..

I would be thankfull for any help..



tagline I don't need no stinken tagline...

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embedding error in python example

2007-10-09 Thread [EMAIL PROTECTED]
On Oct 9, 6:11 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> I compiled the comand line example and I am getting an error when I
> try to use the program when the program is cleaning up (I don't know
> that it would prevent the program from running though I will run more
> tests)...  ebedpython test testt
> result of call: -1
> exception exceptions.TypeError: 'an integer is required' in ' 'garbage
> collection' ignored
> Fatal Python error: unexpected exception during garbage collection...
>
> the program is just
> test.py
>
> def testt():
>  x = 'test'
>
> doesn't realy do anything it was my first test of the program..
>
> I would be thankfull for any help..
>
> tagline I don't need no stinken tagline...

def testt():
v = open('file.txt','w')
v.write('test')
v.close()
 #x := 'test'
 #print x

This seems to work but gives me the annoying looking error..  I now
have a file with the word test in it...  This is done with xp, with
python 2.5 dll and the example that you find when you look up python +
embed in google..  I copied all the .dll's in the root (msvcrt exc)
and python25.dll to the directory..  any help would be apreaceated..

-- 
http://mail.python.org/mailman/listinfo/python-list


Editing particular lines of a text file.

2007-10-09 Thread Shriphani
Hello all,

I am trying to create a script that looks at specific strings in a
file like:

msgid "I am a disco dancer."

and compares the part in quotes to the keys in a dictionary, finds the
value and creates a new line right after this string in the file. I
have planned to write this as follows:

1. Open the file in read mode
2. parse each line to figure out which line contains "msgid" and use
the shlex module's split method to go and split this line and pick the
2nd element list[1].
3. find the value from the dictionary corresponding to the above
element.
4. Insert the line. This part is where I face a problem. How do I
plainly edit just one line. I would also like to look at some sample
code that does this.
5. open a new file and write the new file with the inserted strings to
it.
6. close both files opened.

Regards,
Shriphani Palakodety

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why did MIT drop scheme for python in intro to computing?

2007-10-09 Thread Harold Ancell
On Tue, 09 Oct 2007 03:28:53 -, [EMAIL PROTECTED] wrote:

>On Oct 8, 1:23 pm, [EMAIL PROTECTED] (Brian Harvey) wrote:

>> "Kjetil S. Matheussen" <[EMAIL PROTECTED]> writes:

>> >I don't think your speculations makes very much sence.

>> Amen.

>> And, in any case, there's no need to speculate.
>> MIT has published, on their web site, pages and
>> pages of rationale for the new curriculum.

>> The most important point, imho, is that the
>> programming language was the /least/ important
>> aspect of the decision.  The most important
>> aspect was the move to an application-based
>> (rather than topic-based) organization of the
>> curriculum.  The details flow out of that big
>> shift of focus.

>[ much snipped. ]

>Does scheme have a gui library?

>I really dont follow the logic.

I really REALLY hope that not a single GUI is
constructed in 6.01-2; adding that to the load
would be stark raving mad (look and you'll agree).

As Brian points out, languages are a means to the
end of teaching stuff, and I wouldn't be surprised
if not a single GUI is constructed in the entire
required/restricted elective curriculum.  That's
just not to the point of an EECS education that
has to be squeezed into 4/5 years (most students
take the combined MEng path, where the MS degree
is terminal and leads straight to industry).

If any library was a consideration in choosing
Python, it was the robots one for 6.01.  Note also
that Hal helped design and teach 6.01, and fully
supports the new curriculum.

As a total LISP/Scheme fanatic who finds parts of
Python's syntax to be too hard for his brain (not
the indentation, that's weird but useful and cool,
much like S-expressions in LISP), I looked hard at
the beginning of 6.01 where they're only teaching
SICP.

For that purpose, Python is not "awful" (remember,
I believe LISP is the One True Way of Computing).
For that initial bit of SICP material, I do not
believe the students will be handicapped.

Beyond that initial bit of material, I have no
informed opinions.

- Harold

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NUCULAR fielded text searchable indexing

2007-10-09 Thread aaron . watters
On Oct 8, 7:00 pm, "Delaney, Timothy (Tim)" <[EMAIL PROTECTED]>
wrote:
> [EMAIL PROTECTED] wrote:
> > ANNOUNCE:
> >   NUCULAR fielded text searchable indexing
>
> Does "NUCULAR" stand for anything? The (apparent) misspelling of
> "nuclear" has already turned me off wanting to find out more about it.
>
> Tim Delaney

No, it doesn't stand for anything.  I guess it's not for you :(.
Sorry about that.

(see the graphic at the bottom of http://nucular.sourceforge.net)

  -- Aaron Watters

===
An apple every 8 hours will keep 3 doctors away. (kliban)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Editing particular lines of a text file.

2007-10-09 Thread Tim Williams
On 09/10/2007, Shriphani <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> I am trying to create a script that looks at specific strings in a
> file like:
>
> msgid "I am a disco dancer."
>
> and compares the part in quotes to the keys in a dictionary, finds the
> value and creates a new line right after this string in the file. I
> have planned to write this as follows:
>
> 1. Open the file in read mode
> 2. parse each line to figure out which line contains "msgid" and use
> the shlex module's split method to go and split this line and pick the
> 2nd element list[1].
> 3. find the value from the dictionary corresponding to the above
> element.
> 4. Insert the line. This part is where I face a problem. How do I
> plainly edit just one line. I would also like to look at some sample
> code that does this.
> 5. open a new file and write the new file with the inserted strings to
> it.
> 6. close both files opened.


infile = open('infile.txt')
outfile = open('outfile.txt','w')
for line in infile:
if 'msgid' in line:
 #  transform line
 #  make sure the line ending is intact
outfile.write(line)
infile.close()
outfile.close()

or maybe

infile = open('infile.txt')
outfile = open('outfile.txt','w')
new_file = []
for line in infile:
if 'msgid' in line:
 #  transform line
 #  make sure the line ending is intact
new_file.append(line)
outfile.write(''.join(new_file)
infile.close()
outfile.close()




-- 

Tim Williams
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and UML

2007-10-09 Thread Diez B. Roggisch
 [EMAIL PROTECTED] wrote:

> On 9 Okt, 12:15, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>>  [EMAIL PROTECTED] wrote:
>> > Hi,
>>
>> > I'm working with Python2.5 and pythonWin.
>>
>> > I'd like to start working with and learning more with UML. Can anyone
>> > suggest any freeware design software that I might use to do this? I
>> > also have
>> > Visio installed on my computer if thats of any use...
>>
>> ArgoUML as modelling tool. The python-IDE eric also generates UML from
>> class-hierarchies.
>>
>> IMHO UML is ... crap, at least when it comes to actual developing. But
>> apart from that very personal opinion, the non-static-typedness of Python
>> makes it hard to bring UML to it's full (however small that is in my POV)
>> power.
>>
>> Diez
> 
>>> IMHO UML is ... crap, at least when it comes to actual developing. But
>>> apart
> from that very personal opinion, the non-static-typedness of Python
> makes
> it hard to bring UML to it's full (however small that is in my POV)
> power.
> 
> What alternatives are there?

Alternatives to what? UML? None. There is no thing that allows you to sit at
a round table, push some rectangles around until everyone at the table
feels comfy & cozy and then release. Coding means typing. 

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python + Shoutpy + Twisted Locks

2007-10-09 Thread Jean-Paul Calderone
On Mon, 08 Oct 2007 23:00:46 GMT, John Nagle <[EMAIL PROTECTED]> wrote:
>Chris Mellon wrote:
>> On 10/7/07, Michel Albert <[EMAIL PROTECTED]> wrote:
>>> On Oct 6, 4:21 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
 En Fri, 05 Oct 2007 04:55:55 -0300, exhuma.twn <[EMAIL PROTECTED]> 
 escribi?:

> [...] What I found
> is that "libshout" is blocking, which should be fine as the whole
> thing runs in it's separate thread. But the application hangs
> nevertheless while streaming. This effectively blocks out the other
> thread that checks the player status, which then fails to append new
> songs to the queue. So only one song is played when streaming.
> The other threads in my application run fine and don't block the rest
> of the app. So I guess, that the main problem is that blocking occurs
> "outside" the python world and "inside" the libshout world.
 Only one thread at a time may be executing Python code; the Global
 Interpreter Lock (GIL) ensures the mutual exclusion. Extension modules
 (written in C) may use the macros
 Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS to release/acquire the GIL
 before/after an external blocking call.
 I don't know libshout, or how you are doing the binding python-libshout,
 but if your analysis is correct it means that the code is not releasing
 the GIL at the appropiate points.

 --
 Gabriel Genellina
>>> Hmmm... ok. I suppose rewriting the whole thing using twisted's
>>> deferreds could then solve the problem. Which are basically nothing
>>> more than callbacks with a weird name ;) Unfortunately this means that
>>> I have to re-think a lot. But in the end I suppose it will pay off.
>>>
>>> Thanks for taking the time and reading my little essay Gabriel ;)
>>>
>>
>> Using Twisted won't help if the libshout calls are really blocking the
>> main thread.
>
> Right.
>
> The whole point of Twisted is that you can't do anything that takes
>very long in a Twisted thread, or the whole server will stall.  If you
>try to do something ongoing, like streaming, in a Twisted server, you
>have to have long-running threads of your own and a scheduling system
>to coordinate them with the Twisted threads.

Except, of course, that there isn't any such thing as a "Twisted thread". :)

Jean-Paul
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: property question

2007-10-09 Thread Bruno Desthuilliers
Manu Hack a écrit :
> hi all,
> 
> If I have a class A with A.x, A.y, A.z.  A.y and A.z are property and
> in order to compute the value of them, A.y depends on A.x while A.z
> depends on A.y and A.x.  If I call A.y, and A.z, the value A.y would
> be computed twice.  Is there a smart way to avoid that as to A.y will
> be recomputed only if A.x has been changed?  Now I can define more
> variables to keep track of what is changed but when there are more
> variables and the dependency becomes more involved it could be very
> complicated.  Thanks a lot.
> 

A Q&D solution is to use a local cache (usually a dict with propnames as 
keys), and have any 'setter' invalidate that cache, ie:

def cached_property(fn):
   propname = fn.__name__
   def fget(self):
 return self._from_cache(propname, fn)
   def fset(self, val):
 raise AttributeError("%s.%s is readonly" % (self, propname))
   return property(fget, fset)

class A(object):
   def __init__(self, x):
 self._cache = {}
 self.x = x

   def _from_cache(self, name, fn):
 try:
   return self._cache[name]
 except KeyError:
   val = fn(self)
   self._cache[name] = val
   return val

   def _invalidate_cache(self, *names):
 for name in names:
   try:
 del self._cache[name]
   except KeyError, e:
 #print "%s : %s not in %s" % (e, name, self._cache)
 pass

   @apply
   def x():
 def fget(self):
   return self._x
 def fset(self, x):
   self._x = x
   # dependencies here - would be nice to have
   self._invalidate_cache('y', 'z')
 return property(**locals())

   @cached_property
   def y(self):
 return self.x + 2

   @cached_property
   def z(self):
 return self.x * (self.y / 2.0)

The remaining problem is that here, it's x that have the knowledge of 
who depends on it. This knowledge would be better expressed as a param 
or the @cached_property decorator and stored somewhere, so that the call 
to _invalidate cache would take the name of the property itself (here 
'x') instead of the list of dependent cached properties. This can be 
done at least with a custom metaclass - implementation left as an 
exercice to the reader !-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Editing particular lines of a text file.

2007-10-09 Thread Larry Bates
Shriphani wrote:
> Hello all,
> 
> I am trying to create a script that looks at specific strings in a
> file like:
> 
> msgid "I am a disco dancer."
> 
> and compares the part in quotes to the keys in a dictionary, finds the
> value and creates a new line right after this string in the file. I
> have planned to write this as follows:
> 
> 1. Open the file in read mode
> 2. parse each line to figure out which line contains "msgid" and use
> the shlex module's split method to go and split this line and pick the
> 2nd element list[1].
> 3. find the value from the dictionary corresponding to the above
> element.
> 4. Insert the line. This part is where I face a problem. How do I
> plainly edit just one line. I would also like to look at some sample
> code that does this.
> 5. open a new file and write the new file with the inserted strings to
> it.
> 6. close both files opened.
> 
> Regards,
> Shriphani Palakodety
> 

Sounds like homework, but I'm feeling generous (not tested).

xlate={'"I am a disco dancer."':'"but John Travolta is better"'}


fp1=open('inputfile.txt', 'r')
fp2=open('outputfile.txt', 'w')

for line in fp1:
 #
 # Your description is unclear here about whether the new line
 # replaces the existing one or is inserted after it.
 #
 fp2.writeline(line)
 if line.startswith('msgid'):
parts=line.split(' ')
 try: parts[1]=xlate[parts[1]]
except:
 #
 # Handle exception if your translation dictionary does
 # not have the string you are looking for here.
 #
 raise KeyError

newline=' '.join(parts)
 fp2.writeline(newline)

fp1.close()
fp2.close()


-Larry
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The fundamental concept of continuations

2007-10-09 Thread Matthias Benkard
> (3) Is it present in python ...?

I don't keep up to date with the recent developments in Python land,
but the last time I used Python, it certainly didn't have first-class
continuations.  There used to be a project called Stackless Python
that tried to add continuations to Python, but as far as I know, it
has always been separate from the official Python interpreter.  I
don't know whether it's still alive.  You may want to check 
http://stackless.com/
for details.


> (6) any good readable references that explain it lucidly ?

If you are familiar with Python syntax, there's
http://www.ps.uni-sb.de/~duchier/python/continuations.html -- and even
if you aren't, you may want to have a look at it, as simple Python
code is ridiculously easy to read.

~ Matthias

-- 
http://mail.python.org/mailman/listinfo/python-list


Drop folder and race conditions

2007-10-09 Thread Larry Bates
I have a need to implement a drop folder upload mechanism for secure uploading 
of files to a server.  At first glance this appears that it would be an easy 
application to write.  Then I begin to think about the race conditions that 
exist between the process that will wake up to upload the files and the fact 
that the user can add additional files to the drop folder at any point in time.
I would like to clear out files/folders after they have been processed but it 
is 
possible that while the background process was uploading files, the user added 
additional files/folders to the drop folder that make the deletion of folders 
impossible.  This project has become significantly more complex than it 
appeared 
at first.  Anyone out there have any "sage" advice on how to tackle this beast?

Thanks in advance for any pointers.

Regards,
Larry Bates
-- 
http://mail.python.org/mailman/listinfo/python-list


Virtual filesystem in python ( Fuse or WebDav ? )

2007-10-09 Thread Thomas W
I want to create a virtual filesystem based on a relational database.
It might run as a server on a different machine, but  it has to be
available like a normal filesystem, either shared using SAMBA or
windows filesharing or thru something else like WebDav.

The idea is that I scan a local filesystem and then create relations
between those files stored in a relational database, eg. a create a
group called family, add a bunch of files related to my family in that
virtual group/folder. When the user accesses the virtual filesystem
and types ls or dir the result is a list of groups, in my case ., ..
and family. The user types "cd family" and dir/ls in that virtual
folder will show all files in that group. How can this be done? I've
looked at dav, especially mod_dav and fuse. I want to be able to
access the files ( and even add files, like if I copy a file into the
family-folder, a relation in the relational database will be created,
but the newly added file itself might be stored some other place on
the filesystem, based on extension or perhaps EXIF-info if it's an
image being added ) using standard filesystem tools, like explorer on
win32 or the shell on linux.

I don't think I can use WebDav directly, because I want to control
what happens if somebody copies a file into a virtual folder, but I
don't know much about webdav so I might be wrong.

Any hint or clue would be appreciated.

-- 
http://mail.python.org/mailman/listinfo/python-list


tarfile...bug?

2007-10-09 Thread Anurag
Hi,

I am trying to use tarfile module to list contents of a 'gz' file but
it seems to hang for large files and CPU usage goes 100%.
though 'tar -tvf' on same file list contents in couple of secs.

Here is a test script which can show the problem; I am using python
Python 2.4.3


import tarfile

bigFilePath = "/tmp/bigFile"
bigFileTGZ = "/tmp/big.tar.gz"

# create a big file
print "Creating big file...",bigFilePath
f = open(bigFilePath,"w")
for i in xrange(100):
f.write("anurag"*1024*1024)
f.close()

#create a tarfile from big file
print "pack to...",bigFileTGZ
tar = tarfile.open(bigFileTGZ, "w:gz")
tar.add(bigFilePath,"bigFile")
tar.close()

print "unpack...",bigFileTGZ
# now try to list contents of tar
tar  = tarfile.open(bigFileTGZ, "r")
tar.list() #hangs


rgds
Anurag

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NUCULAR fielded text searchable indexing

2007-10-09 Thread Istvan Albert
On Oct 9, 7:26 am, [EMAIL PROTECTED] wrote:

> No, it doesn't stand for anything.

It also reminds me of someone we all know, and I wish it didn't.

As the latin proverb says "Nomen est omen". Calling your package
"docindexer" would draw a lot more people. It is hard to justify to a
third party that a project named "nucular" actually does something
useful.

It looks like a great piece of work otherwise. Congrats.

ps. there is a python project named "The Devil Framework", I cringe
every time I hear about it. Nucular is not as bad, but it is close.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why did MIT drop scheme for python in intro to computing?

2007-10-09 Thread J. Clifford Dyer
On Tue, Oct 09, 2007 at 06:28:00AM -0500, Harold Ancell wrote regarding Re: why 
did MIT drop scheme for python in intro to computing?:
> 
> On Tue, 09 Oct 2007 03:28:53 -, [EMAIL PROTECTED] wrote:
> 
> >On Oct 8, 1:23 pm, [EMAIL PROTECTED] (Brian Harvey) wrote:
> 
> >> "Kjetil S. Matheussen" <[EMAIL PROTECTED]> writes:
> 
> >> >I don't think your speculations makes very much sence.
> 
> >> Amen.
> 
> >> And, in any case, there's no need to speculate.
> >> MIT has published, on their web site, pages and
> >> pages of rationale for the new curriculum.
> 
> >> The most important point, imho, is that the
> >> programming language was the /least/ important
> >> aspect of the decision.  The most important
> >> aspect was the move to an application-based
> >> (rather than topic-based) organization of the
> >> curriculum.  The details flow out of that big
> >> shift of focus.
> 
> >[ much snipped. ]
> 
> >Does scheme have a gui library?
> 
> >I really dont follow the logic.
> 
> I really REALLY hope that not a single GUI is
> constructed in 6.01-2; adding that to the load
> would be stark raving mad (look and you'll agree).
> 
> As Brian points out, languages are a means to the
> end of teaching stuff, and I wouldn't be surprised
> if not a single GUI is constructed in the entire
> required/restricted elective curriculum.  That's
> just not to the point of an EECS education that
> has to be squeezed into 4/5 years (most students
> take the combined MEng path, where the MS degree
> is terminal and leads straight to industry).
> 
> If any library was a consideration in choosing
> Python, it was the robots one for 6.01.  Note also
> that Hal helped design and teach 6.01, and fully
> supports the new curriculum.
> 
> As a total LISP/Scheme fanatic who finds parts of
> Python's syntax to be too hard for his brain (not
> the indentation, that's weird but useful and cool,
> much like S-expressions in LISP), I looked hard at
> the beginning of 6.01 where they're only teaching
> SICP.
> 
> For that purpose, Python is not "awful" (remember,
> I believe LISP is the One True Way of Computing).
> For that initial bit of SICP material, I do not
> believe the students will be handicapped.
> 
> Beyond that initial bit of material, I have no
> informed opinions.
> 
>   - Harold
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list

I, for one, (coming from the Python side) would be thrilled to see a rigorous 
SICP-like book published using Python as its basis.  But maybe with the new 
change of focus to application based, that won't be forthcoming.  We'll see.

Cheers,
Cliff


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The fundamental concept of continuations

2007-10-09 Thread Matthias Blume
"." <[EMAIL PROTECTED]> writes:

> On Tue, 09 Oct 2007 05:15:49 +, gnuist006 wrote:
>
>> Again I am depressed to encounter a fundamentally new concept that I
>> was all along unheard of. Its not even in paul graham's book where i
>> learnt part of Lisp. Its in Marc Feeley's video.
>> 
>> Can anyone explain:
>> 
>> (1) its origin
> One of the lambda papers, I think.  I don't remember which.

This is a common misconception.  There is very little that
originated from the "lambda" papers.  But they did a marvelous job at
promoting some of the ideas that existed in the PL community for
years.

As for the concept of continuations, there is Scott and Strachey's
work on denotational semantics, and there is Landin's J operator.
(There's probably more that I am forgetting right now.)

>> (6) any good readable references that explain it lucidly ?
>

One of the most lucid explanations of definitional interpreters --
including those that are based on continuation-passing -- are
explained in J. Reynolds' famous 1971 "Definitional Interpreters for
Higher-Order Functions" paper.  (It has been re-published in 1998 in
HOSC.)  The paper also explains how to perform defunctionalization,
which can be seen as a way to compile (and even hand-compile)
higher-order programs.

Matthias
-- 
http://mail.python.org/mailman/listinfo/python-list


Lamaizm... XML problem...

2007-10-09 Thread durumdara

Hi!

Something makes me crazy!!!
I wanna read some XML, but everytime I got "None" for the value of prop:

The code is:

from xml.dom import minidom
import sys

ResultList = []

def LoadProps(PropTag):
   print PropTag
   t_forms = PropTag.getElementsByTagName('form')
   for t_form in t_forms:
   t_comps = t_form.getElementsByTagName('component')
   for t_comp in t_comps:
   t_props = t_comp.getElementsByTagName('prop')
   for t_prop in t_props:
   attrs = t_prop.attributes.keys()
   print attrs
   print t_prop.nodeName
   print t_prop.nodeType
   print [t_prop.nodeValue]
   sys.exit()
  


doc = minidom.parse('c:\\teszt3.xml')
print doc
t_langfile = doc.documentElement
t_props = doc.getElementsByTagName('properties')[0]
t_constants = doc.getElementsByTagName('constants')[0]
LoadProps(t_props)

---
The result is:

>>>


[u'id', u'name']
prop
1
[None]
>>>
---

The source file is:













---
I can get the attrs, but I can't get nodeValue ()... I got None for it.

Why???

Please help me a little!!! I'm sure that I miss st, but I don't know 
what is that... :-(


Thanks for it:
   dd













-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Lamaizm... XML problem...

2007-10-09 Thread Stefan Behnel
durumdara wrote:
> from xml.dom import minidom
[...]
>t_props = t_comp.getElementsByTagName('prop')
>for t_prop in t_props:
>attrs = t_prop.attributes.keys()
>print attrs
>print t_prop.nodeName
>print t_prop.nodeType
>print [t_prop.nodeValue]
>sys.exit()
> ---
> The result is:
> 

> 
> 
> [u'id', u'name']
> prop
> 1
> [None]

> ---
> 
> The source file is:
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> ---
> I can get the attrs, but I can't get nodeValue ()... I got None for it.

The W3C DOM treats text as nodes, so you have to check the children of t_prop
to find the text node and then read its nodeValue.

Alternatively, consider using an XML library that actually helps users in
working with XML, such as ElementTree or lxml.

http://codespeak.net/lxml

Stefan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NUCULAR fielded text searchable indexing

2007-10-09 Thread aaron . watters
On Oct 9, 8:46 am, Istvan Albert <[EMAIL PROTECTED]> wrote:
> ps. there is a python project named "The Devil Framework", I cringe
> every time I hear about it.Nucularis not as bad, but it is close.

Aw shucks.  I thought it was funny.  Can't I make fun of
politicians in my open source projects?  Besides there is
a great tradition of tounge-in-cheek package names, like
"Cold fusion", for example.

Actually one reason I chose it, is I own nucularOption.com and
also http://nucular.sourceforge.net was available.

too late now.  sorry again,
  -- Aaron Watters

===
It's humbling to think
that when Mozart was my age
he'd been dead for 10 years.
  -- Tom Lehrer

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The fundamental concept of continuations

2007-10-09 Thread Joel J. Adamson
[EMAIL PROTECTED] writes:

> On Oct 8, 10:59 pm, Barb Knox <[EMAIL PROTECTED]> wrote:
>
>>
>> Lambda calculus.  Instead of function A returning to its caller, the
>> caller provides an additional argument (the "continuation") which is a
>> function B to be called by A with A's result(s).  In pure "continuation
>> style" coding, nothing ever "returns" a result.
>>
>> It is easy to mechanically transform normal function-style lambda
>> calculus into continuation-style, but the reverse is not so.
>>
>
> Explanation and reference please

Read R5RS or R6RS, the passage on call-with-current-continuation is similar in 
both
texts ( http://www.r6rs.org/final/html/r6rs/r6rs.html ).

For lambda calculus, look it up on Wikipedia.  Alonzo Church is the
name you're looking for.

Joel

-- 
Joel J. Adamson
Biostatistician
Pediatric Psychopharmacology Research Unit
Massachusetts General Hospital
Boston, MA  02114
(617) 643-1432
(303) 880-3109
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: picture filter

2007-10-09 Thread Michael
You can do do some kinds of image filtering to get a good idea but it's a
lot of work and not a simple script you can throw together. I've tagged and
processed millions of photos through my system to train it and I'm still
constantly finding ways to improve it.

> hii my friends
> > ı want to a filter for porn picture
> > if you know , please help me :S:S
> > how  do ı separate porn form not porn
> > I don't want my web site porn;)
> > (my english bad I hope understant it. very very thans )
>
> If anybody know how to do that, he or she would immediatly become
> incredibly rich, selling this magic filter to concerned parents as well
> as eager porn enthusiasts, to help them filter away the noise or dirt,
> from their respective viewpoints that is of course...
>
> So - you're out of luck buddy. Nobody will be able to help you.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: why did MIT drop scheme for python in intro to computing?

2007-10-09 Thread Joel J. Adamson
[EMAIL PROTECTED] writes:

> On Oct 8, 1:23 pm, [EMAIL PROTECTED] (Brian Harvey) wrote:
>> "Kjetil S. Matheussen" <[EMAIL PROTECTED]> writes:

[...]

>
> Does scheme have a gui library?

Scheme is not a language, it's a standard for implementation.  How
much implementors choose to implement is entirely up to them.

PLT Scheme, a particular implementation of Scheme, does have graphics
and GUI libraries.

Joel

-- 
Joel J. Adamson
Biostatistician
Pediatric Psychopharmacology Research Unit
Massachusetts General Hospital
Boston, MA  02114
(617) 643-1432
(303) 880-3109
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pytz has so many timezones!

2007-10-09 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

> On Oct 8, 1:03 pm, Carsten Haese <[EMAIL PROTECTED]> wrote:
>> On Mon, 2007-10-08 at 10:41 -0700, [EMAIL PROTECTED] wrote:
>> > For example, Windows has seperate listings for
>>
>> > Central America
>> > Central Time (US & Canada)
>> > Guadalahara, Mexico City, Monterry - New
>> > Guadalahara, Mexico City, Monterry - Old
>> > Saskatchewan
>>
>> > but they are all GMT-6
>>
>> But they could have different rules for Daylight Saving Time.
> 
> Which only matters if you're setting your clock.

That's BS. If I'm supposed to be attending a video-conference that spans a
few continents which is scheduled using a web-app, it's VITAL that I get
the invitation and reminder rendered in MY local timezone, DST included.

And for the matter of 

"""
There are only 25 timezones: -12, -11, ... -1, 0 (GMT), +1, ... +11,
+12.
"""

who says that timezones have to be separated by one hour each? Why aren't
they separated by 30minutes, or 20, or 10? Or 2 hours? Or why don't we have
a global time?

Your 25 timezones are an abstraction the same way as are the 400 apparently
in use by people all over the world - and last time I checked, there was no
fundamental law in physics or such that limited the allowed or sensible
number of timezones...

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NUCULAR fielded text searchable indexing

2007-10-09 Thread Steven D'Aprano
On Tue, 09 Oct 2007 12:46:34 +, Istvan Albert wrote:

> On Oct 9, 7:26 am, [EMAIL PROTECTED] wrote:
> 
>> No, it doesn't stand for anything.
> 
> It also reminds me of someone we all know, and I wish it didn't.
> 
> As the latin proverb says "Nomen est omen". Calling your package
> "docindexer" would draw a lot more people. It is hard to justify to a
> third party that a project named "nucular" actually does something
> useful.

Yeah, like those crappy products "Linux", "Lisp", "Apache", "Windows", 
"Java", "Google", "Yahoo" and especially "Python". Can you imagine trying 
to tell your boss that you want to use something called "Python" for your 
programming project?


*wink*



-- 
Steven.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Drop folder and race conditions

2007-10-09 Thread Steven D'Aprano
On Tue, 09 Oct 2007 07:05:57 -0500, Larry Bates wrote:

> I have a need to implement a drop folder upload mechanism for secure
> uploading of files to a server.  At first glance this appears that it
> would be an easy application to write.  Then I begin to think about the
> race conditions that exist between the process that will wake up to
> upload the files and the fact that the user can add additional files to
> the drop folder at any point in time. I would like to clear out
> files/folders after they have been processed but it is possible that
> while the background process was uploading files, the user added
> additional files/folders to the drop folder that make the deletion of
> folders impossible.  This project has become significantly more complex
> than it appeared at first.  Anyone out there have any "sage" advice on
> how to tackle this beast?


Off the top of my head...

Recursively copy the contents of each folder to the server, deepest 
first, deleting each file as it's copied. Then delete the folder as soon 
as you've emptied it (but naturally not the top-level drop folder). If it 
happens to *not* be empty (because the user has added additional files to 
it), just catch the error and ignore it. In another few minutes, you'll 
try again, copying the newly added files and then delete the folder.

Because each file is being deleted as soon as it is copied, you'll won't 
build up an ever-increasing collection of files. At worst, you may have a 
collection of folders -- but unless you're fighting a hostile process 
that can add folders quicker than you can delete them, you'll eventually 
win.

Maybe you need a heuristic that says "if the number of 'directory not 
empty' errors keeps increasing, assume we're dealing with a hostile 
process and take extra steps". Say, lock the drop folder for five minutes 
while you flush it.

Another possibility is that before you start copying from the folders, 
you change their permissions to prohibit the user adding extra files into 
them. That way, nothing can be added to them once you start copying, and 
you can be sure that you can delete them once empty.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The fundamental concept of continuations

2007-10-09 Thread [EMAIL PROTECTED]
On Oct 9, 2:09 am, "." <[EMAIL PROTECTED]> wrote:
> On Tue, 09 Oct 2007 05:15:49 +, gnuist006 wrote:

> > (3) Is it present in python and java ?
>
> Certainly not Java, I dunno about Python.  I've never seen someone use
> them in Python, but the pythonistas seem to want to add everything but a
> decent lambda to their language so I wouldn't be surprised if someone had
> added a call/cc.  Ruby has it.
>

Continuations exist in all computer languages---actually, in anything
that executes code. The continuation is simply "what will happen for
the rest of the program execution." What might or might not exist is
an explicit linguistic mechanism to examine it, refer to the
continuation as a function, or to save it for later use.

> > (4) Its implementation in assembly. for example in the manner that
> > pointer fundamentally arises from indirect addressing and nothing new.
> > So how do you juggle PC to do it.
>

The continuation is typically present in the stack, which contains all
the control-flow information needed to continue program execution from
this point. (I.e., the function call mechanism includes a step saving
the location of the instruction to execute when the function call is
complete, and any registers that it will restore after the function
returns because the function call might destroy them.)

How you save that continuation for later, possibly repeated, use from
a different location in the program is a different question.

-- 
http://mail.python.org/mailman/listinfo/python-list


Problem with argument parsing

2007-10-09 Thread lgwe
I have a python-script: myscript, used to start a program on another
computer and I use OptionParser in optpars.
I use it like this: myscript -H host arg1 -x -y zzz
I would like OptionParser to ignore all arguments after arg1, because
these are options that should be used by the program started on the
oter computer arg1 -x -y zzz.
One solution is to write: myscript -H host "arg1 -x -y zzz"
But is it in some way possible to instruct OptionParser to ignore -x -
y zzz without  the "..."?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why did MIT drop scheme for python in intro to computing?

2007-10-09 Thread Grant Edwards
On 2007-10-09, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> Comparing apples with apples, how do you compare the scheme
> gui library with wxpython ? Isnt it better than Tkinter ?

I haven't used the newer Scheme GUI bindings.  I switched from
STk to tkinter, and then from tkinter to PyGTK and wxPython.  I
found Scheme much easier to use than TCL (an horrible, horrible
language, IMO), but Python is easier yet than Scheme except for
the Tk integration features.

The GTK and wxWidgets Python bindings are native bindings
rather than the TCL-hack used for tkinter, so I would expect a
native GTK or wxWidgets Scheme binding to be quite similar to a
native Python binding for the same library.  However, a lot of
extra work has gone into polishing the wxPython features above
and beyond simply the library bindings, so I wouldn't be
surprised if wxPython is better than a vanilla Scheme wxWidgets
biding.

-- 
Grant Edwards   grante Yow! Did an Italian CRANE
  at   OPERATOR just experience
   visi.comuninhibited sensations in
   a MALIBU HOT TUB?
-- 
http://mail.python.org/mailman/listinfo/python-list


List loops

2007-10-09 Thread Tommy Grav
Hi everyone,

   I have a list of objects where I have want to do two loops.
I want to loop over the list and inside this loop, work on all
the elements of the list after the one being handled in the outer
loop. I can of course do this with indexes:

 >>> alist = range(3)
 >>> for i in xrange(len(alist)):
...   for j in xrange(i+1,len(alist)):
... print i,j,alist[i],alist[j]
...
0 1 0 1
0 2 0 2
1 2 1 2
 >>>


Is there a way to do this without using indexes?

Cheers
Tommy



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Memory leak/gc.get_objects()/Improved gc in version 2.5

2007-10-09 Thread Chris Mellon
On 10/8/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> I'm running a python program that simulates a wireless network
> protocol for a certain number of "frames" (measure of time).  I've
> observed the following:
>
> 1. The memory consumption of the program grows as the number of frames
> I simulate increases.
>
> To verify this, I've used two methods, which I invoke after every
> frame simulated:
>
> --  Parsing the /proc//status file as in:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286222
> --  Using ps vg | grep python | awk '!/grep/ {print " ",$8}'  in an
> os.system() call.
>
> The memory usage vs. frame number graph shows some big "jumps" at
> certain points, and, after a large number of frames, shows a steady
> upward slope
>

This would be expected if you're creating ever-larger amounts of
objects - python uses memory pools and as the number of simultaneous
objects increases, the size of the pool will need to increase. This
isn't expected if the total number of objects you create is pretty
much static, but the way you're trying to determine that is flawed
(see below).

> 2. I think I've verified that the objects I instantiate are actually
> freed-- I'm therefore assuming that this "leak" is "caused" by
> python's garbage collection mechanism. I count the number of objects I
> generate that are being tracked by gc as follows:
>
> gc.collect()
> objCount = {}
> objList = gc.get_objects()
> for obj in objList:
> if getattr(obj, "__class__", None):
> name = obj.__class__.__name__
> if objCount.has_key(name):
> objCount[name] += 1
> else:
> objCount[name] = 1
>
> for name in objCount:
> print name, " :", objCount[name]
>
>del objList
>
> Running this snippet every hundred frames or so, shows that the number
> of objects managed by gc is not growing.
>
> I upgraded to Python 2.5. in an attempt to solve this problem. The
> only change in my observations from version 2.4 is that the absolute
> memory usage level seems to have dropped. However, I still see the
> jumps in memory usage at the same points in time.
>
> Can anybody explain why the memory usage shows significant jumps (~200
> kB or ~500 kb) over time (i.e. "frames") even though there is no
> apparent increase in the objects managed by gc? Note that I'm calling
> gc.collect() regularly.
>

You're misunderstanding the purpose of Pythons GC. Python is
refcounted. The GC exists only to find and break reference cycles. If
you don't have ref cycles, the GC doesn't do anything and you could
just turn it off.

gc.get_objects() is a snapshot of the currently existing objects, and
won't give you any information about peak object count, which is the
most direct correlation to total memory use.

> Thanks for your attention,
>
> Arvind
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Virtual filesystem in python ( Fuse or WebDav ? )

2007-10-09 Thread Grant Edwards
On 2007-10-09, Thomas W <[EMAIL PROTECTED]> wrote:

> I want to create a virtual filesystem based on a relational
> database. [...]

http://en.wikipedia.org/wiki/Filesystem_in_Userspace
http://fuse.sourceforge.net/

-- 
Grant Edwards   grante Yow! I'm a nuclear
  at   submarine under the
   visi.compolar ice cap and I need
   a Kleenex!
-- 
http://mail.python.org/mailman/listinfo/python-list


Mixing Python and C classes in a module

2007-10-09 Thread Stefan Arentz

Is it possible to mix classes defined in both Python and C in the same
module? Ideally I would like to be able to do:

 from some.module import MyPythonClass, MyCClass

I guess that would mean that this would look like this on disk:

 some/
   __init__.py
   module.py  (contains MyPythonClass)
   module.so  (contains MyCClass)

But would this work?

 S.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: supplying password to subprocess.call('rsync ...'), os.system('rsync ...')

2007-10-09 Thread timw.google
On Oct 7, 1:01 pm, Michael Torrie <[EMAIL PROTECTED]> wrote:
> timw.google wrote:
> > Hi
>
> > I want to write a python script that runs rsync on a given directory
> > and host. I build the command line string, but when I try to run
> > subprocess.call(cmd), or p=subprocess.Popen(cmd, shell=True),or
> > os.system(cmd), I get prompted for my login password. I expected this,
> > but when I try to give my password, it's echoed back to the terminal
> > and the special characters in the password is (I think) getting
> > interpreted by the shell (zsh)
>
> > I can't ssh w/o supplying a password. That's the way the security is
> > set up here.
>
> > How do I use python to do this, or do I just have to write a zsh
> > script?
>
> You need to use the pexpect module.
>
>
>
> > Thanks.

Thanks to all the suggestions on getting this to work w/ python. I'll
look into this more when I get the chance. I don't have root access,
so setting up some kind of server is out. I may not be able to try the
other suggestions either, as they have things locked down pretty tight
around here.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mixing Python and C classes in a module

2007-10-09 Thread Chris Mellon
On 09 Oct 2007 16:56:30 +0200, Stefan Arentz <[EMAIL PROTECTED]> wrote:
>
> Is it possible to mix classes defined in both Python and C in the same
> module? Ideally I would like to be able to do:
>
>  from some.module import MyPythonClass, MyCClass
>
> I guess that would mean that this would look like this on disk:
>
>  some/
>__init__.py
>module.py  (contains MyPythonClass)
>module.so  (contains MyCClass)
>
> But would this work?
>

No, you'll need to make module a package, and import from (differently
named) implementation packages.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mixing Python and C classes in a module

2007-10-09 Thread Kay Schluehr
On Oct 9, 4:56 pm, Stefan Arentz <[EMAIL PROTECTED]> wrote:
> Is it possible to mix classes defined in both Python and C in the same
> module? Ideally I would like to be able to do:
>
>  from some.module import MyPythonClass, MyCClass
>
> I guess that would mean that this would look like this on disk:
>
>  some/
>__init__.py
>module.py  (contains MyPythonClass)
>module.so  (contains MyCClass)
>
> But would this work?
>
>  S.

Yes, but you need to write your own importer and customize it using
ihooks.py. The builtin imp module also contains a function new_module
that lets you allow creating a module without any file reference. This
can be returned containg the names of both module.py and module.so.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with argument parsing

2007-10-09 Thread Diez B. Roggisch
lgwe wrote:

> I have a python-script: myscript, used to start a program on another
> computer and I use OptionParser in optpars.
> I use it like this: myscript -H host arg1 -x -y zzz
> I would like OptionParser to ignore all arguments after arg1, because
> these are options that should be used by the program started on the
> oter computer arg1 -x -y zzz.
> One solution is to write: myscript -H host "arg1 -x -y zzz"
> But is it in some way possible to instruct OptionParser to ignore -x -
> y zzz without  the "..."?

Use -- to separate arguments to be parsed by OptionParser from the
to-be-ignored-ones, which is documented btw.

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List loops

2007-10-09 Thread Tim Chase
>  >>> alist = range(3)
>  >>> for i in xrange(len(alist)):
> ...   for j in xrange(i+1,len(alist)):
> ... print i,j,alist[i],alist[j]
> ...
> 0 1 0 1
> 0 2 0 2
> 1 2 1 2
>  >>>
> 
> 
> Is there a way to do this without using indexes?

The following works for me, replicating your code,

 >>> alist = range(3)
 >>> for i, itemA in enumerate(alist):
... for j, itemB in enumerate(alist[i+1:]):
... print i,j+i+1,itemA, itemB
...
0 1 0 1
0 2 0 2
1 2 1 2


and is swappable if your alist has other values in it too:

 >>> alist = ['dog', 'cat', 'mouse']
 >>> for i, itemA in enumerate(alist):
... for j, itemB in enumerate(alist[i+1:]):
... print i,j+i+1,itemA, itemB
...
0 1 dog cat
0 2 dog mouse
1 2 cat mouse


However, if your list only has those range() values in it, 
there's nothing wrong with doing something like

 >>> for i in alist:
... for j in alist[i+1:]:
... print i,j,i,j
...

It looks like you're trying to do permutations/combinations of 
things, in which case you might also find this helpful:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/190465


-tim





-- 
http://mail.python.org/mailman/listinfo/python-list


Native class methods

2007-10-09 Thread Stefan Arentz

Is there an easy way to implement a specific method of a Python class
in C? Like a native method in Java? I would really like to do the
majority of my class code in Python and just do one or two methods
in C.

 S.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List loops

2007-10-09 Thread Chris Mellon
On 10/9/07, Tommy Grav <[EMAIL PROTECTED]> wrote:
> Hi everyone,
>
>I have a list of objects where I have want to do two loops.
> I want to loop over the list and inside this loop, work on all
> the elements of the list after the one being handled in the outer
> loop. I can of course do this with indexes:
>
>  >>> alist = range(3)
>  >>> for i in xrange(len(alist)):
> ...   for j in xrange(i+1,len(alist)):
> ... print i,j,alist[i],alist[j]
> ...
> 0 1 0 1
> 0 2 0 2
> 1 2 1 2
>  >>>
>
>
> Is there a way to do this without using indexes?
>

>>> for idx, i in enumerate(alist):
... for jdx, j in enumerate(range(1,4)):
... print idx, jdx, i, j
...
0 0 0 1
0 1 0 2
0 2 0 3
1 0 1 1
1 1 1 2
1 2 1 3
2 0 2 1
2 1 2 2
2 2 2 3
>>>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Query

2007-10-09 Thread Nathaniel Smith
> I want to make a binary file , which would execute on it's own.

First do
$ which python
to get the location of your python binary. The default, i think, is just
/usr/bin/python.

Then add this line to the top of your file:
#!/usr/bin/python  (or whatever the `which` command returned)

then finally do this command:
$ chmod +x .py

This makes  executable ( that's what the x stands for ).

now run it with:
$ ./.py

you can also trim the .py from the file and it will work just the same.

To have your script work like installed binaries, put it in a folder in your
PATH variable. For example, if you added the path /home//bin/ to your
path variable ( PATH=$PATH:/home//bin/ ) Bash would search that
directory when you typed in a command to execute. What this means is if you
rename your .py to just  and stick it in /home//bin/ you
could just do

$ 

at any time to run your program.

hope my verbosity is helpful.

-- 
-Nate
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Native class methods

2007-10-09 Thread Chris Mellon
On 09 Oct 2007 17:20:09 +0200, Stefan Arentz <[EMAIL PROTECTED]> wrote:
>
> Is there an easy way to implement a specific method of a Python class
> in C? Like a native method in Java? I would really like to do the
> majority of my class code in Python and just do one or two methods
> in C.
>
>  S.
>

Weave kinda does this - you can use it write inline C code, which it
extracts and compiles for you. (http://scipy.org/Weave)

You might also want to look at Pyrex and/or Cython, which let you
write in a Python-like language that is compiled to C.
(http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/ and
http://cython.org).

Depending on what you want to do in C, just writing it as a normal
shared library and calling it with ctypes might also be an effective
solution. (in the standard library, as of 2.5)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Native class methods

2007-10-09 Thread Diez B. Roggisch
Stefan Arentz wrote:

> 
> Is there an easy way to implement a specific method of a Python class
> in C? Like a native method in Java? I would really like to do the
> majority of my class code in Python and just do one or two methods
> in C.

ctypes or subclassing C-implemented classes.

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: List loops

2007-10-09 Thread Hamilton, William
> From: Tommy Grav
> 
> Hi everyone,
> 
>I have a list of objects where I have want to do two loops.
> I want to loop over the list and inside this loop, work on all
> the elements of the list after the one being handled in the outer
> loop. I can of course do this with indexes:
> 
>  >>> alist = range(3)
>  >>> for i in xrange(len(alist)):
> ...   for j in xrange(i+1,len(alist)):
> ... print i,j,alist[i],alist[j]
> ...
> 0 1 0 1
> 0 2 0 2
> 1 2 1 2
>  >>>
> 
> 
> Is there a way to do this without using indexes?
> 

You have to use indices because you are printing the indices.  Given
that, the following loop does what it looks like you are trying to do.

>>> alist = range(3)
>>> for index, i in enumerate(alist):
for jndex, j in enumerate(alist[index:]):
print index, jndex, i, j


0 0 0 0
0 1 0 1
0 2 0 2
1 0 1 1
1 1 1 2
2 0 2 2
>>>


--
-Bill Hamilton
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Native class methods

2007-10-09 Thread Stefan Arentz
"Chris Mellon" <[EMAIL PROTECTED]> writes:

> On 09 Oct 2007 17:20:09 +0200, Stefan Arentz <[EMAIL PROTECTED]> wrote:
> >
> > Is there an easy way to implement a specific method of a Python class
> > in C? Like a native method in Java? I would really like to do the
> > majority of my class code in Python and just do one or two methods
> > in C.
> >
> >  S.
> >
> 
> Weave kinda does this - you can use it write inline C code, which it
> extracts and compiles for you. (http://scipy.org/Weave)
> 
> You might also want to look at Pyrex and/or Cython, which let you
> write in a Python-like language that is compiled to C.
> (http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/ and
> http://cython.org).
> 
> Depending on what you want to do in C, just writing it as a normal
> shared library and calling it with ctypes might also be an effective
> solution. (in the standard library, as of 2.5)

Yeah I'm really trying to do this without any dependencies on external
libraries. The ctypes way looks interesting but I had really hoped for
something more JNI-like :-/

 S.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Native class methods

2007-10-09 Thread Jean-Paul Calderone
On 09 Oct 2007 17:45:12 +0200, Stefan Arentz <[EMAIL PROTECTED]> wrote:
>"Chris Mellon" <[EMAIL PROTECTED]> writes:
>
>> On 09 Oct 2007 17:20:09 +0200, Stefan Arentz <[EMAIL PROTECTED]> wrote:
>> >
>> > Is there an easy way to implement a specific method of a Python class
>> > in C? Like a native method in Java? I would really like to do the
>> > majority of my class code in Python and just do one or two methods
>> > in C.
>> >
>> >  S.
>> >
>>
>> Weave kinda does this - you can use it write inline C code, which it
>> extracts and compiles for you. (http://scipy.org/Weave)
>>
>> You might also want to look at Pyrex and/or Cython, which let you
>> write in a Python-like language that is compiled to C.
>> (http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/ and
>> http://cython.org).
>>
>> Depending on what you want to do in C, just writing it as a normal
>> shared library and calling it with ctypes might also be an effective
>> solution. (in the standard library, as of 2.5)
>
>Yeah I'm really trying to do this without any dependencies on external
>libraries. The ctypes way looks interesting but I had really hoped for
>something more JNI-like :-/
>

JNI is awful.  I can't imagine why you'd want something like it.  However,
since you do, why don't you just use the CPython/C API?  It's the direct
equivalent of JNI (sorry, it's not quite as complex or horrible, though).

  http://docs.python.org/api/api.html

Jean-Paul
-- 
http://mail.python.org/mailman/listinfo/python-list


Static variable vs Class variable

2007-10-09 Thread [EMAIL PROTECTED]
Hi.

I've got a question on the differences and how to define static and
class variables. AFAIK, class methods are the ones which receives the
class itself as an argument, while static methods are the one which
runs statically with the defining class.

Hence, my understanding is that static variables must be bound to the
class defining the variables and shared by children of parent class
where the variable is defined. But, please have a look at this code in
which a guy told me that the variable a is static:

>>> class Foo:
a = 1
@classmethod
def increment(cls):
cls.a += 1
print cls.a

Here, I am defining variable a which, I believe is class variable,
i.e., variable that is not bound to Foo itself. Rather, a is bound to
the class which is accessing the variable. The code that corroborates
this idea is as follows:

>>> class Child1(Foo):
pass

>>> Child1.increment()
4

>>> class Child2(Foo):
pass

>>> Child2.increment()
4

This means that Child1 and Child2 does not share variable a which
means that variable a is class variable rather than static variable.

Could you please comment on this? Is a static or class variable?
What's the most recent way of defining 'class' and 'static' variables?

Thanks.
- Minkoo

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Native class methods

2007-10-09 Thread Chris Mellon
On 09 Oct 2007 17:45:12 +0200, Stefan Arentz <[EMAIL PROTECTED]> wrote:
> "Chris Mellon" <[EMAIL PROTECTED]> writes:
>
> > On 09 Oct 2007 17:20:09 +0200, Stefan Arentz <[EMAIL PROTECTED]> wrote:
> > >
> > > Is there an easy way to implement a specific method of a Python class
> > > in C? Like a native method in Java? I would really like to do the
> > > majority of my class code in Python and just do one or two methods
> > > in C.
> > >
> > >  S.
> > >
> >
> > Weave kinda does this - you can use it write inline C code, which it
> > extracts and compiles for you. (http://scipy.org/Weave)
> >
> > You might also want to look at Pyrex and/or Cython, which let you
> > write in a Python-like language that is compiled to C.
> > (http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/ and
> > http://cython.org).
> >
> > Depending on what you want to do in C, just writing it as a normal
> > shared library and calling it with ctypes might also be an effective
> > solution. (in the standard library, as of 2.5)
>
> Yeah I'm really trying to do this without any dependencies on external
> libraries. The ctypes way looks interesting but I had really hoped for
> something more JNI-like :-/
>
>  S.

Weave is a runtime solution, but Pyrex and Cython are both compilers
(they compile a Python like language to C, which you the compile into
a single extension module), and ctypes is in the standard library.
Using ctypes would be pretty much just like JNI, except it's dynamic
and not horrible.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static variable vs Class variable

2007-10-09 Thread Laszlo Nagy
[EMAIL PROTECTED] wrote:
> Hi.
>
> I've got a question on the differences and how to define static and
> class variables. AFAIK, class methods are the ones which receives the
> class itself as an argument, while static methods are the one which
> runs statically with the defining class.
>
> Hence, my understanding is that static variables must be bound to the
> class defining the variables and shared by children of parent class
> where the variable is defined. But, please have a look at this code in
> which a guy told me that the variable a is static:
>
>   
 class Foo:
 
>   a = 1
>   @classmethod
>   def increment(cls):
>   cls.a += 1
>   print cls.a
>   
In your increment() method, you do this:

cls.a += 1

It does the following thing:

#1. read cls.a
#2. add one
#3. assign this value to cls.a

In point #3, you really bind a name to a value. As you probably know, in 
Python, there are names and objects. The initial value of the name 'a' 
is 1. It is an immutable object. The "+=" operator usually increments a 
value of an object. However, because the 'int' type is immutable, the += 
operator will rather rebind this variable to a newly created value. I 
believe this is what is happening here. Your question "is variable a 
static or class variable?" has no real answer. After running the 
increment() method on a descendant class, e.g. Child1 will rebind the 
name Child1.a, creating a new name in the namespace of the class. So the 
variable Foo.a is still there, but you are accessing Child1.a instead.

If you want to HANDLE a as a static variable, you can handle it with a 
static method. That won't bind a new name in the descendant class. 
(However, you can still rebind it, e.g. "Child.a=42")


Now here is a good question: how do you handle a variable as static, 
from a class (not static) method? Here is an example:

 >>> class Foo(object):
... a = 1
... @classmethod
... def increment(cls):
... Foo.a += 1
... print cls.a
...
 >>> class Child1(Foo):
... pass
...
 >>> Child1.increment()
2
 >>> Child1.increment()
3
 >>> Foo.a
3
 >>> Child1.a = 10
 >>> Child1.increment()
10
 >>> Child1.increment()
10
 >>> Child1.increment()
10
 >>> Foo.a
6
 >>>



However, the question is: why would you do this? :-)

BTW you should use new style classes whenever it is possible. Old style 
classes will have gone...

Hope this helps,

   Laszlo

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static variable vs Class variable

2007-10-09 Thread Marc 'BlackJack' Rintsch
On Tue, 09 Oct 2007 09:16:12 -0700, [EMAIL PROTECTED] wrote:

> I've got a question on the differences and how to define static and
> class variables.

First you have to define what you mean by "static".

> AFAIK, class methods are the ones which receives the
> class itself as an argument, while static methods are the one which
> runs statically with the defining class.

`classmethod`\s receive the class as first arguments, `staticmethod`\s are
just functions bound to the class object.

> Hence, my understanding is that static variables must be bound to the
> class defining the variables and shared by children of parent class
> where the variable is defined. But, please have a look at this code in
> which a guy told me that the variable a is static:

Ask the guy what he means by "static".

 class Foo:
>   a = 1
>   @classmethod
>   def increment(cls):
>   cls.a += 1
>   print cls.a
> 
> Here, I am defining variable a which, I believe is class variable,
> i.e., variable that is not bound to Foo itself.

No you define a class attribute that *is* bound to the class `Foo`.

> Rather, a is bound to the class which is accessing the variable. The code
> that corroborates this idea is as follows:
> 
 class Child1(Foo):
>   pass
> 
 Child1.increment()
> 4

Four!?  Hard to believe.

 class Child2(Foo):
>   pass
> 
 Child2.increment()
> 4
> 
> This means that Child1 and Child2 does not share variable a which means
> that variable a is class variable rather than static variable.
> 
> Could you please comment on this? Is a static or class variable? What's
> the most recent way of defining 'class' and 'static' variables?

There is no such thing as a "static" variable.  Think of attributes that
are bound to objects.  All dynamically.

What happens is: you bind a 1 to the attribute `Foo.a` in the `Foo` class
definition.

When you call `Child1.increment()` the class method will be called with
`Child1` as first argument.  Now ``cls.a += 1`` is executed which is
somewhat like a short form of ``cls.a = cls.a + 1``.  So this is reading
the attribute `a` from `Child1` and then bind the result to `Child1`. 
`Child1` doesn't have an attribute `a`, so it is looked up in the parent
class.  But the result is then bound to `Child1`.  So you are reading from
`Foo` and writing to `Child1`.  That's it.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The fundamental concept of continuations

2007-10-09 Thread Terry Reedy

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| Again I am depressed to encounter a fundamentally new concept that I
| was all along unheard of. Its not even in paul graham's book where i
| learnt part of Lisp. Its in Marc Feeley's video.
|
| Can anyone explain:
|
| (1) its origin
| (2) its syntax and semantics in emacs lisp, common lisp, scheme
| (3) Is it present in python and java ?
| (4) Its implementation in assembly. for example in the manner that
| pointer fundamentally arises from indirect addressing and nothing new.
| So how do you juggle PC to do it.
| (5) how does it compare to and superior to a function or subroutine
| call. how does it differ.
|
| Thanks a lot.
|
| (6) any good readable references that explain it lucidly ?

I am starting with the Wikipedia article 'Continuation' which has 
references both to other W. articles and several other books and papers. 



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static variable vs Class variable

2007-10-09 Thread Laszlo Nagy

> Your question "is variable a 
> static or class variable?" has no real answer. After running the 
> increment() method on a descendant class, e.g. Child1 will rebind the 
> name Child1.a, creating a new name in the namespace of the class. So the 
> variable Foo.a is still there, but you are accessing Child1.a instead.
>   
Please notice, that theoretically there is no way to "change the value" 
of Foo.a in any way, because this is a NAME that references to an 
IMMUTABLE OBJECT. It means that you can only rebind the variable. You 
cannot change its value, because when we are talking about its value, we 
mean the state of the referenced object. The object referenced by the 
name is an integer instance, namely it is "one". The object "one" always 
remains "one", this cannot be changed. You can add one to one, and you 
will get two, but that is another object.

(I'm sorry, probably you already knew this.)

  Laszlo

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: generator_tools-0.1 released

2007-10-09 Thread Steven Bethard
Kay Schluehr wrote:
> Originally I came up with the idea of a pure Python implementation for
> copyable generators as an ActiveState Python Cookbook recipe. Too bad,
> it was badly broken as Klaus Müller from the SimPy project pointed
> out. Two weeks and lots of tests later I got finally a running version
> that works not only in the very most simple use cases. As the code
> size increased it turned out to not really fit anymore into the
> "recipe" category and I created a package called "generator_tools".
> 
> generator_tools-0.1 is available for both Python 2.5 and Python 3.0
> (!)
[snip]
 pickler = GeneratorPickler("test.pkl")
 pickler.pickle_generator(g_gen)
 k_gen = pickler.unpickle_generator()
 list(g_gen) == list(k_gen)
> True

This seems like an odd syntax for pickling. Does the package support the 
normal pickle machinery?  That is, does it register the appropriate 
methods with the copy_reg module?

STeVe
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NUCULAR fielded text searchable indexing

2007-10-09 Thread Robin Becker
[EMAIL PROTECTED] wrote:
> On Oct 9, 8:46 am, Istvan Albert <[EMAIL PROTECTED]> wrote:
>> ps. there is a python project named "The Devil Framework", I cringe
>> every time I hear about it.Nucularis not as bad, but it is close.
> 
> Aw shucks.  I thought it was funny.  Can't I make fun of
> politicians in my open source projects?  Besides there is
> a great tradition of tounge-in-cheek package names, like
> "Cold fusion", for example.
>...

I think it's an excellent name :)
-- 
Robin Becker

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static variable vs Class variable

2007-10-09 Thread Matimus
On Oct 9, 9:16 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Hi.
>
> I've got a question on the differences and how to define static and
> class variables. AFAIK, class methods are the ones which receives the
> class itself as an argument, while static methods are the one which
> runs statically with the defining class.
>
> Hence, my understanding is that static variables must be bound to the
> class defining the variables and shared by children of parent class
> where the variable is defined. But, please have a look at this code in
> which a guy told me that the variable a is static:
>
> >>> class Foo:
>
> a = 1
> @classmethod
> def increment(cls):
> cls.a += 1
> print cls.a
>
> Here, I am defining variable a which, I believe is class variable,
> i.e., variable that is not bound to Foo itself. Rather, a is bound to
> the class which is accessing the variable. The code that corroborates
> this idea is as follows:
>
> >>> class Child1(Foo):
>
> pass
>
> >>> Child1.increment()
>
> 4
>
> >>> class Child2(Foo):
>
> pass
>
> >>> Child2.increment()
>
> 4
>
> This means that Child1 and Child2 does not share variable a which
> means that variable a is class variable rather than static variable.
>
> Could you please comment on this? Is a static or class variable?
> What's the most recent way of defining 'class' and 'static' variables?

In Python `a' is considered a class variable. By modifying `a' using a
class method though, you are essentially re-binding `a' to the class
that it is called from. So, it will be shared by multiple instances of
the same class, but not derivatives. The re-binding only occurs when
`increment' is called. This makes for some very confusing behavior.
I'm not aware of a way, in python, to explicitly specify a variable as
static. For the behavior I think you are looking for you just need to
modify it carefully. This can be done with a static, class or instance
method. Though, using a class method is kind of silly. I'm sure some
would argue that using an instance method is also silly.

code:

class C(object):
 a = 0
 def inc(self):
  C.a += 1 # directly modify the variable on the base class that it is
attached to
  return C.a

# or you could use a static method, which is fine since the instance
isn't being used. This
# will also allow the method to be called without instantiating the
class.

class C(object):
 a = 0
 @staticmethod
 def inc():
  C.a += 1
  return C.a

Matt

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static variable vs Class variable

2007-10-09 Thread Diez B. Roggisch
> In point #3, you really bind a name to a value. As you probably know, in 
> Python, there are names and objects. The initial value of the name 'a' 
> is 1. It is an immutable object. The "+=" operator usually increments a 
> value of an object. However, because the 'int' type is immutable, the += 
> operator will rather rebind this variable to a newly created value. I 
> believe this is what is happening here.

Your believes aside, this is simply wrong. The statement

a += x

always leads to a rebinding of a to the result of the operation +. I 
presume you got confused by the somewhat arbitrary difference between

__add__

and


__iadd__

that somehow suggest there is an in-place-modification going on in case 
of mutables.

but as the following snippet shows - that's not the case:


class Foo(object):
 def __add__(self, o):
 return "__add__"

 def __iadd__(self, o):
 return "__iadd__"


a = Foo()
a += 1
print a

a = Foo()
b = Foo()
c = a + b
print c

So you see, the first += overrides a with the returned value of __iadd__.

The reason for the difference though is most probably what you yourself 
expected: thus it's possible to alter a mutable in place.

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pytz has so many timezones!

2007-10-09 Thread [EMAIL PROTECTED]
On Oct 9, 2:58 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Mon, 08 Oct 2007 10:41:03 -0700, "[EMAIL PROTECTED]"
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
>
>
>
> > There are only 25 timezones: -12, -11, ... -1, 0 (GMT), +1, ... +11,
> > +12.
>
> Uhm... -12 and +12 would be the same, wouldn't they?

No, they are seperated by the International Date Line,
so although zones -12 & +12 have the same clock time, they
are different dates.

>
> There are only 24 divisions 15deg wide in longitude, 7.5deg to each
> size of zone center, and Greenwich is center of 0...

And zones -12 & +12 are each nominally 7.5deg wide,
so 23*15 + 2*7.5 gives you 25 zones spanning 360deg.

>
> However, consider that the former Soviet Union is reputed to have
> used only ONE timezone for the entire width of the country (sunrise at
> 6AM say in Moscow would be near sunset on the east coast)

When was this, in the days before air travel when it took
3 weeks to cross Siberia by train?

>
> So while there are only 24 hourly offsets, there can be many "zones"
> to reflect variations in daylight time changes or non-standard
> offsets...

The point I was trying to make is that although there may
be 400 zones, there aren't 400 offsets. And aren't these
offsets part of the timezone record?

> --
> WulfraedDennis Lee Bieber   KD6MOG
> [EMAIL PROTECTED] [EMAIL PROTECTED]
> HTTP://wlfraed.home.netcom.com/
> (Bestiaria Support Staff:   [EMAIL PROTECTED])
> HTTP://www.bestiaria.com/


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Memory leak/gc.get_objects()/Improved gc in version 2.5

2007-10-09 Thread arvind
On Oct 9, 7:54 am, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
> On 10/8/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
>
> > I'm running a python program that simulates a wireless network
> > protocol for a certain number of "frames" (measure of time).  I've
> > observed the following:
>
> > 1. The memory consumption of the program grows as the number of frames
> > I simulate increases.
>
> > To verify this, I've used two methods, which I invoke after every
> > frame simulated:
>
> > --  Parsing the /proc//status file as in:
> >http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286222
> > --  Using ps vg | grep python | awk '!/grep/ {print " ",$8}'  in an
> > os.system() call.
>
> > The memory usage vs. frame number graph shows some big "jumps" at
> > certain points, and, after a large number of frames, shows a steady
> > upward slope
>
> This would be expected if you're creating ever-larger amounts of
> objects - python uses memory pools and as the number of simultaneous
> objects increases, the size of the pool will need to increase. This
> isn't expected if the total number of objects you create is pretty
> much static, but the way you're trying to determine that is flawed
> (see below).
>
>
>
> > 2. I think I've verified that the objects I instantiate are actually
> > freed-- I'm therefore assuming that this "leak" is "caused" by
> > python's garbage collection mechanism. I count the number of objects I
> > generate that are being tracked by gc as follows:
>
> > gc.collect()
> > objCount = {}
> > objList = gc.get_objects()
> > for obj in objList:
> > if getattr(obj, "__class__", None):
> > name = obj.__class__.__name__
> > if objCount.has_key(name):
> > objCount[name] += 1
> > else:
> > objCount[name] = 1
>
> > for name in objCount:
> > print name, " :", objCount[name]
>
> >del objList
>
> > Running this snippet every hundred frames or so, shows that the number
> > of objects managed by gc is not growing.
>
> > I upgraded to Python 2.5. in an attempt to solve this problem. The
> > only change in my observations from version 2.4 is that the absolute
> > memory usage level seems to have dropped. However, I still see the
> > jumps in memory usage at the same points in time.
>
> > Can anybody explain why the memory usage shows significant jumps (~200
> > kB or ~500 kb) over time (i.e. "frames") even though there is no
> > apparent increase in the objects managed by gc? Note that I'm calling
> > gc.collect() regularly.
>
> You're misunderstanding the purpose of Pythons GC. Python is
> refcounted. The GC exists only to find and break reference cycles. If
> you don't have ref cycles, the GC doesn't do anything and you could
> just turn it off.
>
> gc.get_objects() is a snapshot of the currently existing objects, and
> won't give you any information about peak object count, which is the
> most direct correlation to total memory use.
>
> > Thanks for your attention,
>
> > Arvind
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list

Chris,

Thanks for your reply.

To answer the earlier question, I used CPython 2.4.3 and ActivePython
2.5.1 in my analysis above. No custom modules added. Interpreter
banners are at the end of this message.

In my program, I do keep instantiating new objects every "frame".
However, these objects are no longer needed after a few frames, and
the program no longer maintains a reference to old objects. Therefore,
I expect the reference-counting mechanism built into python (whatever
it is, if not gc) to free memory used by these objects and return it
to the "pool" from which they were allocated. Further, I would expect
that in time, entire pools would become free, and these free pools
should be reused for new objects. Therefore the total number of pools
allocated (and therefore "arenas"?) should not grow over time, if
pools are being correctly reclaimed. Is this not expected behavior?

Also, since I sample gc.get_objects() frequently, I would expect that
I would stumble upon a "peak" memory usage snapshot, or at the very
least see a good bit of variation in the output. However, this does
not occur.

Finally, if I deliberately hold on to references to old objects,
gc.get_objects() clearly shows an increasing number of objects being
tracked in each snapshot, and the memory leak is well explained.

Python version info:

ActivePython 2.5.1.1 (ActiveState Software Inc.) based on
Python 2.5.1 (r251:54863, May  2 2007, 08:46:07)
[GCC 3.3.4 (pre 3.3.5 20040809)] on linux2

AND

Python 2.4.3 (#1, Mar 14 2007, 19:01:42)
[GCC 4.1.1 20070105 (Red Hat 4.1.1-52)] on linux2


Arvind

-- 
http://mail.python.org/mailman/listinfo/python-list


mutable objects as dictionary keys

2007-10-09 Thread Andreas Kraemer
Hi everyone,

I know that the subject of mutable objects as dictionary keys has been 
discussed a number of times in this forum (see for instance "freezing" of 
classes), but I would love to hear the thoughts of the experts on the approach 
below. 

The use case that I encounter frequently is the classification of objects 
according to certain rules or properties: Say, I have objects A, B, C, ... 
(e.g. instances of a class, dict, etc), I can write

d = {}
d.setdefault(A,[]).append(A)
d.setdefault(B,[]).append(B)
...

so objects that map to the same hash key will end up in the same bucket. (A 
"real world" example I had to deal with recently was for instance the 
construction of a directed acyclic graph from many directed trees where 
identical subtrees needed to be identified.)

The easiest way is of course to define custom __hash__() and __eq__() methods, 
but this breaks if objects are mutated (accidentally) after having been 
inserted into the dictionary. The "best" working approach I came up with so far 
is to generate an "immutable view" V of a mutable object O according to my 
classification rule, delegate O.__hash__ and O.__eq__ to V, and make sure that 
the V is memoized and cannot (easily) be altered later, even when O is mutated:

def hashable_mutable_factory(mutable,rule):
  class _mutable(mutable):
def __init__(self,*args,**kw):
  self._view_cache = {}
  super(_mutable,self).__init__(*args,**kw)
def _view(self):
  id_ = id(self)
  if not self._view_cache.has_key(id_):
self._view_cache[id_] = rule(self)
  return self._view_cache[id_]
def __hash__(self):
  return hash(self._view())
def __eq__(self,other):
  return self._view() == other._view()
  return _mutable

E.g.:

>>> hashable_dict = hashable_mutable_factory(dict,lambda obj: 
>>> frozenset(obj.iteritems()))
>>> h = hashable_dict(a=1,b=2)
>>> d = {}
>>> d[h] = 'foo'
>>> d
{{'a': 1, 'b': 2}: 'foo'}
>>> h['c'] = 'bar'
>>> d
{{'a': 1, 'c': 'bar', 'b': 2}: 'foo'}
>>> g = hashable_dict(a=1,b=2)
>>> h

{'a': 1, 'c': 'bar', 'b': 2}

>>> g

{'a': 1, 'b': 2}
>>> id(g) == id(h)
False
>>> g == h
True

I slightly favor the factory function idiom above over defining the rule in a 
super class (this would have to be done for each mutable type and rule function 
separately), especially since I read that future versions of python (2.6 ?, 3.0 
?) will contain class decorators and allow syntax like class A(*bases): pass

Is there a better approach? Any comments are appreciated. 

I have been seriously using Python for one year know, mostly in the context of 
graph algorithms etc., and it has always been a delightful coding experience!

Best regards,

Andreas




-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Static variable vs Class variable

2007-10-09 Thread Steven D'Aprano
On Tue, 09 Oct 2007 19:23:37 +0200, Diez B. Roggisch wrote:

> Your believes aside, this is simply wrong. The statement
> 
> a += x
> 
> always leads to a rebinding of a to the result of the operation +.

Not true.

>>> L = []
>>> id(L)
3083496716L
>>> L += [1]
>>> id(L)
3083496716L

It's the same L, not rebound at all.



> I presume you got confused by the somewhat arbitrary difference between
> 
> __add__
> 
> and
> 
> __iadd__
> 
> that somehow suggest there is an in-place-modification going on in case
> of mutables.

The __iFOO__ methods are supposed to do in-place modification if 
possible, but it is up to the class writer to make them do so. In the 
case of your example, you specifically created an __iadd__ method that 
didn't even attempt in-place modification. What did you expect it to do?


> but as the following snippet shows - that's not the case:
> 
> 
> class Foo(object):
>  def __add__(self, o):
>  return "__add__"
> 
>  def __iadd__(self, o):
>  return "__iadd__"
> 
> 
> a = Foo()
> a += 1
> print a
> 
> a = Foo()
> b = Foo()
> c = a + b
> print c
> 
> So you see, the first += overrides a with the returned value of
> __iadd__.

That's because you told it to do that. If you told it to do something 
more sensible, it would have done so. Lists know how to do in-place 
modification:

>>> id(L)  # from above
3083496716L
>>> L *= 5
>>> id(L)
3083496716L
>>> L = L*5
>>> id(L)
3083496972L


-- 
Steven.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: generator_tools-0.1 released

2007-10-09 Thread Kay Schluehr
On Oct 9, 7:17 pm, Steven Bethard <[EMAIL PROTECTED]> wrote:
> Kay Schluehr wrote:
> > Originally I came up with the idea of a pure Python implementation for
> > copyable generators as an ActiveState Python Cookbook recipe. Too bad,
> > it was badly broken as Klaus Müller from the SimPy project pointed
> > out. Two weeks and lots of tests later I got finally a running version
> > that works not only in the very most simple use cases. As the code
> > size increased it turned out to not really fit anymore into the
> > "recipe" category and I created a package called "generator_tools".
>
> > generator_tools-0.1 is available for both Python 2.5 and Python 3.0
> > (!)
> [snip]
>  pickler = GeneratorPickler("test.pkl")
>  pickler.pickle_generator(g_gen)
>  k_gen = pickler.unpickle_generator()
>  list(g_gen) == list(k_gen)
> > True
>
> This seems like an odd syntax for pickling. Does the package support the
> normal pickle machinery?  That is, does it register the appropriate
> methods with the copy_reg module?
>
> STeVe

The picklegenerators module defines two functions: pickle_generator
that wraps the generator into a GeneratorSnapshot object and
unpickle_generator that calls copy_generator on the unpickled
GeneratorSnapshot. The only reason I also created the GeneratorPickler
class was some simplification of testing. So I didn't invest time yet
keeping the API in line with Pythons normal pickle machinery but will
do so as the project advances i.e. in the next release.

Kay

-- 
http://mail.python.org/mailman/listinfo/python-list


SOAPpy and ArrayOfKeyValue

2007-10-09 Thread Alex Ezell
Can anyone offer any assistance as to how to convert a basic python
dictionary, list, or even tuple into the SOAP type "ArrayOfKeyValue"?

I am currently using SOAPpy, but would be willing to change to ZSI or
something else if it made this conversion easier.

I have tried with the arrayType and structType methods in
SOAPpy.Types, yet they don't seem to do what I need. I suspect there
might not be just a single method call, so, I wrote something like
this:

def dictToKeyValue(self, mydict):
soap_list = []
for key,value in mydict.items():
inner = []
inner.append(SOAPpy.stringType(key,'key'))
inner.append(SOAPpy.stringType(value,'value'))
soap_list.append(SOAPpy.arrayType(inner))
print soap_list
return SOAPpy.arrayType(soap_list)

As you can see, it's pretty nasty and doesn't do what I need either. I
have a client that was written in PHP which I am converting. It uses
this function (which calls the PEAR SOAP library):

function assocArrayToKeyValue($array) {
$soap_array = array();
foreach($array as $key=>$value) {
$inner = array();
$inner[] =& new SOAP_Value('key', 'string', $key);
$inner[] =& new SOAP_Value('value', 'string', $value);
$soap_array[] =& new SOAP_Value("item",
"{{$this->wsdl_urn}}KeyValue", $inner);
}
return $soap_array;
}

Unfortunately, I don't really have a way to see exactly what
$soap_array is so that I could emulate it in my Python code.

Any pointers or suggestions are very much appreciated.

/alex
-- 
http://mail.python.org/mailman/listinfo/python-list


storing meta data on dictionary keys

2007-10-09 Thread Andreas Kraemer
I sometimes find it useful to store meta data on dictionary keys, like in the 
following example:

class Dict(dict):
  def __init__(self,*args,**kw):
self.key_dict = {}
super(Dict,self).__init__(*args,**kw)
  def __setitem__(self,k,v):
self.key_dict[k] = k
super(Dict,self).__setitem__(k,v)
  def get_key(self,key):
return self.key_dict[key]

class Str(str): pass

>>> friends = Dict()
>>> friends[Str('John')] = ['Bill','Jack','Isabelle']
>>> friends[Str('Jim')] = ['John','Bob']
>>> friends[Str('Isabelle')] = ['John','Christine','Anabelle']
>>> friends.get_key('John').hair_color = 'brown'
>>> friends.get_key('Jim').hair_color = 'red'
>>> friends.get_key('Isabelle').hair_color = 'green'
>>> friends
{'Jim': ['John', 'Bob'], 'John': ['Bill', 'Jack', 'Isabelle'], 'Isabelle': 
['John', 'Christine', 'Anabelle']}
>>> friends.get_key('Isabelle').hair_color
'green'

A more sensible, realistic example are attributes of graph nodes (e.g. color, 
shape, etc)  in the networkx package, where node objects are stored as keys of 
(nested) dictionaries.

Is there any particular reason why the built-in dictionary does not define a 
get_key() method, but only keys(), iterkeys(), and has_key() ?

Cheers,

Andreas

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: The fundamental concept of continuations

2007-10-09 Thread George Neuner
On Tue, 09 Oct 2007 05:15:49 -, [EMAIL PROTECTED] wrote:

>Again I am depressed to encounter a fundamentally new concept that I
>was all along unheard of. Its not even in paul graham's book where i
>learnt part of Lisp. Its in Marc Feeley's video.
>
>Can anyone explain:
>
>(1) its origin

Lambda calculus.  Continuation is just a formal term for "what the
code does next".  It manifests, literally, as the next instruction(s)
to be executed.


>(2) its syntax and semantics in emacs lisp, common lisp, scheme

Lisp does not have explicit continuations so there is no syntax for
them.  Continuations in Lisp mainly take the form of function calls,
function returns, exceptions, conditions, etc.  Sometimes code is
written in "continuation passing style" (CPS) in which each function
has one or more additional function parameters (the continuations) -
the function terminates by passing its result as an argument to one of
those continuation functions.

Scheme has explicit continuations based on closures.  Closure
continuations are created using CALL-WITH-CURRENT-CONTINUATION
(usually abbreviated as CALL/CC).  Some Schemes also recognize a
LET/CC form used mainly for escape continuations (exceptions).
Scheme's closure continuations can be stored in data structures and
used for complex control forms such as multitasking.  Like Lisp,
Scheme code also is sometimes written using CPS.


>(3) Is it present in python and java ?

It is present in all languages.  It generally takes the form of
procedure or function calls, returns, exceptions, etc.


>(4) Its implementation in assembly. for example in the manner that
>pointer fundamentally arises from indirect addressing and nothing new.
>So how do you juggle PC to do it.

As I stated above, every function call or return _is_ a continuation
... their implementation is obvious.

For the closure form used in Scheme, the implementation is to create a
closure, a data structure containing the function address and some
method of accessing the function's free variables, and to call the
function.  How you do this depends greatly on the instruction set.


>(5) how does it compare to and superior to a function or subroutine
>call. how does it differ.

Calling closure continuations is a little more complicated and a bit
slower than calling a normal function.  Creating the closure in the
first place may be simple or complicated depending on the complexity
of the source code and the processor's instruction set.


>Thanks a lot.
>
>(6) any good readable references that explain it lucidly ?

Get yourself a good textbook on compilers.  Most of the techniques are
applicable to all languages - even for seemingly very different
languages, the differences in their compilers are simply in how the
basic compilation techniques are combined.


My favorite intermediate-level books are 

Aho, Sethi & Ullman. "Compilers: Principles, Techniques and Tools".
2nd Ed. 2006. ISBN 0-321-48681-1.
The first edition from 1986, ISBN 0-201-10088-6, is also worth having
if you can still find it.  The 1st edition is mainly about procedural
languages, the 2nd gives more time to functional languages and modern
runtime issues like GC and virtual machines.

Cooper & Torczon, "Engineering a Compiler", 2004.  
ISBN 1-55860-698-X (hardcover), 1-55860-699-8 (paperback).
Also available as a restricted 90-day ebook from
http://rapidshare.com/files/24382311/155860698X.Morgan_20Kaufmann.Engineering_20a_20Compiler.pdf


There are also some decent intro books available online.  They don't
go into excruciating detail but they do cover the basics of code
shaping which is what you are interested in.

Torben Mogensen. "Basics of Compiler Design"
http://www.diku.dk/~torbenm/Basics/

"Engineering a Compiler".  I don't have this author's name, nor can
Google find it at the moment.  I have a copy though (~2MB) - if you
are interested, contact me by email and I'll send it to you.


Also Google for free CS books.  Many older books (including some
classics) that have gone out of print have been released
electronically for free download.

George
--
for email reply remove "/" from address
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pytz has so many timezones!

2007-10-09 Thread [EMAIL PROTECTED]
On Oct 9, 8:34 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > On Oct 8, 1:03 pm, Carsten Haese <[EMAIL PROTECTED]> wrote:
> >> On Mon, 2007-10-08 at 10:41 -0700, [EMAIL PROTECTED] wrote:
> >> > For example, Windows has seperate listings for
>
> >> > Central America
> >> > Central Time (US & Canada)
> >> > Guadalahara, Mexico City, Monterry - New
> >> > Guadalahara, Mexico City, Monterry - Old
> >> > Saskatchewan
>
> >> > but they are all GMT-6
>
> >> But they could have different rules for Daylight Saving Time.
>
> > Which only matters if you're setting your clock.
>
> That's BS. If I'm supposed to be attending a video-conference that spans a
> few continents which is scheduled using a web-app, it's VITAL that I get
> the invitation and reminder rendered in MY local timezone, DST included.
>
> And for the matter of
>
> """
> There are only 25 timezones: -12, -11, ... -1, 0 (GMT), +1, ... +11,
> +12.
> """
>
> who says that timezones have to be separated by one hour each?

The Earth says. It takes 24 hours to revolve.

> Why aren't they separated by 30minutes, or 20, or 10? Or 2 hours?

Why isn't an hour defined to be 30 minutes?

> Or why don't we have a global time?

Like UTC?

>
> Your 25 timezones are an abstraction the same way

Not the same way at all. The 25 timezones I speak of are
not merely an abstraction, but related to longitude.

> as are the 400 apparently in use by people all over the world

Where the correlation to longitude is much looser.
Granted, it doesn't need to be for non-navigational
purposes. And although governments can legislate things
like DST, they can't legislate longitude.

> - and last time I checked, there was no
> fundamental law in physics or such that limited the allowed or sensible
> number of timezones...

Isn't there some law somewhere that says the circumference
of a sphere is 360deg? Doesn't that same law mean that no two
points on a sphere can be seperated by more than 180deg
longitude? Doesn't that make GMT+13 non-sensible?

>
> Diez

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NUCULAR fielded text searchable indexing

2007-10-09 Thread Grant Edwards
On 2007-10-09, Robin Becker <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
>> On Oct 9, 8:46 am, Istvan Albert <[EMAIL PROTECTED]> wrote:
>>> ps. there is a python project named "The Devil Framework", I cringe
>>> every time I hear about it.Nucularis not as bad, but it is close.
>> 
>> Aw shucks.  I thought it was funny.  Can't I make fun of
>> politicians in my open source projects?  Besides there is
>> a great tradition of tounge-in-cheek package names, like
>> "Cold fusion", for example.
>>...
>
> I think it's an excellent name :)

And Bush would probably pronounce it "Nuke-lee-ur".

-- 
Grant Edwards   grante Yow! I like your SNOOPY
  at   POSTER!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pytz has so many timezones!

2007-10-09 Thread J. Clifford Dyer
On Tue, Oct 09, 2007 at 11:21:41AM -0700, [EMAIL PROTECTED] wrote regarding Re: 
pytz has so many timezones!:
> 
> The Earth says. It takes 24 hours to revolve.
> 
> > Why aren't they separated by 30minutes, or 20, or 10? Or 2 hours?
> 
> Why isn't an hour defined to be 30 minutes?
> 
> > Or why don't we have a global time?
> 
> Like UTC?
> 
> >
> > Your 25 timezones are an abstraction the same way
> 
> Not the same way at all. The 25 timezones I speak of are
> not merely an abstraction, but related to longitude.
> 
> > as are the 400 apparently in use by people all over the world
> 
> Where the correlation to longitude is much looser.
> Granted, it doesn't need to be for non-navigational
> purposes. And although governments can legislate things
> like DST, they can't legislate longitude.
> 
> > - and last time I checked, there was no
> > fundamental law in physics or such that limited the allowed or sensible
> > number of timezones...
> 
> Isn't there some law somewhere that says the circumference
> of a sphere is 360deg? Doesn't that same law mean that no two
> points on a sphere can be seperated by more than 180deg
> longitude? Doesn't that make GMT+13 non-sensible?
> 

You seem to be talking about time zones as if they are a scientific abstraction 
based on the physical layout of the earth.  They are not.  They are an 
abstraction away from true scientific (solar) time to give us regular 24 hour 
days, and to simplify calculation to make sure that trains don't run into one 
another for having left their respective stations at times based on locally 
defined solar noon.  Solar time is the only kind of time that doesn't have to 
take political considerations into account.  

GMT+13 is not non-sensible at all, if the major trade partners of the island in 
question are at GMT+12.  Imagine the confusion not being able to schedule 
meetings on monday or friday because your next door neighbor, one time zone 
away, is actually off-calendar from you by one day.  The IDL was arbitrarily 
placed in the middle of the pacific to limit this problem to as few people as 
possible, but the people of Kiribati have no reason to accept the disadvantage 
under which this (European) abstraction places them.  What would be 
non-sensible is for them to live 23 hours offset from their closest neighbors 
and family, while living a mere three hours offset from people that they have 
minimal contact with.  

Cheers,
Cliff
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pytz has so many timezones!

2007-10-09 Thread Chris Mellon
On 10/9/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > Why aren't they separated by 30minutes, or 20, or 10? Or 2 hours?
>
> Why isn't an hour defined to be 30 minutes?
>
> > Or why don't we have a global time?
>
> Like UTC?
>
> >
> > Your 25 timezones are an abstraction the same way
>
> Not the same way at all. The 25 timezones I speak of are
> not merely an abstraction, but related to longitude.
>

See, here's what the problem is. You've invented your own definition
of "timezone", which has no relation to how anyone else uses the word,
and are now arguing loudly and rudely about how your pet definition is
right, and everyone else is wrong.

You should have just said at the beginning that you were just
redefining all the terms to match your preference, so I could have
killfilled you then instead of reading all your posts in hope that you
actually had something important and useful to say.
-- 
http://mail.python.org/mailman/listinfo/python-list


Fwd: NUCULAR fielded text searchable indexing

2007-10-09 Thread Bill Hamilton
On 10/9/07, Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2007-10-09, Robin Becker <[EMAIL PROTECTED]> wrote:
> > [EMAIL PROTECTED] wrote:
> >> On Oct 9, 8:46 am, Istvan Albert <[EMAIL PROTECTED]> wrote:
> >>> ps. there is a python project named "The Devil Framework", I cringe
> >>> every time I hear about it.Nucularis not as bad, but it is close.
> >>
> >> Aw shucks.  I thought it was funny.  Can't I make fun of
> >> politicians in my open source projects?  Besides there is
> >> a great tradition of tounge-in-cheek package names, like
> >> "Cold fusion", for example.
> >>...
> >
> > I think it's an excellent name :)
>
> And Bush would probably pronounce it "Nuke-lee-ur".

I dislike Bush as much as the next guy, but could we please keep
politics off the group?


--
-Bill Hamilton
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pytz has so many timezones!

2007-10-09 Thread Bill Hamilton
On 10/9/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> On Oct 9, 8:34 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> > [EMAIL PROTECTED] wrote:
> > > On Oct 8, 1:03 pm, Carsten Haese <[EMAIL PROTECTED]> wrote:
> > >> On Mon, 2007-10-08 at 10:41 -0700, [EMAIL PROTECTED] wrote:
> > >> > For example, Windows has seperate listings for
> >
> > >> > Central America
> > >> > Central Time (US & Canada)
> > >> > Guadalahara, Mexico City, Monterry - New
> > >> > Guadalahara, Mexico City, Monterry - Old
> > >> > Saskatchewan
> >
> > >> > but they are all GMT-6
> >
> > >> But they could have different rules for Daylight Saving Time.
> >
> > > Which only matters if you're setting your clock.
> >
> > That's BS. If I'm supposed to be attending a video-conference that spans a
> > few continents which is scheduled using a web-app, it's VITAL that I get
> > the invitation and reminder rendered in MY local timezone, DST included.
> >
> > And for the matter of
> >
> > """
> > There are only 25 timezones: -12, -11, ... -1, 0 (GMT), +1, ... +11,
> > +12.
> > """
> >
> > who says that timezones have to be separated by one hour each?
>
> The Earth says. It takes 24 hours to revolve.
It only takes 24 hours for the Earth to revolve once because we
defined an hour as 1/24 of the time it takes for the Earth to revolve
once.  We could have said an hour was 1/10 that time, or 1/2, or
1/27.284.

>
> > Or why don't we have a global time?
>
> Like UTC?

What about GMT?  I hear that much more than UTC.

>
> >
> > Your 25 timezones are an abstraction the same way
>
> Not the same way at all. The 25 timezones I speak of are
> not merely an abstraction, but related to longitude.
>
> > as are the 400 apparently in use by people all over the world
>
> Where the correlation to longitude is much looser.
> Granted, it doesn't need to be for non-navigational
> purposes. And although governments can legislate things
> like DST, they can't legislate longitude.
>

But your 25 timezones are only useful to the people that use those 25
timezones.  And the time zone I use is not one of those 25 timezones.

> > - and last time I checked, there was no
> > fundamental law in physics or such that limited the allowed or sensible
> > number of timezones...
>
> Isn't there some law somewhere that says the circumference
> of a sphere is 360deg? Doesn't that same law mean that no two
> points on a sphere can be seperated by more than 180deg
> longitude? Doesn't that make GMT+13 non-sensible?

A timezone is an arbitrary geographical designation.  It has nothing
to do with latitude or longitude.  While some time zones may be
defined as a geographical region between two longitudes, others may be
defined by geographical borders or convienent terrain features.  Take
a look at the international date line.  It doesn't follow a
longitudinal line, but instead jogs east around Asia and then west
around the Aleutian Islands.


--
-Bill Hamilton
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The fundamental concept of continuations

2007-10-09 Thread gnuist006
On Oct 8, 11:09 pm, "." <[EMAIL PROTECTED]> wrote:
> On Tue, 09 Oct 2007 05:15:49 +, gnuist006 wrote:

>
> > Can anyone explain:
>
> > (1) its origin
>
> One of the lambda papers, I think.  I don't remember which.

Hey no-name "dot" you are the only one who says its origin is in
one of the old lambda papers. Give me a reference or someone
give me a reference. I dont have access to any ACM journals or
other conferences. So

step 1
reference and the idea in it

step 2
if you can upload it

This is for historical and conceptual development at the same
time as learning the ideas to use them.

Thanks a lot.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The fundamental concept of continuations

2007-10-09 Thread gnuist006
Special thanks to many of you for your very decent replies.

On Oct 9, 11:18 am, George Neuner  wrote:
> On Tue, 09 Oct 2007 05:15:49 -, [EMAIL PROTECTED] wrote:
> >Again I am depressed to encounter a fundamentally new concept that I
> >was all along unheard of. Its not even in paul graham's book where i
> >learnt part of Lisp. Its in Marc Feeley's video.
>
> >Can anyone explain:
>
> >(1) its origin
>
> Lambda calculus.  Continuation is just a formal term for "what the
> code does next".  It manifests, literally, as the next instruction(s)
> to be executed.
>
> >(2) its syntax and semantics in emacs lisp, common lisp, scheme
>
> Lisp does not have explicit continuations so there is no syntax for
> them.  Continuations in Lisp mainly take the form of function calls,
> function returns, exceptions, conditions, etc.  Sometimes code is
> written in "continuation passing style" (CPS) in which each function
> has one or more additional function parameters (the continuations) -
> the function terminates by passing its result as an argument to one of
> those continuation functions.
>
> Scheme has explicit continuations based on closures.  Closure
> continuations are created using CALL-WITH-CURRENT-CONTINUATION
> (usually abbreviated as CALL/CC).  Some Schemes also recognize a
> LET/CC form used mainly for escape continuations (exceptions).
> Scheme's closure continuations can be stored in data structures and
> used for complex control forms such as multitasking.  Like Lisp,
> Scheme code also is sometimes written using CPS.
>
> >(3) Is it present in python and java ?
>
> It is present in all languages.  It generally takes the form of
> procedure or function calls, returns, exceptions, etc.
>
> >(4) Its implementation in assembly. for example in the manner that
> >pointer fundamentally arises from indirect addressing and nothing new.
> >So how do you juggle PC to do it.
>
> As I stated above, every function call or return _is_ a continuation
> ... their implementation is obvious.
>
> For the closure form used in Scheme, the implementation is to create a
> closure, a data structure containing the function address and some
> method of accessing the function's free variables, and to call the
> function.  How you do this depends greatly on the instruction set.
>
> >(5) how does it compare to and superior to a function or subroutine
> >call. how does it differ.
>
> Calling closure continuations is a little more complicated and a bit
> slower than calling a normal function.  Creating the closure in the
> first place may be simple or complicated depending on the complexity
> of the source code and the processor's instruction set.
>
> >Thanks a lot.
>
> >(6) any good readable references that explain it lucidly ?
>
> Get yourself a good textbook on compilers.  Most of the techniques are
> applicable to all languages - even for seemingly very different
> languages, the differences in their compilers are simply in how the
> basic compilation techniques are combined.
>
> My favorite intermediate-level books are
>
> Aho, Sethi & Ullman. "Compilers: Principles, Techniques and Tools".
> 2nd Ed. 2006. ISBN 0-321-48681-1.
> The first edition from 1986, ISBN 0-201-10088-6, is also worth having
> if you can still find it.  The 1st edition is mainly about procedural
> languages, the 2nd gives more time to functional languages and modern
> runtime issues like GC and virtual machines.
>
> Cooper & Torczon, "Engineering a Compiler", 2004.
> ISBN 1-55860-698-X (hardcover), 1-55860-699-8 (paperback).
> Also available as a restricted 90-day ebook 
> fromhttp://rapidshare.com/files/24382311/155860698X.Morgan_20Kaufmann.Eng...
>
> There are also some decent intro books available online.  They don't
> go into excruciating detail but they do cover the basics of code
> shaping which is what you are interested in.
>
> Torben Mogensen. "Basics of Compiler 
> Design"http://www.diku.dk/~torbenm/Basics/
>
> "Engineering a Compiler".  I don't have this author's name, nor can
> Google find it at the moment.  I have a copy though (~2MB) - if you
> are interested, contact me by email and I'll send it to you.
>
> Also Google for free CS books.  Many older books (including some
> classics) that have gone out of print have been released
> electronically for free download.
>
> George
> --
> for email reply remove "/" from address


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The fundamental concept of continuations

2007-10-09 Thread Jeff M.

> (6) any good readable references that explain it lucidly ?

This was something that has been very interesting to me for a while
now, and I'm actually still having a difficult time wrapping my head
around it completely.

The best written explanation that I've come across was in "The Scheme
Programming Language" (http://mitpress.mit.edu/catalog/item/
default.asp?ttype=2&tid=9946). But perhaps others have better
references.

I'll attempt my own little explanation of call/cc. I'll butcher some
of it, I'm sure, but hopefully those more knowledgeable will politely
correct me. I will start with a loose analogy and point out a couple
examples I came across that did make a lot of sense.

First, the bad analogy I have (if you are coming from C programming
like me) is setjmp and longjmp. This is a bad analogy in that you're
talking about hardware and stack states as opposed to functions, but a
good analogy in that it saves the current state of execution, and
returns to that same state at a later time with a piece of data
attached to it.

My first example of using this would be to create a return function in
Scheme. I hope I don't get this wrong, but the example would be
something like this:

(define (my-test x)
  (call/cc (lambda (return)
 (return x

Now, here's my understanding of what is happening under-the-hood:

1. call/cc stores the current execution state and creates a function
to restore to that state.

2. call/cc then calls its own argument with the function it created.

The key here is that "return" is a function (created by call/cc)
taking 1 argument, and it restores execution at the same state it was
when the call/cc began (or immediately after it?). This line:

(return x)

is really just calling the function created by call/cc, which will
restore the execution state to what it was just prior to the call/cc,
along with a parameter (in this case, the value of x).

My next example I don't follow 100%, and I won't attempt to reproduce
it here, but it generates a continuation that modifies itself (bad?)
to define a list iterator.

http://blog.plt-scheme.org/2007/07/callcc-and-self-modifying-code.html

I recommend putting that code into a Scheme interpreter and running
it. You'll get it.

Hope this helps, and I look forward to better explanations than mine
that will help me along as well. :)

Jeff M.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static variable vs Class variable

2007-10-09 Thread Laszlo Nagy
Steven D'Aprano wrote:
> On Tue, 09 Oct 2007 19:23:37 +0200, Diez B. Roggisch wrote:
>
>   
>> Your believes aside, this is simply wrong. The statement
>>
>> a += x
>>
>> always leads to a rebinding of a to the result of the operation +.
>> 
>
> Not true.
>   
Hmm. Or you can write __iadd__ to rebind the name to the same object 
again? I think usually there is not much difference between "rebinding 
to the same object" and "not rebinding". But as we have seen, sometimes 
there is a difference. I think that Diez made his statement because it 
is possible to rebind from __iadd__ to a different object. So it is more 
safe to think that "inplace operations" will always rebind, than to 
think they will never rebind.

I'm not sure about the language level. It is told that "+=" is an 
inplace operator, but how "in place" is defined? If we say "an inplace 
operator will change the state of an object, and will never create a new 
object" then "+=" is NOT an inplace operator. Well, at least not when 
you watch it from the language level. But what about the implementation 
level? Here is an example:

a = 1
a+= 1 # The compiler will probably optimize this and the Python bytecode 
interpreter will not rebind 'a' here, just increment the integer in memory.

This topic starts to be very interesting. Language lawyers and 
developers, please help us! How "in place operator" is defined in 
Python? What makes it an "in place operator"? Is it the syntax, or what?

Laszlo

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NUCULAR fielded text searchable indexing

2007-10-09 Thread Istvan Albert
On Oct 9, 9:14 am, [EMAIL PROTECTED] wrote:

> a great tradition of tounge-in-cheek package names, like
> "Cold fusion", for example.

Cold Fusion is a super cool name. Nobody will every think of it as
representing something odd or silly.

> too late now.  sorry again,

why would it be late? is the future of you own work not worth the time
it takes to rename it? Compared to all the other work it took ... it
is just a mere inconvenience.

All I can say please do yourself a favor rename it. Imagine yourself
in the position of someone who has no idea what the project is about
and try to imagine what kind of thoughts and feelings the name will
conjure. It matters a lot. It is a shame to put yourself at
disadvantage.

Anyway that's all I can say. FWIW the "Devil Framework" guys are
sticking to their name, I think this is something that feels too
personal, people who invent a name will have a hard time accepting
that it is bad.

i.


-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >