Re: FTP not Returning (Python on Series 60 Nokia)

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

> I'm using the ftp library (layer on top of sockets) to transfer files
> from  a series 60 to an ftp site.  everything works fine, the whole
> file gets uploaded but the command never returns!  so
> i call:
>
> ftp.storbinary('STOR ' + filename,F,1024) # store the image
>
> which does this:
>
>  def storbinary(self, cmd, fp, blocksize=8192):
>  '''Store a file in binary mode.'''
>  self.voidcmd('TYPE I')
>  conn = self.transfercmd(cmd)
>  while 1:
>  buf = fp.read(blocksize)
>  if not buf: break
>  conn.send(buf)
>  conn.close()
>  return self.voidresp()
>
> and the 'while 1' never stops.  That's my guess anyway.

assuming that the connection works properly, the only way to get stuck
in the while loop is if the size of your file is infinitely huge.

so it's probably a connection issue; I suggest adding print statements
around the conn.send and conn.close calls, to make it easier to see
where you get stuck.

setting the debug level (e.g. ftp.set_debuglevel(2)) might also provide
some additional clues.





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


Re: Difference between 'is' and '=='

2006-03-28 Thread Joel Hedlund
> If it weren't for the current CPython optimization (caching small 
> integers) 

This has already been covered elsewhere in this thread. Read up on it.

> this code which it appears you would support writing
> 
>if (flags & os.R_OK) is os.R_OK:

I do not.

You compare a module.CONSTANT to the result of an expression (flags & os.R_OK). 
Expressions are not names bound to objects, the identity of which is what I'm 
talking about. This example does not apply. Also, the identity check in my 
example has a value equality fallback. Yours doesn't, so it really does not 
apply.

 > (I think you should give it up... you're trying to push a rope.)

I'm not pushing anything. I just don't like being misquoted.

Cheers,
Joel Hedlund
-- 
http://mail.python.org/mailman/listinfo/python-list


FTP not Returning (Python on Series 60 Nokia)

2006-03-28 Thread mbukhin
I'm using the ftp library (layer on top of sockets) to transfer files
from  a series 60 to an ftp site.  everything works fine, the whole
file gets uploaded but the command never returns!  so
i call:

ftp.storbinary('STOR ' + filename,F,1024) # store the image

which does this:

 def storbinary(self, cmd, fp, blocksize=8192):
 '''Store a file in binary mode.'''
 self.voidcmd('TYPE I')
 conn = self.transfercmd(cmd)
 while 1:
 buf = fp.read(blocksize)
 if not buf: break
 conn.send(buf)
 conn.close()
 return self.voidresp()

and the 'while 1' never stops.  That's my guess anyway.  When I run
this in interactive bluetooth mode the storbinary command just hangs
(though the file ends up on the server).  i've tried a bunch of
different  things, counters, comparisons, everything.  there's a signal
library in python but i don't think it's supported in mobile devices.

any suggestions?

thanks!

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


Re: doctest, unittest, or if __name__='__main__'

2006-03-28 Thread Fredrik Lundh
Christoph Zwerschke wrote:

> > Is this 'consensus opinion' or mainly your own opinion?
>
> It is just a consequence from the fact that unittest is actually a port
> from JUnit (Java) to Python, i.e. a consequence of trying to emulate a
> standard framework that many programmers are already familiar with,
> which is essentially not a bad idea. However, if you try to counterfeit
> Java programming, your code won't be effective or elegant in Python.

comparing unittest to py.test (which is from the "almost too clever"
school of pythonic engineering) might be illustrative:

http://ianbicking.org/docs/pytest-presentation/pytest-slides.html

(see the "why not unittest" slide for a list of issues with unittest)

> > Is there a summary somewhere (in addition to the Zen of Python thingy)
> > of what kinds of things are 'pythonic' and why they are considered so?
> > I see it referred to a lot, and am starting to get a feel for it in
> > some areas but not others.
>
> It's probably never been listed completely (and it also changes slowly
> as the language evolves).

it cannot be defined, per definition.  a good approxmation is "pencil-like
qualities".





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


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

2006-03-28 Thread Ron Adam
Paul McGuire wrote:
> "Paul Rubin"  wrote in message
> news:[EMAIL PROTECTED]

> To my mind, the *meaning* of all() is that every element in the list asserts
> True.  But this is with an initial assumption that all() is False, unless I
> test every value and find them to be True.  Since I assume False to begin
> with, I get no values in the list to contradict the assumption, and so
> all([]) returns False.

Looking at in a different way...  If we consider also having a function 
  none() (for comparison), would it be consistent with all()?

def none(S):
for x in S:
if x: return False
return True


any([]) -> False

none([])  -> True(same as 'not any(S)')

all([])  ->  True ? False


I think I agree that all() should have an initial presumption of being 
False.


Looking at it in yet another way...  (yes, not as efficient)

def all(S):
S_ = [x for x in S if x]
return S_ == S

def any(S):
S_ = [x for x in S if x]
return S_ != []

def none(S):
S_ = [x for x in S if x]
return S_ == []


In this view and empty set can be True for all().  Is it posible 
'all([])'  is undefined?  Here, none() and all() return contradicting 
values.  So maybe the correct version may be...

def all(S):
if S == []: return False
for x in S:
if x return True
return False

I think a few valid actual use case examples could clear it up.  What 
makes the most sense?

Cheers,
Ron

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


Re: web

2006-03-28 Thread Tim Roberts
[EMAIL PROTECTED] wrote:
>
>Hello, 2ExtremeStudios.com would like to offer you a great deal on a
>brand new website for your business.
>We invite you to visit www.2ExtremeStupids.com, we offer business
>information site design and
>e-store integration, as well as other services.
>
>Thanks for your time,
>Daniel N.
>Phone. 1.416.834.1592
>e-mail. [EMAIL PROTECTED]
>url. http://2ExtremeStupids.com

Mmm, yes, spamming the technical newsgroups is a GREAT way to convince the
world that you are reliable, trustworthy, and knowledgable.

Not.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 1.090516455488E9 / 1000000.000 ???

2006-03-28 Thread Tim Roberts
"Math" <[EMAIL PROTECTED]> wrote:
>
>Thanks  this does the job
>And yes,  I really need this accuracy..

Then you need to understand that you don't really HAVE this accuracy.  You
are fooling yourself.  1090.516455488 cannot be represented exactly in
binary, just like 1/3 cannot be represented exactly in decimal.  Further,
the more arithmetic you do, the less precise is your result.

Floating point is a very tricky world of approximation.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2006-03-28 Thread Sybren Stuvel
Paul McGuire enlightened us with:
>> That goes against the usual meaning of "all" in, say, mathematical
>> logic.
>>
>> Usually, "for all X in S, PRED(x) is true" means: there does not
>> exist X in S so that PRED(x) is false.
>>
> How do you get this "usually" stuff?

>From its mathematical definition.

> I would agree that this is usually implemented as a short-circuited
> loop through the list, that breaks out at the first False value.

Implementation is irrelevant when it comes to the definition of a
mathematical operator.

> But I would not be quick to equate "commonality of implementation"
> with "meaning".

Which is good.

> Perhaps we should consult a more formal mathematical resource for
> this.

In mathematics, 'for all x in A, f(x) is True' is true when A is
empty. You can either look it up on trust someone who studied
mathematics (me) on it.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2006-03-28 Thread Paul Rubin
"Paul McGuire" <[EMAIL PROTECTED]> writes:
> > Usually, "for all X in S, PRED(x) is true" means:
> > there does not exist X in S so that PRED(x) is false.
> >
> How do you get this "usually" stuff?  I would agree that this is usually
> implemented as a short-circuited loop through the list, that breaks out at
> the first False value.  But I would not be quick to equate "commonality of
> implementation" with "meaning".

See :

Generally, then, the negation of a propositional function's universal
quantification is an existential quantification of that propositional
function's negation; symbolically,

\lnot\ \forall{x}{\in}\mathbf{X}\, P(x) \equiv\
\exists{x}{\in}\mathbf{X}\, \lnot\ P(x)
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2006-03-28 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote

> Fredrik Lundh wrote:
> > [EMAIL PROTECTED] wrote:
> >
> > > The OP points out an ambiguity in the docs, and as usual,
> > > gets told he can't read, etc.  How typical.
> >
> > where did anyone tell the OP that he can't read?
>
>   "it could be that the tutorial author expected you
>   to read chapter 8 before you read chapter 9,..."

What makes you so sure that wasn't a statement about the tutorial ?

>   "...because some random guy on a newsgroup read
>   the tutorial backwards..."

Does the word "context" mean anything to you?  or the word "de-
precation", that was used multiple times by the OP ?  Or the phrase
"changing the language", that you cut out from that quote.

> I don't want to, and probably couldn't

That's pretty obvious.

> write a tutorial as good as what is already there.  But what I can
> do is report problems I find when using it, and make suggestions
> about how to avoid those problems.

There's no shortage of ideas -- nor people who can write a tutorial
that's better than the current one (which is far from optimal, mostly
thanks to a zillion peephole edits over the years).  There's a shortage
of volunteer time, though.  That's why the "I'm just the idea guy,
someone else will have to provide the hundreds of hours required
to implement my idea" arguments are so offensively meaningless.

Come up with an idea that *reduces* the overall work needed to write
and maintain a good manual, and people might start listening to what
you have to say.

Or come up with some money.  If you can fund a technical writer for
one year, there are lots of things that could be done.

> But the perception I get here, from responses like yours,
> is that such suggestions are unwelcome, and unlikely
> to be acted upon.  I gather corrections of factual
> errors are welcome, but stylistic, or organizational
> ones are not.  And the latter kind of changes, applied
> extensively to all the docs, are what will make a big
> improvement.  Difficult at best, but absolutely impossible
> if you and the other powers-that-be are happy with
> the status-quo.

The problem with people like you is that you are completely ignoring
all the hard work done by the people who build the free stuff that
anonymous cowards like you like to complain about.

Luckily, most people are not like you.  If they were, nothing would
ever happen.





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


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

2006-03-28 Thread Steve R. Hastings
Thank you very much for explaining this.  And so thoroughly!

Of course I withdraw all objections.  :-)
-- 
Steve R. Hastings"Vita est"
[EMAIL PROTECTED]http://www.blarg.net/~steveha

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


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

2006-03-28 Thread Paul McGuire
"Steve R. Hastings" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> So, Python 2.5 will have new any() and all() functions.
> http://www.python.org/dev/peps/pep-0356/
>
>
> any(seq) returns True if any value in seq evaluates true, False otherwise.
>
> all(seq) returns True if all values in seq evaluate true, False otherwise.
>
> I have a question: what should these functions return when seq is an empty
> list?
>
Here is my attempt at a more formal approach to this question, rather than
just using our intuition.  Unfortunately, following this process proves my
earlier post to be wrong, but, oh well...

Consider two sets A and B where A+B is the union of the two sets.

if any(A+B) = True -> any(A) or any(B) = True
but we cannot assert either any(A)=True or any(B)=True.

if any(A+B) = False -> any(A) = False and any(B) = False.


if all(A+B) = True -> all(A)=True and all(B)=True
if all(A+B) = False -> all(A)=False or all(B)=False
but we cannot assert either all(A)=False or all(B)=False.


Now instead of B, lets add the empty set 0 to A.  We want to come up logic
such that adding the empty set does not change the values of all() or any(),
since A+0=A.

any(A+0) = any(A) or any(0)

any(0) must be False, so that if any(A) is True, any(A+0) is True, and if
any(A) is False, any(A+0) is False.

all(A+0) = all(A) and all(0)

if all(A) is True, all(A+0) is True.
Therefore, all(0) is True.

-- Paul


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


Re: Nevow LivePage tutorial

2006-03-28 Thread Mir Nazim

Tim Parkin wrote:
> Mir Nazim wrote:
> > I really appriciate the help a lot, the but the problems is that i have
> > already real those. What i was looking for was some kind of detailed
> > tutorial, that explains the basic ideas about live page and
> > formhandling etc.
> > (my be it the time some nevow know guy got onto it)
> What are you trying to implement.. it may be that you don't need
> livepage at all.. Is it just some javascript to enhance a form field?
> Tim Parkin

you are right, if it was just a some java script to enhance some for
functionality. But my needs are much more.
I have implemented a School management system for a few school in my
area. Currently it id implemented in PHP. Now they have asked my to
redesign it using AJAX. According to thier specs a lot of AJAX will be
put in to it. Not only this the scope has broadnd a lot. I have to
develop integrated accounting and groupware/collaboration functionality
to it.

Now as we know python is much better language than php. I want to do it
in python in order to keep it maintainable over the period of time. So
thoght Nevow will be good for it. I have understod the basics from the
docs that come with nevow and coded a few basic pages as well. But
these docs do not talk about LivePage and form handling. I did no get
any thing from google either. I even looked at the examples. but could
no understand beyond very very basic things. Things like how to
establish as connection between client side JS and server-side python,
how to notify and how does it take place etc. Most important how much
what sort of JS is I need to put on clien sde and how much server side.

These are few things i would like to know.

So can any one help me, please. It will be OK if some could give me
some code examples with explaination like how to establish a
connection, how to ask for data from serverside etc.

Thanks

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


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

2006-03-28 Thread Ben Finney
"Steve R. Hastings" <[EMAIL PROTECTED]> writes:

> So, Python 2.5 will have new any() and all() functions.
> http://www.python.org/dev/peps/pep-0356/

And there was much rejoicing.

> any(seq) returns True if any value in seq evaluates true, False otherwise.

Yep.

> all(seq) returns True if all values in seq evaluate true, False otherwise.

Not quite how I'd phrase it. I prefer, for symmetry with 'any':

all(seq) returns False if any value in seq evaluates false, True otherwise.

> I have a question: what should these functions return when seq is an
> empty list?
>
>
>
> Here is Guido's original article where he suggested any() and all():
> http://www.artima.com/weblogs/viewpost.jsp?thread=98196
>
> He offered this sample code for the semantics of any() and all():
>
> def any(S):
> for x in S:
> if x:
> return True
> return False
>
> def all(S):
> for x in S:
> if not x:
> return False
> return True

I love the symmetry of these semantics, find them quite intuitive, and
therefore disagree with your interpretation of 'all()'.

> I'm completely on board with the semantics for any().  But all() bothers
> me.  If all() receives an empty list, it will return True, and I don't
> like that.  To me, all() should be a more restrictive function than any(),
> and it bothers me to see a case where any() returns False but all()
> returns True.

-1.

You may as well argue that "any() should be a more restrictive
function than all(), and it bothers me to see a case where all()
returns False but any() returns True."


It seems clear to me that an empty argument list fails a check for
"any True?", because that's the same as a check for "all False?". The
only reasonable alternative would be a special case for an empty
argument list, and that's too ugly.

It seems clear to me that an empty argument list passes a check for
"all True?", because that's the same as a check for "any False?". The
only reasonable alternative would be a special case for an empty
argument list, and that's too ugly.

To imagine that one of these "should be a more restrictive function"
would belie their simple, elegant, and (to me) obvious definitions. I
disagree with your interpretation.

-- 
 \"My house is made out of balsa wood, so when I want to scare |
  `\ the neighborhood kids I lift it over my head and tell them to |
_o__)  get out of my yard or I'll throw it at them."  -- Steven Wright |
Ben Finney

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


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

2006-03-28 Thread Paul McGuire
"Paul Rubin"  wrote in message
news:[EMAIL PROTECTED]
> "Steve R. Hastings" <[EMAIL PROTECTED]> writes:
> > In the all() example, if there *are* no values in S, then none of the
> > values can be != 0, and IMHO all() should return False.
>
> That goes against the usual meaning of "all" in, say, mathematical logic.
>
> Usually, "for all X in S, PRED(x) is true" means:
> there does not exist X in S so that PRED(x) is false.
>
How do you get this "usually" stuff?  I would agree that this is usually
implemented as a short-circuited loop through the list, that breaks out at
the first False value.  But I would not be quick to equate "commonality of
implementation" with "meaning".

> So, all(empty sequence) should be true.
"should be"? Or "usually turns out to be"?

To my mind, the *meaning* of all() is that every element in the list asserts
True.  But this is with an initial assumption that all() is False, unless I
test every value and find them to be True.  Since I assume False to begin
with, I get no values in the list to contradict the assumption, and so
all([]) returns False.

It would seem that the resolution rests on which initial condition we
choose, False or True.  Perhaps we should consult a more formal mathematical
resource for this.

-- Paul
"If it was so, it might be; and if it were so, it would be; but as it isn't,
it ain't. That's logic."


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


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

2006-03-28 Thread Tim Peters
[Steve R. Hastings]
> So, Python 2.5 will have new any() and all() functions.
> http://www.python.org/dev/peps/pep-0356/
>
>
> any(seq) returns True if any value in seq evaluates true, False otherwise.
>
> all(seq) returns True if all values in seq evaluate true, False otherwise.
>
> I have a question: what should these functions return when seq is an empty
> list?

Here, from the current development trunk, is what they _do_ return:

Python 2.5a0 (trunk:43410M, Mar 28 2006, 16:42:49) ...
Type "help", "copyright", "credits" or "license" for more information.
>>> any([])
False
>>> all([])
True

> Here is Guido's original article where he suggested any() and all():
> http://www.artima.com/weblogs/viewpost.jsp?thread=98196
>
> He offered this sample code for the semantics of any() and all():
>
>
>
> def any(S):
> for x in S:
> if x:
> return True
> return False
>
> def all(S):
> for x in S:
> if not x:
> return False
> return True
>
> ...
>|
> I'm completely on board with the semantics for any().  But all() bothers
> me.  If all() receives an empty list, it will return True,

Yes.

> and I don't like that.

Tough ;-)

> To me, all() should be a more restrictive function than any(),
> and it bothers me to see a case where any() returns False but all()
> returns True.

There are deeper principles at work:  so that endcases work out as
smoothly as possible, a "reduction" function applied to an empty
collection always arranges to return the identity element for the
reduction operation.  This is the reason that sum([]) returns 0, for
example:  0 is the identity element for addition, meaning that x+0=x
for all x.

Other useful identities follow from this, and from the associativity
of most reduction operations.  For example, sum(seq) = sum(seq[:i]) +
sum(seq[i:]) for any i >= 0, even if i is such that one (or both!) of
the slices on the right-hand side is empty.  That wouldn't be true if
sum([]) were not 0, and arranging to make it true saves programmers
from having to deal with some otherwise special cases.

The reduction operation for any() is logical-or, and False is the
identity element for logical-or:   x logical-or False = x for all
Boolean x.

Likewise the reduction operation for all() is logical-and, and True is
the identity element for that:  x logical-and True = x for all Boolean
x.

Examples of other useful identities that follow from picking the
identity elements in the empty case, which hold even if `seq` is
empty:

any(seq) = not all(not x for x in seq)
all(seq) = not any(not x for x in seq)

> In the all() example, if there *are* no values in S, then none of the
> values can be != 0, and IMHO all() should return False.

That would break everything mentioned above.  Think of it another way:
 if all(seq) is false, shouldn't it be the case that you can point to
a specific element in seq that is false?  After all (pun intended
;-)), if it's not the case that all x in seq are true, it must be the
case that some x in seq is false.  But if seq is empty, there is no x
in seq that's either true or false, and in particular there's no x in
seq that's false.  Since we can't exhibit an x in seq such that x is
false, saying that all(seq) is false would be very surprising to you
on some other day ;-)

> Therefore, I propose that all() should work as if it were written this way:
>
> def all(S):
> ret_val = False
>
> for x in S:
> ret_val = True
> if not x:
> return False
>
> return ret_val
>
>
> Comments?

That won't happen, for three reasons:  several were given above; this
is also the convention used for universal and existential quantifiers
applied to empty sets in mathematical logic (and for much the same
reasons there); and it matches prior art in the ABC language (which is
one of Python's predecessors, and which had direct syntactic support
for universal and existential quantifiers in Boolean expressions).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No Cookie: how to implement session?

2006-03-28 Thread Paul Rubin
[EMAIL PROTECTED] (Alex Martelli) writes:
> Cookies aren't "tricks" -- they are THE standard, architected solution
> for session persistence in HTTP 1.1 -- people who disable them are
> saying they do not *WANT* persistent sessions... on their heads be it.

That so many people do this is partly the fault of browsers.  Until
recently, there was no way to configure most browsers to accept all
cookies but treat them as ephemeral (dispose of them when you close
the browser).  Your choices were:

  1) accept all cookies; non-ephemeral ones would persist on your hard disk
  2) accept only ephemeral cookies: ones marked non-ephemeral would be
 ignored
  3) ignore ALL cookies

Choice #1 enables invasive long-term user tracking that is not
necessary for mere session persistence.

Choice #2 stops the long-term tracking, but session cookies get
ignored if they have an expiration date (that makes them
non-ephemeral).  That stops most session cookies from working.  This
choice was available in some versions of Netscape Communicator but I
don't think MS Explorer had it.

Choice #3 stops sessions from working all the time.

What you really want is for your browser to accept all cookies
including persistent ones, but the cookie at the end of the session
regardless of the requested expiration date.  Firefox can do that and
it's the setting that I use.  I don't know if other browsers can do it yet.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Graphs from Python

2006-03-28 Thread Philippe Bouige
In article <[EMAIL PROTECTED]>, 
DurumDara wrote:
>Hi !
>
>I want to create graphs (edges, nodes) from python.

  NetworkX
https://networkx.lanl.gov/

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


Re: No Cookie: how to implement session?

2006-03-28 Thread Alex Martelli
Sullivan WxPyQtKinter <[EMAIL PROTECTED]> wrote:

> As you said, There is no solution? I mean, tracing a real session
> without using tricks like hidden field and cookies in CGI script?

Cookies aren't "tricks" -- they are THE standard, architected solution
for session persistence in HTTP 1.1 -- people who disable them are
saying they do not *WANT* persistent sessions... on their heads be it.


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


Re: No Cookie: how to implement session?

2006-03-28 Thread Sullivan WxPyQtKinter
As you said, There is no solution? I mean, tracing a real session
without using tricks like hidden field and cookies in CGI script?
Dennis Lee Bieber 写道:

> On 28 Mar 2006 09:40:24 -0800, "Sullivan WxPyQtKinter"
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
>
> >  I do not want to use Cookies in my site since not all web browser
> > support it well and sometimes people close cookie functioning for
> > security reasons.
> >
>   Yes... And watch them flounder on sites that use cookies /for/ a
> form of security (ie, those sites that require logins...) Cookies can be
> set to expire, so the "session" can time-out... whereas...
>
> > I tried to add hidden field with a sessionID in every python CGI script
> > generated web pages, so everytime my client POST a request, the server
>
>   This would imply that a client could start a session today, and
> finally submit tomorrow... There's no real time-out capability unless
> you run some background timer thread for each "session ID"...
>
> > will retrieve the sessionID and decide if it is in the same session.
> > However, since python cgi do not have a function for redirecting to a
> > page, I use Location: url http head or 
>   Isn't redirect normally the responsibility of the web server
> /before/ invoking the CGI script itself? I'll concede I'm weak on that
> level of detail.
>
> > Really wish python would have session management or equivalent in
> > standard CGI module
>
>   The standard CGI module is only the lowest common base for dynamic
> web pages. The technology goes back decades, possibly even predating
> cookies. Look at the name: Common Gateway Interface... It's a building
> block responsible for getting submitted form data, as passed by the web
> server environment, and returning generated data -- the interface
> between an application and the web server. All else must be built on top
> of it -- hence separate modules for Cookie control, etc.
> --
>  > == <
>  >   [EMAIL PROTECTED]  | Wulfraed  Dennis Lee Bieber  KD6MOG <
>  >  [EMAIL PROTECTED] |   Bestiaria Support Staff   <
>  > == <
>  >   Home Page: <
>  >Overflow Page: <

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

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

2006-03-28 Thread Paul Rubin
"Steve R. Hastings" <[EMAIL PROTECTED]> writes:
> In the all() example, if there *are* no values in S, then none of the
> values can be != 0, and IMHO all() should return False.

That goes against the usual meaning of "all" in, say, mathematical logic.

Usually, "for all X in S, PRED(x) is true" means:
there does not exist X in S so that PRED(x) is false.

So, all(empty sequence) should be true.  
-- 
http://mail.python.org/mailman/listinfo/python-list


any() and all() on empty list?

2006-03-28 Thread Steve R. Hastings
So, Python 2.5 will have new any() and all() functions.
http://www.python.org/dev/peps/pep-0356/


any(seq) returns True if any value in seq evaluates true, False otherwise.

all(seq) returns True if all values in seq evaluate true, False otherwise.

I have a question: what should these functions return when seq is an empty
list?



Here is Guido's original article where he suggested any() and all():
http://www.artima.com/weblogs/viewpost.jsp?thread=98196

He offered this sample code for the semantics of any() and all():



def any(S):
for x in S:
if x:
return True
return False

def all(S):
for x in S:
if not x:
return False
return True



And he pointed out how nifty it is to combine generator functions with
these two new functions:


any(x > 42 for x in S) # True if any elements of S are > 42
all(x != 0 for x in S) # True if all elements if S are nonzero



I'm completely on board with the semantics for any().  But all() bothers
me.  If all() receives an empty list, it will return True, and I don't
like that.  To me, all() should be a more restrictive function than any(),
and it bothers me to see a case where any() returns False but all()
returns True.

In the all() example, if there *are* no values in S, then none of the
values can be != 0, and IMHO all() should return False.

Therefore, I propose that all() should work as if it were written this way:

def all(S):
ret_val = False

for x in S:
ret_val = True
if not x:
return False

return ret_val


Comments?

P.S. I searched with Google, and with Google Groups, trying to find
anyplace this might have been discussed before.  Apologies if this has
already been discussed and I missed it somehow.
-- 
Steve R. Hastings"Vita est"
[EMAIL PROTECTED]http://www.blarg.net/~steveha

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


Re: Looking for a language/framework

2006-03-28 Thread Nick Craig-Wood
walterbyrd <[EMAIL PROTECTED]> wrote:
>  Ideally, I would like to be able to develop a database driven web-app,
>  in much the same manner as I could develop an ms-access app. As much as
>  I dislike msft, I have to admit, an ms-access app can be put together
>  quickly, without any steep learning curve.

Look at django then.  It excels (IMHO) at this interfacing to an SQL
database.  Its admin interface is all you'll ever need for trusted
data entry, and you won't have to write any code at all for it.

We're currently converting a twisty mass of perl code which we can't
maintain any more into a django site, and we've been monstrously
impressed!

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String To Dict Problem

2006-03-28 Thread [EMAIL PROTECTED]
> def default(self, node, **kw):
> for child in node.getChildNodes():
> return self.visit(child, **kw)
>
> visitExpression = default

I'm not sure I grok this part.  It leads to unexpected results:
>>> safe_dict("""gid = 'FPS', type = 'Label', pos = [0, 20], text = 'FPS', text2
= 'more text without quotes', fmtline = "@VALUE @SIGNAL", signals =
[('FPS',None), ('FPS2', 'something')], danger = 2+2""")
{'text2': 'more text without quotes', 'danger': 2, 'fmtline': '@VALUE
@SIGNAL', 'text': 'FPS', 'pos': [0, 20], 'signals': [('FPS', None),
('FPS2', 'something')], 'gid': 'FPS', 'type': 'Label'}
>>> safe_dict("""gid = 'FPS', type = 'Label', pos = [0, 20], text = 'FPS', text2
= 'more text without quotes', fmtline = "@VALUE @SIGNAL", signals =
[('FPS',None), ('FPS2', 'something')], danger = foo()""")
{'text2': 'more text without quotes', 'danger': None, 'fmtline':
'@VALUE @SIGNAL', 'text': 'FPS', 'pos': [0, 20], 'signals': [('FPS',
None), ('FPS2', 'something')], 'gid': 'FPS', 'type': 'Label'}

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


Weekly Python Patch/Bug Summary

2006-03-28 Thread Kurt B. Kaiser
Patch / Bug Summary
___

Patches :  389 open ( -3) /  3117 closed (+23) /  3506 total (+20)
Bugs:  901 open ( -6) /  5687 closed (+41) /  6588 total (+35)
RFE :  214 open ( +1) /   206 closed ( +4) /   420 total ( +5)

New / Reopened Patches
__

Minimalist fix for bug 1446847  (2006-03-17)
CLOSED http://python.org/sf/1452332  opened by  Nick Coghlan

N-d array interface for array object  (2006-03-17)
   http://python.org/sf/1452906  opened by  Alexander Belopolsky

IDNA codec simplification  (2006-03-18)
   http://python.org/sf/1453235  opened by  Walter Dörwald

popen2 new parameter and setpgid  (2006-03-20)
CLOSED http://python.org/sf/1454425  opened by  Oskar Anderö

2 Tools for easy inter-thread communication->Queue,threading  (2006-03-20)
   http://python.org/sf/1454452  opened by  kxroberto

Make thread stack size runtime tunable  (2006-03-20)
   http://python.org/sf/1454481  opened by  Andrew I MacIntyre

patch for SIGSEGV in arraymodule.c  (2006-03-20)
   http://python.org/sf/1454485  reopened by  tbmetin

patch for SIGSEGV in arraymodule.c  (2006-03-20)
   http://python.org/sf/1454485  opened by  Baris Metin

Use dlopen() to load extensions on Darwin, where possible  (2006-03-20)
   http://python.org/sf/1454844  opened by  Zach Pincus

patch for mbcs codecs  (2006-03-22)
   http://python.org/sf/1455898  opened by  ocean-city

timestamp() method for datetime objects  (2006-03-23)
CLOSED http://python.org/sf/1457227  opened by  Chris AtLee

Support different GPG keys in upload --sign  (2006-03-23)
   http://python.org/sf/1457316  opened by  Stefan Behnel

patch for building trunk with VC6  (2006-03-24)
   http://python.org/sf/1457736  opened by  ocean-city

floor division  (2006-03-25)
CLOSED http://python.org/sf/1458419  opened by  Andy

Improved PySet C API  (2006-03-25)
CLOSED http://python.org/sf/1458476  opened by  Barry A. Warsaw

Mutable Iterators PEP  (2006-03-26)
   http://python.org/sf/1459011  opened by  Adam DePrince

Install PKG-INFO with packages  (2006-03-27)
   http://python.org/sf/1459476  opened by  Phillip J. Eby

Add docs for zlib.decompressobj.flush optional param  (2006-03-27)
CLOSED http://python.org/sf/1459630  opened by  Chris AtLee

Update docs for zlib.decompressobj.flush()  (2006-03-27)
   http://python.org/sf/1459631  opened by  Chris AtLee

convenient Message.as_string to use mangle_from_=unixfrom ?  (2006-03-28)
   http://python.org/sf/1459867  opened by  kxroberto

Patches Closed
__

PEP 338 implementation  (2006-02-11)
   http://python.org/sf/1429601  closed by  ncoghlan

patch for 1441408  compiler fails to spot extended slice  (2006-03-10)
   http://python.org/sf/1446847  closed by  ncoghlan

Minimalist fix for bug 1441408  (2006-03-17)
   http://python.org/sf/1452332  closed by  ncoghlan

PEP 338 documentation  (2006-02-11)
   http://python.org/sf/1429605  closed by  ncoghlan

error checking after PyXXX_New  (2006-03-08)
   http://python.org/sf/1445505  closed by  gbrandl

audioop - alaw encoding/decoding added, code updated  (2005-07-02)
   http://python.org/sf/1231053  closed by  anthonybaxter

Method for cell objects to access contents  (2005-03-25)
   http://python.org/sf/1170323  closed by  gbrandl

Incremental codecs for CJKCodecs  (2006-03-05)
   http://python.org/sf/1443155  closed by  perky

A wait4() implementation  (2005-09-30)
   http://python.org/sf/1309579  closed by  nnorwitz

Make itertools.tee participate in GC  (2006-03-06)
   http://python.org/sf/1444398  closed by  twouters

more leaky, leaky  (2006-03-07)
   http://python.org/sf/1445431  closed by  nnorwitz

Some fixes for the binary distribution builder  (2005-12-14)
   http://python.org/sf/1380777  closed by  ronaldoussoren

popen2 new parameter and setpgid  (2006-03-20)
   http://python.org/sf/1454425  closed by  oskar_andero

CALL_ATTR opcode  (2003-03-26)
   http://python.org/sf/709744  closed by  twouters

FreeBSD is system scope threads capable  (2006-01-04)
   http://python.org/sf/1396919  closed by  perky

timestamp() method for datetime objects  (2006-03-23)
   http://python.org/sf/1457227  closed by  gvanrossum

Add method to function objects to simplify decoration  (2005-03-12)
   http://python.org/sf/1161819  closed by  ncoghlan

Simplify using Queues with consumer threads  (2006-03-21)
   http://python.org/sf/1455676  closed by  rhettinger

floor division  (2006-03-25)
   http://python.org/sf/1458419  closed by  nnorwitz

Improved PySet C API  (2006-03-25)
   http://python.org/sf/1458476  closed by  gvanrossum

Add docs for zlib.decompressobj.flush optional param  (2006-03-27)
   http://python.org/sf/1459630  closed by  gbrandl

New / Reopened Bugs
___

xmlrpclib.py problem solved  (2006-03-17)
CLOSED http://python.org/sf/1452174  opened by  varun bhansaly

htmllib doesn'

RE: ldap usage

2006-03-28 Thread Jed Parsons
Title: RE: ldap usage







Looks like the top of my message got garbled

I was trying to say that I'm using ldap for the first time,
trying to write a script that authenticates a user against
our ldap server.  etc.  The rest came through.

Hope that makes more sense now :)

j

-Original Message-
From: [EMAIL PROTECTED] on behalf of Jed Parsons
Sent: Tue 3/28/2006 5:55 PM
To: python-list@python.org
Subject: ldap usage


Hi,

  authenticates a user against our ldap server.: User types in name and
password, and module sees if name and password check out right with the
ldap server.

I see that it's pretty straightforward to do this with:

 import ldap
 l = ldap.open('our.ldap.server')
 try:
 l.bind_s(username, password, ldap.AUTH_SIMPLE)
 authenticated = True
 except:
    authenticated = False

But this uses the plaintext of the user's password.  Is there a proper
way to send a cryptographic hash to the ldap server?  Or do I have to
negotiate this through an ssl tunnel or something?

Thanks for any tips.  Cheers!
j

--
Jed Parsons   Industrial Light + Magic  (415) 746-2974
   
grep(do{for(ord){(!$_&&print"$s\n")||(($O+=(($_-1)%6+1)and
grep(vec($s,$O++,1)=1,1..int(($_-6*6-1)/6}},(split(//,
"++,++2-27,280,481=1-7.1++2,800+++2,8310/1+4131+1++2,80\0.  What!?")));
--
http://mail.python.org/mailman/listinfo/python-list






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

Re: sending ctrl C to a process

2006-03-28 Thread Grant Edwards
On 2006-03-29, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> hi
> thanks for the reply.

Please properly quote the article to which you're replying so
that we can tell who/what your talking to/about.

> Actually, i should clarify what i am doing. the program's
> output will be displayed to a web browser using cgi, so there
> is no keyboard interrupt. The backend cgi script (python
> script) will have to send Ctrl-C to break the program. 

Actually, you don't want to send a Ctrl-C to the program. You
want to send a SIGINT signal to the process.  That's what the
tty line-discipline layer in the tty driver sends to processes
attached to a tty when the tty receives the interrupt character
(which defaults to Ctrl-C).

Sending signals to processes is done using os.kill()

  http://docs.python.org/lib/os-process.html

-- 
Grant Edwards   grante Yow!  How do I get HOME?
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sending ctrl C to a process

2006-03-28 Thread s99999999s2003
hi
thanks for the reply.Actually, i should clarify what i am doing.
the program's output will be displayed to a web browser using cgi, so
there is no
keyboard interrupt. The backend cgi script (python script) will have to
send Ctrl-C to break the program. 
thanks

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


SEEK_SET defined?

2006-03-28 Thread Roger Miller
I see that the posixfile module is deprecated.  Have the SEEK_SET, etc.
constants moved somewhere else, or do I need to define them myself?

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


Re: python ctype question about "access violation reading location 0x5a5a5a5a"

2006-03-28 Thread Chris Mellon
On 3/28/06, Yanping Zhang <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> I need to use this C routine in python and there is a void pointer parameter 
> in it:
> (this routine was written by someone else):
>
> myfunc(int a, (void *)userdata, bool b)
>
> I saw someone in his C++ wrapper used this routine in this way:
> myfunc(a, (void *)0x5a5a5a5a, b)
>
> In my python wrapper, I tried  to call it as the following and both failed:
> 1. myfunc(c_int(a), 0x5a5a5a5a, c_int(b))
>got error "access voilation reading from 0x5a5a5a5a"
> 2.
>   data = 0x5a5a5a5a
>   mydata = c_void_p(data)
>   myfunc(c_int(a), mydata, c_int(b))
>   same error as in 1
>
> Can anyone know how to fix it? Thanks!
>

You are re-creating the C code correctly, the problem is that C code
you're working from is wrong (and whoever wrote it should be beaten).
Passing a constant like that as a pointer (that myfunc presumably does
something with) is something that just can't work.

> __
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sending ctrl C to a process

2006-03-28 Thread Felipe Almeida Lessa
Em Ter, 2006-03-28 às 18:14 -0800, [EMAIL PROTECTED] escreveu:
> It will need a Ctrl-C in order to break out of the program.
> I wish to run this program using python (either thru os.system() or
> some other subprocess modules) and how can i pass Ctrl-C to this
> program to terminate it in python? 

$ python2.4 && echo "  Python terminates!"
Python 2.4.2 (#2, Mar 27 2006, 21:07:39)
[GCC 4.0.3 (Debian 4.0.3-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> ^C
KeyboardInterrupt
>>> try:
... while 1:
... pass
... except KeyboardInterrupt:
... print "\nHey, why did you press Ctrl-C?!"
... except:
... print "\nStrange..."
...
^C
Hey, why did you press Ctrl-C?!
>>> import sys
>>> try:
... while 1:
... pass
... except KeyboardInterrupt:
... sys.exit(0)
...
^C
  Python terminates!
$

HTH,

-- 
Felipe.

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

Re: Problem with httplib and HEAD request

2006-03-28 Thread Mitch . Garnaat
For what it's worth, I made the following change to httplib.py and it
seems to have solved my problems:

c455
< if self.chunked:
---
> if self.chunked and self._method != 'HEAD':

I'm using Python 2.4.1 on MacOS.

Mitch

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


sending ctrl C to a program

2006-03-28 Thread s99999999s2003
hi
i have a program that works very similar to tail -f in Unix
It will need a Ctrl-C in order to break out of the program.
I wish to run this program using python (either thru os.system() or
some other subprocess modules) and how can i pass Ctrl-C to this
program to terminate it in python? 
thanks

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


sending ctrl C to a process

2006-03-28 Thread s99999999s2003
hi
i have a program that works very similar to tail -f in Unix
It will need a Ctrl-C in order to break out of the program.
I wish to run this program using python (either thru os.system() or
some other subprocess modules) and how can i pass Ctrl-C to this
program to terminate it in python? 
thanks

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


ldap usage

2006-03-28 Thread Jed Parsons

Hi,

  authenticates a user against our ldap server.: User types in name and 
password, and module sees if name and password check out right with the 
ldap server.

I see that it's pretty straightforward to do this with:

 import ldap
 l = ldap.open('our.ldap.server')
 try:
 l.bind_s(username, password, ldap.AUTH_SIMPLE)
 authenticated = True
 except:
authenticated = False

But this uses the plaintext of the user's password.  Is there a proper 
way to send a cryptographic hash to the ldap server?  Or do I have to 
negotiate this through an ssl tunnel or something?

Thanks for any tips.  Cheers!
j

-- 
Jed Parsons   Industrial Light + Magic  (415) 746-2974

grep(do{for(ord){(!$_&&print"$s\n")||(($O+=(($_-1)%6+1)and
grep(vec($s,$O++,1)=1,1..int(($_-6*6-1)/6}},(split(//,
"++,++2-27,280,481=1-7.1++2,800+++2,8310/1+4131+1++2,80\0.  What!?")));
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tips for this exercise?

2006-03-28 Thread Duncan Smith
John Salerno wrote:
> I'm working on another exercise now about generating random numbers for
> the lottery. What I want to do is write a function that picks 5 random
> numbers from 1-53 and returns them. Here's what I have so far:
> 
> numbers = range(1, 54)
> 
> def genNumbers():
> for x in range(5):
> fiveNumbers = []
> number = random.choice(numbers)
> numbers.remove(number)
> fiveNumbers = fiveNumbers.append(number)
> return fiveNumbers
> 
> Other than being sort of ugly, this also has the side effect of actually
> editing the original list, which I don't want since I will want to
> generate more than one set of numbers.
> 
> Is there a better way to extract a certain number of items from a list
> (so maybe I don't need the for loop)? Is a list even the right type to
> use, since it gets edited in place? Perhaps a set?


Another approach (of possibly academic interest, if that).

>>> import random
>>> def genNumbers(k, n, draws):
 rand = random.randint
 numbers = range(1, n+1)
 for i in xrange(draws):
  for j in range(k):
   rand_int = rand(j, n-1)
   numbers[j], numbers[rand_int] = numbers[rand_int], numbers[j]
  yield numbers[:k]


>>> n = genNumbers(5, 54, 3)
>>> list(n)
[[23, 11, 9, 53, 45], [54, 29, 36, 22, 46], [20, 8, 29, 43, 12]]
>>>

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


Re: Convert Word .doc to Acrobat .pdf files

2006-03-28 Thread Justin Ezequiel
"When you create a PostScript file you have to send the host fonts.
Please go to the printer properties, "Adboe PDF Settings" page and turn
OFF the option "Do not send fonts to Distiller".

kbperry,

sorry about that.
go to "Printers and Faxes"
go to properties for the "Adobe PDF" printer
go to the "General" tab, "Printing Preferences" button
"Adobe PDF Settings" tab
uncheck the "Do not send fonts..." box



rune,

>> "'!CreatePDFAndCloseDoc"

I had Adobe 6 once and recalled it had Word macros you could call.
However, when I installed Adobe 7, I could not find the macros.
Perhaps it has something to do with the naming.
Thanks for the post. Will check it out.

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


python ctype question about "access violation reading location 0x5a5a5a5a"

2006-03-28 Thread Yanping Zhang
Hi All,

I need to use this C routine in python and there is a void pointer parameter in 
it: 
(this routine was written by someone else):

myfunc(int a, (void *)userdata, bool b)

I saw someone in his C++ wrapper used this routine in this way:
myfunc(a, (void *)0x5a5a5a5a, b)

In my python wrapper, I tried  to call it as the following and both failed:
1. myfunc(c_int(a), 0x5a5a5a5a, c_int(b))
   got error "access voilation reading from 0x5a5a5a5a"
2. 
  data = 0x5a5a5a5a
  mydata = c_void_p(data)
  myfunc(c_int(a), mydata, c_int(b))
  same error as in 1

Can anyone know how to fix it? Thanks!

 

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2006-03-28 Thread Terry Reedy

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Fredrik Lundh wrote:
>> [EMAIL PROTECTED] wrote:
>> where did anyone tell the OP that he can't read?
>
>  "it could be that the tutorial author expected you
>  to read chapter 8 before you read chapter 9,..."

This actually acknowledges an ability to read ;-)
-- that just was not exercised sufficiently (in his opinion) ...

> as good as what is already there.  But what I can do is
> report problems I find when using it, and make suggestions
> about how to avoid those problems.  For example, the
> sentence in question,
>
>  "There are two new valid (semantic) forms for the
>  raise statement: "
>
> could be replaced with
>
>  "There are two other forms for the raise statement
>  in addition to the one described in chapter 8:"

That said, and without looking at the context in the doc, this looks like 
an improvement.

> or
>
>  "Two new forms for the raise statement were introduced
>  in Python verion 2.x:"

This is incorrect, I believe.

> depending on what the meaning of "new" is in the
> original sentence.  (I'm still not sure, but your post
> implies it is the former.)

I agree that the current text seems ambiguous.

> But the perception I get here, from responses like yours,
> is that such suggestions are unwelcome, and unlikely
> to be acted upon.

FL is not the main doc maintainer.  Even if you were to be correct about 
his views, premature generalization is the source of much error.

>  I gather corrections of factual
> errors are welcome, but stylistic, or organizational
> ones are not.  And the latter kind of changes, applied
> extensively to all the docs, are what will make a big
> improvement.  Difficult at best, but absolutely impossible
> if you and the other powers-that-be are happy with
> the status-quo.

If you wish to become a volunteer Python improver, let me know either here 
or privately and I will respond with a suggestion and an offer.

Terry Jan Reedy







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


Re: A SANE scanner backend written in Python?

2006-03-28 Thread Lonnie Princehouse
Recompile Python and SANE with debugging enabled, if you haven't
already. That should allow you to trace back to the source of the error
using gdb (or your favorite gdb front-end).  AFAIK there's no inherent
reason that embedding Python in a shared library wouldn't work.Did
you try compiling the outline of the shared library without the
PyInitialize call?  Is it possible that the segfault had nothing to do
with python?

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


Re: tips for this exercise?

2006-03-28 Thread John Salerno
Paul Rubin wrote:
> John Salerno <[EMAIL PROTECTED]> writes:
>> Is there a better way to extract a certain number of items from a list
>> (so maybe I don't need the for loop)? Is a list even the right type to
>> use, since it gets edited in place? Perhaps a set?
> 
> See the doc for random.sample.

Thanks, looks like just what I was needing!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pySerial: write in a blocking mode

2006-03-28 Thread Grant Edwards
On 2006-03-28, Alejandro <[EMAIL PROTECTED]> wrote:
> Hi:
>
> I'm using pySerial to talk to a RS232 to RS485 converter. In order to
> control the converter, I need to control the DTR line to enable/disable
> de RS485 driver. In particular, I need to :
>
> write a character to the serial port
> set the DTR line to level 1 _after_ the last bit of the character is
> send
>
> So I tried this (ser is the serial port object):
>
> ser.write(x)
> ser.setDTR(1)

ser.write(x)
ser.drainOutput()
ser.setDTR(1)

> The problem with this is that the ser.write function returns before the
> character is send, and thus, the DTR line is set too soon. (I checked
> this behaivour with an osciloscope).
>
> I thought that seting the writeTimeout parameter could help, but then I
> realized that the write function wait "up to this time", so it doesn't
> work.
>
> Then I tried waiting some time with time.sleep() after ser.write, but
> the shortest time for time.sleep is to big, and non deterministic, so I
> think this is not an option.

Linux is not a real-time operating system.  The
ser.drainOutput() call is going to have the same granularity
and non-determinism as time.sleep().

It sounds like you need a serial board that supports
half-duplex operation.

-- 
Grant Edwards   grante Yow!  Hand me a pair of
  at   leather pants and a CASIO
   visi.comkeyboard -- I'm living
   for today!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Difference between 'is' and '=='

2006-03-28 Thread Felipe Almeida Lessa
Em Ter, 2006-03-28 às 15:18 -0800, Ross Ridge escreveu:
[snip]
> Consider this example using the socket.IPPROTO_RAW constant:
> 
> >>> socket.getaddrinfo("localhost", None, socket.AF_INET, socket.SOCK_RAW, 
> >>> socket.IPPROTO_RAW)[0][2] is socket.IPPROTO_RAW
> False
> 
> >>> socket.getaddrinfo("localhost", None, socket.AF_INET, socket.SOCK_RAW, 
> >>> socket.IPPROTO_RAW)[0][2] == socket.IPPROTO_RAW
> True

Ok, you win. It's not safe to do "is" checks on these kinds of
constants.

-- 
Felipe.

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

Re: pySerial: write in a blocking mode

2006-03-28 Thread Alejandro

Peter Hansen wrote:
> Alejandro wrote:
> > I'm using pySerial to talk to a RS232 to RS485 converter. In order to
> > control the converter, I need to control the DTR line to enable/disable
> > de RS485 driver.
>
> This seems a little odd to me.  We've used several RS232-RS485
> converters without needing to do that.  Maybe a more sophisticated
> device would eliminate this need?

Yes. The device is very simple (I made it).

> What you're trying to do is a hard realtime operation, and unless it's
> directly supported you could be up against an impossible task using
> Windows.  (But it seems you already knew that. :-)

I know it can be difficult/impossible. By the way, I am coding in
Linux, but want my code to be portable between Windows and Linux(!).

I will rethink the whole issue. May be I will use the time.sleep
alternative, taking a good margin to manage the uncertainty of the
delay.

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


Re: Convert Word .doc to Acrobat .pdf files

2006-03-28 Thread Rune Strand

kbperry wrote:
> Questions:
> Does Acrobat Pro, have some way to interface with it command-line (I
> tried searching, but couldn't find anything)?  Is there any other good
> way to script word to pdf conversion?
>
> Note:  The word documents do contain images, and lots of stuff besides
> just text.

The Acrobat Distiller installs (or van install) a Word VBS macro which
allows Word to Save As .PDF. It's easy to call from Python:

doc = "somefile.doc"
import win32com.client

# Create COM-object
wordapp = win32com.client.gencache.EnsureDispatch("Word.Application")

wordapp.Documents.Open(doc)
wordapp.Run("'!CreatePDFAndCloseDoc")  # the name of the macro for
Acrobat 6.0
wordapp.ActiveDocument.Close()
wordapp.Quit()

You'll probably wrap this in more logic, but it works.

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


A SANE scanner backend written in Python?

2006-03-28 Thread dwelch
I've read many times on this newsgroup over the years that you can write 
"just about anything" in Python, except perhaps a full operating system 
(maybe even that...?). So, with this spirit in mind, I would like to try 
to write a SANE scanner backend that I need to write, in Python rather 
than C. This work is being done on Linux using Python 2.4.2.

If you are not familar with SANE, and the SANE API, it basically boils 
down to supplying a libsane-.so shared library 
that supports a basic C interface. Example sane API calls into a backend 
are: sane_init(), sane_open(), sane_start(), sane_read() and 
sane_cancel(). At runtime, a backend is loaded up and its C interface is 
called to determine what devices are supported by the backend, to set 
options, and to actually perform a scan.

Obviously, this is an example of embedding Python, albiet with a 
different end result. I have not found any examples in the wild that 
embed Python in a shared library (vs. a standalone executable).

My trials so far have been fruitless. To start with, I simply took an 
outline of a shared library that defined all the relevant SANE APIs, 
linked it with SANE and Python, and placed a PyInitialize() in the 
sane_init() function. This immediately results in a segmentation fault. 
I'm not sure how to proceed from here. How would a separate .py file be 
accessed in this way and how would I call "back" into Python code when a 
C API was called? Is there going to be a problem of maintaining "state" 
in Python between invocations of the C API?

I've also explored using Elmer for this task, but have not had luck so 
far. Its also not clear to me whether this tool is appropriate for this 
task.

So, what I'd be interested in knowing is whether this is a foolish 
venture, or if I just have the wrong approach.

Any thoughts would be appreciated.

Thanks,

-Don


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


Re: Difference between 'is' and '=='

2006-03-28 Thread Ross Ridge
Felipe Almeida Lessa wrote:
> That said, you can do thinks like:
> >>> import socket
> >>> a = socket.AF_UNIX
> >>> a is socket.AF_UNIX
> True
>
> That kind of constants can be used with "is". But if don't want to be
> prone to errors as I do, use "is" only when you really know for sure
> that you're dealing with singletons.

It's only safe to to compare address family values with socket.AF_UNIX
using "is", if small integers are guaranteed to be singletons, and
socket.AF_UNIX has one of those small values.  Otherwise, address
family values equal in value to socket.AF_UNIX can be generated using
different objects.  There's no requirement that the socket module or
anything else return values using the same object that the
socket.AF_UNIX constant uses.

Consider this example using the socket.IPPROTO_RAW constant:

>>> socket.getaddrinfo("localhost", None, socket.AF_INET, socket.SOCK_RAW, 
>>> socket.IPPROTO_RAW)[0][2] is socket.IPPROTO_RAW
False

>>> socket.getaddrinfo("localhost", None, socket.AF_INET, socket.SOCK_RAW, 
>>> socket.IPPROTO_RAW)[0][2] == socket.IPPROTO_RAW
True

Ross Ridge

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


Re: tips for this exercise?

2006-03-28 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> Generally, lottery numbers are selected from a range, e.g. one to forty.
> So rather than passing a global list, just pass the maximum number:
> 
> def getNumbers(maxn=40):
> L = range(1, maxn+1)
> random.shuffle(L)
> return L[0:5]

Why is everyone using shuffle?

Python 2.3.4 (#1, Feb  2 2005, 12:11:53) 
[GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import random
>>> random.sample(xrange(1,41), 5)
[24, 15, 9, 39, 19]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing csh scripts with python

2006-03-28 Thread Dave Benjamin
On Tue, 28 Mar 2006, David Hirschfield wrote:

> I need to be able to parse the script, modify some variable settings and 
> then write the script back out so that the only changes are the 
> variables I've modified (comments, ordering of statements, etc. must 
> remain the same).
>
> I looked at shlex, but I don't think it will do what I need.

What about regular expressions?

-- 
.:[ dave benjamin -( ramen/sp00 )- http://spoomusic.com/ ]:.
"one man's constant is another man's variable" - alan perlis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pySerial: write in a blocking mode

2006-03-28 Thread Peter Hansen
Alejandro wrote:
> I'm using pySerial to talk to a RS232 to RS485 converter. In order to
> control the converter, I need to control the DTR line to enable/disable
> de RS485 driver. 

This seems a little odd to me.  We've used several RS232-RS485 
converters without needing to do that.  Maybe a more sophisticated 
device would eliminate this need?

> Does anybody know how to do a ser.write() in a blocking way?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/flushfilebuffers.asp

(If that link is broken, it's the docs for the FlushFileBuffers routine. 
  This doesn't appear to be exposed in Pyserial, but you could probably 
subclass serial.Serial and add it yourself pretty easily.  The Pyserial 
source is quite accessible.)

Disclaimer: I haven't tried using that routine myself, but the docs 
imply it is supposed to do what you want.  Unfortunately, I doubt 
there's any particular guarantee about whether the data has only left 
the Windows buffers, or whether it has also left the transmit buffer of 
the UART *and* that the stop bit itself has even been transmitted.  What 
you're trying to do is a hard realtime operation, and unless it's 
directly supported you could be up against an impossible task using 
Windows.  (But it seems you already knew that. :-)

-Peter

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


Re: tips for this exercise?

2006-03-28 Thread Steven D'Aprano
On Tue, 28 Mar 2006 20:32:32 +, John Salerno wrote:

> Brian Quinlan wrote:
> 
>> I would just write the function like this:
>> 
>> def genNumbers():
>> shuffle_nums = numbers[:]# copy the list to preserve the orginal
>>  # order (if it matters)
>> random.shuffle(shuffle_nums) # shuffle the entire list
>> return shuffle_nums[:5]  # return the first 5 elements
> 
> Thanks. Interesting idea. I did consider copying it, but does that hurt 
> performance each time the function is called? I know it may not be 
> noticeable, but I don't like the idea of doing unnecessary work like 
> that, if it is in fact unnecessary.

Generally, lottery numbers are selected from a range, e.g. one to forty.
So rather than passing a global list, just pass the maximum number:

def getNumbers(maxn=40):
L = range(1, maxn+1)
random.shuffle(L)
return L[0:5]

This recreates the master list as needed. If you are running a lot of
trials, or if your maxn is huge (in the tens of millions perhaps) you
might want to optimize by re-using the list each time:

all_numbers = range(1, maxn+1)

def getNumbers(L):
random.shuffle(L)
return L[0:5]

getNumbers(all_numbers)

Notice that this has the side-effect of shuffling your master list. In
general, side-effects are to be avoided whenever possible, although this
one is fairly benign.

However, and this is important, consider this note from the random.shuffle
__doc__ string:
 
Note that for even rather small len(x), the total number of
permutations of x is larger than the period of most random number
generators; this implies that "most" permutations of a long
sequence can never be generated.

In other words, this is not a good technique for producing a fair lottery.
The results will be biased.

Here is a method that is less biased:

def genNumbers(maxn=40):
# Warning: untested
L = range(1, maxn+1)
chosen = []
for _ in range(5):
n = random.choice(L)
L.remove(n)
chosen.append(n)
return chosen

If you want to allow duplicates, you can simplify the code:

def genNumbersWithDuplicates(maxn=40):
# Warning: untested
L = range(1, maxn+1)
chosen = []
for _ in range(5):
chosen.append(random.choice(L))
return chosen


Hope this helps.


-- 
Steven.

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


Re: Obtaining the remote ip address

2006-03-28 Thread Peter Hansen
EP wrote:
> While on the subject of network identity, does anyone have a scheme to 
> get the MAC address of the end device?  I've never come up with a way to 
> do it, but I haven't had it proven to me that it is impossible (yet).

Which end?  I'll assume you mean _not_ the server end. :-)

The MAC address for the client end (i.e. the end you don't control) 
isn't going to be available to you unless it's local to your network. 
If that's the case, one option is parsing the output of the "arp" 
command as appropriate for your platform (note: this is inherently a 
platform-specific issue).

If the other end is not local, it's unclear what value the MAC address 
would have for you.  Maybe describing that will lead to some more 
effective solutions being suggested.

-Peter

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


Re: Command line option -Q (floor division)

2006-03-28 Thread Christoph Zwerschke
Just for the records, Anthony Baxter explained that this is by intent, 
because it would be still too disruptive a change. The testsuite does 
not even run completely with -Qnew yet. So it will be probably only 
changed with Python 3.0.

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


Re: Difference between 'is' and '=='

2006-03-28 Thread Steven D'Aprano
On Tue, 28 Mar 2006 12:12:52 +0200, Joel Hedlund wrote:

> I try to stay away from speed microoptimisations as much as possible since it 
> generally results in less readable code, which in turn often results in an 
> overall speed loss because code maintenance will be harder.

+1 QOTW


-- 
Steven.

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


Re: doctest, unittest, or if __name__='__main__'

2006-03-28 Thread Christoph Zwerschke
[EMAIL PROTECTED] wrote:
> Hi there Christopher, I was wondering if you (or anyone reading this )
> could quickly summarize the ways in which unittest is unpythonic, or
> point me to somewhere which discusses this.
> Is this 'consensus opinion' or mainly your own opinion?

It is just a consequence from the fact that unittest is actually a port 
from JUnit (Java) to Python, i.e. a consequence of trying to emulate a 
standard framework that many programmers are already familiar with, 
which is essentially not a bad idea. However, if you try to counterfeit 
Java programming, your code won't be effective or elegant in Python.

> Is there a summary somewhere (in addition to  the Zen of Python thingy)
> of what kinds of things are 'pythonic' and why they are considered so?
> I see it referred to a lot, and am starting to get a feel for it in
> some areas but not others.

It's probably never been listed completely (and it also changes slowly 
as the language evolves). Programming in an unpythonic way is like 
driving a nail with a screwdriver. Here are some more explanations:
http://faassen.n--tree.net/blog/view/weblog/2005/08/06/0
http://mail.python.org/pipermail/europython/2005-April/004975.html

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


Parsing csh scripts with python

2006-03-28 Thread David Hirschfield
Is there a module out there that would be able to parse a csh script and 
give me back a parse tree?

I need to be able to parse the script, modify some variable settings and 
then write the script back out so that the only changes are the 
variables I've modified (comments, ordering of statements, etc. must 
remain the same).

I looked at shlex, but I don't think it will do what I need.
Any suggestions would be appreciated,
-Dave

-- 
Presenting:
mediocre nebula.

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


Re: instantiate a class with a variable

2006-03-28 Thread John
Thanks for the help, this was exactly what I needed. Working Great
bruno at modulix wrote:
> John wrote:
> > Hi, is it possible to instantiate a class with a variable.
> >
> > example
> >
> > class foo:
> > def method(self):
> > pass
> >
> > x='foo'
> >
> > Can I use variable x value to create an instance of my class?
>
> You got examples using string 'foo', now if all you need is to store or
> pass around the class, just use it as any other object (yes, classes
> *are* objects):
>
> class Foo(object): pass
>
> x = Foo
>
> f = x()
> assert type(f) is Foo
>
>
> --
> 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: Multiplying sequences with floats

2006-03-28 Thread Caleb Hattingh
Christoph

I understand the explanation regarding the underlying math.floor()
call.   Were I using this functionality in my code,

int(a//b)* some_list

would not be something I consider a big deal.  However, I see what
you're saying: The multiplcation by list can only work with an int, and
you have an integer number, but unfortunatly with type float.  Well, I
guess that's life :)

Again, a small cast like that is not a problem for me, so I can't
really comment on this.

Keep well
Caleb

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


Re: CGI redirection: let us discuss it further

2006-03-28 Thread Sybren Stuvel
Sullivan WxPyQtKinter enlightened us with:
> Sorry I do not quite understand what is the difference between an
> internal redirection and an external one?

External:
- Browser requests URL A
- Server responds "Go to URL B"
- Browser requests URL B
- Server responds with contents of B
- Browser displays B

Internal:
- Browser requests URL A
- Server responds with contents of B
- Browser displays B

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CGI redirection: let us discuss it further

2006-03-28 Thread Sybren Stuvel
[EMAIL PROTECTED] enlightened us with:
> What's wrong with the redirection page?
>
> If there's really a necessary reason for not using an HTTP redirect
> (for example, needing to set a cookie, which doesn't work
> cross-browser on redirects), the best bet is a page containing a
> plain link and 

Re: Python plug-in

2006-03-28 Thread Jean-Paul Calderone
On Tue, 28 Mar 2006 22:42:46 +0200, toto <[EMAIL PROTECTED]> wrote:
>Hi,
>
>I'm trying to find some howto, tutorial in order to create a python program
>that will allow plug-in programming. I've found various tutos on how to
>write a plug-in for soft A or soft B but none telling me how to do it in my
>own programs. Do you have any bookmarks ??

Here's one way: 


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


Re: Multiplying sequences with floats

2006-03-28 Thread Caleb Hattingh
Hi Fredrik

Fair enough; I wasn't precise.  Upon further reflection, I actually
meant floor division, via the // operator.  In the following snippet:

>>> 4/2
2
>>> 4//2
2
>>> 4.0/2.0
2.0
>>> 4.0//2
2.0
>>> 4.0//2.0
2.0

We know the last two operations can only return what are effectively
integer numbers (or raise an error), but the type that gets returned
for a valid operation is a float.   Now, I'm not pretending to know
much about this stuff, just pointing out that that behaviour is
interesting.Just like how MvL pointed out to me in a recent thread
that in certain cases .read().splitlines(True) is significantly faster
than .readlines() on some file objects: that's interesting.

I am sure there are good reasons for this, and I can't imagine that the
issue of return type didn't come up when discussions about the floor
division operator was discussed;  in fact, thinking about it a little
more, I suspect this operator is probably more likely to be used in a
sequence of floating-point operations anyway, for which the current
implementation saves a type conversion that might have been necessary
had it been made to return int to start with.

So regarding my previous statement:

>> I agree that integer division should return an integer,
>> because using the operator at all means you expect one.

I am not so sure now :)

By the way (regarding PIL), have you seen this site:
http://www.greyc.unicaen.fr/~dtschump/greycstoration/index.html

It is an open-source project implementing fancy methods for cleaning up
images and (my interest) resizing images with better clarity on
enlargements.  I had been working on a python implementation for this
kind of thing with heavy leaning on the PIL, but I saw this project on
the daily freshmeat newsletter, and so will probably use that code
instead.

regards
Caleb

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


Re: tips for this exercise?

2006-03-28 Thread Kent Johnson
John Salerno wrote:
> Brian Quinlan wrote:
> 
>>I would just write the function like this:
>>
>>def genNumbers():
>>shuffle_nums = numbers[:]# copy the list to preserve the orginal
>> # order (if it matters)
>>random.shuffle(shuffle_nums) # shuffle the entire list
>>return shuffle_nums[:5]  # return the first 5 elements
> 
> 
> Thanks. Interesting idea. I did consider copying it, but does that hurt 
> performance each time the function is called? I know it may not be 
> noticeable, but I don't like the idea of doing unnecessary work like 
> that, if it is in fact unnecessary.

Yes, it hurts performance. No, you won't notice it. It probably is 
unnecessary for your application, since you are just going to shuffle 
the list again for the next use.

BUT...worrying about performance at this level is generally a waste of 
your time. For a program that picks lottery numbers, performance would 
have to be truly awful before you even noticed. Don't optimize until you 
have identified a problem.

Python is pretty fast for most of the things you will want to do with it.

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


Re: Simple py script to calc folder sizes

2006-03-28 Thread Caleb Hattingh
Thanks John

I will use your code :)   30% improvement is not insignificant, and
that's what I was looking for.

I find the log function a little harder to read, but I guess that is a
limitation of me, not your code.

Caleb

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


pySerial: write in a blocking mode

2006-03-28 Thread Alejandro
Hi:

I'm using pySerial to talk to a RS232 to RS485 converter. In order to
control the converter, I need to control the DTR line to enable/disable
de RS485 driver. In particular, I need to :

write a character to the serial port
set the DTR line to level 1 _after_ the last bit of the character is
send

So I tried this (ser is the serial port object):

ser.write(x)
ser.setDTR(1)

The problem with this is that the ser.write function returns before the
character is send, and thus, the DTR line is set too soon. (I checked
this behaivour with an osciloscope).

I thought that seting the writeTimeout parameter could help, but then I
realized that the write function wait "up to this time", so it doesn't
work.

Then I tried waiting some time with time.sleep() after ser.write, but
the shortest time for time.sleep is to big, and non deterministic, so I
think this is not an option.

Does anybody know how to do a ser.write() in a blocking way?

Regards,
Alejandro.

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


Re: tips for this exercise?

2006-03-28 Thread Steve M
You have two lines inside the loop that ought to be outside the loop -
the initial assignment to fiveNumbers and the return statement. Also,
the line that appends new numbers to fiveNumbers is not quite correct -
the append() method modifies the list in place, rather than return a
new list.

Here's one that does what you seem to want. It exploits the fact that a
given number can't be in a set twice. It eliminates having to modify
and recreate the numbers list, but incurs the risk of calling choice()
more than five times; however each such extra call to choice is
increasingly improbable...

from random import choice
numbers = range(1,54)

def genNumbers():
fiveNumbers = set()
while len(fiveNumbers) < 5:
fiveNumbers.add(choice(numbers))
return list(fiveNumbers)

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


Python plug-in

2006-03-28 Thread toto
Hi,

I'm trying to find some howto, tutorial in order to create a python program
that will allow plug-in programming. I've found various tutos on how to
write a plug-in for soft A or soft B but none telling me how to do it in my
own programs. Do you have any bookmarks ??

Regards,

Laurent.


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


Re: Convert Word .doc to Acrobat .pdf files

2006-03-28 Thread kbperry
Justin,
While I was salivating when reading your post, it doesn't work for me,
but I am not sure why.

I keep getting an error:

Titled:  Adobe PDF
"When you create a PostScript file you have to send the host fonts.
Please go to the printer properties, "Adboe PDF Settings" page and turn
OFF the option "Do not send fonts to Distiller".

Keith
www.301labs.com

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


Re: tips for this exercise?

2006-03-28 Thread Paul Rubin
John Salerno <[EMAIL PROTECTED]> writes:
> Is there a better way to extract a certain number of items from a list
> (so maybe I don't need the for loop)? Is a list even the right type to
> use, since it gets edited in place? Perhaps a set?

See the doc for random.sample.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tips for this exercise?

2006-03-28 Thread Larry Bates
Not a lot wrong with your code except that your
return fiveNumbers will execute the first time
through the loop because it is indented inside
the loop.  Also, append does its work in place,
it doesn't return a new list.

You also might want to pass the maximum number
and return count, into the function and initialize
numbers list there.  That way you can call
genNumbers(54, 5) or genNumbers(103, 7) and get
differing length lists back from your function.

def genNumbers(maxnum, retcount):
numbers=range(1, maxnum)
for x in range(retcount):
retNumbers = []
number = random.choice(numbers)
numbers.remove(number)
retNumbers.append(number)

return retNumbers


-Larry Bates


John Salerno wrote:
> I'm working on another exercise now about generating random numbers for
> the lottery. What I want to do is write a function that picks 5 random
> numbers from 1-53 and returns them. Here's what I have so far:
> 
> numbers = range(1, 54)
> 
> def genNumbers():
> for x in range(5):
> fiveNumbers = []
> number = random.choice(numbers)
> numbers.remove(number)
> fiveNumbers = fiveNumbers.append(number)
> return fiveNumbers
> 
> Other than being sort of ugly, this also has the side effect of actually
> editing the original list, which I don't want since I will want to
> generate more than one set of numbers.
> 
> Is there a better way to extract a certain number of items from a list
> (so maybe I don't need the for loop)? Is a list even the right type to
> use, since it gets edited in place? Perhaps a set?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Perforce p4c.run("print" error - AttributeError: OutputBinary

2006-03-28 Thread kbperry
This seemed to fix my problem.

Keith

www.301labs.com

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


Re: tips for this exercise?

2006-03-28 Thread John Salerno
Brian Quinlan wrote:

> I would just write the function like this:
> 
> def genNumbers():
> shuffle_nums = numbers[:]# copy the list to preserve the orginal
>  # order (if it matters)
> random.shuffle(shuffle_nums) # shuffle the entire list
> return shuffle_nums[:5]  # return the first 5 elements

Thanks. Interesting idea. I did consider copying it, but does that hurt 
performance each time the function is called? I know it may not be 
noticeable, but I don't like the idea of doing unnecessary work like 
that, if it is in fact unnecessary.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Quick Question regarding Frames

2006-03-28 Thread Chris S
HI Dave,
Thanks for the reply.
I am a bit confused by this piece of code:
  class FrameB(wx.Frame):
  def __init__(self, frameA, ...):
  self.frameA = frameA

What is frameA in the __init__ definition?
Do I need to create something called frameA in order to pass it to that
__init__ function?

Presently I would call FrameB as
w2 = FrameB(None, -1,"")
w2.Show()

Where would I put the reference to frameA?

Thanks.

Chris

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


Re: Looking for a language/framework

2006-03-28 Thread Steve Juranich
[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.

Thanks much.
-- 
Steve Juranich
Tucson, AZ
USA

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


Re: tips for this exercise?

2006-03-28 Thread Brian Quinlan
John Salerno wrote:
> I'm working on another exercise now about generating random numbers for 
> the lottery. What I want to do is write a function that picks 5 random 
> numbers from 1-53 and returns them. Here's what I have so far:
> 
> numbers = range(1, 54)
> 
> def genNumbers():
>  for x in range(5):
>   fiveNumbers = []
>   number = random.choice(numbers)
>   numbers.remove(number)
>   fiveNumbers = fiveNumbers.append(number)
>   return fiveNumbers
> 
> Other than being sort of ugly, this also has the side effect of actually 
> editing the original list, which I don't want since I will want to 
> generate more than one set of numbers.
> 
> Is there a better way to extract a certain number of items from a list 
> (so maybe I don't need the for loop)? Is a list even the right type to 
> use, since it gets edited in place? Perhaps a set?

I would just write the function like this:

def genNumbers():
 shuffle_nums = numbers[:]# copy the list to preserve the orginal
  # order (if it matters)
 random.shuffle(shuffle_nums) # shuffle the entire list
 return shuffle_nums[:5]  # return the first 5 elements

Cheers,
Brian


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


Re: Redirect output

2006-03-28 Thread Donn Cave
In article <[EMAIL PROTECTED]>,
 "abcd" <[EMAIL PROTECTED]> wrote:
> I have a program which is written in C and interfaced with python via
> Swig.  However, the function I call prints stuff out to the console.  I
> would like to capture what it is printing out.  I tried:
> 
> [code]
> import MyCProg, sys
> 
> f = open("tmp.txt", "wb")
> sys.stdout = f
> MyCProg.getData()
> f.close()
> sys.stdout = sys.__stdout__
> 
> print open("tmp.txt", "rb").read()
> [/code]
> 
> However, it just prints the data to the screen.  I tried redirecting
> stderr as well.
> 
> other than modifying the C code and re-generating the interface via
> Swig, any ideas?  just asking before i have to do that.

As you probably surmised, C I/O doesn't notice when you've
swapped the stdout object in the Python sys module.

If that's what you're trying to do, redirect the output of
something like printf() or puts(), then you might look at
the os.dup2() function as a way to redirect unit 1.  Get
the new output unit from os.open() with os.O_CREAT plus whatever
other flags, or open the output file some other way that
creates a file object and use its fileno() function.  Flush
stdout before each dup2().

To revert back to the original stdout, you will want a
copy of that stream, which you can get with the os.dup()
function, prior to redirection.  All the left over file
descriptors can be closed afterwards.

I assume you're on a UNIX platform or something to that effect.

   Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem w/Tkinter on 2.5 (Panther)

2006-03-28 Thread w chun
i've built a Python 2.5a0 interpreter on my iBook using gcc 3.3-1666
using the tarball from last nite...

$ uname -a
Darwin myMac.local 7.9.0 Darwin Kernel Version 7.9.0: Wed Mar 30
20:11:17 PST 2005; root:xnu/xnu-517.12.7.obj~1/RELEASE_PPC  Power
Macintosh powerpc
$
$ python
Python 2.5a0 (trunk, Mar 28 2006, 02:53:21)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> ^D

it has a particular symptom with Tkinter where if i run the
interactive interpreter, "import Tkinter", etc., things work great...
i can bring up and create Tk objects which work as expected using
XDarwin 1.3.0/XFree86 4.4.0, BUT when i try to run anything as a
script, even the 1-liner: "import _tkinter", it bombs out with a Bus
Error.  here is the output in GDB:

$ gdb /usr/local/bin/python2.5
GNU gdb 5.3-20030128 (Apple version gdb-330.1) (Fri Jul 16 21:42:28 GMT 2004)
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "powerpc-apple-darwin".
Reading symbols for shared libraries .. done
(gdb) set args tk-test.py
(gdb) run
Starting program: /usr/local/bin/python2.5 tk-test.py
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done

Program received signal EXC_BAD_ACCESS, Could not access memory.
0x901c5118 in __CFStringCreateImmutableFunnel3 ()
(gdb)

has anyone else seen this error before?  the script (obviously) works
using earlier versions of Python.  i have Tcl/Tk 8.4 on my system and
have T{CL,K}_LIBRARY pointed at the right place(s) when i built my 2.5
interpreter.

thanks,
-wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
-- 
http://mail.python.org/mailman/listinfo/python-list


tips for this exercise?

2006-03-28 Thread John Salerno
I'm working on another exercise now about generating random numbers for 
the lottery. What I want to do is write a function that picks 5 random 
numbers from 1-53 and returns them. Here's what I have so far:

numbers = range(1, 54)

def genNumbers():
 for x in range(5):
fiveNumbers = []
number = random.choice(numbers)
numbers.remove(number)
fiveNumbers = fiveNumbers.append(number)
return fiveNumbers

Other than being sort of ugly, this also has the side effect of actually 
editing the original list, which I don't want since I will want to 
generate more than one set of numbers.

Is there a better way to extract a certain number of items from a list 
(so maybe I don't need the for loop)? Is a list even the right type to 
use, since it gets edited in place? Perhaps a set?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trying to use popen2() to communicate with C program

2006-03-28 Thread I. Myself
Dennis Lee Bieber wrote:
> On Tue, 28 Mar 2006 18:02:46 GMT, "I. Myself" <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
>
>   
>> The compile C program, commer.exe, writes a line of text to its stdout.  
>> The python program does not receive it; it never gets to print "Got here 
>> 2".   Commer.exe does begin execution.  Here's commer.c, but there 
>> appears to be no problem with it.  Commer.exe can be executed alone, and 
>> it behaves as expected.
>>
>> 
>   Try flushing stdout... Many C runtimes detect when stdout is not a
> console and go to a buffered output mode; without a flush, it may be
> holding data until a (disk) block is filled...
>   
That worked!  I put   fflush(stdout);   after the printf() statement, 
and that fixed it.

Thanks!

Mitchell Timin

I'm proud of http://ANNEvolve.sourceforge.net.  I'm currently working on a
major update of the SailChallenge package.  If you want to write software,
or articles, or do testing for ANNEvolve, let me know.

Humans may know that my email address is zenguy at shaw789 dot ca.
(Remove the 3-digit number.)


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


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

2006-03-28 Thread Georg Brandl
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.

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


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

2006-03-28 Thread rurpy
Fredrik Lundh wrote:
> [EMAIL PROTECTED] wrote:
>
> > The OP points out an ambiguity in the docs, and as usual,
> > gets told he can't read, etc.  How typical.
>
> where did anyone tell the OP that he can't read?

  "it could be that the tutorial author expected you
  to read chapter 8 before you read chapter 9,..."

  "...because some random guy on a newsgroup read
  the tutorial backwards..."

> it's pretty clear
> that you have trouble reading things without mixing them up with
> your own preconceptions, but we already knew that.111

> > Maybe if comments like this were encouraged and acted upon
>
> do you think your posts would look any different if we replaced you
> with a markov generator and fed it with your old posts ?
>
> if you want to contribute, contribute.  a new tutorial would be great.
> get to work!

I don't want to, and probably couldn't, write a tutorial
as good as what is already there.  But what I can do is
report problems I find when using it, and make suggestions
about how to avoid those problems.  For example, the
sentence in question,

  "There are two new valid (semantic) forms for the
  raise statement: "

could be replaced with

  "There are two other forms for the raise statement
  in addition to the one described in chapter 8:"

or

  "Two new forms for the raise statement were introduced
  in Python verion 2.x:"

depending on what the meaning of "new" is in the
original sentence.  (I'm still not sure, but your post
implies it is the former.)

But the perception I get here, from responses like yours,
is that such suggestions are unwelcome, and unlikely
to be acted upon.  I gather corrections of factual
errors are welcome, but stylistic, or organizational
ones are not.  And the latter kind of changes, applied
extensively to all the docs, are what will make a big
improvement.  Difficult at best, but absolutely impossible
if you and the other powers-that-be are happy with 
the status-quo.

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


Re: No Cookie: how to implement session?

2006-03-28 Thread Paul Rubin
Dennis Lee Bieber <[EMAIL PROTECTED]> writes:
>   Yes... And watch them flounder on sites that use cookies /for/ a
> form of security (ie, those sites that require logins...) Cookies can be
> set to expire, so the "session" can time-out... whereas...

Sites should never rely on cookies timing out.  If there's any
security concern about session persistence and you don't want to track
the session timeout on the server, then encode an expiration time into
the cookie itself, and cryptographically authenticate the cookie.

> > I tried to add hidden field with a sessionID in every python CGI script
> > generated web pages, so everytime my client POST a request, the server

The trouble here is that it stops internal links (retrieved with GET
rather than POST) from working.  So normally what you're describing is
done with session ID's in the url (see amazon.com for example).  That,
too, isn't so great for security, especially for ecommerce sites,
since people tend to share url's with their friends.  E.g., they'll
post to Usenet or web bbs's, So-and-so is offering a great deal on
Python manuals, the url is  where "whatever"
includes the session ID.  Anyone clicking the url then ends up with
the same shopping cart as the person who posted it.

To OP: keep in mind also that anyone who disables cookies probably
also disables javascript, so relying on javascript as you described
for redirection doesn't work too well either.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trying to use popen2() to communicate with C program

2006-03-28 Thread I. Myself
Rene Pijlman wrote:
> I. Myself:
>   
>> I can't get this to work
>> 
>
> With what versions of what software on what platform?
>   
I'm glad you asked.  really!

Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32

Windows 2000.  AMD processor.  mingw compiler.

Mitchell Timin

-- 
I'm proud of http://ANNEvolve.sourceforge.net.  I'm currently working on a
major update of the SailChallenge package.  If you want to write software,
or articles, or do testing for ANNEvolve, let me know.

Humans may know that my email address is zenguy at shaw dot ca.


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


Re: Looking for a language/framework

2006-03-28 Thread [EMAIL PROTECTED]
As far as languages go, Python seems a far better choice than php or
perl based solutions.  I haven't tried Ruby - so I can't comment.

The Zope framework for python has been remarkably productive for me
both with and wtihout plone(CMF modules and a look and feel on top of
Zope).  The documentation is improving, but I can's say the situation
is good.  In truth, Zope knowledge is zope specific (at least I haven't
found it useful) and it was a bit of a transition coming from a j2ee
background.

I didn't find the learning curve to be very steep, but the path is
covered in brambles - haha.  Mostly due to the fast pace of
development.

btw, I am not a zope person or a plone, person - I  have however used
both solutions to develop  some pretty nifty sites faster than anything
else I have used.  Even through the "gettting to know you phase"  So
I'm a pretty big fan.  That being said, Zope is it's own universe of
ideas, and a lot of them seem "odd".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.

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


Re: problems with looping, i suppose

2006-03-28 Thread John Salerno
Sion Arrowsmith wrote:
> John Salerno  <[EMAIL PROTECTED]> wrote:
>> Does what I originally pasted in my message look incorrect? To me, it 
>> all seems indented properly.
> 
> Yes. Somewhere or other you've got your tabstop set to 4, and python
> treats literal tabs as being of equivalent indent to 8 spaces. As
> does my newsreader, so the problem was obvious:
> 
> while True:
> tries += 1
> ^ This was a tab (my cut&paste has turned it back into spaces)
> try:
> ^ This was a tab too.
> if guess == number:
>  This was eight spaces even before I cut&pasted.
> 

Ah, that makes sense now! Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dir_util.copy_tree call

2006-03-28 Thread Dave Mandelin
In IDLE, by default the working directory for the interactive prompt is
the working directory for IDLE itself. The working directory for
running a module is the directory the module is stored in. In your
script, use absolute paths or set the

--
Want to play tabletop RPGs over the internet?
Check out Koboldsoft RPZen:http://www.koboldsoft.comcwd.

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


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

2006-03-28 Thread Fabiano Sidler
I really wanted to learn the reason for this, nothing else! ;)

Greetings,
F. Sidler
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Quick Question regarding Frames

2006-03-28 Thread Dave Mandelin
Chris S wrote:
> Hello All,
> Just starting out with Python and wxPython.  I have two Frames, FrameA
> and FrameB.  FrameA opens FrameB when a button on FrameA is clicked.  I
> can get this.  Now I want a button on FrameB to update a control on
> FrameA.  I am having an issue with this.  Can anyone point me in the
> right direction?

I'm sure there are many ways of doing it, but I have always done it by
giving FrameB a reference to FrameA. Something like:

class FrameA(wx.Frame):
...
def OnSomethingClicked(self, event):
f = FrameB(self, ...)
f.Show()
event.Skip()

# This function does the updating of the control, to make things
# easier to maintain than having FrameB manipulate controls
# of FrameA directly.
def UpdateSomeControl(self, ...):
...

class FrameB(wx.Frame):
def __init__(self, frameA, ...):
self.frameA = frameA

def OnOtherThingClicked(self, event):
self.frameA.UpdateSomeControl(...)

--
Want to play tabletop RPGs over the internet?
Check out Koboldsoft RPZen:http://www.koboldsoft.com

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


Redirect output

2006-03-28 Thread abcd
I have a program which is written in C and interfaced with python via
Swig.  However, the function I call prints stuff out to the console.  I
would like to capture what it is printing out.  I tried:

[code]
import MyCProg, sys

f = open("tmp.txt", "wb")
sys.stdout = f
MyCProg.getData()
f.close()
sys.stdout = sys.__stdout__

print open("tmp.txt", "rb").read()
[/code]

However, it just prints the data to the screen.  I tried redirecting
stderr as well.

other than modifying the C code and re-generating the interface via
Swig, any ideas?  just asking before i have to do that.

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


Re: trying to use popen2() to communicate with C program

2006-03-28 Thread Rene Pijlman
I. Myself:
>I can't get this to work

With what versions of what software on what platform?

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


web

2006-03-28 Thread support
Hello, 2ExtremeStudios.com would like to offer you a great deal on a
brand new website for your business.
We invite you to visit www.2ExtremeStudios.com, we offer business
information site design and
e-store integration, as well as other services.


Thanks for your time,
Daniel N.
Phone. 1.416.834.1592
e-mail. [EMAIL PROTECTED]
url. http://2ExtremeStudios.com

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


Re: Looking for a language/framework

2006-03-28 Thread walterbyrd
> You can bet it'll be plain old cgi - possibly with an outdated Pyton version.

I think you are right. In practical terms, what does that mean? Will I
not be able to use modules? Will I not be able to use frameworks?

> Which frameworks have you looked at ?

django, turbogears, cheetah, cherrypy, . . .

By "looked at" I mean I read up on them, a little. I have not tried any
of them.

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


Re: CGI redirection: let us discuss it further

2006-03-28 Thread Sullivan WxPyQtKinter

> Just read the name of the server (os.environ['SERVER_NAME']) to work
> out what absolute URL to redirect to, whist still being portable.
>
> Here's some code I dug up that should also cope with non-default ports
> and SSL, if that's of any use:
>
>   ssl= os.environ.get('HTTPS', 'off') not in ('', 'off', 'false', 'no')
>   scheme= ['http', 'https'][ssl]
>   port= ['80', '443'][ssl]
>   host= os.environ.get('SERVER_NAME', 'localhost')
>   url= '%s://%s:%s' % (scheme, host, os.environ.get('SERVER_PORT',
> port))
>   if url.endswith(':'+port):
> server= server[:-(len(port)+1)]
>   url+= path
>
> (You *can* pass relative URLs back to the web server in a Location:
> header, but this should do an internal redirect inside the server,
> which may not be what you want.)


Sorry I do not quite understand what is the difference between an
internal redirection and an external one?
> 
> -- 
> And Clover
> mailto:[EMAIL PROTECTED]
> http://www.doxdesk.com/

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


dir_util.copy_tree call

2006-03-28 Thread Phoe6
Hi all.
I am using IDLE when I am on the python shell, I do:

>>>import os
>>>os.mkdir('newdir')
>>>from dirutils import dir_util
>>>#copy a big directory tree
>>>dir_util.copy_tree('big_directory','newdir')

This works properly, but I find a huge Resource Comsumption of my PC.
100% of CPU and Memory.

Now, when I put the same steps a python file and then Run Module:

copy_tree is failing with

Traceback (most recent call last):
  File "C:\builds\AutomateBuild\pyBuildAutomate.py", line 19, in ?
dir_util.copy_tree('Py4CliLinux','CliAuto-lin')
  File "C:\Python24\Lib\distutils\dir_util.py", line 172, in copy_tree
dry_run=dry_run))
  File "C:\Python24\Lib\distutils\dir_util.py", line 175, in copy_tree
preserve_times, update, dry_run=dry_run)
  File "C:\Python24\Lib\distutils\file_util.py", line 165, in copy_file
_copy_file_contents(src, dst)
  File "C:\Python24\Lib\distutils\file_util.py", line 47, in
_copy_file_contents
fdst = open(dst, 'wb')
IOError: [Errno 2] No such file or directory: 'big_directory/some/path'
# modified the actual names.

- What I am doing is trying to copy a directory tree to a another
directory tree.
- shutil.copytree does not help as it requires the dst directory to be
absent.

Any help?

Thanks!
Senthil


--
http://puggy.symonds.net/~senthil

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


[wxPython-users] ANNOUNCE: wxPython 2.6.3.0

2006-03-28 Thread Robin Dunn
Announcing
--

The 2.6.3.0 release of wxPython is now available for download at
http://wxpython.org/download.php.  There have been many enhancements
and fixes implemented in this version, many of which are listed
below and at http://wxpython.org/recentchanges.php.


What is wxPython?
-

wxPython is a GUI toolkit for the Python programming language. It
allows Python programmers to create programs with a robust, highly
functional graphical user interface, simply and easily. It is
implemented as a Python extension module that wraps the GUI components
of the popular wxWidgets cross platform library, which is written in
C++.

wxPython is a cross-platform toolkit. This means that the same program
will usually run on multiple platforms without modifications.
Currently supported platforms are 32-bit Microsoft Windows, most Linux
or other Unix-like systems using GTK2, and Mac OS X 10.2+, in most
cases the native widgets are used on each platform.


Changes in 2.6.3.0
--

Change the wx.ListCtrl InsertStringItem wrapper to use the form that
takes an imageIndex, and set the default to -1.  This ensures that on
wxMSW that if there is an image list but they don't specify an image,
the native control doesn't use one anyway.

wxMSW: wx.ListCtrl in report mode is now able to support images in
other columns besides the first one.  Simply pass an image index to
SetStringItem.  For virtual list controls you can specify the image to
use on the extra columns by overriding OnGetItemColumnImage in your
derived class.  It is passed the item number and the column number as
parameters, and the default version simply calls OnGetItemImage for
column zero, or returns -1 for other columns.

Switched to using SWIG 1.3.27 for generating the wrapper code.  There
are some small changes needed to SWIG to work around some bugs that
wxPython exposes, and to be able to generate code that matches that
which wxPython is using.  If you are building wxPython yourself and
need to modify any of the *.i files or to add your own, then you will
want to be sure to use a matching SWIG.  See wxPython/SWIG/README.txt
in the source tarball for details.

wx.Image.Copy now also copies the alpha channel.

wxMSW: Fixed problem in wx.TextCtrl where using SetValue and
wx.TE_RICH2 would cause the control to be shown if it was hidden.

wxMSW: Numpad special keys are now distinguished from normal keys in
key events.

wxMSW: Multiline notebook tab label change now resizes the control
correctly if an extra row is removed or added.

wxMSW: On XP fall back to unthemed wxNotebook if specified orientation
not available in the themed version.

Added wx.Toolbar.GetToolsCount.

Added wx.GridSizer.CalcRowsCols.

Added wx.OutputStream.LastWrite.

wxGTK: EVT_SET_CURSOR is now sent.

wxGTK: Fix RequestMore for idle events.

wxGTK: Implement user dashes for PS and GNOME printing.

wxGTK: Correct update region code. Don't always invalidate the whole
window upon resize. Reenable support for thewx.NO_FULL_REPAINT_ON_RESIZE
flag.  Also disable refreshing custom controls when focusing in and out.

wx.lib.pubsub: Publisher is now able to parse a dotted notation string
into a topic tuple.  For example: subscribing to "timer.clock.seconds"
is the same as subscribing to ("timer", "clock", "seconds").

Applied patch #1441370: lib.plot - allow passing in wx.Colour()

Added wx.CommandEvent.GetClientData.

Updated wxStyledTextCtrl to use version 1.67 of Scintilla.
NOTE: The STC_LEX_ASP and STC_LEX_PHP lexers have been deprecated,
you should use STC_LEX_HTML instead.

wxSTC: Implemented fix for SF Bug #1436503.  Delay the start of the
DnD operation in case the user just intended to click, not drag.

Updated the analogclock.py module to the new analogclock package from
E. A. Tacao.

Added the wx.lib.mixins.listctrl.CheckListCtrlMixin class from Bruce
Who, which makes it easy to put checkboxes on list control items.

Applied a patch from Christian Kristukat to wx.lib.plot that adds
scrollbars when the plot is zoomed in, and also the ability to grab a
zoomed plot and move it around with a mouse drag.

XRCed updated to allow wxMenuBar to be created inside a wxFrame.



-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


trying to use popen2() to communicate with C program

2006-03-28 Thread I. Myself
I can't get this to work:

# commer.py - to test communication with other process
from popen2 import popen2
(child_stdout, child_stdin) = popen2("commer.exe")
print "Got here 1"
line = child_stdout.readline()
print "Got here 2"
child_stdin.write(line)  
child_stdin.close
child_stdout.close

The compile C program, commer.exe, writes a line of text to its stdout.  
The python program does not receive it; it never gets to print "Got here 
2".   Commer.exe does begin execution.  Here's commer.c, but there 
appears to be no problem with it.  Commer.exe can be executed alone, and 
it behaves as expected.

/* commer.c - to test communication with other process */
/* this program will output a line of text to stdout, and then
   accept a line of input from stdin.
   It also creates a text file called out.txt and writes to it.
*/   
#include 
#include 
int main()  {
char line[] = "A line of text-";
FILE *outfile;
/* Record that execution began: */
outfile = fopen("out.txt", "w");
fprintf(outfile, "commer.exe starting up.\n");
fclose(outfile);
/* Output a line of text to stdout: */
printf("%s\n", line);
/* Record that that happened: */
outfile = fopen("out.txt", "a");
fprintf(outfile, "text line was output to stdout\n");
fclose(outfile);
/* Get a line of text from stdin: */
scanf("%s", line);
/* Record the result: */   
outfile = fopen("out.txt", "a");
fprintf(outfile,"%s was received.\n", line);   
fclose(outfile);
return 0;
}

Thanks,

Mitchell Timin

-- 
I'm proud of http://ANNEvolve.sourceforge.net.  I'm currently working on a
major update of the SailChallenge package.  If you want to write software,
or articles, or do testing for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the number)
zenguy at shaw789 dot ca.


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


Re: 1.090516455488E9 / 1000000.000 ???

2006-03-28 Thread Math
Thanks  this does the job
And yes,  I really need this accuracy..

Many Thanks
- Original Message - 
From: "Felipe Almeida Lessa" <[EMAIL PROTECTED]>
To: "Fredrik Lundh" <[EMAIL PROTECTED]>
Cc: 
Sent: Tuesday, March 28, 2006 6:00 PM
Subject: Re: 1.090516455488E9 / 100.000 ???


> Em Ter, 2006-03-28 às 16:59 +0200, Fredrik Lundh escreveu:
>> and consider using
>>
>> http://www.python.org/doc/lib/module-decimal.html
>>
>> instead.
>
> $ python2.4
> Python 2.4.2 (#2, Nov 20 2005, 17:04:48)
> [GCC 4.0.3 2005 (prerelease) (Debian 4.0.2-4)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
 from decimal import Decimal
 a = Decimal("1.090516455488E15")
 a
> Decimal("1.090516455488E+15")
 b = a / 100
 b
> Decimal("1090516455.488")
 str(b)
> '1090516455.488'
>
> *But*,
>
> $ python2.4 -mtimeit -s 'from decimal import Decimal; a =
> Decimal("1.090516455488E15")' 'a/100'
> 1000 loops, best of 3: 222 usec per loop
> $ python2.4 -mtimeit -s 'a=1.090516455488E15' 'a/100' 100 loops,
> best of 3: 0.234 usec per loop
> $ calc 222/0.234
>~948.71794871794871794872
>
> Decimal is almost one thousand times slower. Do you really need this
> accuracy?
>
> HTH,
>
> -- 
> Felipe.
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list 

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

Re: freeze.py and GTK apps

2006-03-28 Thread Kristian Hermansen
On 3/28/06, Adam DePrince <[EMAIL PROTECTED]> wrote:
> When your Python installation uses shared library modules such as
> _tkinter.pyd, these will not be incorporated in the frozen program.
>  Again, the frozen program will work when you test it, but it won't
>  work when you ship it to a site without a Python installation.

No, it didn't even run!!!  So, it won't run frozen on ANY system.  The
_gtk import choked the whole program and it died with exit status ==
1.  So, even though I did have the GTK libraries locally, the program
exited improperly.  The unfrozen script ran fine, so isn't this a
different problem entirely?

> Freeze prints a warning when this is the case at the end of the
> freezing process:
>
> Warning: unknown modules remain: ...
>
> When this occurs, the best thing to do is usually to rebuild Python
> using static linking only. Or use the approach described in the previous
> section to declare a library path using sys.path, and place the modules
> such as _tkinter.pyd there.
>
> Same applies here ...

Well, what we want is a totally static frozen build, but if not
possible (GTK is huge right?), GTK is assumed to be on the target
machine.  However, the frozen binary still doesn't run properly.  Any
suggestions?  Try freezing the example code yourself and running it,
perhaps I am doing something amazingly wrong here...
--
Kristian Hermansen
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Perforce p4c.run("print" error - AttributeError: OutputBinary

2006-03-28 Thread kbperry
I received a response from Robert Cowham ( the author of the API):

The problem is that something like print was only expected to be done
for text files not binary.

You could try editing p4.py and add a method similar to:

def OutputText(self, text):
"Adds text lines to the output data."
for line in string.split(text, '\n'):
self.output.append(line)

e.g. around line 214 add

def OutputBinary(self, text):
"Adds lines to the output data."
self.output.append(text)


Note:  I am sure that Robert will be updating the P4 module for python,
so if you can I would just download the most recent version (I would
give him a couple of days though).

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


No Cookie: how to implement session?

2006-03-28 Thread Sullivan WxPyQtKinter
 I do not want to use Cookies in my site since not all web browser
support it well and sometimes people close cookie functioning for
security reasons.

I tried to add hidden field with a sessionID in every python CGI script
generated web pages, so everytime my client POST a request, the server
will retrieve the sessionID and decide if it is in the same session.
However, since python cgi do not have a function for redirecting to a
page, I use Location: url http head or  javascript  for
redirecting.in this case, hidden field could not be used any more.

Really wish python would have session management or equivalent in
standard CGI module

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


  1   2   3   >