Re: fast regex

2010-05-11 Thread Paul Rubin
Lawrence D'Oliveiro  writes:
> “Fast regex” is a contradiction in terms. You use regexes when you want ease 
> of definition and application, not speed.
>
> For speed, consider hand-coding your own state machine. Preferably in a 
> compiled language like C.

But, nothing stops a regexp library from doing that, and some of them do.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Upgrade Python 2.6.4 to 2.6.5

2010-05-11 Thread Werner F. Bruhin

Martin,

Thanks for the quick reply.

On 10/05/2010 22:25, Martin v. Loewis wrote:

Werner F. Bruhin wrote:
   

Just upgraded on my Windows 7 machine my copy of 2.6.4 to 2.6.5.

However doing sys.version still shows 2.6.4 even so python.exe is dated
19. March 2010 with a size of 26.624 bytes.

Is this a known issue?  Or did I do something wrong?
 

Look at the copy of python26.dll. This should be the new one; perhaps
you have another copy in the system32 folder?
   

The one in system32 is 2.6.5 and the one in c:\python26 is 2.6.4.

When will it install into system32?

Did the upgrade inform you that it was an upgrade, or did it warn you
that you would overwrite the previous installation?
   

It warned me that there is a previous installation.

Best regards
Werner

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


Iterating a sequence two items at a time

2010-05-11 Thread Ulrich Eckhardt
Hi!

I have a list [1,2,3,4,5,6] which I'd like to iterate as (1,2), (3,4),
(5,6). I can of course roll my own, but I was wondering if there was
already some existing library function that already does this.


def as_pairs(seq):
i = iter(seq)
yield (i.next(), i.next())

Question to this code: Is the order of the "i.next()" calls guaranteed to be
from left to right? Or could I end up with pairs being switched?

Thanks!

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: Is Python a functional programming language?

2010-05-11 Thread Paul Rubin
Luis M. González  writes:
> That doesn't mean python can compete with other purely functional
> languages, but it's probably as functional as it can be for a more
> conventional, multiparadigm language.

Ben Lippmeier made the interesting claim that one of the defining
characteristics of functional programming is type systems based on the
Curry-Howard correspondence.  By that standard I think even Scheme
(perhaps the grandaddy of functional languages) wouldn't qualify.

I do think of Scheme as a functional language, but of Python and Lisp as
imperative languages with functional aspects.

I like learnyouahaskell.com if you want to get some exposure to Haskell,
probably the archetypal functional language these days.  I've been
fooling with it on and off for the past couple years.  I'm still not
convinced that it's that good a vehicle for practical general purpose
software development, but there are some specific areas where it works
out just beautifully.  And in terms of the challenges it presents and
the amount I've learned from it, it's one of the most interesting things
I've done as a programmer in as long as I can remember.  It really is
mind altering.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Iterating a sequence two items at a time

2010-05-11 Thread Chris Rebert
On Tue, May 11, 2010 at 12:09 AM, Ulrich Eckhardt
 wrote:
> Hi!
>
> I have a list [1,2,3,4,5,6] which I'd like to iterate as (1,2), (3,4),
> (5,6). I can of course roll my own, but I was wondering if there was
> already some existing library function that already does this.

When a problem involves iteration, always check the `itertools` module
in the std lib.
From the module docs's recipe section
(http://docs.python.org/library/itertools.html#recipes):

import itertools
def grouper(n, iterable, fillvalue=None):
"grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
args = [iter(iterable)] * n
return itertools.izip_longest(fillvalue=fillvalue, *args)

>>> # Let's try it out.
>>> list(grouper(2, [1,2,3,4,5,6]))
[(1, 2), (3, 4), (5, 6)]
>>> # Success!

> def as_pairs(seq):
>    i = iter(seq)
>    yield (i.next(), i.next())
>
> Question to this code: Is the order of the "i.next()" calls guaranteed to be
> from left to right? Or could I end up with pairs being switched?

Pretty sure left-to-right is guaranteed; see http://bugs.python.org/issue448679
Also, if you're using Python 2.6+, the line should be:
yield (next(i), next(i))
See http://docs.python.org/library/functions.html#next

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTTP Post Request

2010-05-11 Thread kak...@gmail.com
On May 11, 5:06 am, Kushal Kumaran 
wrote:
> On Mon, May 10, 2010 at 8:26 PM, kak...@gmail.com  wrote:
> > On May 10, 10:22 am, Kushal Kumaran 
> > wrote:
> >> On Mon, May 10, 2010 at 7:30 PM, kak...@gmail.com  wrote:
> >> > Hi to all, i want to ask you a question, concerning the best way to do
> >> > the following as a POST request:
> >> > There is server-servlet that accepts xml commands
> >> > It had the following HTTP request headers:
>
> >> >            Host: somehost.com
> >> >            User-Agent: Jakarta Commons-HttpClient
> >> >            Content-Type: text/xml
> >> >            Content-Length: 415
>
> >> > and the following request body (reformatted here for clarity):
>
> >> >            
> >> >            
> >> >              search
> >> >            
> >> > How can i send the above to the Listener Servlet?
> >> > Thanks in advance
>
> >> Use the xmlrpclib module.
>
> > OK, sending headers with xmlrpclib,
> > but how do i send the XML message?
>
> Your XML message is an XML RPC message.  You will use xmlrpclib like this:
>
> server_proxy = xmlrpclib.ServerProxy(('somehost.com', 80))
> result = server_proxy.search()
>
> The call to server_proxy.search will result in an actual XML RPC
> message being sent.
>
> Read up on the xmlrpclib documentation 
> here:http://docs.python.org/library/xmlrpclib.html, and the XMLRPC spec
> here:http://www.xmlrpc.com/spec
>
> --
> regards,
> kushal

Ok I got it!
Thank you!!!

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


Re: Iterating a sequence two items at a time

2010-05-11 Thread Bruno Desthuilliers

Ulrich Eckhardt a écrit :

Hi!

I have a list [1,2,3,4,5,6] which I'd like to iterate as (1,2), (3,4),
(5,6). I can of course roll my own, but I was wondering if there was
already some existing library function that already does this.




>>> l = range(10)
>>> for x, y in zip(l[::2], l[1::2]):
...   print x, y
...
0 1
2 3
4 5
6 7
8 9

SimplestThingThatCouldPossiblyWork(tm) - but might not be the most 
efficient idiom, specially with large lists...



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


inherit from data type

2010-05-11 Thread Richard Lamboj

Hello,

i want to inherit from a data type. How can i do this? Can anyone explain more 
abou this? How knows python that it is a float, or a string?

Kind Regards

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


Re: fast regex

2010-05-11 Thread Bryan
Lawrence D'Oliveiro wrote:
> “Fast regex” is a contradiction in terms. You use
> regexes when you want ease of definition and
> application, not speed.

Python or Perl regex's are not actually regular expressions. Real
regular expression compilers produce blazing fast results, but they
cannot support many of the features of offered by the search-and-
backtrack engines that Python and Perl use.

> For speed, consider hand-coding your own state
> machine. Preferably in a compiled language like C.

The speed of a real regular expression engine is hard to beat.

I assume you're not actually suggesting hand-writing a state machine
for the problem at issue here, which requires recognizing about 5000
different words.

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


Re: Iterating a sequence two items at a time

2010-05-11 Thread Ulrich Eckhardt
Ulrich Eckhardt wrote:
> I have a list [1,2,3,4,5,6] which I'd like to iterate as (1,2), (3,4),
> (5,6). I can of course roll my own, but I was wondering if there was
> already some existing library function that already does this.
> 
> 
> def as_pairs(seq):
> i = iter(seq)
> yield (i.next(), i.next())

Obviously this code does _not_ do what I want, it must be like this:

 def as_pairs(seq):
 i = iter(seq)
 while True:
 yield (i.next(), i.next())

Gah!

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: inherit from data type

2010-05-11 Thread Ulrich Eckhardt
Richard Lamboj wrote:
> i want to inherit from a data type. How can i do this? Can anyone explain
> more abou this?

Other than in e.g. C++ where int and float are special types, you can
inherit from them in Python like from any other type. The only speciality
of int, float and string is that they are immutable.

> How knows python that it is a float, or a string? 

I'm not actually sure I understand this question. If you derive from float,
Python obviously knows that you derive from float


Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: inherit from data type

2010-05-11 Thread James Mills
On Tue, May 11, 2010 at 6:38 PM, Richard Lamboj
 wrote:
> i want to inherit from a data type. How can i do this? Can anyone explain more
> abou this? How knows python that it is a float, or a string?

$ python
Python 2.6.5 (r265:79063, Apr 27 2010, 18:26:49)
[GCC 4.4.1 (CRUX)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class MyFloat(float):
... def __repr__(self):
... return "MyFloat(%f)" % self
...
>>> x = MyFloat(3.1415926535897931)
>>> x
MyFloat(3.141593)
>>>

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


Re: inherit from data type

2010-05-11 Thread Bruno Desthuilliers

Richard Lamboj a écrit :

Hello,

i want to inherit from a data type. How can i do this?


Hmmm, let's see... Could it be possible that it's documented somewhere ? 
Like, in the FineManual(tm) ?-)


http://docs.python.org/tutorial/classes.html#inheritance

Can anyone explain more 
abou this? How knows python that it is a float, or a string?


which "it" ?

Sorry, I'd like to help but I can't make sense of this question...
--
http://mail.python.org/mailman/listinfo/python-list


How to eliminate "Debug: src/helpers.cpp(140): 'CreateActCtx' failed" message ?

2010-05-11 Thread Barak, Ron
Hi,

I created my first py2exe windows exe, and when it's run, I see on the console:

$ ./svm_ts_tool_in_progress.exe
11:49:32: Debug: src/helpers.cpp(140): 'CreateActCtx' failed with error 
0x007b (the filename, directory name, or volume label syntax is incorrect.).

This is a non-fatal error and the application continues to run.

I googled, but did not find a way to eliminate this Debug message.

Could you suggest how to eliminate this message ?

Thanks,
Ron.



Notes:

$ python -V
Python 2.6.4

$ cat setup.py
#!/usr/bin/env python

from distutils.core import setup
import py2exe
from glob import glob

"""
data_files = [("Microsoft.VC90.CRT", glob(r'C:\Program Files\HHD Software\Hex 
Editor Neo\Microsoft.VC90.CRT\*.*'))]
icon_files = [("icons", 
glob(r'c:\views\cc_view\TS_svm_ts_tool\svm_ts_tool\*.gif'))]
"""

file_list = []
for i in glob(r'c:\views\cc_view\TS_svm_ts_tool\svm_ts_tool\*.gif'):
file_list.append(i)

data_files = [("data", file_list)]

setup(
data_files=data_files
)

setup(
console=["svm_ts_tool_in_progress.py"],
zipfile=None,
options={ "py2exe" :
   {"optimize" : 1
   }
  }
)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: inherit from data type

2010-05-11 Thread Richard Lamboj

Am Tuesday 11 May 2010 10:47:35 schrieb Ulrich Eckhardt:
> Richard Lamboj wrote:
> > i want to inherit from a data type. How can i do this? Can anyone explain
> > more abou this?
>
> Other than in e.g. C++ where int and float are special types, you can
> inherit from them in Python like from any other type. The only speciality
> of int, float and string is that they are immutable.
>
> > How knows python that it is a float, or a string?
>
> I'm not actually sure I understand this question. If you derive from float,
> Python obviously knows that you derive from float
>
>
> Uli
>
> --
> Sator Laser GmbH
> Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

"How knows python that it is a float, or a string?" Sorry this was bad 
expressed. I want to create a new data type, which inherits from float. I 
just know the "dir" function and the "help" function to get more infromations 
about the class, but i need to get more information about the class 
structure.

What i also want to know:
>>> variable1 = 10.50
>>> type(variable1)


Is there a way to tell python that it use antoher class than float for float, 
like myfloat? Its just a "tell-me-what-is-possible".

Sample:
>>> variable1 = 10.50
>>> type(variable1)


Kind Regards,

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


How to make this doctest work?

2010-05-11 Thread
Hello

I ran across this accidentally and wonders how to make the doctest in
following code snippet work:


import doctest

def a():
 """
>>> a = '\\r\\n'
>>> print a


No matter how many blank lines I add here, it just can't get enough -_-
"""
pass

doctest.testmod()



ps: I want variable "a" to be '\r\n', but python kept telling me
ValueError: line 4 of the docstring has inconsistent leading
whitespace: "'"
Why can't doctest module deal with statement "a='\r\n'"?

-- 
Luyun Xie
http://magefromhell.blogspot.com/
(http://blog.hellmage.info/)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: inherit from data type

2010-05-11 Thread Chris Rebert
On Tue, May 11, 2010 at 2:18 AM, Richard Lamboj
 wrote:

> What i also want to know:
 variable1 = 10.50
 type(variable1)
> 
>
> Is there a way to tell python that it use antoher class than float for float,
> like myfloat? Its just a "tell-me-what-is-possible".
>
> Sample:
 variable1 = 10.50
 type(variable1)
> 

No, it's not possible to have the float literal syntax produce
instances of your custom subclass.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Dynamically compiling and reloading SWIG .pyd file

2010-05-11 Thread Dave Guthrie
I am creating an application which has it's code split between python
and C. The Python is used to provide a high level GUI interface and
the C is for low level functions. I use SWIG to create Python Bindings
for the C functions. I want to implement a feature where there is a
button in the toolbar of the GUI which will automatically compile the
C code into a .pyd file. The problem I have is when the GUI is
running, the .pyd is loaded as a DLL and thus is locked by the GUI, so
I can't get "gcc" to overwrite the .pyd file.

I have tried to force the GUI to close it's handle on the file

handle =
ctypes.windll.kernel32.GetModuleHandleA("_FirmwareSubSys.pyd")

if handle == 0:
print "_FirmwareSubSys.pyd not loaded"
else:
_ctypes.FreeLibrary(handle)

But by doing this the next time I load the DLL python crashes.

Do anyone know how to dynamically compile and load SWIG Python
Bindings?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: inherit from data type

2010-05-11 Thread Ulrich Eckhardt
Richard Lamboj wrote:
> "How knows python that it is a float, or a string?" Sorry this was bad
> expressed. I want to create a new data type, which inherits from float. I
> just know the "dir" function and the "help" function to get more
> infromations about the class, but i need to get more information about the
> class structure.

I'd suggest the tutorial, see http://docs.python.org, though your question
is already beyond the range of beginners' questions.

> What i also want to know:
 variable1 = 10.50
 type(variable1)
> 
> 
> Is there a way to tell python that it use antoher class than float for
> float, like myfloat? Its just a "tell-me-what-is-possible".
> 
> Sample:
 variable1 = 10.50
 type(variable1)
> 

The expression "10.5" will always be a float, you can't change that. What
you can do is create your own type, derived from float:

  >>> class myfloat(float):
  ... pass
  ...

and then create an object of that type:

  >>> x = myfloat(3.14)
  >>> type(x)
  
  >>>  


Lastly one warning: In many cases where people wanted to derive from a
concrete data type, their problems were easier solved by external code. I
don't know your problem though.

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: Picking a license

2010-05-11 Thread Paul Boddie
On 10 Mai, 17:01, Patrick Maupin  wrote:
>
> I'll be charitable and assume the fact that you can make that
> statement without apparent guile merely means that you haven't read
> the post I was referring to:
>
> http://www.gnu.org/philosophy/why-not-lgpl.html

Of course I have read it, and not just recently either. But this is a
position paper by the author of the licence, and it doesn't mean that
someone who has written a GPL-licensed library completely agrees with
that position. And anyway, it's a case of "take it or leave it" - it's
not like the author or the FSF are sneaking stuff into every product
and every corner of the market and then telling you that you can't
"unchoose" their stuff.

[...]

> Legally, I don't think they can dictate the license terms of, e.g.
> clisp just because it can link to readline.  But practically, they DID
> manage to do this, simply because Bruno Haible, the clisp author, was
> more concerned about writing software than spending too much time
> sparring with Stallman over the license, so he finally licensed clisp
> under the gpl.  clisp *could* use readline, but didn't require it;
> nonetheless Stallman argued that clisp was a "derivative" of
> readline.  That case of the tail wagging the dog would be laughable if
> it hadn't worked.  In any case, Stallman's success at that tactic is
> probably one of the things that led him to write the paper on why you
> should use GPL for your library.

Although it seems quite unfair, the e-mail discussion about the
licence does show that Stallman was not initially convinced that works
should be affected in such a way (with regard to the Objective-C
compiler developed by NeXT), and that Haible was not strongly opposed
to changing the licence. You can argue that Stallman overreached by
demanding a licence change and that consideration of such matters has
progressed since that time, but Haible always had the option of not
using or supporting readline - only the latter is contentious, and the
obligation of GPL-compatible licensing (as opposed to GPL-licensing)
now diminishes how contentious this is today.

[...]

> I think that, legally, they probably don't have a leg to stand on for
> some of their overarching claims (e.g. about shipping proprietary
> software that could link to readline, without even shipping
> readline).  But morally -- well, they've made their position
> reasonably clear and I try to abide by it.  That still doesn't make it
> "not really FUD."  I'd call this sort of badgering "copyright misuse"
> myself.

Again, you have to consider the intent of the licensing: that some
software which links to readline results in a software system that
should offer the "four freedoms", because that's the price of linking
to readline whose licence has promised that any system which builds
upon it shall offer those privileges.

> > As for rst2pdf, what your modifications would mean is that the
> > software would need to be redistributed under a GPL-compatible
> > licence.
>
> That's parsing semantics rather finely.  In practice, what it really
> means is that the combination (e.g. the whole program) would
> effectively be GPL-licensed.  This then means that downstream users
> would have to double-check that they are not combining the whole work
> with licenses which are GPL-incompatible, even if they are not using
> the svg feature.  Hence, the term "viral."

Once again, I refer you to the intent of the licensing: if someone has
the software in front of them which uses svglib, then they need to
have the privileges granted to them by the GPL. Yes, if the software
also uses some component with a GPL-incompatible licence, then this
causes a problem.

[...]

> http://www.gnu.org/licenses/gpl-faq.html#GPLInProprietarySystem
>
> "A system incorporating a GPL-covered program is an extended version
> of that program. The GPL says that any extended version of the program
> must be released under the GPL if it is released at all."
>
> This makes it clear that the overall work must be GPLed.  Now, all of
> a sudden, downstream users cannot do some things they could have done
> before.  Can you not see that taking a preexisting MIT-licensed
> project and adding code to make it GPL could negatively affect some of
> its users and that that is not necessarily an unalloyed good?

Well, I have referred several times to WebKit without you taking the
hint, but that provides a specific case of a project which is LGPL-
licensed despite being based on (in GPLv3 terminology) libraries which
were distributed under the GPL and combined with that software.
Similarly, the effort to ensure that CPython's licence was GPL-
compatible had a lot to do with the right to redistribute with GPL-
licensed code (actually readline, if I remember correctly).

[...]

> > Well, even the FSF doesn't approve of trivial projects using the GPL:
>
> >http://www.gnu.org/licenses/gpl-faq.html#WhatIfWorkIsShort
>
> Sure, that's a pragmatic view -- copyright might not even be permitted

Re: HTTP Post Request

2010-05-11 Thread kak...@gmail.com
On May 11, 10:56 am, "kak...@gmail.com"  wrote:
> On May 11, 5:06 am, Kushal Kumaran 
> wrote:
>
>
>
> > On Mon, May 10, 2010 at 8:26 PM, kak...@gmail.com  wrote:
> > > On May 10, 10:22 am, Kushal Kumaran 
> > > wrote:
> > >> On Mon, May 10, 2010 at 7:30 PM, kak...@gmail.com  
> > >> wrote:
> > >> > Hi to all, i want to ask you a question, concerning the best way to do
> > >> > the following as a POST request:
> > >> > There is server-servlet that accepts xml commands
> > >> > It had the following HTTP request headers:
>
> > >> >            Host: somehost.com
> > >> >            User-Agent: Jakarta Commons-HttpClient
> > >> >            Content-Type: text/xml
> > >> >            Content-Length: 415
>
> > >> > and the following request body (reformatted here for clarity):
>
> > >> >            
> > >> >            
> > >> >              search
> > >> >            
> > >> > How can i send the above to the Listener Servlet?
> > >> > Thanks in advance
>
> > >> Use the xmlrpclib module.
>
> > > OK, sending headers with xmlrpclib,
> > > but how do i send the XML message?
>
> > Your XML message is an XML RPC message.  You will use xmlrpclib like this:
>
> > server_proxy = xmlrpclib.ServerProxy(('somehost.com', 80))
> > result = server_proxy.search()
>
> > The call to server_proxy.search will result in an actual XML RPC
> > message being sent.
>
> > Read up on the xmlrpclib documentation 
> > here:http://docs.python.org/library/xmlrpclib.html, and the XMLRPC spec
> > here:http://www.xmlrpc.com/spec
>
> > --
> > regards,
> > kushal
>
> Ok I got it!
> Thank you!!!
>
> A.K

Apparently the server i'm trying to connect accepts only POST
connections. So xmlrpclib is useless.
I think I need the httplib library module.

Any hints?

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


Re: Picking a license

2010-05-11 Thread Paul Boddie
On 10 Mai, 20:36, Patrick Maupin  wrote:
>
> I've addressed this before.  Aahz used a word in an accurate, but to
> you, inflammatory, sense, but it's still accurate -- the man *would*
> force you to pay for the chocolate if you took it.

Yes, *if* you took it. He isn't forcing you to take it, though, is he?

> You're making it sound like whining, but Aahz was simply trying to state a 
> fact.

It is whining if someone says, "I really want that chocolate, but that
nasty man is going to make me pay for it!"

> The fact is, I know the man would force me to pay for the chocolate, so in
> some cases that enters into the equation and keeps me from wanting the
> chocolate.

If the man said, "please take the chocolate, but I want you to share
it with your friends", and you refused to do so because you couldn't
accept that condition, would it be right to say, "that man is forcing
me to share chocolate with my friends"?

>  This isn't whining; just a common-sense description of
> reality.  Personally, I think this use of the word "force" is much
> less inflammatory than the deliberate act of co-opting the word
> "freedom" to mean "if you think you can take this software and do
> anything you want with it, you're going to find out differently when
> we sue you."

The word "freedom" means a number of things. If you don't like the way
Messrs Finney and Stallman use the term, please take it up with them.
But to say that someone entering a voluntary agreement is "forced" to
do something, when they weren't forced into that agreement in the
first place, is just nonsense. It's like saying that the shopkeeper is
some kind of Darth Vader character who is coercing people to take the
chocolate and then saddling them with obligations against their will.

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


Re: lame sphinx questions [Was: lame epydoc questions]

2010-05-11 Thread Jean-Michel Pichavant

Phlip wrote:

On May 10, 1:51 pm, Phlip  wrote:
  

On May 10, 1:39 pm, Chris Rebert  wrote:



Sphinx is in vogue right now:http://sphinx.pocoo.org/
  


Okay, we have ten thousand classes to document. How to add them all to
index.rst?
  
I remember trying using Sphinx for auto documented APIs, but it was not 
suitable at that time. You can include API docs generated from the code, 
but you still need to write the docs around.

If I'm correct,  Sphinx is one of the best tool to document public APIs.
However to build internal documentation with everything from interfaces 
to implementations, epydoc is still the best, it builds everything with 
no additional writing, just press the button.



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


win32com sql update problem

2010-05-11 Thread Mark Carter
Consider the following snippet of code:

import win32com.client

DSN = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=M:\\Finance\\camel\
\camel.mdb;'
conn.Open(DSN)
cursor = conn.Execute("UPDATE tblInvoice SET InvComments='Python'
WHERE InvBillingPeriod = 'April 2010' AND InvJobCode = '2169'")
rows = cursor.Affected_Rows()
print rows
conn.Close()

I am using Python 2.6.5, and pywin32. If I try to run it, I get the
response:
Traceback (most recent call last):
  File "C:/Users/mcarter/tacc/pypms/post.py", line 79, in 
AdjustPms(d)
  File "C:/Users/mcarter/tacc/pypms/post.py", line 64, in AdjustPms
cursor = conn.Execute("UPDATE tblInvoice SET InvComments='Python'
WHERE InvBillingPeriod = 'April 2010' AND InvJobCode = '2169'")
  File "", line 3, in Execute
  File "C:\Python26\lib\site-packages\win32com\client\dynamic.py",
line 272, in _ApplyTypes_
result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags,
retType, argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0,
u'Microsoft JET Database Engine', u"Cannot open database ''.  It may
not be a database that your application recognizes, or the file may be
corrupt.", None, 5003049, -2147467259), None)

I have used the same DNS to retrieve data from the database using
SELECT statements, so I'm at a loss to figure out what's going wrong.
It seems to think the database name as an empty string. I'm not sure
if that's the root cause of the problem, though. Any ideas?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python a functional programming language?

2010-05-11 Thread Lawrence D'Oliveiro
In message <7xvdavd4bq@ruckus.brouhaha.com>, Paul Rubin wrote:

> Python is a pragmatic language from an imperative tradition ...

I thought the opposite of “functional” was “procedural”, not “imperative”. 
The opposite to the latter is “declarative”. But (nearly) all procedural 
languages also have declarative constructs, not just imperative ones 
(certainly Python does). Presumably an “imperative” language would not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python a functional programming language?

2010-05-11 Thread Lawrence D'Oliveiro
In message , Stefan 
Behnel wrote:

> But the beauty is that Python is multi-paradigm ...

The trouble with “multi-paradigm” is that it offends the zealots on all 
sides. It’s like saying that, to effect a compromise among multiple 
conflicting monotheistic religions, we should create a polytheistic amalgam 
of them.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Picking a license

2010-05-11 Thread Steven D'Aprano
On Tue, 11 May 2010 03:34:49 -0700, Paul Boddie wrote:

> It's like saying that the shopkeeper is some kind of Darth Vader
> character who is coercing people to take the chocolate

Last time I came home with chocolate, I tried that excuse on my wife. She 
didn't believe it for a second.

Next time, I'll try claiming that I was obliged to eat the chocolate 
because of the GPL.


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


Re: Is Python a functional programming language?

2010-05-11 Thread Stefan Behnel

Lawrence D'Oliveiro, 11.05.2010 13:13:

Stefan Behnel wrote:


But the beauty is that Python is multi-paradigm ...


The trouble with “multi-paradigm” is that it offends the zealots on all
sides. It’s like saying that, to effect a compromise among multiple
conflicting monotheistic religions, we should create a polytheistic amalgam
of them.


The Romans were pretty successful in doing so, for several hundred years. 
Let's see if Python will conquer and rule for that long.


Stefan

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


unittest basics

2010-05-11 Thread John Maclean
is there a way to test that a certian library or module is or can be 
loaded successfully?


self.assert('import blah')

--
John Maclean
MSc. (DIC) BSc. (Hons)
Linux Systems and Applications
07739 171 531
--
http://mail.python.org/mailman/listinfo/python-list


Re: inherit from data type

2010-05-11 Thread Richard Lamboj

Am Tuesday 11 May 2010 11:38:42 schrieb Ulrich Eckhardt:
> Richard Lamboj wrote:
> > "How knows python that it is a float, or a string?" Sorry this was bad
> > expressed. I want to create a new data type, which inherits from float. I
> > just know the "dir" function and the "help" function to get more
> > infromations about the class, but i need to get more information about
> > the class structure.
>
> I'd suggest the tutorial, see http://docs.python.org, though your question
> is already beyond the range of beginners' questions.
>
> > What i also want to know:
>  variable1 = 10.50
>  type(variable1)
> >
> > 
> >
> > Is there a way to tell python that it use antoher class than float for
> > float, like myfloat? Its just a "tell-me-what-is-possible".
> >
> > Sample:
>  variable1 = 10.50
>  type(variable1)
> >
> > 
>
> The expression "10.5" will always be a float, you can't change that. What
>
> you can do is create your own type, derived from float:
>   >>> class myfloat(float):
>
>   ... pass
>   ...
>
> and then create an object of that type:
>   >>> x = myfloat(3.14)
>   >>> type(x)
>
>   
>
>
>
> Lastly one warning: In many cases where people wanted to derive from a
> concrete data type, their problems were easier solved by external code. I
> don't know your problem though.
>
> Uli
>
> --
> Sator Laser GmbH
> Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

I just want to test what is possible with python and what not. There is no 
problem that i need to solve.

This is what i'am searching for: 
http://docs.python.org/reference/datamodel.html

Last year i have stopped programming python, but now i'am back with a big 
black hole in my brain and i want to understand what the interpreter is doing 
in the background.

I think my question was not well formulated...

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


Re: unittest basics

2010-05-11 Thread Giampaolo Rodolà
There's no reason for such a thing.
You can just make "import module" in your test and if something goes
wrong that will be treated as any other test failure.

--- Giampaolo
http://code.google.com/p/pyftpdlib
http://code.google.com/p/psutil


2010/5/11 John Maclean :
> is there a way to test that a certian library or module is or can be loaded
> successfully?
>
> self.assert('import blah')
>
> --
> John Maclean
> MSc. (DIC) BSc. (Hons)
> Linux Systems and Applications
> 07739 171 531
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


how to import a module for global use in a library package ?

2010-05-11 Thread Auré Gourrier
Dear all,

I am building a library package of the form:

rootlib
---__init__
---subpackage1
--__init__
--sub1module1
--sub1module2
--...
---subpackage2
-- __init__
--sub2module1
--sub2module2
--...

My rootlib.__init__ file contains:

__name__= ...
__version__ = ...
__author__  = ...
__author_email__= ...
__url__ = ...
__description__ = ...
 
import subpackage1
import subpackage2

__all__ = []
__all__.extend(['subpackage1','subpackage2'])

My question is the following: I need to import an external package, say numpy, 
for use in various submodules. So far, I simply do an import numpy as _numpy 
where needed, say sub1module1 and sub2module2. This means that I import this 
package a number of times which doesn't seem to be a logical thing to do (?).  
In the end, I would like to make this module a "global" module for my library.

I would find it more practical to simply do this import in the __init__ of 
rootlib and then use it directly in the submodules as rootlib._numpy calls, but 
I'm not sure exactly how to do this because it would mean that I would have to 
do an import rootlib in my subpackages which doesn't sound so good...

Can anyone give me a hint ?

Cheers,

Auré


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


Re: how to import a module for global use in a library package ?

2010-05-11 Thread Jean-Michel Pichavant

Auré Gourrier wrote:

[snip]
My question is the following: I need to import an external package, 
say numpy, for use in various submodules. So far, I simply do an 
import numpy as _numpy where needed, say sub1module1 and sub2module2. 
This means that I import this package a number of times which doesn't 
seem to be a logical thing to do (?).

No problem at all.
You need numpy in a file, then import numpy at the very beginning of the 
file. You have 100 files requiring numpy? you'll end up with 100 'import 
numpy' statements, but who cares ? This is perfectly logic and pythonic 
in the way it is explicit.


You could reference numpy as member of you rootlib package, but any call 
of numpy methods will be prefixed by rootlib.numpy, and you still need a 
import rootlib (circular imports since rootlib is importing your 
submodules !)



JM


Auré




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


Re: virtualenvwrapper for Windows (Powershell)

2010-05-11 Thread Guillermo
On May 11, 7:43 am, Lawrence D'Oliveiro  wrote:
> In message
> <22cf35af-44d1-43fe-8b90-07f2c6545...@i10g2000yqh.googlegroups.com>,
>
> Guillermo wrote:
> > If you've ever missed it on Windows and you can use Powershell ...
>
> I thought the whole point of Windows was to get away from this command-line
> stuff. Not such a good idea after all?

I suppose it depends.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unittest basics

2010-05-11 Thread Chris Withers

import unittest

class MyTestCase(unittest.TestCase):

  def test_my_import(self):
import blah

cheers,

Chris

John Maclean wrote:
is there a way to test that a certian library or module is or can be 
loaded successfully?


self.assert('import blah')



--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to measure speed improvements across revisions over time?

2010-05-11 Thread exarkun

On 08:13 pm, m...@tplus1.com wrote:

I know how to use timeit and/or profile to measure the current run-time
cost of some code.

I want to record the time used by some original implementation, then
after I rewrite it, I want to find out if I made stuff faster or 
slower,

and by how much.

Other than me writing down numbers on a piece of paper on my desk, does
some tool that does this already exist?

If it doesn't exist, how should I build it?


http://github.com/tobami/codespeed sounds like the kind of thing you're 
looking for.  You can see an example of what it does at 
http://speed.pypy.org/


Jean-Paul


Matt

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

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


Re: virtualenvwrapper for Windows (Powershell)

2010-05-11 Thread David Robinow
On Tue, May 11, 2010 at 1:43 AM, Lawrence D'Oliveiro
 wrote:
> In message
> <22cf35af-44d1-43fe-8b90-07f2c6545...@i10g2000yqh.googlegroups.com>,
> Guillermo wrote:
>> If you've ever missed it on Windows and you can use Powershell ...
> I thought the whole point of Windows was to get away from this command-line
> stuff. Not such a good idea after all?
 The whole point of Windows was to make money for Microsoft. Microsoft
can be criticized for many things but a mindless devotion to principle
is not one of them.
-- 
http://mail.python.org/mailman/listinfo/python-list


reading xml from python

2010-05-11 Thread Hvidberg, Martin
I'm looking for at way to read (and later write) small simple .xml file from 
Python.

e.g. I would like to read the following from a small ini.xml file into a 
dictionary.



 default
 False
 False
 UBMlight
 True

I would prefer a relative simple (not too much creating new classes) way to do 
this.

Any suggestions appreciated.

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


Re: Picking a license

2010-05-11 Thread Lie Ryan
On 05/11/10 20:24, Paul Boddie wrote:
> On 10 Mai, 17:01, Patrick Maupin  wrote:
>>
>> I'll be charitable and assume the fact that you can make that
>> statement without apparent guile merely means that you haven't read
>> the post I was referring to:
>>
>> http://www.gnu.org/philosophy/why-not-lgpl.html
> 
> Of course I have read it, and not just recently either. But this is a
> position paper by the author of the licence, and it doesn't mean that
> someone who has written a GPL-licensed library completely agrees with
> that position. And anyway, it's a case of "take it or leave it" - it's
> not like the author or the FSF are sneaking stuff into every product
> and every corner of the market and then telling you that you can't
> "unchoose" their stuff.


Come on, 99%  of the projects released under GPL did so because they
don't want to learn much about the law; they just need to release it
under a certain license so their users have some legal certainty. Most
programmers are not lawyers and don't care about the law and don't care
about the GPL; if a commercial programmer want to use the GPL-code in an
incompatible licensed program, and he comes up asking, many would just
be happy to say yes.

Most people release their code in GPL just because it's popular, not for
the exact clauses in it. Heck, many people that releases code in GPL
might not actually have read the full license.

Only big GPL projects have the resources to waste on a lawyer. And only
very big projects have the resources to waste on enforcing the license
they uses. The rest of us just don't care.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reading xml from python

2010-05-11 Thread Chris Rebert
On Tue, May 11, 2010 at 5:54 AM, Hvidberg, Martin  wrote:
> I'm looking for at way to read (and later write) small simple .xml file from
> Python.
>
> e.g. I would like to read the following from a small ini.xml file into a
> dictionary.
>
>
> 
> 
>  default
>  False
>  False
>  UBMlight
>  True
> 
>
> I would prefer a relative simple (not too much creating new classes) way to
> do this.

from xml.etree.ElementTree import ElementTree
tree = ElementTree()
tree.parse("ini.xml")
as_dictionary = dict((child.tag, child.text) for child in tree.getchildren())

Writing is left as an exercise for another poster.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reading xml from python

2010-05-11 Thread Philip Semanchuk


On May 11, 2010, at 8:54 AM, Hvidberg, Martin wrote:

I'm looking for at way to read (and later write) small simple .xml  
file from Python.


e.g. I would like to read the following from a small ini.xml file  
into a dictionary.




default
False
False
UBMlight
True

I would prefer a relative simple (not too much creating new classes)  
way to do this.


Any suggestions appreciated.


Hej Martin,
Did you look in the standard library? ElementTree in the XML section  
of the standard library will do what you want. There are several other  
choices there if you don't like that.



bye
Philip

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


urllib.urlopen blocking?

2010-05-11 Thread Dominik Gabi
Hi,

I'm new to python and have been playing around with it for a few days
now. So please forgive me if this is a stupid question :)

I've tried writing a little application with pygtk and urllib. When a
button is clicked I create a new thread that opens an URL with urllib.
The new thread is running but as soon as I call
urllib.urlopen("https://someurl";, postdata) it blocks. It blocks until
I do something in the interface (e.g. click another button). I've
obviously missed something here. The interface should not interfere
with anything that runs in an other thread!?

Here are a few extracts from my code:

def send_message(self, widget, data=None):
  # This is called when the button is clicked ...
  threading.Thread(target=message.send).start() ...

def send(self):
  # This is executed in its own thread
  ...
  postdata = urllib.urlencode(data) # This line is the last one
executed
  resp = urllib.urlopen('https://theurl', postdata)

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


Re: lame sphinx questions [Was: lame epydoc questions]

2010-05-11 Thread Phlip
On May 11, 3:54 am, Jean-Michel Pichavant 
wrote:

> I remember trying using Sphinx for auto documented APIs, but it was not
> suitable at that time. You can include API docs generated from the code,
> but you still need to write the docs around.
> If I'm correct,  Sphinx is one of the best tool to document public APIs.
> However to build internal documentation with everything from interfaces
> to implementations, epydoc is still the best, it builds everything with
> no additional writing, just press the button.

Ah, thanks. We are all about writing '''doc strings''', then ripping
them to form documentation that we DO intend someone to READ and USE!

Now the problem with epydoc is it uses a persnickety text markup
language that...

 - throws a syntax error & reverts to  when the wind blows
 - demands all kinds of extra markup, such as @param
 - uses >3 different kinds of escapes, @, L{}, & 
 - has no developer tests to speak of

I'm all about cross-linking and transcluding, and I wanted to upgrade
epydoc to do it, so I need to make sure that all those issues are
going to be either worth our time to fix or work around, and I didn't
overlook some better system.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: urllib.urlopen blocking?

2010-05-11 Thread Antoine Pitrou
On Tue, 11 May 2010 06:22:29 -0700 (PDT)
Dominik Gabi  wrote:
> 
> I'm new to python and have been playing around with it for a few days
> now. So please forgive me if this is a stupid question :)
> 
> I've tried writing a little application with pygtk and urllib.

For the record, have you tried calling gobject.threads_init() at the
beginning of your application (just after importing all modules)?


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


Re: Extract all words that begin with x

2010-05-11 Thread Aahz
In article ,
Terry Reedy   wrote:
>On 5/10/2010 5:35 AM, James Mills wrote:
>> On Mon, May 10, 2010 at 6:50 PM, Xavier Ho  wrote:
>>> Have I missed something, or wouldn't this work just as well:
>>>
>> list_of_strings = ['2', 'awes', '3465sdg', 'dbsdf', 'asdgas']
>> [word for word in list_of_strings if word[0] == 'a']
>>> ['awes', 'asdgas']
>>
>> I would do this for completeness (just in case):
>>
>> [word for word in list_of_strings if word and word[0] == 'a']
>>
>> Just guards against empty strings which may or may not be in the list.
>
>  ... word[0:1] does the same thing. All Python programmers should learn 
>to use slicing to extract a  char from a string that might be empty.
>The method call of .startswith() will be slower, I am sure.

And if it is slower, so what?  Using startswith() makes for faster
reading of the code for me, and I'm sure I'm not the only one.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

f u cn rd ths, u cn gt a gd jb n nx prgrmmng.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lame sphinx questions [Was: lame epydoc questions]

2010-05-11 Thread Jean-Michel Pichavant

Phlip wrote:

On May 11, 3:54 am, Jean-Michel Pichavant 
wrote:

  

I remember trying using Sphinx for auto documented APIs, but it was not
suitable at that time. You can include API docs generated from the code,
but you still need to write the docs around.
If I'm correct,  Sphinx is one of the best tool to document public APIs.
However to build internal documentation with everything from interfaces
to implementations, epydoc is still the best, it builds everything with
no additional writing, just press the button.



Ah, thanks. We are all about writing '''doc strings''', then ripping
them to form documentation that we DO intend someone to READ and USE!
  
Now the problem with epydoc is it uses a persnickety text markup

language that...

 - throws a syntax error & reverts to  when the wind blows
 - demands all kinds of extra markup, such as @param
 - uses >3 different kinds of escapes, @, L{}, & 
 - has no developer tests to speak of

I'm all about cross-linking and transcluding, and I wanted to upgrade
epydoc to do it, so I need to make sure that all those issues are
going to be either worth our time to fix or work around, and I didn't
overlook some better system.
  
epydoc supports reStructured text markups. AFAIK it's still the best doc 
builder available for python code. Too bad it is not maintained since 2 
years and the 3.0 release.
If there was any effort to provide however, I think it would be on 
sphinx so it would allow building the complete doc from python code. As 
written in the doc, it's currently half-automated.


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


Re: Picking a license

2010-05-11 Thread Paul Boddie
On 11 Mai, 15:00, Lie Ryan  wrote:
>
> Come on, 99%  of the projects released under GPL did so because they
> don't want to learn much about the law; they just need to release it
> under a certain license so their users have some legal certainty.

Yes, this is frequently the case. And the GPL does offer some
certainty that various permissive licences do not.

> Most programmers are not lawyers and don't care about the law and don't care
> about the GPL; if a commercial programmer want to use the GPL-code in an
> incompatible licensed program, and he comes up asking, many would just
> be happy to say yes.

Yes, quite possibly. I did mention this myself elsewhere.

> Most people release their code in GPL just because it's popular, not for
> the exact clauses in it. Heck, many people that releases code in GPL
> might not actually have read the full license.

Yes, this is also probably the case for a number of people. Although
many probably understand the principles of the licence and feel that
it represents their wishes most accurately.

> Only big GPL projects have the resources to waste on a lawyer. And only
> very big projects have the resources to waste on enforcing the license
> they uses. The rest of us just don't care.

Well, that's always an option as well, but at the same time, there are
people willing to pursue licence violations, and these people have
done so successfully. There's no need to make an impassioned argument
for apathy, though. Some people do wish to dictate what others can do
with their work.

Or are you trying to make another point here? That people would choose
something other than the GPL if only they "knew better", perhaps?
Since the FSF goes out of its way to list lots of Free Software
licences, GPL-compatible or otherwise, and those other licences aren't
exactly secret anyway, I hardly think there's a conspiracy at work.

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


Slice last char from string without raising exception on empty string (Re: Extract all words that begin with x)

2010-05-11 Thread python
Terry,

>  ... word[0:1] does the same thing. All Python programmers should learn to 
> use slicing to extract a char from a string that might be empty.

Is there an equivalent way to slice the last char from a string (similar
to an .endswith) that doesn't raise an exception when a string is empty?

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


Re: urllib.urlopen blocking?

2010-05-11 Thread Dominik Gabi
> For the record, have you tried calling gobject.threads_init() at the
> beginning of your application (just after importing all modules)?

I haven't... now it works, thanks :) Any tips on how to avoid mistakes
like that in the future? I'm somewhat confused as to how I was
supposed to get this out of the documentation...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python a functional programming language?

2010-05-11 Thread Paul Rubin
Lawrence D'Oliveiro  writes:
> I thought the opposite of “functional” was “procedural”, not “imperative”. 
> The opposite to the latter is “declarative”. But (nearly) all procedural 
> languages also have declarative constructs, not just imperative ones 
> (certainly Python does). Presumably an “imperative” language would not.

Offhand I can't tell that imperative and procedural mean something
different.  Both basically mean that the programmer specifies a series
of steps for the computer to carry out.  Functional languages are mostly
declarative; for example, an expression like
   x = 3
is called an "equation" rather than an "assignment".  It declares "x is
equal to 3", rather than directing x to be set to 3.  If someplace else
in the program you say "x = 4", that is an error, normally caught by
the compiler, since x cannot be equal to both 3 and 4.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unable to get Hudson to run unit tests

2010-05-11 Thread j vickroy

Thanks again, Stefan.  My comments are below.

Stefan Behnel wrote:

j vickroy, 10.05.2010 17:39:

Unfortunately, when "Hudson Build now" is performed, the Hudson Console
output, for this job, is:


Started by user anonymous
Updating svn://vm-svn/GOES data 
processing/trunk/GOES/13,14,15/SXI/level-1

At revision 3403
no change for svn://vm-svn/GOES data
processing/trunk/GOES/13,14,15/SXI/level-1 since the previous build
[workspace] $ python.exe
C:\DOCUME~1\JIM~1.VIC\LOCALS~1\Temp\hudson5273111667332806239.sh
os.getcwd(): C:\Documents and Settings\jim.vickroy\.hudson\jobs\GOES
13-15 SXI Level-1 Products Generation\workspace
os.listdir(os.getcwd()): ['level-1']
[workspace] $ cmd.exe -xe
C:\DOCUME~1\JIM~1.VIC\LOCALS~1\Temp\hudson991194264891924641.sh
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\jim.vickroy\.hudson\jobs\GOES 13-15 SXI
Level-1 Products Generation\workspace>Recording test results
No test report files were found. Configuration error?
Finished: FAILURE


The second [workspace] section output (above) looks like cmd.exe is
being executed with no parameters (i.e., without the
"nosetests.exe --where=level-1 --with-xunit --verbose") parameter.


No, what Hudson actually does, is, it writes your command(s) into a text 
file and runs it with the system's shell interpreter (which, unless 
otherwise configured, is "cmd.exe" on Windows). 


This is not the behavior I am experiencing on my Windows XP Pro (Service 
Pack 3) workstation.


If I do not specify "C:\WINDOWS\system32\cmd.exe" for "Manage Hudson | 
Configuration System | Shell | Shell executable", the "Console output" 
after a "Build now" is:


-
Started by user anonymous
Updating svn://vm-svn/GOES data processing/trunk/GOES/13,14,15/SXI/level-1
At revision 3417
no change for svn://vm-svn/GOES data 
processing/trunk/GOES/13,14,15/SXI/level-1 since the previous build
[workspace] $ sh -xe 
C:\DOCUME~1\JIM~1.VIC\LOCALS~1\Temp\hudson869574722591302824.sh

The system cannot find the file specified
FATAL: command execution failed
java.io.IOException: Cannot run program "sh" (in directory "C:\Documents 
and Settings\jim.vickroy\.hudson\jobs\GOES 13-15 SXI Level-1 Products 
Generation\workspace"): CreateProcess error=2, The system cannot find 
the file specified

at java.lang.ProcessBuilder.start(Unknown Source)
at hudson.Proc$LocalProc.(Proc.java:149)
at hudson.Proc$LocalProc.(Proc.java:121)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:636)
at hudson.Launcher$ProcStarter.start(Launcher.java:271)
at hudson.Launcher$ProcStarter.join(Launcher.java:278)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:83)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:58)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)
	at 
hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:584)

at hudson.model.Build$RunnerImpl.build(Build.java:174)
at hudson.model.Build$RunnerImpl.doRun(Build.java:138)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:416)
at hudson.model.Run.run(Run.java:1244)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:122)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot 
find the file specified

at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 17 more
Recording test results
Finished: FAILURE
-

Note Hudson is looking for "sh".

This assures the highest
possible compatibility with the executed script. You can even use the 
shebang in Hudson's scripts that way, so that you can execute scripts in 
basically any scripting language.


The likely reason why it doesn't find your test results is that you 
didn't tell it where to look. 


Actually, Hudson is not finding the tests results because they are not 
being generated.  There is no "nosetests.xml" file anywhere on my hard 
drive (except in the Recycle Bin from my explicit executions of the 
"nosetests.exe --where=level-1 --with-xunit --verbose" command).  This 
is why I thought Hudson was not executing the above nosetests.exe 
command (specified in "*job* | Configure | Build | Execute shell | command".



Put a wildcard path into the unit test
config box that finds the XML files that nosetest writes. It's also best 
to tell nosetest where to put them explicitly using a command line option.


Stefan



Thanks again for your continued interest. 

Re: Is Python a functional programming language?

2010-05-11 Thread Michele Simionato
On May 10, 8:18 pm, a...@pythoncraft.com (Aahz) wrote:
> saying that functional features
> are "tacked on" understates the case.  Consider how frequently people
> reach for list comps and gen exps.  Function dispatch through dicts is
> the standard replacement for a switch statement.  Lambda callbacks are
> common.  Etc, etc, etc

Just to play devil's advocate, I will notice that list comps and gen
exps are not really
functional (a generator has a state that changes at each call of
next). A functional language
would use streams instead. Function dispatch through dicts is very
lame compared to pattern matching. Lambdas are restricted. There is no
tail call optimization. Definitively Python functional features are
"tacked on" with respect to a language defined to be functional.
Having said that, the functional features are still usable and one can
use a functional style
in Python if she wants to (module a few caveats).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: urllib.urlopen blocking?

2010-05-11 Thread Antoine Pitrou
On Tue, 11 May 2010 07:35:52 -0700 (PDT)
Dominik Gabi  wrote:

> > For the record, have you tried calling gobject.threads_init() at the
> > beginning of your application (just after importing all modules)?
> 
> I haven't... now it works, thanks :) Any tips on how to avoid mistakes
> like that in the future? I'm somewhat confused as to how I was
> supposed to get this out of the documentation...

I'm afraid I don't know the answer. I'm not a pygtk expert at all, I
just remember that I had to do that in one of my applications long ago,
otherwise pygtk doesn't support Python threads properly.

Regards

Antoine.


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


Re: Extract all words that begin with x

2010-05-11 Thread superpollo

Aahz ha scritto:

In article ,
Terry Reedy   wrote:

On 5/10/2010 5:35 AM, James Mills wrote:

On Mon, May 10, 2010 at 6:50 PM, Xavier Ho  wrote:

Have I missed something, or wouldn't this work just as well:


list_of_strings = ['2', 'awes', '3465sdg', 'dbsdf', 'asdgas']
[word for word in list_of_strings if word[0] == 'a']

['awes', 'asdgas']

I would do this for completeness (just in case):


[word for word in list_of_strings if word and word[0] == 'a']

Just guards against empty strings which may or may not be in the list.
 ... word[0:1] does the same thing. All Python programmers should learn 
to use slicing to extract a  char from a string that might be empty.

The method call of .startswith() will be slower, I am sure.


And if it is slower, so what?  Using startswith() makes for faster
reading of the code for me, and I'm sure I'm not the only one.


also, what if the OP intended "words that begin with x" with x a string 
(as opposed to a single character) ?


then startswith is the solution methinks...

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


Re: unable to get Hudson to run unit tests

2010-05-11 Thread Stefan Behnel

j vickroy, 11.05.2010 16:46:
> Stefan Behnel wrote:

No, what Hudson actually does, is, it writes your command(s) into a
text file and runs it with the system's shell interpreter (which,
unless otherwise configured, is "cmd.exe" on Windows).


This is not the behavior I am experiencing on my Windows XP Pro (Service
Pack 3) workstation.


Then setting the "Shell executable" to "cmd.exe" will do the right thing here.



This assures the highest
possible compatibility with the executed script. You can even use the
shebang in Hudson's scripts that way, so that you can execute scripts
in basically any scripting language.


... although the shebang isn't really supported by cmd.exe, I guess ...



The likely reason why it doesn't find your test results is that you
didn't tell it where to look.


Actually, Hudson is not finding the tests results because they are not
being generated. There is no "nosetests.xml" file anywhere on my hard
drive


That's why I told you to configure nosetest to use an specific output path 
for the unit test file.




Thanks again for your continued interest. I quickly got Hudson to
retrieve job source from our subversion repository so I thought it would
be equally easy to get Hudson to run the unit tests, but that has proven
to be difficult, and so far I do not know how to diagnose this since it
seems there is no way to prevent Hudson from immediately deleting the
temporary scripts it generates.


Which is ok, since it prints what it does during the script execution, and 
the scripts contain nothing more than what you typed in.


Does nosetest produce an XML file when you call it manually from the 
command line? Is nosetest.exe in your PATH, so that the cmd.exe that Hudson 
starts can find it?


Personally, I'd always step into the target directory before running a 
command, so I'd make the script


cd level-1
nosetest.exe ...

Stefan

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


Iterating over dict and removing some elements

2010-05-11 Thread Ulrich Eckhardt
Hi!

I wrote a simple loop like this:

  d = {}
  ...
  for k in d:
  if some_condition(d[k]):
  d.pop(k)

If I run this, Python complains that the dictionary size changed during
iteration. I understand that the iterator relies on the internal structure
not changing, but how would I structure this loop otherwise?

My first approach was to simply postpone removing the elements, but I was
wondering if there was a more elegant solution.

Thanks!

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: Slice last char from string without raising exception on empty string (Re: Extract all words that begin with x)

2010-05-11 Thread superpollo

pyt...@bdurham.com ha scritto:

Terry,


 ... word[0:1] does the same thing. All Python programmers should learn to use 
slicing to extract a char from a string that might be empty.


Is there an equivalent way to slice the last char from a string (similar
to an .endswith) that doesn't raise an exception when a string is empty?



could it be:

word[len(word)-1:] ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Iterating over dict and removing some elements

2010-05-11 Thread superpollo

Ulrich Eckhardt ha scritto:

Hi!

I wrote a simple loop like this:

  d = {}
  ...
  for k in d:
  if some_condition(d[k]):
  d.pop(k)

If I run this, Python complains that the dictionary size changed during
iteration. I understand that the iterator relies on the internal structure
not changing, but how would I structure this loop otherwise?


my first thought (untested):

use a copy of d for the if clause, then pop from the original.

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


PyMPI comm.gather problem

2010-05-11 Thread Peyman Askari
Hi

I have run into a serious problem with PyMPI (Python bindings for the Message 
Passing Interface). Unfortunately I can not provide any example code as it is a 
massive program (38,000+ lines) and it is very difficult to break the program 
down due to multiple inheritance.

When I run the program (on multiple nodes), there is a linear increase in time 
per iteration. Every 1,500 iterations, it gains a tenth of a second per 
iteration. I timed different regions of my code which were engaged in messaging 
(broadcasting and gathering) and I found the increase to be in a gather 
statement, much like so

IO_list=self.comm.gather(IO,root=0)

each iteration this single command requires more and more time to pass 
information. I checked the size of IO being sent from every node (including 
root node) and it always remains constant. I also checked the size of the 
IO_list, and it too is always constant. Furthermore, I added a sleep(5) command 
before the line to make sure it was not a synchronization issue. 

Has anyone got any possible ideas as to what could possibly be going wrong? 

Cheers


Peyman Askari



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


Re: Iterating over dict and removing some elements

2010-05-11 Thread Michele Simionato
Or you copy the whole dictionary or you just copy the keys:

for k in d.keys():
...

or

for k in list(d):
...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Iterating over dict and removing some elements

2010-05-11 Thread Jerry Hill
On Tue, May 11, 2010 at 11:08 AM, Ulrich Eckhardt
 wrote:
> My first approach was to simply postpone removing the elements, but I was
> wondering if there was a more elegant solution.

Iterate over something other than the actual dictionary, like this:

d = {1: 'one', 2: 'two', 3: 'three'}

for k in d.keys():
if d[k] == 'two':
d.pop(k)


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


Re: unable to get Hudson to run unit tests

2010-05-11 Thread j vickroy

Stefan Behnel wrote:

j vickroy, 11.05.2010 16:46:
 > Stefan Behnel wrote:

No, what Hudson actually does, is, it writes your command(s) into a
text file and runs it with the system's shell interpreter (which,
unless otherwise configured, is "cmd.exe" on Windows).


This is not the behavior I am experiencing on my Windows XP Pro (Service
Pack 3) workstation.


Then setting the "Shell executable" to "cmd.exe" will do the right thing 
here.




This assures the highest
possible compatibility with the executed script. You can even use the
shebang in Hudson's scripts that way, so that you can execute scripts
in basically any scripting language.


... although the shebang isn't really supported by cmd.exe, I guess ...



The likely reason why it doesn't find your test results is that you
didn't tell it where to look.


Actually, Hudson is not finding the tests results because they are not
being generated. There is no "nosetests.xml" file anywhere on my hard
drive


That's why I told you to configure nosetest to use an specific output 
path for the unit test file.


OK, I will do this and report back.





Thanks again for your continued interest. I quickly got Hudson to
retrieve job source from our subversion repository so I thought it would
be equally easy to get Hudson to run the unit tests, but that has proven
to be difficult, and so far I do not know how to diagnose this since it
seems there is no way to prevent Hudson from immediately deleting the
temporary scripts it generates.


Which is ok, since it prints what it does during the script execution, 
and the scripts contain nothing more than what you typed in.


Yes, and I am not seeing the nosetests.exe command listed anywhere in 
the Hudson console output.  This is why I do not think Hudson is 
executing it.




Does nosetest produce an XML file when you call it manually from the 
command line? 


Yes it does.  The exact same command (specified for the Hudson job) 
works perfectly from a Windows console.


Is nosetest.exe in your PATH, so that the cmd.exe that

Hudson starts can find it?


Yes, it is.  "C:\Python26\Scripts" is in PATH and that is where 
"nosetests.exe" is.


Personally, I'd always step into the target directory before running a 
command, so I'd make the script


cd level-1
nosetest.exe ...


OK, I will try this.



Stefan


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


Re: Iterating over dict and removing some elements

2010-05-11 Thread superpollo

superpollo ha scritto:

Ulrich Eckhardt ha scritto:

Hi!

I wrote a simple loop like this:

  d = {}
  ...
  for k in d:
  if some_condition(d[k]):
  d.pop(k)

If I run this, Python complains that the dictionary size changed during
iteration. I understand that the iterator relies on the internal 
structure

not changing, but how would I structure this loop otherwise?


my first thought (untested):

use a copy of d for the if clause, then pop from the original.

bye


i mean:

>>> d = {"name":"max","surname":"zanardi","nick":"zanna"}
>>> dc = copy.copy(d)
>>> dc
{'nick': 'zanna', 'surname': 'zanardi', 'name': 'max'}
>>> for k in dc:
... if dc[k].startswith("z"):
... d.pop(k)
...
'zanna'
'zanardi'
>>> d
{'name': 'max'}
>>> dc
{'nick': 'zanna', 'surname': 'zanardi', 'name': 'max'}
>>>

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


Re: Slice last char from string without raising exception on empty string (Re: Extract all words that begin with x)

2010-05-11 Thread Jerry Hill
On Tue, May 11, 2010 at 10:37 AM,   wrote:
> Is there an equivalent way to slice the last char from a string (similar
> to an .endswith) that doesn't raise an exception when a string is empty?

If you use negative indexes in the slice, they refer to items from the
end of the sequence instead of the front.  So slicing the last
character from the string would be:

word[-1:]

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


Re: unable to get Hudson to run unit tests

2010-05-11 Thread j vickroy

Stefan Behnel wrote:

j vickroy, 11.05.2010 16:46:
 > Stefan Behnel wrote:

No, what Hudson actually does, is, it writes your command(s) into a
text file and runs it with the system's shell interpreter (which,
unless otherwise configured, is "cmd.exe" on Windows).


This is not the behavior I am experiencing on my Windows XP Pro (Service
Pack 3) workstation.


Then setting the "Shell executable" to "cmd.exe" will do the right thing 
here.




This assures the highest
possible compatibility with the executed script. You can even use the
shebang in Hudson's scripts that way, so that you can execute scripts
in basically any scripting language.


... although the shebang isn't really supported by cmd.exe, I guess ...



The likely reason why it doesn't find your test results is that you
didn't tell it where to look.


Actually, Hudson is not finding the tests results because they are not
being generated. There is no "nosetests.xml" file anywhere on my hard
drive


That's why I told you to configure nosetest to use an specific output 
path for the unit test file.




Thanks again for your continued interest. I quickly got Hudson to
retrieve job source from our subversion repository so I thought it would
be equally easy to get Hudson to run the unit tests, but that has proven
to be difficult, and so far I do not know how to diagnose this since it
seems there is no way to prevent Hudson from immediately deleting the
temporary scripts it generates.


Which is ok, since it prints what it does during the script execution, 
and the scripts contain nothing more than what you typed in.


Does nosetest produce an XML file when you call it manually from the 
command line? Is nosetest.exe in your PATH, so that the cmd.exe that 
Hudson starts can find it?


Personally, I'd always step into the target directory before running a 
command, so I'd make the script


cd level-1
nosetest.exe ...

Stefan



Here are the Hudson job | Configure | Execute shell | Command inputs:

--
cd level-1
dir
nosetests.exe --with-xunit --xunit-file=nosetests.xml --verbose
--
#!python.exe
print 'FOOO'
import os ; print 'os.getcwd():',os.getcwd(); print 
'os.listdir(os.getcwd()):',os.listdir(os.getcwd())

--


and here is the Hudson Console Output:

--
Started by user anonymous
Updating svn://vm-svn/GOES data processing/trunk/GOES/13,14,15/SXI/level-1
At revision 3417
no change for svn://vm-svn/GOES data 
processing/trunk/GOES/13,14,15/SXI/level-1 since the previous build
[workspace] $ C:\WINDOWS\system32\cmd.exe -xe 
C:\DOCUME~1\JIM~1.VIC\LOCALS~1\Temp\hudson2208088016039194869.sh

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

C:\Documents and Settings\jim.vickroy\.hudson\jobs\GOES 13-15 SXI 
Level-1 Products Generation\workspace>[workspace] $ python.exe 
C:\DOCUME~1\JIM~1.VIC\LOCALS~1\Temp\hudson6398132145818001258.sh
os.getcwd(): C:\Documents and Settings\jim.vickroy\.hudson\jobs\GOES 
13-15 SXI Level-1 Products Generation\workspace

os.listdir(os.getcwd()): ['level-1']
Recording test results
No test report files were found. Configuration error?
Finished: FAILURE
--


There is no nosetests.xml file anywhere on my hard drive (except as 
previously noted in the Recycle Bin).


From the above Console Output, I see no evidence that the nosetests.exe 
command was ever executed.

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


Re: Slice last char from string without raising exception on empty string (Re: Extract all words that begin with x)

2010-05-11 Thread python
Superpollo,

> word[len(word)-1:] 

Perfect! Thank you,

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


Re: Slice last char from string without raising exception on empty string (Re: Extract all words that begin with x)

2010-05-11 Thread python
Jerry,

> If you use negative indexes in the slice, they refer to items from the end of 
> the sequence instead of the front. So slicing the last character from the 
> string would be:
> 
> word[-1:]

Perfect! Thank you,

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


plot debugging problem

2010-05-11 Thread Sandy Sandy

Hi friends

pls help with debugging problem

the mutter is:

during debugging the  debug processes stacks when fig is created

for example, in code



import random



import matplotlib.pyplot as plt

from pylab import *





x= 23;

y = 11;

print(23456)

plt.plot(range(10))



plot([1,2,3])

show()



print()



a=888



it is impossible after show() to continue debug

as stated in

Beginning Python Visualization - Crafting Visual Transformation Scripts 
(2009)

page  187



Note If you’re not using matplotlib interactively in Python, be sure

to call the function show() after all

graphs have been generated, as it enters a user interface main loop

that will stop execution of the rest of

your code. The reason behind this behavior is that matplotlib is

designed to be embedded in a GUI as well.

In Windows, if you’re working from interactive Python, you need only

issue show() once; close the figures

(or figures) to return to the shell. Subsequent plots will be drawn

automatically without issuing show(), and

you’ll be able to plot graphs interactively.



Best Regards

Sandy 
_
Hotmail: Free, trusted and rich email service.
https://signup.live.com/signup.aspx?id=60969-- 
http://mail.python.org/mailman/listinfo/python-list


graphs in Python during debugging

2010-05-11 Thread Sandy Sandy



Hi friends

Can you help pls  to find how to plot graphs in Python
during debugging without destroying figures to continue to debug

the mutter is:

during debugging the  debug processes stacks when fig is created

for example, in code

import random

import matplotlib.pyplot as plt

from pylab import *

x= 23;

y = 11;

print(23456)

plt.plot(range(10))

plot([1,2,3])

show()

print()

a=888



it is impossible after show() to continue debug

as stated in

Beginning Python Visualization - Crafting Visual Transformation Scripts (2009)

page  187



Note If you’re not using matplotlib interactively in Python, be sure

to call the function show() after all

graphs have been generated, as it enters a user interface main loop

that will stop execution of the rest of

your code. The reason behind this behavior is that matplotlib is

designed to be embedded in a GUI as well.

In Windows, if you’re working from interactive Python, you need only

issue show() once; close the figures

(or figures) to return to the shell. Subsequent plots will be drawn

automatically without issuing show(), and

you’ll be able to plot graphs interactively.



Best Regards

Sandy

  
_
Your E-mail and More On-the-Go. Get Windows Live Hotmail Free.
https://signup.live.com/signup.aspx?id=60969-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Slice last char from string without raising exception on empty string (Re: Extract all words that begin with x)

2010-05-11 Thread James Mills
On Wed, May 12, 2010 at 2:01 AM,   wrote:
>> word[len(word)-1:]

This works just as well:

>>> word[-1:]

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


Re: Slice last char from string without raising exception on empty string (Re: Extract all words that begin with x)

2010-05-11 Thread superpollo

James Mills ha scritto:

On Wed, May 12, 2010 at 2:01 AM,   wrote:

word[len(word)-1:]


This works just as well:


word[-1:]


d'uh. ;-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: unable to get Hudson to run unit tests

2010-05-11 Thread Stefan Behnel

j vickroy, 11.05.2010 17:42:

Here are the Hudson job | Configure | Execute shell | Command inputs:

--
cd level-1
dir
nosetests.exe --with-xunit --xunit-file=nosetests.xml --verbose
--
#!python.exe
print 'FOOO'
import os ; print 'os.getcwd():',os.getcwd(); print
'os.listdir(os.getcwd()):',os.listdir(os.getcwd())
--


and here is the Hudson Console Output:

--

Started by user anonymous
Updating svn://vm-svn/GOES data processing/trunk/GOES/13,14,15/SXI/level-1
At revision 3417
no change for svn://vm-svn/GOES data
processing/trunk/GOES/13,14,15/SXI/level-1 since the previous build
[workspace] $ C:\WINDOWS\system32\cmd.exe -xe
C:\DOCUME~1\JIM~1.VIC\LOCALS~1\Temp\hudson2208088016039194869.sh
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\jim.vickroy\.hudson\jobs\GOES 13-15 SXI
Level-1 Products Generation\workspace>[workspace] $ python.exe


This is telling. It doesn't properly execute the cmd.exe shell. Maybe you 
have to configure the shell setup somehow to make it accept MS's cmd.exe? 
Note that cmd.exe isn't really what I'd call a "shell", so you may have to 
put some work into getting it to run your scripts.


You can also try to add a shebang "#!cmd.exe" to the script, it seems like 
Hudson interprets that by itself. Or execute nosetest from a Python script, 
just check what the nosetest main script is doing and do the same in a 
Python script.


Disclaimer: I never used Hudson on MS Windows, and I'm happy I don't have to.

Stefan

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


Re: Problem displaying jpgs in Tkinter via PIL

2010-05-11 Thread Armin
Never mind, I gave up on Tkinter and have switched to wxPython now. 
Getting jpg images to display in a wx frame worked like a charm... (As 
I said, I'm very new to Python, so I didn't really know what my options 
for GUI programming were.)


It seems like the ImageTk module on the Enthought distribution on my 
Mac is broken, but I can't figure out how to fix that. (I wiped my 
python installations and did a re-install, all to no avail.) As long as 
I don't need Tkinter for the GUI I'm envisioning, I don't really care 
however.




On 2010-05-10 14:01:10 -0700, Armin said:

I'm new to Python and have been playing around with it using the 
Enthought Python distribution for Mac OS X 10.6.3 (EPD academic 
license, version 6.1 with python 2.6.4).


It's been great learning the basics, but I've started running into 
problems when I'm trying to use the PIL library with Tkinter. All I'm 
trying to do is display a JPG as a Tkinter label:


It all works fine when I'm just using GIF images through Tkinter's 
photoimage object, but as soon as I'm trying to convert an image 
through ImageTk, I get the following error:


ImportError: 
dlopen(/Library/Frameworks/Python.framework/Versions/6.1/lib/python2.6/site-packages/PIL/_imagingtk.so, 
2): Library not loaded: /sys...@rpath/Tcl Referenced from: 
/Library/Frameworks/Python.framework/Versions/6.1/lib/python2.6/site-packages/PIL/_imagingtk.so 
Reason: image not found


I have no idea what that means, but I've always assumed the EPD 
includes all the stuff that's needed to make Tkinter work with PIL.

Any advice would be greatly appreciated. Thanks!



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


Re: Problem displaying jpgs in Tkinter via PIL

2010-05-11 Thread Antoine Pitrou
On Tue, 11 May 2010 09:57:01 -0700
Armin  wrote:
> Never mind, I gave up on Tkinter and have switched to wxPython now. 
> Getting jpg images to display in a wx frame worked like a charm... (As 
> I said, I'm very new to Python, so I didn't really know what my options 
> for GUI programming were.)

You might also want to try PyQT, which is often considered more modern
than wxPython (I've never tried it, though).

Regards

Antoine.


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


Re: lame sphinx questions [Was: lame epydoc questions]

2010-05-11 Thread Phlip
> epydoc supports reStructured text markups.

Oh, good. For a moment there, I thought I'd be stuck with a markup
language that was persnickety!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: plot debugging problem

2010-05-11 Thread Matteo Landi
I imagine you have to create a separate thread for it. Just thoughts.

On Tue, May 11, 2010 at 6:08 PM, Sandy Sandy  wrote:
> Hi friends
> pls help with debugging problem
> the mutter is:
> during debugging the  debug processes stacks when fig is created
> for example, in code
>
> import random
>
> import matplotlib.pyplot as plt
> from pylab import *
>
>
> x= 23;
> y = 11;
> print(23456)
> plt.plot(range(10))
>
> plot([1,2,3])
> show()
>
> print()
>
> a=888
>
> it is impossible after show() to continue debug
> as stated in
> Beginning Python Visualization - Crafting Visual Transformation Scripts
> (2009)
> page  187
>
> Note If you’re not using matplotlib interactively in Python, be sure
> to call the function show() after all
> graphs have been generated, as it enters a user interface main loop
> that will stop execution of the rest of
> your code. The reason behind this behavior is that matplotlib is
> designed to be embedded in a GUI as well.
> In Windows, if you’re working from interactive Python, you need only
> issue show() once; close the figures
> (or figures) to return to the shell. Subsequent plots will be drawn
> automatically without issuing show(), and
> you’ll be able to plot graphs interactively.
>
> Best Regards
> Sandy
> 
> Hotmail: Free, trusted and rich email service. Get it now.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>



-- 
Matteo Landi
http://www.matteolandi.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python a functional programming language?

2010-05-11 Thread Terry Reedy

On 5/11/2010 7:11 AM, Lawrence D'Oliveiro wrote:

In message<7xvdavd4bq@ruckus.brouhaha.com>, Paul Rubin wrote:


Python is a pragmatic language from an imperative tradition ...


I thought the opposite of “functional” was “procedural”, not “imperative”.
The opposite to the latter is “declarative”. But (nearly) all procedural
languages also have declarative constructs, not just imperative ones
(certainly Python does).


Python has only two: 'global' and now 'nonlocal'.
There are also two meta-declarations: the coding cookie (which 
would/will go away in an entirely unicode world) and future imports 
(which are effectively temporarily gone in 3.x until needed again).


Newbies sometimes trip over def and class being imperative (executable) 
statments rather than declarations.


Terry Jan Reedy



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


Re: inherit from data type

2010-05-11 Thread Terry Reedy

On 5/11/2010 7:51 AM, Richard Lamboj wrote:


I just want to test what is possible with python and what not. There is no
problem that i need to solve.

This is what i'am searching for:
http://docs.python.org/reference/datamodel.html

Last year i have stopped programming python, but now i'am back with a big
black hole in my brain and i want to understand what the interpreter is doing
in the background.


I suggest you (re)read and try examples in the Tutorial. It covers the 
basic syntax pretty well.


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


documentation bug? (format spec mini language)

2010-05-11 Thread Alan G Isaac

The documentation at 
http://docs.python.org/py3k/library/string.html#format-specification-mini-language

'<' Forces the field to be left-aligned within the available space 
(This is the default.)

The conflicting example::

>>> format(3.2,'10.5f')
'   3.2'
>>> format(3.2,'<10.5f')
'3.2   '

Am I somehow misreading the documentation?

Thanks,
Alan Isaac


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


Re: plot debugging problem

2010-05-11 Thread Matteo Landi
Well, I cannot tell you how to do that in a precise way, but googling
a bit I found this (expecially the second example):

http://eli.thegreenplace.net/2008/08/01/matplotlib-with-wxpython-guis/

Take a look also at the Matplotlib cookbook:

http://www.scipy.org/Cookbook/Matplotlib

ps. when you answer back, remember to include the list, or the flow will be cut!

On Tue, May 11, 2010 at 7:49 PM, Sandy Sandy  wrote:
> great!!!
> how to do it?
>
> this way it is not working:
>
> from pylab import plot,show,close
> x = range(10)
> plot(x)
> from threading import Timer
> t = Timer(0, show)
> t.start()
>
> y = [2, 8, 3, 9, 4]
> plot(y)
> close()
>
> Best Regards
> Sandy
>
>
>
>
>
>
>
>
>
>
>
>
>
>> From: landima...@gmail.com
>> Date: Tue, 11 May 2010 19:46:27 +0200
>> Subject: Re: plot debugging problem
>> To: c...@live.com
>> CC: python-list@python.org
>>
>> I imagine you have to create a separate thread for it. Just thoughts.
>>
>> On Tue, May 11, 2010 at 6:08 PM, Sandy Sandy  wrote:
>> > Hi friends
>> > pls help with debugging problem
>> > the mutter is:
>> > during debugging the  debug processes stacks when fig is created
>> > for example, in code
>> >
>> > import random
>> >
>> > import matplotlib.pyplot as plt
>> > from pylab import *
>> >
>> >
>> > x= 23;
>> > y = 11;
>> > print(23456)
>> > plt.plot(range(10))
>> >
>> > plot([1,2,3])
>> > show()
>> >
>> > print()
>> >
>> > a=888
>> >
>> > it is impossible after show() to continue debug
>> > as stated in
>> > Beginning Python Visualization - Crafting Visual Transformation Scripts
>> > (2009)
>> > page  187
>> >
>> > Note If you’re not using matplotlib interactively in Python, be sure
>> > to call the function show() after all
>> > graphs have been generated, as it enters a user interface main loop
>> > that will stop execution of the rest of
>> > your code. The reason behind this behavior is that matplotlib is
>> > designed to be embedded in a GUI as well.
>> > In Windows, if you’re working from interactive Python, you need only
>> > issue show() once; close the figures
>> > (or figures) to return to the shell. Subsequent plots will be drawn
>> > automatically without issuing show(), and
>> > you’ll be able to plot graphs interactively.
>> >
>> > Best Regards
>> > Sandy
>> > 
>> > Hotmail: Free, trusted and rich email service. Get it now.
>> > --
>> > http://mail.python.org/mailman/listinfo/python-list
>> >
>> >
>>
>>
>>
>> --
>> Matteo Landi
>> http://www.matteolandi.net/
>
> 
> Hotmail: Powerful Free email with security by Microsoft. Get it now.



-- 
Matteo Landi
http://www.matteolandi.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to make this doctest work?

2010-05-11 Thread Terry Reedy

On 5/11/2010 5:29 AM, Xie&Tian wrote:

Hello

I ran across this accidentally and wonders how to make the doctest in
following code snippet work:


import doctest

def a():
  """
 >>>  a = '\\r\\n'
 >>>  print a


 No matter how many blank lines I add here, it just can't get enough -_-
 """
 pass

doctest.testmod()



ps: I want variable "a" to be '\r\n', but python kept telling me
 ValueError: line 4 of the docstring has inconsistent leading
whitespace: "'"
 Why can't doctest module deal with statement "a='\r\n'"?


You should post (copy and paste) entire error messages.
The problem is with the print statement, not the assignment.
I would prefix the docstring with r instead doubling \s within it.
The point of doctest is to imitate what one would get with the 
interactive interpreter. However, literally entering what you have 
within the doc string does (3.1)


>>> a = '\\r\\n'
>>> print(a)
\r\n
>>>

Terry Jan Reedy



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


Pythonw.exe randomly crashing

2010-05-11 Thread Dean Weimer
Hi, I have a python application I wrote that is randomly crashing, I was
wondering if anyone else has ran into this error, or if anyone has any
idea about how to fix it.  This is currently running under Windows
server 2008 R2 x64 in terminal services, with Python 2.6.4 x64
installed.  I ran into this problem with previous versions of Python on
windows 2003 server running under 32 bit.  I have been unable to
duplicate the error under a devolvement platform.  The application is a
simple GUI used for time clock stations on a shop floor; it has a
multithreaded GUI which displays some rotating informational images.  A
Text box that displays a constantly updating clock, and a text box that
accepts employee clock number input and one that displays results
returned from a background thread that runs a telnet session to a
server.  I can't really tell you where the error is occurring within the
actual code, as it takes days of the application running to happen.

Does anyone have any suggestions as to how I can get it to give me more
information about the crash?

 

Log Name:  Application

Source:Application Error

Date:  5/6/2010 3:33:40 PM

Event ID:  1000

Task Category: (100)

Level: Error

Keywords:  Classic

User:  N/A

Description:

Faulting application name: pythonw.exe, version: 0.0.0.0, time stamp:
0x4ba3b0d9

Faulting module name: tcl85.dll, version: 8.5.2.2, time stamp:
0x48515e43

Exception code: 0xc005

Fault offset: 0x0005863d

Faulting process id: 0xa98

Faulting application start time: 0x01cae87cff98c7c4

Faulting application path: C:\Python26\pythonw.exe

Faulting module path: C:\Python26\DLLs\tcl85.dll

Report Id: a7a18c68-594e-11df-b65f-005056b55389

 

 

Thanks,

 Dean Weimer

 Network Administrator

 Orscheln Management Co

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


default argument

2010-05-11 Thread Back9
Hi,

Is this grammer working in Python?

class test:
  self._value = 10
  def func(self, self._value)

When i try it, it complains about undefined self.

i don't know why.

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


Re: default argument

2010-05-11 Thread Back9
On May 11, 3:06 pm, Back9  wrote:
> Hi,
>
> Is this grammer working in Python?
>
> class test:
>   self._value = 10
>   def func(self, self._value)
>
> When i try it, it complains about undefined self.
>
> i don't know why.
>
> TIA

Sorry
here is the what i meant
class test:
  self._value = 10
  def func(self, pos = self._value)

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


Re: documentation bug? (format spec mini language)

2010-05-11 Thread MRAB

Alan G Isaac wrote:
The documentation at 
http://docs.python.org/py3k/library/string.html#format-specification-mini-language 



'<' Forces the field to be left-aligned within the available 
space (This is the default.)


The conflicting example::

>>> format(3.2,'10.5f')
'   3.2'
>>> format(3.2,'<10.5f')
'3.2   '

Am I somehow misreading the documentation?


It does look misleading. Numbers default to right-aligned, as you
discovered.

You usually want numbers to be right-aligned so that the decimal points
line up when writing a columns of them.
--
http://mail.python.org/mailman/listinfo/python-list


Re: default argument

2010-05-11 Thread Chris Rebert
On Tue, May 11, 2010 at 12:08 PM, Back9  wrote:
> On May 11, 3:06 pm, Back9  wrote:

>> When i try it, it complains about undefined self.
>>
>> i don't know why.
>>
>> TIA
>
> Sorry
> here is the what i meant
> class test:
>  self._value = 10
>  def func(self, pos = self._value)

You're still defining the class, so how could there possibly be an
instance of it to refer to as "self" yet (outside of a method body)?
Also, just so you know, default argument values are only evaluated
once, at the time the function/method is defined, so `pos =
self._value` is never going to work.

Do you mean for self._value to be a class variable (Java lingo: static
variable), or an instance variable?

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python a functional programming language?

2010-05-11 Thread Chris Rebert
On Tue, May 11, 2010 at 11:13 AM, Terry Reedy  wrote:
> On 5/11/2010 7:11 AM, Lawrence D'Oliveiro wrote:
>> In message<7xvdavd4bq@ruckus.brouhaha.com>, Paul Rubin wrote:
>>
>>> Python is a pragmatic language from an imperative tradition ...
>>
>> I thought the opposite of “functional” was “procedural”, not “imperative”.
>> The opposite to the latter is “declarative”. But (nearly) all procedural
>> languages also have declarative constructs, not just imperative ones
>> (certainly Python does).
>
> Python has only two: 'global' and now 'nonlocal'.
> There are also two meta-declarations: the coding cookie (which would/will go
> away in an entirely unicode world) and future imports (which are effectively
> temporarily gone in 3.x until needed again).
>
> Newbies sometimes trip over def and class being imperative (executable)
> statments rather than declarations.

Er, declarative programming has nothing to do with variable declarations.
http://en.wikipedia.org/wiki/Declarative_programming

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to import a module for global use in a library package ?

2010-05-11 Thread Terry Reedy

On 5/11/2010 8:04 AM, Auré Gourrier wrote:

Dear all,

I am building a library package of the form:

rootlib
---__init__
---subpackage1
--__init__
--sub1module1
--sub1module2
--...
---subpackage2
-- __init__
--sub2module1
--sub2module2
--...

My rootlib.__init__ file contains:

__name__= ...
__version__ = ...
__author__  = ...
__author_email__= ...
__url__ = ...
__description__ = ...

import subpackage1
import subpackage2

__all__ = []
__all__.extend(['subpackage1','subpackage2'])

My question is the following: I need to import an external package,

say numpy, for use in various submodules. So far, I simply do an import
numpy as _numpy where needed, say sub1module1 and sub2module2. This
means that I import this package a number of times which doesn't seem to
be a logical thing to do (?). In the end, I would like to make this
module a "global" module for my library.

I have a similar package structure and after writing a few submodules, I 
developed a template that includes common text, including a couple of 
imports that are usually needed. I also made a backup copy of the 
template in case I open the template and forget to 'save as 
' before just 'save'ing ;-).


If I had several such imports, and thought the list might expand, I 
might make one submodule for imports and then do 'from rootlib.util 
import importmod as m' in the template. But I have no need now for such.


Terry Jan Reedy


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


Re: default argument

2010-05-11 Thread Back9
On May 11, 3:20 pm, Chris Rebert  wrote:
> On Tue, May 11, 2010 at 12:08 PM, Back9  wrote:
> > On May 11, 3:06 pm, Back9  wrote:
> 
> >> When i try it, it complains about undefined self.
>
> >> i don't know why.
>
> >> TIA
>
> > Sorry
> > here is the what i meant
> > class test:
> >  self._value = 10
> >  def func(self, pos = self._value)
>
> You're still defining the class, so how could there possibly be an
> instance of it to refer to as "self" yet (outside of a method body)?
> Also, just so you know, default argument values are only evaluated
> once, at the time the function/method is defined, so `pos =
> self._value` is never going to work.
>
> Do you mean for self._value to be a class variable (Java lingo: static
> variable), or an instance variable?
>
> Cheers,
> Chris
> --http://blog.rebertia.com

self._value will be instance variable
-- 
http://mail.python.org/mailman/listinfo/python-list


First Timer

2010-05-11 Thread Donna Lane
I have downloaded Python and I'm a beginner in every sense.  What I want to
know now is when I am in Idle and have made a syntax error how do I repair?
After the error I can't type in

anything and I get this bing noise.  Usually I just start idle over again.

Thanks to anyone out there who responds.

 

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


Re: Iterating over dict and removing some elements

2010-05-11 Thread Terry Reedy

On 5/11/2010 11:29 AM, Jerry Hill wrote:

On Tue, May 11, 2010 at 11:08 AM, Ulrich Eckhardt
  wrote:

My first approach was to simply postpone removing the elements, but I was
wondering if there was a more elegant solution.


Iterate over something other than the actual dictionary, like this:

d = {1: 'one', 2: 'two', 3: 'three'}

for k in d.keys():
 if d[k] == 'two':
 d.pop(k)


This, as written, does not work in 3.1, where d.keys is a view of the 
dict. Nor does


for k in filter(lambda k: d[k] == 'two', d):
d.pop(k)

But these do

for k in list(filter(lambda k: d[k] == 'two', d)):
d.pop(k)

for k in [k for k in d if d[k] == 'two']:
d.pop(k)

Rather than make an external list of *all* keys, one only needs to make 
a list of keys to be removed, which often  will be much smaller.


Terry Jan Reedy

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


Re: inherit from data type

2010-05-11 Thread Richard Lamboj

Am Tuesday 11 May 2010 20:16:50 schrieb Terry Reedy:
> On 5/11/2010 7:51 AM, Richard Lamboj wrote:
> > I just want to test what is possible with python and what not. There is
> > no problem that i need to solve.
> >
> > This is what i'am searching for:
> > http://docs.python.org/reference/datamodel.html
> >
> > Last year i have stopped programming python, but now i'am back with a big
> > black hole in my brain and i want to understand what the interpreter is
> > doing in the background.
>
> I suggest you (re)read and try examples in the Tutorial. It covers the
> basic syntax pretty well.

There are many programming languages, so i have forgotten that python data 
types are objects and not a "wrapper". So its a little bit confusing 
that "self" returns the value of the datatype and not something 
like "self.value". But who cares about logical mistakes in my brain.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: fast regex

2010-05-11 Thread Nobody
On Tue, 11 May 2010 17:48:41 +1200, Lawrence D'Oliveiro wrote:

>> I was working with regex on a very large text, really large but I have
>> time constrained.
> 
> “Fast regex” is a contradiction in terms.

Not at all. A properly-written regexp engine will be limited only by
memory bandwidth, provided that the state table fits into the primary
cache.

> You use regexes when you
> want ease of definition and application, not speed.

Other way around.

> For speed, consider hand-coding your own state machine. Preferably in a
> compiled language like C.

Or use a decent regexp library.

Even if you want to use non-regular expressions (e.g. backreferences), a
decent engine will still use a DFA, bactracking only where strictly
necessary.

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


Limitation of os.walk

2010-05-11 Thread kj



I want implement a function that walks through a directory tree
and performs an analsysis of all the subdirectories found.  The
task has two essential requirements that, AFAICT, make it impossible
to use os.walk for this:

1. I need to be able to prune certain directories from being visited.

2. The analysis on each directory can be performed only after it
   has been performed on all its subdirectories.

Unless I'm missing something, to do (1), os.walk must be run with
topdown=True, whereas to do (2) it must be run with topdown=False.

Is there a work around that I'm missing?

TIA!

~K

PS: I never understood why os.walk does not support hooks for key
events during such a tree traversal.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: default argument

2010-05-11 Thread Chris Rebert
On Tue, May 11, 2010 at 12:41 PM, Back9  wrote:
> On May 11, 3:20 pm, Chris Rebert  wrote:
>> On Tue, May 11, 2010 at 12:08 PM, Back9  wrote:
>> > On May 11, 3:06 pm, Back9  wrote:
>> 
>> >> When i try it, it complains about undefined self.
>>
>> >> i don't know why.
>>
>> >> TIA
>>
>> > Sorry
>> > here is the what i meant
>> > class test:
>> >  self._value = 10
>> >  def func(self, pos = self._value)
>>
>> You're still defining the class, so how could there possibly be an
>> instance of it to refer to as "self" yet (outside of a method body)?
>> Also, just so you know, default argument values are only evaluated
>> once, at the time the function/method is defined, so `pos =
>> self._value` is never going to work.
>>
>> Do you mean for self._value to be a class variable (Java lingo: static
>> variable), or an instance variable?
>
> self._value will be instance variable

class Test(object):
def __init__(self):
self._value = 10
def func(self, pos=None):
if pos is None:
pos = self._value
#do whatever

Using None like this is the idiomatic way to have non-constant or
mutable default argument values in Python.

I recommend you read the part of the Python tutorial on
object-oriented programming:
http://docs.python.org/tutorial/classes.html

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: default argument

2010-05-11 Thread j vickroy

Back9 wrote:

Hi,

Is this grammer working in Python?

class test:
  self._value = 10
  def func(self, self._value)

When i try it, it complains about undefined self.

i don't know why.

TIA


... not exactly; try:

class Test:
   _value = 10
   def func(self):
  print id(self._value), self._value
  print id(Test._value), Test._value

t = Test()
t.func()
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python a functional programming language?

2010-05-11 Thread Terry Reedy

On 5/11/2010 3:25 PM, Chris Rebert wrote:

On Tue, May 11, 2010 at 11:13 AM, Terry Reedy  wrote:

On 5/11/2010 7:11 AM, Lawrence D'Oliveiro wrote:

In message<7xvdavd4bq@ruckus.brouhaha.com>, Paul Rubin wrote:


Python is a pragmatic language from an imperative tradition ...


I thought the opposite of “functional” was “procedural”, not “imperative”.
The opposite to the latter is “declarative”. But (nearly) all procedural
languages also have declarative constructs, not just imperative ones
(certainly Python does).


Python has only two: 'global' and now 'nonlocal'.
There are also two meta-declarations: the coding cookie (which would/will go
away in an entirely unicode world) and future imports (which are effectively
temporarily gone in 3.x until needed again).

Newbies sometimes trip over def and class being imperative (executable)
statments rather than declarations.


Er, declarative programming has nothing to do with variable declarations.
http://en.wikipedia.org/wiki/Declarative_programming


I found it hard to get much from the vague description. I will leave it 
to Lawrence to list what *he* thinks are 'declarative constructs' in Python.



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


Re: First Timer

2010-05-11 Thread Chris Rebert
On Tue, May 11, 2010 at 12:28 PM, Donna Lane  wrote:
> I have downloaded Python and I'm a beginner in every sense.  What I want to
> know now is when I am in Idle and have made a syntax error how do I repair?
> After the error I can't type in
>
> anything and I get this bing noise.  Usually I just start idle over again.

You re-type or copy-paste and then fix the line(s) after the new >>>
prompt that appears after the SyntaxError message. You can't edit
lines you've already run.

Also, you can compose an entire file of code and then run the file,
rather than working directly at the interactive interpreter (aka
shell). File->New Window makes an empty file you can work in; pressing
F5 in the file editor window will run the file.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python a functional programming language?

2010-05-11 Thread Nobody
On Tue, 11 May 2010 07:36:30 -0700, Paul Rubin wrote:

> Offhand I can't tell that imperative and procedural mean something
> different.  Both basically mean that the programmer specifies a series of
> steps for the computer to carry out.  Functional languages are mostly
> declarative; for example, an expression like
>x = 3
> is called an "equation" rather than an "assignment".  It declares "x is
> equal to 3", rather than directing x to be set to 3.  If someplace else in
> the program you say "x = 4", that is an error, normally caught by the
> compiler, since x cannot be equal to both 3 and 4.

In both ML and Haskell, bindings are explicitly scoped, i.e.

let x = 3 in ... end(ML)
let x = 3 in ...(Haskell)

If you bind a variable which is already bound, it introduces a new binding
which "overrides" the existing binding. It won't generate an error.

The key point is that a variable has a fixed (constant) value at any
specific point in the program. The value depends upon which bindings are
in scope at that point, and not on the "state" of the variable at a
particular point in time.

E.g. (Haskell):

test y = let x = 3
 in let f y = x + y
in let x = 5
   in f y
test 5
8

x has the value 3 at the point that f is defined, so that's the value
which is used when f is used.

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


Re: Is Python a functional programming language?

2010-05-11 Thread Lie Ryan
On 05/12/10 05:25, Chris Rebert wrote:
> On Tue, May 11, 2010 at 11:13 AM, Terry Reedy  wrote:
>> On 5/11/2010 7:11 AM, Lawrence D'Oliveiro wrote:
>>> In message<7xvdavd4bq@ruckus.brouhaha.com>, Paul Rubin wrote:
>>>
 Python is a pragmatic language from an imperative tradition ...
>>>
>>> I thought the opposite of “functional” was “procedural”, not “imperative”.
>>> The opposite to the latter is “declarative”. But (nearly) all procedural
>>> languages also have declarative constructs, not just imperative ones
>>> (certainly Python does).
>>
>> Python has only two: 'global' and now 'nonlocal'.
>> There are also two meta-declarations: the coding cookie (which would/will go
>> away in an entirely unicode world) and future imports (which are effectively
>> temporarily gone in 3.x until needed again).
>>
>> Newbies sometimes trip over def and class being imperative (executable)
>> statments rather than declarations.
> 
> Er, declarative programming has nothing to do with variable declarations.
> http://en.wikipedia.org/wiki/Declarative_programming
> 

Variable declarations have everything to do with declarative programming.

An imperative way to create a variable is to allocate the memory
yourself and instead of "variables" you have just registers and the
memory; fortunately all popular imperative languages (wisely) picks up
declarative syntax from the declarative paradigm. In Python, the regular
def/class is a pseudo-declaration, but it is also possible to
*imperatively/procedurally* create a class by calling type() and a
function by passing a __call__() to type()'s __dict__ argument.

A fully declarative language just turn everything into declarations
including the "business logic" of the application (and of course,
variable declaration).
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >