Re: I'm a python addict !

2009-01-28 Thread afriere
On Jan 27, 4:52 am, Paul McGuire  wrote:
[snip]
>
>     # how you have to do it in C++ and Java
>     # light = light.next_state()
>
>     # using Python
>     light.__class__ = light.next_state

I'm sure you can, but why poke yourself in the eye with a blunt
stick? ;)

IMO there are two obvious problems with the latter approach.  Firstly
the information about the next state is left lying about in some
namespace separate from the object, whereas the object itself ought to
know what it's 'next_state' is (or, more correctly, how to determine
it).

Secondly you miss the opportunity of sending a signal to the new
state.  Consider that in some jurisdictions the amber light shows
before the green as well as before the red (yeah, I know is that an
invitation for drag racing or what!?).  If you called next_state as a
verb you could pass the current state as an argument and the amber (or
yellow, if you prefer) light could work which of the two possible next
states to call in turn.  The fact that this behaviour is, in this
example, peculiar to the amber light, demonstrates the pertinence of
my first objection above.

Fortunately the "C++ and Java" approach, (though I would never want to
be seen advocating the C++ or Java approach to anything), is in this
case available in Python as well, at the cheaper price of fewer
characters and arguably greater readibility to boot.

I know, Iknow ... you wanted to show how that code could be used in a
non "sulphurous" way.  Which just goes to show that the devil makes
work for idle hands ... or foils the best laid plans ... or is in the
detail ... or something sulphurous. :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Results of executing hyperlink in script

2009-01-28 Thread Tino Wildenhain

Tim Chase wrote:

1. This method was suggested by Cameron Laird:

  os.system("start %s" % URL)

It works. But, if the URL contains character &, it will fail. For



As an aside, the START command is a bit picky regarding quotes. You have 
to use this horrible contortion


  os.system('start "title" "%s"' % URL)

The "title" is optional content-wise, but required positionally if 
there's a quoted resource, so you can just use


  start "" "%s"

a pain, but that's CMD.EXE for you. :)


ah, and just for the records, at least
os.popen2,os.popen3 support tuple as argument:

i,o=os.popen2((cmd,arg1,arg2)) and quotes them
correctly.

Regards
Tino


smime.p7s
Description: S/MIME Cryptographic Signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: Profiling Python Apps on Mac?

2009-01-28 Thread Robert Kern

On 2009-01-28 13:14, RGK wrote:

I'm writing a python app on a Mac (in Eclipse + PyDev w/ Python2.5 &
wxPython under OSX 10.4)

As I make program architecture decisions, it would be nice to be able to
profile the choices. Should I add that extra thread? Is this big-assed
xml object I just created horribly bloated or kind of ordinary.

Is there anything out there I should look into to if I want to see how
those things are affecting my app? The closest I have is the widget
iStat, but it's a very static low resolution view of what's really going
on.


I have a script kernprof.py which provides a few conveniences over the builtin 
cProfile module. One of its modes of operation is to inject a decorator into the 
__builtins__. It will enable the profiler on entry to the method and disable it 
on exit. This lets you localize your profile results to just the part of your 
code that you are interested in. I found this especially useful in GUI apps 
which require user interaction to trigger the part of the code you are actually 
interesting in profiling. You don't want the interesting parts of your profile 
to be obscured by the GUI event loop waiting for your input.


You can get it as part of my line_profiler package (which you may also be 
interested in; cProfile profiles function calls, line_profiler profiles 
individual lines).


  http://pypi.python.org/pypi/line_profiler

You can view the profile results interactively with "python -m pstats 
my_script.py.prof", RunSnakeRun, or pyprof2calltree if you manage to install 
kcachegrind on your system:


  http://www.vrplumber.com/programming/runsnakerun/
  http://pypi.python.org/pypi/pyprof2calltree/1.1.0

I don't recommend using hotshot because it is deprecated and slow to postprocess 
the data dumps. Also, I don't recommend using the plain profile module because 
it slows down your program rather more than cProfile. See the Python 
documentation for an overview of these modules:


  http://docs.python.org/library/profile

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: Recommendation for a small web framework like Perl's CGI::Application to run as CGI?

2009-01-28 Thread Jeroen Ruigrok van der Werven
-On [20090128 20:36], excord80 (excor...@gmail.com) wrote:
>If that's correct, it would be great if there were a Werkzeug tutorial
>on deploying it for use with CGI.

There are some real life frontends for CGI, FCGI and WSGI in Zine[1]. Look
in the servers directory in the repository.

I'll double check the documentation and expand where necessary.

[1] http://zine.pocoo.org/

-- 
Jeroen Ruigrok van der Werven  / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B
Earth to earth, ashes to ashes, dust to dust...
--
http://mail.python.org/mailman/listinfo/python-list


Re: dicts,instances,containers, slotted instances, et cetera.

2009-01-28 Thread Michele Simionato
On Jan 29, 12:23 am, ocsch...@gmail.com wrote:

> I just find it odd that there's no quick answer on the
> fastest way in Python to implement a mapping in this context.

A Python dict is as fast as you can get. If that is not enough, your
only choice is to try something at the C level, which may give the
desired speedup or not. Good luck!

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


Re: self-aware list of objects able to sense constituent member alterations?

2009-01-28 Thread Peter Wang
On Jan 27, 3:16 pm, Reckoner  wrote:
> I'm not sure this is possible, but I would like to have
> a list of  objects
>
> A=[a,b,c,d,...,z]
>
> where,  in the midst of a lot of processing I might do something like,
>
> A[0].do_something_which_changes_the_properties()
>
> which alter the properties of the object 'a'.
>
> The trick is that I would like A to be mysteriously aware that
> something about the  object 'a' has changed so that when I revisit A,
> I will know that the other items in the list need to be refreshed to
> reflect the changes in A as a result of changing 'a'.
>
> Even better would be to automatically percolate the subsequent changes
> that resulted from altering 'a' for the rest of the items in the list.
> Naturally, all of these items are related in some parent-child
> fashion.
>
> that might be a lot to ask, however.
>
> Any advice appreciated.

You should really look at Enthought's Traits package.  It does exactly
what you are asking for, and much, much more.  See:

http://code.enthought.com/projects/traits/documentation.php
http://code.enthought.com/projects/traits/examples.php

Using Traits, you could do the following:

from enthought.traits.api import *
class Child(HasTraits):
state = Enum("happy", "sad", "bawling")

class Parent(HasTraits):
child = Instance(Child)

@on_trait_change('child.state')
def handler(self):
print "new child state:", self.child.state

bob_jr = Child()
bob = Parent(child = bob_jr)

bob_jr.state = "sad"
# This would result in bob.handler() being called

(Disclosure: I work at Enthought and have been using Traits heavily
for the last 4+ years.)

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


Re: Profiling Python Apps on Mac?

2009-01-28 Thread David Cournapeau
On Thu, Jan 29, 2009 at 4:14 AM, RGK  wrote:
> I'm writing a python app on a Mac (in Eclipse + PyDev w/ Python2.5 &
> wxPython under OSX 10.4)
>
> As I make program architecture decisions, it would be nice to be able to
> profile the choices.  Should I add that extra thread?  Is this big-assed xml
> object I just created horribly bloated or kind of ordinary.
>
> Is there anything out there I should look into to if I want to see how those
> things are affecting my app?   The closest I have is the widget iStat, but
> it's a very static low resolution view of what's really going on.

On Mac OS X, dtrace can sometimes be quite useful. The Apple-provided
python has the necessary 'probes'.

http://blogs.sun.com/binujp/entry/dtrace_provider_for_python

There are some useful scripts in the dtrace toolkit geared toward python:

http://www.brendangregg.com/dtrace.html#DTraceToolkit

If you want dtrace support for a bare python (built from sources), I
made a quick patch, "documented" here:

http://cournape.wordpress.com/?s=dtrace

I don't know if it works for 2.6 (I doubt it would work out of the box
- I don't claim any understanding of dtrace internals, I just applied
the apple patches, removing all the apple specifics I did not care
about).

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


Re: Profiling Python Apps on Mac?

2009-01-28 Thread Pierre-Alain Dorange
RGK  wrote:

> As I make program architecture decisions, it would be nice to be able to
> profile the choices.  Should I add that extra thread?  Is this big-assed
> xml object I just created horribly bloated or kind of ordinary.

python -m profile yourscript.py

see 

-- 
Pierre-Alain Dorange

MicroWar 2.0 : tuez des PC

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


Re: self-aware list of objects able to sense constituent member alterations?

2009-01-28 Thread Steven D'Aprano
On Wed, 28 Jan 2009 11:06:21 -0800, Reckoner wrote:

> thanks for your reply.
> 
> For the second case where
> 
>> class TaintThing(object):
>> parent = A
>> def __init__(self, obj):
>> self.__dict__['_proxy'] = obj
>> def __getattr__(self, attr):
>> return getattr(self._proxy, attr)
>> def __setattr__(self, attr, value):
>> setattr(self._proxy, attr, value)
>> self.parent.taint()
> 
> you have told it that parent is 'A'. Shouldn't that be passed to it
> somehow in the following:
> 
>> # untested
>> class TaintList(list):
>> def append(self, obj):
>> list.append(self, TaintThing(obj))
>> # similar for __setitem__, extend, insert


Sure. Just change the initialisation of TaintThing to something like this:

#untested
def __init__(self, obj, parent):
self.__dict__['_proxy'] = obj
self.parent = parent


and then TaintList to something like this:

def append(self, obj):
list.append(self, TaintThing(obj, self))
# similar for __setitem__, extend, insert





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


Re: Tkinter w.pack()?

2009-01-28 Thread John Posner
The difference between the fill=, expand=, and anchor= options to the pack()
function takes a while to get used to. In brief:

* fill= controls the size of a control itself

* expand= controls the size of the space into which the pack() function
places a control

* anchor= comes into play if the size of the space exceeds the size of the
control

This Google Doc might be helpful:

   http://docs.google.com/Doc?id=dhmzfrmj_0c685rrdb

It shows the effects of progressively adding various fill= and expand=
clause within three statements that create and place Button controls.

-John





E-mail message checked by Spyware Doctor (6.0.0.386)
Database version: 5.11640
http://www.pctools.com/en/spyware-doctor-antivirus/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter w.pack()?

2009-01-28 Thread r
On Jan 28, 10:57 pm, "W. eWatson"  wrote:
> The word pack doesn't exist on the NMT pdf. Maybe there's a newer one?

Only the grid manager is discussed at NMT. I just like how at NMT the
widget attributes are in a table and then a list the widget methods
follows below that -- much better navigation.

I talked again to John at NMT and he assured me very soon he's going
to make all the updates. It would probably help if you sent him a nice
message of encouragement like -- 'Can you please update the
documentation, i really like the sites layout?' -- but please don't
forget to thank him for all his contributions to the Python community.

I am currently crusading to have all the old Python tuts and
documentation updated(among other crusades). This was my second win
and i hope that more will follow. The python docs out there need a
dusting off and spit shining.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter w.pack()?

2009-01-28 Thread Gabriel Genellina
En Thu, 29 Jan 2009 02:57:04 -0200, W. eWatson   
escribió:



The word pack doesn't exist on the NMT pdf. Maybe there's a newer one?


There is a PDF version of "An Introduction to Tkinter" here:
http://www.pythonware.com/library/

--
Gabriel Genellina

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


Re: Tkinter w.pack()?

2009-01-28 Thread W. eWatson

r wrote:

To expand on this there exists three geometry mangers [grid, pack,
place]. I personally use pack() the most, grid() almost never, and
place -- well never. But each one has it's strengths and weaknesses.

w.grid()
http://effbot.org/tkinterbook/grid.htm

w.place()
http://effbot.org/tkinterbook/place.htm



There seems to be a pattern here. :-)

Everything you need to know about Tkinter exists here:
http://effbot.org/tkinterbook/

and at the NMT site i showed you before

The word pack doesn't exist on the NMT pdf. Maybe there's a newer one?

--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 

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


Re: Tkinter w.pack()?

2009-01-28 Thread W. eWatson

r wrote:

On Jan 28, 10:12 pm, "W. eWatson"  wrote:

Where in the world is a description of pack() for Tkinter widgets? Is it
some sort of general method for all widgets? I'm looking in a few docs that
use it without ever saying where it is described. For one,
. In the NM Tech pdf on Tkinter,
it's not found anywhere. I see Universal methods for widgets, but no mention
of pack(). package, packed, but no pack.


did you try here :)
http://effbot.org/tkinterbook/pack.htm
Thanks. I have the site bookmarked, but it's hard to search. I posted a 
comment to them that they should have it in pdf form.


--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 

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


Re: dicts,instances,containers, slotted instances, et cetera.

2009-01-28 Thread Steven D'Aprano
On Wed, 28 Jan 2009 15:20:41 -0800, ocschwar wrote:

> On Jan 28, 4:50 pm, Aaron Brady  wrote:
>> On Jan 28, 2:38 pm, ocsch...@gmail.com wrote:
>>
>> Hello, quoting myself from another thread today:
>>
>> There is the 'shelve' module.  You could create a shelf that tells you
>> the filename of the 5 other ones.  A million keys should be no problem,
>> I guess.  (It's standard library.)  All your keys have to be strings,
>> though, and all your values have to be pickleable.  If that's a
>> problem, yes you will need ZODB or Django (I understand), or another
>> relational DB.
>>
>> There is currently no way to store live objects.
> 
> 
> The problem is NOT archiving these objects. That works fine.
> 
> It's the computations I'm using these thigns for that are slow, and that
> failed to speed up using __slots__.

You've profiled and discovered that the computations are slow, not the 
archiving?

What parts of the computations are slow?


> What I need is something that will speed up getattr() or its equivalent,
> and to a lesser degree setattr() or its equivalent.

As you've found, __slots__ is not that thing.

>>> class Slotted(object):
... __slots__ = 'a'
... a = 1
...
>>> class Unslotted(object):
... a = 1
...
>>> t1 = Timer('x.a', 'from __main__ import Slotted; x = Slotted()')
>>> t2 = Timer('x.a', 'from __main__ import Unslotted; x = Unslotted()')
>>>
>>> min(t1.repeat(10))
0.1138761043548584
>>> min(t2.repeat(10))
0.11414718627929688


One micro-optimization you can do is something like this:

for i in xrange(100):
obj.y = obj.x + 3*obj.x**2
obj.x = obj.y - obj.x
# 12 name lookups per iteration


Becomes:


y = None
x = obj.x
try:
for i in xrange(100):
y = x + 3*x**2
x = y - x
# 6 name lookups per iteration
finally:
obj.y = y
obj.x = x


Unless you've profiled and has evidence that the bottleneck is attribute 
access, my bet is that the problem is some other aspect of the 
computation. In general, your intuition about what's fast and what's slow 
in Python will be misleading if you're used to other languages. E.g. in C 
comparisons are fast and moving data is slow, but in Python comparisons 
are slow and moving data is fast.


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


Re: Tkinter w.pack()?

2009-01-28 Thread r
To expand on this there exists three geometry mangers [grid, pack,
place]. I personally use pack() the most, grid() almost never, and
place -- well never. But each one has it's strengths and weaknesses.

w.grid()
http://effbot.org/tkinterbook/grid.htm

w.place()
http://effbot.org/tkinterbook/place.htm


Everything you need to know about Tkinter exists here:
http://effbot.org/tkinterbook/

and at the NMT site i showed you before
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter w.pack()?

2009-01-28 Thread r
On Jan 28, 10:12 pm, "W. eWatson"  wrote:
> Where in the world is a description of pack() for Tkinter widgets? Is it
> some sort of general method for all widgets? I'm looking in a few docs that
> use it without ever saying where it is described. For one,
> . In the NM Tech pdf on Tkinter,
> it's not found anywhere. I see Universal methods for widgets, but no mention
> of pack(). package, packed, but no pack.

did you try here :)
http://effbot.org/tkinterbook/pack.htm
--
http://mail.python.org/mailman/listinfo/python-list


Tkinter w.pack()?

2009-01-28 Thread W. eWatson
Where in the world is a description of pack() for Tkinter widgets? Is it 
some sort of general method for all widgets? I'm looking in a few docs that 
use it without ever saying where it is described. For one, 
. In the NM Tech pdf on Tkinter, 
it's not found anywhere. I see Universal methods for widgets, but no mention 
of pack(). package, packed, but no pack.


While I'm at it, what is w in the result of w = Label(parent, image=photo)? 
Just a widget pointer, address?

--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 

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


Re: Exec woes

2009-01-28 Thread Rhodri James
On Wed, 28 Jan 2009 07:47:00 -, Hendrik van Rooyen  
 wrote:



Stephen Hansen wrote:

Exec is a statement, not a function nor an object: even though you can  
enclose parens around its arguments like you do later on, they

don't have any syntax meaning


This is actually not correct - it is the root cause of my trouble.
if you write, in a nested scope:

exec ( "somestring to execute" in globals(),locals())

You get the syntax error, as the interpreter somehow sees it as one,  
unqualified thing.


Well, no.  Look at the error Python gives you, nested scope or not:

Traceback (most recent call last):
  File "", line 1, in 
TypeError: exec: arg 1 must be a string, file, or code object

If exec is a function, arg 1 is the boolean expression
  "somestring to execute" in globals()
which is unlikely to be what you want.  If exec is a statement,
arg 1 is a tuple of two elements,
  "somestring to execute" in globals()
and
  locals()
which is also unlikely to be what you want.  Neither of these are
giving you a string, file or code object, exactly as the interpreter
is telling you.

--
Rhodri James *-* Wildebeeste Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: need help

2009-01-28 Thread juvy j
Hi tkc,

Thanks so much.. it works! :-)
I used  the urllib.

and thanks also to everybody who replied.

jtj

On Thu, Jan 29, 2009 at 11:08 AM, Tim Chase
wrote:

>  Thanks for you reply. I am newbie in python.
>> Im going to use HTTP.
>>
>
> If all you want is to download a file, you might want to look into using
> "wget" or "curl" (which work for both HTTP and FTP).  E.g.
>
>  bash$ wget http://myothermachine/path/to/file.html
>
> However, if you need to roll it into a script, Python's urllib module will
> do the trick
>
>  >>> import urllib
>  >>> url = "http://myothermachine/path/to/file.html";
>  >>> f = urlib.urlopen(url)
>  >>> out = file('python.txt', 'w')
>  >>> for line in f: out.write(line)
>  ...
>  >>> out.close()
>  >>> f.close()
>
> If the content is small, you can just use
>
>  >>> content = f.read()
>  >>> out.write(content)
>
> instead of the "for line in f: out.write(line)".  If you need to actually
> parse the HTML that's returned, the common suggestion is to use the
> BeautifulSoup add-on module which has worked for my needs.
>
> -tkc
>
>
>
>
>
>
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Function Application is not Currying

2009-01-28 Thread Tim Greer
Russ P. wrote:

> On Jan 28, 1:32 pm, Xah Lee  wrote:
>> Function Application is not Currying
>>
>> Xah Lee, 2009-01-28
>>
>> In Jon Harrop's book Ocaml for Scientist
>> athttp://www.../chapter1.html
>>
>> It says:
>>
>> Currying
>>
>> A curried function is a function which returns a function as its
>> result.
>>
>> LOL. That is incorrect.
> 
> What does that have to do with the price of bananas in Costa Rica?

Xah Lee does this stuff in 4 or 5 groups he's decided to post random
things to.  They rarely have any relevance or substance, just his
personal thoughts.  He liked to provoke arguing and tell everyone he's
a genius in his own mind.  It's best to just filter his posts out like
most of us have already done.  I don't know what group you're seeing
his post in, but he bugs us in the Perl group all the time, cross
posting things that have nothing to do with Perl (same with his cross
posts to Python, too). :-)
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Function Application is not Currying

2009-01-28 Thread Russ P.
On Jan 28, 1:32 pm, Xah Lee  wrote:
> Function Application is not Currying
>
> Xah Lee, 2009-01-28
>
> In Jon Harrop's book Ocaml for Scientist 
> athttp://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html
>
> It says:
>
>     Currying
>
>     A curried function is a function which returns a function as its
> result.
>
> LOL. That is incorrect.

What does that have to do with the price of bananas in Costa Rica?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Results of executing hyperlink in script

2009-01-28 Thread Tim Chase

1. This method was suggested by Cameron Laird:

  os.system("start %s" % URL)

It works. But, if the URL contains character &, it will fail. For



As an aside, the START command is a bit picky regarding quotes. 
You have to use this horrible contortion


  os.system('start "title" "%s"' % URL)

The "title" is optional content-wise, but required positionally 
if there's a quoted resource, so you can just use


  start "" "%s"

a pain, but that's CMD.EXE for you. :)

-tkc




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


Re: pyAA for Python2.5

2009-01-28 Thread Kottiyath
On Jan 29, 1:51 am, Rob Williscroft  wrote:
> Kottiyath wrote in news:6a594643-f6a2-4d8d-aab3-27eb16cb2fb8
> @b38g2000prf.googlegroups.com in comp.lang.python:
>
>
>
> > I have mingw32-gcc in my path. If I try that too -it fails.
>
> > C:\Documents and Settings\Guest\pyAA>python setup.py install -c
> > "mingw32-gcc"
> > invalid command name 'mingw32-gcc'
>
> All the examples I found via google have the tool name as "mingw32"
> so try:
>
>         python setup.py install -c mingw32
>
> or
>
>         python setup.py build --compiler=mingw32 install
>
> The compiler that the MinGW package installs is gcc.
>
> You shoulf be able to verify it is on your path by typing:
>
>         gcc --help
> or
>         gcc --version
>
> and see some output.
>
> Rob.
> --http://www.victim-prime.dsl.pipex.com/

Thank you Rob.
The installation went ahead for some more time - but failed showing a
lot of errors:
>compile
running build
running build_py
file pyAAc.py (for module pyAAc) not found
file pyAAc.py (for module pyAAc) not found
...
pyAAc.cpp:5887: error: `EVENT_OBJECT_HELPCHANGE' was not declared in
this scope
pyAAc.cpp:5888: error: `EVENT_OBJECT_DEFACTIONCHANGE' was not declared
in this scope
pyAAc.cpp:5889: error: `EVENT_OBJECT_ACCELERATORCHANGE' was not
declared in this scope
...
error: command 'gcc' failed with exit status 1

I cannot understand why it fails. I have not worked in C till now, so
I am pretty confused.
I googled also, but to no avail.
--
http://mail.python.org/mailman/listinfo/python-list


Re: need help

2009-01-28 Thread Tim Chase

Thanks for you reply. I am newbie in python.
Im going to use HTTP.


If all you want is to download a file, you might want to look 
into using "wget" or "curl" (which work for both HTTP and FTP).  E.g.


  bash$ wget http://myothermachine/path/to/file.html

However, if you need to roll it into a script, Python's urllib 
module will do the trick


 >>> import urllib
 >>> url = "http://myothermachine/path/to/file.html";
 >>> f = urlib.urlopen(url)
 >>> out = file('python.txt', 'w')
 >>> for line in f: out.write(line)
 ...
 >>> out.close()
 >>> f.close()

If the content is small, you can just use

 >>> content = f.read()
 >>> out.write(content)

instead of the "for line in f: out.write(line)".  If you need to 
actually parse the HTML that's returned, the common suggestion is 
to use the BeautifulSoup add-on module which has worked for my needs.


-tkc






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


Re: Results of executing hyperlink in script

2009-01-28 Thread Gabriel Genellina
En Wed, 28 Jan 2009 20:49:14 -0200, Muddy Coder   
escribió:



My previous post got a many helps from the people, and I tested what
they suggested. Since this topic maybe needed in future, so I drop
these lines below to help the future programmers. The methods worked
as below:

1. This method was suggested by Cameron Laird:

  os.system("start %s" % URL)

It works. But, if the URL contains character &, it will fail. For



2. The best way is to use urllib2, suggested by Ron Barak, my code is
below:

import urllib2
source = urllib2.urlopen(URL).read()
print source


Note that both methods are essencially different. The first one opens a  
browser window, and it's up to the user what to do after the initial  
request is done -- if this is what you want, the webbrowser module is  
better suited for that task.
The second one is a pure programming interfase - the Python script is in  
control, and the user isn't involved at all.


--
Gabriel Genellina

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


How to get atexit hooks to run in the presence of execv?

2009-01-28 Thread R. Bernstein
As a hobby I've been (re)writing a debugger. One of the commands,
"restart", works by calling an execv(). You may need to do this when
the program you are debugging is threaded or when one needs to ensure
that all program state is reinitialized.

Recently, I added remote debugging via TCP sockets. (Well, also FIFO's
as well but closing sockets before restarting is what's of concern.)

I noticed that execv in Python 2.5.2 doesn't arrange exit hooks to get
called. Should it?  Furthermore, I don't seen any atexit routine that
would let me initiate such finalization. Should there be one?

Or perhaps I'm missing something. Is there a way to arrange atexit
hooks to get run before issuing an execv-like call? 

Thanks.

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


Re: Sloooooowwwww WSGI restart

2009-01-28 Thread Ron Garret
In article 
<4cd232ff-ba8b-47aa-8ee6-d8d9712db...@s1g2000prg.googlegroups.com>,
 Graham Dumpleton  wrote:

> On Jan 29, 8:35 am, Ron Garret  wrote:
> > I'm running a WSGI app under apache/mod_wsgiand I've noticed that
> > whenever I restart the server after making a code change it takes a very
> > long time (like a minute) before the script is active again.  In other
> > words, I do an apachectl restart, reload the page in my browser, and one
> > minute later it finally comes up.  During this time CPU usage is
> > essentially zero.  Loading all the code manually into a python
> > interpreter is virtually instantaneous, and all subsequence interactions
> > with the app are very fast.
> >
> > Does anyone have any ideas what might be going on or how to debug this?
> 
> The better place to discuss this is the mod_wsgi list.
> 
>   http://groups.google.com/group/modwsgi?hl=en

The reason I don't go there is that I'm using an NNTP client.  I find 
Google Groups' web interface to be very annoying because there's no way 
to keep track of read messages.

> As to the problem, you need to distinguish between whether it is
> Apache that is taking a long time to restart and ready to handle
> requests, or whether the delay is on the first subsequent request made
> against your WSGI application.
> 
> When Apache restarts, it doesn't by default load your WSGI
> application, it only does that the first time a request comes in
> directed at it. Thus, if after you restart Apache you do a request of
> a static file, do you get a response straight away?

I thought I did, but having poked at it more I now realize that I was 
just getting a cached page.  It does appear to be an apache issue, not a 
WSGI issue.  Sorry for the false alarm.

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


Re: date handling problem

2009-01-28 Thread Gabriel Genellina
En Wed, 28 Jan 2009 18:55:21 -0200, S.Selvam Siva   
escribió:


I need to parse rss-feeds based on time stamp,But rss-feeds follow  
different

standards of date(IST,EST etc).
I dont know,how to standardize this standards.It will be helpful if you  
can

hint me.


You may find the Olson timezone database useful.
http://pytz.sourceforge.net/

--
Gabriel Genellina

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


Re: Quickbooks

2009-01-28 Thread Gabriel Genellina
En Wed, 28 Jan 2009 16:21:29 -0200, Stephen Chapman  
 escribió:


Has anyone Implemented the Quickbooks  COM object in Python.  If so can  
you give me

an Idea of where to begin.


You'll want the pywin32 package by Mark Hammond -available from  
sourceforge-. It provides the infrastructure required to manipulate any  
COM object from Python.
M. H. coauthored the book "Python Programming On Win32"; the sample  
chapter available at Amazon is precisely "Introduction to COM".


--
Gabriel Genellina

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


Re: Drawing and Displaying an Image with PIL

2009-01-28 Thread W. eWatson

Peter Otten wrote:

W. eWatson wrote:


r wrote:

Change this line:
draw.line((0,0),(20,140), fill=128)

To This:
draw.line((0,0, 20,140), fill=128)

And you should be good to go. Like you said, if you need to combine 2
tuples you can do:
(1,2)+(3,4)

Yes, that's true, but the big question is how to "see" the final image?
Either one employees another module or writes the file into a folder, then
displays it with a paint program?


For debugging purposes you can just invoke the show() method

im = Image.open(...)
# modify image
im.show() 


If you want to integrate the image into your own Tkinter program -- that is
explained here:

http://effbot.org/tkinterbook/photoimage.htm

Following these instruction you code might become

import Tkinter as tk
import Image
import ImageTk
import ImageDraw
import sys

filename = sys.argv[1]
im = Image.open(filename)

draw = ImageDraw.Draw(im)
draw.line((0, 0) + im.size, fill=128)
draw.line(((0,0),(20,140)), fill=128)


root = tk.Tk()
pi = ImageTk.PhotoImage(im)
label = tk.Label(root, image=pi)
label.pack()
root.mainloop()

Peter
My initial quest was to do it in PIL. That seems impossible, and the way out 
is Tkinter. I'm not yet savvy enough with Pythons graphics. I was definitely 
leaning towards PhotoImage as the way out. What module is show in?


Repairing my (0,0), ... to (0,0)+, and. replacing arg with ImageOPen, 
produces a correct solution.


My NM Tech pdf misses the boat on PhotoImage. I've seen your reference 
before, but never looked at PhotoImage. I'll bookmark it. I sure wish it was 
in pdf format.


Thanks.


--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 

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


Re: writing large dictionaries to file using cPickle

2009-01-28 Thread Gabriel Genellina

En Wed, 28 Jan 2009 14:13:10 -0200,  escribió:


i have a large dictionary which contains about 10 keys, each key has a
value which is a list containing about 1 to 5 million (small)
dictionaries. for example,

mydict = {key1: [{'a': 1, 'b': 2, 'c': 'hello'}, {'d', 3, 'e': 4, 'f':
'world'}, ...],
key2: [...]}

[pickle] creates extremely large files (~ 300 MB) though it does so
*extremely* slowly. it writes about 1 megabyte per 5 or 10 seconds and
it gets slower and slower. it takes almost an hour if not more to
write this pickle object to file.


There is an undocumented Pickler attribute, "fast". Usually, when the same  
object is referenced more than once, only the first appearance is stored  
in the pickled stream; later references just point to the original. This  
requires the Pickler instance to remember every object pickled so far --  
setting the "fast" attribute to a true value bypasses this check. Before  
using this, you must be positively sure that your objects don't contain  
circular references -- else pickling will never finish.


py> from cPickle import Pickler
py> from cStringIO import StringIO
py> s = StringIO()
py> p = Pickler(s, -1)
py> p.fast = 1
py> x = [1,2,3]
py> y = [x, x, x]
py> y
[[1, 2, 3], [1, 2, 3], [1, 2, 3]]
py> y[0] is y[1]
True
py> p.dump(y)

py> s.getvalue()
'\x80\x02](](K\x01K\x02K\x03e](K\x01K\x02K\x03e](K\x01K\x02K\x03ee.'

Note that, when unpickling, shared references are broken:

py> s.seek(0,0)
py> from cPickle import load
py> y2 = load(s)
py> y2
[[1, 2, 3], [1, 2, 3], [1, 2, 3]]
py> y2[0] is y2[1]
False

--
Gabriel Genellina

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


Re: Results of executing hyperlink in script

2009-01-28 Thread Cameron Laird
In article ,
MRAB   wrote:
>Muddy Coder wrote:
.
.
.
>You could put quotes around the URL:
>
>os.startfile('"%s"' % URL)
>
>or:
>
>os.system('start "%s"' % URL)
>
>if "&" has a special meaning to the command-line.

In fact, no, happiness does NOT result in these contexts with
another layer of quoting.
  os.startfile(URL)
works fine even if URL embeds special characters, and does not
work at all if URL is itself quoted.

  os.system("start ...")

just gives a variety of unuseful results if URL embeds special
characters.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Function Application is not Currying

2009-01-28 Thread Kaz Kylheku
On 2009-01-28, Xah Lee  wrote:
> Function Application is not Currying

That's correct, Xah. Currying is a special case of function application. 
A currying function is applied to some other function, and returns function
that has fewer arguments.

In some languages, you don't see the currying function. It's invisibly
performed whenever you forget an argument. Hit a three argument function with
only two arguments, and you don't get a nice ``insufficient arguments in
function call'' error, but the call is diverted to the currying function, which
gives you back a function of one argument, which you can then call with the
missing argument to compute the original function.

> Xah Lee, 2009-01-28
>
> In Jon Harrop's book Ocaml for Scientist at
> http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html

Figures you'd be reading this. Learning anything?

> It says:
>
> Currying
>
> A curried function is a function which returns a function as its
> result.
>
> LOL. That is incorrect.

Yawn. Say it isn't so.
--
http://mail.python.org/mailman/listinfo/python-list


Re: need help

2009-01-28 Thread juvy j
Hi Steve,

Thanks for you reply. I am newbie in python.
Im going to use HTTP.

thanks a lot

On Wed, Jan 28, 2009 at 9:40 PM, Steve Holden  wrote:

> juvy j wrote:
> > Hi guys,
> >
> > need help on how to read file from other server(linux).
> >
> Which service do you plan to use: FTP, HTTP and NFS are three
> possibilities that immediately come to mind, all well handled by {ython
> standard library modules. A little more background might help.
>
> regards
>  Steve
> --
> Steve Holden+1 571 484 6266   +1 800 494 3119
> Holden Web LLC  http://www.holdenweb.com/
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Sloooooowwwww WSGI restart

2009-01-28 Thread Graham Dumpleton
On Jan 29, 8:44 am, Aleksandar Radulovic  wrote:
> Hi there,
>
> On Wed, Jan 28, 2009 at 9:35 PM, Ron Garret  wrote:
> > I'm running a WSGI app under apache/mod_wsgiand I've noticed that
>
> Off the bat, there's no reason to run an app under apache/mod_wsgi
> while developing it,
> ie. if u use Pylons or TurboGears, there's an easier way to serve the
> app (using paster
> or cherrypy).
>
> Secondly, why are you restarting apache after code changes? In normal
> circumstances,
> you shouldn't have to do that.

Sorry, you are wrong to assume that an Apache restart is not be
required.

If you are using mod_wsgi embedded mode, or mod_python, then a code
change will always require a full restart of Apache.

If you are using mod_wsgi daemon mode, you need to at least touch the
WSGI script file for an automatic restart of that specific application
to occur. Changes to arbitrary Python code files are not detected.

If using mod_wsgi daemon mode, you can also set up a separate
background thread to monitor for arbitrary code changes as described
for Django in:

  http://blog.dscpl.com.au/2008/12/using-modwsgi-when-developing-django.html

That page references original documentation on mod_wsgi wiki for bulk
of information.

Thus, the conjecture that Apache/mod_wsgi cannot be used and that
CherryPy WSGI server or Paster server must be used when developing a
Python web application is false. If using mod_wsgi then daemon mode
would of course be preferred though, with touching the WSGI script
file being safest option to ensure updates across multiple files
picked up at same time, but if you really want completely automated
restarts, use the recipe in mod_wsgi documentation.

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


Re: Sloooooowwwww WSGI restart

2009-01-28 Thread Ron Garret
In article ,
 Jean-Paul Calderone  wrote:

> On Wed, 28 Jan 2009 13:35:56 -0800, Ron Garret  wrote:
> >I'm running a WSGI app under apache/mod_wsgi and I've noticed that
> >whenever I restart the server after making a code change it takes a very
> >long time (like a minute) before the script is active again.  In other
> >words, I do an apachectl restart, reload the page in my browser, and one
> >minute later it finally comes up.  During this time CPU usage is
> >essentially zero.  Loading all the code manually into a python
> >interpreter is virtually instantaneous, and all subsequence interactions
> >with the app are very fast.
> >
> >Does anyone have any ideas what might be going on or how to debug this?
> 
> strace is nice.  It sounds like some blocking network operation.  rdns can
> often cause things like this.  If you're lucky, strace will point right at
> the problem.
> 
> Jean-Paul

That's a good idea.  Thanks!

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


Re: Sloooooowwwww WSGI restart

2009-01-28 Thread Ron Garret
In article ,
 Aleksandar Radulovic  wrote:

> Hi there,
> 
> On Wed, Jan 28, 2009 at 9:35 PM, Ron Garret  wrote:
> > I'm running a WSGI app under apache/mod_wsgi and I've noticed that
> 
> Off the bat, there's no reason to run an app under apache/mod_wsgi
> while developing it,
> ie. if u use Pylons or TurboGears, there's an easier way to serve the
> app (using paster
> or cherrypy).

Yes, I know.  I guess I'm just a masochist.  But this would be an issue 
in production as well.  I don't want to have to go down for a minute 
every time I push a new release.

> Secondly, why are you restarting apache after code changes? In normal
> circumstances, you shouldn't have to do that.

I thought (and experiment confirms) that only the main WSGI app file 
gets reloaded automatically when it changes, not the libraries.

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


Re: Sloooooowwwww WSGI restart

2009-01-28 Thread Graham Dumpleton
On Jan 29, 8:35 am, Ron Garret  wrote:
> I'm running a WSGI app under apache/mod_wsgiand I've noticed that
> whenever I restart the server after making a code change it takes a very
> long time (like a minute) before the script is active again.  In other
> words, I do an apachectl restart, reload the page in my browser, and one
> minute later it finally comes up.  During this time CPU usage is
> essentially zero.  Loading all the code manually into a python
> interpreter is virtually instantaneous, and all subsequence interactions
> with the app are very fast.
>
> Does anyone have any ideas what might be going on or how to debug this?

The better place to discuss this is the mod_wsgi list.

  http://groups.google.com/group/modwsgi?hl=en

As to the problem, you need to distinguish between whether it is
Apache that is taking a long time to restart and ready to handle
requests, or whether the delay is on the first subsequent request made
against your WSGI application.

When Apache restarts, it doesn't by default load your WSGI
application, it only does that the first time a request comes in
directed at it. Thus, if after you restart Apache you do a request of
a static file, do you get a response straight away? If it doesn't
respond straight away, then it is an issue with Apache restart and not
mod_wsgi as your WSGI application wouldn't be involved.

If the static file request is fine and only first request to WSGI
application is slow, then likely that problem is to do with the
startup cost of loading your WSGI application and initialising it upon
first request. As you don't say what Python web framework/application
you are using, hard to say what the issue may be there.

If it is an Apache issue and not mod_wsgi, as pointed out already,
could be that you have Apache setup to do reverse DNS lookups on
client IP address and that isn't working properly. This often happens
for Windows people.

So, narrow down where problem is occurring.

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


program organization question

2009-01-28 Thread Vincent Davis
Basically my program simulates the Medical Residency Match, generating
simulated data, running the match and then summarizing results. Currently it
does this all in one document (starting conditions--Gen data--run
match--summarize results). I will be running multiple simulations on
different starting condition and data generation. My question is how should
I organize this. My plane was to have a separate document for staring
conditions, data generation because these will change for each simulation.
Then on for the match a summarizing data as this will always be the same
except for saving the results as different names.
I don't even know how to pass data from on program to another although I
think I can figure this out.

Any guidance?

Thanks
Vincent Davis
--
http://mail.python.org/mailman/listinfo/python-list


Re: Reuse of DB-API 2.0 cursors for multiple queries?

2009-01-28 Thread Carsten Haese
moreati wrote:
> Today, I used the adodbapi module against an SQL Server Express
> database. I was surprised to get an exception, when I attempted to
> submit a second query with my cursor object. The full session is
> below.
> 
> With cx_Oracle I've become used to reusing a cursor for subsequent
> queries. The PEP doesn't specify either way, that I can see.

The PEP doesn't say explicitly that a cursor can execute multiple
queries, but it's definitely implied by the second paragraph:

"""
.execute(operation[,parameters])

Prepare and execute a database operation (query or
command).  Parameters may be provided as sequence or
mapping and will be bound to variables in the operation.
Variables are specified in a database-specific notation
(see the module's paramstyle attribute for details). [5]

A reference to the operation will be retained by the
cursor.  If the same operation object is passed in again,
then the cursor can optimize its behavior.  This is most
effective for algorithms where the same operation is used,
but different parameters are bound to it (many times).
"""

You might want to check on a list dedicated to adodbapi whether there
are module-specific quirks or caveats to watch out for. Or wait for
somebody with adodbapi-specific knowledge to chime in.

HTH,

--
Carsten Haese
http://informixdb.sourceforge.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Windows PIL installer question

2009-01-28 Thread Gabriel Genellina

En Wed, 28 Jan 2009 15:07:54 -0200, cjl  escribió:


Is there any way to run the PIL installer from the command line on
Windows in 'silent' mode, without displaying the install screens or
requiring user interaction?


Is it a .msi?
msiexec /i filename.msi /quiet /log path\to\logfile.log

--
Gabriel Genellina

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


Re: Function Application is not Currying

2009-01-28 Thread James Mills
On Thu, Jan 29, 2009 at 10:28 AM, alex23  wrote:
> On Jan 29, 7:32 am, Xah Lee  wrote:
>> But he is really a asshole, and
>> take every chance to peddle his book.
>
> As opposed to really being an asshole and peddling one's website at
> every opportunity?

It would seem that Xah Lee suffers from a syndrome
we've come to know as "I'm Mr. Big Shot look at me I know everything"

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


Re: Function Application is not Currying

2009-01-28 Thread alex23
On Jan 29, 7:32 am, Xah Lee  wrote:
> But he is really a asshole, and
> take every chance to peddle his book.

As opposed to really being an asshole and peddling one's website at
every opportunity?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Package Managment

2009-01-28 Thread david.lyon
Hi,


>>> People coming to Python from Perl and Ruby expect to be able to just
>>> run a command to download and install a package. 

TRUE TRUE

Forgive me, but I am no python specialist. But I use all the other
languages as well and python isn't up to standard in this area.

Perphaps 50% of all my python time, is spent searching and testing packages
for what I need off peoples web sites. It is crazy...

In perl it is so much easier on cpan, but i hate the language (perl)...

I really propose something be done about it, but it takes a team 

In perl, it is so easy to remember "ppm" (perl package manager)..

My only suggestion is that allowance be made for platform specific
components, ie, windows, mac... because under windows, a lot of the tools I
use are platform specific linking to the o/s. It would be desirable to
seperate those out from packages that are not platform specific.

On Wed, 28 Jan 2009 19:53:42 +0900, David Cournapeau 
wrote:
> On Wed, Jan 28, 2009 at 3:16 PM, Bernard Rankin 
> wrote:
>> [extracted from pylons-discuss]
>>
>>
>>> >> I hate to pass the buck, but this is Python's fault for not having
>>> >> reliable package management built in.  There's nothing Pylons can do
>>> >> about it except switch to another programming language.
>>> > [SNIP]
>>>
>>> Without Setuptools,
>>> Pylons and TurboGears couldn't exist, and Zope and Twisted
>>> would not have been able to split themselves into several packages.
>>> People coming to Python from Perl and Ruby expect to be able to just
>>> run a command to download and install a package.  That problem was
>>> solved ten years ago, so why does Python still not have it standard?
>>>
>>> If Setuptools and Virtualenv or the equivalent were built into Python,
>>> you could trust that every computer that has successfully installed
>>> Python can install packages and make virtual environments the same
>>> way..
>>>
>>> That would eliminate 2/3 of the problems users have when
>>> installing Pylons, and the subsequent need to explain the problems and
>>> workarounds in the installation docs.  At
>>> work people say, "Half the trouble of Pylons is installing it", and I
>>> often have to help them install it in person because otherwise they
>>> get stuck at some error message and have no idea what to do.
>>>
>>
>> Agreed.  I would even move ipython (or something like it) to core.
>>
>> Of course, even Setuptools has a long way to go in some areas.
> (Installation Rollback, for one.)
>>
>> Python is about "batteries included", and these are major "batteries" in
> most modern environments.
>>
>> A CPAN like "in-house hosted" archive would nice, too.  This way,
> modules have a better chance of outliving the original author's
> interest/commitment in paying for, possibly non-trivial, web hosting.
>>
>> I'm sure these issues has been discussed to death, but I wonder what the
> larger Python community thinks.
> 
> You may be interested in the following:
> 
> http://mail.python.org/pipermail/python-dev/2006-April/063952.html
> 
> The thread is two years and a half old, but my impression is that the
> situation has not changeed much since. Few if any people are against
> improving the situation, but more people are against the currently
> available solutions (setuptools, virtualenv, etc...).
> 
> cheers,
> 
> David
> --
> http://mail.python.org/mailman/listinfo/python-list

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


Re: small python-cgi wiki?

2009-01-28 Thread Дамјан Георгиевски
> I'm looking to set up a small private wiki, and am looking for
> recommendations.
> 
> Some sort of CGI based package that I could just untar somewhere web
> accessable via Apache would be great.

http://hatta.sheep.art.pl/About
· single file
· stores stuff in mercurial.
· it's WSGI, so yes you can run it as CGI too 
(wsgiref.handlers.CGIHandler)
http://hatta.sheep.art.pl/Features

-- 
дамјан ( http://softver.org.mk/damjan/ )

A: Because it reverses the logical flow of converstion.
Q: Why is top posting frowned upon?

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


how to update python on gnu emacs?

2009-01-28 Thread John Seales

I've updated to python 2.6. My terminal application finds the new python just 
fine, but my gnu-emacs still is on python 2.3. Does anyone know how I can 
change that?

using x86 powerbook

John Seales

_
Windows Live™ Hotmail®…more than just e-mail. 
http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howitworks_012009--
http://mail.python.org/mailman/listinfo/python-list


Re: Reuse of DB-API 2.0 cursors for multiple queries?

2009-01-28 Thread Дамјан Георгиевски


> Today, I used the adodbapi module against an SQL Server Express
> database. I was surprised to get an exception, when I attempted to
> submit a second query with my cursor object. The full session is
> below.

>>> curs.execute('select * from localview_roles')
>>> curs.execute('select * from localview_roles')

have you tried to curs.fetch() or fetchall() before the second execute?



-- 
дамјан ( http://softver.org.mk/damjan/ )

Scarlett Johansson: You always see the glass half-empty.
Woody Allen: No. I see the glass half-full, but of poison.

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


Re: errno 22 instead of errno 2

2009-01-28 Thread Gabriel Genellina
En Wed, 28 Jan 2009 07:04:30 -0200, Tim Golden   
escribió:

Glenn Linderman wrote:



open("c:\abc","rb")
 This simple one-line script, produces errno 22 on Python 2.6, but  
errno 2 on Python 2.5.2


Just glancing quickly at the svn logs, there certainly were some
changes around that area in 2008:

I'd question whether it's strictly a "regression", unintentional or
otherwise, since I doubt the code makes any particular commitment as
to which error code is raised, but I'd certainly be looking askance
if I had code which relied on a particular error number which then
changed!  Still, that's what unit tests are for, I suppose.


Even if nothing had changed on Python, one should note that the Windows  
API doesn't promise anything about the specific set of error codes a  
function might set (not that it happens every day, but MS has reserved the  
right to alter them).


PS: and thanks for my new word of the day: "askance"

--
Gabriel Genellina

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


Re: writing large dictionaries to file using cPickle

2009-01-28 Thread John Machin
On Jan 29, 9:43 am, perfr...@gmail.com wrote:
> On Jan 28, 5:14 pm, John Machin  wrote:
>
>
>
> > On Jan 29, 3:13 am, perfr...@gmail.com wrote:
>
> > > hello all,
>
> > > i have a large dictionary which contains about 10 keys, each key has a
> > > value which is a list containing about 1 to 5 million (small)
> > > dictionaries. for example,
>
> > > mydict = {key1: [{'a': 1, 'b': 2, 'c': 'hello'}, {'d', 3, 'e': 4, 'f':
> > > 'world'}, ...],
> > >                 key2: [...]}
>
> > > in total there are about 10 to 15 million lists if we concatenate
> > > together all the values of every key in 'mydict'. mydict is a
> > > structure that represents data in a very large file (about 800
> > > megabytes).
>
> > > what is the fastest way to pickle 'mydict' into a file? right now i am
> > > experiencing a lot of difficulties with cPickle when using it like
> > > this:
>
> > > from cPickle import pickle
> > > pfile = open(my_file, 'w')
> > > pickle.dump(mydict, pfile)
> > > pfile.close()
>
> > > this creates extremely large files (~ 300 MB) though it does so
> > > *extremely* slowly. it writes about 1 megabyte per 5 or 10 seconds and
> > > it gets slower and slower. it takes almost an hour if not more to
> > > write this pickle object to file.
>
> > > is there any way to speed this up? i dont mind the large file... after
> > > all the text file with the data used to make the dictionary was larger
> > > (~ 800 MB) than the file it eventually creates, which is 300 MB.  but
> > > i do care about speed...
>
> > > i have tried optimizing this by using this:
>
> > > s = pickle.dumps(mydict, 2)
> > > pfile.write(s)
>
> > > but this takes just as long... any ideas ? is there a different module
> > > i could use that's more suitable for large dictionaries ?
> > > thank you very much.
>
> > Pardon me if I'm asking the "bleedin' obvious", but have you checked
> > how much virtual memory this is taking up compared to how much real
> > memory you have? If the slowness is due to pagefile I/O, consider
> > doing "about 10" separate pickles (one for each key in your top-level
> > dictionary).
>
> the slowness is due to CPU when i profile my program using the unix
> program 'top'... i think all the work is in the file I/O. the machine
> i am using several GB of ram and ram memory is not heavily taxed at
> all. do you know how file I/O can be sped up?

More quick silly questions:

(1) How long does it take to load that 300MB pickle back into memory
using:
(a) cpickle.load(f)
(b) f.read()
?

What else is happening on the machine while you are creating the
pickle?

(2) How does

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


Re: Function Application is not Currying

2009-01-28 Thread MRAB

s...@netherlands.com wrote:

On Wed, 28 Jan 2009 13:32:29 -0800 (PST), Xah Lee  wrote:


Function Application is not Currying

Xah Lee, 2009-01-28

In Jon Harrop's book Ocaml for Scientist at
http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html

It says:

   Currying

   A curried function is a function which returns a function as its
result.


Curry, is that like chicken soup or some Indian mash?

"Currying" is named after someone called Curry. The 'correct' term is 
"partial parameterisation", which explains why it's often called 
"Currying" instead! :-)



Why ? How about returning an index number into an array of function pointers
as handlers from packet data?

Oh, thats network communications.


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


Re: file date/time on windows

2009-01-28 Thread MRAB

m.banaouas wrote:

thanks,
someone gave me the solution:
simply call time.localtime(...) instead of time.gmtime(...)

The explorer file time is what I need because it's the only file date visible
for most of users. So localtime is perfect for me.
We are talking about the same file stored in a shared lan-computer-folder.
I gess that if computers of those users are in different timezones, they could
see different file date ?


The filetime is stored as UTC and is converted to local time only for 
display. (Actually, that might apply only to NTFS.)


There's also the idiosyncrasy that the filetime, when converted to local 
time, will have 1 added to the hour during DST, irrespective of whether 
the filetime itself was during DST, so a file that was modified at 09:00 
on 1 January will appear to have been modified at 10:00 if viewed during 
June, and a file that was modified at 09:00 on 1 June will appear to 
have been modified at 08:00 if viewed during non-DST!



MRAB a écrit :

m.banaouas wrote:

hi,

I noticed recently that the value of file date/time I get with python:
time.strftime('%Y-%m-%d %H:%M', time.gmtime(os.stat(fullname).st_mtime))
is forwarding by one hour the real file date/time.

Example:
file A.txt: 2009-01-18 16:13
returned valeur:  2009-01-28 15:13

Is there a simple way to get it work correctely  (other than adding
always 1
hour ...) ?


time.gmtime(), as the name suggests, returns GMT (UTC).

From your email address I presume you're in France, which is GMT+1.

Windows Explorer shows the file time in local time, which for you is
currently GMT+1, but when the clocks go forward (DST) it'll be GMT+2.

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



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


Re: Terminating a Python program that uses multi-process, multi-threading

2009-01-28 Thread akineko
On Jan 28, 1:11 pm, MRAB  wrote:
> A hacky way of killing the processes would be for the processes to write
> their process IDs to the log and then you can write another script which
> will parse the log to get the process IDs and then kill the processes
> with those IDs. (Left as an exercise for the reader.

Thank you MRAB.
Your suggestion is very reasonable. I think I will do both.
Try to reduce the chance of freeze-up and create a script to clean-up.

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


Re: bigint to timestamp

2009-01-28 Thread John Machin
On Jan 29, 10:00 am, John Machin  wrote:
> On Jan 29, 1:05 am, Jon Clements  wrote:
>
>
>
> > On Jan 28, 1:50 pm, Steve Holden  wrote:
>
> > > Shah Sultan Alam wrote:
> > > > Hi Group,
> > > > I have file with contents retrieved from mysql DB.
> > > > which has a time field with type defined bigint(20)
> > > > I want to parse that field into timestamp format(-MM-DD HH:MM:SS
> > > > GMT) using python code.
> > > > The value I found for that field is 212099016004150509
> > > > Give me sample code that does the conversion.
>
> > > Please?
>
> > > Perhaps you could tell us what date and time 212099016004150509 is
> > > supposed to represent? The classic format is "seconds since the Unix
> > > epoch" but that isn't what this is:
>
> > > >>> time.localtime(212099016004150509)
>
> > > Traceback (most recent call last):
> > >   File "", line 1, in 
> > > ValueError: timestamp out of range for platform time_t
>
> > > Neither does it appear to be a MySQL TIME field, since the maximum value
> > > for that would appear to be
>
> > > >>> ((838*60)+59)*60+59
>
> > > 3020399
>
> > > So, just what is this field? What do the values mean?
>
> > > regards
> > >  Steve
> > > --
> > > Steve Holden        +1 571 484 6266   +1 800 494 3119
> > > Holden Web LLC              http://www.holdenweb.com/
>
> > Bit hard to guess without the actual date to compare to... and I'm a
> > bit busy, but thought I'd throw this in the pool: I'm guessing it's a
> > MySQL database that's had data put into it via a .NET application
> > using the .NET DateTime (so a 20 byte int sounds about right IIRC),
> > which is based on the number of ticks since Jan 1, 1 I think that
> > should end up around 2[18ish digits here...]...
>
> Mmmm ... I thought it might be the MS format that's ticks since
> 1600-01-01T00-00-00 (proleptic Gregorian calendar) where ticks happen
> 10,000,000 times per second, but:
>
> >>> x = 212099016004150509
> >>> seconds = x / 1000.0
> >>> seconds
> 21209901600.415051
> >>> days = seconds / 60. / 60. / 24.
> >>> days
> 245484.97222702604
> >>> years_approx = days / 365.25
> >>> years_approx
>
> 672.10122444086528
>
> which would make it in the year 2272.
>
> Perhaps the OP could tell us what are the maximum and minimum non-zero
> non-null values he can find, and what years those might belong to.
> Also (very important) he might assure us that he is copying/pasting
> those large numbers, not retyp[o]ing them.

About .Net DateTime: the word from Mordor is "Time values are measured
in 100-nanosecond units called ticks, and a particular date is the
number of ticks since 12:00 midnight, January 1, 1 A.D. (C.E.) in the
GregorianCalendar calendar."

"12:00 midnight"??? Is this 0001-01-02T00:00:00 ??? In any case, this
would make the OP's bigint about 50 years after the Hegira ...
plausible only if his database is rather historical.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Results of executing hyperlink in script

2009-01-28 Thread Jean-Paul Calderone

On Wed, 28 Jan 2009 23:14:59 +, MRAB  wrote:

Muddy Coder wrote:

Hi Folks,

My previous post got a many helps from the people, and I tested what
they suggested. Since this topic maybe needed in future, so I drop
these lines below to help the future programmers. The methods worked
as below:

1. This method was suggested by Cameron Laird:

  os.system("start %s" % URL)

It works. But, if the URL contains character &, it will fail. For
example, if URL has only one field, such as: 
http://www.mydomain.com/ascript.cgi?user=muddy

this method works well. But, if there more than one field need to be
input, such as http://www.mydomain.com/ascript.cgi/user=muddy&password=foo,
the field password failed to reach server, and the CGI script
complained.

You could put quotes around the URL:

os.startfile('"%s"' % URL)

or:

os.system('start "%s"' % URL)

if "&" has a special meaning to the command-line.


What if the URL has a " in it?  Worse, what if the URL is:

   " & rm -rf ~

os.system is a pretty bad thing to use.  Fortunately, the suggestion to
use urllib was a much better one, and you can't use os.system here anyway
since the poster is interested in getting the contents of the page at the
URL.

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


Re: dicts,instances,containers, slotted instances, et cetera.

2009-01-28 Thread Diez B. Roggisch

ocsch...@gmail.com schrieb:

On Jan 28, 4:50 pm, Aaron Brady  wrote:

On Jan 28, 2:38 pm, ocsch...@gmail.com wrote:

Hello, quoting myself from another thread today:

There is the 'shelve' module.  You could create a shelf that tells you
the filename of the 5 other ones.  A million keys should be no
problem, I guess.  (It's standard library.)  All your keys have to be
strings, though, and all your values have to be pickleable.  If that's
a problem, yes you will need ZODB or Django (I understand), or another
relational DB.

There is currently no way to store live objects.



The problem is NOT archiving these objects. That works fine.


I know. But if they are sorted to various criteria, doing that inside a 
DB might also be faster. That was the point I wanted to make.


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


Re: dicts,instances,containers, slotted instances, et cetera.

2009-01-28 Thread ocschwar
On Jan 28, 5:21 pm, "Diez B. Roggisch"  wrote:
> ocsch...@gmail.com schrieb:
>
>
>
> > Hi, all.
>
> > I have an application that that creates, manipulates, and finally
> > archives on disk 10^6 instances of an object that in CS/DB terms is
> > best described as a relation.
>
> > It has 8 members, all of them common Python datatypes. 6 of these are
> > set once and then not modified. 2 are modified around 4 times before
> > the instance's archving. Large collections (of small lists) of these
> > objects are created, iterated through, and sorted using any and all of
> > the 8 members as sorting keys.
>
> > It neither has nor needs custom methods.
>
> > I used a simple dictionary to create the application prototype. Now I
> > need to speed things up.
> > I first tried changing to a new style class, with __slots__, __init__,
> > __getstate__& __setstate__ (for pickling) and was shocked to see
> > things SLOW down over dictionaries.
>
> > So of these options, where should I go first to satisfy my need for
> > speed?
>
> > 0. Back to dict
> > 1. old style class
> > 2. new style class
> > 3. new style class, with __slots__, with or without some nuance I'm
> > missing.
> > 4. tuple, with constants to mark the indices
> > 5. namedTuple
> > 6. other...
>
> Use a database? Or *maybe* a C-extension wrapped by ctypes.
>
> Diez

I can't port the entire app to be a stored database procedure.

ctypes, maybe. I just find it odd that there's no quick answer on the
fastest way in Python to implement a mapping in this context.
--
http://mail.python.org/mailman/listinfo/python-list


Re: dicts,instances,containers, slotted instances, et cetera.

2009-01-28 Thread ocschwar
On Jan 28, 4:50 pm, Aaron Brady  wrote:
> On Jan 28, 2:38 pm, ocsch...@gmail.com wrote:
>
> Hello, quoting myself from another thread today:
>
> There is the 'shelve' module.  You could create a shelf that tells you
> the filename of the 5 other ones.  A million keys should be no
> problem, I guess.  (It's standard library.)  All your keys have to be
> strings, though, and all your values have to be pickleable.  If that's
> a problem, yes you will need ZODB or Django (I understand), or another
> relational DB.
>
> There is currently no way to store live objects.


The problem is NOT archiving these objects. That works fine.

It's the computations I'm using these thigns for that are slow, and
that failed to speed up using __slots__.

What I need is something that will speed up getattr() or its
equivalent, and to a lesser degree setattr() or its equivalent.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Function Application is not Currying

2009-01-28 Thread sln
On Wed, 28 Jan 2009 13:32:29 -0800 (PST), Xah Lee  wrote:

>Function Application is not Currying
>
>Xah Lee, 2009-01-28
>
>In Jon Harrop's book Ocaml for Scientist at
>http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html
>
>It says:
>
>Currying
>
>A curried function is a function which returns a function as its
>result.
>
Curry, is that like chicken soup or some Indian mash?

Why ? How about returning an index number into an array of function pointers
as handlers from packet data?

Oh, thats network communications.

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


Re: Results of executing hyperlink in script

2009-01-28 Thread MRAB

Muddy Coder wrote:

Hi Folks,

My previous post got a many helps from the people, and I tested what
they suggested. Since this topic maybe needed in future, so I drop
these lines below to help the future programmers. The methods worked
as below:

1. This method was suggested by Cameron Laird:

  os.system("start %s" % URL)

It works. But, if the URL contains character &, it will fail. For
example, if URL has only one field, such as: 
http://www.mydomain.com/ascript.cgi?user=muddy
this method works well. But, if there more than one field need to be
input, such as http://www.mydomain.com/ascript.cgi/user=muddy&password=foo,
the field password failed to reach server, and the CGI script
complained.


You could put quotes around the URL:

os.startfile('"%s"' % URL)

or:

os.system('start "%s"' % URL)

if "&" has a special meaning to the command-line.
--
http://mail.python.org/mailman/listinfo/python-list


Re: writing large dictionaries to file using cPickle

2009-01-28 Thread Aaron Brady
On Jan 28, 4:43 pm, perfr...@gmail.com wrote:
> On Jan 28, 5:14 pm, John Machin  wrote:
>
>
>
> > On Jan 29, 3:13 am, perfr...@gmail.com wrote:
>
> > > hello all,
>
> > > i have a large dictionary which contains about 10 keys, each key has a
> > > value which is a list containing about 1 to 5 million (small)
> > > dictionaries. for example,
>
> > > mydict = {key1: [{'a': 1, 'b': 2, 'c': 'hello'}, {'d', 3, 'e': 4, 'f':
> > > 'world'}, ...],
> > >                 key2: [...]}
>
> > > in total there are about 10 to 15 million lists if we concatenate
> > > together all the values of every key in 'mydict'. mydict is a
> > > structure that represents data in a very large file (about 800
> > > megabytes).
snip

> in reply to the other poster: i thought 'shelve' simply calls pickle.
> if thats the case, it wouldnt be any faster, right ?

Yes, but not all at once.  It's a clear winner if you need to update
any of them later, but if it's just write-once, read-many, it's about
the same.

You said you have a million dictionaries.  Even if each took only one
byte, you would still have a million bytes.  Do you expect a faster I/
O time than the time it takes to write a million bytes?

I want to agree with John's worry about RAM, unless you have several+
GB, as you say.  You are not dealing with small numbers.
--
http://mail.python.org/mailman/listinfo/python-list


Re: file date/time on windows

2009-01-28 Thread m.banaouas
thanks,
someone gave me the solution:
simply call time.localtime(...) instead of time.gmtime(...)

The explorer file time is what I need because it's the only file date visible
for most of users. So localtime is perfect for me.
We are talking about the same file stored in a shared lan-computer-folder.
I gess that if computers of those users are in different timezones, they could
see different file date ?


MRAB a écrit :
> m.banaouas wrote:
>> hi,
>>
>> I noticed recently that the value of file date/time I get with python:
>> time.strftime('%Y-%m-%d %H:%M', time.gmtime(os.stat(fullname).st_mtime))
>> is forwarding by one hour the real file date/time.
>>
>> Example:
>> file A.txt: 2009-01-18 16:13
>> returned valeur:  2009-01-28 15:13
>>
>> Is there a simple way to get it work correctely  (other than adding
>> always 1
>> hour ...) ?
>>
> time.gmtime(), as the name suggests, returns GMT (UTC).
> 
> From your email address I presume you're in France, which is GMT+1.
> 
> Windows Explorer shows the file time in local time, which for you is
> currently GMT+1, but when the clocks go forward (DST) it'll be GMT+2.
--
http://mail.python.org/mailman/listinfo/python-list


Re: bigint to timestamp

2009-01-28 Thread John Machin
On Jan 29, 1:05 am, Jon Clements  wrote:
> On Jan 28, 1:50 pm, Steve Holden  wrote:
>
>
>
> > Shah Sultan Alam wrote:
> > > Hi Group,
> > > I have file with contents retrieved from mysql DB.
> > > which has a time field with type defined bigint(20)
> > > I want to parse that field into timestamp format(-MM-DD HH:MM:SS
> > > GMT) using python code.
> > > The value I found for that field is 212099016004150509
> > > Give me sample code that does the conversion.
>
> > Please?
>
> > Perhaps you could tell us what date and time 212099016004150509 is
> > supposed to represent? The classic format is "seconds since the Unix
> > epoch" but that isn't what this is:
>
> > >>> time.localtime(212099016004150509)
>
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > ValueError: timestamp out of range for platform time_t
>
> > Neither does it appear to be a MySQL TIME field, since the maximum value
> > for that would appear to be
>
> > >>> ((838*60)+59)*60+59
>
> > 3020399
>
> > So, just what is this field? What do the values mean?
>
> > regards
> >  Steve
> > --
> > Steve Holden        +1 571 484 6266   +1 800 494 3119
> > Holden Web LLC              http://www.holdenweb.com/
>
> Bit hard to guess without the actual date to compare to... and I'm a
> bit busy, but thought I'd throw this in the pool: I'm guessing it's a
> MySQL database that's had data put into it via a .NET application
> using the .NET DateTime (so a 20 byte int sounds about right IIRC),
> which is based on the number of ticks since Jan 1, 1 I think that
> should end up around 2[18ish digits here...]...

Mmmm ... I thought it might be the MS format that's ticks since
1600-01-01T00-00-00 (proleptic Gregorian calendar) where ticks happen
10,000,000 times per second, but:

>>> x = 212099016004150509
>>> seconds = x / 1000.0
>>> seconds
21209901600.415051
>>> days = seconds / 60. / 60. / 24.
>>> days
245484.97222702604
>>> years_approx = days / 365.25
>>> years_approx
672.10122444086528

which would make it in the year 2272.

Perhaps the OP could tell us what are the maximum and minimum non-zero
non-null values he can find, and what years those might belong to.
Also (very important) he might assure us that he is copying/pasting
those large numbers, not retyp[o]ing them.


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


Re: Addition of multiprocessing ill-advised? (was: Python 3.0.1)

2009-01-28 Thread James Mills
Jesse: Can I mail you off-list regarding multiprocessing ?

cheers
James

--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list


Results of executing hyperlink in script

2009-01-28 Thread Muddy Coder
Hi Folks,

My previous post got a many helps from the people, and I tested what
they suggested. Since this topic maybe needed in future, so I drop
these lines below to help the future programmers. The methods worked
as below:

1. This method was suggested by Cameron Laird:

  os.system("start %s" % URL)

It works. But, if the URL contains character &, it will fail. For
example, if URL has only one field, such as: 
http://www.mydomain.com/ascript.cgi?user=muddy
this method works well. But, if there more than one field need to be
input, such as http://www.mydomain.com/ascript.cgi/user=muddy&password=foo,
the field password failed to reach server, and the CGI script
complained.

2. The best way is to use urllib2, suggested by Ron Barak, my code is
below:

import urllib2
source = urllib2.urlopen(URL).read()
print source

It successfully triggered CGI script, and also got feedback from
server. It works very well!

My thanks go to all the helpers!

Muddy Coder

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


Re: writing large dictionaries to file using cPickle

2009-01-28 Thread perfreem
On Jan 28, 5:14 pm, John Machin  wrote:
> On Jan 29, 3:13 am, perfr...@gmail.com wrote:
>
>
>
> > hello all,
>
> > i have a large dictionary which contains about 10 keys, each key has a
> > value which is a list containing about 1 to 5 million (small)
> > dictionaries. for example,
>
> > mydict = {key1: [{'a': 1, 'b': 2, 'c': 'hello'}, {'d', 3, 'e': 4, 'f':
> > 'world'}, ...],
> >                 key2: [...]}
>
> > in total there are about 10 to 15 million lists if we concatenate
> > together all the values of every key in 'mydict'. mydict is a
> > structure that represents data in a very large file (about 800
> > megabytes).
>
> > what is the fastest way to pickle 'mydict' into a file? right now i am
> > experiencing a lot of difficulties with cPickle when using it like
> > this:
>
> > from cPickle import pickle
> > pfile = open(my_file, 'w')
> > pickle.dump(mydict, pfile)
> > pfile.close()
>
> > this creates extremely large files (~ 300 MB) though it does so
> > *extremely* slowly. it writes about 1 megabyte per 5 or 10 seconds and
> > it gets slower and slower. it takes almost an hour if not more to
> > write this pickle object to file.
>
> > is there any way to speed this up? i dont mind the large file... after
> > all the text file with the data used to make the dictionary was larger
> > (~ 800 MB) than the file it eventually creates, which is 300 MB.  but
> > i do care about speed...
>
> > i have tried optimizing this by using this:
>
> > s = pickle.dumps(mydict, 2)
> > pfile.write(s)
>
> > but this takes just as long... any ideas ? is there a different module
> > i could use that's more suitable for large dictionaries ?
> > thank you very much.
>
> Pardon me if I'm asking the "bleedin' obvious", but have you checked
> how much virtual memory this is taking up compared to how much real
> memory you have? If the slowness is due to pagefile I/O, consider
> doing "about 10" separate pickles (one for each key in your top-level
> dictionary).

the slowness is due to CPU when i profile my program using the unix
program 'top'... i think all the work is in the file I/O. the machine
i am using several GB of ram and ram memory is not heavily taxed at
all. do you know how file I/O can be sped up?

in reply to the other poster: i thought 'shelve' simply calls pickle.
if thats the case, it wouldnt be any faster, right ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: what's the point of rpython?

2009-01-28 Thread Mike
On Jan 17, 5:55 pm, "Brendan Miller"  wrote:
> The python devs seem to
> consider the GIL a non-issue, though they may change their mind in 3
> years when we all have 32 core desktops,

For what it's worth, I am currently using Python to perform a
scientific computation on 1400+ cores, and it seems to work fairly
well.  (http://greylag.org/ if you're curious.)

There are a number of things that annoy me about Python (even though
it's my favorite everyday language), but the GIL isn't among them.

The rare cases where the GIL is truly a problem can be balanced
against the large majority where threading is simply inappropriate
anyway.  That the latter might help compulsive threaders kick their
habit (or at least head for more convoluted horizons) might be
considered a virtue.

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


Re: Dynamic methods and lambda functions

2009-01-28 Thread Gabriel Genellina
En Wed, 28 Jan 2009 16:05:39 -0200, coutinhoti...@gmail.com  
 escribió:



  I had the same problem myself.
  Mark's detailed explanation really helped me understand.

  I ended up doing something like:


The code doesn't work as-is, could you please post a working version? Just  
for the record, so people reading this thread later don't get confused.


--
Gabriel Genellina

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


Re: dicts,instances,containers, slotted instances, et cetera.

2009-01-28 Thread Diez B. Roggisch

ocsch...@gmail.com schrieb:

Hi, all.

I have an application that that creates, manipulates, and finally
archives on disk 10^6 instances of an object that in CS/DB terms is
best described as a relation.

It has 8 members, all of them common Python datatypes. 6 of these are
set once and then not modified. 2 are modified around 4 times before
the instance's archving. Large collections (of small lists) of these
objects are created, iterated through, and sorted using any and all of
the 8 members as sorting keys.

It neither has nor needs custom methods.

I used a simple dictionary to create the application prototype. Now I
need to speed things up.
I first tried changing to a new style class, with __slots__, __init__,
__getstate__& __setstate__ (for pickling) and was shocked to see
things SLOW down over dictionaries.

So of these options, where should I go first to satisfy my need for
speed?

0. Back to dict
1. old style class
2. new style class
3. new style class, with __slots__, with or without some nuance I'm
missing.
4. tuple, with constants to mark the indices
5. namedTuple
6. other...


Use a database? Or *maybe* a C-extension wrapped by ctypes.

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


Re: Python 3.0, 'Hello' < 42

2009-01-28 Thread Terry Reedy

Martin v. Löwis wrote:

But the document also mentions that the result is not strictly
"undefined" but "reproducable undetermined".


What specific document are you looking at, and where specifically
does it say that? I can't believe that the quotation marks indicate
an actual quote, in particular because "reproducible" is misspelled.


I believe there was something like that in the 2.x docs but nothing in 
the Expressions / Comparisons section of 3.0.


In any case, I can't find anything like that in the 3.0 changes
document, and, given that the comparison *does* give an exception,
any statement that the result is undetermined would be false.


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


Re: writing large dictionaries to file using cPickle

2009-01-28 Thread John Machin
On Jan 29, 3:13 am, perfr...@gmail.com wrote:
> hello all,
>
> i have a large dictionary which contains about 10 keys, each key has a
> value which is a list containing about 1 to 5 million (small)
> dictionaries. for example,
>
> mydict = {key1: [{'a': 1, 'b': 2, 'c': 'hello'}, {'d', 3, 'e': 4, 'f':
> 'world'}, ...],
>                 key2: [...]}
>
> in total there are about 10 to 15 million lists if we concatenate
> together all the values of every key in 'mydict'. mydict is a
> structure that represents data in a very large file (about 800
> megabytes).
>
> what is the fastest way to pickle 'mydict' into a file? right now i am
> experiencing a lot of difficulties with cPickle when using it like
> this:
>
> from cPickle import pickle
> pfile = open(my_file, 'w')
> pickle.dump(mydict, pfile)
> pfile.close()
>
> this creates extremely large files (~ 300 MB) though it does so
> *extremely* slowly. it writes about 1 megabyte per 5 or 10 seconds and
> it gets slower and slower. it takes almost an hour if not more to
> write this pickle object to file.
>
> is there any way to speed this up? i dont mind the large file... after
> all the text file with the data used to make the dictionary was larger
> (~ 800 MB) than the file it eventually creates, which is 300 MB.  but
> i do care about speed...
>
> i have tried optimizing this by using this:
>
> s = pickle.dumps(mydict, 2)
> pfile.write(s)
>
> but this takes just as long... any ideas ? is there a different module
> i could use that's more suitable for large dictionaries ?
> thank you very much.

Pardon me if I'm asking the "bleedin' obvious", but have you checked
how much virtual memory this is taking up compared to how much real
memory you have? If the slowness is due to pagefile I/O, consider
doing "about 10" separate pickles (one for each key in your top-level
dictionary).
--
http://mail.python.org/mailman/listinfo/python-list


Re: dicts,instances,containers, slotted instances, et cetera.

2009-01-28 Thread Aaron Brady
On Jan 28, 2:38 pm, ocsch...@gmail.com wrote:
> Hi, all.
>
> I have an application that that creates, manipulates, and finally
> archives on disk 10^6 instances of an object that in CS/DB terms is
> best described as a relation.
>
> It has 8 members, all of them common Python datatypes. 6 of these are
> set once and then not modified. 2 are modified around 4 times before
> the instance's archving. Large collections (of small lists) of these
> objects are created, iterated through, and sorted using any and all of
> the 8 members as sorting keys.
>
> It neither has nor needs custom methods.
>
> I used a simple dictionary to create the application prototype. Now I
> need to speed things up.
> I first tried changing to a new style class, with __slots__, __init__,
> __getstate__& __setstate__ (for pickling) and was shocked to see
> things SLOW down over dictionaries.
>
> So of these options, where should I go first to satisfy my need for
> speed?
>
> 0. Back to dict
> 1. old style class
> 2. new style class
> 3. new style class, with __slots__, with or without some nuance I'm
> missing.
> 4. tuple, with constants to mark the indices
> 5. namedTuple
> 6. other...

Hello, quoting myself from another thread today:

There is the 'shelve' module.  You could create a shelf that tells you
the filename of the 5 other ones.  A million keys should be no
problem, I guess.  (It's standard library.)  All your keys have to be
strings, though, and all your values have to be pickleable.  If that's
a problem, yes you will need ZODB or Django (I understand), or another
relational DB.

There is currently no way to store live objects.
--
http://mail.python.org/mailman/listinfo/python-list


Re: writing large dictionaries to file using cPickle

2009-01-28 Thread Aaron Brady
On Jan 28, 10:13 am, perfr...@gmail.com wrote:
> hello all,
>
> i have a large dictionary which contains about 10 keys, each key has a
> value which is a list containing about 1 to 5 million (small)
> dictionaries. for example,
snip
> but this takes just as long... any ideas ? is there a different module
> i could use that's more suitable for large dictionaries ?
> thank you very much.

There is the 'shelve' module.  You could create a shelf that tells you
the filename of the 5 other ones.  A million keys should be no
problem, I guess.  (It's standard library.)  All your keys have to be
strings, though, and all your values have to be pickleable.  If that's
a problem, yes you will need ZODB or Django (I understand), or another
relational DB.
--
http://mail.python.org/mailman/listinfo/python-list


Re: New to python, open source Mac OS X IDE?

2009-01-28 Thread Aleksandar Radulovic
On Tue, Jan 27, 2009 at 11:06 PM, joseph.a.mar...@gmail.com
 wrote:
> I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you
> even use an IDE for Python?

I'm on a Mac, too. I don't use a full-fledged IDE for Python
development, nor I think it's
necessary.

> Any recommendations on open source Python environments?

Komodo Edit looks very professional and very usable. Other
alternatives are PyDev w/ Eclipse,
but I opted for TextMate - it has excellent features. I highly
recommend spending ~$50 on it,
it's money well spent.


-- 
a lex 13 x
http://www.a13x.info
--
http://mail.python.org/mailman/listinfo/python-list


Re: Sloooooowwwww WSGI restart

2009-01-28 Thread Aleksandar Radulovic
Hi there,

On Wed, Jan 28, 2009 at 9:35 PM, Ron Garret  wrote:
> I'm running a WSGI app under apache/mod_wsgi and I've noticed that

Off the bat, there's no reason to run an app under apache/mod_wsgi
while developing it,
ie. if u use Pylons or TurboGears, there's an easier way to serve the
app (using paster
or cherrypy).

Secondly, why are you restarting apache after code changes? In normal
circumstances,
you shouldn't have to do that.

-- 
a lex 13 x
http://www.a13x.info
--
http://mail.python.org/mailman/listinfo/python-list


Re: Sloooooowwwww WSGI restart

2009-01-28 Thread Jean-Paul Calderone

On Wed, 28 Jan 2009 13:35:56 -0800, Ron Garret  wrote:

I'm running a WSGI app under apache/mod_wsgi and I've noticed that
whenever I restart the server after making a code change it takes a very
long time (like a minute) before the script is active again.  In other
words, I do an apachectl restart, reload the page in my browser, and one
minute later it finally comes up.  During this time CPU usage is
essentially zero.  Loading all the code manually into a python
interpreter is virtually instantaneous, and all subsequence interactions
with the app are very fast.

Does anyone have any ideas what might be going on or how to debug this?


strace is nice.  It sounds like some blocking network operation.  rdns can
often cause things like this.  If you're lucky, strace will point right at
the problem.

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


Sloooooowwwww WSGI restart

2009-01-28 Thread Ron Garret
I'm running a WSGI app under apache/mod_wsgi and I've noticed that 
whenever I restart the server after making a code change it takes a very 
long time (like a minute) before the script is active again.  In other 
words, I do an apachectl restart, reload the page in my browser, and one 
minute later it finally comes up.  During this time CPU usage is 
essentially zero.  Loading all the code manually into a python 
interpreter is virtually instantaneous, and all subsequence interactions 
with the app are very fast.

Does anyone have any ideas what might be going on or how to debug this?

Thanks,
rg
--
http://mail.python.org/mailman/listinfo/python-list


Function Application is not Currying

2009-01-28 Thread Xah Lee
Function Application is not Currying

Xah Lee, 2009-01-28

In Jon Harrop's book Ocaml for Scientist at
http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html

It says:

Currying

A curried function is a function which returns a function as its
result.

LOL. That is incorrect.

Here are some examples of a function that returns a function as
result, but is not currying.

Mathematica example:

f[n_]:=Function[n^#];
f[7][2]
(* returns 49 *)

Emacs lisp example:

(defmacro f (n) (list 'lambda (list 'x) (list 'expt n 'x) ) )
(funcall (f 7) 2)

Perl example:

sub f {$n=$_[0]; sub { $n ** $_[0]} };
print &{ f(7) } (2);

Javascript example:

function f(n) {return function (x) {return Math.pow(x,n);}; }
alert (f(7) (2));

In the above, a function returns a function, and the result function
is applied to a value. They demonstrate 2 things:

* The ability of the lang to have a function that returns a
function.
* The ability to apply a value (of type function) to a value.

These, are 2 of the features that is part of often sloppily termed as
“function as first class citizens”.

However, the above are not languages that support currying, which is a
feature that Haskell & Ocaml has.

So what is Currying?

Wikipedia article Currying said it best:

In computer science, currying, invented by Moses Schönfinkel and
Gottlob Frege, and independently by Haskell Curry,[1] is the technique
of transforming a function that takes multiple arguments (or more
accurately an n-tuple as argument) in such a way that it can be called
as a chain of functions each with a single argument.

Note how it says “is the technique of ...”.

To be more concrete, in the context of a given computer language, to
say that it support curring, is to mean that the compiler understand
the concept to certain degree. More to the point, the language is
inherently able to take a function of more than one arg and
deconstruct it to several functions of single arg.

To say that function returning function is Currying, is a confusion of
fundamental concepts.

Mathematically, currying is the concept of deconstructing a function
of multiple parameters to a composition of several functions all of
arity 1.

I like Jon, because i consider majority of his argument and
perspective are more correct or sensible in his trollish spats in
newsgroup fighting with tech geekers. But he is really a asshole, and
take every chance to peddle his book. Every mother fucking
opponitunity, he injects random opinion into discussions about how
static typing or greatness of Microsoft, which paves a way for him to
post a link to his book on Ocaml/F# or “study” or “speed comparison”
of his site. He does this repeatedly and intentionally, about every
week for the past 2 or so years, and write in a way to provoke irate
responses. In the past 2 or 3 years, i have for 2 or so times without
his or anyone's solicitation, publically supported him in ugly
newsgroup fights (such as some serious sounding post that accuse him
of spamming or or some real life threats about network abuse).
However, in the past year as i have had some debates on language
issues with jon, i find Jon to be a complete asshole as far as his
newsgroup demeanor goes.

PS see also: A Mathematica Optimization Problem ( story of a thread
where Jon started a fight with me )

Perm url for this post:
• Function Application is not Currying
  http://xahlee.org/UnixResource_dir/writ/apply_func_examples.html

  Xah
∑ http://xahlee.org/

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


Re: Terminating a Python program that uses multi-process, multi-threading

2009-01-28 Thread MRAB

akineko wrote:

Hello Python experts,

I have a program that uses three processes (invoked by
multiprocessing) and several threads.
The program is terminated when ^C is typed (KeyboardInterrupt).
The main process takes the KeyboardInterrupt Exception and it orderly
shutdown the program.

It works fine in normal situation.

However, KeyboardInterrupt is not accepted when, for example, the
program is stuck somewhere due to error in network. I understand that
the KeyboardInterrupt won't be processed until the program moves out
from an atomic step in a Python program.

Probably this is partly my fault as I use some blocking statements
(without timeout) as they should not block the program in normal
situation.

As the program freezes up, I cannot do anything except killing three
processes using kill command.
So, I cannot tell which statement is actually blocking when this
occurs (and there are many suspects).

Is there any good way to deal with this kind of problem?
Killing three processes when it hangs is not a fun thing to do.

Any suggestions will be greatly appreciated.

The scripts could write to a log around where they could block (write to 
the log just before and just after), so that you can then see where they 
blocked.


A hacky way of killing the processes would be for the processes to write 
their process IDs to the log and then you can write another script which 
will parse the log to get the process IDs and then kill the processes 
with those IDs. (Left as an exercise for the reader. :-))

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


Re: Recommendation for a small web framework like Perl's CGI::Application to run as CGI?

2009-01-28 Thread excord80
On Jan 28, 3:10 pm, Fred Pacquier  wrote:
>
> That would be something close to Karrigell...

You know, I stumbled across Karrigell while looking around but was
initially uninterested because of what initially seems like a lack of
direction. That is, they tell you that you can use it any way you
like:

* python script
* K service
* html inside python
* python inside html
* cgi script

So, I wasn't sure what to make of that. However, perhaps it's a
strength... will have to look more into K.

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


date handling problem

2009-01-28 Thread S.Selvam Siva
Hi all,

I need to parse rss-feeds based on time stamp,But rss-feeds follow different
standards of date(IST,EST etc).
I dont know,how to standardize this standards.It will be helpful if you can
hint me.



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


Re: pyAA for Python2.5

2009-01-28 Thread Rob Williscroft
Kottiyath wrote in news:6a594643-f6a2-4d8d-aab3-27eb16cb2fb8
@b38g2000prf.googlegroups.com in comp.lang.python:

> 
> I have mingw32-gcc in my path. If I try that too -it fails.
> 
> C:\Documents and Settings\Guest\pyAA>python setup.py install -c
> "mingw32-gcc"
> invalid command name 'mingw32-gcc'
> 

All the examples I found via google have the tool name as "mingw32"
so try:

python setup.py install -c mingw32

or

python setup.py build --compiler=mingw32 install


The compiler that the MinGW package installs is gcc.

You shoulf be able to verify it is on your path by typing: 

gcc --help
or 
gcc --version

and see some output.


Rob.
-- 
http://www.victim-prime.dsl.pipex.com/
--
http://mail.python.org/mailman/listinfo/python-list


Terminating a Python program that uses multi-process, multi-threading

2009-01-28 Thread akineko
Hello Python experts,

I have a program that uses three processes (invoked by
multiprocessing) and several threads.
The program is terminated when ^C is typed (KeyboardInterrupt).
The main process takes the KeyboardInterrupt Exception and it orderly
shutdown the program.

It works fine in normal situation.

However, KeyboardInterrupt is not accepted when, for example, the
program is stuck somewhere due to error in network. I understand that
the KeyboardInterrupt won't be processed until the program moves out
from an atomic step in a Python program.

Probably this is partly my fault as I use some blocking statements
(without timeout) as they should not block the program in normal
situation.

As the program freezes up, I cannot do anything except killing three
processes using kill command.
So, I cannot tell which statement is actually blocking when this
occurs (and there are many suspects).

Is there any good way to deal with this kind of problem?
Killing three processes when it hangs is not a fun thing to do.

Any suggestions will be greatly appreciated.

Best regards,
Aki Niimura

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


dicts,instances,containers, slotted instances, et cetera.

2009-01-28 Thread ocschwar
Hi, all.

I have an application that that creates, manipulates, and finally
archives on disk 10^6 instances of an object that in CS/DB terms is
best described as a relation.

It has 8 members, all of them common Python datatypes. 6 of these are
set once and then not modified. 2 are modified around 4 times before
the instance's archving. Large collections (of small lists) of these
objects are created, iterated through, and sorted using any and all of
the 8 members as sorting keys.

It neither has nor needs custom methods.

I used a simple dictionary to create the application prototype. Now I
need to speed things up.
I first tried changing to a new style class, with __slots__, __init__,
__getstate__& __setstate__ (for pickling) and was shocked to see
things SLOW down over dictionaries.

So of these options, where should I go first to satisfy my need for
speed?

0. Back to dict
1. old style class
2. new style class
3. new style class, with __slots__, with or without some nuance I'm
missing.
4. tuple, with constants to mark the indices
5. namedTuple
6. other...
--
http://mail.python.org/mailman/listinfo/python-list


RE: New to python, open source Mac OS X IDE?

2009-01-28 Thread Benjamin J. Racine
I've tried Wing IDE professional, vim, textmate, and PyDev and am intrigued by 
each one for different reasons.  Whichever module browser I get more 
comfortable between Wing and PyDev/Eclipse is probably the direction I will end 
up going.  Further, if I get the Hg and SVN plugins for PyDev/Eclipse up and 
running, I think I will probably go in that direction, but will probably still 
need to use a wxPython GUI constructor like BOA or Glade.

I have vim key-bindings in all four, so at least I don't fumble over that.  I 
really haven't been able to decide yet... You could go to showmedo.com in order 
to see ipython, wing and pydev/eclipse all in action.

HTH,

Ben

-Original Message-
From: python-list-bounces+bjracine=glosten@python.org 
[mailto:python-list-bounces+bjracine=glosten@python.org] On Behalf Of 
joseph.a.mar...@gmail.com
Sent: Tuesday, January 27, 2009 4:14 PM
To: python-list@python.org
Subject: Re: New to python, open source Mac OS X IDE?

On Jan 27, 6:47 pm, André  wrote:
> On Jan 27, 7:06 pm, "joseph.a.mar...@gmail.com"
>
>  wrote:
> > Greetings! I've heard enough raving about Python, I'm going to see 
> > for myself what all the praise is for!
>
> > I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you 
> > even use an IDE for Python?
>
> If you already use netbeans, what 
> abouthttp://www.netbeans.org/features/python/
> ?
>

Wow, you guys are fast... yes, I was having trouble deciding between that 
(Netbeans), Smultron, or TextWrangler. Thanks!
--
http://mail.python.org/mailman/listinfo/python-list
--
http://mail.python.org/mailman/listinfo/python-list


Re: What is intvar? [Python Docs]

2009-01-28 Thread r
On Jan 26, 11:15 am, "W. eWatson"  wrote:
> I might be repeating myself here, but If anyone has pdf experience, and
> could provide page numbers and maybe a TOC for some of Lundh's
> contributions, that would be helpful.

Did you try this one?
http://effbot.org/tkinterbook/tkinter-index.htm

here is the older less detailed version:
http://www.pythonware.com/library/tkinter/introduction/

neither are PDF thought. But NMT has a PDF download here:
http://infohost.nmt.edu/tcc/help/pubs/tkinter/

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


Re: Recommendation for a small web framework like Perl's CGI::Application to run as CGI?

2009-01-28 Thread Fred Pacquier
excord80  said :

>> What are you looking for in your framework?
> 
> Well, let's see. I don't need a templating library, since -- as you
> pointed out -- I can just use Python's own. I don't need a db
> interface (can just make my own dbapi calls if needed). Don't need url
> mapping (can just use mod_rewrite rules in my .htaccess to point at my
> cgi scripts). Don't think I need any i80n. And I don't need an admin
> interface. ... It would seem that I don't need a whole lot at the
> moment.

That would be something close to Karrigell...
--
http://mail.python.org/mailman/listinfo/python-list


Re: small python-cgi wiki?

2009-01-28 Thread Petite Abeille


On Jan 28, 2009, at 6:02 PM, Bernard Rankin wrote:

I'm looking to set up a small private wiki, and am looking for  
recommendations.


Some sort of CGI based package that I could just untar somewhere web  
accessable via Apache would be great.


You might be interested by Nanoki, a small, simple wiki engine.

Online demo:

http://svr225.stepx.com:3388/search?q=python

http://svr225.stepx.com:3388/nanoki

One thing though... it's not Python :)

Cheers,

--
PA.
http://alt.textdrive.com/nanoki/

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


Re: Why doesn't eval of generator expression work with locals?

2009-01-28 Thread Peter Otten
Gabriel Genellina wrote:

 L = list(n for n in [globals(),locals()])
 L[0] is L[1]
> True
 L = list(n() for n in [globals,locals])
 L[0] is L[1]
> False
> 
> (I think this has to do with free variables in the "right side" (after
> the "in" keyword) of a generator expression; they appear to be evaluated
> when the expression is *defined*, not when is is *used*. By contrast, free
> variables in the "left side" appear to be evaluated when the expression is
> used.)

Indeed, the right side is evaluated in the enclosing namespace and then
passed as an argument to the genexpr:

 >>> dis.dis(compile("(x for y in z)", "nofile", "exec"))
  1   0 LOAD_CONST   0 ( at
0x2b22b2dcf828, file "nofile", line 1>)
  3 MAKE_FUNCTION0
  6 LOAD_NAME0 (z)
  9 GET_ITER
 10 CALL_FUNCTION1
 13 POP_TOP
 14 LOAD_CONST   1 (None)
 17 RETURN_VALUE


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


Re: Profiling Python Apps on Mac?

2009-01-28 Thread RGK

Philip Semanchuk wrote:


Is there any reason that this wouldn't work?

http://docs.python.org/library/hotshot.html


It suggests that it doesn't work well with threads, but as I didn't know 
about any options, it's a step forward.  Thanks for the pointer.  :)


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


Re: Why doesn't eval of generator expression work with locals?

2009-01-28 Thread Gabriel Genellina
En Wed, 28 Jan 2009 16:00:43 -0200, Scott David Daniels  
 escribió:

Gabriel Genellina wrote:
En Wed, 28 Jan 2009 01:36:57 -0200, Steve Holden   
escribió:

Gabriel Genellina wrote:
En Tue, 27 Jan 2009 22:17:16 -0200, Robert Kern  


escribió:



I *thought* I did understand this until I came to this example:

1)

id(globals()), id(locals())

(11239760, 11239760)

This is a bad test.  We know distinct objects are distinct, but:
 >>> print id(object()), id(object())
10598120 10598120

 >>> a = object(); b = object()
 >>> print id(a), id(b)
10598120 10598128

The reason is that once your created object has its id taken, you
must keep a handle on it, otherwise it may get recycled and reused.


It doesn't matter in this case, I think. globals() is always the same  
object and is alive during the whole test. So something having the same  
id() than globals() must be the very same object, and something having a  
different id() than globals() cannot be the same object.


If you like, I can rewrite the example without using id():


L = list(n for n in [globals(),locals()])
L[0] is L[1]

True

L = list(n() for n in [globals,locals])
L[0] is L[1]

False

(I *think* this has to do with free variables in the "right side" (after  
the "in" keyword) of a generator expression; they appear to be evaluated  
when the expression is *defined*, not when is is *used*. By contrast, free  
variables in the "left side" appear to be evaluated when the expression is  
used.)


--
Gabriel Genellina

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


Re: Recommendation for a small web framework like Perl's CGI::Application to run as CGI?

2009-01-28 Thread excord80
On Jan 28, 1:33 pm, Jeroen Ruigrok van der Werven  wrote:
> -On [20090128 19:01], excord80 (excor...@gmail.com) wrote:
>
> >Again, the solution must work for plain vanilla CGI. I don't have WSGI
> >available. But thank you.
>
> It works for plain CGI. I myself use it for FCGI.

Thanks, Jeroen. After looking at the Werkzeug "deploying" page, it
seems as though one is able to write a WSGI webapp and have it work
via CGI using something called wsgiref. Sounds good.

If that's correct, it would be great if there were a Werkzeug tutorial
on deploying it for use with CGI.

Will look into wsgiref and Werkzeug. Thanks!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Profiling Python Apps on Mac?

2009-01-28 Thread Philip Semanchuk


On Jan 28, 2009, at 2:14 PM, RGK wrote:

I'm writing a python app on a Mac (in Eclipse + PyDev w/ Python2.5 &  
wxPython under OSX 10.4)


As I make program architecture decisions, it would be nice to be  
able to profile the choices.  Should I add that extra thread?  Is  
this big-assed xml object I just created horribly bloated or kind of  
ordinary.


Is there anything out there I should look into to if I want to see  
how those things are affecting my app?   The closest I have is the  
widget iStat, but it's a very static low resolution view of what's  
really going on.


Is there any reason that this wouldn't work?

http://docs.python.org/library/hotshot.html
--
http://mail.python.org/mailman/listinfo/python-list


Profiling Python Apps on Mac?

2009-01-28 Thread RGK
I'm writing a python app on a Mac (in Eclipse + PyDev w/ Python2.5 & 
wxPython under OSX 10.4)


As I make program architecture decisions, it would be nice to be able to 
profile the choices.  Should I add that extra thread?  Is this big-assed 
xml object I just created horribly bloated or kind of ordinary.


Is there anything out there I should look into to if I want to see how 
those things are affecting my app?   The closest I have is the widget 
iStat, but it's a very static low resolution view of what's really going on.


Thx in advance.
Ross.
--
http://mail.python.org/mailman/listinfo/python-list


Re: self-aware list of objects able to sense constituent member alterations?

2009-01-28 Thread Reckoner
On Jan 27, 9:46 pm, Steven D'Aprano
 wrote:
> On Tue, 27 Jan 2009 13:16:36 -0800, Reckoner wrote:
> > I'm not sure this is possible, but I would like to have a list of
> > objects
>
> > A=[a,b,c,d,...,z]
>
> > where,  in the midst of a lot of processing I might do something like,
>
> > A[0].do_something_which_changes_the_properties()
>
> > which alter the properties of the object 'a'.
>
> > The trick is that I would like A to be mysteriously aware that something
> > about the  object 'a' has changed so that when I revisit A, I will know
> > that the other items in the list need to be refreshed to reflect the
> > changes in A as a result of changing 'a'.
>
> Can't be done if A is a built-in list, probably can't be done entirely
> generically, but you can probably do it in a cooperative manner.
>
> class TaintList(list):
> tainted = False
> def taint(self):
> self.tainted = True
> def untaint(self):
> self.tainted = False
>
> A = TaintList()
>
> import functools
> def taint(parent):
> def decorator(func):
> @functools.wraps(func)
> def f(*args, **kwargs):
> parent.taint()
> return func(*args, **kwargs)
> return f
> return decorator
>
> class TaintAwareThing(object):
> def __init__(self):
> self.attr = 0
> @taint(A)
> def change_attribute(self, x):
> self.attr = x
>
> >>> x = TaintAwareThing()
> >>> y = TaintAwareThing()
> >>> z = TaintAwareThing()
>
> >>> A.extend([x, y, z])
> >>> A.tainted
> False
> >>> x.change_attribute(5)
> >>> A.tainted
>
> True
>
> Here is a second approach: create a proxy class TaintThing that wraps
> whatever object you want, using delegation:
>
> class TaintThing(object):
> parent = A
> def __init__(self, obj):
> self.__dict__['_proxy'] = obj
> def __getattr__(self, attr):
> return getattr(self._proxy, attr)
> def __setattr__(self, attr, value):
> setattr(self._proxy, attr, value)
> self.parent.taint()
>
> Now change TaintList to automatically wrap anything stored in it:
>
> # untested
> class TaintList(list):
> def append(self, obj):
> list.append(self, TaintThing(obj))
> # similar for __setitem__, extend, insert
>
> --
> Steven

thanks for your reply.

For the second case where

> class TaintThing(object):
> parent = A
> def __init__(self, obj):
> self.__dict__['_proxy'] = obj
> def __getattr__(self, attr):
> return getattr(self._proxy, attr)
> def __setattr__(self, attr, value):
> setattr(self._proxy, attr, value)
> self.parent.taint()

you have told it that parent is 'A'. Shouldn't that be passed to it
somehow in the following:

> # untested
> class TaintList(list):
> def append(self, obj):
> list.append(self, TaintThing(obj))
> # similar for __setitem__, extend, insert

I apologize.  I am probably missing something.  This is getting pretty
advanced for me.

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


Re: Python 3.0, 'Hello' < 42

2009-01-28 Thread Scott David Daniels

towit...@gmail.com wrote:

Hello,

In the 3.0 changes list there is mentioned that "<"-compares are not
supported anymore if the compared types are different (except
numbers). Like
  42 < "Hello"
did return True of False depending on the implementation but is now a
TypeError.

But the document also mentions that the result is not strictly
"undefined" but "reproducable undetermined". Meaning, that on a given
machine with a given python implementation result will always be the
same. But on another machine, or with another python implementation,
it might give a different result.

My question now is, why this is? E.g, Is there an integer large enough
so that the result changes? What circumstances influence the result?


The ordering of ints and strings may vary between python builds, but
_any_ strings will have the same relationship to _any_ integers.
That is, (str(x) < int(y)) == (str(y) < int(x))  for any x and y that
don't cause exceptions.  The types are compared before the values for
sufficiently disparate types without accomodation in the comparison
methods.  This means the 2.X python series can sort more lists, but
the sort order is not a particularly useful one (except for the fact
that there is an order).

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: unable to print Unicode characters in Python 3

2009-01-28 Thread Ross Ridge
John Machin writes:
> The only font choice offered apart from "Raster Fonts" in the Command
> Prompt window's Properties box is "Lucida Console", not "Lucida Sans
> Unicode". It will let me print Cyrillic characters from a C program,
> but not Chinese. I'm off looking for how to get a better font.

Thorsten Kampe   wrote:
>I have
>[HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont]
>"00"="DejaVu Sans Mono"

As near as I can tell the DejaVu Sans Mono font doesn't include Chinese
characters.  If you want to display Chinese characters in a console window
on Windows you'll probably have change the (global) system locale to an
appropriate Chinese locale and reboot.

Note that a complete Unicode console font is essentially an impossibility,
so don't bother looking for one.  There are many characters in Unicode
that can't be reasonably mappped to a single fixed-width "console" glyph.
There are also characters in Unicode that should be represented as
single-width gylphs in Western contexts, but as double-width glyphs in
Far-Eastern contexts.

Ross Ridge

-- 
 l/  //   Ross Ridge -- The Great HTMU
[oo][oo]  rri...@csclub.uwaterloo.ca
-()-/()/  http://www.csclub.uwaterloo.ca/~rridge/ 
 db  //   
--
http://mail.python.org/mailman/listinfo/python-list


Re: Recommendation for a small web framework like Perl's CGI::Application to run as CGI?

2009-01-28 Thread Jeroen Ruigrok van der Werven
-On [20090128 19:01], excord80 (excor...@gmail.com) wrote:
>Again, the solution must work for plain vanilla CGI. I don't have WSGI
>available. But thank you.

It works for plain CGI. I myself use it for FCGI.

-- 
Jeroen Ruigrok van der Werven  / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B
Earth to earth, ashes to ashes, dust to dust...
--
http://mail.python.org/mailman/listinfo/python-list


Quickbooks

2009-01-28 Thread Stephen Chapman
Has anyone Implemented the Quickbooks  COM object in Python.  If so can 
you give me

an Idea of where to begin.
Thanks
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.0, 'Hello' < 42

2009-01-28 Thread Martin v. Löwis
> But the document also mentions that the result is not strictly
> "undefined" but "reproducable undetermined".

What specific document are you looking at, and where specifically
does it say that? I can't believe that the quotation marks indicate
an actual quote, in particular because "reproducible" is misspelled.

In any case, I can't find anything like that in the 3.0 changes
document, and, given that the comparison *does* give an exception,
any statement that the result is undetermined would be false.

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


  1   2   >