Re: any() and all() on empty list?

2006-03-30 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> Think of it this way: if all(seq) is true, shouldn't it be the case
> that you can point to a specific element in seq that is true?

No, all(seq) is true if you can't point to a specific element in seq
that's false.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GUI in python

2006-03-30 Thread peter . mosley
See this thread

http://groups.google.co.uk/group/comp.lang.python/browse_thread/thread/989b957f244d48e0/429378d911ba4357?hl=en#429378d911ba4357


Peter

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


Re: ldap usage

2006-03-30 Thread Michael Ströder
Jed Parsons wrote:
> 
> As an addendum, I discovered one little gotcha, namely that this:
> 
> l.bind_s(username, password, ldap.AUTH_SIMPLE)
> 
> throws an ldap.INVALID_CREDENTIALS error if the password contains the
> wrong text, but works if the password is empty.  I guess this is
> tantamount to binding as ("", ""), but I wasn't expecting it; I figured
> if a username was specified, the password would have to agree.

Yes, this is by design. Empty cred means just switching to anon
bind. LDAP was not intended to be used for password checking at that time.

Which LDAP server are you using? You can switch off this behaviour with
OpenLDAP. See man 5 slapd.conf, allow .

>  So my
> little authentication example also needs to test for empty passwords.

Yes!

Ciao, Michael.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Free Python IDE ?

2006-03-30 Thread bruno at modulix
Ernesto wrote:
> I'm looking for a tool that I can use to "step through" python software
> (debugging environment).  

This is not an 'IDE', it's a debugger.

> Is there a good FREE one 

http://www.python.org/doc/2.4.2/lib/module-pdb.html

Strange enough, I almost never had a use for a debugger in 5+ years of
Python programming.

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating COM server Events?

2006-03-30 Thread Roger Upole
You'll need to implement the IConnectionPoint and
IConnectionPointContainer interfaces with your server.
See \win32com\demos\connect.py and
\win32com\server\connect.py for some sample code.

   Roger

"Dan" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
>I have need to create a com server that will fire events back to
> clients. I have looked at some of the documentation and I am new to
> Python so cant quite get it. I have created an IDL file of the
> interfaces. Can someone tell me approximately what needs to be done
> here. I have seen examples of implementing the regular interfaces but
> don't know what to do about the events interfaces.The vid...Events
> interface is the main question here. In regular com development you
> would implement something along the lines of Fire_OnNewData(). My Com
> developement has mostly been with Borland tools and they do quite a bit
> for you, As I hope Python will. Heres the IDL:
>
> [
>  uuid(B0ADD4E1-1793-4089-8298-20B5A2DB0E82),
>  version(1.0),
>  helpstring("vidVisPython Library")
>
> ]
> library vidVisPython
> {
>
>  importlib("stdole2.tlb");
>
>  [
>uuid(E26E3023-4F65-4E3D-A900-56C6302CD4E0),
>version(1.0),
>dual,
>oleautomation
>  ]
>   interface IVideoVisitationPython: IDispatch
>  {
>[
>id(0x0001)
>]
>HRESULT _stdcall AdviseNewData( void );
>  };
>
>  [
>uuid(50A02634-215F-47C6-9749-CDD02DC99B13),
>version(1.0)
>  ]
>   dispinterface IVideoVisitationPythonEvents
>  {
>properties:
>methods:
>[
>id(0x0001)
>]
>HRESULT OnNewData( void );
>  };
>
>  [
>uuid(134821F5-35B9-4917-B6EE-EF5C508BE949),
>version(1.0)
>  ]
>  coclass CoVideoVisitationPython
>  {
>[default] interface IVideoVisitationPython;
>[default, source] dispinterface IVideoVisitationPythonEvents;
>  };
>
> };
> 




== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet 
News==
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 
Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter question

2006-03-30 Thread Eric Brunel
(Please quote a part of the message you're replying to; I had problems  
figuring out you were replying to my post...)

On 29 Mar 2006 14:08:02 -0800, <[EMAIL PROTECTED]> wrote:
> Ultimately what I am trying to is create a public computer session
> manager.
>
> 1) User logs in and main application window is withdrawn (easy)
> 2) After (for example) 55 minutes - a warning window/dialoguebox
> "session will end in 5 minutes"
> 3) With 30 seconds to go  - a warning window/dialoguebox "session will
> end in 30 seconds"
> 4) User logged out (easy)
>
> I am having problems with steps 2 and 3
> Either the window/dialoguebox  will
> (a) pause the program execution upon display waiting for user input
> or (b) both warnings display together when application has finished.
>
> What I want want is a window/dialogue box that will not halt
> application logic, and will display immediately.

But what does it do between steps 1 and 2? Is Python/Tkinter still in  
control, or are you running some external program, or something else?

As for the dialogue box pausing the program execution waiting for user  
input, you're probably using the "built-in" show* or ask* functions from  
the tkMessageBox module that are designed to be modal. If you just create  
a Toplevel and populate it with widgets, it will just display once the  
control is returned to the Tkinter mainloop and no user input will be  
needed. But the control *has* to return to the mainloop, or the window  
won't show up. One acceptable workaround may be to call the "update"  
method on the Toplevel, but it may depend on what you do between steps 1 &  
2.

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: does python could support sequence of short or int?

2006-03-30 Thread Diez B. Roggisch
momobear schrieb:
> hi, is there a way to let python operate on sequence of int or short?
> In C, we just need declare a point, then I could get the point value,
> just like:
> short* k = buffer, //k is a point to a sequence point of short.
> short i = *k++,
> but python is a dynamic language,
> a = buffer
> i = ? I don't know how to continue, what's a? a seems to be a str?

You should read the python tutorial, especially the parts about list, 
tuples and dicts.

http://docs.python.org/tut/

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


Re: Free Python IDE ?

2006-03-30 Thread Joel Hedlund
Ernesto wrote:
> I'm looking for a tool that I can use to "step through" python software
> (debugging environment).  Is there a good FREE one (or one which is
> excellent and moderately priced ) ?
> 

Try searching this newsgroup for "python ide", "editor" and such and you'll get 
plenty of good advice. This topic is discussed about once every week or so.

Cheers!
/joel
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: win32com: error 80004005

2006-03-30 Thread Roger Upole
The only thing I see wrong is that the Hello method
doesn't take any arguments, but the VB code is passing one.
It works fine for me if I remove the arg.
When registered with --debug, you should still be able
to see the output in Pythonwin's trace collector window
even when the object is instantiated via VB.

  hth
   Roger

"ago" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
>I am trying to make the win32com HelloWorld server work with a VBA
> client but I get:
>
> Run-time error '-2147467259(80004005)':
> Automation error
> Unspecified error
>
> I googled for the error but the suggested solutions (commenting out
> _reg_class_spec_ and putting the server on the python path) do not seem
> to make any difference (to be precise, unless I comment out
> _reg_class_spec_ I cannot register the server at all) . The server
> works under the python client but not on excel vba. I also tried to
> debug with win32traceutil.py but I can only see the trace when using
> the python client, not with excel. Any hint would be appreciated.
>
> ### PYTHON SERVER ###
> class HelloClass:
> _reg_desc_ = "Python Test COM Server"
> _reg_clsid_ = "{91281AFC-25DF-4400-8868-FDBFCA2612A2}"
> _reg_progid_ = "Python.HelloHello"
> _public_methods_ = ['Hello']
>
> def __init__(self): pass
> def Hello(self): return "Hello"
>
> if __name__ == "__main__":
> import win32com.server.register
> import sys
> #sys.argv.append("--debug")
> win32com.server.register.UseCommandLine(HelloClass)
>
> ### PYTHON CLIENT (WORKS) ###
> import win32com.client
> obj = win32com.client.Dispatch('Python.HelloHello')
> print obj.Hello()
>
> ### VBA CLIENT (ERROR 80004005 WHEN EXECUTING "CreateObject") ###
> Public Sub test()
>Dim obj As Object
>Set obj = CreateObject("Python.HelloHello")
>MsgBox obj.Hello("ago")
> End Sub
> 




== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet 
News==
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 
Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GUI in python

2006-03-30 Thread Eric Brunel
On 29 Mar 2006 14:20:03 -0800, <[EMAIL PROTECTED]> wrote:

> Hi,
>
> I am a python newbie and have used it for about a month. I want to make
> a simple GUI app in Python ( I take input form user and do processing
> and show results).
>
> Which gui package is good for me. I need to do it quick and I would not
> want a long learning curve.
>
> I was taking look at wxPython, pyGTK etc.
>
>
> Please suggest me the most simplest and easiest one as I dont need
> super cool aesthetics just a plain simple GUI app.

This site will allow you to decide for yourself based on the important  
criteria for you:
http://www.awaretek.com/toolkits.html

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GUI in python

2006-03-30 Thread Nicolay A. Vasiliev
Hello!

I think this library is enough old, isn't it? Version 0.72 was released 
on 2004-06-20.

Nicolay

[EMAIL PROTECTED] wrote:
> For quick, no learning curve, simple:
>
> http://www.ferg.org/easygui/
>
>   

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


Re: Try Python!

2006-03-30 Thread bruno at modulix
Michael Tobis wrote:
> We had some discussion of this in the edu-sig meeting at PyCon.
> 
> I alleged that I had read that there is no such thing as a Python
> sandbox. 

And yet Zope 2 has some restricted environment for TTW scripts...

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-03-30 Thread Michael Paoli
mp wrote:
> i have a python program which attempts to call 'cls' but fails:
> sh: line 1: cls: command not found
> i'm using os x.

[Note Followup-to: severely trimmed]

I'd guestimate (those more familiar with python can probably fill in
more relevant python specific details) that the python program is
probably doing something like:
system("cls")
... or whatever the python-specific way of writing something like that
is.  Most likely that was written, intended for some Microsoft
DOS/Windows/XP or similar type of operating system - where CLS is a
legitimate command (to clear the screen).  On UNIX (and probably also
OS X), there is no "cls" as a standard command, but there is the quite
standard command "clear", to clear the "terminal" screen.

In the land of UNIX, most languages implement the system() function or
equivalent, by typically fork(2)ing and exec(3)ing (at least one of the
exec(3) family of calls), generally invoking "the" or a default shell
(typically /bin/sh) with a first option argument of "-c", and then the
argument to system passed as one single string as the other argument to
the shell.  It would seem likely that python was "smart enough" (of
course) to know on UNIX to implement system() as sh -c ..., rather than
something like COMMAND /C ... or CMD /C ... as it would likely do on
DOS/Windows/XP or similar.  But "of course" python probably has no clue
what the cls is that's handed to it with system(), and likely just
blindly passes it on to the shell.  The diagnostic you got would also
seem to imply that's what happened (the shell (sh) couldn't find the
cls command). ... as a matter of fact, if I try that on Debian
GNU/Linux 3.1 (technically not "UNIX", but neither is OS X, but for
practical purposes they're both quite sufficiently close), I get
results that would appear exceedingly consistent with the hypothesis I
put forth:
$ sh -c cls
sh: line 1: cls: command not found

If it's desired to have the python program function as close to its
(apparent) original intent as feasible, it may be desirable to:
have it test the operating system, and if it is UNIX or similar, use
clear, instead of cls ... or if one wants to port/adapt it to UNIX
(and OS X, etc.), with no need or intention to move it back and forth
or among significantly different operating systems, then perhaps
consider simply replacing the system(cls) with system(clear), or
whatever the precise suitable change in the python code would be.
It would probably also be worth inspecting the code for other
occurrences of system() that may also need to be adjusted or changed.

Note also that some languages (e.g. Perl) will potentially take
shortcuts with the system() function.  For example, with Perl
(paraphrasing and perhaps over-simplifying a bit) if Perl sees no
need or reason to have to use the overhead of the shell to invoke the
system() function, it will just quite directly (after the fork(2))
exec(3) the command, setting the argument(s) suitably.  Python may
(or may not) try similar shortcuts.  For example, CLS, on DOS, etc.,
is internal to the "shell" (command interpreter), so, if python
didn't find an external CLS command, it would have to pass it to the
"shell", hoping the shell would know what to do with it.  That would
happen to work with DOS, but would generally fail on UNIX (where cls
would generally not exist as a command, and wouldn't be built-in to
the shell).

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


How to run python program on the embeded system?

2006-03-30 Thread boyeestudio
How to run python program on the embeded system?
My mobile phone support J2ME,CLDC-1.1,midp-2.0  and I want to let it run python program,but I have no idea how to.
Maybe I need write a python compiler which can run on my phone,But it is a complex work.
Please help and tell me What can I do,Thanks a lot
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: any() and all() on empty list?

2006-03-30 Thread Steven D'Aprano
Paul Rubin wrote:

> Steven D'Aprano <[EMAIL PROTECTED]> writes:
> 
>>Think of it this way: if all(seq) is true, shouldn't it be the case
>>that you can point to a specific element in seq that is true?
> 
> 
> No, all(seq) is true if you can't point to a specific element in seq
> that's false.

No, all(seq) is true if every element in seq is true. 
Surely that's a more intuitive definition than your 
definition by what you can't do.

The question that needs to be answered is, what if 
there are no elements at all? That's an arbitrary 
decision. Like the question "what is 0**0?" in 
mathematics, some answers are more useful than others. 
I can respect that practical answer -- but it isn't the 
*only* answer.

(For those who don't see why 0**0 is problematic, 0**x 
is equal to 0 for all x, and x**0 is equal to 1 for all 
  x, so what do you do for 0**0?)

Here's another way of looking at the problem:

all(flying elephants which are pink) => true
all(flying elephants which are not pink) => true

So, these flying elephants -- are they pink or not?



-- 
Steven.

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


Re: any() and all() on empty list?

2006-03-30 Thread Steven D'Aprano
Duncan Booth wrote:

> Ron Adam wrote:
> 
> 
>>Where we are assembling widgets in a manufacturing plant. Where we don't 
>>want to go to the next step until *all* the sub parts are present.
>>
>>if all(part.status == 'present' for part in unit):
>> do_release()
>>
>>Oops!  Some empty bins showed up at the next assembly station. ;-)
> 
> 
> I don't see the problem. You only get an empty bin if there is some part 
> assembled from no sub-parts, in which case you wanted an empty bin.

Okay, Ron's example wasn't the best. How about this 
one, from chess:

The intention is to play cautiously if all threatened 
pieces are valuable, and daringly otherwise. Here is 
the obvious, but wrong, code:

if all(piece.value() > 5 for piece in \
 threatened_pieces):
 play_cautiously()
else:
 play_daringly()

It is wrong because it leads to incorrect behaviour 
when there are no threatened pieces at all -- the 
intention is to play daringly by default, except for 
the specific case of there being threatened pieces, all 
of which are high value pieces.

So one correct, but more verbose, way to code this 
would be:

valuable_danger = [piece.value() > 5 for piece in \
 threatened_pieces]
if valuable_danger and all(valuable_danger):
 play_cautiously()
else:
 play_daringly()


Another obvious way of coding this would be to reverse 
the sign of the test like so:

if not any(piece.value() <= 5 for piece in \
 threatened_pieces):
 play_cautiously()
else:
 play_daringly()

In other words, play daringly unless no threatened 
piece is low value. Unfortunately, while this is 
obvious, it also gives the wrong behaviour when there 
are no threatened pieces.



The lesson of this example is that while the standard 
behaviour of any() and all(), as implemented in Python, 
are often, usually, the Right Way to do things, they do 
fail on some occasions, and coders should be aware of 
cases where the assumptions break down.


-- 
Steven.

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


Re: List conversion

2006-03-30 Thread bruno at modulix
yawgmoth7 wrote:
> Hello, I have a piece of code:
> 
>command = raw_input("command> ")
>words = string.split(command, ' ')
>temparg = words
>if len(words)<= 3:
>temparg = words[4:]
>else:
>temparg = words[5:]
>funcarg = string.upper(temparg)
>str(funcarg)
>continue
> 
> There's a little snippet of code from my script, it all looks fine,

Well, I'm sorry to have to say this, but it doesn't look fine at all:

>>> words = "one two three".split()
>>> words
['one', 'two', 'three']
>>> len(words)
3
>>> words[4:]
[]
>>> import string
>>> string.upper(words[4:])
Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib64/python2.4/string.py", line 235, in upper
return s.upper()
AttributeError: 'list' object has no attribute 'upper'
>>> str(words[4:])
'[]'
>>> words[4:]
[]
>>>

Python comes with an interactive interpreter that makes testing and
exploring a breeze. Why not using it to see how things works and avoid
obvious errors ?-)

> well, then I have a function that looks something like:
> 
> def nick(funcarg):
>sock.send(funcarg\r\n)

Either it's not your real code or you should have another error:

>>> def send(aString):
... print "sending %s" % aString
...
>>> send(words[4:]\r\n)
  File "", line 1
send(words[4:]\r\n)
  ^
SyntaxError: invalid token
>>>


> Well, that's okay, but i get this error when I try to run that command
> at the commmand prompt like enviroment I wrote:
> 
> TypeError: send() argument 1 must be string or read-only buffer, not list
> 
> Well, that is why I put in the str(funcarg) line, hoping that it would
> convert it to a string,

This is called "programming by accident", and it's the worst thing to
do. Don't "hope", try and make sure:

>>> str(words)
"['one', 'two', 'three']"
>>> words
['one', 'two', 'three']
>>>

As you can see, str() :
- returns a *representation* of it's arg as a string - but this
representation may not be what your looking for
- does *not* modify it's argument.

What you want here is to join the parts of the list:

>>> " ".join(words)
'one two three'


> instead of being a list, does anyone have any
> suggestions, 

Yes :
1/ there are at least two good tutorials, the one in the official
documentation and Dive Into Python (diveintopython.org IIRC).

2/ don't guess, don't hope, *test* (hint : use the interactive interpreter).

3/ (optional) don't hold it against me if all this sounds a bit harsh.

thanks, bye.
> --


needs a whitespace after the two dashes. It's '-- ', not '--'.


HTH
-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: any() and all() on empty list?

2006-03-30 Thread Carl Banks

Steven D'Aprano wrote:
> Paul Rubin wrote:
>
> > Steven D'Aprano <[EMAIL PROTECTED]> writes:
> >
> >>Think of it this way: if all(seq) is true, shouldn't it be the case
> >>that you can point to a specific element in seq that is true?
> >
> >
> > No, all(seq) is true if you can't point to a specific element in seq
> > that's false.
>
> No, all(seq) is true if every element in seq is true.
> Surely that's a more intuitive definition than your
> definition by what you can't do.
>
> The question that needs to be answered is, what if
> there are no elements at all?

Then every element in seq is true.

(And false. :)


Carl Banks

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


Re: any() and all() on empty list?

2006-03-30 Thread Peter Otten
Steven D'Aprano wrote:

> Okay, Ron's example wasn't the best. How about this
> one, from chess:
> 
> The intention is to play cautiously if all threatened
> pieces are valuable, and daringly otherwise.

Isn't that example even worse? Compare:

- You have one of your valuable pieces threatened. You decide to play
cautiously. 

- You have one valuable and one piece of lesser value threatened. You play
daringly.

What is that? The courage of despair?

if any(piece.value > 5 for piece in threatened):
# play cautiously
else:
# play daringly

looks more convincing to the non-chessplaying bystander (read: me) and --
surprise -- is supported by the new builtins just fine.

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


Re: dynamic construction of variables / function names

2006-03-30 Thread bruno at modulix
Steven D'Aprano wrote:
> Sakcee wrote:
> 
>> python provides a great way of dynamically creating fuctions calls and
>> class names from string
>>
(snip)

> Personally, I think the best way is: find another way to solve your
> problem.
> 

See Duncan's post for a pretty clean and pythonic solution. Another one
that may be more explicit and avoid messing with locals() or globals() is:

>> is it correct way, is there a simple way, is this techniqe has a name?
> 
> 
> I'm told that some people call this "dynamic programming",

In some other languages, it could be called 'metaprogramming', but this
is such a common idiom in Python that I'd just call this "programming" !-)

> but
> personally I call it "difficult to maintain, difficult to debug
> programming".

Oh yes ? Why so ? I've used such patterns hundreds of time, and it has
never been a problem so far.

Dynamically selecting the function to call given a name (as string) is
is a well-known programming pattern. I learned this in C, using a
hashtable to store names/function pointer pairs. And that's mostly what
the proposed solutions (the one based on globals() or locals() as well
as Duncan's class-based one) do - the main difference being that Python
offers the hashtable for free !-)

nb : I agree that the use of the global or local namespaces may not be
the best thing to do - better to use (any variant of) Duncan's solution
IMHO.

> (Before people get all cranky at me, I'm aware that it isn't *always*
> the Wrong Way to solve problems,  but it is a technique which is subject
> to abuse and can often be avoided by using function objects instead of
> function names.)

When you get the function name as user input, you cannot directly access
the function object.

And anyway, what do you think Python do when you call a function ?
Python namespaces *are* hash tables mapping symbols names (as string) to
objects (as pointers). I don't see much difference here.

(nb 2 : I agree that it is of course better to avoid 'manual' namespace
lookup whenever possible)



-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: any() and all() on empty list?

2006-03-30 Thread Georg Brandl
Steven D'Aprano wrote:
> Paul Rubin wrote:
> 
>> Steven D'Aprano <[EMAIL PROTECTED]> writes:
>> 
>>>Think of it this way: if all(seq) is true, shouldn't it be the case
>>>that you can point to a specific element in seq that is true?
>> 
>> 
>> No, all(seq) is true if you can't point to a specific element in seq
>> that's false.
> 
> No, all(seq) is true if every element in seq is true. 
> Surely that's a more intuitive definition than your 
> definition by what you can't do.
> 
> The question that needs to be answered is, what if 
> there are no elements at all? That's an arbitrary 
> decision. Like the question "what is 0**0?" in 
> mathematics, some answers are more useful than others. 
> I can respect that practical answer -- but it isn't the 
> *only* answer.
> 
> (For those who don't see why 0**0 is problematic, 0**x 
> is equal to 0 for all x, and x**0 is equal to 1 for all 
>   x, so what do you do for 0**0?)
> 
> Here's another way of looking at the problem:
> 
> all(flying elephants which are pink) => true
> all(flying elephants which are not pink) => true
> 
> So, these flying elephants -- are they pink or not?

No, you ask two different sets whether they are true.

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


Re: does python could support sequence of short or int?

2006-03-30 Thread bruno at modulix
momobear wrote:
> hi, is there a way to let python operate on sequence of int or short?
> In C, we just need declare a point, 

I assume you mean a 'pointer'.

> then I could get the point value,
> just like:
> short* k = buffer, //k is a point to a sequence point of short.
> short i = *k++,
> but python is a dynamic language,
> a = buffer
> i = ? I don't know how to continue, what's a? a seems to be a str?
> 


You'd probably get better answers by exposing the problem you're trying
to solve instead of what you think is the solution


Anyway, if you want a list if integers, just put integers into a list
and iterate over that list:

buffer = [1, 2, 3, 42]
for i in buffer:
  do_something_with(i)


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


regular expressions and matches

2006-03-30 Thread Johhny
Hello,

I have recently written a small function that will verify that an IP
address is valid.

==SNIP==

import re
ipAddress = raw_input('IP Address : ')

def validateIP(ipAddress):
ipRegex =
r"^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$"
re_ip = re.compile(ipRegex)
match = re_ip.match(ipAddress)
if not match:
print "an error has occured with ipAddress"
return match
else:
return match

print(validateIP(ipAddress))

==SNIP==

I was having issues trying to get my code working so that I could pass
the IP addresses and it would return a true or false. When it matches I
get something that looks like this.

python ip_valid.py
IP Address : 192.158.1.1
<_sre.SRE_Match object at 0xb7de8c80>

As I am still attempting to learn python I am interested to know how I
could get the above to return a true or false if it matches or does not
match the IP address. I would also like to expand that so that if the
IP is wrong it requests the IP address again and recalls the function.
I have done the same thing in php very easily but python appears to be
getting the better of me. Any assistance and advice would be greatly
appreciated.

Regards,

Johhny

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


Re: regular expressions and matches

2006-03-30 Thread Fredrik Lundh
"Johhny" wrote:

> I was having issues trying to get my code working so that I could pass
> the IP addresses and it would return a true or false. When it matches I
> get something that looks like this.
>
> python ip_valid.py
> IP Address : 192.158.1.1
> <_sre.SRE_Match object at 0xb7de8c80>
>
> As I am still attempting to learn python I am interested to know how I
> could get the above to return a true or false if it matches or does not
> match the IP address.

you can use the return value right away.  the match function/method
returns None if it fails to find a match, and None is treated as a false
value in a "boolean context":

http://docs.python.org/ref/Booleans.html

if you get a match instead, you get a match object (SRE_Match),
which is treated as True.

if you really really really want to return True or False, you can do

result = bool(re.match(...))





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


Re: regular expressions and matches

2006-03-30 Thread bruno at modulix
Johhny wrote:
> Hello,
> 
> I have recently written a small function that will verify that an IP
> address is valid. 

(snip re.match() based solution - just one remark: compiling the regexp
on each function call is more than useless)

> I was having issues trying to get my code working so that I could pass
> the IP addresses and it would return a true or false. When it matches I
> get something that looks like this.
> 
> python ip_valid.py
> IP Address : 192.158.1.1
> <_sre.SRE_Match object at 0xb7de8c80>
> 
> As I am still attempting to learn python I am interested to know how I
> could get the above to return a true or false if it matches or does not
> match the IP address.

If you re-read the fine manual, you'll notice that re.match() returns
either None or a Match object. Since, in a boolean context, None evals
to False and a Match object to True, just convert the return of re.match
to a boolean:

  return bool(re_ip.match(ipAddress))

BTW, don't mix outputs and a logic. Your validateIp() function should
*only* validate, not print anything (except for debugging purpose, but
then it should either go to a log or at least to stderr, stdout is for
normal program outputs).

> I would also like to expand that so that if the
> IP is wrong it requests the IP address again and recalls the function.

Then wrap the raw_input()/validateIp() into a loop. And wrap this loop
into a function !-)

def get_valid_ip(prompt="please enter an ip",
 errormsg="Sorry, %s is not a valid ip"):
  while True:
ip = raw_input("%s : " % prompt).strip()
if validateIp(ip):
   return ip
else:
  print errormsg % ip

ip = get_valid_ip()


> I have done the same thing in php very easily but python appears to be
> getting the better of me.

Knowledge doesn't map one-to-one from one language to another.


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: any() and all() on empty list?

2006-03-30 Thread Ron Adam
Duncan Booth wrote:
> Ron Adam wrote:
> 
>> Where we are assembling widgets in a manufacturing plant. Where we don't 
>> want to go to the next step until *all* the sub parts are present.
>>
>> if all(part.status == 'present' for part in unit):
>>  do_release()
>>
>> Oops!  Some empty bins showed up at the next assembly station. ;-)
> 
> I don't see the problem. You only get an empty bin if there is some part 
> assembled from no sub-parts, in which case you wanted an empty bin.

Hmmm...  It wasn't a well though out example.  I was thinking in terms 
of several processes working at the same time, and not communicating 
with each other.  Ie.. a bin getter, a part inserter, a part checker, a 
bin mover. etc.

But even then if all the parts get marked as 'present' even though they 
are aren't there, the bin could be released to the next station.  And so 
that example is void.  I'll try and think of a better one.


Cheers,
Ron

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


Re: does python could support sequence of short or int?

2006-03-30 Thread momobear
but what about buffer is not be declared in python program, it comes
from a C function. and what about I want to treat a string as a short
list?
buffer = foobur() // a invoke from C function, it is encapsulated as a
string
but I want to treat it as a short list.  how can I?

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


Re: does python could support sequence of short or int?

2006-03-30 Thread bruno at modulix
momobear wrote:
> but what about buffer is not be declared in python program, it comes
> from a C function. and what about I want to treat a string as a short
> list?


There are no "short" in Python. An integer is an integer is an integer...


> buffer = foobur() // a invoke from C function, it is encapsulated as a
> string
> but I want to treat it as a short list.  how can I?

I think you want the struct package from the standard lib:
http://www.python.org/doc/2.4.2/lib/module-struct.html


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: does python could support sequence of short or int?

2006-03-30 Thread Fuzzyman

momobear wrote:
> hi, is there a way to let python operate on sequence of int or short?
> In C, we just need declare a point, then I could get the point value,
> just like:
> short* k = buffer, //k is a point to a sequence point of short.
> short i = *k++,
> but python is a dynamic language,
> a = buffer
> i = ? I don't know how to continue, what's a? a seems to be a str?

A byte sequence in Python is a 'str'. They are immutable, so any
operations that change the object will return a new instance of 'str'.

In Python although we use references to objects, they aren't pointers -
so you don't operate directly on the byte sequence in memory. (Not
using the basic datatypes anyway).

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: LDTP 0.4.0 released !!!

2006-03-30 Thread Paul Boddie
Ben Finney wrote:
> "A Nagappan" <[EMAIL PROTECTED]> writes:
>
> > Welcome to the seventh issue of LDTP Newsletter!
>
> Nowhere in this newsletter do I see anything germane to a forum about
> Python. Why post it here, rather than somewhere more related to Linux
> or Desktops or Testing?
>
> And no, "because many Python programmers may be interested" is not
> good enough.

Is the response "because LDTP seems to use Python extensively" good
enough? At least according to the Web site:

http://ldtp.freedesktop.org/wiki/About
http://ldtp.freedesktop.org/wiki/Docs

I suppose such information could have been communicated more clearly in
the newsletter, but then I suppose a bit more awareness of the
different projects Python actually gets used for (ie. outside the
bubble where obsessing about one's favourite "full stack" Web framework
and other programming languages seems to be the fashion) wouldn't be a
bad thing, either.

Paul

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


Re: Apache and Python and Ubuntu

2006-03-30 Thread Paul Boddie
[EMAIL PROTECTED] wrote:
> Thanx a lot for your input and advice.  I went through the
> documentation on httpd.apache.org/docs/2.2/howto/cgi.html and added the
> following:
> AddModule cgi-script .cgi .py
> 
>  Options +ExecCGI
> 

Does Apache actually support "DIRECTORY" as opposed to "Directory"? The
configuration file isn't "old-school HTML", and I'd recommend following
the conventions in the documentation as closely as possible until you
have something working.

> It now gives me a 403 forbidden.  When I check the error logs, it still
> says that Options ExecCGI is not turned on in /var/www/
>
> Is there a special place inside of apache2.conf I'm supposed to have
> the  tag? and/or AddModule line?

I would imagine that you're not supposed to be editing apache2.conf
unless the changes are fairly important and change the global
configuration of the server. On Debian/Ubuntu, you're supposed to add
files to the /etc/apache2/sites-available directory and then use the
a2ensite program to enable the new site.

> I also double checked to make sure owner/group/other all have execute
> and it does.

You could also investigate the ScriptAlias directive to permit access
to a particular file or directory as a CGI program (or a collection of
CGI programs) at (or under) a specified location; I've found that to be
much more convenient.

Paul

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


Connecting to gnuplot with Popen?

2006-03-30 Thread Anton81
Hi,

it seems to be a FAQ, but I still haven't found a solution. I want to
control gnuplot with a python program. The following at least gives me the
gnuplot output:

subp=Popen("gnuplot",stdin=None,stderr=PIPE,stdout=PIPE)
...
subp.stderr.readline()

even though I'm not sure how to check if no more lines can be read with
readline() so that it doesn't block.
But after the script has finished, the console doesn't show me the
characters I type.

However, as soon as I try:

subp=Popen("gnuplot",stdin=PIPE,stderr=PIPE,stdout=PIPE)
...
subp.stderr.readline()

the program hangs.

What's wrong?

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


Re: any() and all() on empty list?

2006-03-30 Thread Ron Adam
Steven D'Aprano wrote:
> Paul Rubin wrote:
> 
>> Steven D'Aprano <[EMAIL PROTECTED]> writes:
>>
>>> Think of it this way: if all(seq) is true, shouldn't it be the case
>>> that you can point to a specific element in seq that is true?
>>
>>
>> No, all(seq) is true if you can't point to a specific element in seq
>> that's false.
> 
> No, all(seq) is true if every element in seq is true. Surely that's a 
> more intuitive definition than your definition by what you can't do.


Yes, they are both valid view points.  One is 'is all true' and the 
other is 'has all true'.

You can also use either to express the other...

  S and isalltrue(S)   ->  hasalltrue(S)

  not S or hasalltrue(S)   ->  isalltrue(S)



A possibly useful thing to have:

  hasall(S, value, test=None)

  hasall(S, True) # Test for actual "True" values or 1.
  hasall(S, True, bool)   # test for true values, not zero or False.
  hasall(S, 'ok')
  hasall(S, True, lambda n: n=42)

Cheers,
Ron







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


Re: any() and all() on empty list?

2006-03-30 Thread Ron Adam
Ron Adam wrote:
>
>  hasall(S, True, lambda n: n=42)
> 

That was suppose to be:

   hasall(S, True, lambda n: n==42)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: any() and all() on empty list?

2006-03-30 Thread Marcin Ciura
Georg Brandl wrote:
> Steven D'Aprano wrote:
>>all(flying elephants which are pink) => true
>>all(flying elephants which are not pink) => true
>>
>>So, these flying elephants -- are they pink or not?
> 
> No, you ask two different sets whether they are true.

No, there is only one empty set.
Relevant to this discussion is stuff
about syllogisms concerning non-existent objects
and what C.S. Peirce did to them in the 19th century.
See e.g. http://www.math.fau.edu/schonbek/mfla/mfla1f01syl.html#tth_sEc5
   Marcin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Connecting to gnuplot with Popen?

2006-03-30 Thread Dan Sommers
On Thu, 30 Mar 2006 12:59:01 +0200,
Anton81 <[EMAIL PROTECTED]> wrote:

> it seems to be a FAQ, but I still haven't found a solution. I want to
> control gnuplot with a python program ...

Unfortunately, I don't know how to solve your problem, but try this:

http://gnuplot-py.sourceforge.net/

Regards,
Dan

-- 
Dan Sommers

"I wish people would die in alphabetical order." -- My wife, the genealogist
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GUI in python

2006-03-30 Thread [EMAIL PROTECTED]
Hi,

I readed in python brazilian list, about a Eagle, it's seems like you
need...

http://www.python.org/pypi/eagle/
http://code.gustavobarbieri.com.br/eagle/

[]s

Luciano Pacheco

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


Re: any() and all() on empty list?

2006-03-30 Thread Fredrik Lundh
Marcin Ciura wrote:

>>>all(flying elephants which are not pink) => true
>>>
>>>So, these flying elephants -- are they pink or not?
>>
>> No, you ask two different sets whether they are true.
>
> No, there is only one empty set.

who said anything about empty sets ?

 



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


re.I slowness

2006-03-30 Thread vvikram
We process a lot of messages in a file based on some regex pattern(s)
we have in a db.
If I compile the regex using re.I, the processing time is substantially
more than if I
don't i.e using re.I is slow.

However, more surprisingly, if we do something on the lines of :

s = 
s = s.lower()
t = dict([(k, '[%s%s]' % (k, k.upper())) for k in
string.ascii_lowercase])
for k in t: s = s.replace(k, t[k])
re.compile(s)
..

its much better than using plainly re.I.

So the qns are:
a) Why is re.I so slow in general?
b) What is the underlying implementation used and what is wrong, if
any,
with above method and why is it not used instead?

Thanks
Vikram

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


Re: regular expressions and matches

2006-03-30 Thread johnzenger

Johhny wrote:
> Hello,
>
> I have recently written a small function that will verify that an IP
> address is valid.
>
> ==SNIP==
>
> import re
> ipAddress = raw_input('IP Address : ')
>
> def validateIP(ipAddress):
> ipRegex =
> r"^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$"

Good lord!  You might as well be writing in assembly!  The re module
docs should include a customer warning label.

Regular expressions are not the answer here.  Probably 80% of the regex
virus could be stamped out if people used split instead.  How about
something simpler, like this:

def ipValid(ipAddress):
dots = ipAddress.split(".")
if len(dots) != 4:
return False
for item in dots:
if not 0 <= int(item) <= 255:
return False
return True

...although even this function (like yours) will declare as "valid" an
IP address like 0.255.0.0.

For a real-world application, how about:

import socket
try:
mm = socket.inet_aton(ipAddress)
return True # We got through that call without an error, so it is
valid
except socket.error:
return False # There was an error, so it is invalid


> re_ip = re.compile(ipRegex)
> match = re_ip.match(ipAddress)
> if not match:
> print "an error has occured with ipAddress"
> return match
> else:
> return match
>
> print(validateIP(ipAddress))
>
> ==SNIP==
>
> I was having issues trying to get my code working so that I could pass
> the IP addresses and it would return a true or false. When it matches I
> get something that looks like this.
>
> python ip_valid.py
> IP Address : 192.158.1.1
> <_sre.SRE_Match object at 0xb7de8c80>
>
> As I am still attempting to learn python I am interested to know how I
> could get the above to return a true or false if it matches or does not
> match the IP address. I would also like to expand that so that if the
> IP is wrong it requests the IP address again and recalls the function.
> I have done the same thing in php very easily but python appears to be
> getting the better of me. Any assistance and advice would be greatly
> appreciated.
> 
> Regards,
> 
> Johhny

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


Re: Try Python!

2006-03-30 Thread Cyril Bazin
Now, you can try "laszlo in 10 minutes" http://www.laszlosystems.com/lps/laszlo-in-ten-minutes/ .

Reference: http://www.openlaszlo.org/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: i have error then use ftplib

2006-03-30 Thread Stefan Schwarzer
Hello nazarianin,

On 2006-03-30 09:35, 5>=>2 ;5:A59 wrote:
> from ftplib import FTP
> def handleDownload(block):
> file.write(block)
> print "."
>
> file = open('1', 'wb')
> ftp = FTP('ftp.utk.ru')
> ftp.set_pasv(1)
> ftp.login()
> ftp.retrlines('LIST')
> [...]

> and have this error message.
>
> Traceback (most recent call last):
>   File "ftp.py", line 10, in ?
> ftp.retrlines('LIST')
> [...]
> socket.error: (10065, 'No route to host')
>
> Programs that not use Python connect to the server ok.
> Where I do mistake?

Are you sure that you don't need user and password arguments in
.login()? The documentation on ftplib says:

login([user[, passwd[, acct]]])
Log in as the given user. The passwd and acct parameters are
optional and default to the empty string. If no user is
specified, it defaults to 'anonymous'. If user is
'anonymous', the default passwd is 'anonymous@'. This
function should be called only once for each instance, after
a connection has been established; it should not be called at
all if a host and user were given when the instance was
created. Most FTP commands are only allowed after the client
has logged in.

Perhaps the server wasn't satisfied with your credentials and
closed the connection between the .login() and .retrlines()
calls?

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


Re: does python could support sequence of short or int?

2006-03-30 Thread momobear
then how can I convert it to a int list? I read about struct and array,
I think they are not suitable, since I don't know how long will the
buffer is. I know if I write a plugins modules in C should works, but
that's really upset to tell to myself there is no way in Python.

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


Re: LDTP 0.4.0 released !!!

2006-03-30 Thread Ben Finney
"Paul Boddie" <[EMAIL PROTECTED]> writes:

> Ben Finney wrote:
>> "A Nagappan" <[EMAIL PROTECTED]> writes:
>> > Welcome to the seventh issue of LDTP Newsletter!
>> Nowhere in this newsletter do I see anything germane to a forum
>> about Python. Why post it here, rather than somewhere more related
>> to Linux or Desktops or Testing?
>
> Is the response "because LDTP seems to use Python extensively" good
> enough?

That information in the newsletter would be much more helpful, yes.
Otherwise it just looks like open season for announcing any technical
project to the list.

Most projects have a consistent "what is this thing and why should you
care" paragraph in every release announcement; this would be the place
to make clear the association with the forum where it's posted.

-- 
 \   "People come up to me and say, 'Emo, do people really come up |
  `\ to you?'"  -- Emo Philips |
_o__)  |
Ben Finney

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


Re: does python could support sequence of short or int?

2006-03-30 Thread Mirco Wahab
Hi momobear

> then how can I convert it to a int list? I read about struct and array,
> I think they are not suitable, since I don't know how long will the
> buffer is. I know if I write a plugins modules in C should works, but
> that's really upset to tell to myself there is no way in Python.

this was imho a typical non-problem in
"scripting languages" - regarding the
areas where they are usually employed.

there are some good exensions for Python,
numarray and numpy and so on ...
(http://numeric.scipy.org/)

These provide C-like arrays and
allow you writing programs entirely
in Python w/C-speed on arrays.

interesting: Perl6 will be the first
(afaik) scripting language w/"type arrays"
build into the core language
e.g.
 sub hist(Int @vals) returns Array of Int {
  my Int @histogram;
  for @vals { @histogram[$_]++ }
  return @histogram;
}
(from http://www.jauu.net/data/foils/perl6/perl_6.html)

Regards,

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


Re: Looking for a language/framework

2006-03-30 Thread Magnus Lycka
Steve Juranich wrote:
> [EMAIL PROTECTED] wrote:
> 
>> As far as hosting, I also know
>> where Zope/Plone hosting from 7.95 a month - although the host doesn't
>> list it on their ads, they do use and host it.
> 
> Which host would this be?  I'm currently exploring some options for getting
> a Zope site hosted.

Virtual servers is getting cheaper and cheaper. That's obviously
a viable way to host Zope, if you don't mind being your own sysop.
-- 
http://mail.python.org/mailman/listinfo/python-list


Set Windows Environment Variable

2006-03-30 Thread Fuzzyman
Hello all,

I would like to set a Windows Environment variable for another
(non-child) process.

This means that the following *doesn't* work : ::

os.environ['NAME'] = value

In the ``win32api`` package there is a ``GetEnvironmentVariable``
function, but no ``SetEnvironmentVariable``. Any options ?

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: does python could support sequence of short or int?

2006-03-30 Thread Diez B. Roggisch
momobear wrote:

> then how can I convert it to a int list? I read about struct and array,
> I think they are not suitable, since I don't know how long will the
> buffer is. I know if I write a plugins modules in C should works, but
> that's really upset to tell to myself there is no way in Python.

You think wrong - they _are_ suitable. You can create the
struct.unpack-format string on the fly, which allows you to do this:

import struct
some_ints = range(1000)
v = struct.pack("%ih" % len(some_ints), *some_ints)
print struct.unpack("%ih" % len(some_ints), v)

Regards,

Diez



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


Low Pass Hamming filter design

2006-03-30 Thread LabWINC
Hi all,
i have a question for all :-D

I would like to design and apply a FIR low pass filter with Hamming
window.
I'm using scipy module.

First I create the windows with the signal.firwin function and after i
apply this window to my signal with the signal.lfilter function.

I didn't understand where i can specify what kind of filter i'm
implementing (low, high or band pass).

Thanks all,

Vincenzo

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


Re: Set Windows Environment Variable

2006-03-30 Thread Duncan Booth
Fuzzyman wrote:

> Hello all,
> 
> I would like to set a Windows Environment variable for another
> (non-child) process.
> 
> This means that the following *doesn't* work : ::
> 
> os.environ['NAME'] = value
> 
> In the ``win32api`` package there is a ``GetEnvironmentVariable``
> function, but no ``SetEnvironmentVariable``. Any options ?

No, your only option is to find a solution which doesn't involve changing 
another process's environment.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New Python website, new documentation ?

2006-03-30 Thread Tim Parkin
[EMAIL PROTECTED] wrote:

>Hi,
>
>I was wondering : as there has been a change in python.org website with
>a new design, is it planned for the documentation section to be
>revamped as well ? If yes, would it be just a appearance renewal or
>would there also be changes in the doc itself ?
>
>Martin.
>  
>
docs.python.org will stay the same as far as I am aware but I'll be
looking at trying out a version of the docs using the new python.org
layout. Obviously this will affect more regular users of the site and so
will need testing out first. The structure of the documentation won't
change but it will have a new navigation (rather than just the back, up,
forward on the current latex2html output). It's probably best to get
something up on a test site to look at before over-analysing it though..

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


Countdown from 2 minutes - how?

2006-03-30 Thread [EMAIL PROTECTED]
Hi.

Can anyone tell me the python code for a simple countdown from eg. 2.00
minutes.

It should be printet out to the screen.
When it is finished it should write "Time is up"

Hope you can help.

Henrik

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


Re: does python could support sequence of short or int?

2006-03-30 Thread Richard Brodie

"momobear" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

> then how can I convert it to a int list? I read about struct and array,
> I think they are not suitable, since I don't know how long will the
> buffer is. I know if I write a plugins modules in C should works, but
> that's really upset to tell to myself there is no way in Python.

I'm not sure why you think that the array and struct modules are
unsuitable:

>>>import array
>>>buffer = 'iidfkljhfpa3'
>>>arr = array.array('h', buffer)
>>> print arr
array('h', [26985, 26212, 27755, 27498, 27499, 26731, 28774, 13153])



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


Non-GUI source code browser with file system tree view

2006-03-30 Thread Stefan Schwarzer
Hello,

from time to time I want to inspect the source code of projects
on remote computers.(*) I've googled for one or two hours but
didn't find anything helpful. :-/ I'm looking for something like
IDLE's path browser - i. e. a tree view and file view
side-by-side - but with the following differences:

- doesn't need an X connection to the remote computer where the
  sources are

- must also work with other programming languages (ideally with
  syntax highlighting)

- consequently, the tree view will not be based on a module
  search path but on a file system directory

Ideally, but not necessesarily, this browser should be written in
Python. If possible, it should be open source software. It _must_
run on GNU/Linux and, if possible, on Mac OS X (a local X server
is ok if the mentioned browser is a curses-based program).
(Another approach might be a small web application server in the
spirit of "pydoc -p " which could connect to a local port
forwarded with ssh.)

Does anyone know of a source code browser which meets the
requirements listed above or links that could help me? Many
thanks in advance. :-)

(*) Copying the files to the local host is probably rather
impractical because the files sometimes change very frequently.
Developing only locally is impractical for some projects because
the remote development server has some infrastructure that I
can't reproduce locally or only with a lot of work.

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


ANN: pywinauto 0.3.1 released - Performance tune-ups

2006-03-30 Thread mark . m . mcmahon
Hi,

The 0.3.1 release of pywinauto is now available.

pywinauto is a set of open-source (LGPL) modules for using Python as a
GUI
automation 'driver' for Windows NT based Operating Systems (NT/W2K/XP).

SourceForge project page:
http://sourceforge.net/projects/pywinauto

Download from SourceForge
http://sourceforge.net/project/showfiles.php?group_id=157379


Here is the list of changes from 0.3.0:

0.3.1 Performance tune-ups
--
30-Mar-2006

* Change calculation of distance in
findbestmatch.GetNonTextControlName()
  so that it does not need to square or get the square root to
  find the real distance - as we only need to compare values - not have
  the actual distance. (Thanks to Stefaan Himple)

* Compiled regular expression patterns before doing the match to
  avoid compiling the regular expression for window that is being
  tested (Thanks to Stefaan Himple)

* Made it easier to add your own control tests by adding a file
  extra_tests.py which needs to export a ModifyRegisteredTests()
method.
  Also cleaned up the code a little.

* Updated notepad_fast.py to make it easier to profile (adde a method)

* Changed WrapHandle to use a cache for classes it has matched - this
is
  to avoid having to match against all classes constantly.

* Changed default timeout in SendMessageTimeout to .001 seconds from .4
  seconds this results in a significant speedup. Will need to make this
  value modifiable via the timing module/routine.

* WaitNot was raising an error if the control was not found - it should
  have returned (i.e. success - control is not in any particular state
  because it does not exist!).

* Added ListViewWrapper.Deselect() per Chistophe Keller's suggestion.
  While I was at it I added a check on the item value passed in and
added
  a call to WaitGuiIdle(self) so that the control has a chance to
process
  the message.

* Changed doc templates and moved dependencies into pywinauto
  subversion to ensure that all files were availabe at www.openqa.org
and
  that they are not broken when viewed there.

* Moved all timing information into the timings.Timings class. There
are
  some simple methods for changing the timings.


If you want to follow this project then please sign up to the mailing
list:
https://lists.sourceforge.net/mailman/listinfo/pywinauto-users

Thanks
 Mark


Mark Mc Mahon
Manchester, NH 03110, USA

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


Re: Non-GUI source code browser with file system tree view

2006-03-30 Thread Fredrik Lundh
Stefan Schwarzer wrote:

> (*) Copying the files to the local host is probably rather
> impractical because the files sometimes change very frequently.

do lots of files change very frequently, or just a small number ?

if the latter, I doubt you'll be able to beat rsync+local browsing.

 



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


Re: New Python website, new documentation ?

2006-03-30 Thread Armin Ronacher
I paste my idea (original posted in #pythonpaste a few days ago):

 Chairos: what I really miss is a "go-python.org" page :)
 which would be what?
 showing up python gui application, python wsgi
applications, a python documentation with a comment section, tutorials
and a wiki
 and everything compact
 and python.org for the companies and core developers

Something really basic. Only small tutorials, a documentation with
comments and a list of python applications. With a clean design and
only few links per page. Something like the rubyonrails page for
example.

Regards,
Armin

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


Re: Countdown from 2 minutes - how?

2006-03-30 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> Can anyone tell me the python code for a simple countdown from eg. 2.00
> minutes.
>
> It should be printet out to the screen.
> When it is finished it should write "Time is up"

here's a first version:

import time
time.sleep(2*60)
print "Time is up"

to improve this, I suggest reading the chapter on loops in the tutorial:

http://docs.python.org/tut/node6.html

 



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


Stackless Python for 2.4.3

2006-03-30 Thread Richard Tew
Hi,

Stackless Python is now available for the recent release of Python
2.4.3 (final).

You can either obtain the source code from the SVN repository or
download the precompiled windows binaries.

SVN:http://codespeak.net/svn/stackless/Python-2.4.3/dev
Download: http://www.stackless.com/download

If anyone plans to download and compile the source, there are
however some minor things that need to be taken into account which you
may be able to help me with, if you have the time.

 1. I need a generated 'configure' file.  I believe the 'configure.in'
fine should be fine, but if someone could run autoconf and send me
the result so I can check it in, it would be appreciated.

It would be best if anyone planning to do this checked the
Stackless mailing list to see if there was any mention of
someone else already having taken care of it.

 2. Having the Python tests run, and the Stackless unittests run by
various people on different platforms would give a better
indication of the state of the port.

The following instructions are of course Win32 specific, but they
should be translate easily.

a) Retrieve the 2.4.3 source code from SVN at:
   http://codespeak.net/svn/stackless/Python-2.4.3/dev

b) Compile it.

c) Open a console in the 'Stackless\unittests' directory.
   Type '..\..\PCBuild\python.exe run_all.py'.

   The expected result is that one pickling test will fail, this is
   ok and it is the same known bug that we had for 2.4.2, which
   should be easy enough to fix if someone wants to step forward
   and put in the time and effort.

d) Open a console in the top level of the source code.
   Type 'PCBuild\python.exe Lib\test\regrtest.py'

   The expected result is that there will be a lot of skipped
   tests, and possibly some failures depending on your platform.

   I had these fail:
   - test_email
   - test_winsound

   Neither of the errors were necessarily Stackless related, but
   it is possible they are.  But if you see any for your build that
   are unexpected, please mention them.

Thanks,
Richard Tew.

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


How to determine an object is "scriptable"

2006-03-30 Thread abcd
I recently came across a problem where I saw this error:
"TypeError: unsubscriptable object"

How can I determine if an object is "scriptable" or "unscriptable"?

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


Re: Countdown from 2 minutes - how?

2006-03-30 Thread Fuzzyman

[EMAIL PROTECTED] wrote:
> Hi.
>
> Can anyone tell me the python code for a simple countdown from eg. 2.00
> minutes.
>
> It should be printet out to the screen.
> When it is finished it should write "Time is up"
>
> Hope you can help.
>

You need the module ``time`` :

import time
start = time.time()
lastprinted = 0
finish = start + 120
while time.time() < finish:
now = int(time.time())
if now != lastprinted:
print int(finish - now)
lastprinted = now
time.sleep(0.5)   # this stops the system hanging whilst this is
running

print "Time is up"

HTH

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> Henrik

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


Re: Doc suggestions (was: Why "class exceptions" are not deprecated?)

2006-03-30 Thread Fredrik Lundh
Ed Singleton wrote:

> I'd suggest adding some sort of guidance page so that people know
> roughly what's expected.  IE can they just add questions and comments
> into the text, hoping that someone more knowledgeable will sort it out
> (or delete it).

I've added some notes to the front-page.  feel free to tweak/clarify (or post
comments here or on the site).

for now, I think it's worth trying to keep the text clean and reasonably read-
able at all times, and use the comment function to add questions/suggestions
(more wikipedia than c2, in other words).

more later.

 



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


Re: any() and all() on empty list?

2006-03-30 Thread Antoon Pardon
Op 2006-03-30, Steven D'Aprano schreef <[EMAIL PROTECTED]>:
> Paul Rubin wrote:
>
>> Steven D'Aprano <[EMAIL PROTECTED]> writes:
>> 
>>>Think of it this way: if all(seq) is true, shouldn't it be the case
>>>that you can point to a specific element in seq that is true?
>> 
>> 
>> No, all(seq) is true if you can't point to a specific element in seq
>> that's false.
>
> No, all(seq) is true if every element in seq is true. 
> Surely that's a more intuitive definition than your 
> definition by what you can't do.
>
> The question that needs to be answered is, what if 
> there are no elements at all? That's an arbitrary 
> decision. Like the question "what is 0**0?" in 
> mathematics, some answers are more useful than others. 
> I can respect that practical answer -- but it isn't the 
> *only* answer.
>
> (For those who don't see why 0**0 is problematic, 0**x 
> is equal to 0 for all x, and x**0 is equal to 1 for all 
>   x, so what do you do for 0**0?)
>
> Here's another way of looking at the problem:
>
> all(flying elephants which are pink) => true
> all(flying elephants which are not pink) => true
>
> So, these flying elephants -- are they pink or not?

They are both.

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


Re: Python Debugger / IDE ??

2006-03-30 Thread Magnus Lycka
Don Taylor wrote:
> Is there a free or low-cost version of Delphi for Windows available 
> anywhere?

Sure.

If my memory serves me correctly, I have several CDs from various
computer magazines with previous versions of Delphi at home. I don't
know if such offers have been around recently, but you could check
some computer magazines with included CDs or DVDs.

Borlands web site currently says: "Please note that Delphi 2005
Personal is only distributed through select publications, and is not
available for download."

Google for more info... See e.g.
http://www.delphigamedev.com/2005_04_01_archive.htm#111429746345094436
http://blogs.slcdug.org/rhordijk/archive/2005/02/12/1114.aspx

See also:
http://groups.google.se/group/borland.public.delphi.non-technical
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stackless Python for 2.4.3

2006-03-30 Thread Fuzzyman

Richard Tew wrote:
> Hi,
>
> Stackless Python is now available for the recent release of Python
> 2.4.3 (final).
>

Does anyone happen to know if Stackless Python is compatible with
existing third party extension modules (like e.g. Tkinter and wxPython)
?

I'm afraid my internet connection here is 'restricted' or I would
google first...

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: How to determine an object is "scriptable"

2006-03-30 Thread Richard Brodie

"abcd" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

>I recently came across a problem where I saw this error:
> "TypeError: unsubscriptable object"
>
> How can I determine if an object is "scriptable" or "unscriptable"?

subscriptable: supports an indexing operator, like a list does.



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


Re: Looking for a language/framework

2006-03-30 Thread [EMAIL PROTECTED]
Actually I recently went from a managed hosting to a virtual host via
XEN, it's been great value for the cost

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


Re: How to determine an object is "scriptable"

2006-03-30 Thread abcd
Richard Brodie wrote:
> subscriptable: supports an indexing operator, like a list does.

doesn't seem to be a builtin function or module...or is that just your
definition of subscriptable?

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


Re: re.I slowness

2006-03-30 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> We process a lot of messages in a file based on some regex pattern(s)
> we have in a db.
> If I compile the regex using re.I, the processing time is substantially
> more than if I
> don't i.e using re.I is slow.
>
> However, more surprisingly, if we do something on the lines of :
>
> s = 
> s = s.lower()
> t = dict([(k, '[%s%s]' % (k, k.upper())) for k in
> string.ascii_lowercase])
> for k in t: s = s.replace(k, t[k])
> re.compile(s)
> ..
>
> its much better than using plainly re.I.
>
> So the qns are:
> a) Why is re.I so slow in general?
> b) What is the underlying implementation used and what is wrong, if
> any,
> with above method and why is it not used instead?
>
> Thanks
> Vikram
>
Can't tell you why re.I is slow, but perhaps this expression will make your
RE transform a little plainer (no need to create that dictionary of uppers
and lowers).

s = 
makeReAlphaCharLowerOrUpper = lambda c : c.isalpha() and "[%s%s]" %
(c.lower(),c.upper()) or c
s_optimized =  "".join( makeReAlphaCharLowerOrUpper(k) for k in s)

or

s_optimized =  "".join( map( makeReAlphaCharLowerOrUpper, s ) )


Just curious, but what happens if your RE contains something like this
spelling check error finder:
"[^c]ei"
(looking for violations of "i before e except after c")

Can []'s nest in an RE?

-- Paul


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


Re: How to determine an object is "scriptable"

2006-03-30 Thread Larry Bates
abcd wrote:
> I recently came across a problem where I saw this error:
> "TypeError: unsubscriptable object"
> 
> How can I determine if an object is "scriptable" or "unscriptable"?
> 
Simplest answer is to use isinstance to see if it is a string, list,
or tuple:

if isinstance(variable, (str, list, tuple)):
.
.
.

Now the problem is that this answer doesn't address the problem.
Your code is attempting to do something to the wrong type of
object/variable which is a logic problem.

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


Re: a hobbyist's dilemma

2006-03-30 Thread Benny
John Salerno wrote:

> Anyway, any suggestions are appreciated!

What've you got for hobbies? As my first Python
based project I wrote something that put up a GUI
and allowed me to add and delete records in a file
so that I could catalogue my model railway collection.

Now I could have used a dB package (overkill) or a
spreadsheet (if all you have is a hammer, every
problem looks like a nail) or something that
someone else had written (mostly MS Windows based)
but part of the point was to practise programming
in Python. (On top of which, if I do it this way,
the thing's much more portable across the OS's that
I use.)

At the point that my enthusiasm returns I'm going
to be coding up a simulation of a gravity shunting
yard using PyGame (based on something I saw at
the Dutch National Railway Museum) and then further
extend that to a more generic shunting simulator.
(Should keep me happy whilst I build the basics
of the track plan on the model railway boards...)

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


Re: How to determine an object is "scriptable"

2006-03-30 Thread Daniel Evers
Richard Brodie wrote:

> subscriptable: supports an indexing operator, like a list does.

Right. You can check this e.g. with

hasattr(x, "__getitem__")

because the __getitem__ method is used for indexing.

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


Re: Non-GUI source code browser with file system tree view

2006-03-30 Thread bruno at modulix
Stefan Schwarzer wrote:
> Hello,
> 
> from time to time I want to inspect the source code of projects
> on remote computers.(*) I've googled for one or two hours but
> didn't find anything helpful. :-/ I'm looking for something like
> IDLE's path browser - i. e. a tree view and file view
> side-by-side - but with the following differences:
> 
> - doesn't need an X connection to the remote computer where the
>   sources are
> 
> - must also work with other programming languages (ideally with
>   syntax highlighting)
> 
> - consequently, the tree view will not be based on a module
>   search path but on a file system directory
> 
> Ideally, but not necessesarily, this browser should be written in
> Python. If possible, it should be open source software. It _must_
> run on GNU/Linux and, if possible, on Mac OS X (a local X server
> is ok if the mentioned browser is a curses-based program).
> (Another approach might be a small web application server in the
> spirit of "pydoc -p " which could connect to a local port
> forwarded with ssh.)
> 
> Does anyone know of a source code browser which meets the
> requirements listed above or links that could help me? Many
> thanks in advance. :-)

emacs + emacs code browser.



-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to determine an object is "scriptable"

2006-03-30 Thread abcd
Daniel Evers wrote:
> Right. You can check this e.g. with
>
> hasattr(x, "__getitem__")
>
> because the __getitem__ method is used for indexing.

Thanks...that is what I was looking for!

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


Re: Countdown from 2 minutes - how?

2006-03-30 Thread preved . rly
#!/bin/env python
# countdown.py
import time
import doctest

def countdown( time_in_minutes):
"""
>>> import countdown
>>> countdown.countdown(0.1) # doctest:+ELLIPSIS
6
5
...
1
Time is up
"""
for i in reversed(xrange(1, int(time_in_minutes * 60) + 1)):
print i
time.sleep(1)
print 'Time is up'

if __name__=='__main__':
doctest.testmod()

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


Re: Countdown from 2 minutes - how?

2006-03-30 Thread preved . rly
#!/bin/env python
# countdown.py

import time
import doctest

def countdown( time_in_minutes):
"""
>>> import countdown
>>> countdown.countdown(0.1) # doctest:+ELLIPSIS
6
5
...
1
Time is up
"""
for i in xrange(int(time_in_minutes * 60 + 0.5), 0, -1):
print i
time.sleep(1)
print 'Time is up'

if __name__=='__main__':
doctest.testmod()

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


Re: Why are so many built-in types inheritable?

2006-03-30 Thread Antoon Pardon
Op 2006-03-28, Georg Brandl schreef <[EMAIL PROTECTED]>:
> Fabiano Sidler wrote:
>> I really wanted to learn the reason for this, nothing else! ;)
>
> I suspect performance reasons. Can't give you details but function
> is used so often that it deserves special treatment.

I would find this a bit odd. I think integers, tuples and lists
are used just as often if not more and they aren't treated special.

I for one would gladly treat some performance for the ability
to subclass slices.

  class islice(slice):
...

doesn't work


And if I just write

  class islice:

 def __init__(self, start, stop, step):
   self.start = start
   self.stop = stop
   self.step = step

then the following doesn't work:

  lst = range(20)
  sl = islice(2,6,None)
  lst[sl]


So much for ducktyping.

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


Re: How to determine an object is "scriptable"

2006-03-30 Thread bruno at modulix
Larry Bates wrote:
> abcd wrote:
> 
>>I recently came across a problem where I saw this error:
>>"TypeError: unsubscriptable object"
>>
>>How can I determine if an object is "scriptable" or "unscriptable"?
>>
> 
> Simplest answer is to use isinstance to see if it is a string, list,
> or tuple:
> 
> if isinstance(variable, (str, list, tuple)):

Which will fail for a whole lot of objects that are scriptable...
Better use Daniel's solution or a try/except.

> 
> Now the problem is that this answer doesn't address the problem.
> Your code is attempting to do something to the wrong type of
> object/variable which is a logic problem.

Of course !-)



-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to determine an object is "scriptable"

2006-03-30 Thread Richard Brodie

"abcd" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

> doesn't seem to be a builtin function or module...or is that just your
> definition of subscriptable?

Yes, I figured you were just confused. You were using the wrong words,
after all.



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


Re: How to determine an object is "scriptable"

2006-03-30 Thread bruno at modulix
abcd wrote:
> Richard Brodie wrote:
> 
>>subscriptable: supports an indexing operator, like a list does.
>  
> doesn't seem to be a builtin function or module...

It's not. Look no further.

> or is that just your
> definition of subscriptable?

It's a correct definition of 'subscriptable' in the context of the
Python programming language - as well as a good exemple of an implied
interface.

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stackless Python for 2.4.3

2006-03-30 Thread Stephan Diehl
On Thu, 30 Mar 2006 06:04:27 -0800, Fuzzyman wrote:

> 
> Richard Tew wrote:
>> Hi,
>>
>> Stackless Python is now available for the recent release of Python
>> 2.4.3 (final).
>>
> 
> Does anyone happen to know if Stackless Python is compatible with
> existing third party extension modules (like e.g. Tkinter and wxPython)
> ?
> 
It's definatelly compatible with wxPython. If memory serves right, there
were some issues with Tkinter. It would be best to ask on stackless 
mailinglist for details (I'm not sure, if wxPython worked out of the box
or if there was some trick involved)

Stephan

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


Re: Why are so many built-in types inheritable?

2006-03-30 Thread Georg Brandl
Antoon Pardon wrote:
> Op 2006-03-28, Georg Brandl schreef <[EMAIL PROTECTED]>:
>> Fabiano Sidler wrote:
>>> I really wanted to learn the reason for this, nothing else! ;)
>>
>> I suspect performance reasons. Can't give you details but function
>> is used so often that it deserves special treatment.
> 
> I would find this a bit odd. I think integers, tuples and lists
> are used just as often if not more and they aren't treated special.

Well, for integers, tuples and lists you can at least give useful
use cases for subclassing.

I now looked in the code, and the ability to subclass is given by a
flag in the type object. This is there in list or int, but not in function.

A little performance is saved by the fact that PyFunction_Check, which
verifies that an object is indeed a function, doesn't have to check for
subtypes.

So, if you want to make functions or slices subclassable, ask on python-dev!

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


Re: Why are so many built-in types inheritable?

2006-03-30 Thread Michele Simionato
I cannot find the reference now, but I remember Tim Peters saying some
time ago that the only
reason why FunctionType is not subclassable is that nobody bothered to
write a patch for it.

   Michele Simionato

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


Re: does python could support sequence of short or int?

2006-03-30 Thread Magnus Lycka
momobear wrote:
> hi, is there a way to let python operate on sequence of int or short?

If you want to work with arrays of numbers, you might want to
look at NumArray etc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to determine an object is "scriptable"

2006-03-30 Thread bruno at modulix
abcd wrote:
> I recently came across a problem where I saw this error:
> "TypeError: unsubscriptable object"
> 
> How can I determine if an object is "scriptable" or "unscriptable"?

By trying to apply the subscript operator ('[]'). If it raises a
TypeError, then it's not subscriptable.

But, as Larry Bates already pointed out, your real problem is a logic
error: you get an unsubscriptable object where you assumed you had a
subscriptable one.

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Apache and Python and Ubuntu

2006-03-30 Thread msuemnig
Paul,

thank you so much for your information and help!  That was exactly the
issue.

I added ExecCGI and addHandler cgi-script .cgi to the
sites-available/default file and bounce the service and it's working!

Thanx again!

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


Re: a hobbyist's dilemma

2006-03-30 Thread John Salerno
Benny wrote:
> John Salerno wrote:
> 
>> Anyway, any suggestions are appreciated!
> 
> What've you got for hobbies? 

Hmm, my hobbies...well, programming for one. :) Also literature and 
anything computer-related. I suppose I could try to catalog some books. 
One like I'd like to learn is how to use Python with MySQL, but I just 
can't get MySQL to work on my computer, so I'm at a dead end there. 
Seems like the best option for cataloging though.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stackless Python for 2.4.3

2006-03-30 Thread Richard Tew
I would just like to clarify, the windows specific paths do not
imply that Stackless compiles only on Windows, or that the
tests being run on Windows is all I am interested in.

Stackless compiles on a range of non-Windows platforms, including
x86 linux, mac os and others.  And knowing the port works on them
all and is therefore more or less complete except for known issues
is what I am interesting in learning.  Or what has to be fixed.

Thanks,
Richard.

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


Re: RELEASED Python 2.4.3, final.

2006-03-30 Thread John Salerno
Anthony Baxter wrote:

> On behalf of the Python development team and the Python community,
> I'm happy to announce the release of Python 2.4.3 (final).

Thanks!

> Assuming no major bugs pop up, the next release of Python will
> be Python 2.5 (alpha 1), with a final 2.4.4 release of Python 
> shortly after the final version of Python 2.5.

Why would 2.4.4 come out after the final release of 2.5?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RELEASED Python 2.4.3, final.

2006-03-30 Thread Gerhard Häring
John Salerno wrote:
> Anthony Baxter wrote:
>>On behalf of the Python development team and the Python community,
>>I'm happy to announce the release of Python 2.4.3 (final).
> 
> Thanks!
> 
>>Assuming no major bugs pop up, the next release of Python will
>>be Python 2.5 (alpha 1), with a final 2.4.4 release of Python 
>>shortly after the final version of Python 2.5.
> 
> Why would 2.4.4 come out after the final release of 2.5?

Because upgrading to a higher Python micro release is always 
backwards-compatible. Even with existing third-party extension modules 
that you have installed.

Going from 2.4.x to 2.5.x normally means you have to recompile all your 
extension modules written in C. Or download and install them, if they 
have binaries for your platform.

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


Re: RELEASED Python 2.4.3, final.

2006-03-30 Thread Fredrik Lundh
John Salerno wrote:

> > Assuming no major bugs pop up, the next release of Python will
> > be Python 2.5 (alpha 1), with a final 2.4.4 release of Python
> > shortly after the final version of Python 2.5.
>
> Why would 2.4.4 come out after the final release of 2.5?

the 2.X.Y releases are bugfix releases, which mainly contain things discovered
and fixed during development of 2.(X+1).  releasing the last 2.X.Y maintenance
release *after* releasing 2.(X+1) final is a good way to make sure that nothing
got left out.





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


Re: a hobbyist's dilemma

2006-03-30 Thread benchline
Since you want to learn to use python with a database you may want to
try it with SQLite.  SQLite is a very easy to use database that stores
the whole database in one file.  Working with it would be very similar
to working with Mysql through python.

http://www.sqlite.org
http://initd.org/tracker/pysqlite

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


printing under MS win

2006-03-30 Thread Dean Allen Provins
Hi:

My Linux-based Python/Tkinter application runs nicely, and printing
works just fine (to a user-selected file, or an "lpr" device specified
in the Entry box).  Alas, the user wants to run it under MS Win, and of
course will want to print the canvas for posterity.

A Google search turned up a similar request from many years ago, which
seemed to go unanswered.

My current thoughts are 1) get the user to print to a file and let him
copy the file to his printer (which is postscript); 2) do much the same
as (1), but let the user display and print under Ghostscript/Ghostview;
and 3) get the user to install UNIX printing services (which I found not
to be trivial when I had to do it once) and then printing will run much
as it does on UNIX/Linux.

Any thoughts or other ideas?

Regards,

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


Re: a hobbyist's dilemma

2006-03-30 Thread John Salerno
benchline wrote:
> Since you want to learn to use python with a database you may want to
> try it with SQLite.  SQLite is a very easy to use database that stores
> the whole database in one file.  Working with it would be very similar
> to working with Mysql through python.
> 
> http://www.sqlite.org
> http://initd.org/tracker/pysqlite
> 

The thing about mysql is that it's also the db used on my website, so I 
figure it might be nice to learn that one in case I ever need to use 
that db also. Unless the basic uses for all databases are the same (i.e. 
if it isn't like learning a new language for each different database)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Doc suggestions (was: Why "class exceptions" are not deprecated?)

2006-03-30 Thread Gerard Flanagan
Fredrik Lundh wrote:

> Ed Singleton wrote:
>
> > I'd suggest adding some sort of guidance page so that people know
> > roughly what's expected.  IE can they just add questions and comments
> > into the text, hoping that someone more knowledgeable will sort it out
> > (or delete it).
>
> I've added some notes to the front-page.  feel free to tweak/clarify (or post
> comments here or on the site).
>
> for now, I think it's worth trying to keep the text clean and reasonably read-
> able at all times, and use the comment function to add questions/suggestions
> (more wikipedia than c2, in other words).
>
> more later.
>
> 

I like it!

Can a page be easily recovered if someone decided to delete it?

Can anyone add a page? How to do this?

Would it be a good idea to make every subsection of a page linkable?
eg.

http://pytut.infogami.com/node6.html#the_range_function

then a list of the subsections at the top of each page? For example
I've added such a list at http://pytut.infogami.com/node6.html

Gerard

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


Re: RELEASED Python 2.4.3, final.

2006-03-30 Thread John Salerno
Fredrik Lundh wrote:
> John Salerno wrote:
> 
>>> Assuming no major bugs pop up, the next release of Python will
>>> be Python 2.5 (alpha 1), with a final 2.4.4 release of Python
>>> shortly after the final version of Python 2.5.
>> Why would 2.4.4 come out after the final release of 2.5?
> 
> the 2.X.Y releases are bugfix releases, which mainly contain things discovered
> and fixed during development of 2.(X+1).  releasing the last 2.X.Y maintenance
> release *after* releasing 2.(X+1) final is a good way to make sure that 
> nothing
> got left out.
> 
> 
> 
> 
> 

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


Re: a hobbyist's dilemma

2006-03-30 Thread Fredrik Lundh
John Salerno wrote:

> One like I'd like to learn is how to use Python with MySQL, but I just
> can't get MySQL to work on my computer, so I'm at a dead end there.
> Seems like the best option for cataloging though.

if you want to play with SQL and Python's DB-API *without* having
to install server stuff, pysqlite is a good choice:

http://initd.org/tracker/pysqlite





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


Re: Set Windows Environment Variable

2006-03-30 Thread Magnus Lycka
Duncan Booth wrote:
> Fuzzyman wrote:
>> In the ``win32api`` package there is a ``GetEnvironmentVariable``
>> function, but no ``SetEnvironmentVariable``. Any options ?
> 
> No, your only option is to find a solution which doesn't involve changing 
> another process's environment.

Surely there must be a way to programatically set up the
environment variables for not yet started processes? I.e.
doing the same as when you manually change things in the
control panel. I'm pretty sure many Windows installers do
that, and while I suppose this is technically a registry
manipulation, I suspect there is a more direct API somewhere.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: does python could support sequence of short or int?

2006-03-30 Thread Magnus Lycka
momobear wrote:
> but what about buffer is not be declared in python program, it comes
> from a C function. and what about I want to treat a string as a short
> list?

Python is a high level language with much stronger typing than C.
If you want a list of integers, use a list of integers. Strings
are for text. You might well extract numeric values from a string that
you get from another source, and you can use array or struct for that,
but don't use that while processing numeric values in Python.

Sorry, but when I hear you, I see the image of someone who shoves dirt
into the trunk of a car, goes over to the front, tries to lift it with
his bare hands, and complains that this is a really clunky wheel-barrow.
;^)

Don't try to make Python into some kind of crippled C. It's much more
powerful than C if you use it as intended. Used backward, it will only
irritate you. I can well understand that you try to use C idioms if that
is what you know, but you should understand that this will often lead
you to bad Python solutions.

I don't quite understand how you intend that the interface between C
and Python would look. You can't just pass a raw C pointer to Python.
If you want that data to be managed by your C code, you need to provide
an API that you can access from Python that will make sense for Python.

If you e.g. pass a string as a return value from a wrapped C function,
you can e.g. use array or struct in Python to access it in a way that
makes sense in Python.

Assuming that your C function returns a string with 2 byte integers like
this:
 >>> s
'\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\t\x00'

You can easily make a list like this:

 >>> import struct
 >>> l = list(struct.unpack('h'*(len(s)/2), s))
 >>> l
[1, 2, 3, 4, 5, 6, 7, 8, 9]

If you don't need to manipulate it, you can skip the 'list()'
part and get an immutable tuple instead.

The advantage with struct over array in s case like this (as far as I
understand) is that you have control over endianness.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Validating Syntax only with PyParser_SimpleParseString ?

2006-03-30 Thread gaston . gloesener
Thanks for th eanswers so far.

But as you can see from the function I use, I do need an interface
function to do th ejob from C++. I canno timagine there is no clean way
to do this. Calling th epython interpreter to execute a compule
function in python and then get the output parsed to get th eerror
message i snot an option. The strange thing however is that I have
tried to use th ecompile interface function first and this one did
return an error. I supposed this was because th ewhole context did not
exist so I went to the "parse only" function.

The main question I have is what to do with the pointer to the node
structure returned by this function, as freeing th epointer with free()
throws an error.

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


  1   2   3   >