Re: No trees in the stdlib?

2009-06-28 Thread Lie Ryan
João Valverde wrote:
> alex23 wrote:
>> João Valverde  wrote:
>>  
>>> Currently I don't have a strong need for this.
>>> 
>>
>> And clearly neither has anyone else, hence the absence from the
>> stdlib. As others have pointed out, there are alternative approaches,
>> and plenty of recipes on ActiveState, which seem to have scratched
>> whatever itch there is for the data structure you're advocating.
>>   
> 
> Propose such alternative then. There are none that offer the same
> performance. At best they're workarounds.
> 
> I don't care about recipes. That's called research.
> 
> If people don't find it to be useful, that's fine. Surprising, but fine.

Python devs, based on my observation, tend to choose a data structure
based on the interface and not its implementation. Binary Sorted Tree is
an implementation, its interface can be a sorted dict (sorted key-value
mapping) or a list (not the most natural interface for a tree).

Basically, python already have all the common interfaces, i.e. list,
set, and mapping/dict.

Let's see it like this. In how many ways can a list be implemented?
- Array (python's builtin list)
- Linked List
- Binary Tree
- and the list goes on...

All of them can expose their interface as list, but only array
implementation is available as builtin.

> And I don't have a need because I'm not using Python for my project. If
> I wanted to I couldn't, without implementing myself or porting to Python
> 3 a basic computer science data structure.
> 
>> While Python's motto is "batteries included" I've always felt there
>> was an implicit "but not the kitchen sink" following it. Just because
>> something "could" be useful shouldn't be grounds for inclusion. That's
>> what pypi & the recipes are for. Ideally, little should be created
>> wholesale for the stdlib, what should be added are the existing 3rd
>> party modules that have become so ubiquitous that their presence on
>> any python platform is just expected.
>>   
> 
> Agreed.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What does Guido want in a GUI toolkit for Python?

2009-06-28 Thread Simon Forman
On Jun 27, 12:54 pm, "laplacia...@gmail.com" 
wrote:
> I just read a blog post of 
> Guido'shttp://neopythonic.blogspot.com/2009/06/ironpython-in-action-and-decl...
> and notice that he doesn't comment on what he wants in a GUI toolkit
> for Python.
>
> I sorta' wish he'd just come out and say, "This is what I think would
> be suitable for a GUI toolkit for Python: ...". That way, someone
> could then just come along and implement it. (Or maybe he's said this
> and I missed it?)
>
> So, what *does* Guido want in a GUI toolkit for Python?

FWIW, I created a simple GUI builder module I call pygoo that lets you
create Tkinter GUIs from a simple text "specification".

http://www.pygoo.com/
http://code.google.com/p/pygoo/

Warm regards,
~Simon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tokenize module

2009-06-28 Thread Tim Roberts
Jim  wrote:

>I'm trying to understand the output of the tokenize.generate_tokens()
>generator.  The token types returned seem to be more general than I'd
>expect.  For example, when fed the following line of code:
>
>def func_a():
>...
>It seems to me that the token '(' should be identified as 'LPAR' and
>')' as 'RPAR', as found in the dictionary token.tok_name.  What am I
>missing here?

Did you read the module?  Right at the top, it says:


It is designed to match the working of the Python tokenizer exactly, except
that it produces COMMENT tokens for comments and gives type OP for all
operators

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What does Guido want in a GUI toolkit for Python?

2009-06-28 Thread Nobody
On Sat, 27 Jun 2009 17:17:22 -0700, Dennis Lee Bieber wrote:

>> His concern really isn't what is in the toolkit, but what isn't.
>> It must not require lots of lines of code to produce a simple
>> GUI, it must not require specification of absolute coordinates,
>> ... - you should be able to continue the list yourself.
>>
> 
>   Sounds a bit like a return of DECWindows on Xt... Which had a
> textual design language to define the widgets in use, names for
> callbacks, etc. and only required the application to load the file and
> map the callbacks to actual code...
> 
>   You could change the layout without touching the application code
> (as long as you weren't adding new widgets)

Xt itself provides some of that, the rest can be had through UIL (which is
part of Motif). GTK+ can do much of this using Glade.

The concept of separating code from data is sensible enough, and mirrors
the concept of stylesheets in HTML. It shouldn't be necessary to specify
size, position, labels, colours and the like via code. Code only needs to
be able to get a handle on a specific widget so that it can read and write
its state, dynamically register callbacks, etc.

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


Re: What does Guido want in a GUI toolkit for Python?

2009-06-28 Thread Stef Mientki

Martin v. Löwis wrote:

I sorta' wish he'd just come out and say, "This is what I think would
be suitable for a GUI toolkit for Python: ...".



He is not in the business of designing GUI toolkits, but in the business
of designing programming languages. So he abstains from specifying
(or even recommending) a GUI library.

What he makes clear is the point that Terry cites: no matter what the
GUI toolkit is or what features it has - it should be simple to create
GUIs, as simple as creating HTML.

  

So, what *does* Guido want in a GUI toolkit for Python?



His concern really isn't what is in the toolkit, but what isn't.
It must not require lots of lines of code to produce a simple
GUI, it must not require specification of absolute coordinates,
... - you should be able to continue the list yourself.

  

Gui_support obey the above 2 rules,
so I guess, 'm on the right way with GUI_support
 http://mientki.ruhosting.nl/data_www/pylab_works/pw_gui_support.html
What are the other rules ?

cheers,
Stef

Regards,
Martin
  


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


Advantages of Python (for web/desktop apps)?

2009-06-28 Thread iceangel89

i am mainly a PHP (mainly using Zend Framework MVC now) Web Developer. used
.NET (VB & C#) for Desktop apps. i nv used Python and am looking at Python
now (for desktop apps since its open source and just want to try what it
offers, but will like to know what good it has for web development also)

i wonder what do users of Python say? 

somethings i am curious abt (that came to my mind) now are:
- performance
- ide to use? 
- how do i design GUI for windows app?  
-- 
View this message in context: 
http://www.nabble.com/Advantages-of-Python-%28for-web-desktop-apps%29--tp24239603p24239603.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: The Python Way for module configuration?

2009-06-28 Thread Ben Finney
Steven D'Aprano  writes:

> On Sun, 28 Jun 2009 13:28:31 +1000, Ben Finney wrote:
> 
> > (Even if you don't want to receive email, could you please give your
> > actual name in the ‘From’ field instead of just initials? It makes
> > conversation less confusing.)
> 
> Some people prefer to be known by their initials.

Some people prefer to spend their volunteer time conversing with people
who don't just use initials or pseudonyms.

> There's nothing confusing about addressing somebody by their initials.

I find it much less confusing to converse with someone if I can keep
straight who they are, and names work better than initials for that
purpose.

-- 
 \   “Whenever you read a good book, it's like the author is right |
  `\   there, in the room talking to you, which is why I don't like to |
_o__)   read good books.” —Jack Handey |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fast Dictionary Access

2009-06-28 Thread Ben Finney
Steven D'Aprano  writes:

> On Sat, 27 Jun 2009 09:41:13 -0700, Rachel P wrote:
> [...]
> > Raymond
> 
> Raymond, does Rachel know you're using her gmail account?

It's a good thing names are being used here, rather than just initials.

-- 
 \“No one ever went broke underestimating the taste of the |
  `\   American public.” —Henry L. Mencken |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Nobody
On Sat, 27 Jun 2009 16:12:10 -0500, Benjamin Peterson wrote:

> Python 3.1 focuses on the stabilization and optimization of the features and
> changes that Python 3.0 introduced.  For example, the new I/O system has been
> rewritten in C for speed.  File system APIs that use unicode strings now
> handle paths with undecodable bytes in them.

That's a significant improvement. It still decodes os.environ and sys.argv
before you have a chance to call sys.setfilesystemencoding(), but it
appears to be recoverable (with some effort; I can't find any way to re-do
the encoding without manually replacing the surrogates).

However, sys.std{in,out,err} are still created as text streams, and AFAICT
there's nothing you can do about this from within your code.

All in all, Python 3.x still has a long way to go before it will be
suitable for real-world use.

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


Re: The Python Way for module configuration?

2009-06-28 Thread Hendrik van Rooyen
 "kj"  wrote:

> I want to write a module that serves as a Python front-end to a
> database.  This database can be either in the form of tab-delimited
> flat files, XML files, or a PostgreSQL server.  The module is meant
> to hide these database implementation details from its users.
> 
> But, minimally, the module needs to have some configuration details
> to know where to get the data.  There are many ways to provide this
> configuration data to the module, but I would like to know what's
> considered "best practice" for this type of problem in the Python
> world.
> 
> Ideally, I'm looking for a system that is unobtrusive under normal
> operations, but easy to override during testing and debugging.

To pass in configuration to a module, you have basically two
choices:

- Use the command line and sys.argv
- Put the stuff in a file of some sort.

I would not recommend the first option, because it ultimately
ends up as an abomination such as we can see with gcc, where
it has spawned over elaborate systems of makefiles to tell
it how to do something - so we are back at a file, in any event.

So the questions become - how do you organise the file,
and how do you get hold of the stuff in it.

You have been pointed to configparser, and others.

You can also do a simple thing, as a module gets executed
upon import.  If your parameters are simple, this may be the
easiest way of doing it, namely to just write the bunch of
them down, all in a configuration.py file, like this:

P1 = 7
P2 = 42
alloweds = [john,mary,sally]

Then where you want to use them, you do the following:

import configuration as cf

if cf.P1 > 3:
   do something

if suspect in cf.alloweds:
   let user in
else:
   print "Go away you fiend from the nether regions"
   sys.stdout.flush()
   sys.exit()

if not cf.P2 == 42:
print "The end of the universe has arrived - hide!"
while True:
pass

Do not forget that you can put a dictionary
there to handle more complex stuff.

You can also get fancy and put whole classes
of data into such a file.  In what I do, I have
never felt the need for that.

You get the drift (I hope)

- Hendrik



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


Re: Beginning with Python; the right choice?

2009-06-28 Thread Simon Brunning
2009/6/27 sato.ph...@gmail.com :
> Thank you for all of the links and advice.
>
> What do I want to learn Python for?
>
> Again, pardon me for my lack of relevant information.  I am also a
> journalist (an out of work one at the moment, like so many others) and
> I feel that learning python could be useful for computer assisted
> reporting, that is, utilizing databases, creating interactive maps and
> the like.
>
> http://chicago.everyblock.com/crime/

That's a Python site!

As a journalist, you might also be interested in

- The Guardian, a UK national newspaper, quickly wrote and deployed a
Python application to allow their readers to cooperate in the massive
manual task of analysing MPs' expenses receipts, looking for
ill-doing.

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


Re: Dictionary self lookup

2009-06-28 Thread Carl Banks
On Jun 27, 4:33 am, Jure Erznožnik  wrote:
> When you write code like
> config = {"home" : "/home/test"}
> config["user1"] = config["home"] + "/user1"
>
> config["user1"] isn't stored in memory as config["home"] + "/user1",
> but as a concatenated string ("/home/test/user1"), composed of both
> those strings. The reference to original composing strings is lost at
> the moment the expression itself is evaluated to be inserted into the
> dict.
> There's no compiler / interpreter that would do this any other way. At
> least not that I know of.

It's called Lazy Evaluation and there are a bunch of tools that do it
implicitly and automatically.  Off hand I can think of make and
Mathematica.  I know there are some functional programming languages
that do it as well.

Also there are languages like Lisp that have strong syntactic support
for lazy evaluation although it's not done implicitly.

Not Python, though.


> So best suggestion would be to simply do an object that would parse
> strings before returning them. In the string itself, you can have
> special blocks that tell your parser that they are references to other
> objects.

[snip example]

> But you sure better not expect this to be included in language syntax.
> It's a pretty special case.

That is a very good suggestion that might be a better solution to the
OP's problem.

You are right that is would require a bit of work.  Python does have
string interpolation methods that can do keyword-based substitution,
but they don't work recursively, and it's not straightforward to get
it to work recursively.


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


Re: Fast Dictionary Access

2009-06-28 Thread Carl Banks
On Jun 27, 4:40 am, Duncan Booth  wrote:
> Thomas Lehmann  wrote:
> > Hi!
>
> > In C++, programming STL you will use the insert method which always
> > provides a position and a flag which indicates whether the position
> > results from a new insertion or an exisiting element. Idea is to have
> > one search only.
>
> >
> > if  data.has_key(key):
> >    value = data[key]
> >
>
> > But this does mean (does it?) that the dictionary is searched two
> > times! If so, can somebody show me how to do this in one step?
>
> That code actually does 3 dictionary lookups and creates a temporary
> object: the first lookup is to find the 'has_key' method, then it has to
> bind the method to data which involves creating a 'built-in method' object
> and then it calls it. Only then do you get the two lookups you expected.
>
> Replacing your code with:
>
>    if key in data: value = data[key]
>
> reduces the overhead to two dictionary lookups, no temporary objects or
> function calls.
>
> The suggested alternative:
>
>    value = data.get(key, None)
>
> also has two dictionary lookups: one to find the 'get' method and one to
> find the key, but as in the first case it also has the overhead of binding
> the method and then calling it.
>
> In other words the get method is often the clearest (and therefore best)
> way to write the code, but if performance matters do a check using the 'in'
> operator (or if you know the key lookup will fail only very rarely consider
> using try..except).

It's not that simple.  Attribute lookups are fast because the keys are
interned strings.  However, the key lookup in the data object might be
an object where hash and compare operations are much slower.

So it's not valid in general to equate the two lookups.  Unless you
know that your dict keys are going to be really fast like interned
strings it makes sense to minimize dict lookups.


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


Re: Measuring Fractal Dimension ?

2009-06-28 Thread Steven D'Aprano
On Sat, 27 Jun 2009 23:52:02 -0700, Paul Rubin wrote:

> Steven D'Aprano  writes:
>> Depends on how you define "discontinuous".
> 
> The mathematical way, of course.  For any epsilon > 0, etc.

I thought we were talking about discontinuities in *nature*, not in 
mathematics. There's no "of course" about it.


>> Catastrophe theory is full of discontinuous changes in state. Animal
>> (by which I include human) behaviour often displays discontinuous
>> changes.  So does chemistry: one minute the grenade is sitting there,
>> stable as can be, the next it's an expanding cloud of gas and metal
>> fragments.
> 
> If that transition from grenade to gas cloud takes a minute (or even a
> femtosecond), it's not a mathematical discontinuity.  

In mathematics, you can cut up a pea and reassemble it into a solid 
sphere the size of the Earth. Try doing that with a real pea.

Mathematics is an abstraction. It doesn't necessarily correspond to 
reality. Assuming that reality "really is" the mathematical abstraction 
underneath is just an assumption, and not one supported by any evidence.


> The other examples work out about the same way.


Quantum phenomenon are actual mathematical discontinuities, or at least 
they can be, e.g. electron levels in an atom. Even when they are 
continuous, they're continuous because they consist of an infinity of 
discontinuous levels infinitesimally far apart.




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


Re: to use unicode strings only

2009-06-28 Thread Gaudha
On Jun 27, 9:44 pm, Benjamin Peterson  wrote:
> Gaudha  gmail.com> writes:
>
> > And Peter, I tried importing the __future__ module. It's also not
> > working...
>
> How so?

Sorry guys, __future__ module is working excellent :-). I had some bad
coding somewhere else, just fixed it. Anyway, thank you for all...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Python Way for module configuration?

2009-06-28 Thread Steven D'Aprano
On Sun, 28 Jun 2009 18:39:28 +1000, Ben Finney wrote:

> Steven D'Aprano  writes:
> 
>> On Sun, 28 Jun 2009 13:28:31 +1000, Ben Finney wrote:
>> 
>> > (Even if you don't want to receive email, could you please give your
>> > actual name in the ‘From’ field instead of just initials? It makes
>> > conversation less confusing.)
>> 
>> Some people prefer to be known by their initials.
> 
> Some people prefer to spend their volunteer time conversing with people
> who don't just use initials or pseudonyms.

And some people refuse to use words with the letter "E" in them.

Just out of curiosity, how are you supposed to recognise people who are 
using pseudonyms? For all we know, "Steven D'Aprano" might be a pseudonym 
-- you haven't seen my birth certificate.

I noticed that you ignored my comment about people's whose legal names 
are initials.


>> There's nothing confusing about addressing somebody by their initials.
> 
> I find it much less confusing to converse with someone if I can keep
> straight who they are, and names work better than initials for that
> purpose.

Really? Can you cope with two-letter names like Jo, Li, Ed, Cy, or even 
Wm (a variant of William), or are you about to start insisting that 
people choose three-letter names?

If you can cope with Al, Di or Mo, then what's the difference between 
those names and two-letter initials?


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


Re: Fast Dictionary Access

2009-06-28 Thread Steven D'Aprano
On Sun, 28 Jun 2009 02:57:50 -0700, Carl Banks wrote:

> So it's not valid in general to equate the two lookups.  Unless you know
> that your dict keys are going to be really fast like interned strings it
> makes sense to minimize dict lookups.

Or to stop making assumptions about what's fast and what's not fast, and 
actually profile the code and see where the hold-ups are.


"Dear Pythonistas, I have a program that runs for six hours performing 
some wickedly complicated calculations on data extracted from a dict. The 
dictionary lookups take five and a half seconds, how can I speed them up?"


*wink*



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


Re: Measuring Fractal Dimension ?

2009-06-28 Thread Paul Rubin
Steven D'Aprano  writes:
> I thought we were talking about discontinuities in *nature*, not in 
> mathematics. There's no "of course" about it.

IIRC we were talking about fractals, which are a topic in mathematics.
This led to some discussion of mathematical continuity, and the claim
that mathematical discontinuity doesn't appear to occur in nature (and
according to some, it shouldn't occur in mathematics either).

> In mathematics, you can cut up a pea and reassemble it into a solid 
> sphere the size of the Earth. Try doing that with a real pea.

That's another example of a mathematical phenomenon that doesn't occur
in nature.  What are you getting at?

> Quantum phenomenon are actual mathematical discontinuities, or at
> least they can be, e.g. electron levels in an atom.

I'm sure you know more physics than I do, but I was always taught
that observables (like electron levels) were eigenvalues of underlying
continuous operators.  That the eigenvalues are discrete just means
some continuous function has multiple roots that are discrete.

There is a theorem (I don't know the proof or even the precise
statement) that if quantum mechanics has the slightest amount of
linearity, then it's possible in principle to solve NP-hard problems
in polynomial time with quantum computers.  So I think it is treated
as perfectly linear.
-- 
http://mail.python.org/mailman/listinfo/python-list


PyQT QWebView Local swf file not loading

2009-06-28 Thread sgperone
Just downloaded the pyQT 4.5 for python 2.6 and noticed this strange
behaviour:

inside a widget i have this code:

self.view = QWebView(self)
self.view.settings().setAttribute(QWebSettings.PluginsEnabled,True)

that's i'm creating a QWebView instance with PluginsEnabled flag on.

next lines are:

Case 1
===
f = QtCore.QUrl("http://www.example.com/myflashfile.swf";)
print f
self.view.load(f)

in this case f == True and the swf file is showing correctly inside
the widget

Case 2
===
f = QtCore.QUrl.fromLocalFile(r"C:\myflashfile.swf")
print f
self.view.load(f)

in this case f == False and no swf clip showed up.

Really weird... if I use a local html file with code to embed the
local swf file everything is working.

So, it seems that:

It is impossible to load a local swf file directly into QWebView
without a "wrapper" html code.

Anyone experienced the same issue ?

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


Re: PyQT QWebView Local swf file not loading

2009-06-28 Thread sgperone
On 28 Giu, 13:05, sgperone  wrote:
> Just downloaded the pyQT 4.5 for python 2.6 and noticed this strange
> behaviour:
>
> inside a widget i have this code:
>
> self.view = QWebView(self)
> self.view.settings().setAttribute(QWebSettings.PluginsEnabled,True)
>
> that's i'm creating a QWebView instance with PluginsEnabled flag on.
>
> next lines are:
>
> Case 1
> ===
> f = QtCore.QUrl("http://www.example.com/myflashfile.swf";)
> print f
> self.view.load(f)
>
> in this case f == True and the swf file is showing correctly inside
> the widget
>
> Case 2
> ===
> f = QtCore.QUrl.fromLocalFile(r"C:\myflashfile.swf")
> print f
Correction:
===

it's not "f" that is True or False, but :

inside code i have:

self.connect(self.view,QtCore.SIGNAL("loadFinished
(bool)"),self.loadFinished)

and

def loadFinished(self,bool):
  print bool


> self.view.load(f)
>
> in this case f == False and no swf clip showed up.
>
> Really weird... if I use a local html file with code to embed the
> local swf file everything is working.
>
> So, it seems that:
>
> It is impossible to load a local swf file directly into QWebView
> without a "wrapper" html code.
>
> Anyone experienced the same issue ?
>
> Thanks

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


Python and journalism (was Re: Beginning with Python; the right choice?)

2009-06-28 Thread Aahz
In article ,
sato.ph...@gmail.com  wrote:
>
>What do I want to learn Python for?
>
>Again, pardon me for my lack of relevant information.  I am also a
>journalist (an out of work one at the moment, like so many others) and
>I feel that learning python could be useful for computer assisted
>reporting, that is, utilizing databases, creating interactive maps and
>the like.

You're absolutely right!  You're also not the first person to have that
realization:

http://www.time.com/time/business/article/0,8599,1902202,00.html
http://www.ojr.org/ojr/stories/060605niles/
http://www.medill.northwestern.edu/admissions/page.aspx?id=58645

(Probably you already knew this, but I'm posting for other people.)
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Martin v. Löwis
> That's a significant improvement. It still decodes os.environ and sys.argv
> before you have a chance to call sys.setfilesystemencoding(), but it
> appears to be recoverable (with some effort; I can't find any way to re-do
> the encoding without manually replacing the surrogates).

See PEP 383.

> However, sys.std{in,out,err} are still created as text streams, and AFAICT
> there's nothing you can do about this from within your code.

That's intentional, and not going to change. You can access the
underlying byte streams if you want to, as you could already in 3.0.

Regards,
Martin

P.S. Please identify yourself on this newsgroup.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: encoding problem

2009-06-28 Thread Martin v. Löwis
> That is the reason why we have to explicitly declare a encoding as
> long as we have non-ASCII in source.

True - but it doesn't have to be the "correct" encoding. If you
declared your source as latin-1, the effect is the same on byte string
literals, but not on Unicode literals.

In that sense, the encoding declaration only "matters" for Unicode
literals (of course, it also matters for source editors, and in a few
other places).

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


Re: Advantages of Python (for web/desktop apps)?

2009-06-28 Thread Tim Chase

iceangel89 wrote:

i am mainly a PHP (mainly using Zend Framework MVC now) Web Developer. used
.NET (VB & C#) for Desktop apps. i nv used Python and am looking at Python
now (for desktop apps since its open source and just want to try what it
offers, but will like to know what good it has for web development also)

somethings i am curious abt (that came to my mind) now are:


gvn ur pnchnt 4 illgble shrthnd, u mgt prefr perl ovr pythn.  or 
prhps u wnt asmbly lang.  XOR EAX, EAX; MOV [EAX], EAX



- performance


More than sufficient for my needs (scripting, web apps, most GUI 
apps) -- you can always drop to optimized C/C++ functions/modules 
if needed or use custom modules like numpy/numeric/etc for 
processor-intense work.


- ide to use? 


http://lmgtfy.com/?q=python+ide

I use vim.  Others use emacs.  Some use Eclipse.  Some use 
WingIDE.  Etc, etc, etc.  Try 'em each and see what you like


- how do i design GUI for windows app?  


http://lmgtfy.com/?q=python+gui

Lots of options -- choose the one you like.

-tkc




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


Running a script from a windows right click menu..?

2009-06-28 Thread Nuff Nuff
I wrote a little script that affects a bunch of files in the folder
that it is run in.

Now what I want to do is to make it run from the right click menu but
I don't know how.

Would you give me an example script that will simply print the
woriking directory,  and show me how to add that to the right click
menu in windows explorer?

TIA

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


Re: pep 8 constants

2009-06-28 Thread Eric S. Johansson
Bruno Desthuilliers wrote:
> Brendan Miller a écrit :
>> PEP 8 doesn't mention anything about using all caps to indicate a
>> constant.
>>
>> Is all caps meaning "don't reassign this var" a strong enough
>> convention to not be considered violating good python style? I see a
>> lot of people using it, but I also see a lot of people writing
>> non-pythonic code... so I thought I'd see what the consensus is.
> 
> Most - if not all - of the python code I've seen so far used this
> convention, and I always used (and respected) it myself.

I reject this convention because any form of caps significantly increases vocal
load for disabled programmers using speech recognition through extra utterances,
and degraded recognition.

In my experience, language conventions like this come about because most geeks
generally don't think about disabled programmers and the effect that language
changes will have on them.  I deal by trying to build my accessibility tools as
best I can but handling stuff like pep 8 is hard because it requires a smart
environment that know the meanings of every class, method. or variable so it can
lead the grammar in the right direction. ThenWenUHve names like this.  Cr** in a
stick.  you might as well take a gun to my wrists because that is how much pain
I will be in typing them.  again need *good* editor support for English to name
translation.

so I reject pep 8 because I have no voice safe alternative
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Buffer pair for lexical analysis of raw binary data

2009-06-28 Thread Aahz
In article <0qec45lho8lkng4n20sb1ad4eguat67...@4ax.com>,
Angus Rodgers   wrote:
>
>Partly as an educational exercise, and partly for its practical
>benefit, I'm trying to pick up a programming project from where
>I left off in 2001.  It implemented in slightly generalised form
>the "buffer pair" scheme for lexical analysis described on pp.
>88--92 of Aho et al., /Compilers: Principles, Techniques and 
>Tools/ (1986). (I'm afraid I don't have a page reference for the
>2007 second edition.  Presumably it's also in Knuth somewhere.)
>
>  [...]
>
>Does some Python library already provide some functionality like
>this?  (It's enough to do it with nblocks = 2, as in Aho et al.)

Not AFAIK, but there may well be something in the recipes or PyPI; have
you tried searching them?

>If not, is this a reasonable thing to try to program in Python?

Definitely!  It should be lots easier to program this with Python.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


creating garbage collectable objects (caching objects)

2009-06-28 Thread News123
Hi.

I started playing with PIL.

I'm performing operations on multiple images and would like compromise
between speed and memory requirement.

The fast approach would load all images upfront and create then multiple
result files. The problem is, that I do not have enough memory to load
all files.

The slow approach is to load each potential source file only when it is
needed and to release it immediately after (leaving it up to the gc to
free memory when needed)



The question, that I have is whether there is any way to tell python,
that certain objects could be garbage collected if needed and ask python
at a later time whether the object has been collected so far (image has
to be reloaded) or not (image would not have to be reloaded)


# Fastest approach:
imgs = {}
for fname in all_image_files:
imgs[fname] = Image.open(fname)
for creation_rule in all_creation_rules():
img = Image.new(...)
for img_file in creation_rule.input_files():
img = do_somethingwith(img,imgs[img_file])
img.save()


# Slowest approach:
for creation_rule in all_creation_rules():
img = Image.new(...)
for img_file in creation_rule.input_files():
src_img = Image.open(img_file)
img = do_somethingwith(img,src_img)
img.save()



# What I'd like to do is something like:
imgs = GarbageCollectable_dict()
for creation_rule in all_creation_rules():
img = Image.new(...)
for img_file in creation_rule.input_files():
if src_img in imgs: # if 'm lucke the object is still there
src_img = imgs[img_file]
else:
src_img = Image.open(img_file)
img = do_somethingwith(img,src_img)
img.save()



Is this possible?

Thaks in advance for an answer or any other ideas of
how I could do smart caching without hogging all the system's
memory





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


Re: Advantages of Python (for web/desktop apps)?

2009-06-28 Thread Aahz
In article ,
Tim Chase   wrote:
>
>> - how do i design GUI for windows app?  
>
>http://lmgtfy.com/?q=python+gui

This is the first time I've tried LMGTFY, and it seems to be a piece of
trash that requires JavaScript.  I suggest that lmgtfy.com not be
considered a standard part of the Python community.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What does Guido want in a GUI toolkit for Python?

2009-06-28 Thread John Fabiani
Casey Hawthorne wrote:

>>So, what *does* Guido want in a GUI toolkit for Python?
> 
> I saw a talk by a school teacher on pyFLTK: GUI programming made easy.
> 
> On another note: I#: Groovy makes it easy to tie into the Java Swing
> GUI, so if Python could do that, with the added complication being the
> user would need a JVM.
> 
> --
> Regards,
> Casey

Dabo makes it transparent when it come to tying the data to the widget. 
Based on the wxPython.  So it meets Guido's requirements.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Benjamin Peterson
Nobody  nowhere.com> writes:
> All in all, Python 3.x still has a long way to go before it will be
> suitable for real-world use.

Such as?




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


Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Scott David Daniels

Nobody wrote:

On Sat, 27 Jun 2009 16:12:10 -0500, Benjamin Peterson wrote: 

That's a significant improvement
All in all, Python 3.x still has a long way to go before it will be
suitable for real-world use.


Fortunately, I have assiduously avoided the real word, and am happy to
embrace the world from our 'bot overlords.

Congratulations on another release from the hydra-like world of
multi-head development.

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


Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Paul Moore
2009/6/28 "Martin v. Löwis" :
>> However, sys.std{in,out,err} are still created as text streams, and AFAICT
>> there's nothing you can do about this from within your code.
>
> That's intentional, and not going to change. You can access the
> underlying byte streams if you want to, as you could already in 3.0.

I had a quick look at the documentation, and couldn't see how to do
this. It's the first time I'd read the new IO module documentation, so
I probably missed something obvious. Could you explain how I get the
byte stream underlying sys.stdin? (That should give me enough to find
what I was misunderstanding in the docs).

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


Re: The Python Way for module configuration?

2009-06-28 Thread Aahz
In article <87bpo8vjjz@benfinney.id.au>,
Ben Finney   wrote:
>Steven D'Aprano  writes:
>> On Sun, 28 Jun 2009 13:28:31 +1000, Ben Finney wrote:
>>> 
>>> (Even if you don't want to receive email, could you please give your
>>> actual name in the ‘From’ field instead of just initials? It makes
>>> conversation less confusing.)
>> 
>> Some people prefer to be known by their initials.
>
>Some people prefer to spend their volunteer time conversing with people
>who don't just use initials or pseudonyms.

Bully for you!  Just don't bully people who don't follow your preferred
naming system.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Christian Heimes
Paul Moore schrieb:
> 2009/6/28 "Martin v. Löwis" :
>>> However, sys.std{in,out,err} are still created as text streams, and AFAICT
>>> there's nothing you can do about this from within your code.
>> That's intentional, and not going to change. You can access the
>> underlying byte streams if you want to, as you could already in 3.0.
> 
> I had a quick look at the documentation, and couldn't see how to do
> this. It's the first time I'd read the new IO module documentation, so
> I probably missed something obvious. Could you explain how I get the
> byte stream underlying sys.stdin? (That should give me enough to find
> what I was misunderstanding in the docs).

You've missed the most obvious place to look for the feature -- the
documentation of sys.stdin :)

http://docs.python.org/3.0/library/sys.html#sys.stdin

>>> import sys
>>> sys.stdin

>>> sys.stdin.buffer

>>> sys.stdin.read(1)

'\n'
>>> sys.stdin.buffer.read(1)

b'\n'

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


Re: Buffer pair for lexical analysis of raw binary data

2009-06-28 Thread Angus Rodgers
On 28 Jun 2009 08:00:23 -0700, a...@pythoncraft.com (Aahz) wrote:

>In article <0qec45lho8lkng4n20sb1ad4eguat67...@4ax.com>,
>Angus Rodgers   wrote:
>>
>>Partly as an educational exercise, and partly for its practical
>>benefit, I'm trying to pick up a programming project from where
>>I left off in 2001.  It implemented in slightly generalised form
>>the "buffer pair" scheme for lexical analysis described on pp.
>>88--92 of Aho et al., /Compilers: Principles, Techniques and 
>>Tools/ (1986). (I'm afraid I don't have a page reference for the
>>2007 second edition.  Presumably it's also in Knuth somewhere.)
>>
>>  [...]
>>
>>Does some Python library already provide some functionality like
>>this?  (It's enough to do it with nblocks = 2, as in Aho et al.)
>
>Not AFAIK, but there may well be something in the recipes or PyPI; have
>you tried searching them?

Searching for "buffer" at  (which I
didn't know about) gives quite a few hits (including reflex 0.1,
"A lightweight regex-based lexical scanner library").

By "recipes", do you mean
 (also new to me)?

There is certainly a lot of relevant code there (e.g. "Recipe 392150:
Buffered Stream with Multiple Forward-Only Readers"), which I can try
to learn from, even if I can't use it directly.

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


Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Piet van Oostrum
> Paul Moore  (PM) wrote:

>PM> 2009/6/28 "Martin v. Löwis" :
 However, sys.std{in,out,err} are still created as text streams, and AFAICT
 there's nothing you can do about this from within your code.
>>> 
>>> That's intentional, and not going to change. You can access the
>>> underlying byte streams if you want to, as you could already in 3.0.

>PM> I had a quick look at the documentation, and couldn't see how to do
>PM> this. It's the first time I'd read the new IO module documentation, so
>PM> I probably missed something obvious. Could you explain how I get the
>PM> byte stream underlying sys.stdin? (That should give me enough to find
>PM> what I was misunderstanding in the docs).

http://docs.python.org/3.1/library/sys.html#sys.stdin
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Paul Moore
2009/6/28 Christian Heimes :
> Paul Moore schrieb:
>> I had a quick look at the documentation, and couldn't see how to do
>> this. It's the first time I'd read the new IO module documentation, so
>> I probably missed something obvious. Could you explain how I get the
>> byte stream underlying sys.stdin? (That should give me enough to find
>> what I was misunderstanding in the docs).
>
> You've missed the most obvious place to look for the feature -- the
> documentation of sys.stdin :)
>
> http://docs.python.org/3.0/library/sys.html#sys.stdin
>
 import sys
 sys.stdin
> 
 sys.stdin.buffer
> 
 sys.stdin.read(1)
>
> '\n'
 sys.stdin.buffer.read(1)

Thanks. Like you say, the obvious place I didn't think of... :-) (I'd
have experimented, but this PC doesn't have Python 3 installed at the
moment :-()

The "buffer" attribute doesn't seem to be documented in the docs for
the io module. I'm guessing that the TextIOBase class should have a
note that you get at the buffer through the "buffer" attribute?

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


Re: Buffer pair for lexical analysis of raw binary data

2009-06-28 Thread Aahz
In article ,
Angus Rodgers   wrote:
>
>By "recipes", do you mean
> (also new to me)?

Yup!  You may also want to pick up the edited recipes in the Python
Cookbook.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Nobody
On Sun, 28 Jun 2009 15:22:15 +, Benjamin Peterson wrote:

> Nobody  nowhere.com> writes:
>> All in all, Python 3.x still has a long way to go before it will be
>> suitable for real-world use.
> 
> Such as?

Such as not trying to shoe-horn every byte string it encounters into
Unicode. Some of them really are *just* byte strings.

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


Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Benjamin Peterson
Nobody  nowhere.com> writes:
> 
> Such as not trying to shoe-horn every byte string it encounters into
> Unicode. Some of them really are *just* byte strings.


You're certainly allowed to convert them back to byte strings if you want.




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


Re: The Python Way for module configuration?

2009-06-28 Thread kj
In <87fxdlujds@benfinney.id.au> Ben Finney  
writes:

>(Even if you don't want to receive email, could you please give your
>actual name in the ‘From’ field instead of just initials? It makes
>conversation less confusing.)

I don't know why, but for as long as I can remember everyone calls
me kj, even my mom.  My name is Keaweikekahialiʻiokamoku
Jallalahwallalruwalpindi

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


Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Terry Reedy

Nobody wrote:

On Sun, 28 Jun 2009 15:22:15 +, Benjamin Peterson wrote:


Nobody  nowhere.com> writes:

All in all, Python 3.x still has a long way to go before it will be
suitable for real-world use.

Such as?


Such as not trying to shoe-horn every byte string it encounters into
Unicode. Some of them really are *just* byte strings.


Let's ignore the disinformation. So false it is hardly worth refuting.


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


Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Benjamin Peterson
Paul Moore  gmail.com> writes:

> The "buffer" attribute doesn't seem to be documented in the docs for
> the io module. I'm guessing that the TextIOBase class should have a
> note that you get at the buffer through the "buffer" attribute?


Good point. I've now documented it, and the "raw" attribute of BufferedIOBase.




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


Re: Advantages of Python (for web/desktop apps)?

2009-06-28 Thread Benjamin Kaplan
On Sun, Jun 28, 2009 at 11:03 AM, Aahz wrote:
> In article ,
> Tim Chase   wrote:
>>
>>> - how do i design GUI for windows app?
>>
>>http://lmgtfy.com/?q=python+gui
>
> This is the first time I've tried LMGTFY, and it seems to be a piece of
> trash that requires JavaScript.  I suggest that lmgtfy.com not be
> considered a standard part of the Python community.


It's not a standard part of the python community. It stands for "let
me google that for you" and it's a slightly more polite way of saying
STFW.

It's just an animation of typing the search term in a Google-like
search page and clicking the search button. Then it says "was that so
hard" and redirects you to the Google search results for that term.

> --
> Aahz (a...@pythoncraft.com)           <*>         http://www.pythoncraft.com/
>
> "as long as we like the same operating system, things are cool." --piranha
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating garbage collectable objects (caching objects)

2009-06-28 Thread Terry Reedy

News123 wrote:

Hi.

I started playing with PIL.

I'm performing operations on multiple images and would like compromise
between speed and memory requirement.

The fast approach would load all images upfront and create then multiple
result files. The problem is, that I do not have enough memory to load
all files.

The slow approach is to load each potential source file only when it is
needed and to release it immediately after (leaving it up to the gc to
free memory when needed)

The question, that I have is whether there is any way to tell python,
that certain objects could be garbage collected if needed and ask python
at a later time whether the object has been collected so far (image has
to be reloaded) or not (image would not have to be reloaded)


See the weakref module. But note that in CPython, objects are collected 
as soon as there all no normal references, not when 'needed'.



# Fastest approach:
imgs = {}
for fname in all_image_files:
imgs[fname] = Image.open(fname)
for creation_rule in all_creation_rules():
img = Image.new(...)
for img_file in creation_rule.input_files():
img = do_somethingwith(img,imgs[img_file])
img.save()


# Slowest approach:
for creation_rule in all_creation_rules():
img = Image.new(...)
for img_file in creation_rule.input_files():
src_img = Image.open(img_file)
img = do_somethingwith(img,src_img)
img.save()



# What I'd like to do is something like:
imgs = GarbageCollectable_dict()
for creation_rule in all_creation_rules():
img = Image.new(...)
for img_file in creation_rule.input_files():
if src_img in imgs: # if 'm lucke the object is still there
src_img = imgs[img_file]
else:
src_img = Image.open(img_file)
img = do_somethingwith(img,src_img)
img.save()



Is this possible?


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


Re: creating garbage collectable objects (caching objects)

2009-06-28 Thread Simon Forman
On Jun 28, 11:03 am, News123  wrote:
> Hi.
>
> I started playing with PIL.
>
> I'm performing operations on multiple images and would like compromise
> between speed and memory requirement.
>
> The fast approach would load all images upfront and create then multiple
> result files. The problem is, that I do not have enough memory to load
> all files.
>
> The slow approach is to load each potential source file only when it is
> needed and to release it immediately after (leaving it up to the gc to
> free memory when needed)
>
> The question, that I have is whether there is any way to tell python,
> that certain objects could be garbage collected if needed and ask python
> at a later time whether the object has been collected so far (image has
> to be reloaded) or not (image would not have to be reloaded)
>
> # Fastest approach:
> imgs = {}
> for fname in all_image_files:
>     imgs[fname] = Image.open(fname)
> for creation_rule in all_creation_rules():
>     img = Image.new(...)
>     for img_file in creation_rule.input_files():
>         img = do_somethingwith(img,imgs[img_file])
>     img.save()
>
> # Slowest approach:
> for creation_rule in all_creation_rules():
>     img = Image.new(...)
>     for img_file in creation_rule.input_files():
>         src_img = Image.open(img_file)
>         img = do_somethingwith(img,src_img)
>     img.save()
>
> # What I'd like to do is something like:
> imgs = GarbageCollectable_dict()
> for creation_rule in all_creation_rules():
>     img = Image.new(...)
>     for img_file in creation_rule.input_files():
>         if src_img in imgs: # if 'm lucke the object is still there
>                 src_img = imgs[img_file]
>         else:
>                 src_img = Image.open(img_file)
>         img = do_somethingwith(img,src_img)
>     img.save()
>
> Is this possible?
>
> Thaks in advance for an answer or any other ideas of
> how I could do smart caching without hogging all the system's
> memory

Maybe I'm just being thick today, but why would the "slow" approach be
slow?  The same amount of I/O and processing would be done either way,
no?
Have you timed both methods?

That said, take a look at the weakref module Terry Reedy already
mentioned, and maybe the gc (garbage collector) module too (although
that might just lead to wasting a lot of time fiddling with stuff that
the gc is supposed to handle transparently for you in the first place.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Flexible warning system

2009-06-28 Thread Shrutarshi Basu
I'm writing a Python package where I have an underlying object model that is
manipulated by a runtime control layer and clients that interface with this
runtime. As I'm developing this i'm realizing that there are going to be a
number of places where the runtime might affect the object model in ways
that might not be immediately obvious to the user. I would like to have some
sort of warning system where the runtime can raise a warning and then the
clients can 'catch' those warnings and display them as they want to. Is
there some sort of a system that will operates like that or will I have to
roll my own? If I do need to roll my own, any ideas on how I should go about
it? I know that there is a warning module, but it seems to that all outputs
go to standard out which isn't what I want.
Thanks,
Basu

Shrutarshi Basu
Computer Science,
Electrical and Computer Engineering,
Lafayette College,
The ByteBaker -- http://bytebaker.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running a script from a windows right click menu..?

2009-06-28 Thread Gabriel Genellina
En Sun, 28 Jun 2009 10:45:49 -0300, Nuff Nuff   
escribió:



I wrote a little script that affects a bunch of files in the folder
that it is run in.

Now what I want to do is to make it run from the right click menu but
I don't know how.

Would you give me an example script that will simply print the
woriking directory,  and show me how to add that to the right click
menu in windows explorer?


In the Windows registry, add a new key under  
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell

Make its default value the item text you want in the context menu.
Add a new key under it, "command", and make its default value the command  
line you want to execute. Will look like this:

"path to python.exe" "path to your script.py" %1 %*

See http://msdn.microsoft.com/en-us/library/dd807139(VS.85).aspx for more  
details


--
Gabriel Genellina

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


Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Aahz
In article ,
Benjamin Peterson   wrote:
>Nobody  nowhere.com> writes:
>> 
>> Such as not trying to shoe-horn every byte string it encounters into
>> Unicode. Some of them really are *just* byte strings.
>
>You're certainly allowed to convert them back to byte strings if you want.

Yes, but do you get back the original byte strings?  Maybe I'm missing
something, but my impression is that this is still an issue for the email
module as well as command-line arguments and environment variables.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Advantages of Python (for web/desktop apps)?

2009-06-28 Thread Aahz
In article ,
Benjamin Kaplan   wrote:
>On Sun, Jun 28, 2009 at 11:03 AM, Aahz wrote:
>> In article ,
>> Tim Chase =A0 wrote:
>>>
 - how do i design GUI for windows app?
>>>
>>>http://lmgtfy.com/?q=3Dpython+gui
>>
>> This is the first time I've tried LMGTFY, and it seems to be a piece of
>> trash that requires JavaScript. =A0I suggest that lmgtfy.com not be
>> considered a standard part of the Python community.
>
>It's not a standard part of the python community. It stands for "let
>me google that for you" and it's a slightly more polite way of saying
>STFW.
>
>It's just an animation of typing the search term in a Google-like
>search page and clicking the search button. Then it says "was that so
>hard" and redirects you to the Google search results for that term.

Perhaps I was unclear: I already knew what LMGTFY stands for, and I think
that using a site that requires JavaScript is anti-social.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating garbage collectable objects (caching objects)

2009-06-28 Thread Dave Angel

News123 wrote:

Hi.

I started playing with PIL.

I'm performing operations on multiple images and would like compromise
between speed and memory requirement.

The fast approach would load all images upfront and create then multiple
result files. The problem is, that I do not have enough memory to load
all files.

The slow approach is to load each potential source file only when it is
needed and to release it immediately after (leaving it up to the gc to
free memory when needed)



The question, that I have is whether there is any way to tell python,
that certain objects could be garbage collected if needed and ask python
at a later time whether the object has been collected so far (image has
to be reloaded) or not (image would not have to be reloaded)


# Fastest approach:
imgs = {}
for fname in all_image_files:
imgs[fname] = Image.open(fname)
for creation_rule in all_creation_rules():
img = Image.new(...)
for img_file in creation_rule.input_files():
img = do_somethingwith(img,imgs[img_file])
img.save()


# Slowest approach:
for creation_rule in all_creation_rules():
img = Image.new(...)
for img_file in creation_rule.input_files():
src_img = Image.open(img_file)
img = do_somethingwith(img,src_img)
img.save()



# What I'd like to do is something like:
imgs = GarbageCollectable_dict()
for creation_rule in all_creation_rules():
img = Image.new(...)
for img_file in creation_rule.input_files():
if src_img in imgs: # if 'm lucke the object is still there
src_img = imgs[img_file]
else:
src_img = Image.open(img_file)
img = do_somethingwith(img,src_img)
img.save()



Is this possible?

Thaks in advance for an answer or any other ideas of
how I could do smart caching without hogging all the system's
memory


  
You don't say what implementation of Python, nor on what OS platform.  
Yet you're asking how to influence that implementation.


In CPython, version 2.6 (and probably most other versions, but somebody 
else would have to chime in) an object is freed as soon as its reference 
count goes to zero.  So the garbage collector is only there to catch 
cycles, and it runs relatively infrequently.


So, if you keep a reference to an object, it'll not be freed.  
Theoretically, you can use the weakref module to keep a reference 
without inhibiting the garbage collection, but I don't have any 
experience with the module.  You could start by studying its 
documentation.  But probably you want a weakref.WeakValueDictionary.  
Use that in your third approach to store the cache.


If you're using Cython or Jython, or one of many other implementations, 
the rules will be different.


The real key to efficiency is usually managing locality of reference.  
If a given image is going to be used for many output files, you might 
try to do all the work with it before going on to the next image.  In 
that case, it might mean searching all_creation_rules for rules which 
reference the file you've currently loaded, measurement is key.



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


Re: Running a script from a windows right click menu..?

2009-06-28 Thread Michel Claveau - MVP
Bonsoir ! 

Un exemple là: http://www.mclaveau.com/grimoire/bleu.html#999

@-salutations
-- 
MCI

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


Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Benjamin Peterson
Aahz  pythoncraft.com> writes:
> Yes, but do you get back the original byte strings?  Maybe I'm missing
> something, but my impression is that this is still an issue for the email
> module as well as command-line arguments and environment variables.

The email module is, yes, broken. You can recover the bytestrings of
command-line arguments and environment variables.


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


Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Nobody
On Sun, 28 Jun 2009 19:21:49 +, Benjamin Peterson wrote:

>> Yes, but do you get back the original byte strings?  Maybe I'm missing
>> something, but my impression is that this is still an issue for the email
>> module as well as command-line arguments and environment variables.
> 
> The email module is, yes, broken. You can recover the bytestrings of
> command-line arguments and environment variables.

1. Does Python offer any assistance in doing so, or do you have to
manually convert the surrogates which are generated for unrecognised bytes?

2. How do you do this for non-invertible encodings (e.g. ISO-2022)?

Most of the issues can be worked around by calling
sys.setfilesystemencoding('iso-8859-1') at the start of the program, but
sys.argv and os.environ have already been converted by this point.

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


Column types with DB API

2009-06-28 Thread Thomas Robitaille

Hi,

I'm trying to use DB API compliant database modules
(psycopg2,MySQLdb,SQLite) to access SQL databases, and I am trying to
determine the type of each column in a table. The DB API defines
cursor.description which contains information about the column names and
types (once .execute() has been used to select part or all of the table),
but the types are expressed as integers. I realize that these numbers can be
checked against the type objects such as MySQLdb.NUMBER to determine whether
a given column is a number, a date, text, etc. However, is there any way to
determine what the sub-type of a column is, for example if a column is a
NUMBER, is there a way to determine if it is a 2, 4, or 8-byte integer or
real number?

Thanks in advance for any advice,

Thomas
-- 
View this message in context: 
http://www.nabble.com/Column-types-with-DB-API-tp24245424p24245424.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Nobody
On Sun, 28 Jun 2009 13:31:50 -0400, Terry Reedy wrote:

>>> Nobody  nowhere.com> writes:
 All in all, Python 3.x still has a long way to go before it will be
 suitable for real-world use.
>>> Such as?
>> 
>> Such as not trying to shoe-horn every byte string it encounters into
>> Unicode. Some of them really are *just* byte strings.
> 
> Let's ignore the disinformation.

Translation: let's ignore anything which falsifies the assumptions.

> So false it is hardly worth refuting.

Your copy of Trolling by Numbers must be getting pretty dog-eared by now.

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


Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Benjamin Peterson
Nobody  nowhere.com> writes:

> 
> On Sun, 28 Jun 2009 19:21:49 +, Benjamin Peterson wrote:
> 
> >> Yes, but do you get back the original byte strings?  Maybe I'm missing
> >> something, but my impression is that this is still an issue for the email
> >> module as well as command-line arguments and environment variables.
> > 
> > The email module is, yes, broken. You can recover the bytestrings of
> > command-line arguments and environment variables.
> 
> 1. Does Python offer any assistance in doing so, or do you have to
> manually convert the surrogates which are generated for unrecognised bytes?

fs_encoding = sys.getfilesystemencoding()
bytes_argv = [arg.encode(fs_encoding, "surrogateescape") for arg in sys.argv]

> 
> 2. How do you do this for non-invertible encodings (e.g. ISO-2022)?

What's a non-invertible encoding? I can't find a reference to the term.




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


Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Hallvard B Furuseth
Benjamin Peterson writes:
>Nobody  nowhere.com> writes:
>> On Sun, 28 Jun 2009 19:21:49 +, Benjamin Peterson wrote:
>> 1. Does Python offer any assistance in doing so, or do you have to
>> manually convert the surrogates which are generated for unrecognised bytes?
>
> fs_encoding = sys.getfilesystemencoding()
> bytes_argv = [arg.encode(fs_encoding, "surrogateescape") for arg in sys.argv]
>
>> 2. How do you do this for non-invertible encodings (e.g. ISO-2022)?
>
> What's a non-invertible encoding? I can't find a reference to the term.

Different ISO-2022 strings can map to the same Unicode string.
Thus you can convert back to _some_ ISO-2022 string, but it won't
necessarily match the original.

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


fork, threads and proper closing

2009-06-28 Thread Tomasz Pajor

Hello,

Configuration is as follows.

I have a starter process which creates 3 sub processes (forks) and each 
of this processes creates a number of threads.
Threads in that processes have semaphore so on KeyboardInterrupt without 
sending a sigterm to the subprocess i'm not able to close threads.
Is there any work around? Can I somehow run join for the thread on 
keyboard interrupt?


--
Best regards
Tomasz Pajor
--
http://mail.python.org/mailman/listinfo/python-list


Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Martin v. Löwis
> 2. How do you do this for non-invertible encodings (e.g. ISO-2022)?

ISO-2022 cannot be used as a system encoding.

Please do read the responses I write, and please do identify yourself.

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


Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Rhodri James
On Sat, 27 Jun 2009 22:12:10 +0100, Benjamin Peterson  
 wrote:


On behalf of the Python development team, I'm thrilled to announce the  
first production release of Python 3.1.


Why is everyone always thrilled to announce things?  Why is noone ever
bored to announce? :-)

So PEP 378 got in then?  Bleh.  It's still the wrong solution, and it
still makes the right solution harder to do.

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


Re: pep 8 constants

2009-06-28 Thread Rhodri James
On Sun, 28 Jun 2009 15:09:21 +0100, Eric S. Johansson   
wrote:



Bruno Desthuilliers wrote:

Brendan Miller a écrit :

PEP 8 doesn't mention anything about using all caps to indicate a
constant.

Is all caps meaning "don't reassign this var" a strong enough
convention to not be considered violating good python style? I see a
lot of people using it, but I also see a lot of people writing
non-pythonic code... so I thought I'd see what the consensus is.


Most - if not all - of the python code I've seen so far used this
convention, and I always used (and respected) it myself.


I reject this convention because any form of caps significantly  
increases vocal
load for disabled programmers using speech recognition through extra  
utterances,

and degraded recognition.


Reject away, but I'm afraid you've still got some work to do to
convince me that PEP 8 is more work for an SR system than any other
convention.  If, on the other hand you're trying to convince me that
*no* convention is preferable, I'm going to laugh hollowly.

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


Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Rhodri James
On Sun, 28 Jun 2009 23:13:34 +0100, Martin v. Löwis   
wrote:



On behalf of the Python development team, I'm thrilled to announce the
first production release of Python 3.1.


Why is everyone always thrilled to announce things?


I cannot talk about everyone, but in the specific case, I suppose
Benjamin was thrilled because it was his first release of a large
open source software package. Knowing that you have worked so long
on a single project, to see the project then finally completed,
is exciting - just try it out for yourself.


There was a smiley at the end of that paragraph, Martin!

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


Re: Column types with DB API

2009-06-28 Thread Gerhard Häring
Thomas Robitaille wrote:
> Hi,
> 
> I'm trying to use DB API compliant database modules
> (psycopg2,MySQLdb,SQLite) to access SQL databases, and I am trying to
> determine the type of each column in a table. The DB API defines
> cursor.description which contains information about the column names and
> types (once .execute() has been used to select part or all of the table),
> but the types are expressed as integers. I realize that these numbers can be
> checked against the type objects such as MySQLdb.NUMBER to determine whether
> a given column is a number, a date, text, etc. However, is there any way to
> determine what the sub-type of a column is, for example if a column is a
> NUMBER, is there a way to determine if it is a 2, 4, or 8-byte integer or
> real number?

Not with the DB-API. You'll have to implement all this for each database
separately. For some databases (like SQLite) it's even impossible.

I suggest you don't bother with cursor.description at all. Depending on
it doesn't harmonize with the way Python is typically used: duck typing.

-- Gerhard

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


Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Gerhard Häring
Scott David Daniels wrote:
> Nobody wrote:
>> On Sat, 27 Jun 2009 16:12:10 -0500, Benjamin Peterson wrote:
>> 
>>
>> That's a significant improvement
>> All in all, Python 3.x still has a long way to go before it will be
>> suitable for real-world use.
> 
> Fortunately, I have assiduously avoided the real word, and am happy to
> embrace the world from our 'bot overlords.
> 
> Congratulations on another release from the hydra-like world of
> multi-head development.

+1 QOTW

-- Gerhard

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


Re: [RELEASED] Python 3.1 final

2009-06-28 Thread Martin v. Löwis
>> On behalf of the Python development team, I'm thrilled to announce the
>> first production release of Python 3.1.
> 
> Why is everyone always thrilled to announce things? 

I cannot talk about everyone, but in the specific case, I suppose
Benjamin was thrilled because it was his first release of a large
open source software package. Knowing that you have worked so long
on a single project, to see the project then finally completed,
is exciting - just try it out for yourself.

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


handeling very large dictionaries

2009-06-28 Thread mclovin
Hello all,

I need to have a dictionary of about 8 gigs (well the data it is
processing is around 4gb). so naturally i am running into memory
errors.

So i looked around and found bsddb which acts like a dictionary object
only offloads the data from the RAM to the HDD, however that only
supports strings.

my dictionaries hold my own class objects

Is there something like it that is more flexible?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Measuring Fractal Dimension ?

2009-06-28 Thread Steven D'Aprano
On Sun, 28 Jun 2009 03:28:51 -0700, Paul Rubin wrote:

> Steven D'Aprano  writes:
>> I thought we were talking about discontinuities in *nature*, not in
>> mathematics. There's no "of course" about it.
> 
> IIRC we were talking about fractals, which are a topic in mathematics.
> This led to some discussion of mathematical continuity, and the claim
> that mathematical discontinuity doesn't appear to occur in nature (and
> according to some, it shouldn't occur in mathematics either).

I would argue that it's the other way around: mathematical *continuity* 
doesn't occur in nature. If things look continuous, it's only because 
we're not looking close enough.

But that depends on what you call "things"... if electron shells are real 
(and they seem to be) and discontinuous, and the shells are predicted/
specified by eigenvalues of some continuous function, is the continuous 
function part of nature or just a theoretical abstraction?


>> In mathematics, you can cut up a pea and reassemble it into a solid
>> sphere the size of the Earth. Try doing that with a real pea.
> 
> That's another example of a mathematical phenomenon that doesn't occur
> in nature.  What are you getting at?

The point is that you can't safely draw conclusions about *nature* from 
*mathematics*. The existence or non-existence of discontinuities/
continuities in nature is an empirical question that can't be settled by 
any amount of armchair theorising, even very intelligent theorising, by 
theorists, philosophers or mathematicians. You have to go out and look.

By the way, the reason you can't do to a pea in reality what you can do 
with a mathematical abstraction of a pea is because peas are made of 
discontinuous atoms.



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


Re: pep 8 constants

2009-06-28 Thread Steven D'Aprano
On Sun, 28 Jun 2009 10:09:21 -0400, Eric S. Johansson wrote:

> Bruno Desthuilliers wrote:
>> Brendan Miller a écrit :
>>> PEP 8 doesn't mention anything about using all caps to indicate a
>>> constant.
>>>
>>> Is all caps meaning "don't reassign this var" a strong enough
>>> convention to not be considered violating good python style? I see a
>>> lot of people using it, but I also see a lot of people writing
>>> non-pythonic code... so I thought I'd see what the consensus is.
>> 
>> Most - if not all - of the python code I've seen so far used this
>> convention, and I always used (and respected) it myself.
> 
> I reject this convention because any form of caps significantly
> increases vocal load for disabled programmers using speech recognition
> through extra utterances, and degraded recognition.
[...]
> so I reject pep 8 because I have no voice safe alternative

And you are perfectly entitled to.

That puts you at a disadvantage if you wish to submit code for the 
standard library, where PEP 8 compliance is required, but for your own 
code you are entitled to use whatever conventions you prefer.



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


Re: Measuring Fractal Dimension ?

2009-06-28 Thread Paul Rubin
Steven D'Aprano  writes:
> But that depends on what you call "things"... if electron shells are real 
> (and they seem to be) and discontinuous, and the shells are predicted/
> specified by eigenvalues of some continuous function, is the continuous 
> function part of nature or just a theoretical abstraction?

Again, electron shells came up in the context of a question about
quantum theory, which is a mathematical theory involving continuous
operators.  That theory appears to very accurately model and predict
observable natural phenomena.  Is the real physical mechanism
underneath observable nature actually some kind of discrete "checkers
game" to which quantum theory is merely a close approximation?  Maybe,
but there's not a predictive mathematical theory like that right now,
and even if there was, we'd be back to the question of just how it is
that the checkers get from one place to another.

> By the way, the reason you can't do to a pea in reality what you can do 
> with a mathematical abstraction of a pea is because peas are made of 
> discontinuous atoms.

Not so much discontinuity, as the physical unreality of non-measurable
sets.

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


Re: tokenize module

2009-06-28 Thread bootkey
On Jun 28, 1:46 am, Tim Roberts  wrote:
> Jim  wrote:
> >I'm trying to understand the output of the tokenize.generate_tokens()
> >generator.  The token types returned seem to be more general than I'd
> >expect.  For example, when fed the following line of code:
>
> >def func_a():
> >...
> >It seems to me that the token '(' should be identified as 'LPAR' and
> >')' as 'RPAR', as found in the dictionary token.tok_name.  What am I
> >missing here?
>
> Did you read the module?  Right at the top, it says:
>
> 
> It is designed to match the working of the Python tokenizer exactly, except
> that it produces COMMENT tokens for comments and gives type OP for all
> operators
> 
> --
> Tim Roberts, t...@probo.com
> Providenza & Boekelheide, Inc.

Thanks for the reply.  I wonder why the tokenizer classifies all
operators simply as OP, instead of the various operators listed in the
tok_name dictionary.

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


Re: Measuring Fractal Dimension ?

2009-06-28 Thread greg

Steven D'Aprano wrote:
one 
minute the grenade is sitting there, stable as can be, the next it's an 
expanding cloud of gas and metal fragments.


I'm not sure that counts as "discontinuous" in the mathematical
sense. If you were to film the grenade exploding and play it
back slowly enough, the process would actually look fairly
smooth.

Mathematically, it's possible for a system to exhibit chaotic
behaviour (so that you can't tell exactly when the grenade is
going to go off) even though all the equations describing its
behaviour are smooth and continuous.


My money is on the universe being fundamentally discontinuous.


That's quite likely true. Quantum mechanics doesn't actually
predict discrete behaviour -- the mathematics deals with
continuously-changing state functions. It's only the interpretation
of those functions (as determining the probabilities of finding
the system in one of a discrete set of states) that introduces
discontinuities.

So it seems quite plausible that the continuous functions are
just approximations of some underlying discrete process.

The trick will be figuring out how such a process can work
without running afoul of the various theorems concerning the
non-existince of hidden variable theories...

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


Re: Measuring Fractal Dimension ?

2009-06-28 Thread greg

Paul Rubin wrote:

Steven D'Aprano  writes:

But that depends on what you call "things"... if electron shells are real 
(and they seem to be) and discontinuous, and the shells are predicted/
specified by eigenvalues of some continuous function, is the continuous 
function part of nature or just a theoretical abstraction?


Another thing to think about: If you put the atom in a
magnetic field, the energy levels of the electrons get
shifted slightly. To the extent that you can vary the
magnetic field continuously, you can continuously
adjust the energy levels.

This of course raises the question of whether it's
really possible to continuously adjust a magnetic field.
But it's at least possible to do so with much finer
granularity than the differences between energy levels
in an atom.

So if there is a fundamentally discrete model
underlying everything, it must be at a much finer
granularity than anything we've so far observed, and
the discrete things that we have observed probably
aren't direct reflections of it.

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


Re: handeling very large dictionaries

2009-06-28 Thread Aahz
In article <9efff087-bd6e-49fb-ad30-a955a64b8...@j32g2000yqh.googlegroups.com>,
mclovin   wrote:
>
>I need to have a dictionary of about 8 gigs (well the data it is
>processing is around 4gb). so naturally i am running into memory
>errors.
>
>So i looked around and found bsddb which acts like a dictionary object
>only offloads the data from the RAM to the HDD, however that only
>supports strings.

Look at the pickle module.  Personally, I'd use SQLite instead of bsddb.
You might also look into a full-blown ORM such as SQLAlchemy.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Measuring Fractal Dimension ?

2009-06-28 Thread Terry Reedy

greg wrote:

Steven D'Aprano wrote:
one minute the grenade is sitting there, stable as can be, the next 
it's an expanding cloud of gas and metal fragments.


I'm not sure that counts as "discontinuous" in the mathematical
sense. If you were to film the grenade exploding and play it
back slowly enough, the process would actually look fairly
smooth.


radioactive emission might be a better example then.
I do not believe there is any acceleration like you see with grenade 
fragments.  Certainly, none with em radiation. Nothingemission at 
light speed.


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


Re: handeling very large dictionaries

2009-06-28 Thread alex23
On Jun 29, 9:13 am, mclovin  wrote:
> Is there something like it that is more flexible?

Have you seen the stdlib module 'shelve'? 
http://docs.python.org/library/shelve.html

It creates a persistent file-based dictionary, which can hold any type
of object as long as it can be pickled.

I really like the 3rd party module 'shove': http://pypi.python.org/pypi/shove

It's similar to shelve but provides many more backend options,
including dbs, svn and Amazon S3. Very handy.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No trees in the stdlib?

2009-06-28 Thread João Valverde

Paul Rubin wrote:

a...@pythoncraft.com (Aahz) writes:
  

(In particular, WRT the bisect module, although insertion and deletion
are O(N), the constant factor for doing a simple memory move at C speed
swamps bytecode until N gets very large -- and we already have
collections.deque() for some other common use cases.)



Again, at least in my case, I'd hope for an immutable structure.

  
Could you clarify what you mean by immutable? As in... not mutable? As 
in without supporting insertions and deletions? That's has the same 
performance as using binary search on a sorted list. What's the point of 
using a tree for that?

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


Re: No trees in the stdlib?

2009-06-28 Thread Paul Rubin
João Valverde  writes:
> Could you clarify what you mean by immutable? As in... not mutable? As
> in without supporting insertions and deletions?  

Correct.  

> That's has the same performance as using binary search on a sorted
> list.  What's the point of using a tree for that?

The idea is you can accomplish the equivalent of insertion or deletion
by allocating a new root, along with the path down to the place you
want to insert, i.e. O(log n) operations.  So instead of mutating an
existing tree, you create a new tree that shares most of its structure
with the old tree, and switch over to using the new tree.  This
trivially lets you maintain snapshots of old versions of the tree,
implement an "undo" operation, have a background thread do a complex
operation on a snapshot while the foreground thread does any number of
update-and-replace operations, etc.

This is very standard stuff.  See:

  http://en.wikipedia.org/wiki/Persistent_data_structure

The wikipedia article on AVL trees makes it pretty obvious how an
implementation would work.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pep 8 constants

2009-06-28 Thread Eric S. Johansson
Rhodri James wrote:

> Reject away, but I'm afraid you've still got some work to do to
> convince me that PEP 8 is more work for an SR system than any other
> convention.  

Name  name
higher than normal recognition error rate. can require multiple tries 
or hand
correction

MultiWordName  mulitwordname
very high error rate.  many retries or hand hurting typing.

multi_word_name multiwordname
normal error rate (low), can need multiple tries or hand correction

StdlYCps  sierra tango delta lima yankee charley papa sierra

*** very high error rate *** search and replace for all instances with 
a x_y_z
form name is recommended

If, on the other hand you're trying to convince me that
> *no* convention is preferable, I'm going to laugh hollowly.

no, I know the value if convention when editors can't tell you anything about
the name in question.  I would like to see more support for disabled programmers
like myself and the thousands of programmers injured every year and forced to
leave the field.  seriously, there is no money in disability access especially
for programmers.  and forgive me if this comes off sounding like a jerk but if
the collective you don't give a sh** about your fellow programmers, who will?
should all disabled programmers be dumped on the shelf even their brains are
still good and they have guts to try to work in a field that gave them a life
rearranging injury?

please help.  the disability access you help build may save your own job
someday.  Or, what I need to edit code may make your world better as well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: fork, threads and proper closing

2009-06-28 Thread OdarR
On 28 juin, 23:26, Tomasz Pajor  wrote:
> Hello,
>
> Configuration is as follows.
>
> I have a starter process which creates 3 sub processes (forks) and each
> of this processes creates a number of threads.
> Threads in that processes have semaphore so on KeyboardInterrupt without
> sending a sigterm to the subprocess i'm not able to close threads.
> Is there any work around? Can I somehow run join for the thread on
> keyboard interrupt?

When creating a thread you can add a Queue parameter to communicate
with threads:
http://docs.python.org/library/queue.html
easy and reliable.

give them a "poison pill" in the queue: a recognizable object placed
on the queue that means "when you get this, stop."

better to not rely on keyboard for thread stopping.

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


Re: No trees in the stdlib?

2009-06-28 Thread João Valverde

Paul Rubin wrote:

João Valverde  writes:
  

Could you clarify what you mean by immutable? As in... not mutable? As
in without supporting insertions and deletions?  



Correct.  

  

That's has the same performance as using binary search on a sorted
list.  What's the point of using a tree for that?



The idea is you can accomplish the equivalent of insertion or deletion
by allocating a new root, along with the path down to the place you
want to insert, i.e. O(log n) operations.  So instead of mutating an
existing tree, you create a new tree that shares most of its structure
with the old tree, and switch over to using the new tree.  This
trivially lets you maintain snapshots of old versions of the tree,
implement an "undo" operation, have a background thread do a complex
operation on a snapshot while the foreground thread does any number of
update-and-replace operations, etc.


  
Interesting, thanks. The concept is not difficult to understand but I'm 
not sure it would be preferable. A copy operation should have the same 
cost as a "snapshot", undo is kind of redundant and multithreading... 
don't see a compelling use that would justify it. Also the interface is 
a mapping so it'd be rather nice to emulate dict's.


Have you considered how the syntax would work in Python by the way? This:

new_tree = old_tree.insert(object)

Just looks wrong. The interface should support non functional idioms too.
--
http://mail.python.org/mailman/listinfo/python-list


Re: No trees in the stdlib?

2009-06-28 Thread João Valverde

João Valverde wrote:

Paul Rubin wrote:

João Valverde  writes:
 

Could you clarify what you mean by immutable? As in... not mutable? As
in without supporting insertions and deletions?  


Correct. 
 

That's has the same performance as using binary search on a sorted
list.  What's the point of using a tree for that?



The idea is you can accomplish the equivalent of insertion or deletion
by allocating a new root, along with the path down to the place you
want to insert, i.e. O(log n) operations.  So instead of mutating an
existing tree, you create a new tree that shares most of its structure
with the old tree, and switch over to using the new tree.  This
trivially lets you maintain snapshots of old versions of the tree,
implement an "undo" operation, have a background thread do a complex
operation on a snapshot while the foreground thread does any number of
update-and-replace operations, etc.


  
Interesting, thanks. The concept is not difficult to understand but 
I'm not sure it would be preferable. A copy operation should have the 
same cost as a "snapshot", undo is kind of redundant and 
multithreading... don't see a compelling use that would justify it. 
Also the interface is a mapping so it'd be rather nice to emulate dict's.


Have you considered how the syntax would work in Python by the way? This:

new_tree = old_tree.insert(object)



Heh, that's a poor example for a mapping. But:

bst[key] = object

is even dicier for immutable structures no?
--
http://mail.python.org/mailman/listinfo/python-list


Re: No trees in the stdlib?

2009-06-28 Thread Paul Rubin
João Valverde  writes:
> Interesting, thanks. The concept is not difficult to understand but
> I'm not sure it would be preferable. A copy operation should have the
> same cost as a "snapshot", 

You mean a deep-copy?  That is unnecessarily expensive; with a
functional structure you can snapshot (or copy) by copying a single
pointer.

> undo is kind of redundant and multithreading... don't see a
> compelling use that would justify it. 

Here is one:
 http://groups.google.com/group/comp.lang.python/msg/1fbe66701e4bc65b

> Have you considered how the syntax would work in Python by the way? This:
> new_tree = old_tree.insert(object)
> Just looks wrong. 

It looks fine to me.  Obviously you could support a wrapper with
a mutating slot that holds a pointer to the tree.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No trees in the stdlib?

2009-06-28 Thread Paul Rubin
João Valverde  writes:
> bst[key] = object
> is even dicier for immutable structures no?

bst = bst.insert(key, object)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Imaging Library download link broken?

2009-06-28 Thread Lawrence D'Oliveiro
In message <976cc575-80b9-406a-
ae4d-03cb4d401...@p36g2000prn.googlegroups.com>, olivergeorge wrote:

> (and why PIL is such a pain to install for that matter.)

"apt-get install python-imaging", anybody?

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


Re: pep 8 constants

2009-06-28 Thread alex23
"Eric S. Johansson"  wrote:
> no, I know the value if convention when editors can't tell you anything about
> the name in question.  I would like to see more support for disabled 
> programmers
> like myself and the thousands of programmers injured every year and forced to
> leave the field.  seriously, there is no money in disability access especially
> for programmers.

Well, if we can't use conventions like uppercasing, camelcasing and
underscoring, what are you recommending we do instead?

You seem to be asking us to change our behaviour to benefit only
others, but without offering any guidance on to how that is possible.
More importantly, shouldn't these modifications to common conventions
be coming _from_ the community of disabled programmers? I have a hard
time ensuring that I've gotten accurate requirements from co-workers
with whom I can actually see and speak, trying to determine how I
could write my code with accessibility in mind without any established
means of gauging success just seems impossible.

> and forgive me if this comes off sounding like a jerk but if
> the collective you don't give a sh** about your fellow programmers, who will?

This isn't intended to be callous, as I feel that the collective
doesn't care as a whole about _any_ programmers, but isn't the answer
the very same disabled programmers for whom accessibility is an issue?
Programming tends to be needs driven (which, admittedly, can be simply
"to pay the bills"), and those who have a need tend to be better at
working out how to address it.

One possibility may be to approach a group for whom accessibility is
already a consideration, such as the Gnome Accessibility Project:
http://live.gnome.org/GAP

As they are already developing Python-based accessibility tools for
Gnome - http://live.gnome.org/Accessibility/PythonPoweredAccessibility
- it wouldn't be a big stretch to start addressing coding
accessibility within that scope, either as part of the project or as
an independent adjunct to it, especially if someone with domain
knowledge volunteered ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No trees in the stdlib?

2009-06-28 Thread João Valverde

Paul Rubin wrote:

João Valverde  writes:
  

Interesting, thanks. The concept is not difficult to understand but
I'm not sure it would be preferable. A copy operation should have the
same cost as a "snapshot", 



You mean a deep-copy?  That is unnecessarily expensive; with a
functional structure you can snapshot (or copy) by copying a single
pointer.

  


Shallow copy...


undo is kind of redundant and multithreading... don't see a
compelling use that would justify it. 



Here is one:
 http://groups.google.com/group/comp.lang.python/msg/1fbe66701e4bc65b

  


I just skimmed that but if someone really needs multithreading for such 
intensive processing without wanting a database, fair enough I guess.



Have you considered how the syntax would work in Python by the way? This:
new_tree = old_tree.insert(object)
Just looks wrong. 



It looks fine to me.  Obviously you could support a wrapper with
a mutating slot that holds a pointer to the tree.
  
I didn't get the last part, sorry. But I think you'd have a lot of users 
annoyed that the interface is similar to a list yet their objects 
mysteriously disappear. To me, tree.insert() implies mutability but I 
defer that to others like yourself with more experience in Python than me.


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


Re: handeling very large dictionaries

2009-06-28 Thread Joseph Turian
You could also try using a key-value store.
I am using pytc, a Python API for Tokyo Cabinet. It seems to figure
out quite nicely when to go to disk, and when to use memory. But I
have not done extensive tests.

Here is some example code for using pytc:
  http://github.com/turian/pytc-example/tree/master

 Joseph

On Jun 28, 7:13 pm, mclovin  wrote:
> Hello all,
>
> I need to have a dictionary of about 8 gigs (well the data it is
> processing is around 4gb). so naturally i am running into memory
> errors.
>
> So i looked around and found bsddb which acts like a dictionary object
> only offloads the data from the RAM to the HDD, however that only
> supports strings.
>
> my dictionaries hold my own class objects
>
> Is there something like it that is more flexible?

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


Re: No trees in the stdlib?

2009-06-28 Thread João Valverde

João Valverde wrote:

Paul Rubin wrote:

João Valverde  writes:
 

Interesting, thanks. The concept is not difficult to understand but
I'm not sure it would be preferable. A copy operation should have the
same cost as a "snapshot", 


You mean a deep-copy?  That is unnecessarily expensive; with a
functional structure you can snapshot (or copy) by copying a single
pointer.

  


Shallow copy...


Actually I meant whatever that snapshot operation is, minus the 
insertion, if that makes sense.


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


Re: pep 8 constants

2009-06-28 Thread Peter Otten
Eric S. Johansson wrote:

> MultiWordName  mulitwordname
> very high error rate.  many retries or hand hurting typing.

Can you define macros in your speech recognition software?

multiwordname

might slightly lower the error rate.

Peter


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


Re: fork, threads and proper closing

2009-06-28 Thread Tomasz Pajor



On 28 juin, 23:26, Tomasz Pajor  wrote:
  

Hello,

Configuration is as follows.

I have a starter process which creates 3 sub processes (forks) and each
of this processes creates a number of threads.
Threads in that processes have semaphore so on KeyboardInterrupt without
sending a sigterm to the subprocess i'm not able to close threads.
Is there any work around? Can I somehow run join for the thread on
keyboard interrupt?



When creating a thread you can add a Queue parameter to communicate
with threads:
http://docs.python.org/library/queue.html
easy and reliable.

give them a "poison pill" in the queue: a recognizable object placed
on the queue that means "when you get this, stop."
  

can You provide any working example?

better to not rely on keyboard for thread stopping.
  

i use keyboard interrupt only for debuging purposes

Olivier
  


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


Re: Python Imaging Library download link broken?

2009-06-28 Thread John Machin
On Jun 28, 6:02 am, Scott David Daniels  wrote:
> olivergeorge wrote:
> > Ditto.  Anyone know what's happening with pythonware?  (and why PIL is
> > such a pain to install for that matter.)
>

> (2) I suggest you demand a refund.

... and tell us what the response was :-)

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