Re: why a main() function?

2006-09-19 Thread billie
Another advantage is that you can catch all the unhandled exceptions of
the entire program (it they occurs) by doing something like this:

def another_call():
raise SomeUnexpectedException   # it will be catched in '__main__'

def call():
another_call()

def run():
call()

in __name__ == '__main__':
try:
 run()
except:
 # do cleanup
 # log exit message
 # exit

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


Re: How to efficiently proceed addition and subtraction in python list?

2006-09-19 Thread Ant

Tim Chase wrote:
> > I have a list AAA = [1, 2, 3] and would like to subtract one from list
> > AAA
> > so AAA' = [0, 1, 2]
> >
> > What should I do?
>
>
> Sounds like a list comprehension to me:

Also the built in function 'map' would work:

>>> a = [1,2,3]
>>> b = map(lambda x: x-1, a)
>>> b
[0, 1, 2]

List comprehensions are more pythonic, but map would probably be faster
if performance was a (real) issue.

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


Re: Python programs always open source?

2006-09-19 Thread Diez B. Roggisch
Ben Finney schrieb:
> Leif K-Brooks <[EMAIL PROTECTED]> writes:
> 
 Ben Finney wrote:
> So long as you're not distributing some or all of Python itself,
> or a derivative work, the license for Python has no legal effect
> on what license you choose for your own work.
> 
>> I was replying to Ben Finney's claim that in a hypothetical world
>> where Python was licensed under the GPL, there would still be no
>> restriction on distributing Python programs under a closed-source
>> license.
> 
> My claim (and IANAL) is that it doesn't matter *what* license Python
> is distributed under; unless you do something with Python that is a
> right of the copyright holder, such as distributing part or all of
> Python, the copyright license terms of Python have no legal effect on
> what license you choose for your own work.

IANAL - having said that:

Not true for the GPL. Part of python is the library, which you either 
use explicit (I can't imagine a program that doesn't, beyond print 
"hello world"), or implicit (sys and os are AFAIX used internally to 
bootstrap the interpreter)

And the GPL exactly requires that when a library licensed under it is 
used, that makes the using program GPL-licensed, too.

And the LGPL (L for lesser or library) remedies that.

If I recall correctly, the LGPL stats that you might use the headers and 
link against a LGPL-lib as long as you don't change it, and you are ok.

So - I would certainly be very cautious when using GPL-based products if 
I wanted to build some closed-source-application on top of it.

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


Re: CONSTRUCT - Adding Functionality to the Overall System

2006-09-19 Thread Diez B. Roggisch
>>
>> I think '__metaclass__ = whatever' affects only the creation of 
>> classes that
>> would otherwise be old-style classes?
> 
> Wrong.
> 
> If you set __metaclass__ = type, every class in that module will be 
> new-style.
> 
> If you set __metaclass__ = MyClass, and MyClass inherits from , every
> class in that module will be new-style and have MyClass as a metaclass.
> 
> The usual way to create new-style classes, inheriting from object or 
> another
> new-style class, works because if no __metaclass__ is defined, the first
> base class's class is taken as the metaclass.


I was under that impression, too. But this behaves different (py2.4):


 test.py 
class meta(type):
 def __new__(*args):
 print args
 return type(*args[1:])

__metaclass__ = meta

class OldStyle:
 pass

class NewStyle(object):
 #__metaclass__ = meta

 pass



 test.py 

deets$ python2.4 /tmp/test.py
(, 'OldStyle', (), {'__module__': '__main__'})
deets$

I was astonished to see that. Any explanation?

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


Re: CONSTRUCT - Adding Functionality to the Overall System

2006-09-19 Thread Damjan
>>> __metaclass__ = whatever
>>> 
>>> at the top of each module whose classes are to get the new behavior.
>> 
>> I think '__metaclass__ = whatever' affects only the creation of classes
>> that would otherwise be old-style classes?
> 
> Wrong.
> 
> If you set __metaclass__ = type, every class in that module will be
> new-style.

 >>> from UserDict import UserDict
 >>> type(UserDict)
 
 >>> class A(UserDict):
 ...   pass
 >>> type(A)
 
 >>> __metaclass__ = type
 >>> class B(UserDict):
 ...   pass
 >>> type(B)
 

It seems that NOT every class in my module will be a new style class,
especially those that inherit from other old-style classes in other
modules.



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


Re: CONSTRUCT - Adding Functionality to the Overall System

2006-09-19 Thread Georg Brandl
Diez B. Roggisch wrote:
>>>
>>> I think '__metaclass__ = whatever' affects only the creation of 
>>> classes that
>>> would otherwise be old-style classes?
>> 
>> Wrong.
>> 
>> If you set __metaclass__ = type, every class in that module will be 
>> new-style.
>> 
>> If you set __metaclass__ = MyClass, and MyClass inherits from , every
>> class in that module will be new-style and have MyClass as a metaclass.
>> 
>> The usual way to create new-style classes, inheriting from object or 
>> another
>> new-style class, works because if no __metaclass__ is defined, the first
>> base class's class is taken as the metaclass.
> 
> 
> I was under that impression, too. But this behaves different (py2.4):

[...]

> deets$ python2.4 /tmp/test.py
> (, 'OldStyle', (), {'__module__': '__main__'})
> deets$
> 
> I was astonished to see that. Any explanation?

Yes. I was wrong, the order of lookup is reversed. This first base class's
class is used before the global __metaclass__.

So what Damjan said is correct: global __metaclass__ is only usable for
classes that don't have bases.

Whether this is desirable is another question...

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


Re: Creating database structures in a portable way

2006-09-19 Thread Samuel
> > SQLAlchemy looks pretty good, but unfortunately apparently requires
> > shell access for installation (or at least, I have not found any other
> > solution covered in the docs), which I can not use.
>
> It doesn't use binaries AFAIK, so just copying should work as well.

Indeed, from browsing the package it seems like a pure Python solution.
I installed it (but didn't test it yet because I have no code to drive
it yet).

> > Rewriting the schema is possible (I only want to keep it separated from
> > the code),
>
> Why ? Isn't your code supposed to use it ?

It often makes sense to use meta languages to enforce clean separation
of logic. In my experience it is helpful to separate the database logic
from the application logic.

> A first point is that the DB-API doesn't hide the differences between
> various SQL dialects.

I see.

> A second point is that DB-API requires you to
> embed SQL statements as strings, while SQLAlchemy allow you to build
> your SQL queries in pure Python.

I'd rather not rewrite every single Sql statement into Python, since it
would

1. replace code that has already proven to work by something untested.
2. add yet another abstraction, at the cost of performance.

Luckily, SQLAlchemy also lets me use SQL statements directly.

> (and FWIW, if using an existing DB, you
> don't even have to describe the schema a second time to use it). Well,
> just start playing with it, and I really doubt you'll want to come back
> to the embedded hand-written SQL !-)

If I ever write something from scratch I'll use it.

Thanks for your comments, this was very helpful.

-Samuel

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


ImportError: Don't know how to import XYZ (type code 3)

2006-09-19 Thread daniel
Trying to load a C++ module that is wrapped with boost_python and get
the error

ImportError: Don't know how to import XYZ (type code 3)

I think type code 3 is means that it is a C++ wrapped .pyd.

I have know idea what that means or how to fix it.

Any ideas?

D.

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


Re: When is it a pointer (aka reference) - when is it a copy?

2006-09-19 Thread Magnus Lycka
Fredrik Lundh wrote:
> this article
> 
> http://effbot.org/zone/python-objects.htm
> 
> may be useful for those who haven't already seen it.

I don't know how many times I've referred to, or paraphrased,
that article. Shouldn't it be incorporated into the standard
tutorial? I think it's very helpful for people who are used
to the way C etc handles variables.
-- 
http://mail.python.org/mailman/listinfo/python-list


Formatting device from a script on Windows

2006-09-19 Thread volcano
Hello, folks!
Script I am creating has to format a device - USB flash drive. I have
tried using regular DOS "format" through "os.system" - did not work
well, because DOS format requires input from user. And the script
should run without user interference.
I have taken a look at ActivePython "win32..." libraries - did not find
anything.
Ideas? Pretty please?

Regards, Mark

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


Re: When is it a pointer (aka reference) - when is it a copy?

2006-09-19 Thread GHUM

Magnus Lycka schrieb:
> > http://effbot.org/zone/python-objects.htm
> > may be useful for those who haven't already seen it.
>
>Shouldn't it be incorporated into the standard tutorial?
>I think it's very helpful for people who are used
> to the way C etc handles variables.

That would also be a good headline. "information for those coming from
C", and it should be possible to grow similiar sections for those
comming from Java or PERL.

At least it belongs into the FAQ :)

Harald

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


Re: When is it a pointer (aka reference) - when is it a copy?

2006-09-19 Thread Simon Brunning
On 9/19/06, Magnus Lycka <[EMAIL PROTECTED]> wrote:
> Fredrik Lundh wrote:
> > this article
> >
> > http://effbot.org/zone/python-objects.htm
> >
> > may be useful for those who haven't already seen it.
>
> I don't know how many times I've referred to, or paraphrased,
> that article. Shouldn't it be incorporated into the standard
> tutorial? I think it's very helpful for people who are used
> to the way C etc handles variables.

I agree. These two, also:

http://effbot.org/zone/unicode-objects.htm
http://effbot.org/zone/import-confusion.htm

And probably more...

-- 
Cheers,
Simon B,
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Formatting device from a script on Windows

2006-09-19 Thread weir
this may help, you need ctypes module.

##
from ctypes import *

fm = windll.LoadLibrary('fmifs.dll')

def myFmtCallback(command, modifier, arg):
print command
return 1# TRUE

FMT_CB_FUNC = WINFUNCTYPE(c_int, c_int, c_int, c_void_p)


FMIFS_HARDDISK = 0x0C
fm.FormatEx(c_wchar_p('H:\\'), FMIFS_HARDDISK, c_wchar_p('NTFS'),
c_wchar_p('title'), True, c_int(0), FMT_CB_FUNC(myFmtCallback))

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


Re: Python programs always open source?

2006-09-19 Thread [EMAIL PROTECTED]
Diez B. Roggisch wrote:
> Ben Finney schrieb:
>  Ben Finney wrote:
> > So long as you're not distributing some or all of Python itself,
> > or a derivative work, the license for Python has no legal effect
> > on what license you choose for your own work.
> >
[SNIP]
> > My claim (and IANAL) is that it doesn't matter *what* license Python
> > is distributed under; unless you do something with Python that is a
> > right of the copyright holder, such as distributing part or all of
> > Python, the copyright license terms of Python have no legal effect on
> > what license you choose for your own work.
>
> IANAL - having said that:
>
> Not true for the GPL.

[Re: the hypothetical situation where Python were GPL'd]

It doesn't matter what the GPL says, if your work is not a derivative
work of Python then you have no obligation to follow _any_ terms in
Python's license to distribute your own work.  The GPL could make all
the claims it wants[1], it doesn't matter since you aren't legally
required to follow any of them for your own (non-derived) work.

In particular, if your program ran on PyPy or Jython, it'd be pretty
much impossible to argue that it's a derivative work of CPython. Now,
if Jython/PyPy both required CPython libraries (which your code used)
then there could be a case that your code is derivative of those
libraries and bound by their license terms--it's not obvious that
argument would fly, but it's also not obvious it wouldn't.

[1] in reality the GPL recognizes this--see clause 5

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


Re: why a main() function?

2006-09-19 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

> Others have already told you the most important things.
> 
> There is another secondary advantage: the code inside a function runs
> faster (something related is true for C programs too). Usually this
> isn't important, but for certain programs they can go 20%+ faster.

I totally fail to see why that should be the case - for python as well as
for C.

So - can you explain that a bit more, or provide resources to read up on it?

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


Re: why a main() function?

2006-09-19 Thread Simon Brunning
On 9/19/06, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:

> I totally fail to see why that should be the case - for python as well as
> for C.

If you put your code into a main() function, all the names that it
binds are in the function's local scope, whereas if the code is in the
module's top level, the names are bound to the module's global scope.
Access to locals is somewhat faster than access to globals.

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


Re: Python programs always open source?

2006-09-19 Thread Ben Finney
"Diez B. Roggisch" <[EMAIL PROTECTED]> writes:

> Ben Finney schrieb:
> > My claim (and IANAL) is that it doesn't matter *what* license
> > Python is distributed under; unless you do something with Python
> > that is a right of the copyright holder, such as distributing part
> > or all of Python, the copyright license terms of Python have no
> > legal effect on what license you choose for your own work.
>
> Not true for the GPL. Part of python is the library, which you
> either use explicit (I can't imagine a program that doesn't, beyond
> print "hello world"), or implicit (sys and os are AFAIX used
> internally to bootstrap the interpreter)

And just about every program on a GNU/Linux system uses the libc
library, which is distributed under the GPL. That license *only*
affects works that are *derivative* of the libc library.

> And the GPL exactly requires that when a library licensed under it
> is used, that makes the using program GPL-licensed, too.

No, only when a new work *derives from* the existing work does
copyright on the existing work take effect.

You may be thinking of the "linking" clause, which depends on the
*inclusion of* existing header files from the library code, supplied
under the GPL. There's no such concept in an interpreted language like
Python: you write your program in the Python language without
including a single piece of the original in your work.

The GPL itself is clear on the fact that its terms cannot claim
anything that is not granted to the copyright holder -- and
*execution* of a library is not a right over which the library author
has any rights.

Even if execution (or "use") of a program library, without including
*any* of its code in your own work, were a right the library author
could restrict, no free software program can place any restriction on
execution (otherwise it's trivially non-free). If Python's license
were ever to have such a restrictive term, it would likely be
unenforcible, but would certainly disqualify it from inclusion in any
free operating system.

Copyright is currently weighted greatly in favour of copyright
holders, but please don't buy into the absolute-power rhetoric more
than necessary.

-- 
 \   "Yesterday I told a chicken to cross the road. It said, 'What |
  `\  for?'"  -- Steven Wright |
_o__)  |
Ben Finney

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


Re: why a main() function?

2006-09-19 Thread Fredrik Lundh
"Diez B. Roggisch" wrote:

>> There is another secondary advantage: the code inside a function runs
>> faster (something related is true for C programs too). Usually this
>> isn't important, but for certain programs they can go 20%+ faster.
>
> I totally fail to see why that should be the case - for python as well as
> for C.
>
> So - can you explain that a bit more, or provide resources to read up on it?

Python stores local variables in an indexed array, but globals in a dictionary.
Looking things up by index is faster than looking them up by name.

Not sure what the C thing is; C doesn't really support putting *code* outside
functions.  Maybe he was thinking about static vs. auto variables ?

 



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


Re: why a main() function?

2006-09-19 Thread Peter Otten
Diez B. Roggisch wrote:

> [EMAIL PROTECTED] wrote:
> 
>> Others have already told you the most important things.
>> 
>> There is another secondary advantage: the code inside a function runs
>> faster (something related is true for C programs too). Usually this
>> isn't important, but for certain programs they can go 20%+ faster.
> 
> I totally fail to see why that should be the case - for python as well as
> for C.
> 
> So - can you explain that a bit more, or provide resources to read up on
> it?

A trivial example (for Python):

$ cat main.py
def main():
x = 42
for i in xrange(100):
x; x; x; x; x; x; x; x; x; x
x; x; x; x; x; x; x; x; x; x
x; x; x; x; x; x; x; x; x; x

main()
$ time python main.py

real0m0.874s
user0m0.864s
sys 0m0.009s
$ cat nomain.py
x = 42
for i in xrange(100):
x; x; x; x; x; x; x; x; x; x
x; x; x; x; x; x; x; x; x; x
x; x; x; x; x; x; x; x; x; x
$ time python nomain.py

real0m2.154s
user0m2.145s
sys 0m0.009s
$

Now let's verify that global variables are responsible for the extra time:

$ cat main_global.py
def main():
global i, x
x = 42
for i in xrange(100):
x; x; x; x; x; x; x; x; x; x
x; x; x; x; x; x; x; x; x; x
x; x; x; x; x; x; x; x; x; x

main()
$ time python main_global.py

real0m2.002s
user0m1.995s
sys 0m0.007s


Peter

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


Writing Video conference software for Windows

2006-09-19 Thread Paolo Pantaleo
Hi,

I need to write a software that allow to see the desktop and hear the
microphone capture of a remote PC across a network. I need to do that
for a unviresity assignement. The software must  run on Windows. Since
I like Python very much I am thinking to write that software in
Python. Do you thinkit is a good choice? Are there libraries for audio
compression (OGG or MP3 or maybe GSM or something like realaudio) and
video compression (btw what can be some good libraries to transmit
images of a desktop in a bandwidth-efficent way?). What about capture
of audio and screen? (Probably i will need some Win32 system call,
there are bindings in Python, aren't they?)

If I needed to write some Python modules in C, would it be difficult?

Can some language like C# or C++ may be better?

Thnx
PAolo

-- 
if you have a minute to spend please visit my photogrphy site:
http://mypic.co.nr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Formatting device from a script on Windows

2006-09-19 Thread volcano

weir wrote:
> this may help, you need ctypes module.
>
> ##
> from ctypes import *
>
> fm = windll.LoadLibrary('fmifs.dll')
>
> def myFmtCallback(command, modifier, arg):
> print command
> return 1  # TRUE
>
> FMT_CB_FUNC = WINFUNCTYPE(c_int, c_int, c_int, c_void_p)
>
>
> FMIFS_HARDDISK = 0x0C
> fm.FormatEx(c_wchar_p('H:\\'), FMIFS_HARDDISK, c_wchar_p('NTFS'),
> c_wchar_p('title'), True, c_int(0), FMT_CB_FUNC(myFmtCallback))

Thanks for info, but somehow I am getting "invalid syntax" on this.
What could go wrong?

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


Installing Python on a 64-Bit OS

2006-09-19 Thread Nico Grubert
Hi there,

I'd like to install Python 2.3.5. on a 64-Bit OS (Suse Linux Enterprise 
Server 10) on an AMD Opteron 64-Bit machine.
I have to use Python 2.3.5.

Do I need a special source archive or can I use "Python-2.3.5.tgz" from 
http://www.python.org/ftp/python/2.3.5/Python-2.3.5.tgz ?

Is there anything special I have to care about or is installing Python 
on a 64 Bit OS just as easy as installing it on a 32-Bit OS?

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


Compile AST to bytecode?

2006-09-19 Thread Rob De Almeida
Hi,

I would like to compile an AST to bytecode, so I can eval it later. I
tried using parse.compileast, but it fails:

>>> import compiler, parser
>>> ast = compiler.parse("42")
>>> parser.compileast(ast)
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: compilest() argument 1 must be parser.st, not instance

Any hints?

TIA,
--Rob

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


Re: Installing Python on a 64-Bit OS

2006-09-19 Thread Ivan Voras
Nico Grubert wrote:

> Is there anything special I have to care about or is installing Python 
> on a 64 Bit OS just as easy as installing it on a 32-Bit OS?

It is as easy. Look around, you'll probably find a pre-built binary 
package for your OS.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [ANN] Code Golf Challenge : 1,000 Digits Of Pi

2006-09-19 Thread Neil Cerutti
On 2006-09-18, Calvin Spealman <[EMAIL PROTECTED]> wrote:
> Just once, I would like to see a programming contest that was
> judged on the quality of your code, not the number of bytes you
> managed to incomprehensively hack it down to.

Check out the ICFP Functional Programming Contest. Most of the
challenges they put together are rated on many factors, and code
size is usually not one of them.

Despite the contest's title, they welcome entrants from any
programming language (provided it supports thier testing system),
since presumably that gives the functional programmers something
to defeat.

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


Re: How to efficiently proceed addition and subtraction in python list?

2006-09-19 Thread Steve Holden
Ant wrote:
> Tim Chase wrote:
> 
>>>I have a list AAA = [1, 2, 3] and would like to subtract one from list
>>>AAA
>>>so AAA' = [0, 1, 2]
>>>
>>>What should I do?
>>
>>
>>Sounds like a list comprehension to me:
> 
> 
> Also the built in function 'map' would work:
> 
> 
a = [1,2,3]
b = map(lambda x: x-1, a)
b
> 
> [0, 1, 2]
> 
> List comprehensions are more pythonic, but map would probably be faster
> if performance was a (real) issue.
> 
And statements like that are probably going to annoy me ;-)

  >>> t = timeit.Timer("b = map(lambda x: x-1, a)", setup="a=[1,2,3]")
  >>> t.timeit()
2.4686168214116599
  >>> t = timeit.Timer("b = [x-1 for x in a]", setup="a=[1,2,3]")
  >>> t.timeit()
0.9930245324475635
  >>>

Any timing prediction involving the word "probably" isn't worth the 
paper it's written on (or even less if it's posted in a newsgroup ;-). 
If it's "probably" faster, and if performance is *really* important, you 
need to benchmark both options to remove the "probably". As the above 
test makes clear, your assertions are certainly untrue for 2.4.2 on Windows.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: How to efficiently proceed addition and subtraction in pythonlist?

2006-09-19 Thread Fredrik Lundh
Steve Holden wrote:

> And statements like that are probably going to annoy me ;-)
>
>  >>> t = timeit.Timer("b = map(lambda x: x-1, a)", setup="a=[1,2,3]")
>  >>> t.timeit()
> 2.4686168214116599
>  >>> t = timeit.Timer("b = [x-1 for x in a]", setup="a=[1,2,3]")
>  >>> t.timeit()
> 0.9930245324475635
>  >>>

And now someone's probably reading this and thinking that list comprehensions
are *always* faster than "map"...

 



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


Re: How to efficiently proceed addition and subtraction in pythonlist?

2006-09-19 Thread Steve Holden
Fredrik Lundh wrote:
> Steve Holden wrote:
> 
> 
>>And statements like that are probably going to annoy me ;-)
>>
>> >>> t = timeit.Timer("b = map(lambda x: x-1, a)", setup="a=[1,2,3]")
>> >>> t.timeit()
>>2.4686168214116599
>> >>> t = timeit.Timer("b = [x-1 for x in a]", setup="a=[1,2,3]")
>> >>> t.timeit()
>>0.9930245324475635
>> >>>
> 
> 
> And now someone's probably reading this and thinking that list comprehensions
> are *always* faster than "map"...
> 
You are so right. So, let me repeat the important part that Fredrik 
didn't quote:

"""if performance is *really* important, you
need to benchmark both options"""

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


RELEASED Python 2.5 (FINAL)

2006-09-19 Thread Anthony Baxter
It's been nearly 20 months since the last major release
of Python (2.4), and 5 months since the first alpha
release of this cycle, so I'm absolutely thrilled to be
able to say:

On behalf of the Python development team
and the Python community, I'm happy to
announce the FINAL release of Python 2.5.

This is a *production* release of Python 2.5. Yes, that's
right, it's finally here.

Python 2.5 is probably the most significant new release
of Python since 2.2, way back in the dark ages of 2001.
There's been a wide variety of changes and additions,
both user-visible and underneath the hood. In addition,
we've switched to SVN for development and now use Buildbot
to do continuous testing of the Python codebase.

Much more information (as well as source distributions
and Windows and Universal Mac OSX installers) are available
from the 2.5 website:

http://www.python.org/2.5/

The new features in Python 2.5 are described in Andrew
Kuchling's What's New In Python 2.5. It's available
from the 2.5 web page.

Amongst the new features of Python 2.5 are conditional
expressions, the with statement, the merge of try/except
and try/finally into try/except/finally, enhancements
to generators to produce coroutine functionality, and
a brand new AST-based compiler implementation underneath
the hood. There's a variety of smaller new features as
well.

New to the standard library are hashlib, ElementTree,
sqlite3, wsgiref, uuid and ctypes. As well, a new
higher-performance profiling module (cProfile) was
added.

Extra-special thanks on behalf of the entire Python
community should go out to Neal Norwitz, who's done
absolutely sterling work in shepherding Python 2.5
through to it's final release.

Enjoy this new release, (and Woo-HOO! It's done!)
Anthony

Anthony Baxter
[EMAIL PROTECTED]
Python Release Manager
(on behalf of the entire python-dev team)


pgpVmTT37pPi9.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Installing Python on a 64-Bit OS

2006-09-19 Thread Steve Holden
Nico Grubert wrote:
> Hi there,
> 
> I'd like to install Python 2.3.5. on a 64-Bit OS (Suse Linux Enterprise 
> Server 10) on an AMD Opteron 64-Bit machine.
> I have to use Python 2.3.5.
> 
> Do I need a special source archive or can I use "Python-2.3.5.tgz" from 
> http://www.python.org/ftp/python/2.3.5/Python-2.3.5.tgz ?
> 
> Is there anything special I have to care about or is installing Python 
> on a 64 Bit OS just as easy as installing it on a 32-Bit OS?
> 
More recent versions of Python have incorporated much more support for 
64-bit architectures. 2.5 is about to be released (I believe it should 
be out in the next 24 hours), and I'd recommend that over the older 
version you are considering.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Compile AST to bytecode?

2006-09-19 Thread Duncan Booth
"Rob De Almeida" <[EMAIL PROTECTED]> wrote:

> I would like to compile an AST to bytecode, so I can eval it later. I
> tried using parse.compileast, but it fails:
> 
 import compiler, parser
 ast = compiler.parse("42")
 parser.compileast(ast)
> Traceback (most recent call last):
>   File "", line 1, in ?
> TypeError: compilest() argument 1 must be parser.st, not instance
> 
> Any hints?

There are two distinct varieties of AST in the Python standard library. 
compiler and parser ast objects are not compatible.

I'm not sure there are any properly documented functions for converting an 
AST to a code object, so your best bet may be to examine what a 
pycodegen class like Expression or Module actually does.

>>> import compiler
>>> def ast_to_evalcode(ast):
return compiler.pycodegen.ExpressionCodeGenerator(ast).getCode()

>>> def parse_to_ast(src):
return compiler.pycodegen.Expression(src, "")._get_tree()

>>> ast = parse_to_ast("40+2")
>>> ast
Expression(Add((Const(40), Const(2
>>> ast_to_evalcode(ast)
 at 0122D848, file "", line -1>
>>> eval(_)
42
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installing Python on a 64-Bit OS

2006-09-19 Thread Steve Holden
Steve Holden wrote:
> Nico Grubert wrote:
> 
>>Hi there,
>>
>>I'd like to install Python 2.3.5. on a 64-Bit OS (Suse Linux Enterprise 
>>Server 10) on an AMD Opteron 64-Bit machine.
>>I have to use Python 2.3.5.
>>
>>Do I need a special source archive or can I use "Python-2.3.5.tgz" from 
>>http://www.python.org/ftp/python/2.3.5/Python-2.3.5.tgz ?
>>
>>Is there anything special I have to care about or is installing Python 
>>on a 64 Bit OS just as easy as installing it on a 32-Bit OS?
>>
> 
> More recent versions of Python have incorporated much more support for 
> 64-bit architectures. 2.5 is about to be released (I believe it should 
> be out in the next 24 hours), and I'd recommend that over the older 
> version you are considering.
> 
Correction: it's out NOW!

get-it-while-it's-hot-ly y'rs  - steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Installing Python on a 64-Bit OS

2006-09-19 Thread Anthony Baxter
> More recent versions of Python have incorporated much more support for
> 64-bit architectures. 2.5 is about to be released (I believe it should
> be out in the next 24 hours), and I'd recommend that over the older
> version you are considering.

If by "24 hours" you mean "20 minutes ago", this is entirely correct 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to efficiently proceed addition and subtraction in pythonlist?

2006-09-19 Thread Ant

Steve Holden wrote:
> Fredrik Lundh wrote:
> > Steve Holden wrote:
> >
...
> """if performance is *really* important, you
> need to benchmark both options"""

Fair point.

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


Re: Installing Python on a 64-Bit OS

2006-09-19 Thread Daniel Dittmar
Nico Grubert wrote:
> I'd like to install Python 2.3.5. on a 64-Bit OS (Suse Linux Enterprise 
> Server 10) on an AMD Opteron 64-Bit machine.
> I have to use Python 2.3.5.
> 
> Do I need a special source archive or can I use "Python-2.3.5.tgz" from 
> http://www.python.org/ftp/python/2.3.5/Python-2.3.5.tgz ?
> 
> Is there anything special I have to care about or is installing Python 
> on a 64 Bit OS just as easy as installing it on a 32-Bit OS?

On this platform, it should be easy to build from the sources as gcc 
builds 64 bit programs by default.

On some platforms (Solaris/Sparc, AIX, HP-UX/PA-RISC), the compiler 
defaults to 32bit programs. You then have to convince configure to use 
the right CFLAGS. The exact technique might differ from configure to 
configure: some require an option, some require an environment variable. 
Tip: create wrapper scripts for the compiler (and possibly ld and ar), 
which uses the proper options. Add the location of these scripts at the 
start of PATH, thus overiding the compiler. Now all configures will 
default to 64 bit.

Daniel

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


Re: Formatting device from a script on Windows

2006-09-19 Thread volcano
OK, it worked. Obviosly, quick format was a bad choice.

Thanks a lot for your help!
Mark

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


Re: How to efficiently proceed addition and subtraction in python list?

2006-09-19 Thread Simon Brunning
On 18 Sep 2006 15:43:31 -0700, Daniel Mark <[EMAIL PROTECTED]> wrote:
> Hello all:
>
> I have a list AAA = [1, 2, 3] and would like to subtract one from list
> AAA
> so AAA' = [0, 1, 2]

You've had some excellent suggestions as to how to go about this
assuming that by "efficient" you mean in terms of CPU. If, instead,
you are concerned with memory usage, you might instead do something
like:

for index, value in enumerate(AAA):
AAA[index] = value-1

-- 
Cheers,
Simon B,
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compile AST to bytecode?

2006-09-19 Thread Rob De Almeida
Duncan Booth wrote:
> > I would like to compile an AST to bytecode, so I can eval it later.
> I'm not sure there are any properly documented functions for converting an
> AST to a code object, so your best bet may be to examine what a
> pycodegen class like Expression or Module actually does.

Thanks, Duncan. It worked perfectly. :-)

For arbitrary nodes I just had to wrap them inside an Expression node:

>>> ast = compiler.ast.Expression(node)
>>> ast.filename = 'dummy'
>>> c = compiler.pycodegen.ExpressionCodeGenerator(ast)
>>> obj = eval(c.getCode(), scope)

--Rob

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


I need some tips to begin a simple project

2006-09-19 Thread dutche
Hi, I'm new in Python and I'm learning with "Learning Python" oreilly's
book which is very good written and explanatory.

Now, that I know a bit of Python, I want to make some simple project, I
thought something like a menu, just like "kxdocks" menu or something
like that, with transparency and all with xml. But I dont know what
things I have to know.

PyGame is in it, right?

And I can use some other graphical interface, like OpenGL? Or with
PyGame I can do an animattion like zooming the icon image when hover?

All sugestions would be very nice :)

Thanks for all

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


Re: Installing Python on a 64-Bit OS

2006-09-19 Thread Steve Holden
Anthony Baxter wrote:
>>More recent versions of Python have incorporated much more support for
>>64-bit architectures. 2.5 is about to be released (I believe it should
>>be out in the next 24 hours), and I'd recommend that over the older
>>version you are considering.
> 
> 
> If by "24 hours" you mean "20 minutes ago", this is entirely correct 

:-)
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


win32 Service: path to .py script

2006-09-19 Thread Gregor Horvath
Hi,

I have a testservice.py (see below). I installed the Windows-Service
successfully. (via commandlineoption install)
The problem is that it runs only when it is in c:\windows\system32 or in
the python path.
I added the desired path (Y:\) to the PYTHONPATH environment variable
for the system account and rebooted.
When I start command line python and do a import testservice everything
is fine.
Starting the service with the script only in Y:\ gives the error in the
event log:

Python could not import the service's module

exceptions.ImportError: No module named testservice

Thanks for your help.

--
Greg

testservice.py:

import win32serviceutil, win32service
import servicemanager
import win32api
import win32event
import sys

class TestPipeService(win32serviceutil.ServiceFramework):
_svc_name_ = "MDE Dispatcher"
_svc_display_name_ = "MDE-Dispatcher"
_svc_description_ = "Dispatches machine events from the Siemens ODC
to registrered MDE clients (windows) over the network via XML-RPC"
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)

def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)


def SvcDoRun(self):
# Write an event log record - in debug mode we will also
# see this message printed.
servicemanager.LogMsg(
servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED,
(self._svc_name_, '')
)

while 1:
win32api.Sleep(2)
rc = win32event.WaitForSingleObject(self.hWaitStop, 2000)
if rc == win32event.WAIT_OBJECT_0:
break


# Write another event log record.
servicemanager.LogMsg(
servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STOPPED,
(self._svc_name_, " TEST ")
)


if __name__=='__main__':
win32serviceutil.HandleCommandLine(TestPipeService)

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


Re: CONSTRUCT - Adding Functionality to the Overall System

2006-09-19 Thread Ilias Lazaridis
Ilias Lazaridis wrote:
> I understand that I can use __metaclass__ to create a class which
> modifies the behaviour of another class.
>
> How can I add this metaclass to *all* classes in the system?
>
> (In ruby I would alter the "Class" class)

I got confused from the discussion about __metaclass__.

possibly a little more practical.

I like to add a method "writeDebug(self, msg)" to all (or the most
possible) classes in the system.

How do I do this?

* with new style classes
* with old style classes
 
> .
> 
> http://lazaridis.com

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


Installing 2.5 with 2.4?

2006-09-19 Thread John Salerno
Hi all. Just curious, before I do it myself, about the best way to 
install 2.5 if it's the only version I want to use. Should I uninstall 
2.4 first? Does 2.5 replace 2.4? I doubt the latter, but if I install 
2.5, does that mean I need to reinstall all the extensions I had for 2.4 
again, or does 2.5 detect them somehow?

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


Pyglade, gtk, howto write more efficiently, and waste less code?

2006-09-19 Thread Pipiten
Hi everybody, i` m new in this group, and python so.., my greetings to
everybody here.
I wrote a little program, in wich i do this:
(I have several "Select File" buttons, one for each file (in this case,
an image) wich has an text_entry, so i can add a comment for each
picture.)

def on_button1_clicked(self,widget):
   """Button 1 pressed"""
   image_file1 = FileSelection(self)
   self.path1.set_text(image_file1)
   self.image1.set_from_file(image_file1)
   self.image1.show()

   def on_button2_clicked(self,widget):
   """Button 2 pressed"""
   image_file2 = FileSelection(self)
   self.path2.set_text(image_file2)
   self.image2.set_from_file(image_file2)
   self.image2.show()

   def on_button3_clicked(self,widget):
   """Button 3 pressed"""
   image_file3 = FileSelection(self)
   self.path3.set_text(image_file3)
   self.image3.set_from_file(image_file3)
   self.image3.show()

   def on_button4_clicked(self,widget):
   """Button 4 pressed"""
   image_file4 = FileSelection(self)
   self.path4.set_text(image_file4)
   self.image4.set_from_file(image_file4)
   self.image4.show()

   def on_button5_clicked(self,widget):
   """Output dir button pressed"""
   outputpath = FileSelection(self)
   self.path5.set_text(outputpath)


Is there any way to do this, with a for bucle, or something like that?.
For example, if i want to to the same, 25 times, not to copy and paste.
Does anyone knows how to do that?, write it one time, and flexible to
use many times.
( I think it should be with the variables sent by parameters, isn´t? )



Thanks a lot, have a nice day!

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


Re: Installing 2.5 with 2.4?

2006-09-19 Thread Fredrik Lundh
John Salerno wrote:
> Hi all. Just curious, before I do it myself, about the best way to 
> install 2.5 if it's the only version I want to use. Should I uninstall 
> 2.4 first?

if you don't plan to use it anymore, yes.

> Does 2.5 replace 2.4?

no.

> I doubt the latter, but if I install 2.5, does that mean I need to
 > reinstall all the extensions I had for 2.4 again

yes.

> does 2.5 detect them somehow?

no.  extensions built for 2.5 are, in general, not compatible with 
extensions built for 2.4.



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


Re: CONSTRUCT - Adding Functionality to the Overall System

2006-09-19 Thread Diez B. Roggisch
Ilias Lazaridis wrote:

> Ilias Lazaridis wrote:
>> I understand that I can use __metaclass__ to create a class which
>> modifies the behaviour of another class.
>>
>> How can I add this metaclass to *all* classes in the system?
>>
>> (In ruby I would alter the "Class" class)
> 
> I got confused from the discussion about __metaclass__.
> 
> possibly a little more practical.
> 
> I like to add a method "writeDebug(self, msg)" to all (or the most
> possible) classes in the system.
> 
> How do I do this?
> 
> * with new style classes
> * with old style classes

OMFG. For asking the question (paraphrased) "why do you want to do this",
Mr. Spealman received an

http://case.lazaridis.com/wiki/Please#OffTopicPosts

But now you do exactly that - give more details. Maybe this could teach you
the lesson that the variance of input you get here to your questions is
worth considering?

But I've got the wicked feeling that this won't happen...

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


Re: Installing 2.5 with 2.4?

2006-09-19 Thread Diez B. Roggisch
John Salerno wrote:

> Hi all. Just curious, before I do it myself, about the best way to
> install 2.5 if it's the only version I want to use. Should I uninstall
> 2.4 first? Does 2.5 replace 2.4? I doubt the latter, but if I install
> 2.5, does that mean I need to reinstall all the extensions I had for 2.4
> again, or does 2.5 detect them somehow?

Without an OS given, difficult answer. Generally, you can assume that there
is no need to ditch one version because you use another, they don't
interfer with each other. Only which one is perceived as "current" might
change and alter some behavior.

However, you have to install all extensions again, that is for sure. And
most probably some of them won't work so far, as they might need some
modification or at least time to make them available as binary.

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


Re: Installing 2.5 with 2.4?

2006-09-19 Thread John Salerno
Diez B. Roggisch wrote:
> John Salerno wrote:
> 
>> Hi all. Just curious, before I do it myself, about the best way to
>> install 2.5 if it's the only version I want to use. Should I uninstall
>> 2.4 first? Does 2.5 replace 2.4? I doubt the latter, but if I install
>> 2.5, does that mean I need to reinstall all the extensions I had for 2.4
>> again, or does 2.5 detect them somehow?
> 
> Without an OS given, difficult answer. Generally, you can assume that there
> is no need to ditch one version because you use another, they don't
> interfer with each other. Only which one is perceived as "current" might
> change and alter some behavior.
> 
> However, you have to install all extensions again, that is for sure. And
> most probably some of them won't work so far, as they might need some
> modification or at least time to make them available as binary.
> 
> Diez

Thanks for the answers guys. I'm using WinXP. I noticed that when I 
installed 2.5rc2, it wasn't automatically assigned as the default 
version of Python. I wasn't sure if this was just because it was an RC, 
or maybe I have to manually make 2.5 the default. But I will uninstall 
2.4 first anyway, so it shouldn't matter.

Can't wait to play around with it! :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why a main() function?

2006-09-19 Thread Diez B. Roggisch
Fredrik Lundh wrote:

> "Diez B. Roggisch" wrote:
> 
>>> There is another secondary advantage: the code inside a function runs
>>> faster (something related is true for C programs too). Usually this
>>> isn't important, but for certain programs they can go 20%+ faster.
>>
>> I totally fail to see why that should be the case - for python as well as
>> for C.
>>
>> So - can you explain that a bit more, or provide resources to read up on
>> it?
> 
> Python stores local variables in an indexed array, but globals in a
> dictionary. Looking things up by index is faster than looking them up by
> name.

Interesting. How is the index computed? I would have assumed that locals()
is somehow used, which is a dicht.

I can imagine enumerating left-hand-side names and trying to replace their
occurence with the index, falling back to the name if that is not
possible/the index isn't found. Does that come close?

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


Re: why a main() function?

2006-09-19 Thread Paul Rubin
"Diez B. Roggisch" <[EMAIL PROTECTED]> writes:
> > Python stores local variables in an indexed array, but globals in a
> > dictionary. Looking things up by index is faster than looking them up by
> > name.
> 
> Interesting. How is the index computed? I would have assumed that locals()
> is somehow used, which is a dicht.

They're static indexes assigned at compile time.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pyglade, gtk, howto write more efficiently, and waste less code?

2006-09-19 Thread [EMAIL PROTECTED]
Pipiten wrote:

> Hi everybody, i` m new in this group, and python so.., my greetings to
> everybody here.
> I wrote a little program, in wich i do this:
> (I have several "Select File" buttons, one for each file (in this case,
> an image) wich has an text_entry, so i can add a comment for each
> picture.)
>
> def on_button1_clicked(self,widget):
>  """Button 1 pressed"""
>  image_file1 = FileSelection(self)
>  self.path1.set_text(image_file1)
>  self.image1.set_from_file(image_file1)
>  self.image1.show()
> ...

You can connect all buttons to the same callback,
and in the callback you pick they matching image.

At least that what I would do (Up to now I don't use glade).

 HTH,
  Thomas

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


Re: why a main() function?

2006-09-19 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Paul Rubin wrote:

> "Diez B. Roggisch" <[EMAIL PROTECTED]> writes:
>> > Python stores local variables in an indexed array, but globals in a
>> > dictionary. Looking things up by index is faster than looking them up by
>> > name.
>> 
>> Interesting. How is the index computed? I would have assumed that locals()
>> is somehow used, which is a dicht.
> 
> They're static indexes assigned at compile time.

Which BTW is the reason why ``locals()['answer'] = 42`` does not work
within functions.  The dictionary isn't the dictionary that's used for
locals but a proxy just for read access.

Ciao,
Marc 'BlackJack' Rintsch

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


Re: why a main() function?

2006-09-19 Thread Fredrik Lundh
Diez B. Roggisch wrote:

> Interesting. How is the index computed? I would have assumed that locals()
> is somehow used, which is a dicht.
> 
> I can imagine enumerating left-hand-side names and trying to replace their
> occurence with the index, falling back to the name if that is not
> possible/the index isn't found. Does that come close?

yes, but there is no fallback: if a name inside a function is local or 
not is decided once and for all by the compiler, using static analysis.
see:

 http://pyref.infogami.com/naming-and-binding



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


Re: Python programs always open source?

2006-09-19 Thread Chris Lambacher
On Tue, Sep 19, 2006 at 09:46:13PM +1000, Ben Finney wrote:
> "Diez B. Roggisch" <[EMAIL PROTECTED]> writes:
> 
> > Ben Finney schrieb:
> > > My claim (and IANAL) is that it doesn't matter *what* license
> > > Python is distributed under; unless you do something with Python
> > > that is a right of the copyright holder, such as distributing part
> > > or all of Python, the copyright license terms of Python have no
> > > legal effect on what license you choose for your own work.
> >
> > Not true for the GPL. Part of python is the library, which you
> > either use explicit (I can't imagine a program that doesn't, beyond
> > print "hello world"), or implicit (sys and os are AFAIX used
> > internally to bootstrap the interpreter)
> 
> And just about every program on a GNU/Linux system uses the libc
> library, which is distributed under the GPL. That license *only*
> affects works that are *derivative* of the libc library.
Hmmm... The copyright file I have for GNU C Library looks to be LGPL:
"""
Copyright (C) 1991,92,93,94,95,96,97,98,99,2000,2001,2002,2003 Free Software
Foundation, Inc.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.
"""

The difference between the GPL and the LGPL is the linking thing.  Whether or
not it would hold up in court the FSF believes that GPL libraries mean only
GPL or GPL compatible licences are allowed to link, while anything can link
(dynamically not statically) to LGPL libraries.
http://www.gnu.org/licenses/why-not-lgpl.html:
"""
Proprietary software developers have the advantage of money; free software
developers need to make advantages for each other. Using the ordinary GPL 
for
a library gives free software developers an advantage over proprietary
developers: a library that they can use, while proprietary developers cannot
use it.

Using the ordinary GPL is not advantageous for every library. There are
reasons that can make it better to use the Library GPL in certain cases. The
most common case is when a free library's features are readily available for
proprietary software through other alternative libraries. In that case, the
library cannot give free software any particular advantage, so it is better 
to
use the Library GPL for that library.
"""

> 
> > And the GPL exactly requires that when a library licensed under it
> > is used, that makes the using program GPL-licensed, too.
> 
> No, only when a new work *derives from* the existing work does
> copyright on the existing work take effect.
> 
> You may be thinking of the "linking" clause, which depends on the
> *inclusion of* existing header files from the library code, supplied
> under the GPL. There's no such concept in an interpreted language like
> Python: you write your program in the Python language without
> including a single piece of the original in your work.
> 
> The GPL itself is clear on the fact that its terms cannot claim
> anything that is not granted to the copyright holder -- and
> *execution* of a library is not a right over which the library author
> has any rights.
> 
> Even if execution (or "use") of a program library, without including
> *any* of its code in your own work, were a right the library author
> could restrict, no free software program can place any restriction on
> execution (otherwise it's trivially non-free). If Python's license
> were ever to have such a restrictive term, it would likely be
> unenforcible, but would certainly disqualify it from inclusion in any
> free operating system.
> 
> Copyright is currently weighted greatly in favour of copyright
> holders, but please don't buy into the absolute-power rhetoric more
> than necessary.
> 
> -- 
>  \   "Yesterday I told a chicken to cross the road. It said, 'What |
>   `\  for?'"  -- Steven Wright |
> _o__)  |
> Ben Finney
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


newlines and sax.saxutils.quoteattr

2006-09-19 Thread Edward K. Ream
Hello all,

I recently ran across a situation in which sax.saxutils.quoteattr did not 
work as I expected.  I am writing Leo outlines as opml files
http://en.wikipedia.org/wiki/OPML
which forces me to write python code in xml attributes rather than xml 
elements (as is done in .leo files).

The problem is that the sax parser I am using ignores newlines in 
attributes.  After reading the thread at:

http://mail.python.org/pipermail/python-list/2006-March/332307.html

I was able to work around the problem by converting newlines to '
\n'. 
This makes the opml file as readable as possible (since the attributes 
contains newlines in addition to the character reference 
  In addition, 
the sax parser seems happy.

My questions:

- Does anyone know whether this is guaranteed to be a general solution? That 
is, are sax parsers *obliged* to ignore newlines in attributes?

- If sax parsers are indeed obliged to ignore newlines in attributes, would 
it be a good idea to (optionally?) have sax.saxutils.quoteattr perform the 
substitution of newlines to '
\n' ?

Thanks.

Edward

Edward K. Ream   email:  [EMAIL PROTECTED]
Leo: http://webpages.charter.net/edreamleo/front.html



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


Re: why a main() function?

2006-09-19 Thread Steven Bethard
Steve Holden wrote:
> [EMAIL PROTECTED] wrote:
>> I think I read a suggestion somewhere to wrap the code where a Python
>> script starts in a main() function, so one has
>>
>> def main():
>> print "hi"
>>
>> main()
>>
>> instead of
>>
>> print "hi"
>>
>> What are the advantages of doing this?
>>
> Guido van Rossum himself can tell you:
> 
>   http://www.artima.com/forums/flat.jsp?forum=106&thread=4829

Interesting.  A lot of the suggestions he makes are unnecessary if you 
use argparse_ or optparse, since they do much cleaner argument parsing 
and error reporting.

I basically never write a main() function in the sense described here. 
My code usually looks something like:

 if __name__ == '__main__':
 parser = _argparse.ArgumentParser(...)
 parser.add_argument(...)
 ...
 arguments = parser.parse_args()

 function_that_actually_does_stuff(arguments.foo,
   arguments.bar,
   arguments.baz)

So my ``if __name__ == '__main__'`` block does just enough argument 
parsing to be able to call a real function.

.. _argparse: http://argparse.python-hosting.com/

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


Re: win32 Service: path to .py script

2006-09-19 Thread Larry Bates
Gregor Horvath wrote:
> Hi,
> 
> I have a testservice.py (see below). I installed the Windows-Service
> successfully. (via commandlineoption install)
> The problem is that it runs only when it is in c:\windows\system32 or in
> the python path.
> I added the desired path (Y:\) to the PYTHONPATH environment variable
> for the system account and rebooted.
> When I start command line python and do a import testservice everything
> is fine.
> Starting the service with the script only in Y:\ gives the error in the
> event log:
> 
> Python could not import the service's module
> 
> exceptions.ImportError: No module named testservice
> 
> Thanks for your help.
> 
> --
> Greg
> 
> testservice.py:
> 
> import win32serviceutil, win32service
> import servicemanager
> import win32api
> import win32event
> import sys
> 
> class TestPipeService(win32serviceutil.ServiceFramework):
> _svc_name_ = "MDE Dispatcher"
> _svc_display_name_ = "MDE-Dispatcher"
> _svc_description_ = "Dispatches machine events from the Siemens ODC
> to registrered MDE clients (windows) over the network via XML-RPC"
> def __init__(self, args):
> win32serviceutil.ServiceFramework.__init__(self, args)
> self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
> 
> def SvcStop(self):
> self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
> win32event.SetEvent(self.hWaitStop)
> 
> 
> def SvcDoRun(self):
> # Write an event log record - in debug mode we will also
> # see this message printed.
> servicemanager.LogMsg(
> servicemanager.EVENTLOG_INFORMATION_TYPE,
> servicemanager.PYS_SERVICE_STARTED,
> (self._svc_name_, '')
> )
> 
> while 1:
> win32api.Sleep(2)
> rc = win32event.WaitForSingleObject(self.hWaitStop, 2000)
> if rc == win32event.WAIT_OBJECT_0:
> break
> 
> 
> # Write another event log record.
> servicemanager.LogMsg(
> servicemanager.EVENTLOG_INFORMATION_TYPE,
> servicemanager.PYS_SERVICE_STOPPED,
> (self._svc_name_, " TEST ")
> )
> 
> 
> if __name__=='__main__':
> win32serviceutil.HandleCommandLine(TestPipeService)
> 
I believe that your problem is that services run under Local
System account.  Normally Local System account would not have
a drive mapping Y:\.  You can change the account that a service
runs under in the Service Manager-Log On tab.  Normally you
wouldn't run services from mapped drives, they would be
installed on local machine and started from there.  If services
need to access mapped drives, you need to put full UNC
pathnames to access them or run the services under an account
that has the drives mapped properly.

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


Re: Compile AST to bytecode?

2006-09-19 Thread fumanchu
Rob De Almeida wrote:
> Duncan Booth wrote:
> > > I would like to compile an AST to bytecode, so I can eval it later.
> > I'm not sure there are any properly documented functions for converting an
> > AST to a code object, so your best bet may be to examine what a
> > pycodegen class like Expression or Module actually does.
>
> Thanks, Duncan. It worked perfectly. :-)
>
> For arbitrary nodes I just had to wrap them inside an Expression node:
>
> >>> ast = compiler.ast.Expression(node)
> >>> ast.filename = 'dummy'
> >>> c = compiler.pycodegen.ExpressionCodeGenerator(ast)
> >>> obj = eval(c.getCode(), scope)

If you're only worried about expressions, then you can have CPython do
the compilation for you much faster by wrapping the expression in a
lambda:

>>> f = lambda: 42
>>> f.func_code.co_code
'd\x01\x00S'
>>> map(ord, _)
[100, 1, 0, 83]

>>> g = lambda x, y: (x * 3) + len(y)
>>> map(ord, g.func_code.co_code)
[124, 0, 0, 100, 1, 0, 20, 116, 1, 0, 124, 1, 0, 131, 1, 0, 23, 83]

For a complete round-trip Expression library, see
http://projects.amor.org/dejavu/browser/trunk/logic.py


Robert Brewer
System Architect
Amor Ministries
[EMAIL PROTECTED]

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


Re: CONSTRUCT - Adding Functionality to the Overall System

2006-09-19 Thread MonkeeSage
Ilias Lazaridis wrote:
> How do I do this?

It's easy:

def writeDebug(msg):
  print "I do not debug things, I _evaluate_ with professionals on the
industries! See ticket 547!\n" \
"Oh yeah, and %s" % msg
...
class Foo:
  writeDebug("how can I configure the interpreter for understand
Klingon participals and noun-phrases? Must I rectify the standard
dictionaries first?")

Regards,
Jordan

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


Re: Threads blocking on OpenBSD w/ Python 2.4.2

2006-09-19 Thread [EMAIL PROTECTED]

[EMAIL PROTECTED] wrote:
> I'm attempting to write a faily simple threaded app that fires off a
> thread to select() on a FIFO while the main loop handles data read from
> that pipe and a few other tasks.  For some reason, calls to
> time.sleep() seem to block until the first time data is dumped into the
> pipe.  Clearly, I could work around this quite easily by "priming the
> pipe" as it were with a bit of garbage data.  However, I'd rather
> understand the problem.

I've verified the same behavior with Python 2.5.

-Ben

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


Pydev 1.2.3 released

2006-09-19 Thread Fabio Zadrozny
Hi All,

Pydev and Pydev Extensions 1.2.3 have been released

Details on Pydev Extensions: http://www.fabioz.com/pydev
Details on Pydev: http://pydev.sf.net
Details on its development: http://pydev.blogspot.com


Release Highlights in Pydev Extensions:
-

* Support for python 2.5 has been added
* Some minor issues on mark occurrences when the definition for something could not be found were fixed

Release Highlights in Pydev:
--

* When the user specifies an invalid interpreter, a better error report is given (previously it was only shown in the error log)
* When threads die, the debugger is notified about it (so that they are removed from the stack)
* Writing the preferences to the disk is now buffered
* Fixed problem when debugging in jython with the statement "from xxx import *"
* Fixed one issue with the indentation engine
* Commenting a line does not remove a blank line in the end anymore
* Added debug mode for unit-test
* Added the possibility of setting the -Dpython.cachedir for running
the jython shell (errors can arise in unix-based machines if jython is
not able to write its cache)

  Contributions
      o Darrell Maples:
            + Unit-test refactoring
            + Run as jython unit-test
            + Filter test methods to run

      o Joel Hedlund
            + Added a
support to ease adding options to Ctrl+1 in the scripting engine
            + Added a ctrl+1 for the case:

              def m1(self, arg=None):
                  arg |<-- Ctrl+1 shows option to do:
                  
              def m1(self, arg=None):
                  if arg is None:
                      arg = []

  Support for python 2.5
      o Added the new relative import
      o Added the new if _expression_
      o Added the unified try..except..finally statement
      o Added the with x:... statement
      o Indenting after the new with statement
      o Recognizing 'with' as a keyword in syntax highlighting 


What is PyDev?
---

PyDev is a plugin that enables users to use Eclipse for Python and
Jython development -- making Eclipse a first class Python IDE -- It
comes with many goodies such as code completion, syntax highlighting,
syntax analysis, refactor, debug and many others.


Cheers,

-- 
Fabio Zadrozny
--
Software Developer

ESSS - Engineering Simulation and Scientific Software
http://www.esss.com.br

Pydev Extensions
http://www.fabioz.com/pydev

Pydev - Python Development Enviroment for Eclipse
http://pydev.sf.net
http://pydev.blogspot.com

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

Re: Installing 2.5 with 2.4?

2006-09-19 Thread John Machin

John Salerno wrote:
> Diez B. Roggisch wrote:
> > John Salerno wrote:
> >
> >> Hi all. Just curious, before I do it myself, about the best way to
> >> install 2.5 if it's the only version I want to use. Should I uninstall
> >> 2.4 first? Does 2.5 replace 2.4? I doubt the latter, but if I install
> >> 2.5, does that mean I need to reinstall all the extensions I had for 2.4
> >> again, or does 2.5 detect them somehow?
> >
> > Without an OS given, difficult answer. Generally, you can assume that there
> > is no need to ditch one version because you use another, they don't
> > interfer with each other. Only which one is perceived as "current" might
> > change and alter some behavior.
> >
> > However, you have to install all extensions again, that is for sure. And
> > most probably some of them won't work so far, as they might need some
> > modification or at least time to make them available as binary.
> >
> > Diez
>
> Thanks for the answers guys. I'm using WinXP. I noticed that when I
> installed 2.5rc2, it wasn't automatically assigned as the default
> version of Python. I wasn't sure if this was just because it was an RC,
> or maybe I have to manually make 2.5 the default. But I will uninstall
> 2.4 first anyway, so it shouldn't matter.
>

1. You need to set your path manually. A BAT file called pypath.bat
placed somewhere on your PATH and containing:
path c:\python%1;c:\python%1\scripts;%path%
might come in handy. Warning: this is best used once each time you open
up a command window; it's cumulative (Windows is not smart enough to
remove duplicate entries) and there is a an upper limit (I believe) on
the size of the PATH.
2. Re-installing purely-Python packages is highly desirable -- don't
just copy existing files from 2.4.
3. Re-installing packages with a binary component (.pyd) on Windows is
*essential* -- they won't work on a Python version other than the one
whose libs they were linked against.

I'd suggest that you uninstall 2.4 later if at all. Ensure that you
have got all the extensions you want/need for 2.5 before you burn your
boats. As Diez says in effect, there is no guarantee that any
particular extension is available for 2.5 on Windows right now.

Cheers,
John

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


Re: newlines and sax.saxutils.quoteattr

2006-09-19 Thread Fredrik Lundh
Edward K. Ream wrote:

> - Does anyone know whether this is guaranteed to be a general solution? That 
> is, are sax parsers *obliged* to ignore newlines in attributes?

 http://www.w3.org/TR/REC-xml/#AVNormalize

> - If sax parsers are indeed obliged to ignore newlines in attributes, would 
> it be a good idea to (optionally?) have sax.saxutils.quoteattr perform the 
> substitution of newlines to '
\n' ?

perhaps.  a really good idea would be store free-format text in 
elements, not attributes, but I guess it's too late to fix OPML.



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


Re: I need some tips to begin a simple project

2006-09-19 Thread Simon Hibbs
> PyGame is in it, right?

Python comes with a basic GUI toolkit called Tk with basic stuff such
as buttons, text and graphics widgets, menus, etc.

PyGame is a seperate package that you can download that makes it fairly
easy to create games. There are also additional libraries that make
PyGame programing even easier.

Having said all that, Python isn't magic. I'd recommend doing something
simple first, such as a calculator or a text editor. These are very
easy to do, but will cover the basics of creating a user interface,
manipulating data and accessing files.

Simon Hibbs

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


Re: CONSTRUCT - Adding Functionality to the Overall System

2006-09-19 Thread Ilias Lazaridis
Diez B. Roggisch wrote:
> Ilias Lazaridis wrote:
> > Ilias Lazaridis wrote:
> >> I understand that I can use __metaclass__ to create a class which
> >> modifies the behaviour of another class.
> >>
> >> How can I add this metaclass to *all* classes in the system?
> >>
> >> (In ruby I would alter the "Class" class)
> >
> > I got confused from the discussion about __metaclass__.
> >
> > possibly a little more practical.
> >
> > I like to add a method "writeDebug(self, msg)" to all (or the most
> > possible) classes in the system.
> >
> > How do I do this?
> >
> > * with new style classes
> > * with old style classes
>
> OMFG. For asking the question (paraphrased) "why do you want to do this",
> Mr. Spealman received an
>
> http://case.lazaridis.com/wiki/Please#OffTopicPosts
>
> But now you do exactly that - give more details. Maybe this could teach you
> the lesson that the variance of input you get here to your questions is
> worth considering?
>
> But I've got the wicked feeling that this won't happen...

I've not given more details, but less.

Just simplified my request.

.

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


Re: CONSTRUCT - Adding Functionality to the Overall System

2006-09-19 Thread Ilias Lazaridis

MonkeeSage wrote:
> Ilias Lazaridis wrote:
> > How do I do this?
>
> It's easy:
>
> def writeDebug(msg):
>   print "I do not debug things, I _evaluate_ with professionals on the
> industries! See ticket 547!\n" \
> "Oh yeah, and %s" % msg

where do I place this function...

> ...
> class Foo:
>   writeDebug("how can I configure the interpreter for understand
> Klingon participals and noun-phrases? Must I rectify the standard
> dictionaries first?")

...thus it becomes available within class "Foo" and all other Classes?

Something like a central import?

.

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


Re: Writing Video conference software for Windows

2006-09-19 Thread Jordan
If you're going to need win32 system access use the win32all python
extension (very, very good extension).  Do you need single frame image
capture, or constant video stream? PIL can be used for the first, it
might also be usable for video, I'm not sure. For sound, python comes
with some built in libraries, but you should also take a look at
pysonic http://www.cs.unc.edu/Research/assist/developer.shtml.  For the
bandwidth efficiency issue, what type of connection are you using? The
socket module is quite capable of transmiting whatever data you have,
so unless you're thinking of implementing some mini bittorrent like
network in an attempt to save bandwidth I don't know what you can do
about that. There's an extension called IPqueue which might give you
somewhere to start for packet/bandwidth manipulation.  Check out The
Vaults of Parnassus, which has a lot of stuff (including ogg/mp3
converters last time a check).Big question, is this supposed to act
like a remote desktop, or just show what's happening?  Start by
searching Google, it's very useful.

Paolo Pantaleo wrote:
> Hi,
>
> I need to write a software that allow to see the desktop and hear the
> microphone capture of a remote PC across a network. I need to do that
> for a unviresity assignement. The software must  run on Windows. Since
> I like Python very much I am thinking to write that software in
> Python. Do you thinkit is a good choice? Are there libraries for audio
> compression (OGG or MP3 or maybe GSM or something like realaudio) and
> video compression (btw what can be some good libraries to transmit
> images of a desktop in a bandwidth-efficent way?). What about capture
> of audio and screen? (Probably i will need some Win32 system call,
> there are bindings in Python, aren't they?)
>
> If I needed to write some Python modules in C, would it be difficult?
>
> Can some language like C# or C++ may be better?
>
> Thnx
> PAolo
>
> --
> if you have a minute to spend please visit my photogrphy site:
> http://mypic.co.nr

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


ANN: Python Molecular Viewer - 1.4.3

2006-09-19 Thread sargis
We are pleased to announce version 1.4.3 of our software tools
including: PMV, ADT and VISION.

Binary (LINUX, Mac OS X and Windows) and Source distributions can be
downloaded from:
http://mgltools.scripps.edu/downloads

NEW FEATURES:
--

PMV:
   - added support for rendering secondary structures in DNAs/RNAs
   - helpCommands.py is added to provide About-->Help widget.
   - added progressBar to APBS Web Services.
   - added Open DX reader to Grid commands.
   - added a command to build coarse molecular surface.

Vision:
  - parenting system is now compatible with geoms imported from pmv
  - introduced real 3d labels

DejaVu:
  - editable color palette to modify predefined atom's colors
  - several new mode of stereo vision
  - improved tile renderer (works also with stereo vision modes)
  - added NucleicBases.py for displaying Nucleic Bases.

Volume:
  - Binary AVS Field data parser is added.
  - added all supported files in ReadAnyMap node.

And of course many bug fixes across all packages.

For other inquiries, send an email to mgltools mgltools(at)scripps.edu

More information can be found on our web site at
http://mgltools.scripps.edu

Thank you for using our tools. 

The MGLTools development team

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


Tkinter and ActiveX event

2006-09-19 Thread swell
Hi,
  I want to integrate into an GUI a activeX component that generate
some events.
What i have done is :
  - Create the activeX component ( DispatchWithEvents method )
  - create the GUI
  - app.mainloop()

My pb is that i don't know how to take into account the events
generated by the activeX component into my Tk app main loop to update
the GUI for ex. Can someone spot me an example or give some clues?

Thx
Manu

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


Curious issue with simple code

2006-09-19 Thread codefire
Hi,

I have some simple code - which works...kind of..here's the code:

[code]
import os

def print_tree(start_dir):
for f in os.listdir(start_dir):
fp = os.path.join(start_dir, f)
print fp
if os.path.isfile(fp): # will return false if use f here!
if os.path.splitext(fp)[1] == '.html':
print 'html file found!'
if os.path.isdir(fp):
print_tree(fp)

print os.path
print_tree(r'c:\intent\docn')
[/code]

As above it all works as expected. However, on the marked line, if I
use f instead of fp then that condition returns false! Surely,
isfile(f) should return true, even if I just give a filename, rather
than the full path? 

If anyway can explain this I'd be grateful,

Tony

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


Re: newlines and sax.saxutils.quoteattr

2006-09-19 Thread Edward K. Ream
Thanks, Fredrik, for the reference to the attribute normalization algorithm.

> I guess it's too late to fix OPML.

It's too late for OPML 1.  I'll check with Dave Winer about OPML 2.

Edward

Edward K. Ream   email:  [EMAIL PROTECTED]
Leo: http://webpages.charter.net/edreamleo/front.html



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


Re: I need some tips to begin a simple project

2006-09-19 Thread codefire

dutche wrote:

> Now, that I know a bit of Python, I want to make some simple project, I
> thought something like a menu, just like "kxdocks" menu or something
> like that, with transparency and all with xml. But I dont know what
> things I have to know.
>

Start with some simple non-gui apps first. How about a text based
lottery number picker program - you can add a GUI later :)

Writing GUI apps takes a bit of experience - I have done it in other
languages but not Python (yet).

There are several good GUI toolkits TK as mentioned and also wxPython
is worth looking at.

Tony

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


Re: win32 Service: path to .py script

2006-09-19 Thread Gregor Horvath
Larry Bates schrieb:

> I believe that your problem is that services run under Local
> System account.  Normally Local System account would not have
> a drive mapping Y:\.  You can change the account that a service

You are absolutly correct.
I moved the script to a local drive instead of a mapped network drive,
now it works perfectly.

Thank you a lot.

-- 
  Servus, Gregor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CONSTRUCT - Adding Functionality to the Overall System

2006-09-19 Thread MonkeeSage
Ilias Lazaridis wrote:
> where do I place this function...

The place where you want it to be.

> ...thus it becomes available within class "Foo" and all other Classes?

Anything defined in the top-level (i.e., the sys.modules['__main__']
namespace) is accessible in every scope...but I assume you already know
that.

You could also use a super-duper super class from which to derive all
your other classes, and add/replace any methods you want there:

class lazaridis(object):
  def evaluate(self, community):
if 1 is 1:
  print "Evaluating %s... Result: failed!" % community

class Foo(lazaridis, str):
  pass

f=Foo('This has been a test of the lazaridis evaluation system')
f.evaluate('Python')
f.evaluate('Ruby')
f.evaluate('Java')
print f

> Something like a central import?

That would probably be the most logical thing to do.

But again, I assume you already know all this, so why are you asking?
Is this part of the evaluation process?

Regards,
Jordan

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


Re: Curious issue with simple code

2006-09-19 Thread Fredrik Lundh
codefire wrote:

> As above it all works as expected. However, on the marked line, if I
> use f instead of fp then that condition returns false! Surely,
> isfile(f) should return true, even if I just give a filename, rather
> than the full path? 

try printing both "f" and "fp", and see if you can tell the difference 
between the two filenames...



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


RE: Curious issue with simple code

2006-09-19 Thread Richard Morello
Dear Tony,

You're not in that directory (start_dir) when the isfile() function is
called.  See function os.path.curdir() and os.chdir().  Also, you may be
confusing the behavior of os.path.walk(), in which the function called will
happen once you have been chdired to the directory it is examining.  

Hope this was helpful.

Yours truly,
Rich.

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
codefire
Sent: Tuesday, September 19, 2006 1:08 PM
To: [email protected]
Subject: Curious issue with simple code


Hi,

I have some simple code - which works...kind of..here's the code:

[code]
import os

def print_tree(start_dir):
for f in os.listdir(start_dir):
fp = os.path.join(start_dir, f)
print fp
if os.path.isfile(fp): # will return false if use f here!
if os.path.splitext(fp)[1] == '.html':
print 'html file found!'
if os.path.isdir(fp):
print_tree(fp)

print os.path
print_tree(r'c:\intent\docn')
[/code]

As above it all works as expected. However, on the marked line, if I use f
instead of fp then that condition returns false! Surely,
isfile(f) should return true, even if I just give a filename, rather than
the full path? 

If anyway can explain this I'd be grateful,

Tony

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


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


Re: Curious issue with simple code

2006-09-19 Thread Diez B. Roggisch
codefire wrote:

> Hi,
> 
> I have some simple code - which works...kind of..here's the code:
> 
> [code]
> import os
> 
> def print_tree(start_dir):
> for f in os.listdir(start_dir):
> fp = os.path.join(start_dir, f)
> print fp
> if os.path.isfile(fp): # will return false if use f here!
> if os.path.splitext(fp)[1] == '.html':
> print 'html file found!'
> if os.path.isdir(fp):
> print_tree(fp)
> 
> print os.path
> print_tree(r'c:\intent\docn')
> [/code]
> 
> As above it all works as expected. However, on the marked line, if I
> use f instead of fp then that condition returns false! Surely,
> isfile(f) should return true, even if I just give a filename, rather
> than the full path?

Of course not, unless a file with that very name exists in the current
working directory. Otherwise, where would be the difference between a
full-path and the leaf path?

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


Re: Curious issue with simple code

2006-09-19 Thread MonkeeSage
codefire wrote:
> As above it all works as expected. However, on the marked line, if I
> use f instead of fp then that condition returns false! Surely,
> isfile(f) should return true, even if I just give a filename, rather
> than the full path?

Hi Tony,

Actually the file is in a different directory from the working
directory, so you need to give it the path where to find it. If you
started the script from 'c:\intent\docn' (i.e., start_dir), then just
using f would work.

Regards,
Jordan

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


Re: Curious issue with simple code

2006-09-19 Thread Tim Chase
 > [code]
 > import os
 >
 > def print_tree(start_dir):
 > for f in os.listdir(start_dir):
 > fp = os.path.join(start_dir, f)
 > print fp
 > if os.path.isfile(fp): # will return false if use f here!
 > if os.path.splitext(fp)[1] == '.html':
 > print 'html file found!'
 > if os.path.isdir(fp):
 > print_tree(fp)
 >
 > print os.path
 > print_tree(r'c:\intent\docn')
 > [/code]
 >
 > As above it all works as expected. However, on the marked
 > line, if I use f instead of fp then that condition returns
 > false! Surely, isfile(f) should return true, even if I
 > just give a filename, rather than the full path?
 >
 > If anyway can explain this I'd be grateful,

If your current working directory (CWD) is the same as
start_dir, the behaviors of using "f" and "fp" will be the
same.  However, if your CWD is *not* the same, "f" is
relative to the CWD, and fp is "start_dir + f" relative to
the CWD.

Thus,

 >>> start_dir = 'temp'
 >>> os.path.abspath(os.path.curdir)
'/home/tim'
 >>> f = 'filename'
 >>> fp = os.path.join(start_dir, f)
 >>> fp
'temp/filename'
 >>> os.path.abspath(f)
'/home/tim/filename'
 >>> os.path.abspath(fp)
'/home/tim/temp/filename'


You may also want to read up on os.walk:

for root, dirs, files in os.walk(start_dir):
 for f in files:
 if os.path.splitext(f)[1].lower()[1:] == 'html':
 print 'HTML:', os.path.join(root, f)
 #else:
 #print 'Not HTML:', os.path.join(root, f)

which allows you to easily do what it looks like your code
is doing.

-tkc





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


Re: Curious issue with simple code

2006-09-19 Thread codefire
Ah of course, isfile(f) can only return true if it can find f! :)

I'm going to investigate those other functions too :)

Thanks a lot guys!
Tony

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


help with relative imports

2006-09-19 Thread John Salerno
I'm reading the "What's New" section of the 2.5 docs, and I'm a little 
confused by the last section of "Absolute and Relative Imports":

---
For example, code in the A.B.C module can do:

from . import D # Imports A.B.D
from .. import E# Imports A.E
from ..F import G   # Imports A.F.G
---

Can someone explain this? It seems like information is missing. How do 
you know where D, E, F and G are to figure this out? If all you are 
given is A.B.C, and then someone gives you the above three examples, 
what steps do you take to figure out what gets imported from where?

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


Re: Installing 2.5 with 2.4?

2006-09-19 Thread John Salerno
John Machin wrote:

> I'd suggest that you uninstall 2.4 later if at all. Ensure that you
> have got all the extensions you want/need for 2.5 before you burn your
> boats. As Diez says in effect, there is no guarantee that any
> particular extension is available for 2.5 on Windows right now.
>

Thanks for the tips. As it turns out, all I really need for 2.4 is 
mysqldb, but since I don't see it for 2.5 yet, I'm keeping 2.4.3 around 
for now.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CONSTRUCT - Adding Functionality to the Overall System

2006-09-19 Thread Steve Holden
Ilias Lazaridis wrote:
> MonkeeSage wrote:
> 
>>Ilias Lazaridis wrote:
>>
>>>How do I do this?
>>
>>It's easy:
>>
>>def writeDebug(msg):
>>  print "I do not debug things, I _evaluate_ with professionals on the
>>industries! See ticket 547!\n" \
>>"Oh yeah, and %s" % msg
> 
> 
> where do I place this function...
> 
> 
>>...
>>class Foo:
>>  writeDebug("how can I configure the interpreter for understand
>>Klingon participals and noun-phrases? Must I rectify the standard
>>dictionaries first?")
> 
> 
> thus it becomes available within class "Foo" and all other Classes?
> 
> Something like a central import?
> 
> ..
> 
Good grief ...
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: help with relative imports

2006-09-19 Thread Robert Kern
John Salerno wrote:
> I'm reading the "What's New" section of the 2.5 docs, and I'm a little 
> confused by the last section of "Absolute and Relative Imports":
> 
> ---
> For example, code in the A.B.C module can do:
> 
> from . import D # Imports A.B.D
> from .. import E# Imports A.E
> from ..F import G   # Imports A.F.G
> ---
> 
> Can someone explain this? It seems like information is missing. How do 
> you know where D, E, F and G are to figure this out? If all you are 
> given is A.B.C, and then someone gives you the above three examples, 
> what steps do you take to figure out what gets imported from where?

What is ambiguous about A.B.D, A.E, and A.F.G? But if you like:

A/
   B/
 C.py
 D.py
   E.py
   F/
 G.py

-- 
Robert Kern

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

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


Re: Mechanoid Web Browser - Recording Capability

2006-09-19 Thread John J. Lee
"Seymour" <[EMAIL PROTECTED]> writes:

> Somehow I had the notion that Mechanize was a Pearl script.

mechanize the Python module started as a port of Andy Lester's Perl
module WWW::Mechanize (in turn based on Gisle Aas' libwww-perl), and
on some very high level has "the same" conceptual interface, but most
of the details (internal structure, features and bugs ;-) are
different to LWP and WWW::Mechanize due to the integration with
urllib2, httplib and friends, and with my own code.  Most parts of the
code are no longer recognisable as having originated in LWP (and of
course, lots of it *didn't* originate there).


John

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


Python 2.5 slower with pyparsing 1.4.3

2006-09-19 Thread Paul McGuire
Running my Verilog parser tests, I get a 5-10% slowdown with Python 2.5 vs. 
Python 2.4.1 (See http://pyparsing.wikispaces.com/News.)

I apologize for not running performance tests sooner, I only ran regression 
tests on the release candidates, and those were all okay.

I'll look through the "What's New in 2.5" and see if there are some features 
I can take advantage of for the upcoming 1.4.4 release (while retaining 
backward compat with Py2.3).

-- Paul


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


Re: Installing Python on a 64-Bit OS

2006-09-19 Thread Martin v. Löwis
Nico Grubert schrieb:
> Is there anything special I have to care about or is installing Python
> on a 64 Bit OS just as easy as installing it on a 32-Bit OS?

Despite what everybody else said: most likely, special care is
necessary. However, nobody probably knows what precisely you need
to be aware of.

Several changes have been made to Python 2.4 and 2.5 to support
AMD64-Linux better, and not all of these changes have been
incorporated into Python 2.3, as this software is no longer
maintained.

My advise is just to try building it, run the test suite, and
see whether it passes. If it fails to compile or pass the
test suite, post a message with the specific problem - hopefully,
somebody will remember how it was fixed.

As others have said: you should really try to use the python 2.4
that comes with the operating system. Can you share the reason why
you have to use Python 2.3?

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


Re: Mechanoid Web Browser - Recording Capability

2006-09-19 Thread John J. Lee
"Seymour" <[EMAIL PROTECTED]> writes:
[...]
> one program, MaxQ, that records web surfing.  It seems to work great.
[...]

There are lots of such programs about (ISTR twill used to use MaxQ for
its recording feature, but I think Titus got rid of it in favour of
his own code, for some reason).  How useful they are depends on the
details of what you're doing: the information that goes across HTTP is
on a fairly low level, so e.g., most obviously, you may need to be
sending a session ID that varies per-request.  Those programs usually
have some way of dealing with that specific problem, but you may run
into other problems that have the same origin.  Don't let me put you
off it gets your job done, but it's good to be a bit wary: All current
web-scraping approaches using free software suck in one way or
another.


John

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


Re: help with relative imports

2006-09-19 Thread John Salerno
Robert Kern wrote:

> What is ambiguous about A.B.D, A.E, and A.F.G? But if you like:

I guess maybe I was looking at it backwards. From the way it was worded, 
I thought the only information we had to use was the structure A.B.C, 
and then given a statement like:

from . import D

we just had to figure out for ourselves that this results in A.B.D, 
instead of, for example, A.C.D, or any other possibility.

But I'm still a little confused about the use of the single or double 
period. In this case:

from . import D # Imports A.B.D
from .. import E# Imports A.E

why do you need a single period in the first example, and a double in 
the second, if they both are importing from A? If E is directly under A, 
couldn't you just use a single period? And since D is nested twice 
beneath A (i.e., in A, then in B), wouldn't you need two periods there 
instead?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nano Technology Application For Health,Wellness and Beauty

2006-09-19 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Dear lovely moderator, please allow me to spread this information,
> somebody might need it, please forgive me if you are bothered
>
> Dear All, this might be useful for you and your family
>



Does it also predict earthquakes?

For your callous targetting of those suffering autism and "other mental and 
physical disease", I suggest a special application of your BIO DISK for the 
treatment of hemorrhoids.

-- Paul 


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


new string method in 2.5 (partition)

2006-09-19 Thread John Salerno
Forgive my excitement, especially if you are already aware of this, but 
this seems like the kind of feature that is easily overlooked (yet could 
be very useful):


Both 8-bit and Unicode strings have new partition(sep) and 
rpartition(sep) methods that simplify a common use case.
The find(S) method is often used to get an index which is then used to 
slice the string and obtain the pieces that are before and after the 
separator. partition(sep) condenses this pattern into a single method 
call that returns a 3-tuple containing the substring before the 
separator, the separator itself, and the substring after the separator. 
If the separator isn't found, the first element of the tuple is the 
entire string and the other two elements are empty. rpartition(sep) also 
returns a 3-tuple but starts searching from the end of the string; the 
"r" stands for 'reverse'.

Some examples:


 >>> ('http://www.python.org').partition('://')
('http', '://', 'www.python.org')
 >>> ('file:/usr/share/doc/index.html').partition('://')
('file:/usr/share/doc/index.html', '', '')
 >>> (u'Subject: a quick question').partition(':')
(u'Subject', u':', u' a quick question')
 >>> 'www.python.org'.rpartition('.')
('www.python', '.', 'org')
 >>> 'www.python.org'.rpartition(':')
('', '', 'www.python.org')

(Implemented by Fredrik Lundh following a suggestion by Raymond Hettinger.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Curious issue with simple code

2006-09-19 Thread George Sakkis
codefire wrote:

> Ah of course, isfile(f) can only return true if it can find f! :)
>
> I'm going to investigate those other functions too :)
>
> Thanks a lot guys!
> Tony

By the way, an easier way to deal with paths is the path.py module
(http://www.jorendorff.com/articles/python/path/). Your example could
be rewritten simply as:

from path import path
for html_file in path(start_dir).walkfiles('*.html'):
print 'html file found!' 

George

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


Re: xmlrpc, extract data from http headers

2006-09-19 Thread Milos Prudek

> A better solution would be to extract cookies from headers in the
> request method and return them with response (see the code below). I

Full solution! Wow! Thank you very much. I certainly do not deserve such 
kindness. Thanks a lot Filip!

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


Re: help with relative imports

2006-09-19 Thread [EMAIL PROTECTED]

John Salerno wrote:
> Robert Kern wrote:
>
> > What is ambiguous about A.B.D, A.E, and A.F.G? But if you like:
>
> I guess maybe I was looking at it backwards. From the way it was worded,
> I thought the only information we had to use was the structure A.B.C,
> and then given a statement like:
>
> from . import D
>
> we just had to figure out for ourselves that this results in A.B.D,
> instead of, for example, A.C.D, or any other possibility.
>
> But I'm still a little confused about the use of the single or double
> period. In this case:
>
> from . import D # Imports A.B.D
> from .. import E# Imports A.E
>
> why do you need a single period in the first example, and a double in
> the second, if they both are importing from A? If E is directly under A,
> couldn't you just use a single period? And since D is nested twice
> beneath A (i.e., in A, then in B), wouldn't you need two periods there
> instead?

I was staring at this too for a bit.
You just have to remember basic directory relative paths:
. -> Current Directory
.. -> One level up from current.

At least I'm assuming this is right based on the test and the example
above.

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


Re: new string method in 2.5 (partition)

2006-09-19 Thread metaperl
sweet thanks for the heads up.

John Salerno wrote:
> Forgive my excitement, especially if you are already aware of this, but
> this seems like the kind of feature that is easily overlooked (yet could
> be very useful):
>
>
> Both 8-bit and Unicode strings have new partition(sep) and
> rpartition(sep) methods that simplify a common use case.
> The find(S) method is often used to get an index which is then used to
> slice the string and obtain the pieces that are before and after the
> separator. partition(sep) condenses this pattern into a single method
> call that returns a 3-tuple containing the substring before the
> separator, the separator itself, and the substring after the separator.
> If the separator isn't found, the first element of the tuple is the
> entire string and the other two elements are empty. rpartition(sep) also
> returns a 3-tuple but starts searching from the end of the string; the
> "r" stands for 'reverse'.
>
> Some examples:
>
>
>  >>> ('http://www.python.org').partition('://')
> ('http', '://', 'www.python.org')
>  >>> ('file:/usr/share/doc/index.html').partition('://')
> ('file:/usr/share/doc/index.html', '', '')
>  >>> (u'Subject: a quick question').partition(':')
> (u'Subject', u':', u' a quick question')
>  >>> 'www.python.org'.rpartition('.')
> ('www.python', '.', 'org')
>  >>> 'www.python.org'.rpartition(':')
> ('', '', 'www.python.org')
>
> (Implemented by Fredrik Lundh following a suggestion by Raymond Hettinger.)

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


Re: help with relative imports

2006-09-19 Thread Robert Kern
John Salerno wrote:
> Robert Kern wrote:
> 
>> What is ambiguous about A.B.D, A.E, and A.F.G? But if you like:
> 
> I guess maybe I was looking at it backwards. From the way it was worded, 
> I thought the only information we had to use was the structure A.B.C, 
> and then given a statement like:
> 
> from . import D
> 
> we just had to figure out for ourselves that this results in A.B.D, 
> instead of, for example, A.C.D, or any other possibility.
> 
> But I'm still a little confused about the use of the single or double 
> period. In this case:
> 
> from . import D # Imports A.B.D
> from .. import E# Imports A.E
> 
> why do you need a single period in the first example, and a double in 
> the second, if they both are importing from A? If E is directly under A, 
> couldn't you just use a single period? And since D is nested twice 
> beneath A (i.e., in A, then in B), wouldn't you need two periods there 
> instead?

Remember that this is code in the A.B.C module. The first form looks for 
modules 
in the A.B package, that is, next to A.B.C . The second looks for modules in 
the 
A package, next to A.B .

-- 
Robert Kern

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

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


Re: new string method in 2.5 (partition)

2006-09-19 Thread [EMAIL PROTECTED]
I'm confused.
What's the difference between this and string.split?

John Salerno wrote:
> Forgive my excitement, especially if you are already aware of this, but
> this seems like the kind of feature that is easily overlooked (yet could
> be very useful):
>
>
> Both 8-bit and Unicode strings have new partition(sep) and
> rpartition(sep) methods that simplify a common use case.
> The find(S) method is often used to get an index which is then used to
> slice the string and obtain the pieces that are before and after the
> separator. partition(sep) condenses this pattern into a single method
> call that returns a 3-tuple containing the substring before the
> separator, the separator itself, and the substring after the separator.
> If the separator isn't found, the first element of the tuple is the
> entire string and the other two elements are empty. rpartition(sep) also
> returns a 3-tuple but starts searching from the end of the string; the
> "r" stands for 'reverse'.
>
> Some examples:
>
>
>  >>> ('http://www.python.org').partition('://')
> ('http', '://', 'www.python.org')
>  >>> ('file:/usr/share/doc/index.html').partition('://')
> ('file:/usr/share/doc/index.html', '', '')
>  >>> (u'Subject: a quick question').partition(':')
> (u'Subject', u':', u' a quick question')
>  >>> 'www.python.org'.rpartition('.')
> ('www.python', '.', 'org')
>  >>> 'www.python.org'.rpartition(':')
> ('', '', 'www.python.org')
>
> (Implemented by Fredrik Lundh following a suggestion by Raymond Hettinger.)

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


value exists (newbie question)

2006-09-19 Thread eldorado
Hello,

I am trying to parse some files so that if a postal code exists, but is 
longer than five digits it will return me only the first five digits:
...
for insDict in insureDict:
insDict['postalcode'] = insDict.get('postalcode')[:5]
...
This works, except for when I get a blank postalcode.  In which case I get 
the following error.
ERR exceptions.TypeError: iteration over non-sequence

What I would like to do is to check to make sure a value exists.  I just 
cannot seem to find the syntax to do that.  (not asking anyone to write my 
code, just looking for a pointer)

Thanks


-- 
Randomly generated signature --
In God I Trust -- on all others I use dsniff, ettercap and lczroex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new string method in 2.5 (partition)

2006-09-19 Thread Lawrence Oluyede
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> What's the difference between this and string.split?

>>> ('http://www.python.org').partition('://')
('http', '://', 'www.python.org')
>>> ('http://www.python.org').split('://')
['http', 'www.python.org']



-- 
Lawrence - http://www.oluyede.org/blog
"Nothing is more dangerous than an idea
if it's the only one you have" - E. A. Chartier
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new string method in 2.5 (partition)

2006-09-19 Thread John Salerno
[EMAIL PROTECTED] wrote:
> I'm confused.
> What's the difference between this and string.split?

 >>> s = 'hello, world'

 >>> s.split(',')
['hello', ' world']

 >>> s.partition(',')
('hello', ',', ' world')


split returns a list of the substrings on either side of the specified 
argument.

partition returns a tuple of the substring on the left of the argument, 
the argument itself, and the substring on the right. rpartition reads 
from right to left.


But you raise a good point. Notice this:

 >>> s = 'hello, world, how are you'

 >>> s.split(',')
['hello', ' world', ' how are you']

 >>> s.partition(',')
('hello', ',', ' world, how are you')

split will return all substrings. partition (and rpartition) only return 
the substrings before and after the first occurrence of the argument.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >