Re: No typical loops, and other crazy ideas

2005-01-06 Thread Peter Otten
Bulba! wrote:

 motivation). I've tried to manipulate the data just in Python
 and not in typical loops. One thing that may not be entirely

A list comprehension is just a fancy way to write a loop. Resisting the
temptation to use it can sometimes improve your code.

 [Also, for some reason the advice by another poster, to
 use:
 
 oldl=list(orig)
 
 instead of:
 
 oldl=[x for x in orig]
 
 ..somehow didn't work. The first instruction has produced only empty
 lists.]
 
 
 #-Code follows---

[...]

 #oldl=list(orig)
 #newl=list(orig)

Because you used the same reader twice newl will always be empty. 

Peter


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


Re: OT: spacing of code in Google Groups

2005-01-06 Thread Jacek Generowicz
Peter Hansen [EMAIL PROTECTED] writes:

 Why the heck would I ever have to do rectangle operations on a
 regular basis?  ;-)

Well, given that all editors are cat equivalent[*], you don't _have_
to use any of their features :-)

But just like Python (particularly in the hands of a skilled Python
programmer) is more productive than a Turing Machine, any featureful
editor (in the hands of an experienced user) is far more productive
than cat  file.


[*] A bit like Turing equivalence: any program you can write in any
other editor, you could also write with cat  file
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: file.readlines() - gives me error (bad file descriptor)

2005-01-06 Thread Binu K S
On Thu, 6 Jan 2005 13:17:11 +0530, Gurpreet Sachdeva
[EMAIL PROTECTED] wrote:
 On Thu, 6 Jan 2005 12:55:22 +0530, Binu K S [EMAIL PROTECTED] wrote:
 The file's current position moves as you write into it.
 I concure and have figured out the solution BUT while reading from the
 file from the position where the file handler is, should return
 Null/Blank/Anything in this world BUT should not write into the
 file...
 The information written was that in the Buffer of the handler... Does
 that mean reading a file will actually release the buffer by throwing
 the contents in the file???
 

I'm sorry, I didn't get what you trying to say here. Where do you see
a read altering the file? An example might help.

 Please Comment...
 
 You normally wouldn't read from the file that you are writing into.
 
 May be applicable in handling logs...

Sometimes after opening a file you read the contents of a file and
then append to it. I haven't seen writing to a file and then going
back to see what was written.

 
 Regards,
 Garry

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


Re: python-dev Summary for 2004-11-16 through 2004-11-30

2005-01-06 Thread michele . simionato
 Would you like the source with your function?

Yes, since I asked for this feature something like two years ago ;-)
Michele Simionato

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


Re: file.readlines() - gives me error (bad file descriptor)

2005-01-06 Thread Gurpreet Sachdeva
On Thu, 6 Jan 2005 14:27:40 +0530, Binu K S [EMAIL PROTECTED] wrote:
 I'm sorry, I didn't get what you trying to say here. Where do you see
 a read altering the file? An example might help.

Please try:

logfile=file(r'test.txt','w+')
logfile.write('datetime')

Check the contents of test.txt, you will get what ever was required...

Now Run:

logfile=file(r'test.txt','w+')
logfile.write('datetime')
logfile.readlines()

and check the contents of test.txt???
My doubt is that logfile.write('datetime') will write datetime that is
universaly accepted but why all that junk is appending to that when I
add logfile.readlines()

Strange or Am I on drugs??? :o)

Please Comment...

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


navigating/changing directories

2005-01-06 Thread skip
A simple script like the one below lets me jump through a directory 
structure.  However, if I run it from /this/directory and within it to go to 
/a/totally/different/directory...  I'm still actually going to be in 
/this/directory when I exit the script.  Is it possible to have a script 
that can drop me off into a different directory than where I initiated it 
from?

import os
process = 1
while (process):
# Display directories
for i in os.listdir(os.getcwd()):
if (os.path.isdir(os.path.join(os.getcwd(),i))):
print i

# Change directory
goto_dir = raw_input(: )
if (goto_dir in os.listdir(os.getcwd())):
os.chdir(os.path.join(os.getcwd(),goto_dir))
else:
process = 0 # Exit


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


Re: Building unique comma-delimited list?

2005-01-06 Thread Duncan Booth
Roy Smith wrote:

 The best I've come up with is the following.  Can anybody think of a
 simplier way?
 
 
 words = [foo, bar, baz, foo, bar, foo, baz]
 
 # Eliminate the duplicates; probably use set() in Python 2.4
 d = dict()
 for w in words:
 d[w] = w
 
 if d.has_key (foo):
 newWords = [foo]
 del (d[foo])
 else:
 newWords = []
 
 for w in d.keys():
 newWords.append (w)
 
 s = ', '.join (newWords)
 print s
 
 

You need to make the dictionary and list types work harder for you. They 
have a variety of methods you might find useful.

 words = [foo, bar, baz, foo, bar, foo, baz]
 distinguished = [foo]
 d = dict.fromkeys(words, True)
 newwords = [ w for w in distinguished if d.pop(w, False) ]
 newwords.extend(d.keys())
 newwords
['foo', 'baz', 'bar']
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cookbook 2nd ed Credits

2005-01-06 Thread Anand
Yes, such a list is available.

I have uploaded a tentative list of contributors at
http://harvestman.freezope.org  . The original list is courtesy Alex.

For the impatient, here are the direct links...

List of first authors:
http://harvestman.freezope.org/cookbook/credau.html
List of all authors:
http://harvestman.freezope.org/cookbook/creds.html
Hope this helps!

Regards

-Anand

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


Contributor's List

2005-01-06 Thread Anand
A list of contributors to Python Cookbook (Second Edition) is available
at the following links. Original list courtesy Alex Martelli.

Since the book is not yet in print, the lists are still tentative
because of potential last minute editing changes.

List of first authors
o http://harvestman.freezope.org/cookbook/credau.html

List of all authors
o http://harvestman.freezope.org/cookbook/creds.html   


-Anand

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


Re: Python evolution: Unease

2005-01-06 Thread Carlos Ribeiro
On 5 Jan 2005 19:31:53 -0800, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 John Roth:
  The bottom line is that I'm not going to be writing any
  extensive pieces of Python documentation. My time
  is better spent elsewhere.
 
 Well, a couple of years ago I realized that some documentation on the
 MRO
 was missing. I wrote a document in reST, posted here, and Guido put it
 on
 python.org. It was as easy as it sounds. So I don't see your problem.
 
 Dave Kulhman wrote some utility to convert reST in latex using the same
 style of the standard library docs; I haven't used it myself, but you
 may check
 with him: http://www.rexx.com/~dkuhlman/

Couldn't a better document-writing interface be implemented? This is
the kind of stuff Zope  Plone are used for on a daily basis; not to
mention other countless web frameworks  CMS available in Python. Even
a simple automated service to process  publish reST or SGML files
would be better than requiring aspiring Python doc writers to install
the full toolchain, as pointed out. But, whatever it is (and that's a
difficult choice, politically speaking), it should be hosted on the
main Python site... because that's the place where people look for
info first place.

 P.S. since you cite descriptors, what's wrong with Raimond Hetting
 documentation?
 http://users.rcn.com/python/download/Descriptor.htm
 
 The only problem I see is that it is not integrated with the official
 docs, but this is a
 minor issue, I think.

The docs are great, but it took me some time to find them out after
searching inside Python docs. This is not a minor issue IMHO.

-- 
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: [EMAIL PROTECTED]
mail: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Other notes

2005-01-06 Thread Timo Virkkala
[EMAIL PROTECTED] wrote:
Andrew Dalke:
(BTW, it needs to be 1 .. 12 not 1..12 because 1. will be interpreted
as the floating point value 1.0.)
Uhm, I have to fix my ignorance about parsers.
Cannot a second . after the first tell that the first . isn't in
the middle of a floating point number?
Python uses an LL(1) parser. From Wikipedia:
 LL(1) grammars, although fairly restrictive, are very popular because the 
corresponding LL parsers only need to look at the next token to make their 
parsing decisions.

This may allow: assert 5 interval 9 == interval(5,9)
Maybe you could give an example of when you need this in real life?
Every time you have a function with 2 parameters, you can choose to use
it infix.
But why would you want to? What advantage does this give over the standard 
syntax? Remember, in Python philosophy, there should be one obvious way to do 
it, and preferably only one. Adding a whole another way of calling functions 
complicates things without adding much advantage. Especially so because you 
suggest it is only used for binary, i.e. two-parameter functions.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Contributor's List

2005-01-06 Thread grahamd
Anand wrote:
 A list of contributors to Python Cookbook (Second Edition) is
available
 at the following links. Original list courtesy Alex Martelli.

 Since the book is not yet in print, the lists are still tentative
 because of potential last minute editing changes.

 List of first authors
 o http://harvestman.freezope.org/cookbook/credau.html

 List of all authors
 o http://harvestman.freezope.org/cookbook/creds.html

Is this mean't to only cover additional entries which were added in
the 2nd edition, or is it also mean't to encompass entries which were
carried over from the 1st edition as well.

If it is both, then the editing must have been quite cut throat as I
dropped from 3 entries in the 1st edition to 0 in the 2nd edition.

I can sort of understand if the intent was to get rid of entries which
referenced packages which weren't regarded as mainstream. I guess
it is only 14 years of work down the drain. ;-(

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


Re: Contributor's List

2005-01-06 Thread grahamd
Anand wrote:
 A list of contributors to Python Cookbook (Second Edition) is
available
 at the following links. Original list courtesy Alex Martelli.

 Since the book is not yet in print, the lists are still tentative
 because of potential last minute editing changes.

 List of first authors
 o http://harvestman.freezope.org/cookbook/credau.html

 List of all authors
 o http://harvestman.freezope.org/cookbook/creds.html

Is this mean't to only cover additional entries which were added in
the 2nd edition, or is it also mean't to encompass entries which were
carried over from the 1st edition as well.

If it is both, then the editing must have been quite cut throat as I
dropped from 3 entries in the 1st edition to 0 in the 2nd edition.

I can sort of understand if the intent was to get rid of entries which
referenced packages which weren't regarded as mainstream. I guess
it is only 14 years of work down the drain. ;-(

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


Re: Why tuples use parentheses ()'s instead of something else like 's?

2005-01-06 Thread Timo Virkkala
[EMAIL PROTECTED] wrote:
I can't thank you enough for your reply and for everyones' great info
on this thread.  The end of your email gave a rock solid reason why it
is impossible to improve upon ()'s for tuples
Actually, you missed the point. The parentheses don't have anything to do with 
the tuple. They are just used for disambiguation. It's the commas that define 
the tuple.

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


Re: file.readlines() - gives me error (bad file descriptor)

2005-01-06 Thread Binu K S
http://mail.python.org/pipermail/python-bugs-list/2001-October/007650.html
Rest assured you're not on drugs :)

On Thu, 6 Jan 2005 14:45:24 +0530, Gurpreet Sachdeva
[EMAIL PROTECTED] wrote:
 On Thu, 6 Jan 2005 14:27:40 +0530, Binu K S [EMAIL PROTECTED] wrote:
  I'm sorry, I didn't get what you trying to say here. Where do you see
  a read altering the file? An example might help.
 
 Please try:
 
 logfile=file(r'test.txt','w+')
 logfile.write('datetime')
 
 Check the contents of test.txt, you will get what ever was required...
 
 Now Run:
 
 logfile=file(r'test.txt','w+')
 logfile.write('datetime')
 logfile.readlines()
 
 and check the contents of test.txt???
 My doubt is that logfile.write('datetime') will write datetime that is
 universaly accepted but why all that junk is appending to that when I
 add logfile.readlines()
 
 Strange or Am I on drugs??? :o)
 
 Please Comment...
 
 Garry

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


Re: Contributor's List

2005-01-06 Thread Anand
Please direct all queries to the Cookbook editors...!

Thanks

-Anand

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


Re: Contributor's List

2005-01-06 Thread Anand
Please direct all queries to the Cookbook editors!

Thanks

-Anand

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


Re: Contributor's List

2005-01-06 Thread Anand
Please direct any query to the Cookbook editors.

Thanks

-Anand

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


Re: Contributor's List

2005-01-06 Thread Anand
I have no idea. I am just another contributor like you. Just doing a
service to the Python community by providing the list at my site.
However, I am not responsible
for its content. Please direct your queries to the editors, if any.
Thanks

-Anand

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


Python C Object Comparison

2005-01-06 Thread Anand K Rayudu
Dear All,
I have some question regarding embedding and exposing of C pointers.
We have embedded python and extended to expose our APIs and c objects to 
python.
Every thing is working fine as far as customizing our application 
through python.

How ever i am expecting following behavior but it failed. Can some oe 
suggest a work around!!

Here is my python code
import myModule
a=myModule.myAPI1(1)
b=myModule.myAPI2(name)
# basically both above functions return same C pointer.
# so i want to compare
if(a==b): print They are same
else : print They are different
python always prints they are different,
I guess this is because in python layer we create PythonCObject for 
every C pointer, and that is how it is exposed to python. Though both 
the APIs are returning the same C pointer, they are different instances 
of PythonCObject.
So i guess that is the reason comparison is failing.
How ever is it possible to make python to compare actual C pointer, 
rather than the PythonCObject Pointer.

Can some one please suggest
Regards,
Anand
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] Let's get rid of unbound methods

2005-01-06 Thread Nick Coghlan
Andrew Koenig wrote:
duck typing?

That's the Australian pronunciation of duct taping.
More Kiwi, I'm thinking ;)
Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Securing a future for anonymous functions in Python

2005-01-06 Thread Nick Coghlan
Paul Rubin wrote:
Nick Coghlan [EMAIL PROTECTED] writes:
Do you consider generator expressions or list comprehensions deficient
because they don't allow several statements in the body of the for
loop?

I don't see what it would mean to do otherwise.
Exactly the same as a suite would in the innermost portion of the equivalent 
explicit generator (i.e. where the implicit yield expr currently ends up).

If you could put a suite inside a function expression (i.e. replacing the 
implicit return expr) why not inside generator expressions as well?

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2005-01-06 Thread Stefan Axelsson
Bulba! wrote:
Nope. IMHO, GPL attempts to achieve the vendor lock-in. For different
purposes than another well-known vendor, but it still does.
It's actually even worse: the only thing you can't share  on a
well-known vendor's platform is the software written by that
well-known vendor -- you can choose to share or choose not to 
share whatever you or other people write on this platform. 

If GPL folks had their way, it would not be possible not to share
_anything_ you create. It is widely acknowledged that GPL
license has the viral aspect of extending itself on your 
software - can you point to closed-source licenses that would 
have this aspect? None of the licenses I've read except GPL has 
this aspect.  
Then you haven't read very many source code licenses, many (perhaps 
most?) that state that if you've as much as looked at the code you're 
not even allowed to write somethings similar twenty years down the line, 
or anything that remotely resembles something similar. (Most do in fact 
go a bit further than that, but the legality would be in question. Still 
it would take you lawyers to get off the hook). Where do you think the 
'clean-room approach' came from in the first place? Furthermore, you're 
most often not allowed to change, disseminate, compile, discuss, etc the 
code but in fact just look at it. (And when it comes to Microsoft's 
binary licenses it's not as rosy as you would like to put it, read 
through them sometime there's a lot more you're not allowed to do than 
just 'share' it with others.)

Can you say NDA? Knew you could.
Now, Stallman might or might not want to achieve world domination, not 
by sharks with lasers on their heads, but by aiming for all software to 
be free software, but the GPL is actually a lot less ambitious than 
that. All the GPL says is that: if you received a binary, the person who 
 provided you with it, must provide you with the source code that built 
it. *All* the source code, not just what he happened to receive, on the 
off chance that he's modified it. And as having the source code without 
being able to modify it would be rather pointless, you're allowed to do 
that too, it's a given. If you don't want to distribute binaries, that's 
fine, and all of the GPL falls. The GPL doesn't *force* you to share 
anything. It only says what must happen if you do.

And I'm rather tired of the GPL's so called 'viral' nature. Look, if 
you're using my code, you play by my rules, that's called copyright. If 
you don't want to play by my rules, fine, don't use my code. So far I'm 
no better than Microsoft, or Sun (though that might change) or IBM for 
that matter. With the GPL I'm actually not as bad as that, I'll even let 
you look at the code, modify it, and distribute copies willy nilly 
(though you I'm not forcing you to), in fact, I'll even *forbid* others 
from taking that right away from you. If you use it, however, as a small 
token of your appreciation, you'll have to also agree to not take the 
same rights you had away from others.

Finally, what *you* do with *your* code is of no concern to the GPL. As 
long as you don't use *my* code you can do whatever you please. But, and 
that's a big 'BUT', it really irks me when people release code under 
e.g. the BSD (or as has happened to me in the past, public domain), and 
then bitch and moan when I incorporate parts of it in *my* software and 
release the whole under the GPL. As if that was somehow 'unfair'. Look, 
(and I'm obviously not saying this to the parent poster as he never 
expressed any such sentiment, I'm just venting) that's what *you* wanted 
when you released the code under that license. If you don't want me to 
do that, then don't use those licenses, mkay.

Stefan,
--
Stefan Axelsson  (email at http://www.cs.chalmers.se/~sax)
--
http://mail.python.org/mailman/listinfo/python-list


wxPython clipboard

2005-01-06 Thread lbolognini
Hi all,

I'm thinking about coding a free version of this software:
http://www.pitrinec.com/pkindex.htm

I would use wxPython and wx.Clipboard class (hoping to be able to make
it cross-platform)

The software above detects macros you code in any Windows active window
and replaces them with a text: something like you write /ff and he
pastes Feel free to call us back for whatever questions you might
have.

This kind of softwares are very usefull in a call-centre environment
(where I'm currently working).

The thing is I'm thinking about the best approach (in terms of CPU
resources) to detect the macro. Not sure how keyloggers work but I
suspect I could run a service that compares everything beign written in
the active window with the macros I saved in the software
configuration.

Could you please give me some advice on the best approach to solve this
problem?

Thanks a lot,
Lorenzo
--
http://www.bolognini.net/

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


wxPython clipboard

2005-01-06 Thread lbolognini
Hi all,

I'm thinking about coding a free version of this software:
http://www.pitrinec.com/pkindex.htm

I would use wxPython and wx.Clipboard class (hoping to be able to make
it cross-platform)

The software above detects macros you code in any Windows active window
and replaces them with a text: something like you write /ff and he
pastes Feel free to call us back for whatever questions you might
have.

This kind of softwares are very usefull in a call-centre environment
(where I'm currently working).

The thing is I'm thinking about the best approach (in terms of CPU
resources) to detect the macro. Not sure how keyloggers work but I
suspect I could run a service that compares everything beign written in
the active window with the macros I saved in the software
configuration.

Could you please give me some advice on the best approach to solve this
problem?

Thanks a lot,
Lorenzo
--
http://www.bolognini.net

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


Re: Deferred expressions (was Re: Lambda as declarative idiom)

2005-01-06 Thread Nick Coghlan
Bengt Richter wrote:
I like the fact that 'def' can serve as a mnemonic for 'defer' or 'deferred' ;-)
Yeah, me too. I didn't actually notice that until after I'd thought of the 
phrase.
OTOH, I like concise notation for expressions, and the def and from aren't
really necessary if you can tag the first expression with some syntax marker.
I suggested (: rather than (def since  (: is illegal now and won't break 
anything.
True, but I've always liked Python's preference for keywords over punctuation. 
And 'def' is only 2 characters longer than ':', too.

That is an advantage of having it inside the outer parens, which my 
(:expr)(params)
couldn't benefit from -- unless I just take your format and substitute ':' for
both def and from:
But where does that leave Python is executable pseudocode?
Compare:
(lambda (a, b, c) : f(a) + o(b) - o(c))
(: f(a) + o(b) - o(c) : (a, b, c))
(def f(a) + o(b) - o(c) from (a, b, c))
Which of the above most clearly expresses defer a functional expression taking 
arguments a, b, and c?

For comparison, named syntax requires 3 lines, since Guido also wants to remove 
suite one-liners in Py3k:

def f1(a, b, c):
  return f(a) + o(b) - o(c)
f1
Not so bad for a single deferred expression (particularly a 
not-completely-trivial one like this), but fares significantly worse for simple 
zero-argument functions, or if you are just setting up a couple of deferred 
expressions in a function call. There's no more virtue in completely squandering 
vertical screen real estate than there is in being overly conservative with it.

What was the point of all this again? Pretending lambda goes away without really killing it? ;-)
Actually, it was started by the please don't take our lamdbas! comments 
regarding Python 3k. I suggested that one of the problems with lambda is that it 
is an expression but looks like a one-liner statement (it's ugly as sin may 
have been closer to my actual phrasing), that the syntax would be deservedly 
rejected if proposed as a new addition to the language, and a more productive 
response might be to consider nicer alternative syntax that Guido would consider 
retaining in Python 3k (since it would make sense to try out such a syntax in 
the Python 2.x series before committing to it for 3.0).

Of course, after making that suggestion, my brain decided to start working on 
its *own* ideas for a more Pythonic syntax (trying to learn from generator 
expressions), which seemed to set off a few other people :)

The name 'deferred expression' is intended to emphasise what I see as the most 
appropriate application for anonymous functions - using an entire named function 
statement to defer a simple expression is serious overkill. Recognising this use 
case was what switched me from I won't miss lambdas to You know, I'd really 
regret it if they disappeared completely.

Basically, I think lambda has a PR problem - its usefulness as a way to defer 
expression evaluation is obscured by its ugly syntax and its current explanation 
as a neutered form of function definition, but at least you can use it in an 
expression.

On backticks, they have a major problem in that many fonts make ` and ' 
virtually indistinguishable. A secondary problem is that printed text often 
renders an opening single quote like a backtick. Guido has already mentioned 
this in one of Python Regrets talks (in the context of the backtick repr 
syntax). So I don't expect any syntax involving backticks to even be looked at 
by the BDFL.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: OT: spacing of code in Google Groups

2005-01-06 Thread Simon Brunning
On Wed, 05 Jan 2005 22:57:33 GMT, JanC [EMAIL PROTECTED] wrote:
 Rectangular selection only works with the mouse in SciTE/Scintilla:
 alt-click-drag.

Nope - hold down alt-shift, and select with the cursor keys.

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python evolution: Unease

2005-01-06 Thread Andrew MacIntyre
On Wed, 5 Jan 2005, John Roth wrote:

 I would like to contribute some documentation to Python.
 I've got the time, I write quite a bit, etc. I've got fairly
 strong opinions about some things that need to be documented,
 (such as all the new style class descriptor stuff from 2.2)
 and I have relatively little difficulty matching the existing style.

 However, I don't
 know TEX, Latex, CVS or Sourceforge. (The latter two are
 on my learn sometime soon so I can put PyFIT where it belongs
 list.)

 I have no desire to install Perl to run the documentation toolchain.
 I also have no particular desire to write up a bunch of final
 format stuff and drop it on someone else to put into the latex
 format so it can be included.

While being able to make doc changes at the Latex level directly into CVS
is the ultimate, Fred Drake and others are quite happy to take straight
text (ReST markup would probably help them a bit) as bugs/patches on
sourceforge.

-
Andrew I MacIntyre These thoughts are mine alone...
E-mail: [EMAIL PROTECTED]  (pref) | Snail: PO Box 370
[EMAIL PROTECTED] (alt) |Belconnen ACT 2616
Web:http://www.andymac.org/   |Australia
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python evolution: Unease

2005-01-06 Thread Nick Coghlan
Carlos Ribeiro wrote:
Couldn't a better document-writing interface be implemented?
Such as:
http://www.python.org/moin/Documentation
Or AMK's annotatable docs:
http://pydoc.amk.ca/frame.html
Something like that?
The docs are great, but it took me some time to find them out after
searching inside Python docs. This is not a minor issue IMHO.
Actually, this is a fair point - I work on isolated machines a lot (i.e. no net 
access), which means I can't get to any of these handy things.

It would be nice if at least some of these things could be bundled with the 
CPython interpreter and linked to from the main documentation (rather than from 
the sidebar menu on the webpage).

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: navigating/changing directories

2005-01-06 Thread Kartic
 /this/directory when I exit the script.  Is it possible to have a
script
 that can drop me off into a different directory than where I
initiated it
 from?

Use os.chdir(newpath)

So, you can code os.chdir(r'/a/totally/different/directory') and find
yourself in /a/totally/different/directory after the script completes.
Thanks,
--Kartic

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


Re: navigating/changing directories

2005-01-06 Thread Kartic
Hmmm... I take it back... that is not working! I think it changes the
path only during execution time.

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


Re: Python evolution: Unease

2005-01-06 Thread Nick Coghlan
[Daniel Bowett]
#- Contribute to where on Sourceforge??? Which domentation are
#- we talking
#- about in general?
Speaking of docs. . . I think it would help a great deal if the python.org 
version-specific documentation pages used the standard documentation front page 
that actually includes the About the Python Documentation link that explains 
how to do this.

Compare:
http://www.python.org/doc/2.4/
To:
http://www.python.org/dev/doc/devel/
Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python evolution: Unease

2005-01-06 Thread Alex Martelli
Robert Kern [EMAIL PROTECTED] wrote:
   ...
  I love eric3, but if you're an eclipse fan, look at enthought's
  envisage IDE -- it seems to me that it has superb promise.
   ...
  Is it available for download somewhere?
 
 Alex is, I think, jumping the gun a bit. Envisage isn't quite ready for
 prime time as your day to day IDE. It might be useful to you right now

I apologize if I gave a misleading impression: I did not mean it was
ready to use, or _already_ here; I suggested looking at in the sense
of paying attention to, and specifically mentioned promise.

Since the subthread was about future IDE developments, I thought it was
appropriate to mention envisage, in the context of comparisons with
eclipse's plugin-centered architecture.

 as a platform to build a dynamic GUI application (Envisage's intended
 use) if you are willing to get your hands dirty and help us build 
 Envisage. Hence, it is not being advertised widely.

I saw a Pycon proposed talk about it, so I didn't stop to consider the
not advertised widely issue.  Thinking about it, I realize Pycon is
almost 3 months from now, so wanting to enthuse about envisage then
doesn't imply already wanting to widely advertise it now; sorry.

 But Alex is right; Envisage does hold a lot of promise.

The very concept of an architecture based on a spare skeleton and
copious plugins is intrinsically excellent, and I think that by now
eclipse has proven it's also practically viable for real-world powerful
IDEs/platforms/frameworks.


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


Re: Is there any way/where to subscribe for automated PEP status emails?

2005-01-06 Thread Nick Coghlan
Thomas Heller wrote:
You could probably subscribe to python-checkins, and filter it.
Or read it via gmane.
Hmm - can SF be used to setup a mailing list just for checkins to a single 
directory in the source tree?

If so, that would seem to be an easy way to provide a python-pep-updates mailing 
list.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: navigating/changing directories

2005-01-06 Thread Nick Coghlan
The script is executed in a process separate from your command shell, and hence 
has no effect on your shell's current directory.

There are some things that batch files and shell scripts are still good for - 
manipulating the shell :)

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there any way/where to subscribe for automated PEP status emails?

2005-01-06 Thread Thomas Heller
Nick Coghlan [EMAIL PROTECTED] writes:

 Thomas Heller wrote:
 You could probably subscribe to python-checkins, and filter it.
 Or read it via gmane.

 Hmm - can SF be used to setup a mailing list just for checkins to a
 single directory in the source tree?

Yes.  You should suggest this on python-dev.

 If so, that would seem to be an easy way to provide a
 python-pep-updates mailing list.

 Cheers,
 Nick.

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


Re: Cookbook 2nd ed Credits

2005-01-06 Thread Alex Martelli
Steve Holden [EMAIL PROTECTED] wrote:
   ...
   1: 25 u'Luther Blissett'
   2: 21 u'Alex Martelli'
   ...
 And I *still* think we deserve to be told the Luther Blissett story ...
 
 conspiratorial-ly y'rs  - steve

Martin Elster's post back in Aug '02 already had just about all of the
necessary info...:

'''
I had just been reading about Luther Blissett, and this name is a sort
of umbrella name that is available for anyone that is interested, and
that has been used in different underground projects and pranks,
especially in Italy.
'''

Add other well-known facts, such as the fact that Bologna is or was a
hotbed of situationist pranks, Umberto Eco is a professor at Bologna
University, Umberto Eco's best-known historical novels from The Name of
the Rose onwards may be interestingly compared with Luther Blissett's
Q, and so forth, and I'm sure you can design a perfectly adequate
conspiracy theory.


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


Re: Python evolution: Unease

2005-01-06 Thread gabriele renzi
Alex Martelli ha scritto:

But Alex is right; Envisage does hold a lot of promise.

The very concept of an architecture based on a spare skeleton and
copious plugins is intrinsically excellent, and I think that by now
eclipse has proven it's also practically viable for real-world powerful
IDEs/platforms/frameworks.
I think this had been demonstrated from emacs long before :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python evolution: Unease

2005-01-06 Thread Carlos Ribeiro
On Thu, 06 Jan 2005 22:11:22 +1000, Nick Coghlan [EMAIL PROTECTED] wrote:
 Carlos Ribeiro wrote:
  Couldn't a better document-writing interface be implemented?
 
 Such as:
 http://www.python.org/moin/Documentation
 
 Or AMK's annotatable docs:
 http://pydoc.amk.ca/frame.html

Sorry, I wasn't clear. Both are clear steps in the right direction. I
was thinking more along the lines of an automated document processing
service, to avoid the need to install all the tools to generate the
official Python docs (latex, sgml, etc.). One could simply upload
a revised doc and get the processed result back. Of course, such a
service can't be open to the public, but it would still be useful.

-- 
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: [EMAIL PROTECTED]
mail: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Nevow Tutorial and sample app

2005-01-06 Thread mirnazim
Hi,

Can any one redirect me to a good nevow tutorial and/or a an appliction
that is niether too big nor too small and can be help in learning
nevow. Nevow tutorial with the distrubution is too simple and it
doesnot even skim the surface. Another one
http://www.nevow.com/Nevow2004Tutorial.html is good but the does not
conform to the current nevow relaese(0.3). e.g. its says

from nevow.rend import htmlfile

while as htmlfile is actually in loaders module.

thanks


Mir Nazim

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


parameterized metaclass (or metametaclass)

2005-01-06 Thread Antoine Pitrou

Hi,

I've been looking at writing parameterized metaclasses and here are the
two solutions I've come to:
(my goal was to build a way to automatically add a hash function that
would take into account a selected list of object attributes)

1. all-in-one metametaclass:

class Autohash2(type):

Metametaclass that instantiates into a metaclass creating
a hash function based on the attributes passed on instantiation.

def __new__(cls, hash_attributes):
def class_new(cls, name, bases, d):
print New class, name
l = hash_attributes
_hash = hash
_tuple = tuple
c = _hash(_tuple([_hash(k) for k in l]))
def object_hash(obj):
g = obj.__getattribute__
return _hash(_tuple([_hash(g(k)) for k in l]))
d['__hash__'] = object_hash
return super(Autohash2, cls).__new__(cls, name, bases, d)
name = '__private'
bases = (type,)
d = {'__new__': class_new}
print New metaclass, name
return type.__new__(cls, name, bases, d)

2. with the metametaclass property slightly abstracted away:

class Metametaclass(type):
def __new__(cls, name, bases, dict_):
d = { '__new__': dict_['class_new'] }
def meta_new(cls, *args, **kargs):
print New metaclass
name = '__private'
bases = (type,)
return super(Metametaclass, cls).__new__(cls, name, bases, d)
dict_['__new__'] = meta_new
print New metametaclass, name
return type.__new__(cls, name, bases, dict_)

class Autohash(type):
__metaclass__ = Metametaclass

def __init__(cls, hash_attributes):
cls.hash_attributes = hash_attributes

def class_new(cls, name, bases, d):
print New class, name
l = cls.hash_attributes
_hash = hash
_tuple = tuple
c = _hash(_tuple([_hash(k) for k in l]))
def object_hash(obj):
g = obj.__getattribute__
return _hash(_tuple([_hash(g(k)) for k in l]))
d['__hash__'] = object_hash
return super(Autohash, cls).__new__(cls, name, bases, d)


Both of those metametaclasses can be used (successfully!) in the
following way:

class Address(object):
__metaclass__ = Autohash3(('host', 'port'))
# snip rest of class definition

a = Address()
a.host = 'localhost'
a.port = 
b = copy.copy(a)
hash(a) == hash(b)


I was wondering if there is some simpler way of building parameterized
metaclasses ?

Regards

Antoine.


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


Re: get the IP address of a host

2005-01-06 Thread J Berends
Lee Harr wrote:
I found that the socket solutions only work if your
DNS entries are correct ... which in my case was not
true. So I came up with this:
That is indeed correct, and even if the DNS entries are correct at times 
it does not give the full list of IPs by gethostbyname or gethostbyaddr.

import commands
ifconfig = '/sbin/ifconfig'
# name of ethernet interface
iface = 'eth0'
# text just before inet address in ifconfig output
telltale = 'inet addr:'
...

Basically, it scrapes the output from ifconfig for the
actual address assigned to the interface. Works perfectly
on FreeBSD and Linux (given the correct configuration).
Nice way, have to device something for windows than.
From several approached I came up with the following code:
def getipaddr(hostname='default'):
Given a hostname, perform a standard (forward) lookup and return
a list of IP addresses for that host.
if hostname == 'default':
hostname = socket.gethostname()
ips = socket.gethostbyname_ex(hostname)[2]
ips = [i for i in ips if i.split('.')[0] != '127']
if len(ips) != 0:
# check if we have succes in determining outside IP
ip = ips[0]
elif len(ips) == 0 and hostname == socket.gethostname():
# when we want to determine local IP and did not have succes
# with gethostbyname_ex then we would like to connect to say... 

# google.com and determine the local ip address bound to the
# local socket.
try:
s = socket.socket()
s.connect(('google.com', 80))
print ('___ connecting to internet to determine local ip')
ip = s.getsockname()[0]
del s
except:
print ('*** cannot connect to internet in order to \
   determine outside IP address')
raise Exception
if len(ip) != 0:
return ip
else:
print ('*** unable to determine outside IP address')
raise Exception
It returns the IP address with which it connects to the world (not lo), 
might be a pvt LAN address or an internet routed IP. Depend on where the 
host is.

I hate the google trick actually, so any suggestions to something better 
is always welcome.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python evolution: Unease

2005-01-06 Thread Robert Kern
Alex Martelli wrote:
Robert Kern [EMAIL PROTECTED] wrote:
   ...
I love eric3, but if you're an eclipse fan, look at enthought's
envisage IDE -- it seems to me that it has superb promise.
   ...
Is it available for download somewhere?
Alex is, I think, jumping the gun a bit. Envisage isn't quite ready for
prime time as your day to day IDE. It might be useful to you right now

I apologize if I gave a misleading impression: I did not mean it was
ready to use, or _already_ here; I suggested looking at in the sense
of paying attention to, and specifically mentioned promise.
Since the subthread was about future IDE developments, I thought it was
appropriate to mention envisage, in the context of comparisons with
eclipse's plugin-centered architecture.
The subthread was? Okay. Never mind me, then. The threading got broken 
up in my newsreader and I couldn't tell the context.

as a platform to build a dynamic GUI application (Envisage's intended
use) if you are willing to get your hands dirty and help us build 
Envisage. Hence, it is not being advertised widely.

I saw a Pycon proposed talk about it, so I didn't stop to consider the
not advertised widely issue.  Thinking about it, I realize Pycon is
almost 3 months from now, so wanting to enthuse about envisage then
doesn't imply already wanting to widely advertise it now; sorry.
No worries.
The SVN repository address isn't being kept secret, just not advertised 
much. If anyone is interested in anonymous read-access, they can ask me 
for the address.

--
Robert Kern
[EMAIL PROTECTED]
In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die.
  -- Richard Harter
--
http://mail.python.org/mailman/listinfo/python-list


Re: get the IP address of a host

2005-01-06 Thread Nick Coghlan
J Berends wrote:
Lee Harr wrote:
Basically, it scrapes the output from ifconfig for the
actual address assigned to the interface. Works perfectly
on FreeBSD and Linux (given the correct configuration).

Nice way, have to device something for windows than.
Use the same approach, but scrape the output of ipconfig instead. Use subprocess 
to run the command in Python 2.4, or work something out with one of the popen 
variants for earlier versions.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: file.readlines() - gives me error (bad file descriptor)

2005-01-06 Thread Abhijit Soman
[EMAIL PROTECTED] wrote:
Hey guys,
I can't figure this one out, why is this simple script giving me
problems?
logfile=file(r'test.txt','w')
logfile.write('datetime')
test=logfile.readlines()
When I run it I get the error message:
Traceback (most recent call last):
File C:\Documents and Settings\Gregory\My Documents\Get New Great
Job\testfile.py, line 3, in ?
test=logfile.readlines()
IOError: [Errno 9] Bad file descriptor
I'm running Windows XP, Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC
v.1200 32 bit (Intel)] on win32
Any help would be greatly appricated.
Thanks,
Greg
As logfile is opened in write mode you cannot read it. You've to open it
in read mode for reading.
Greetings,
Abhijit
--
Everybody wants to go to heaven but nobody wants to die
--
http://mail.python.org/mailman/listinfo/python-list


Re: get the IP address of a host

2005-01-06 Thread P
J Berends wrote:
def getipaddr(hostname='default'):
[snip]
It returns the IP address with which it connects to the world (not lo), 
might be a pvt LAN address or an internet routed IP. Depend on where the 
host is.

I hate the google trick actually, so any suggestions to something better 
is always welcome.
Yes your IP is determined really by what you connect to.
So I did essentially the same as you.
For reference see getMyIPAddress() at the following:
http://www.pixelbeat.org/libs/PadSocket.c
Pádraig
--
http://mail.python.org/mailman/listinfo/python-list


Re: get the IP address of a host

2005-01-06 Thread Jp Calderone
On Thu, 06 Jan 2005 14:35:16 +0100, J Berends [EMAIL PROTECTED] wrote:

  From several approached I came up with the following code:
 
 def getipaddr(hostname='default'):
  Given a hostname, perform a standard (forward) lookup and return
  a list of IP addresses for that host.
  if hostname == 'default':
  hostname = socket.gethostname()
  ips = socket.gethostbyname_ex(hostname)[2]
  ips = [i for i in ips if i.split('.')[0] != '127']
  if len(ips) != 0:
  # check if we have succes in determining outside IP
  ip = ips[0]
  elif len(ips) == 0 and hostname == socket.gethostname():
  # when we want to determine local IP and did not have succes
  # with gethostbyname_ex then we would like to connect to say... 
 
  # google.com and determine the local ip address bound to the
  # local socket.
  try:
  s = socket.socket()
  s.connect(('google.com', 80))
  print ('___ connecting to internet to determine local ip')
  ip = s.getsockname()[0]

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('1.2.3.4', 56))
ip = s.getsockname()[0]


  del s
  except:
  print ('*** cannot connect to internet in order to \
 determine outside IP address')
  raise Exception
  if len(ip) != 0:
  return ip
  else:
  print ('*** unable to determine outside IP address')
  raise Exception
 
 It returns the IP address with which it connects to the world (not lo), 
 might be a pvt LAN address or an internet routed IP. Depend on where the 
 host is.
 
 I hate the google trick actually, so any suggestions to something better 
 is always welcome.

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


Re: navigating/changing directories

2005-01-06 Thread Cameron Laird
In article [EMAIL PROTECTED],
Nick Coghlan  [EMAIL PROTECTED] wrote:
The script is executed in a process separate from your command shell, and 
hence 
has no effect on your shell's current directory.

There are some things that batch files and shell scripts are still good for - 
manipulating the shell :)
.
.
.
For more on this subject, see URL:
http://phaseit.net/claird/comp.unix.misc/changing_directories.html .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: navigating/changing directories

2005-01-06 Thread Steve Holden
skip wrote:
A simple script like the one below lets me jump through a directory 
structure.  However, if I run it from /this/directory and within it to go to 
/a/totally/different/directory...  I'm still actually going to be in 
/this/directory when I exit the script.  Is it possible to have a script 
that can drop me off into a different directory than where I initiated it 
from?

import os
process = 1
while (process):
# Display directories
for i in os.listdir(os.getcwd()):
if (os.path.isdir(os.path.join(os.getcwd(),i))):
print i
# Change directory
goto_dir = raw_input(: )
if (goto_dir in os.listdir(os.getcwd())):
os.chdir(os.path.join(os.getcwd(),goto_dir))
else:
process = 0 # Exit

As has already been reported, under Linux a change to the current 
working directory won't affect the environment of the parent process. 
You may find that under some Windows command line interpreters that the 
 change to the working directory made by a program persists into the 
interactive session that triggered the program.

One way to achieve your desired goal, of course, is to call your program 
using a shell expansion sequence (assuming Unix-like shell 
environments), as in:

cd `myprogram.py`
and then if your program outputs the path to a directory your shell's 
current working directory will be chaged as you require.

there's-always-a-way-ly y'rs  - steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


sorting on keys in a list of dicts

2005-01-06 Thread J Berends
Suppose I have a list of dictionaries and each dict has a common keyname 
with a (sortable) value in it.

How can I shuffle their position in the list in such way that they 
become sorted.

Maybe I am doing it wrongly and you would say: why don't you get 
yourself a (slimmed-down) implementation of a database class. But then 
please guide me on the right path without having to install a xxSQL 
server for my multiplatform code.
--
http://mail.python.org/mailman/listinfo/python-list


Re: logging from severl classes

2005-01-06 Thread flupke
Vinay Sajip wrote:
It works for me:
#file3.py
import file1
import file2
a = file1.A()
b = file2.B()
b.otherfunction()
gives
2004-12-28 00:18:34,805 DEBUG file2 6 creating class B
2004-12-28 00:18:34,805 DEBUG file2 9 in otherfunction
yeah, the classes where a simplification of the classes i'm using and 
used these to just show what i wanted to do without testing them.
they indeed work. strange.
Thanks for your answer

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


Re: sorting on keys in a list of dicts

2005-01-06 Thread Jp Calderone
On Thu, 06 Jan 2005 15:31:22 +0100, J Berends [EMAIL PROTECTED] wrote:
Suppose I have a list of dictionaries and each dict has a common keyname 
 with a (sortable) value in it.
 
 How can I shuffle their position in the list in such way that they 
 become sorted.
 

  In Python 2.4,

import operator
L.sort(key=operator.itemgetter(key))

  In Python 2.3,

L2 = [(d[key], i, d) for (i, d) in enumerate(L)]
L2.sort()
L = [d for (v, i, d) in L2]

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


Re: The Industry choice

2005-01-06 Thread Steve Holden
Bulba! wrote:
On 04 Jan 2005 19:25:12 -0800, Paul Rubin
http://[EMAIL PROTECTED] wrote:

Rob Emmons [EMAIL PROTECTED] writes:
Me personally, I believe in free software, but always talk about open
source.  My answer regarding forcing people to share -- I like the GPL 
-- and I am perfectly happy to have anyone who does not like the GPL 
not to use any GPLed software.  I don't feel compelled to share.

I'd go further.  It's not possible to force anyone to share, but the
GPL aims to remove software from a system that instead aims to force
people NOT to share.

Nope. IMHO, GPL attempts to achieve the vendor lock-in. For different
purposes than another well-known vendor, but it still does.
Well you are entitled to your opinion. But *my* opinion is that the GPL 
attempts to ensure that if you re-use code by an author who so desires, 
then redistribution of your code is only possible by making your own 
extensions to it available on the same terms. This gives you a clear choice.

To put it another way, it allows an author to specify that their code 
can't be hijacked for proprietary purposes *in distributed programs*. I 
will specifically point out that there is *nothing* in the GPL that 
requires you to reveal the source of program you write but do not 
distribute, even when such programs incorporate tons of GPL'd code.

It's actually even worse: the only thing you can't share  on a
well-known vendor's platform is the software written by that
well-known vendor -- you can choose to share or choose not to 
share whatever you or other people write on this platform. 

Well that's way over-simplified. And if you mean Microsoft, *say*( 
Microsoft. And you certainly can't share GPL'd code on Windows without 
doing so under the terms required by the GPL.

If GPL folks had their way, it would not be possible not to share
_anything_ you create. It is widely acknowledged that GPL
license has the viral aspect of extending itself on your 
software - can you point to closed-source licenses that would 
have this aspect? None of the licenses I've read except GPL has 
this aspect.  LGPL is still a different story, though.

The GPL folks are quite happy to have you share anything that *you* 
create. Their simply-stated and elegantly-achieved intent is that you 
don't share anything that *they* create except on the terms they have 
required for their creations.

So, it seems to me, you are whining because the authors of GPL'd code 
don't want you to release *their* code except under the GPL. What gives 
*you* the right to dictate to them? How would you like it if Richard 
Stallman insisted that you release your code under the GPL? Which, of 
course, he doesn't.

As the MPAA knows, people do want to share, and
forcing them not to do so is impossible without turning the world into
a police state. 

Socialism is unpopular for many reasons, and many of them are indeed to 
do with maintaining the separation between individuals and thereby 
retaining the ability to treat them as separate economic units. But we 
aren't going to change that by insisting on particular software 
licenses. Realize this is a very small part of a very large debate.
What's the cost of copying music files vs cost of combining 
some programs together, even in the form of e.g. using an
external library?


Maybe if Python were GPL, then Bulba wouldn't use it,
but since it's not GPL, some people find themselves much less willing
to contribute to it than if it were GPL.  

And that is their choice. They should realize, however, that some 
licenses (including the more recent Python licenses) are cleared as 
GPL-compatible. I believe this means that if I receive software 
licensed under a GPL-compatible license, I am at liberty to distribute 
it under the GPL.

I suspect that this point is far too infrequently stressed.
Personally, I have precisely opposite impression: the OSS licensed
with BSD/MIT/Artistic/Python-like license gets contributed to a lot
simply because people like to use it and they are not afraid of
licensing issues. 

This merely goes to show that different people can form different 
impressions when discussing the same sets of facts, and therefore how 
useless impressions are as the basis for rational discussion.

When people share:
_it is not because this or that license of software used by them says
so, but because they want to for reasons orthogonal to licensing
issues_.
Absolutely not. Some people want to share under very specific 
conditions, hence the proliferation of licenses in the open source world.


(I myself contribute bug
reports and maybe small patches, but resist larger projects since
there are GPL'd things that I can do instead).  So catering to the
wishes of Bulba and Microsoft may actually be impeding Python
development.  Yes, there are some people selfless enough to do long
and difficult unpaid software tasks so that Bulba and Bill G can get
richer by stopping people from sharing it, but others of us only want
to do unpaid 

Re: sorting on keys in a list of dicts

2005-01-06 Thread Paul Rubin
J Berends [EMAIL PROTECTED] writes:
 Suppose I have a list of dictionaries and each dict has a common
 keyname with a (sortable) value in it.
 
 How can I shuffle their position in the list in such way that they
 become sorted.

Do I understand the question right?  Can't you just say

  thelist.sort(lambda x,y: cmp(x['keyname'], y['keyname']))

or something like that?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2005-01-06 Thread Steve Holden
Bulba! wrote:
On Wed, 5 Jan 2005 11:19:56 +0100, [EMAIL PROTECTED] (Alex Martelli)
wrote:
[...]
You see, I'm not disagreeing with you that your model applies
_where it applies_. I only disagree that it applies in face of
stronger forces. Now what kind of forces is dominant in 
most frequent scenarios would have to be worked out in tedious
empirical research I think. Which I haven't done, because
learning some economics is just a hobby to me.

Yes, by all means let's just spout our opinions without any of that 
inconvenient tedious empirical research which might invalidate them.

[...]
Italian, at most German and French, and not Polish or Russian, closeness
to good international airports and other good transportation, closeness
to partner firms and potential customers' decision-makers, all appeared
to point to Warsaw, if I recall correctly.  Mechanical engineers with
some programming experience or viceversa, good translators, and good
salespeople with connections in the mechanical industry, are not as
ultra-specialized as all that, after all.

Most sales offices in Warsaw do not employ esp. educated people in
my impression. OTOH, the carmaking facilities nowadays require 
more much more know-how and specialized workforce than a sales 
office does. Or at least that was my impression when I worked at 
the construction machine manufacturer in Berlin. 

Again you are forming impressions form rather limited evidence: I might 
agree with you about the relative intelligence and education of 
engineers over sales people, but that might be *my* bias showing.

Capital investments per worker in auto industries are reportedly 
very high. Simple physical tasks are done largely by machines, 
like this 100 million Deutschmark costing laser-cutting installation
that I've seen there, where a pile of iron bars is pulled in at one
end and the pile of ready components is spitted out of the other end
(unlike typical thermal cutting,  laser has the advantage of not
destroying the metal structure adjacent to the cut, so the parts 
of the machines subject to high-stress are oft produced this way). 

The same is true of plasma-arc cutting for thicker steels, and I believe 
it's still not possible to cut 3-inch stainless with a laser. But what's 
your point?

Oh, and by the way that installation doesn't get used much.
Somebody at the office didn't check carefully enough the
energy prices before ordering it and later someone discovered 
that off-site specialized cutting firms that take advantage of 
energy available at low prices at special times in other countries
can get it produced cheaper. Moving it elsewhere or selling
is not an option, since it is a specially constructed, low, 50-meters
long hall that stands inside the huge manufacturing hall of the
company.

And you are using this example to try and argue that engineers are 
better-educated than sales people? Who sold this installation? Who 
bought it? How much, therefore, is education worth?

100 million DM (when 1 DM was worth some half of Euro 
back then) down the drain. When the company was in rather
bad financial situation (later I've learned it was finally bought
out by Americans). Oh well. No big deal.

I was utterly shocked. Having grown up in Soviet times I have
been used to seeing precious resources wasted by organizations
as if resources were growing on trees, but smth like this?! In a
shining ideal country of Germany?! Unthinkable.
Indeed not. Quite often the brown paper bag is a factor in purchases 
like this. I wouldn't be at all surprised if somebody with a major input 
to the decision-making process retired to a nice place in the country 
shortly afterwards. You appear to be making the mistake of believing 
that people will act in the larger interest, when sadly most individuals 
tend to put their own interests first (some would go as far as to define 
self-interest as the determinant of behavior).

The firm I was working for had a consensus decision-making process (even
I was involved) and managers (and other employees) and stockholders were
mostly the same people -- it wasn't all that large a firm at the time.
Nobody needed to practice risk avoidance.  

Again, you may have had good luck. Where I worked (including
some places in Germany and UK) it was almost the only factor 
that seemed to matter to people - they'd do ANYTHING not to 
take a risky decision, to pass the buck, not to stick their necks
out, not to declare doing some work that involved challenges.

Some people are like that. I chose a long time ago to try not to work 
with them whenever I could avoid it and, while that may have had 
negative economic consequences I an convinced it has improved my quality 
of life immensely. Of course, I have no proof for such an assertion.

[and on, and on, and on ...]
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--

Re: The Industry choice

2005-01-06 Thread Alex Martelli
Roel Schroeven [EMAIL PROTECTED] wrote:

 Can you point to closed-source licenses that allow using the code *at
 all*?

As I recall, for example, Microsoft Visual C++ came with sources for
various libraries; all that the (closed-source) license for those
libraries forbade you from doing was to further distribute the _sources_
themselves.  You could do modifications big or small to those libraries
for whatever purposes, and redistribute the _compiled_ form of the code
as a DLL, or statically linked into your own programs, etc, etc.

Is this what you mean by allow using the code *at all*?  I think it's
a pretty common arrangement when the code being sold under closed-source
terms is a set of libraries, or a development system part of whose value
is a set of accompanying libraries.


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


Re: sorting on keys in a list of dicts

2005-01-06 Thread J Berends
Jp Calderone wrote:
On Thu, 06 Jan 2005 15:31:22 +0100, J Berends [EMAIL PROTECTED] wrote:
Suppose I have a list of dictionaries and each dict has a common keyname 
with a (sortable) value in it.

How can I shuffle their position in the list in such way that they 
become sorted.


  In Python 2.4,
import operator
L.sort(key=operator.itemgetter(key))
  In Python 2.3,
L2 = [(d[key], i, d) for (i, d) in enumerate(L)]
L2.sort()
L = [d for (v, i, d) in L2]
  Jp
the 2.3 version seems to work quite nicely! thanks. Using the 2.3 for 
version compatibility. Thanks!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Embedding a restricted python interpreter

2005-01-06 Thread Peter Maas
Craig Ringer schrieb:
That is my understanding. In fact, I'd say with Python it's nearly
impossible given how dynamic everything is and the number of tricks that
can be used to obfuscate what you're doing. Think of the fun that can be
had with str.encode / str.decode and getattr/hasattr .
It would certainly be difficult to track all harmful code constructs.
But AFAIK the idea of a sandbox is not to look at the offending code
but to protect the offended objects: files, databases, URLs, sockets
etc. and to raise a security exception when some code tries to offend
them. Jython is as dynamic as C-Python and yet it generates class
files behaving well under the JVM's security regime.
I looked into this, and my conclusion ended up being Well, I'm using
Python because I want it's power and flexibilty. If I want a secure
scripting environment, I should use something like Lua or Qt Script for
Applications instead.
It would be good for Python if it would offer a secure mode. Some
time ago I asked my hosting provider whether I could use mod_python
with apache to run Python scripts in the same way as PHP scripts.
He denied that pointing to Python security issues and to PHP safe.
mode. Python IS powerful but there are many areas where it is of
vital interest who is allowed to use its power and what can be done
with it. I think it would be a pity to exclude Python from these
areas where a lot of programming/computing is done.
Python is a very well designed language but progress is made by
criticism not by satisfaction ;)
--
---
Peter Maas,  M+R Infosysteme,  D-52070 Aachen,  Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
---
--
http://mail.python.org/mailman/listinfo/python-list


2 versions of python on 1 machine

2005-01-06 Thread flupke
I searched with Google and on this newsgroups and i didn't find any info 
regarding this. If there is more info, please redirect me to that info.

I have version 2.3.4 and 2.4 installed on windows and i thought that by 
switching the PYTHONPATH parameter to the dir of the 2.4 version that 
that would make python 2.4 active.

However when i envoke python from the commandline, it still runs 2.3.4
Is it possible to have 2 versions installed and switching versions when
you need to?
How can i do that?
Thanks,
Benedict
--
http://mail.python.org/mailman/listinfo/python-list


Re: parameterized metaclass (or metametaclass)

2005-01-06 Thread michele . simionato
 I was wondering if there is some simpler way of building
parameterized
 metaclasses ?

Why not just a function returning metaclasses?

def metaFactory(*args):
dic = something possibly depending on args
return type(somemetaclass, (type,), dic)

Alternatively, a metaclass classmethod returning a metaclass, so that
you can use something like

__metaclass__ = MyMetaclass.with(*args) # classmethod returning a
metaclass

 Michele Simionato

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


Re: Developing Commercial Applications in Python

2005-01-06 Thread Nick Vargish
[EMAIL PROTECTED] writes:

 Can somebody there to point me any good commercial applications
 developed using python ?

Python is used in several games, including Temple of Elemental Evil
and the forthcoming Civilization 4. Humungous Games, which makes
software for children, is also using Python. Sorry if games would give
your boss the wrong impression...

Most commercial software houses don't advertise details of their
development platforms.

Nick

-- 
#  sigmask  ||  0.2  ||  20030107  ||  public domain  ||  feed this to a python
print reduce(lambda x,y:x+chr(ord(y)-1),' Ojdl!Wbshjti!=obwAcboefstobudi/psh?')
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nevow Tutorial and sample app

2005-01-06 Thread Valentino Volonghi aka Dialtone
[EMAIL PROTECTED] wrote:

 Can any one redirect me to a good nevow tutorial and/or a an appliction
 that is niether too big nor too small and can be help in learning
 nevow. Nevow tutorial with the distrubution is too simple and it

You should probably look at all the examples in the latest svn release.
I've made some changes on the way examples directory work and now you
can run all the examples by just running:

twistd -noy examples.tac

It will create a local webserver at http://localhost:8080/

with an index of all the examples (in difficulty order) with colored
browseable source code and the live example.

Plus you can access each sample application's (like the blog engine or
the interactive chat server, or the pastebin) source code.

Examples should scale well from very simple and basic hello world to
very sophisticated ones like the blog engine which uses also xmlrpc and
smtp protocols, or live pages like chatola.

-- 
Valentino Volonghi aka Dialtone
Now Running MacOSX 10.3.7
Blog: http://vvolonghi.blogspot.com
http://weever.berlios.de
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: get the IP address of a host

2005-01-06 Thread J Berends
Jp Calderone wrote:
On Thu, 06 Jan 2005 14:35:16 +0100, J Berends [EMAIL PROTECTED] wrote:
From several approached I came up with the following code:
def getipaddr(hostname='default'):
Given a hostname, perform a standard (forward) lookup and return
a list of IP addresses for that host.
if hostname == 'default':
hostname = socket.gethostname()
ips = socket.gethostbyname_ex(hostname)[2]
ips = [i for i in ips if i.split('.')[0] != '127']
if len(ips) != 0:
# check if we have succes in determining outside IP
ip = ips[0]
elif len(ips) == 0 and hostname == socket.gethostname():
# when we want to determine local IP and did not have succes
# with gethostbyname_ex then we would like to connect to say... 

# google.com and determine the local ip address bound to the
# local socket.
try:
s = socket.socket()
s.connect(('google.com', 80))
print ('___ connecting to internet to determine local ip')
ip = s.getsockname()[0]

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('1.2.3.4', 56))
ip = s.getsockname()[0]

del s
except:
print ('*** cannot connect to internet in order to \
   determine outside IP address')
raise Exception
if len(ip) != 0:
return ip
else:
print ('*** unable to determine outside IP address')
raise Exception
It returns the IP address with which it connects to the world (not lo), 
might be a pvt LAN address or an internet routed IP. Depend on where the 
host is.

I hate the google trick actually, so any suggestions to something better 
is always welcome.

  Jp
thanks implemented and works like a charm.
--
http://mail.python.org/mailman/listinfo/python-list


File Handling Problems Python I/O

2005-01-06 Thread Josh
Hi,

I am having a problem with Python. I am new to Python as a programming
language, but I do have experience in other languages. I am
experiencing strange problems with File handling and wonder if anyone
else has seen this or knows what I am doing wrong. I am simply trying
to open a file for read and iterate through until the end of file. I am
able to do so without a problem, but here's the catch: The open
statement is only working on certain files. I open a simple text file
say file1.txt without any issues, but I change the open statement to
another text file and it error's out stating the file doesn't exist. I
know the code is correct because it worked for the other file. I have
tried both binary and ascii modes to no avail. Any idea why this is
happening? I am running Python 2.3.4 wxPython 2.5.3.1 and SPE as the
IDE on Win2k. Thanks

Josh

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


Re: Embedding a restricted python interpreter

2005-01-06 Thread Paul Rubin
Jp Calderone [EMAIL PROTECTED] writes:
   A Python sandbox would be useful, but the hosting provider's excuse
 for not allowing you to use mod_python is completely bogus.  All the 
 necessary security tools for that situation are provided by the 
 platform in the form of process and user separation.

But mod_python is an apache module and runs in the same apache process
with other users' scripts.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: File Handling Problems Python I/O

2005-01-06 Thread Batista, Facundo
Title: RE: File Handling Problems Python I/O





[Josh]


#- able to do so without a problem, but here's the catch: The open
#- statement is only working on certain files. I open a simple text file
#- say file1.txt without any issues, but I change the open statement to
#- another text file and it error's out stating the file 
#- doesn't exist. I
#- know the code is correct because it worked for the other file. I have
#- tried both binary and ascii modes to no avail. Any idea why this is
#- happening? I am running Python 2.3.4 wxPython 2.5.3.1 and SPE as the
#- IDE on Win2k. Thanks


Could you please post the actual code?


Also, post the result to the following: os.listdir('.').


. Facundo


Bitácora De Vuelo: http://www.taniquetil.com.ar/plog
PyAr - Python Argentina: http://pyar.decode.com.ar/



  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

ADVERTENCIA.


La información contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener información confidencial o propietaria, cuya divulgación es sancionada por la ley.

Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no está autorizado a divulgar, copiar, distribuir o retener información (o parte de ella) contenida en este mensaje. Por favor notifíquenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magnético) que pueda haber realizado del mismo.

Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telefónica Comunicaciones Personales S.A. o alguna empresa asociada.

Los mensajes electrónicos pueden ser alterados, motivo por el cual Telefónica Comunicaciones Personales S.A. no aceptará ninguna obligación cualquiera sea el resultante de este mensaje.

Muchas Gracias.



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

Re: Developing Commercial Applications in Python

2005-01-06 Thread Stephen Waterbury
Nick Vargish wrote:
[EMAIL PROTECTED] writes:
Can somebody there to point me any good commercial applications
developed using python ?
Python is used in several games  ...
Also see Python Success Stories:  http://pythonology.org/success
A notable example is Verity's search engine -- see
http://python.oreilly.com/news/PythonSS.pdf
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: OT: spacing of code in Google Groups

2005-01-06 Thread Peter Hansen
Jacek Generowicz wrote:
Peter Hansen [EMAIL PROTECTED] writes:
Why the heck would I ever have to do rectangle operations on a
regular basis?  ;-)
Well, given that all editors are cat equivalent[*], you don't _have_
to use any of their features :-)
This cat equivalent thing is a red-herring.  I can rarely type more
than a line of code without making a typographical error.  Sometimes
I won't catch that error until a bit later.  Using cat alone would
provide me little opportunity to fix the error, so I would never
be able to produce a working program longer than a few lines.
You might call this simply less productive (though I'd argue
it becomes a qualitative difference).  But, okay, let's work from there...
But just like Python (particularly in the hands of a skilled Python
programmer) is more productive than a Turing Machine, any featureful
editor (in the hands of an experienced user) is far more productive
than cat  file.
I don't disagree.  I do, however, claim that the set of features
that are required to make *me* orders of magnitude more productive
than cat (to use your quantitative comparison) is very, very small.
And that I use less than 2% of the features most editors have.
And that if a programmer with equal abilities managed to learn to
use 98% of the features of such an editor, such that he could
readily use whichever such feature was most effective at any given
time, he would not be more than 10% more effective than I am.
But the whole argument is fairly moot...  I've needed a rectangle
operation only once in the last ten years, and if I hadn't known at
the time that my editor could do it (and spent about half an hour
figuring out how it worked), I could have written a utility to
do the job faster if I'd been using Python at the time...
Cheers,
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Embedding a restricted python interpreter

2005-01-06 Thread Steve Holden
Jp Calderone wrote:
[...]

  A Python sandbox would be useful, but the hosting provider's excuse
for not allowing you to use mod_python is completely bogus.  All the 
necessary security tools for that situation are provided by the 
platform in the form of process and user separation.
Not sure this is strictly true: mod_python gets loaded into the server's 
address space and gives the ability to add any type of handler. While 
Apache might well be able to respawn failed subprocesses, it's not 
something that most hosting providers would like to have to do all the 
time for many hosted sites.

regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


PyAr - Python Argentina 5th Meeting, Thursday, January 13th

2005-01-06 Thread Batista, Facundo
Title: PyAr - Python Argentina 5th Meeting, Thursday, January 13th





The Argentinian Python User Group, PyAr, will have its fifth
meeting this Thursday, January 13th at 7:00pm. Please see 
http://pyar.decode.com.ar/Wiki/ProximaReunion for details (in
Spanish.)



Agenda
--


Despite our agenda tends to be rather open, this time we would
like to cover these topics:


- Planning of our first sprint: we actually have two main subjects:
 Messages Queues Manager with interfaces for SMTP (e-mail), SMPP
 (SMS) and MM7 (MMS); and Genetic Algorithms.
- Website organization  content
- Means of promoting the group's activities, in order to increase
 our member base.


 
Where
-


We're meeting at Hip Hop Bar, Hipólito Yirigoyen 640, Ciudad de Buenos
Aires, starting at 19hs. We will be in the back room, so please ask
the barman for us.



About PyAr
--


For more information on PyAr see http://pyar.decode.com.ar (in Spanish), 
or join our mailing list (Also in Spanish. For instructions see 
http://pyar.decode.com.ar/Members/ltorre/listademail)


We meet on the second Thursday of every month.


. Facundo


  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

ADVERTENCIA.


La información contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener información confidencial o propietaria, cuya divulgación es sancionada por la ley.

Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no está autorizado a divulgar, copiar, distribuir o retener información (o parte de ella) contenida en este mensaje. Por favor notifíquenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magnético) que pueda haber realizado del mismo.

Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telefónica Comunicaciones Personales S.A. o alguna empresa asociada.

Los mensajes electrónicos pueden ser alterados, motivo por el cual Telefónica Comunicaciones Personales S.A. no aceptará ninguna obligación cualquiera sea el resultante de este mensaje.

Muchas Gracias.



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

Re: Embedding a restricted python interpreter

2005-01-06 Thread Jp Calderone
On 06 Jan 2005 07:32:25 -0800, Paul Rubin http://phr.cx@nospam.invalid 
wrote:
Jp Calderone [EMAIL PROTECTED] writes:
A Python sandbox would be useful, but the hosting provider's excuse
  for not allowing you to use mod_python is completely bogus.  All the 
  necessary security tools for that situation are provided by the 
  platform in the form of process and user separation.
 
 But mod_python is an apache module and runs in the same apache process
 with other users' scripts.

  I am uncertain as to how this differs from mod_php (the alternative 
discussed in the OP's story).  I've been away from PHP for a while, so 
perhaps mod_php has gained some features of which I am unaware?

  Jp

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


Re: 2 versions of python on 1 machine

2005-01-06 Thread Aaron Bingham
flupke wrote:
I have version 2.3.4 and 2.4 installed on windows and i thought that by 
switching the PYTHONPATH parameter to the dir of the 2.4 version that 
that would make python 2.4 active.

However when i envoke python from the commandline, it still runs 2.3.4
Is it possible to have 2 versions installed and switching versions when
you need to?
How can i do that?
You need to put the path to the desired version in the PATH environment 
variable.  You shoudn't need to change PYTHONPATH at all.

--

Aaron Bingham
Application Developer
Cenix BioScience GmbH

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


Re: Embedding a restricted python interpreter

2005-01-06 Thread Gerhard Haering
On Thu, Jan 06, 2005 at 07:32:25AM -0800, Paul Rubin wrote:
 Jp Calderone [EMAIL PROTECTED] writes:
A Python sandbox would be useful, but the hosting provider's excuse
  for not allowing you to use mod_python is completely bogus.  All the 
  necessary security tools for that situation are provided by the 
  platform in the form of process and user separation.
 
 But mod_python is an apache module and runs in the same apache process
 with other users' scripts.

Which is why it's a good idea for each customer to have it's own system user
and their virtual hosts running under this uid. Which was the idea for the
perchild MPM for Apache 2 - which is abandoned now :-( muxmpm is a replacement
project in beta.

This really sucks when you use Apache2. I myself did make the switch some time
ago, then noticed that this (for me) important feature was missing. It now
works, somehow, but to make it work properly I'd need to either:

- go back to Apache 1.3.x, missing some nice improvements
- use different webservers per user, put them together with mod_proxy (yuck!)

-- Gerhard


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: File Handling Problems Python I/O

2005-01-06 Thread Arjen Dijkstra
I don't think we can help if you don't post some of your code.
Regards,
Arjen
Josh wrote:
Hi,
I am having a problem with Python. I am new to Python as a programming
language, but I do have experience in other languages. I am
experiencing strange problems with File handling and wonder if anyone
else has seen this or knows what I am doing wrong. I am simply trying
to open a file for read and iterate through until the end of file. I am
able to do so without a problem, but here's the catch: The open
statement is only working on certain files. I open a simple text file
say file1.txt without any issues, but I change the open statement to
another text file and it error's out stating the file doesn't exist. I
know the code is correct because it worked for the other file. I have
tried both binary and ascii modes to no avail. Any idea why this is
happening? I am running Python 2.3.4 wxPython 2.5.3.1 and SPE as the
IDE on Win2k. Thanks
Josh
--
http://mail.python.org/mailman/listinfo/python-list


Re: 2 versions of python on 1 machine

2005-01-06 Thread Peter Hansen
flupke wrote:
I have version 2.3.4 and 2.4 installed on windows and i thought that by 
switching the PYTHONPATH parameter to the dir of the 2.4 version that 
that would make python 2.4 active.
That is not the purpose of PYTHONPATH.  I'd suggest removing
any definition of this environment variable that you have,
unless you have a specific reason to use it and know what it
actually does.  I believe the docs on it are fairly clear,
so reading them again might help.  Note that if you have installed
both versions of Python using the regular installer, the
PYTHONPATH information would be redundant anyway because
each version puts the necessary info in the Windows registry.
However when i envoke python from the commandline, it still runs 2.3.4
Is it possible to have 2 versions installed and switching versions when
you need to?
It's quite possible.  It sounds like your problem is that you have
the c:\python23 folder in your PATH (note, not PYTHONPATH, just the
old DOS PATH variable).  If that's the case, you should probably
remove it and use batch files to invoke the different versions
instead.
How can i do that?
On my machine, I have a folder called c:\bin where I put useful
batch files.  I have a python23.bat and a python24.bat file,
which basically just call c:\python23\python.exe or
c:\python24\python.exe as required.  For various reasons which
may or may not apply to you as well, I also have each of them
set the PYTHONHOME variable to point to the right folder
as well.
The content of each batch file is like this:
@echo off
c:\python23\python.exe %1 %2 %3 %4 %5 %6 %7 %8 %9
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: OT: spacing of code in Google Groups

2005-01-06 Thread Grant Edwards
On 2005-01-06, Steve Holden [EMAIL PROTECTED] wrote:
 Peter Hansen wrote:

 [...]
 
 But the whole argument is fairly moot...  I've needed a rectangle
 operation only once in the last ten years, and if I hadn't known at
 the time that my editor could do it (and spent about half an hour
 figuring out how it worked), I could have written a utility to
 do the job faster if I'd been using Python at the time...

 Or even used cut(1) from the command line.

IIRC, that was the first thing suggested.  Using rectangular
operations in an editor was a ways down the list of alternatives.

-- 
Grant Edwards   grante Yow!  Is this ANYWHERE,
  at   USA?
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File Handling Problems Python I/O

2005-01-06 Thread Peter Hansen
Josh wrote:
I am having a problem with Python. I am new to Python as a programming
language, but I do have experience in other languages. I am
experiencing strange problems with File handling and wonder if anyone
else has seen this or knows what I am doing wrong. I am simply trying
to open a file for read and iterate through until the end of file. I am
able to do so without a problem, but here's the catch: The open
statement is only working on certain files. I open a simple text file
say file1.txt without any issues, but I change the open statement to
another text file and it error's out stating the file doesn't exist. 
The usual rookie mistake here is to fail to recognize
that backslashes in strings are interpreted as special
escape sequences if they precede certain characters such
as t or b.  You probably have a path that looks like
this: c:\temp\myfile.txt, right?  The \t is actually
being converted into a TAB character.
You can use *forward* slashes in most cases in Windows,
except on the command line.  The simplest fix is just
to convert your backslashes to forward slashes:
  c:/temp/myfile.txt
Another approach, somewhat less desirable, is to use
raw strings instead, to prevent the escape sequences from
being recognized:
  rc:\temp\myfile.txt
Finally, and by far least desirable, use double-backslashes
to escape each backslash and in effect nullify the usual
escape handling:
  c:\\temp\\myfile.txt
Much less readable that way, but sometimes the right thing to do...
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: OT: spacing of code in Google Groups

2005-01-06 Thread Peter Hansen
Steve Holden wrote:
Peter Hansen wrote:
But the whole argument is fairly moot...  I've needed a rectangle
operation only once in the last ten years, and if I hadn't known at
the time that my editor could do it (and spent about half an hour
figuring out how it worked), I could have written a utility to
do the job faster if I'd been using Python at the time...
Or even used cut(1) from the command line.
Or myybe not :-)
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
c:\cut
'cut' is not recognized as an internal or external command,
operable program or batch file.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: OT: spacing of code in Google Groups

2005-01-06 Thread Grant Edwards
On 2005-01-06, Peter Hansen [EMAIL PROTECTED] wrote:
 Steve Holden wrote:
 Peter Hansen wrote:
 But the whole argument is fairly moot...  I've needed a rectangle
 operation only once in the last ten years, and if I hadn't known at
 the time that my editor could do it (and spent about half an hour
 figuring out how it worked), I could have written a utility to
 do the job faster if I'd been using Python at the time...
 
 Or even used cut(1) from the command line.

 Or myybe not :-)

 Microsoft Windows XP [Version 5.1.2600]
 (C) Copyright 1985-2001 Microsoft Corp.

 c:\

That's not a command line. ;)

 'cut' is not recognized as an internal or external command,
 operable program or batch file.

-- 
Grant Edwards   grante Yow!  I am having FUN... I
  at   wonder if it's NET FUN or
   visi.comGROSS FUN?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Developing Commercial Applications in Python

2005-01-06 Thread Duncan Booth
Nick Vargish wrote:

 [EMAIL PROTECTED] writes:
 
 Can somebody there to point me any good commercial applications
 developed using python ?
 
 Python is used in several games, including Temple of Elemental Evil
 and the forthcoming Civilization 4. Humungous Games, which makes
 software for children, is also using Python. Sorry if games would give
 your boss the wrong impression...

Also Startrek Bridge Commander, and Uru: Ages beyond Myst.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2005-01-06 Thread Roel Schroeven
Alex Martelli wrote:
Roel Schroeven [EMAIL PROTECTED] wrote:

Can you point to closed-source licenses that allow using the code *at
all*?

As I recall, for example, Microsoft Visual C++ came with sources for
various libraries; all that the (closed-source) license for those
libraries forbade you from doing was to further distribute the _sources_
themselves.  You could do modifications big or small to those libraries
for whatever purposes, and redistribute the _compiled_ form of the code
as a DLL, or statically linked into your own programs, etc, etc.
Is this what you mean by allow using the code *at all*?  I think it's
a pretty common arrangement when the code being sold under closed-source
terms is a set of libraries, or a development system part of whose value
is a set of accompanying libraries.
OK, I've been bitten by my exageration. There are indeed special cases 
such as some libraries.

I was thinking more of end-user packages: if you somehow could lay your 
hands on the source code of Visual Studio itself, you're still not 
allowed to do anything with it.

--
Codito ergo sum
Roel Schroeven
--
http://mail.python.org/mailman/listinfo/python-list


RE: OT: spacing of code in Google Groups

2005-01-06 Thread Tim Golden
[Peter Hansen]
| [Steve Holden]
|  Peter Hansen wrote:
|  But the whole argument is fairly moot...  I've needed a rectangle
|  operation only once in the last ten years, and if I hadn't known at
|  the time that my editor could do it (and spent about half an hour
|  figuring out how it worked), I could have written a utility to
|  do the job faster if I'd been using Python at the time...
|  
|  Or even used cut(1) from the command line.
| 
| Or myybe not :-)
| 
| Microsoft Windows XP [Version 5.1.2600]
| (C) Copyright 1985-2001 Microsoft Corp.
| 
| c:\cut
| 'cut' is not recognized as an internal or external command,
| operable program or batch file.

Thanks goodness for UnxUtils, is what I say:

http://unxutils.sourceforge.net/

(But you probably knew that!)

Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

o:\scripts\work_in_progress\timc:\tools\cut --help
Usage: c:\tools\cut [OPTION]... [FILE]...
Print selected parts of lines from each FILE to standard output.

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: Developing Commercial Applications in Python

2005-01-06 Thread Steve Hughes

Can somebody there to point me any good commercial applications
developed using python ?
Yet another game but it's a huge one with a massive DB behind it.
http://www.eve-online.com
--
Steve Hughes
--
http://mail.python.org/mailman/listinfo/python-list


curses is not imported under Linux (and Python 2.4)

2005-01-06 Thread Konrad Koller
import curses
produces the ImportError: No module named _curses
(from _curses import *  in line 15 in __init__.py)
Of course imp.find_module (_curses) reports the same error.
How can I make use of the curses package for writing a Python script
with curses?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: curses is not imported under Linux (and Python 2.4)

2005-01-06 Thread Steve Holden
Konrad Koller wrote:
import curses
produces the ImportError: No module named _curses
(from _curses import *  in line 15 in __init__.py)
Of course imp.find_module (_curses) reports the same error.
How can I make use of the curses package for writing a Python script
with curses?
I get the same thing under Windows: _curses is the compiled extension 
supporting the curses library, so I must presume that isn't supported by 
default on Windows.

No problems under Cygwin or on Linux.
Googling for python curses windows might provide a few pointers.
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: The Industry choice

2005-01-06 Thread Alex Martelli
Roel Schroeven [EMAIL PROTECTED] wrote:
   ...
 Can you point to closed-source licenses that allow using the code *at
 all*?
   ...
  Is this what you mean by allow using the code *at all*?  I think it's
  a pretty common arrangement when the code being sold under closed-source
  terms is a set of libraries, or a development system part of whose value
  is a set of accompanying libraries.
 
 OK, I've been bitten by my exageration. There are indeed special cases
 such as some libraries.
 
 I was thinking more of end-user packages: if you somehow could lay your
 hands on the source code of Visual Studio itself, you're still not 
 allowed to do anything with it.

Yes, apart from libraries and similar cases (frameworks etc), it's no
doubt rare for closed-source end-user packages to be sold with
licenses that include source and allow you to do anything with it.

However, allowing customization (at least for internal use within the
customer organization), while rare, is far from unheard of.  I used to
work for a software house which sold rich and complex packages of
software meant for 3D mechanical design.  The packages came with tens of
thousands of lines of (closed-source) code, in a proprietary scripting
language implemented by the package itself, which users (typically
mechanical engineers) were _expected_ to tweak to customize the overall
product for their specific purposes -- such modified parts of the
scripting source of the overall product were routinely shared among
different customers, and occasionally sold from one to another.

The choice of which parts of code in the scripting language were made
thus customizable and sharable was quite deliberate: the application
contained much more code in that scripting language, but most of it was
only distributed in compiled form (or even with the compiled form
already turned into data in some library or executable) -- the parts
that were sold as sources were picked to be those which would be most
useful for customers to customize and share, yet not damage the business
model of the software house.  (and yes, it WAS closed source software,
anyway -- customers were theoretically not permitted to give our source
or derived works thereof to others who _weren't_ customers, I think;
anyway the engine needed to run the scripts was not redistributable, so
that provisions, if there, was of modest value).

I wouldn't be surprised if such a mixed model was reasonably common
among end-user packages which include a substantial proprietary
scripting component, particularly if the end-users are expected to be
technically skilled (mechanical engineers aren't programmers, but they
will probably have some vague clue about it; a consumer product might be
different).  Just a guess, but, wouldn't, say, Mathematica or some
similar closed-source product benefit from this kind of arrangement --
including, as part of the product being sold, some rich amount of
scripting code, freely customizable and sharable among customers
(perhaps with the license prohibiting giving it away to non-customers)?

I believe some (closed-source) games, including ones which use Python as
their scripting language, may also do something of the kind -- include
Python sources for scenarios with full license to tweak and
redistribute (making new scenarios which are derived works of ones sold
by the games' authors).  Here the language is not proprietary but no
doubt the scripts use large amounts of calls to proprietary modules, so
again there is no damage to the game author's business model anyway.

Hmmm, come to think of it, doesn't Apple include very large amount of
working Applescript code with many of its closed-source applications?


So, although your general point is no doubt sound, almost by definition
of closed source, you may perhaps still need to tweak it further, beyond
libraries and frameworks, to also exclude that closed source with is a
scripting, configuration, or otherwise ancillary part of the
application.


One last reflection -- I believe there are or used to be some programs
written by people no doubt of very good will, distributed with all
sources and often with no profit motive at all, which are NOT open
source because they include in the license some restrictive clause, such
as no military use, no use by organizations which perform testing of
cosmetics on animals, or something of that kind.  These would be
examples of closed-source software which DO allow ALMOST any kind of use
-- any EXCEPT the specific one the authors dislike so intensely.

While most people may not think of such programs as closed source,
they most definitely ARE: the definition of open source is very strict
about this aspect.


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


wsse:Security header

2005-01-06 Thread Angie
Hi, all,

I would like to use Python to generate SOAP message with wsse:Security,
UsernameToken header, does anyone has some example how to using ZSI?
Thanks

Angie

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


Re: How about pure virtual methods?

2005-01-06 Thread George Sakkis
Noam Raphael [EMAIL PROTECTED] wrote:

 Thanks for your suggestion, but it has several problems which the added
 class solves:

 * This is a very long code just to write you must implement this
 method. Having a standard way to say that is better.
 * You can instantiate the base class, which doesn't make sense.
 * You must use testing to check whether a concrete class which you
 derived from the base class really implemented all the abstract methods.
 Testing is a good thing, but it seems to me that when the code specifies
 exactly what should happen, and it doesn't make sense for it not to
 happen, there's no point in having a separate test for it.


Here's a more refined implementation of the one posted before that
addresses these issues. It defines 'abstractclass', which would be
a nice class decoraror when (and if) class decorators make it into
the language. The extra benefit compared to the MustImplement metaclass
is that it allows a class with no abstract methods to be defined as abstract.
This makes no sense if one defines an abstract class as a class with one
or more abstract (deferred) methods. Perhaps a more useful and general
definition of an abstract class is a class that is not allowed to be 
instantiated.
Deferred methods are one reason for making a class uninstantiable, but it's
not the only one. Sometimes it is useful to define a base class that provides
a default implementation of a full protocol, yet disallow its direct 
instantiation,
as in the example below.

George

#===
# test_abstract.py

import unittest
from abstract import abstractclass

class AbstractTestCase(unittest.TestCase):

def test_no_abstractmethods(self):
class SomeBase(object):
# This class has no abstract methods; yet calling foo() or bar()
# on an instance of this class would cause infinite recursion.
# Hence it is defined as abstract, and its concrete subclasses
# should override at least one of (foo,bar) in a way that breaks
# the recursion.
def __init__(self, x):
self._x = x
def foo(self, y):
return self.bar(self._x + y)
def bar(self, y):
return self.foo(self._x - y)
SomeBase = abstractclass(SomeBase)

class Derived(SomeBase):
def __init__(self,x):
SomeBase.__init__(self,x)
def foo(self,y):
return self._x * y

self.assertRaises(NotImplementedError, SomeBase, 5)
self.assertEquals(Derived(5).bar(2), 15)

if __name__ == '__main__':
unittest.main()

#===
# abstract.py

import inspect

__all__ = [abstractclass, abstractmethod, AbstractCheckMeta]


def abstractclass(cls):
'''Make a class abstract.

Example::
# hopefully class decorators will be supported in python 2.x
# for some x, x4
[EMAIL PROTECTED]
class SomeBase(object):
@abstractmethod
def function(self):
Implement me
# the only way as of python 2.4
SomeBase = abstractclass(SomeBase)

@param cls: A new-style class object.
@return: A surrogate of C{cls} that behaves as abstract. The returned
class raises NotImplementedError if attempted to be instantiated
directly; still its subclasses may call its __init__. A subclass of
the returned class is also abstract if it has one or more abstract
methods, or if it is also explicitly decorated by this function. A
method is declared abstract by being assigned to NotImplemented (or
decorated by L{abstractmethod}).
@raise TypeError: If there is a metaclass conflict between C{type(cls)}
and L{AbstractCheckMeta}, or if C{cls} has an C{__abstractmethods__}
attribute.
'''
# check if cls has AbstractCheckMeta (or a subtype) for metaclass
metaclass = type(cls)
if not issubclass(metaclass, AbstractCheckMeta):
# it doesn't; try to make AbstractCheckMeta its metaclass by
# inheriting from _AbstractCheck
cls = metaclass(cls.__name__, (_AbstractCheck,) + cls.__bases__,
dict(cls.__dict__))
# replace __init__ with a proxy ensuring that __init__ is called by a
# subclass (but not directly)
old_init = getattr(cls,'__init__',None)
def new_init(self,*args,**kwds):
if self.__class__ is cls:
raise NotImplementedError(%s is an abstract class % cls.__name__)
if old_init is not None:
old_init(self,*args,**kwds)
setattr(cls,'__init__',new_init)
return cls


def abstractmethod(function):
'''A method decorator for those who prefer the parameters declared.'''
return NotImplemented


class AbstractCheckMeta(type):
'''A metaclass to detect instantiation of abstract classes.'''

def 

Re: File Handling Problems Python I/O

2005-01-06 Thread Josh
Peter,

Thank you for the rookie correction. That was my exact problem. I
changed the address to use forward slashes and it works perfect. I did
not know that a backslash had special meaning within a string, but now
I do! Thanks again

Josh

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


Re: Another PythonWin Excel question

2005-01-06 Thread David Bolen
It's me [EMAIL PROTECTED] writes:

 Yes, I read about that but unfortunately I have no experience with VBA *at
 all*.  :=(

You don't really have to know VBA, but if you're going to try to
interact with COM objects from Python, you'll find it much smoother if
you at least use any available reference information for the COM
object model and interfaces you are using.

In the Excel case, that means understanding - or at least knowing how
to look in a reference - its object model, since that will tell you
exactly what parameters an Add method on a worksheet object will take
and how they work.

For excel, online documentation can be found in a VBAXL9.CHM help file
(the 9 may differ based on Excel release), but it might not always
be installed depending on what options were selected on your system.  In
my English, Office 2000 installation, for example, the files are located in:
c:\Program Files\Microsoft Office\Office\1033

You can load that file directly, or Excel itself will reference it
from within the script editor help (Tools-Macro-Visual Basic Editor,
then F1 for help).  If you methods or classes and have the help
installed it'll bring in the reference.

You can also find it on MSDN on the web, although it can be tricky to
navigate down to the right section - the top of the Office 2000 object
documentation should be available at:

http://msdn.microsoft.com/library/en-us/odeomg/html/deovrobjectmodelguide.asp

This is mostly reference information, but there are some higher level
discussions of overall objects (e.g., worksheets, workbooks, cells,
etc...) too.

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


Re: File Handling Problems Python I/O

2005-01-06 Thread deelan
Josh wrote:
Peter,
Thank you for the rookie correction. That was my exact problem. I
changed the address to use forward slashes and it works perfect. I did
not know that a backslash had special meaning within a string, but now
I do! Thanks again
you may want to check python gotchas to avoid
other typical newbie errors:
http://www.ferg.org/projects/python_gotchas.html
HTH,
deelan
--
Vedrai come ti tratteranno le mie TV
Berlusconi a Follini (Luglio 2004)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Another PythonWin Excel question

2005-01-06 Thread It's me
Thanks,

David Bolen [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 It's me [EMAIL PROTECTED] writes:

  Yes, I read about that but unfortunately I have no experience with VBA
*at
  all*.  :=(

 You don't really have to know VBA, but if you're going to try to
 interact with COM objects from Python, you'll find it much smoother if
 you at least use any available reference information for the COM
 object model and interfaces you are using.

 In the Excel case, that means understanding - or at least knowing how
 to look in a reference - its object model, since that will tell you
 exactly what parameters an Add method on a worksheet object will take
 and how they work.

 For excel, online documentation can be found in a VBAXL9.CHM help file
 (the 9 may differ based on Excel release), but it might not always
 be installed depending on what options were selected on your system.  In
 my English, Office 2000 installation, for example, the files are located
in:
 c:\Program Files\Microsoft Office\Office\1033

 You can load that file directly, or Excel itself will reference it
 from within the script editor help (Tools-Macro-Visual Basic Editor,
 then F1 for help).  If you methods or classes and have the help
 installed it'll bring in the reference.

 You can also find it on MSDN on the web, although it can be tricky to
 navigate down to the right section - the top of the Office 2000 object
 documentation should be available at:


http://msdn.microsoft.com/library/en-us/odeomg/html/deovrobjectmodelguide.asp

 This is mostly reference information, but there are some higher level
 discussions of overall objects (e.g., worksheets, workbooks, cells,
 etc...) too.

 -- David


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


Re: The Industry choice

2005-01-06 Thread Jeff Shannon
Steve Holden wrote:
Bulba! wrote:

I was utterly shocked. Having grown up in Soviet times I have
been used to seeing precious resources wasted by organizations
as if resources were growing on trees, but smth like this?! In a
shining ideal country of Germany?! Unthinkable.
Indeed not. Quite often the brown paper bag is a factor in purchases 
like this. I wouldn't be at all surprised if somebody with a major input 
to the decision-making process retired to a nice place in the country 
shortly afterwards. You appear to be making the mistake of believing 
that people will act in the larger interest, when sadly most individuals 
tend to put their own interests first (some would go as far as to define 
self-interest as the determinant of behavior).
Indeed, it is almost expected that those in charge of any large 
organization (whether government, corporation, trade union, industry 
association, fan club, or whatever else) are likely to act in their 
personal interests at the expense of the organization's interests. 
This is why things like public-disclosure laws and oversight 
committees exist.  As they say, power corrupts.  (Of course, this is 
not at all limited to people in charge; it's just most notable there, 
since those people can direct the efforts of the rest of the 
organization for their personal gain, whereas a rank-and-file member 
can typically only direct their own efforts.)

It's also noteworthy to consider that many times, waste happens not 
because of corruption or self-interest, but simply because of errors 
of judgement.  Humans being as we are, it's inevitable that over time, 
some obvious important details will escape our attention, and the 
resulting imperfect information will result in poor decisions.  This 
is a simple fact of human nature, and (ob-Python ;) ) it's one of the 
reasons that Python is designed as it is -- it makes a serious effort 
to reduce the number of details that might escape detection.

(One should also consider that many business failures are a case of 
simply having played the odds and lost.  Many ventures depend on 
outside events playing in a certain way; when by chance those events 
happen, the decision-makers are called bold and insightful, but if 
things don't work out, they're called foolish or misguided.  Often, 
though, it was not foolishness but shrewd risk-taking -- if you take a 
one-in-three chance of making a tenfold return on investment, then 66% 
of the time you'll lose but if you hit those odds just once, 
you'll come out way ahead.)

Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list


Download .jpg from web

2005-01-06 Thread GMane Python
Hello All.
  Using a network camera with built-in webserver, I'd like to have a python
program download .jpg files on a local lan.  the location is
http://ip-address/jpg/image.jpg.

  Currently, I'm importing urllib and using urlopen to the address, then
read()-ing it, saving it to a binary file.  All that is working great, but
maybe a bit slowly.  I'm getting ~2.3 frames per second, and would like
between 5-10 frames per second.

  Am I approaching this incorrectly?  I have to do a urlopen, then .read()
for each image.  Is there any way to 'persist' the urlopen so I just have to
keep read()-ing or maybe is there a type of streaming read?  I have many
cameras, so there are many threads simultaneously reading and dropping them
in a central Queue for saving later.

  I appreciate it!
-Dave

 WebImage = urllib.urlopen(http://ip-address/jpg/image.jpg).read()
 QueuePacket = []
 QueuePacket.append(WebImage)




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


Re: File Handling Problems Python I/O

2005-01-06 Thread Alex Martelli
Josh [EMAIL PROTECTED] wrote:
   ...
 He is the function where I am making the call. If I change the open
 statment to another file, say c:\test.txt, a file I know exists, it

Are you sure a file exist whose name is, c, colon, tab, e, s, t ...?

\t is an escape sequence and it means TAB (character of ascii code 9).

Try 'c:/test.txt' -- using normal slash instead the backslash -- and you
should be fine.

You mention you have some experience with other languages: if those
languages include C, or Java, or C++, and many others besides (all which
use backslashes for escape sequences in strings), you'd have exactly the
same issues.


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


Re: Python evolution: Unease

2005-01-06 Thread Bengt Richter
On 05 Jan 2005 23:19:39 -0800, Paul Rubin http://[EMAIL PROTECTED] wrote:

[EMAIL PROTECTED] (Bengt Richter) writes:
 What do you think of automated secure importing/installing from a
 remote server?  You know, you try to import something and it imports
 a stub that was included as a battery-place-holder and that has
 basic help info and will give you reasonable options in directing
 the installation of the full thing (or subset you are interested in).

You mean for Python modules, in ordinary operation?  I'd hate that.
For things like apt-get, used for installing nonstandard programs or
getting security updates, I guess it's about as good as one can hope
for.  The user has to activate it explicitly though.  I definitely
don't want my computer opening internet connections unless I
specifically ask it to.  Doing otherwise is almost spyware.
I agree 1000% !! Importing a stub should get you an imported stub that
prints info as it imports, so you know its not functional. And just
gives you the options to type help(themodule) or if you know you want
to go ahead, themodule.install() -- and nothing would touch the internet
until you gave a final yes to an Are you sure at the end of a
what-will-happen-if-you-say-yes summary. I didn't mean any activity
that you don't control. Just activity that you can control easily.


This may sound a little extreme but my distribution philosophy is I'd
like to get closer to an environment where users normally never
install any software of any type, ever.  Microsoft cornered the OS
market cornered by acheiving something pretty close to this: they
deliver Windows with no installation needed.  When people buy new
computers, Windows is already on the hard drive, so the user just
turns the computer on and Windows is there.
It makes a lot of sense for a core plus a delivered specific application
base, but IMO if you try to cover the world with a monolith you will
inevitably still have the problem of getting the latest version of
particular packages for bug fixes or enhancements. The more you have
in your giant collection the more that will be true.


Fedora Core (what I'm running now) isn't shipped that way by any
computer makers that I know of, but it makes up for it by having lots
of applications included.  So I buy a new computer, put in the
bootable Fedora DVD-ROM, and sit back for half an hour while a
one-time installation runs.  That's about as close as I can get to
just turning on the new computer and having Fedora already there.

 I don't see why every gee whiz thing has to be on your hard disk
 from the first.  And for those that want a big grabbag, the stubs
 ought to be designed to to be runnable from a configured script, so
 you can turn it loose and see what's up IRL.

If I have a 400 gig hard drive, I don't see why I need 99.99% of it
empty instead of 99.0% after I do my OS install.  I don't want to
hassle over downloading stuff for hours or days at a time, or about
what components depend on other components, if the distro can just
include it.  I just tried to install a Python program that uses
wxPython, except that meant I had to download both wxPython and
wxWidgets, and the installations failed because of some version
mismatch between the current wxWidgets distro and the version of GTK
included with FC3.  I spent an hour or so messing with it and then
said screw it and gave up on the GUI part of that program.  I'm more
technical than most users (I'm a programmer) yet this installation
stuff is too much hassle even for me.  So I'd really rather that all
that stuff be pre-configured.
There are several parts to those frustrations. But you are presuming
that they would have been solved for you and put on a DVD with all
dependency problems resolved. Ok, let's assume that. In that case,
an installation stub module could just as well have the solution built
into it as to what versions etc are needed to make the module work.
With a large collection, you may need several versions of some support libs.

To bring a large collection into version-alignment ISTM you need a version
freeze across too many libraries of different kinds with different
development schedules and resources to make it reliable.

So you're still going to need the ability to add updates and new modules
and more. I'd rather see effort going into making that process simple
and reliable (and fully controlled by the user -- i.e. no unauthorized
hidden internet activity!!) than to solve the same version problems
for some mega DVD make file where you don't have the script and config info
in a concise single-problem stub form, and can't ask here for help finding
an updated stub. It's a matter of being able to limit the problem you
need to solve when something particular doesn't work.

When your wxPython-using program didn't work, wouldn't it have been nice
to have downloaded a standard stub program (with older stub versions still
available if you have an older system) and have it tell you what
was missing that it 

Re: Other notes

2005-01-06 Thread Andrew Dalke
Me
 (BTW, it needs to be 1 .. 12 not 1..12 because 1. will be interpreted
 as the floating point value 1.0.)

Steve Holden:
 Indeed, but if .. is defined as an acceptable token then there's 
 nothing to stop a strict LL(1) parser from disambiguating the cases in 
 question. Token is not the same thing as character.

Python's tokenizer is greedy and doesn't take part in the
lookahead.  When it sees 1..12 the longest match is for 1.
which is a float.  What remains is .2.  That also gets tokenized
as a float.  float float is not allowed in Python so the
parser raises an compile time SyntaxError exception

 1..12
  File stdin, line 1
1..12
^
SyntaxError: invalid syntax
 

Consider the alternative of 1..a.  Again 1. is tokenized
as a float.  What remains is .a.  The longest match is .
with a remaining.  Then the next token is a.  The token
stream looks like
  float 1.0dotname a
which gets converted to the same thing as
  getattr(1.0, a)

That is legal syntax but floats don't have the a property
so Python raises an AttributeError at run-time.

 1..a 
Traceback (most recent call last):
  File stdin, line 1, in ?
AttributeError: 'float' object has no attribute 'a'
 

Here's a property that does exist

 1..__abs__
method-wrapper object at 0x547d0
 


Because of the greedy lexing it isn't possible to do
1.__abs__ to get the __abs__ method of an integer.
That's because the token stream is

 float 1.0name __abs__

which is a syntax error.

 1.__abs__
  File stdin, line 1
1.__abs__
^
SyntaxError: invalid syntax
 

One way to avoid that is to use 1 .__abs__.  See the
space after the 1?  The tokenizer for this case creates

  integer 1dotname __abs__


which create code equivalent to getattr(1, __abs__) and
is valid syntax

 1 .__abs__
method-wrapper object at 0x54ab0
 

Another option is to use parentheses:  (1).__abs__

I prefer this latter option because the () is easier to
see than a space.  But I prefer using getattr even more.

Andrew
[EMAIL PROTECTED]

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


Re: Building unique comma-delimited list?

2005-01-06 Thread Bengt Richter
On 5 Jan 2005 17:05:40 -0500, [EMAIL PROTECTED] (Roy Smith) wrote:

I've got a silly little problem that I'm solving in C++, but I got to
thinking about how much easier it would be in Python.  Here's the
problem:

You've got a list of words (actually, they're found by searching a
data structure on the fly, but for now let's assume you've got them as
a list).  You need to create a comma-delimited list of these words.
There might be duplicates in the original list, which you want to
eliminate in the final list.  You don't care what order they're in,
except that there is a distinguised word which must come first if it
appears at all.

Some examples (foo is the distinguised word): 

[foo] = foo
[foo, bar] = foo, bar
[bar, foo] = foo, bar
[bar, foo, foo, baz, bar] = foo, bar, baz or foo, baz, bar

The best I've come up with is the following.  Can anybody think of a
simplier way?

(Not tested beyond what you see ;-)
python 2.4:
  words = [foo, bar, baz, foo, bar, foo, baz]
  w2 = list(t[1] for t in sorted((w!='foo', w) for w in set(words)))
  w2
 ['foo', 'bar', 'baz']

Gets you a sort in the bargain ;-)


words = [foo, bar, baz, foo, bar, foo, baz]

# Eliminate the duplicates; probably use set() in Python 2.4
Yup, but 2.3 can be a one-liner too:

  words = [foo, bar, baz, foo, bar, foo, baz]
  w2 = ('foo' in words and ['foo'] or []) + [w for w in 
  dict(zip(words,words)) if w!='foo']
  w2
 ['foo', 'baz', 'bar']

Not sorted, but foo is out front.

d = dict()
for w in words:
d[w] = w

if d.has_key (foo):
newWords = [foo]
del (d[foo])
else:
newWords = []

for w in d.keys():
newWords.append (w)

s = ', '.join (newWords)
print s


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


Re: wxPython clipboard

2005-01-06 Thread Jeremy Bowers
On Thu, 06 Jan 2005 03:27:56 -0800, lbolognini wrote:
 Could you please give me some advice on the best approach to solve this
 problem?

To the best of my knowledge, and I'd be surprised if this wasn't true,
wxPython does not have the necessary tools to do this. 

That program doesn't even use the clipboard; it uses low-level security
flaws* in Windows to directly access text in other programs as it is being
typed, watch for trigger text to go by, and then dynamically replace it;
all of which is a major security flaw in the absence of user permission.

This *particular* application is harmless, but it's still exploiting holes.

Since those holes don't exist cross-platform, wxWindows won't reflect
them. You'd need to go to the WinAPI, and after that I have no idea what
comes next... but I do know it's going to be tricky, painful work and if
you didn't already know you needed to do this, you probably don't want to
go here. Here There Be Dragons.

*: The security flaw lies in the Windows messaging model; once you have a
window handle you can send it any message and get back any data you want,
including stuffing that window with any new data you want, which is a
gaping flaw indeed in a world of buffer exploits. IIRC, there is no way to
do any sort of user-based security, so even if you do everything as a
low-priv user except use this one program as administrator, if that
program has a window on the screen and a buffer overflow, that's a root
exploit waiting to be coded.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Embedding a restricted python interpreter

2005-01-06 Thread Bengt Richter
On Thu, 6 Jan 2005 16:53:23 +0100, Gerhard Haering [EMAIL PROTECTED] wrote:


--rwEMma7ioTxnRzrJ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, Jan 06, 2005 at 07:32:25AM -0800, Paul Rubin wrote:
 Jp Calderone [EMAIL PROTECTED] writes:
A Python sandbox would be useful, but the hosting provider's excuse
  for not allowing you to use mod_python is completely bogus.  All the=20
  necessary security tools for that situation are provided by the=20
  platform in the form of process and user separation.
=20
 But mod_python is an apache module and runs in the same apache process
 with other users' scripts.

Which is why it's a good idea for each customer to have it's own system user
and their virtual hosts running under this uid. Which was the idea for the
perchild MPM for Apache 2 - which is abandoned now :-( muxmpm is a replacem=
ent
project in beta.
Note to self. Another thing to catch up on ;-/

This really sucks when you use Apache2. I myself did make the switch some t=
ime
ago, then noticed that this (for me) important feature was missing. It now
works, somehow, but to make it work properly I'd need to either:

- go back to Apache 1.3.x, missing some nice improvements
And maybe have to recompile to enable the setuid stuff. But IIRC after that you
can run cgi with everything private and serve only generated stuff to the world
if you want.

- use different webservers per user, put them together with mod_proxy (yuck=
!)

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


  1   2   >