Re: Hello everything

2005-09-14 Thread Fredrik Lundh
David Pantoja wrote:

> I have an application in tkinter, one button call to another window,
> but the position of this window is random, i' whish to ask at the
> list, if exist a function to put the window in x position of the
> screen, if exist, which function is it?...

try

w.geometry("%+d%+d" % (xoffset, yoffset))

or

w.geometry("%dx%d%+d%+d" % (width, height, xoffset, yoffset))

also see:

http://smurl.name/w2s





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


Re: PyGTK or wXPython?

2005-09-14 Thread Rod W
Magnus Lycka wrote:
> What OS(es) do yo need to support?

My apps will mostly be run on Windows desktops, but there are some Linux 
users.

> I'm curious about PyGTK on Windows. It seems to me that the GTK+
> Windows port is lagging behind a bit (no 2.8?), doesn't look or
> behave quite as native windows apps do, is clunky to install, and
> isn't as stable and complete as e.g. wxPython. Am I wrong?

The GTK+ port is lagging behind on Windows (I think they have a 2.6 
port).  GTK+ doesn't look exactly like Windows, but the install is clean 
and easy - I use GIMP on Windows for graphic editing and it works just 
fine (it used to be worse)

I'm leaning towards PyGTK because it seems less clunky than wxPython on 
wxWidgets.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What XML lib to use?

2005-09-14 Thread Fredrik Lundh
Robert Kern wrote:

> His interpretation of your words is a perfectly valid one even in the
> context of this thread. "in Python" explicitly provides a context for
> the rest of the sentence.

Exactly.  "in Python", not "in an application with an existing API".

(also, if the OP had been forced to use an existing API by external
constraints, don't you think he would have mentioned it?)

> In English, at least, it is perfectly reasonable to presume that explicit
> contexts override implicit ones.

Letting a part of a sentence override the context of the discussion is
perhaps popular in certain tabloid journalist circles, and among slash-
dot editors and US political bloggers, but most people do in fact have
a context buffer memory that can hold more than a few words.  (how
come you're so sure I wasn't talking about, say, the Python Lisp com-
piler?  or the Monty Python sketch with the sadistic Belgian instrument-
making monk?  or a Harry Potter book?)

I know what I meant.  You know what I meant.  Paul knows what I
meant.  If you still want to play the "but there is a way to interpret
this in another way" game, file a bug report against the python.org
"what is python?" summary page.





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


Hello everything

2005-09-14 Thread David Pantoja
I have an application in tkinter, one button call to another window,
but the position of this window is random, i' whish to ask at the
list, if exist a function to put the window in x position of the
screen, if exist, which function is it?...

thanks in advanced...

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


ddd or eclipse with mod_python

2005-09-14 Thread Sakcee
Hi

I am using mod_python for web development, I am in need of some ide ,
can i use ddd or eclipse with pydev with mod_python.

can these ide's handle requests from mod_python and run server side
scripts 


any help or pointers are greatly appreciated
thanks

clive

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


Re: List of integers & L.I.S. (SPOILER)

2005-09-14 Thread n00m
Thank you both for your replies.
And my personal "Thank you!" to Mr. Hettinger for
all his tremendous work!

> Perhaps because you are not using a real Usenet client?
Yes! And I don't even know what is the beast - Usenet client.
I just keep in Favorites of my browser (IE 6.0) this link:
http://groups.google.com/group/comp.lang.python/

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


Builtin classes list, set, dict reimplemented via B-trees

2005-09-14 Thread barnesc

Nifty, Tim Peters responded to my e-mail.  I must've said something
interesting.  Cool, a PyCelebrity!

>[barnesc at engr.orst.edu]
>> ...
>> I've gotten bored and went back to one of my other projects:
>> reimplementing the Python builtin classes list(), set(), dict(),
>> and frozenset() with balanced trees (specifically, counted B-trees
>> stored in memory).
>>
>> In short, this allows list lookup, insertion, deletion in O(log(N))
>> time.  It allows the set and dictionary types to be maintained in
>> order, and insert/lookup/remove operations here take O(log(N)) time
>> as well.  Getting the k least or k greatest elements takes
>> O(log(N)+k) time.
>
>Note that BTrees for Python have been part of ZODB for many years:
>
>Section 5.3, _BTrees Package_
>http://www.zope.org/Wikis/ZODB/FrontPage/guide/node6.html
>
>If you install ZODB, you can use its BTrees as in-memory data
>structures without using any of the rest of ZODB.  If you want to
>persist them, great, that's what ZODB is for.
>
>Note that ZODB's are really B+ trees, so iterating over the smallest k
>takes O(k) time.  As an extension to Python's mapping protocol, the
>keys/values/items/iterkeys/itervalues/iteritems methods also accept
>optional lower and upper bounds on the keys to return.
>
>A gotcha:  For scalability in multiprocess database apps, ZODB's
>BTrees do not store their size.  As a result, len(a_ZODB_BTree) takes
>time linear in the number of elements.

Thanks for the link!

>> ...
>> So my question is: are there any other *practical* applications of a
>> B-tree based list/set/dict ?
>
>Yes.
>
>> In other words, is this module totally worth coding,
>
>That's a different question entirely ;-)
>
>> or is it just academic wankery and theoretical flim flam ? :)
>
>It's probably not a way to get rich quick.
>

Well, the Tim Peters PyCelebrity experience was fun, but not quite
as exhilarating as advertised.  I'm not sure what to say.  Did I get
my money's worth?  There were no s, even a little sarcasm.  I
guess, overall, yeah it was cool, it was worthwhile, it was fun, man,
it was a life-changing moment!

Thanks for tuning in to PyCelebrity weekly.  We're always glad to
be part of your inexplicable existence in The Hostile And Indifferent
Universe (Incorporated).  Contributions come from hackers like you!

 Reporting live from Python-list, this is...Connelly Barnes.

 Next up: Startling photographs show that Guido van Rossum was
  KIDNAPPED BY ALIENS in 1990!  Rumor has it that his
  superhuman language design skills are really due to
  neuroimplanted nanotube processors!
-- 
http://mail.python.org/mailman/listinfo/python-list


Frivolous pursuit - automated game playing program

2005-09-14 Thread Paul McGuire
My son showed me this Flash game, Orbit (there are *many* links on the
web out there for it, here's one for the Google-challenged:
http://uploads.ungrounded.net/25/250408_orbit.swf), and it is
*addicting*.

Basically, you control a comet to traverse through the gravitational
fields of randomly placed planets.  Your only inputs are starting x,y
location and starting direction and speed, defined by clicking,
dragging, and releasing the mouse (imagine the click/mouseDown picks
the starting location, the drag pulls a rubberbanded line from that
spot, and the release/mouseUp begin's the comet's journey).

The simulation looks quite pretty, and I can visualize the physics and
math of the numerical simulation.  I've been able to reach Level 18,
that is up to 18 planets.  (Note - this program doesn't "solve" the
3-body or n-body problem, it simply numerically simulates the system
given a set of initial conditions.  There is no random behavior here -
the program retraces the exact same path given the same initial
conditions.)  The behavior is beautifully chaotic - small changes in
the initial conditions can have large changes in the simulation
results.

I'm stuck at Level 18, but I would like to write a Python program to
automate the trial-and-error playing of this game.  Of course, once I
have the technology to drive the game from a Python program, I can then
build in optimization logic (gradient-following, Newton-Raphson, neural
net, etc.), not just randomly click about the screen.

Any suggestions on how I might write a Python program to:
1. automatically click-drag in another window
2. detect the running and completion of the simulation (the panel
flashes when the comet collides with a planet)

-- Paul

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


Re: round() wrong in Python 2.4?

2005-09-14 Thread Robert Kern
Robert Kern wrote:
> Reinhold Birkenfeld wrote:
> 
>>Robert Kern wrote:
> 
>>>Antoon:
>>>"Python 2.3 isn't rounding 0.0225 up while pyton 2.4 rounds it down."
>>
>>Written in Pseudocode:
>>
>>not (Py2.3 rounding up and Py2.4 rounding down)
> 
> I presumed the "isn't" was a typo given the "while."

Oh never mind. I'm sorry I started this line of conversation.

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

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


Re: "week-year" conversion to date

2005-09-14 Thread oyvgi
Thanks!

Both solutions worked perfectly.

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


Re: round() wrong in Python 2.4?

2005-09-14 Thread Robert Kern
Reinhold Birkenfeld wrote:
> Robert Kern wrote:

>>Antoon:
>>"Python 2.3 isn't rounding 0.0225 up while pyton 2.4 rounds it down."
> 
> Written in Pseudocode:
> 
> not (Py2.3 rounding up and Py2.4 rounding down)

I presumed the "isn't" was a typo given the "while."

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

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


Re: round() wrong in Python 2.4?

2005-09-14 Thread Reinhold Birkenfeld
Robert Kern wrote:
> Grant Edwards wrote:
>> On 2005-09-14, Robert Kern <[EMAIL PROTECTED]> wrote:
>> 
>>>Antoon Pardon wrote:
>> 
0.0225 isn't representable and it happens that the actual number
you get differ. Now which number python should choose when it is
fed 0.0225, I don't know. But expressing the different behaviour
as a change in round, suggest that the O.P. would be wise to
learn about floating point problems
>>>
>>>Uhh, Python didn't change anything between 2.3 and 2.4 wrt round().
>> 
>> That's what Antoon Pardon just said. The above paragraph says
>> that round() didn't change, and the fact that the OP thinks it
>> did indicates that the OP needs to learn more about FP.
> 
> Antoon:
> "Python 2.3 isn't rounding 0.0225 up while pyton 2.4 rounds it down."

Written in Pseudocode:

not (Py2.3 rounding up and Py2.4 rounding down)

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


Re: Create and display an email

2005-09-14 Thread Gregory Piñero
I looked into this same question many months ago and got stuck just
where you are.  Indeed the webbrowser.open('mailto:...') command
seems like a great idea, but I lost 6 hours of my life trying to figure
out how to do attachments :-(
 Here's my guess at what your two best options are:

1. Work with outlook through it's COM interface to send an email.
2. Build email sending right into your application.  It's not hard
to do, and your app could allow the user to save the email to send
later if they're not online.  Here's a simple email sending script
I put together a while back. 
http://www.blendedtechnologies.com/how-to-send-emails-with-python/19
It might be a good starting point.

-Greg
On 13 Sep 2005 16:30:59 -0700, Adam Endicott <[EMAIL PROTECTED]> wrote:
I've got a wxPython based windows GUI application that takes some inputand creates a PDF file output. At the end, I need to create an emailmessage with this pdf file attached ready for the user to just hit"send". I don't want to actually send the email automatically, I just
want to pop up a message in the default mail program that's ready to go(partially because the person might not be online when the email iscreated, this way they could just put it in their Outlook outbox).
I can't figure out how to do this. I've tried usingwebbrowser.open('mailto:...'), which works, except that I can't add anattachment that way (at least I haven't been successful). And I don'tknow any other way to open up a message in the default mail program.
There has to be something obvious that I'm missing here. Anysuggestions?--http://mail.python.org/mailman/listinfo/python-list
-- Gregory PiñeroChief Innovation OfficerBlended Technologies(www.blendedtechnologies.com)
-- 
http://mail.python.org/mailman/listinfo/python-list

Weekly Python Patch/Bug Summary

2005-09-14 Thread Kurt B. Kaiser
Patch / Bug Summary
___

Patches :  343 open ( +1) /  2927 closed ( +4) /  3270 total ( +5)
Bugs:  908 open ( +0) /  5245 closed (+13) /  6153 total (+13)
RFE :  189 open ( +1) /   185 closed ( +0) /   374 total ( +1)

New / Reopened Patches
__

Allow to restrict ModuleFinder to get "direct" dependencies  (2005-09-08)
   http://python.org/sf/1284670  opened by  Scherer Michael

pygettext - provide comments to help translators  (2005-09-11)
   http://python.org/sf/1288056  opened by  Toby Dickenson

FreeBSD 5.3 and upward has thread-safe getaddrinfo(3)  (2005-09-12)
   http://python.org/sf/1288833  opened by  Maxim Sobolev

Fix reload() error message  (2005-09-13)
CLOSED http://python.org/sf/1290454  opened by  Collin Winter

mmap with unsigned int offset and cross build for ppc  (2005-09-14)
   http://python.org/sf/1291169  opened by  José Pedro Pereira Valente de M

Patches Closed
__

Fix reload() error message  (2005-09-13)
   http://python.org/sf/1290454  closed by  birkenfeld

HP-UX ia64 64-bit Python executable  (2005-06-21)
   http://python.org/sf/1225212  closed by  gvanrossum

AIX port from Elemental Security  (2005-09-07)
   http://python.org/sf/1284289  closed by  gvanrossum

new patch for fixing skipitem() in getargs.c  (2005-06-01)
   http://python.org/sf/1212928  closed by  birkenfeld

New / Reopened Bugs
___

traceback module can return undecodable byte strings  (2005-09-08)
   http://python.org/sf/1284496  opened by  Stuart Bishop

logging module's setLoggerClass not really working  (2005-09-08)
   http://python.org/sf/1284928  opened by  Rotem Yaari

urllib.quote is too slow  (2005-09-08)
   http://python.org/sf/1285086  opened by  Tres Seaver

Call to cmd.exe fails  (2005-09-08)
CLOSED http://python.org/sf/1285325  opened by  Alex Luso

Digest Authentication not working in all cases  (2005-09-08)
   http://python.org/sf/1285440  opened by  Jakob Simon-Gaarde

re special sequence '\w'   (2005-09-09)
CLOSED http://python.org/sf/1285809  opened by  ChristianJ

Python code.interact() and UTF-8 locale  (2005-09-12)
   http://python.org/sf/1288615  opened by  STINNER Victor

timedelta multiply and divide by floating point  (2005-09-12)
   http://python.org/sf/1289118  opened by  Daniel Stutzbach

distutils extension library path bug on cygwin  (2005-09-12)
   http://python.org/sf/1289136  opened by  John Whitley

PyDoc crashes at os.py line 133  (2005-09-12)
CLOSED http://python.org/sf/1289210  opened by  Colin J. Williams

cjkcodec compile error under AIX 5.2 on symbol 100_encode  (2005-09-13)
   http://python.org/sf/1290333  opened by  Deron Meranda

--no-compile option has no effect  (2005-09-13)
CLOSED http://python.org/sf/1290382  opened by  Tim Peters

strptime(): can't switch locales more than once  (2005-09-13)
CLOSED http://python.org/sf/1290505  opened by  Adam Monsen

SSLObject breaks read semantics  (2005-09-14)
   http://python.org/sf/1291446  opened by  Jonathan Ellis

Bugs Closed
___

Call to cmd.exe fails  (2005-09-08)
   http://python.org/sf/1285325  deleted by  delenca

exception when unpickling array.array objects  (2005-09-04)
   http://python.org/sf/1281556  closed by  rhettinger

PyDoc crashes at os.py line 133  (2005-09-12)
   http://python.org/sf/1289210  closed by  rhettinger

--no-compile option has no effect  (2005-09-13)
   http://python.org/sf/1290382  closed by  tim_one

RE parser too loose with {m,n} construct  (2005-05-15)
   http://python.org/sf/1202493  closed by  niemeyer

document {m} regex matcher wrt empty matches  (2005-01-31)
   http://python.org/sf/1113484  closed by  niemeyer

r'\10' as replacement pattern loops in compilation  (2004-11-02)
   http://python.org/sf/1058786  closed by  niemeyer

re nested conditional matching (?()) doesn't work  (2005-09-08)
   http://python.org/sf/1284341  closed by  birkenfeld

skipitem() in getargs.c missing some types  (2004-02-09)
   http://python.org/sf/893549  closed by  birkenfeld

re special sequence '\w'   (2005-09-09)
   http://python.org/sf/1285809  closed by  birkenfeld

suspected cPickle memory leak   (2005-05-13)
   http://python.org/sf/1201461  closed by  birkenfeld

splitunc not documented  (2005-08-27)
   http://python.org/sf/1274828  closed by  birkenfeld

os.startfile() doesn't accept Unicode filenames  (2004-08-11)
   http://python.org/sf/1007046  closed by  birkenfeld

strptime(): can't switch locales more than once  (2005-09-13)
   http://python.org/sf/1290505  closed by  bcannon

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


Re: Software bugs aren't inevitable

2005-09-14 Thread Terry Reedy

"Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Wed, 14 Sep 2005 14:32:17 +0200, Jerzy Karczmarczuk wrote:
>> Here you are a recursive version linear in n; it
>> returns the two last Fibonacci numbers of the sequence

The minor problem is that for n = 0, there are no two last numbers.

>> def fibo(n):
>>   if n<2:
>>  return (n-1,n)
>>   else:
>>  (a,b)=fibo(n-1)
>>  return (b,a+b)
>
> Ah, I like this algorithm! I'll add it to my collection. Thank you.

The above is what I call the 'body recursive' form.  Others have other 
names.
Here is a version of the 'tail recursive' form (without negative input 
check).

def fibt(n):
  if n < 2: return n
  def _fib(i, a, b):
if i < n:
  return _fib(i+1, b, a+b)
return b
  return _fib(2, 1, 1)

The inner function does not have to be wrapped; for n >=2, the outer 
function simply passes on its final return.  However, the wrapping masks 
the accumulator parameters from the user and correctly sets their initial 
values.  It also handles the base cases more efficiently by checking for n 
< 2 just once instead of every inner loop.

Here is the direct iterative equivalent:

def fibi(n):
  if n < 2: return n# same as before
  i, a, b = 2, 1, 1   # corresponds to initial _fib call
  while i < n:# repeated ('recursive') if
i, a, b = i+1, b, a+b  # corresponds to args of recursive _fib call
  return b # same as before

The transformation is mechanical and is done internally by some language 
interpreters.  (Although some might require the inner condition reversed 
and the returns switched.)

Terry J. Reedy




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


Re: urllib.open problem

2005-09-14 Thread Astan Chee




yeah, I actually typed that by hand, the url is a local intranet thus I
dont specify any proxies of any kind (which I assume isnt required).
Sorry about the typo.
Cheers

Dennis Lee Bieber wrote:

  On Thu, 15 Sep 2005 09:19:53 +1000, Astan Chee <[EMAIL PROTECTED]>
declaimed the following in comp.lang.python:

  
  
The code snipplet where this error
happens is
f = urllib.urlopen("http://www.hotmail.com/)
notes= f.readlines()


  
  	Is that a cut&paste, or did you type it by hand?

	Note that you have no closing " on that URL.
  



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

Re: Property and "fset" in Python 2.4

2005-09-14 Thread Bengt Richter
On Wed, 14 Sep 2005 18:12:44 -0700, "Rob Pawsner" <[EMAIL PROTECTED]> wrote:

>With this setup --
>
>PythonWin 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] 
>on win32.
>
>-- I'm seeing the old bug which made "fset" methods unusable with declared 
>properties of a class. Even worse, this is happening with a 
>fourth-generation descendent of the Object class, not an old-style class as 
>in "python-Bugs-1207379", 
>http://www.mail-archive.com/python-bugs-list@python.org/msg03434.html.
>
>Before I clog up the digest with details and code snippets, does this sound 
>familiar to anyone?
>
A snippet demonstrating a real bug would be helpful.
A snippet demonstrating a misunderstanding could be helpful.
What's the problem? ;-)

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


Re: Software bugs aren't inevitable

2005-09-14 Thread Terry Reedy

"Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Wed, 14 Sep 2005 11:28:02 -0400, Terry Reedy wrote:

> But in the context of my response, I was replying to a paraphrased quote
> from somebody who apparently believes that recursion is *always* better
> than iteration. That is clearly not the case.

We agree here.  In fact, I suggested that for a given algorithm implemented 
in Python, iteration should always be faster by a small factor.

> It is a "mere implementation detail" that (for most computer systems, and
> most programming languages) stack space is at a premium and a deeply
> recursive function can run out of stack space while the heap still has
> lots of free memory. But those implementation details in the real world
> make the difference between an elegant solution that runs like a lame 
> duck
> and an practical solution that has nothing going for it except the fact
> that it works.

Which is why, in the part you snipped, I said that recursion (unlike 
iteration)  piles up stack frames unless optimized not to and that Python 
is *not* so optimized.  I will add that when an function or algorithm does 
require or use a stack, the iterative form will use heap memory instead of 
call stack memory and will put less on the stack with each repetition.  But 
your example was about time and my point then and now is about time, not 
space.

>> Recursion and iteration are two syntaxes for the same operation: 
>> repetition
>> with variation.
>
> Yes, in general anything that can be solved recursively can be solved
> iteratively. Some classes of problems lend themselves naturally to one or
> the other solution, but it is always possible (in principle at least) to
> use either.
>
>> Abstractly, these are two algorithms for the same function.  One runs in
>> exponential time because it wastefully calculates and tosses away an
>> exponential number of subvalues.  The other runs in linear time because 
>> it
>> calculates each subvalue once.  When one only wants Fib(n), and not the
>> sequence leading up to it, even this is wasteful, for large enough n, 
>> since
>> there is a third algorithm that caluculates Fib(n) directly by a simple
>> formula (something like the interger part of the golden ratio to the nth
>> power).

To expand on this a bit: seeing the problem as 'recalculating tossed-away 
subvalues' suggests the fruitful question "how do I not do that?".  The 
generic answer is memoization.  A specific answer applicable to Fib() is 
linearization or even formulaization.  This is an extreme example of 
wasteful calculation, but squeezing out waste is a common theme in 
algorithm improvement.  See below for another example.

> Yes. There are lots of algorithms that could be done, and they all have
> their pros and cons. Biset's formula, for example, is mathematically
> correct, but for large enough n, the "mere implementation detail" that
> floats have a finite precision will cause that algorithm to give 
> incorrect
> answers. For "large enough", on my system I mean n=71.

I am assuming you mean the Fib formula?  No matter.  With finite precision 
ints, typically 32 bits, fib(n) by addition overflows sooner than that.  If 
you allow extended precision ints, then allow extended precision floats 
also.

>> Now: I could (and probably someday will) write an iterative version of 
>> the
 >> exponential algorithm (using an explicit stack) that calculates each
>> subvalue exactly as many times as the recursive version of that same
>> algorithm.  And I could compare it to a recursive version of the more
>> efficient linear algorithm (such as posted by Jerzy Karczmarczuk).  And 
>> I
>> could claim that this shows hows iteration can waste time compared to
>> recursion.
>
> Of course it can. But you have to really *work* at getting the iterative
> version to be as wasteful as the obvious recursive version.

For someone who does not know how to write the iterative version, the 
'extravagent' recursive version would be infinitely faster.  But, as I 
said, I do and I would *not* have to work very hard.  I have a 10-15 line 
template (in C) sitting in a book 10 feet away.  Filling it in would be 
easy and straightforward.  If I had the template in Python on my machine, 
maybe 5 minutes.  I hope someday to write a set of such templates, with 
explanations, so that you could potentially do the same ;-).

>> But that, I admit, would be an invalid conclusion.  And that, I claim,
>> is also invalid when 'iteration' and 'recursion' are reversed, no matter
>> how often repeated in texts and articles.  The difference is between the
>> algorithms, not the differing syntactic expressions thereof.
>
> Now you go too far.

Not at all.  I was in my first response and here am talking specifically 
about exponential time wastage and the bogus claim that it is due to 
recursion or, in my reversal, iteration.  It is due to the algorithm 
difference.  The problem with this example, which I know you h

Re: Newbie - instanciating classes from other files

2005-09-14 Thread Devan L

[EMAIL PROTECTED] wrote:
> Hey guys, i just started learning python (i usually use java/C).
>
> this has got me stumped as its not mentioned in the documentation
> (unless im skimming it every time).
>
> How does one instanciate a class from another file

import somefile
foo = somefile.class(__init__arguments-should-go-here)

Don't include the .py, it's won't work.

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


Re: Newbie - instanciating classes from other files

2005-09-14 Thread Jorge Godoy
[EMAIL PROTECTED] writes:

> Hey guys, i just started learning python (i usually use java/C).
> 
> this has got me stumped as its not mentioned in the documentation
> (unless im skimming it every time).
> 
> How does one instanciate a class from another file
> 
> i thought it would be
> ---code---
> import file.py
> 
> thisFile = ClassName()
> ---not code---

import file# see that there's no ".py"
thisFile = file.ClassName()

or


from file import ClassName
thisFile = ClassName()


This is in the docs.

-- 
Jorge Godoy  <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


pyNMS

2005-09-14 Thread Mohammed Smadi
hi

anybody used pyNMS b4?
I compiled it and seem to be able to import modules but cannot use em, or 
more like cannot call them since if i do something like:

import ping
ping.ttl(..)

i get an error like
Traceback (most recent call last):
  File "", line 1, in ?
AttributeError: 'module' object has no attribute 'ttl'


any clue?

thanks
smadi

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


Re: "optimizing out" getattr

2005-09-14 Thread Stephen Thorne
On 14 Sep 2005 19:46:44 -0700, Daishi  Harada <[EMAIL PROTECTED]> wrote:
> Hi,
> 
> I'd like to get the 'get2' function below to
> perform like the 'get1' function (I've included
> timeit.py results).

Do you have profiling results that show that a significant percentage
of your programs time is being spent inside this function?

If you don't, then you're wasting your time doing unnecessery optimisation.
-- 
Stephen Thorne
Development Engineer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python-dev Summary for 2005-08-01 through 2005-08-15

2005-09-14 Thread Steven Bethard
Steve Tregidgo wrote:
> on 2005-08-30 01:45 Tony Meyer said the following:
> 
>> [The HTML version of this Summary is available at
>> http://www.python.org/dev/summary/2005-08-01_2005-08-15.html]
> ...
>> Many revision control systems were extensively discussed, including
>> `Subversion`_ (SVN), `Perforce`_, `Mercurial`_, and `Monotone`_.  
>> Whichever
>> system is moved to, it should be able to be hosted somewhere (if
>> *.python.org, then it needs to be easily installable),
> ...
> 
> Take a look at the HTML version of this summary -- there's some oddness, 
> possibly caused by the asterisk above.  After the paragraph ending 
> "appropriate", we get this, linked by the asterisk:
> 
> System Message: WARNING/2 (./2005-08-01_2005-08-15.ht, line 65); backlink
> Inline emphasis start-string without end-string.

Thanks for the pair of eyes.  Brett Cannon kindly fixed that for us.

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


Newbie - instanciating classes from other files

2005-09-14 Thread comanighttrain
Hey guys, i just started learning python (i usually use java/C).

this has got me stumped as its not mentioned in the documentation
(unless im skimming it every time).

How does one instanciate a class from another file

i thought it would be
---code---
import file.py

thisFile = ClassName()
---not code---
but its not

and its not
---code---
thisFile= filename.ClassName()
---not code---
im stuck:( 

cheers 
dave

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


"optimizing out" getattr

2005-09-14 Thread Daishi Harada
Hi,

I'd like to get the 'get2' function below to
perform like the 'get1' function (I've included
timeit.py results).

I'm not sure how to write 'mkget' to do achieve
this, however, except to use 'exec' - is that what
would be necessary?

Thanks in advance,
d

---
class A:
a = 1
b = 2
a = A()
labels = ('a', 'b')
def get1(x):
return (x.a, x.b)
def mkget(attrs):
def getter(x):
return tuple(getattr(x, label) for label in attrs)
return getter
get2 = mkget(labels)

# % timeit.py -s "import test" "test.get1(test.a)"
# 100 loops, best of 3: 0.966 usec per loop
# % timeit.py -s "import test" "test.get2(test.a)"
# 10 loops, best of 3: 4.46 usec per loop
---

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


Re: global interpreter lock

2005-09-14 Thread Stephen Thorne
On 15/09/05, Michael Sparks <[EMAIL PROTECTED]> wrote:
> At the moment, one option that springs to mind is this:
> yield WaitDataAvailable("inbox")

Twisted supports this.

help("twisted.internet.defer.waitForDeferred")

example usage is:

@deferredGenerator
def thingummy():
  thing = waitForDeferred(makeSomeRequestResultingInDeferred())
  yield thing
  thing = thing.getResult()
  print thing #the result! hoorj!

With the new generator syntax, it becomes somewhat less clunky,
allowing for the syntax:

@defgen
def foo():
   somereturnvalue = yield SomeLongRunningOperation()
   print somereturnvalue

http://svn.twistedmatrix.com/cvs/sandbox/radix/newdefgen.py?view=markup&rev=14348

-- 
Stephen Thorne
Development Engineer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Search Engine app

2005-09-14 Thread Peter Hansen
Will McGugan wrote:
> Alan Meyer wrote:
>> I stand ready to be corrected, but I think Python would not be a
>> good language for writing search engines.  

> Wasn't Google's first search engine actualy written in Python?

Not unless it was some kind of quickie prototype that was immediately
discarded in favour of an optimized C version once it was built.  The
rumour you're probably referring to is the *web spider* part of the
system, while the indexing/searching stuff is written in C or
something close (memory fails me on that point, but I'm sure Google
itself could easily tell you more).

There's an interesting paper about the early architecture/history of
Google which was a published by the authors (when they were still
in figurative diapers) and which was referenced recently in this
newsgroup.  The archives would quickly pull it up for you.

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


Re: help in simplification of code [string manipulation]

2005-09-14 Thread John

But ur previous solution worked on my machine...
although a friend tried it on his machine and the libraries
were not found even if they existed! (Even the -lm was not found)

Can you explain a bit why the previous solution worked?

Thanks for ur help,
--j

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


Re: Find day of week from month and year

2005-09-14 Thread John Machin
Terry Reedy wrote:
>>Laguna wrote:
>>
>>>I want to find the expiration date of stock options (3rd Friday of the
>>>month) for an any give month and year.
> 
> 
>>From year and month (and day=1) get the day of the week (n in [0,6]) of the 
> first of the month using some version of the the standard formula (see 
> below) and look up the third friday date in a precalculated 7-element list, 
> or, with n=0 on Saturday, 3rd Friday is 21-n
> 
> Here is a translation of the guts of a 30-year-old Basic program:
> 
> def friday3(m,y): # ints
>   if m <= 2:
> m += 12
> y -= 1
>   d = 1
>   n = d + 2*m + int(.6*(m+1)) + y + y//4 - y//100 + y//400 + 2

Some simplification is possible:

 >>> [2*m + int(.6*(m+1)) for m in range(15)]
[0, 3, 5, 8, 11, 13, 16, 18, 21, 24, 26, 29, 31, 34, 37]
 >>> [(13*m+3)//5  for m in range(15)]
[0, 3, 5, 8, 11, 13, 16, 18, 21, 24, 26, 29, 31, 34, 37]
 >>>


>   n = int((n/7.0- n//7)*7.0 + .5)

n %= 7

>   # n=0 is Saturday, making 3rd Friday the 21st.
>   return 21 - n
> 
> 
>>>Requirements:
>>>d0 = expiration(9, 2005) # d0 would be 16
>>>d1 = expiration(6, 2003) # d1 would be 20
>>>d2 = expiration(2, 2006) # d2 would be 17
> 
> 
for m,y in ((9,2005), (6,2003), (2,2006)): print friday3(m,y)
> 
> ...
> 16
> 20
> 17
> 
> Terry J. Reedy
> 
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: O'Reilly book on Twisted

2005-09-14 Thread Dave Cook
On 2005-09-14, Steve M <[EMAIL PROTECTED]> wrote:

> Is this book fully up to date with Twisted 2.0?

Yes, according to an email from the author on the twisted-python mailing list

>  Does the book cover Nevow at all?

Doesn't look like it.  More info here:

http://fettig.net/weblog/2005/06/30/my-book-on-twisted/
http://fettig.net/weblog/

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


Re: Pre-PEP Proposal: Codetags

2005-09-14 Thread David Goodger
Also, please update the Post-History header, adding the date(s) you
posted the PEP to the mailing lists and/or newsgroups.

And this time I'll remember to attach the file :-)

--
David Goodger 
PEP: XXX
Title: Codetags
Version: $Revision$
Last-Modified: $Date$
Author: Micah Elliott 
Status: Draft
Type: Informational
Content-Type: text/x-rst
Created: 27-Jun-2005
Post-History: XXX


Abstract


This informational PEP aims to provide guidelines for consistent use
of Codetags, which would enable the construction of standard utilities
to take advantage of the Codetag information, as well as making Python
code more uniform across projects.  Codetags also represent a very
lightweight programming micro-paradigm and become useful for project
managment, documentation, change tracking, and project health
monitoring.  This is submitted as a PEP because I feel its ideas are
Pythonic, although the concepts are not unique to Python programming.
Herein are the definition of Codetags, the philosophy behind them, a
motivation for standardized conventions, a specification, a toolset
description, and possible objections to the Codetag project/paradigm.

This PEP is also living as a wiki_ for people to add comments.


What Are Codetags?
==

Programmers widely use ad-hoc code comment markup conventions to serve
as reminders of sections of code that need closer inspection or
review.  Examples of markup include ``FIXME``, ``TODO``, ``XXX``,
``BUG``, but there many more in wide use in existing software.  Such
markup will henceforth be referred to as *Codetags*.  These Codetags
may show up in application code, unit tests, scripts, general
documentation, or wherever suitable.


Philosophy
==

If you subscribe to most of these values, then Codetags will likely be
useful for you.

1. As much information as possible should be contained **inside the
   source code** (application code or unit tests).  This along with
   use of Codetags impedes duplication.  Most documentation can be
   generated from that source code; e.g., by using help2man, man2html,
   docutils, epydoc/pydoc, ctdocgen, etc.

2. Information should be almost **never duplicated** -- it should be
   recorded in a single original format and all other locations should
   be automatically generated from the original, or simply be
   referenced.  This is the *SPOT* rule.

3. Documentation that gets into customers' hands should be
   **auto-generated** from single sources into all other output
   formats.  People want documentation in many forms.  It is thus
   important to have a documentation system that can generate all of
   these.

4. Whenever information is subject to (and suited for) user
   feedback/input (e.g., FAQ, RFC, PEP), it should be contained in a
   **repository** (e.g. a wiki, usenet, or mailing lists).

5. There should not be a dedicated, disjoint **documentation team**
   for any non-huge project.  The developers writing the code know the
   code best, and they should be the ones to describe it.

6. **Plain text** (with non-invasive markup) is the best form of
   writing anything.  All other formats are to be generated from the
   plain text.

7. **Revision control** should be used for almost everything.  And
   modifications should be checked in at least daily.


Motivation
==

* **Various productivity tools can be built around Codetags.**

  See `Toolset Possibilities`_.

* **Encourages consistency.**

  Historically, a subset of these Codetags has been used informally in
  the majority of source code in existence, whether in Python or in
  other languages.  Tags have been used in an inconsistent manner with
  different spellings, semantics, format, and placement. For example,
  some programmers might include datestamps and/or user identifiers,
  limit to a single line or not, spell the Codetag differently than
  others, etc.

* **Encourages adherence to SPOT/DRY principle.**

  E.g., generating a roadmap dynamically from Codetags instead of
  keeping TODOs in sync with separate roadmap document.

* **Easy to remember.**

  All Codetags must be concise, intuitive, and semantically
  non-overlapping with others.  The format must also be simple.

* **Use not required/imposed.**

  If you don't use Codetags already, there's no obligation to start,
  and no risk of affecting code (but see Objections_).  A small subset
  can be adopted and the Tools_ will still be useful (a few Codetags
  have probably already been adopted on an ad-hoc basis anyway).  Also
  it is very easy to identify and remove if a Codetag is no longer
  deemed useful.  Then it is effectively *committed* and recorded by
  revision control simply by checking in.

* **Gives a global view of code.**

  Tools can be used to generate documentation and reports.

* **A logical location for capturing CRCs/Stories/Requirements.**

  The XP community often does not electronically capture Stories, but
  Codetags seem like a good place 

Re: Some advice on startingout with python.

2005-09-14 Thread Rune Strand
It's not about GUI, but it's a good book. It's both online and printed:

http://diveIntoPython.org

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


Property and "fset" in Python 2.4

2005-09-14 Thread Rob Pawsner
With this setup --

PythonWin 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] 
on win32.

-- I'm seeing the old bug which made "fset" methods unusable with declared 
properties of a class. Even worse, this is happening with a 
fourth-generation descendent of the Object class, not an old-style class as 
in "python-Bugs-1207379", 
http://www.mail-archive.com/python-bugs-list@python.org/msg03434.html.

Before I clog up the digest with details and code snippets, does this sound 
familiar to anyone?

-- Rob Pawsner, Los Angeles 


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


Re: Writing at the beginning of a file

2005-09-14 Thread Terry Reedy

"Thierry Lam" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Is there an easy way to write something of variable length at the top
> of the file?
...
> The other way to do what I want is to write the whole thing to a new
> file, but I want to skip that method if there's an alternative way.

Grant has already given you the two no's to the questions you asked.

> Any suggestions please?

A slightly different question "How do I write a variable length file 
summary after writing the data so that the summary is easy to read without 
reading the entire file, and so I can add data later?" has a yes answer:

1. reserve a fixed amount of space at the top for a 'pointer' to the 
summary.
2. write the data
3. write the summary
4. rewind (seek to beginning) and write the 'pointer'.

The pointer can be either the offset from the beginning or the offset from 
the end (= length of summary) in either binary or text format.

To read, read the pointer, seek to appropriate place, and read summary.

To add data:
1. read the summary
2. write more data, starting where the old summary started
3. write revised summary and pointer.

Terry J. Reedy



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


Re: global interpreter lock

2005-09-14 Thread Michael Sparks
[ Second time lucky... ]
Paul Rubin wrote:
...
> I don't see how generators substitute for microthreads.  In your example
> from another post:

I've done some digging and found what you mean by microthreads -
specifically I suspect you're referring to the microthreads package for
stackless? (I tend to view an activated generator as having a thread of
control, and since it's not a true thread, but is similar, I tend to view
that as a microthread. However your term and mine don't co-incide, and it
appears to cause confusion, so I'll switch my definition to match yours,
given the microthreads package, etc)

The reason I say this is because it naturally encourages small components
which are highly focussed in what they do. For example, when I was
originally looking at how to wrap network handling up, it was logical to
want to do this: 

[ writing something probably implementable using greenlets, but definitely
  pseudocode ]

@Nestedgenerator
def runProtocol(...)
   while:
   data = get_data_from_connection( ... )

# Assume non-blocking socket
def get_data_from_connection(...)
try:
data = sock.recv()
return data
except ... :
Yield(WaitSocketDataReady(sock))
except ... :
return failure

Of something - you get the idea (the above code is naff, but that's because
it's late here) - the operation that would block normally you yield inside
until given a message.

The thing about this is that we wouldn't have resulted in the structure we
do have - which is to have components for dealing with connected sockets,
listening sockets and so on. We've been able to reuse the connected socket
code between systems much more cleanly that we would have done (I
suspect) than if we'd been able to nest yields (as I once asked about here)
or have true co-routines.

At some point it would be interesing to rewrite our entire system based on
greenlets and see if that works out with more or less reuse. (And more or
less ability to make code more parallel or not)

[re-arranging order slightly of comments ]
>class encoder(component):
>   def __init__(self, **args):
>   self.encoder = unbreakable_encryption.encoder(**args)
>   def main(self):
>  while 1:
>  if self.dataReady("inbox"):
> data = self.recv("inbox")
> encoded = self.encoder.encode(data)
> self.send(encoded, "outbox")
>  yield 1
> 
...
> In that particular example, the yield is only at the end, so the
> generator isn't doing anything that an ordinary function closure
> couldn't:
> 
>def main(self):
>def run_event():
>if self.dataReady("inbox"):
>   data = self.recv("inbox")
>   encoded = self.encoder.encode(data)
>   self.send(encoded, "outbox")
>return run_event


Indeed, in particular we can currently rewrite that particular example as:

class encoder(component):
   def __init__(self, **args):
   self.encoder = unbreakable_encryption.encoder(**args)
   def mainLoop(self):
  if self.dataReady("inbox"):
 data = self.recv("inbox")
 encoded = self.encoder.encode(data)
 self.send(encoded, "outbox")
  return 1

And that will work today. (We have a 3 callback form available for people
who aren't very au fait with generators, or are just more comfortable with
callbacks)


That's a bad example though. A more useful example is probably something
more like this: (changed example from accidental early post)
...
  center = list(self.rect.center)
  self.image = self.original
  current = self.image
  scale = 1.0
  angle = 1
  pos = center
  while 1:
self.image = current
if self.dataReady("imaging"):
   self.image = self.recv("imaging")
   current = self.image
if self.dataReady("scaler"):
   # Scaling
   scale = self.recv("scaler")
w,h = self.image.get_size()
self.image = pygame.transform.scale(self.image, (w*scale,
h*scale))
if self.dataReady("rotator"):
   angle = self.recv("rotator")
   # Rotation
self.image = pygame.transform.rotate(self.image, angle)
if self.dataReady("translation"):
   # Translation
   pos = self.recv("translation")
self.rect = self.image.get_rect()
self.rect.center = pos
yield 1


(this code is from Kamaelia.UI.Pygame.BasicSprite)

Can it be transformed to something event based? Yes of course. Is it clear
what's happening though? I would say yes. Currently we encourage the user
to look to see if data is ready before taking it, simply because it's the
simplest interface that we can guarantee consistency with.

For example, currently the exception based equivalent would be:
try:
pos = 

Re: Software bugs aren't inevitable

2005-09-14 Thread Terry Reedy

"Rocco Moretti" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> The algorithm one uses sometimes depends quite heavily on which mindset
> you're using. Some algorithms require much more mental effort to
> understand when in their recursive form versus the iterative form, and
> vice versa. If you're stuck thinking in only one form, you might miss
> the better algorithm because it is not as "simple" in that form.

This is why I disagree with the extreme recursionist and iterationist camps 
that both argue that since both forms cover the same ground, one only needs 
to learn one.

> The ideal case would be a programming language that allows you to write
> the algorithm in whatever form is simplest/most comfortable, and then
> automagically transforms it to the form that works the fastest under the
> hood.

I suspect that recursion can be always be sped up by doing it within one 
frame.  Some languages/compilers do this for the particular form of linear 
recursion called tail recursion.In general, recursion to iteration 
requires two stacks and two loops nested within a third, but there are 
several special cases which are simpler in one way or another.  I think 
making the right choice will generally require extra input from the 
programmer.  But with the extra info and some restraint in formatting, I 
think the rest could be automated.

A separate tranformation issue is how to reduce double recursion to single 
recursion, when possible, and even to no recursion, as one can with the 
Fibonacci example.  For functions which produce a set or sequence of 
structures, a related sort of transformatiom is from all-at-once production 
to one-at-a-time generation.

Terry J. Reedy



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


Re: Writing at the beginning of a file

2005-09-14 Thread Bengt Richter
On 14 Sep 2005 07:13:50 -0700, "Thierry Lam" <[EMAIL PROTECTED]> wrote:

>Let's say I already wrote a file and have the following:
>
>testing
>testing testing
>testing testing testing
>
>Is there an easy way to write something of variable length at the top
>of the file?
>
>For example,
>
>6 testing written
>testing
>testing testing
>testing testing testing
>
>I tried to write some garbage on top right after opening the file and
>then use seek to overwrite the garbage, but since the string to be
>written can be of variable length, I'm not sure how much garbage I have
>to write initially.
>
>The other way to do what I want is to write the whole thing to a new
>file, but I want to skip that method if there's an alternative way.
>
>Another way of doing it is to buffer the whole file writing into some
>variable, but that means I have to change 2000+ lines of codes and
>change fp.write() to something else.
>
>Any suggestions please?
>
Maybe avoid writing at the beginning?

Consider whether appending suitably tagged info at the end of the
file might work for your actual application. If the file-using program
knows of this structure, it can seek e.g. to the end minus a fixed 4 bytes
and read those, assuming that will an n-digit (or maybe rfind-delimited) ascii
number offset to seek back to the beginning of the variable-length chunk
you appended. Then what you read forward from there can be used as if
prefixed to the whole file (or contain fixup info for other parts of
the file before use). This can be a handy way of incrementally modifying
a file without rewriting the whole. It all depends, but it may be an option ;-)

For real safety though, you don't modify or delete an existing important
file until you know you have a new representation safely completed. I say
"new representation" since that also covers the possiblity of original plus
diff patch file as separate files, which could also be an option.

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


Some advice on startingout with python.

2005-09-14 Thread Laszlo Antal
Hi,

Which book(s) would you recommend for me to start learning Python 
programming??
I am interested mostly to do GUI apps. I want to replace my PHP-GTK
programms, and of course learn a lot of Python.
Here are some titles I find and got the best reviews::
-Practical Python  by Magnus Lie Hetland;
-Foundations of Python Network Programming by John Goerzen
-Python Cookbook  by Alex Martelli
-Python Programming On Win32
-Learning Python, Second Edition by Mark Lutz

If there is any other book or online tutorial you recommend please let 
me know.

I appreciate every help
Thank you Laszlo

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


urllib.open problem

2005-09-14 Thread Astan Chee
Hi Guys,
I have a python script which runs perfectly on my machine.
However a machine that I tested it on gives the following error 
message:

Traceback (most recent call last):
  File "whip.py", line 616, in OnRebootRunning
  File "whip.py", line 626, in RebootCustom
  File "urllib.pyc", line 77, in urlopen
  File "urllib.pyc", line 170, in open
TypeError: cannot concatenate 'str' and 'NoneType' objects

The code snipplet where this error
happens is
f = urllib.urlopen("http://www.hotmail.com/)
notes= f.readlines()

Does anyone know what causes this error? Im perplexed because it works 
on some machines and it doesnt work on other computers although they all 
have the same spec.
Thanks for the help
Cheers
Stan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: global interpreter lock

2005-09-14 Thread Michael Sparks
arrgh... hit wrong keystroke which caused an early send before I'd finished
typing... (skip the message I'm replying to hear for a minute please :-)


Michael.

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


Re: Removing duplicates from a list

2005-09-14 Thread Steven Bethard
przemek drochomirecki wrote:
> def unique(s):
>  e = {}
>  for x in s:
>   if not e.has_key(x):
>e[x] = 1
>  return e.keys()

This is basically identical in functionality to the code:

 def unique(s):
 return list(set(s))

And with the new-and-improved C implementation of sets coming in Python 
2.5, there's even more of a reason to use them when you can.

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


Re: global interpreter lock

2005-09-14 Thread Michael Sparks
Paul Rubin wrote:
...
> I don't see how generators substitute for microthreads.  In your example
> from another post:

I've done some digging and found what you mean by microthreads -
specifically I suspect you're referring to the microthreads package for
stackless? (I tend to view an activated generator as having a thread of
control, and since it's not a true thread, but is similar, I tend to view
that as a microthread. However your term and mine don't co-incide, and it
appears to cause confusion, so I'll switch my definition to match yours,
given the microthreads package, etc)

You're right, generators aren't a substitue for microthreads. However I do
see them as being a useful alternative to microthreads. Indeed the fact
that you're limited to a single stack frame I think has actually helped our
architecture.

The reason I say this is because it naturally encourages small components
which are highly focussed in what they do. For example, when I was
originally looking at how to wrap network handling up, it was logical to
want to do this: 

[ writing something probably implementable using greenlets, but definitely
  pseudocode ]

@Nestedgenerator
def runProtocol(...)
   while:
   data = get_data_from_connection( ... )

# Assume non-blocking socket
def get_data_from_connection(...)
try:
data = sock.recv()
return data
except ... :
Yield(WaitSocketDataReady(sock))
except ... :
return failure

Of something - you get the idea (the above code is naff, but that's because
it's late here) - the operation that would block normally you yield inside
until given a message.

The thing about this is that we wouldn't have resulted in the structure we
do have - which is to have components for dealing with connected sockets,
listening sockets and so on. We've been able to reuse the connected socket
code between systems much more cleanly that we would have done (I
suspect) than if we'd been able to nest yields (as I once asked about here)
or have true co-routines.

At some point it would be interesing to rewrite our entire system based on
greenlets and see if that works out with more or less reuse. (And more or
less ability to make code more parallel or not)


[re-arranging order slightly of comments ]
>class encoder(component):
>   def __init__(self, **args):
>   self.encoder = unbreakable_encryption.encoder(**args)
>   def main(self):
>  while 1:
>  if self.dataReady("inbox"):
> data = self.recv("inbox")
> encoded = self.encoder.encode(data)
> self.send(encoded, "outbox")
>  yield 1
> 
...
> In that particular example, the yield is only at the end, so the
> generator isn't doing anything that an ordinary function closure
> couldn't:
> 
>def main(self):
>def run_event():
>if self.dataReady("inbox"):
>   data = self.recv("inbox")
>   encoded = self.encoder.encode(data)
>   self.send(encoded, "outbox")
>return run_event

Indeed, in particular we can currently rewrite that particular example as:

class encoder(component):
   def __init__(self, **args):
   self.encoder = unbreakable_encryption.encoder(**args)
   def mainLoop(self):
  if self.dataReady("inbox"):
 data = self.recv("inbox")
 encoded = self.encoder.encode(data)
 self.send(encoded, "outbox")
  return 1

That's a bad example though. A more useful example is probably something
more like this:

class Multicast_sender(Axon.Component.component):
   def __init__(self, local_addr, local_port, remote_addr, remote_port):
   super(Multicast_sender, self).__init__()
   self.local_addr = local_addr
   self.local_port = local_port
   self.remote_addr = remote_addr
   self.remote_port = remote_port

   def main(self):
   sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
socket.IPPROTO_UDP)
   sock.bind((self.local_addr,self.local_port))
   sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 10)
   while 1:
  if self.dataReady("inbox"):
 data = self.recv()
 l = sock.sendto(data, (self.remote_addr,self.remote_port) );
  yield 1

With a bit of fun with decorators, that can actually be collapsed into
something more like:

@component
def Multicast_sender(self, local_addr, local_port, remote_addr,
remote_port):
   sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
socket.IPPROTO_UDP)
   sock.bind((self.local_addr,self.local_port))
   sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 10)
   while 1:
  if self.dataReady("inbox"):
 data = self.recv()
 l = sock.sendto(data, (self.remote_addr,self.remote_port) );
  yield 1





> You've got the "main" method creating a generator that has its own
> even

Re: working with VERY large 'float' and 'complex' types

2005-09-14 Thread Terry Hancock
> "Todd Steury" <[EMAIL PROTECTED]> writes:
> > or 1.#INDj. However I really need these numbers to be calculated (although 
> > precision isn't key). Is there a way to get python to increase the size 
> > limit of float and complex numbers?

This is really a natural problem with such calculations.

On Wednesday 14 September 2005 02:30 pm, Paul Rubin wrote:
> You could rearrange your formulas to not need such big numbers:
> 
> x = 1000.
> log10_z = x / math.log(10)
> c,m = divmod(log10_z, 1.)
> print 'z = %.5fE%d' % (10.**c, m)

I highly recommend you use this kind of solution. Solve the problem
with algebra, not with a new library.  Most of the time, large numbers
can be avoided (particularly if you are not overly concerned with
precision), simply by dividing out large constant factors and the
like. Logs work better for this problem, as Paul points out.

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Re: Software bugs aren't inevitable

2005-09-14 Thread Terry Hancock
On Wednesday 14 September 2005 02:23 pm, Paul Rubin wrote:
> Steven D'Aprano <[EMAIL PROTECTED]> writes:
> > It is a "mere implementation detail" that (for most computer systems, and
> > most programming languages) stack space is at a premium and a deeply
> > recursive function can run out of stack space while the heap still has
> > lots of free memory.
> 
> Every serious FP language implementation optimizes tail calls and thus
> using recursion instead of iteration doesn't cost any stack space and
> it probably generates the exact same machine code.

I understood both the iterative version (which was efficient)
and the "naive" recursive version MUCH better than the "efficient"
recursive version.

Being able to write the efficient recursive version proves you're
smart, which is very important to some people.  Being able to
write the efficient iterative version proves you don't have to be.

Since I write code to solve problems, not prove my intellectual
prowess, my vote goes for the "dumb" solution.  Probably this
is why I use Python.

Sorry. ;-)

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Re: Removing duplicates from a list

2005-09-14 Thread tcc . chapman
This works too, if speed isn't your thing..

>> a = [ 1,2,3,2,6,1,3,4,1,7,5,6,7]
>> a = dict( ( (i,None) for i in a)).keys()
a
[1, 2, 3, 4, 5, 6, 7]

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


Re: Unexpected Behavior Iterating over a Mutating Object

2005-09-14 Thread Bengt Richter
On Wed, 14 Sep 2005 11:12:14 +0200, bruno modulix <[EMAIL PROTECTED]> wrote:

>Dave Hansen wrote:
>(snip code snippets and sensible explanations)
>
>> Again, iterating over an item that is mutating seems like a Bad
>> Idea(tm) to me.  
>
>It as *always* been a bad idea to modify a list in place (I mean adding
>or removing items) while iterating over it, whatever the language. If
>you *really* need to do such a thing (for effeciency reasons - and then
>it's usually in low-level C code), you'd better use indexed access, and
>adjust the index as needed - but this results in tricky, hard to
>maintain code.
Do you consider this to be tricky, or likely to be hard to maintain?
(not specifically tested beyond what you see ;-)

 >>> data = [ 'First', 'Second DEL', 'Third', 'Fourth',
 ...  'Fifth DEL', 'DEL Sixth', 'Seventh DEL', 'Eighth DEL',
 ...  'Ninth DEL', 'Tenth', 'Eleventh', 'Twelfth']
 >>> iw = 0
 >>> for item in data:
 ... if 'DEL' in item: continue
 ... data[iw] = item
 ... iw += 1
 ...
 >>> del data[iw:]
 >>> data
 ['First', 'Third', 'Fourth', 'Tenth', 'Eleventh', 'Twelfth']

Or that maybe a utility function like the following would be hard to maintain?

 >>> def filter_in_place(L, keep=bool):
 ... iw = 0
 ... for item in L:
 ... if keep(item):
 ... L[iw] = item
 ... iw += 1
 ... del L[iw:]
 ...
 >>> data = [ 'First', 'Second DEL', 'Third', 'Fourth',
 ...  'Fifth DEL', 'DEL Sixth', 'Seventh DEL', 'Eighth DEL',
 ...  'Ninth DEL', 'Tenth', 'Eleventh', 'Twelfth']
 >>> data
 ['First', 'Second DEL', 'Third', 'Fourth', 'Fifth DEL', 'DEL Sixth', 'Seventh 
DEL', 'Eighth DEL'
 , 'Ninth DEL', 'Tenth', 'Eleventh', 'Twelfth']
 >>> filter_in_place(data, lambda x: 'DEL' not in x)
 >>> data
 ['First', 'Third', 'Fourth', 'Tenth', 'Eleventh', 'Twelfth']


>
>> But I was curious: is this the intended behavior, or
>> does this fall under what C programmers would call 'undefined
>> behavior.'
>
>Not being a Language Lawyer(tm), I can't tell for sure, but I'd think
>it's the expected behavior. Anyway it's not a behavior I'd relie upon,
>since it would be too much of a dirty trick anyway.
>
I think it depends on the kind of mutation involved. A mutation of the 
_structure_
of a container being iterated over effectively modifies the initial parameters 
of
the iteration control, so there you need either to have intimate knowledge of 
how
the iterator does its thing, or you have to insulate yourself from that need.
OTOH, a mutation of the content can be safe, if it doesn't modify the content
yet to be accessed during the iteration.

In the case of a list, the order can be depended on, so it's not that hard.
Other iterable containers are not so clear, and of course even in a list you
could have cases of access to early items having side effects on upcoming items,
e.g., if the "keep" evaluation had side effects on deep data shared between 
early
and later list items. But that would be nasty any which way ;-)

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


Re: What XML lib to use?

2005-09-14 Thread Robert Kern
Fredrik Lundh wrote:
> Paul Boddie wrote:
> 
>>>For stand-alone XML manipulation in Python, my point still stands:
>>>programs using DOM and SAX are more bloated and slower than
>>>the alternatives.
>>
>>Your point was that "there are no *sane* reasons to use SAX or DOM in
>>Python", which actually isn't true.
> 
> I replied in the context of this thread.  If you chose to ignore the
> context, or if you're not capable of reading and understanding the
> posts you're replying to, that's your problem.

His interpretation of your words is a perfectly valid one even in the
context of this thread. "in Python" explicitly provides a context for
the rest of the sentence. In English, at least, it is perfectly
reasonable to presume that explicit contexts override implicit ones.

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

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


Re: Example Script to parse web page links and extract data?

2005-09-14 Thread Steven Bethard
livin wrote:
> I'm looking for an easy way to automate the below web site browsing and pull 
> the data I'm searching for.

This is a task that BeautifulSoup[1] is usually good for.

> 4) After search, table shows many links (hundreds sometimes) to the actual 
> data I need.
> Links are this format... 
> 
> 5) Each link opens new window with table providing required data.
> The URLs that each href opens is this... 
> http://armls.marketlinx.com/Roster/Scripts/Member.asp?PubID=AA059 where the 
> PubID is record I need.

I'm not entirely sure I got your problem description right, but I think 
points 4 and 5 would look something like:

base_url = 'http://armls.marketlinx.com/.../Member.asp?PubID=AA059'
html = urllib.urlopen(base_url).read()
soup = BeautifulSoup.BeautifulSoup(html)

link_matcher = re.compile(r'javascript:GetAgent('[^']*')
for link_elem in soup('a', {'href': link_matcher}):
 ...

HTH,

STeVe

[1] http://www.crummy.com/software/BeautifulSoup/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Magic Optimisation

2005-09-14 Thread Terry Reedy

"Paul McGuire" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Terry -
>
> If setting up a try-block is as fast (or "takes as long") as one
> iteration loop, then wont putting a try-block inside a loop double the
> execution time?

It will double (more or less) the loop overhead.  The effect of that 
depends on the overhead/payload ratio.  And, I was responding to the idea 
that adding a loop to avoid most try statements would be significantly 
faster.

Terry J. Reedy



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


Re: Interface with C

2005-09-14 Thread Terry Hancock
On Wednesday 14 September 2005 12:34 pm, Ben Pearson wrote:
> I have a program that is developed in C, that has a simple text 
> interface. I would like to use the same program, but with a GUI. I 
> would like to use Python to interface with it, so that Python will 
> simply read and write the code that would be used from a normal user, 
> but using a TK GUI. For example, in the C program, if you type 0, it 
> will send a ping. I would like to build a program that will run the C 
> program, simply inputing the values that the Text interface would 
> use, but with the graphical interface. EI, the following should work.

If you are asking what I think you're asking, you need
to read up on the "subprocess" module (Python 2.4). There
are ways to do it with earlier versions, but everything I've
heard about this (and personal experience with the old way)
suggests you should just use 2.4's subprocess.

What I thought you said is that your C program runs its own
control loop, taking data from stdin and acting on it, presumeably
outputting to stdout if necessary.

Cheers,
Terry

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Re: Removing duplicates from a list

2005-09-14 Thread przemek drochomirecki
> I've a list with duplicate members and I need to make each entry
> unique.
>
> I've come up with two ways of doing it and I'd like some input on what
> would be considered more pythonic (or at least best practice).
>
> Method 1 (the traditional approach)
>
> for x in mylist:
> if mylist.count(x) > 1:
> mylist.remove(x)
>
> Method 2 (not so traditional)
>
> mylist = set(mylist)
> mylist = list(mylist)
>
> Converting to a set drops all the duplicates and converting back to a
> list, well, gets it back to a list which is what I want.
>
> I can't imagine one being much faster than the other except in the case
> of a huge list and mine's going to typically have less than 1000
> elements.
>
> What do you think?
>
> Cheers,
>
> Robin
>

Hi,

Try this:

def unique(s):
 e = {}
 for x in s:
  if not e.has_key(x):
   e[x] = 1
 return e.keys()

Regards
Przemek


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


strptime() doesn't recognize BST as a valid timezone

2005-09-14 Thread Adam Monsen
I'm unable to parse the following date string using time.strptime():
"Wed Sep 14, 2005 5:07 PM BST"

Format: "%a %b %d, %Y %I:%M %p %Z"

I tried changing the locale and using time.tzset(), but no luck. Is
there anyone in London (or some other BST location) that would try
running the following code?

import time
date_str = "Wed Sep 14, 2005 5:07 PM BST"
format = "%a %b %d, %Y %I:%M %p %Z"
time.strptime(date_str, format)

I get: "ValueError: time data did not match format: ..."

NOTE: there is a workable solution to getting this date into the proper
timezone ('Europe/London'), but I'm still unable to parse the 'BST'
part, even after setting the locale to en_GB.utf8 and the timezone to
'Europe/London'. Here's a solution to "zoning" naive date strings:
http://snipurl.com/hoqz (full url:
http://groups.google.com/group/comp.lang.python/browse_frm/thread/ce4909280561458b/
).

I did notice that the Python docs mention %Z is deprecated, so
http://snipurl.com/hoqz is possibly the best solution available for
now.

Thoughts?

--
Adam Monsen
http://adammonsen.com/

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


Example Script to parse web page links and extract data?

2005-09-14 Thread livin
I'm hoping someone knows of an example script I can see to help me build 
mine.

I'm looking for an easy way to automate the below web site browsing and pull 
the data I'm searching for.
Here's steps it needs to accomplish...

1) login to the site (windows dialog when hitting web page)  *optional*

2) Choose menu link from ASP page (script shows/hides menu items depending 
on mouseover) *optional*

3) Basic Search Form and enter zip code or city to pull all the data.

4) After search, table shows many links (hundreds sometimes) to the actual 
data I need.
Links are this format... 

5) Each link opens new window with table providing required data.
The URLs that each href opens is this... 
http://armls.marketlinx.com/Roster/Scripts/Member.asp?PubID=AA059 where the 
PubID is record I need.

Table format looks like this:







6



Alaze

Mark 


MA142





Banker Success 
Realty

COLD56











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


Re: What XML lib to use?

2005-09-14 Thread Fredrik Lundh
Paul Boddie wrote:

>> For stand-alone XML manipulation in Python, my point still stands:
>> programs using DOM and SAX are more bloated and slower than
>> the alternatives.
>
> Your point was that "there are no *sane* reasons to use SAX or DOM in
> Python", which actually isn't true.

I replied in the context of this thread.  If you chose to ignore the
context, or if you're not capable of reading and understanding the
posts you're replying to, that's your problem.

 



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


Re: some advice about Python GUI apps

2005-09-14 Thread Varghjärta
I'm not sure but wouldn't the simplest(perhaps) solution be to store a
reference to all the dialogs you open up in a mapped array of some
kind (dictionary) and whenever you are going to open up a dialog you
check if it already exists a key matching whatever id you choose. If
it exists then use the window refernce in there to make it go to
front, else make a new, shove it in there with an id(key) of some kind
and display it.

Perhaps I misunderstood the question though.

On 14 Sep 2005 04:26:11 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hi,
> 
> I am writing a program in Python and I am using wx.Python for the GUI.
> I have no prior GUI and Python experience so that's why I turn to the
> specialists for aid.
> Basically, my app is a wx.tree object with items. You can click on each
> item and set some properties of the item (Pydata). To set the
> properties of an item you click on the item and then a 'Set item
> properties' window pops up.
> However, I am looking for a way that you can only open 1 property
> window per item. If I click on an item the 'Set item properties'
> windows open but when I return to the tree window and select the same
> item, I can open an additional 'set properties' window. This leads to
> all kind of C++ errors because these properties windows seems to
> interfere for some reason. I don't have enough OO/Python/GUI knowledge
> yet to fully understand what actually happens.
> Basically, what I want is that when you want to open an items property
> window and the window is alread open that in stead of opening a new
> window, the window the is already open pops to the foreground. Any
> ideay how I can implement this.
> 
> Another solution would be to start the properties windows in a
> 'synchronous' mode, meaning that if this window is open, that you can't
> manipulate the tree window anymore (~like in Word when you open the
> 'open file' window, you can't edit your doc until you this window is
> closed again).
> 
> I hope this makes some sense.
> 
> Any help much appreciated.
> 
> Kris
> 
> Ps.: any refs to good OO/Python GUI books are also welcome (or URLs)
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: round() wrong in Python 2.4?

2005-09-14 Thread Robert Kern
Grant Edwards wrote:
> On 2005-09-14, Robert Kern <[EMAIL PROTECTED]> wrote:
> 
>>Antoon Pardon wrote:
> 
>>>0.0225 isn't representable and it happens that the actual number
>>>you get differ. Now which number python should choose when it is
>>>fed 0.0225, I don't know. But expressing the different behaviour
>>>as a change in round, suggest that the O.P. would be wise to
>>>learn about floating point problems
>>
>>Uhh, Python didn't change anything between 2.3 and 2.4 wrt round().
> 
> That's what Antoon Pardon just said. The above paragraph says
> that round() didn't change, and the fact that the OP thinks it
> did indicates that the OP needs to learn more about FP.

Antoon:
"Python 2.3 isn't rounding 0.0225 up while pyton 2.4 rounds it down."

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

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


Re: Software bugs aren't inevitable

2005-09-14 Thread Paddy
Thanks Giles,
I was hoping for a reply from someone close to Praxis like yourself,
but, I'm shocked when you said they use Perl as their scripting
language of choice, because I thought that with such an emphasis on
correctness and maintainability, that it would spill over into other
aspects of their flow.

Maybe they don't see scripting as part of their flow, but as merely
occasional 'duct tape'?

I did find an email address on the page you specified and have invited
Praxis to join in on this thread, or comment on Python in general.

- Paddy.

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


Re: What XML lib to use?

2005-09-14 Thread Paul Boddie
Fredrik Lundh wrote:
> Paul Boddie wrote:

[On interoperability]

> > For example, PyQt and PyKDE expose various DOMs of the purest
> > "non-Pythonic" kind; Mozilla exposes DOMs for XML and HTML
>
> I didn't see anything about manipulating an application's internal
> data structures in the original post, but I might have missed some-
> thing.

Well, manipulating documents in Mozilla and KHTML are just examples, as
I pointed out, and whilst I'd agree that the in-process restrictions
Mozilla appears to place on full participants in its component system
does kind of mean that the Mozilla DOM is an "application's internal
data structure", the opportunities are more open for KHTML in that one
isn't limited to just automating some application. Moreover, the XML
APIs exposed by PyQt are also available for general XML processing,
whether you regard them as performant or not.

> For stand-alone XML manipulation in Python, my point still stands:
> programs using DOM and SAX are more bloated and slower than
> the alternatives.

Your point was that "there are no *sane* reasons to use SAX or DOM in
Python", which actually isn't true. Sure, processing a 100GB XML
document using the DOM isn't a sensible strategy (with this generation
of hardware!), and SAX isn't necessarily the most elegant way of
expressing the processing logic, and other tools and APIs exist to
perform such tasks more efficiently and elegantly, but then "to
read/write XML files" leaves the questioner's field of endeavour pretty
much open to interpretation. Somewhere amongst the many fields of
endeavour there are places where the DOM (whilst not as "Pythonic" as
some might like) certainly is a valid choice, possibly because it's the
only choice - all thanks to interoperability, as I said. ;-)

Paul

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


Re: Software bugs aren't inevitable

2005-09-14 Thread Paddy
Hmm, They seem to have reorganised things.
As I write, the main article starts here:
  http://www.spectrum.ieee.org/sep05/2164
With the sidebar here:
  http://www.spectrum.ieee.org/sep05/2164/extsb1

- Paddy.

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


Event on executable launch

2005-09-14 Thread presentt
Hello,

Is there a way to make my Python program do something whenever any
executable is launched in Linux?  Like, for instance, a class that
represents the operating system or something?

Thanks a bunch.

~~Ted Present

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


Re: Unexpected Behavior Iterating over a Mutating Object

2005-09-14 Thread Dave Hansen
On Tue, 13 Sep 2005 21:28:21 GMT, [EMAIL PROTECTED] (Dave Hansen)
wrote:

>OK, first, I don't often have the time to read this group, so
>apologies if this is a FAQ, though I couldn't find anything at
>python.org.
>

Thanks to everyone who responded.  All is clear now.  And I know I
need to look deeper into list comprehensions...  

Regards,

   -=Dave
-- 
Change is inevitable, progress is not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: improvements for the logging package

2005-09-14 Thread skip

>> Changed now in CVS.  When 2.4.2 is released it should be there.

Trent> Is this the same kind of thing as the (generally ill-regarded)
Trent> change in Python 2.2.x (for some x != 0) that added:

No, I just backported the documentation bit that marked the keyword
parameter change to basicConfig() as happening in 2.4.  I didn't change any
code.

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


Re: ezPyCrypto

2005-09-14 Thread Maciej Dziardziel
[EMAIL PROTECTED] wrote:

> Hi!!
> 
> I finally decided to use ezPyCrypto for my project but I can't download
> it from http://www.freenet.org.nz/ezPyCrypto/ ...

Check this link now, it works for me.

-- 
Maciej "Fiedzia" Dziardziel (fiedzia (at) fiedzia (dot) prv (dot) pl)
www.fiedzia.prv.pl

Confession is good for the soul only in the sense that a tweed coat is
good for dandruff - it is a palliative rather than a remedy. - Peter DeVries
-- 
http://mail.python.org/mailman/listinfo/python-list


Using multiple threads with pcapy

2005-09-14 Thread billie
Hi all. Because of pcapy sniffng library doesn't permit to listen on 
multiple interfaces I'm trying to use threads to avoid this problem.
In the source below I tried to start a thread for every NIC installed on my 
system (I got 2 NICs) but once I started the first thread the program can't 
go further.
Note that the first trhread works properly (I can sniff traffic) but the 
problem is that the second thread regarding the other NIC never starts.
Does someone got any suggestion?

Thanks in advance.

http://rafb.net/paste/results/0NHfUm76.html 


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


Re: List of integers & L.I.S. (SPOILER)

2005-09-14 Thread Reinhold Birkenfeld
n00m wrote:
> Got it! He is a kind of pythonic monsters.
> 
> Btw, why it's impossible to reply to old threads?
> Namely, there're no more "Reply" link in them.
> Only "Reply to author" etc.

Perhaps because you are not using a real Usenet client?

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


Re: O'Reilly book on Twisted

2005-09-14 Thread Steve M
Does anybody know:

Is this book fully up to date with Twisted 2.0?

Does the book cover Nevow at all?

Does the book cover general programming concepts related to
concurrency? I'm reminded of those high quality articles about
Deferreds and event programming by one of the Twisted developers?

What is the relationship between the primary developers of Twisted and
the book?

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


Re: ezPyCrypto

2005-09-14 Thread Paul Rubin
[EMAIL PROTECTED] writes:
> My goal is to encrypt a nine-digit number so that it can be safely used
> as a student ID number.

Why don't you just use the build in stdlib functions as other people
have proposed?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ezPyCrypto

2005-09-14 Thread [EMAIL PROTECTED]
Why do you want to encrypt just the numbers?

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


Re: packaging python for install.

2005-09-14 Thread J
Hi


I found the solution to problem and I just want to document it for the
next guy. I
did not copy the content of the 'dist' directory created by Py2exe to
the folder containing my executable.

Changing HKEY_LOCAL_MACHINE\SOFTWARE\PythonCore\. alone
did not work for me... maybe I should have found and changed PYTHONPATH
as
well :) Anyways, now I have a solution.

thx for all the help

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


Re: HELP!! Accessing other machines with an IIS CGI script

2005-09-14 Thread Roger Upole
Without knowing what operation fails, it's kind of
difficult to give any meaningful answers.
At what point in the code do you get the error ?

If IIS runs under a local account, it might not have
permission to access the other machine, or to impersonate
a domain user.

You might want to set up auditing on the
folder you're trying to list, and see exactly what user
IIS is connecting as (or if it's connecting at all).

   hth
   Roger


"paulp" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> Greetings,
>
> I'm working on a CGI program that will run under MS IIS 5.0 and will
> browse folders on three other machines, building HTML pages that will
> provide links to these folders.
>
> Essentially, the CGI will connect to each machine in turn, doing the
> FindFirst/FindNext process based on the current criteria.  It will
> select certain files/folders, and build an HTML page as it goes.
>
> The premise is fine.  If I run the program from the command line, it
> seems to work fine and I get my HTML code out.  I can copy the code
> into a separate file, open it in the browser, and all appears right
> with the world.
>
> However, when I try to run the CGI from the browser itself, I get all
> kinds of problems.  The first one I got was a 1312, "A specified logon
> session does not exist.  It may have already been terminated."  After
> doing some searching, I began to investigate impersonation of a logged
> on user.  This produces a different error: 1314, "A required privilege
> is not held by the client."
>
> I've been arguing with this now for several days and the frustration
> level is beginning to get quite high.  Has anyone else ever tried this?
> I find it hard to believe that I'm the first to do this.
>
> Of course, one of my problems is that I'm neither an IIS guru nor an
> Admin guru.  And we have neither here in the office.
>
> I'm coding this in Python 2.4 and the Windows extensions.  I have a
> number of other CGI programs in Python running under IIS that work
> correctly, but those only do database accesses.  This one I'm trying to
> put together is the first one to actually do file searches.
>
> I have set the privileges for the logged on account on my IIS box for
> SE_TCB_NAME, SE_CHANGE_NOTIFY_NAME and SE_ASSIGNPRIMARYTOKEN_NAME and
> rebooted.  To no avail.  I'm not sure if there are additional
> alterations that need to be done to the security policies or not.
> Again, I'm not a guru.
>
> If anyone can give me more information/guidance I would greatly
> appreciate it.  If you need more information from me, I will do my best
> to provide it.
>
> TIA,
>
> Paul
> 



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


ezPyCrypto

2005-09-14 Thread jlocc
Hi!!

I finally decided to use ezPyCrypto for my project but I can't download
it from http://www.freenet.org.nz/ezPyCrypto/ ...

Does anyone know of a different mirror? Maybe a similar wrapper?

My goal is to encrypt a nine-digit number so that it can be safely used
as a student ID number.


THIS IS A SCHOOL PROJECT. NO NEED TO KILL NOBODY OVER EXPORT LAWS OR
UNSAFE PRACTICESpleas!!!

Thanks in advance, 
J

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


Re: Python Search Engine app

2005-09-14 Thread Alan Meyer

"Alan Meyer" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
...
> I stand ready to be corrected, but I think Python would not be a
> good language for writing search engines.  In the ones I've written
> for custom projects - in C or PL/1, it has been necessary to
> perform very high speed operations on highly compressed binary
> structures - which is not Python's forte.
>
> You might be able to put a Python interface over an engine written
> in another language.

It looks like the engines cited by the other responders to the query
are indeed mostly Python wrappings for C++ engines.

One that might not be, "lupy", notes under performance in the FAQ
the simple statement that "Java is faster".

As between Java and C++, I like Java much more as a programmer
friendly programming language, but I think I'd still choose C++ for
a search engine if the number of users or the size of the data was
large.

Alan 


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


Re: working with VERY large 'float' and 'complex' types

2005-09-14 Thread Fernando Perez
Todd Steury wrote:

> Greetings Python'ers:
> 
> I'm just an amature who occasionally uses Python for complex mathematical
> models. The current model I'm working with occasionally generates really
> large numbers that are either "float" or "complex" types. These numbers are
> so large that I either get an overflow error, or some funky code like #INF
> or 1.#INDj. However I really need these numbers to be calculated (although
> precision isn't key). Is there a way to get python to increase the size
> limit of float and complex numbers? I should mention that I'm using a lot of
> pre-made modules and functions like math.exp() and scipy.special.erf() that
> don't seem to be able to use available types like "Decimal" or "FixedPoint"
> (especially since these don't seem to handle complex numbers).

Python floats are C doubles underneath, so you're stuck.  You need extended
numeric types.  Decimal is slow as molasses, and was not designed for
mathematical work (rather for finance-type fixed-point work).  Use this
instead:

http://calcrpnpy.sourceforge.net/clnumManual.html

Cheers,

f

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


Re: Builtin classes list, set, dict reimplemented via B-trees

2005-09-14 Thread Bryan Olson
[EMAIL PROTECTED] wrote:
 > Here overhead is compared to a C array of > 1 million PyObject *s.
 >
 > Thus, on average, a > 1 million element B-tree uses 25% less memory
 > than any other balanced data structure which I am aware of, and 50%
 > more memory than a raw C array.

That's overhead of indexing; it doesn't consider the space
already used to store the keys and values. The B-tree can get by
with modestly fewer pointers, because it has fewer internal
nodes that need to be referenced by other internal pointers.
That assumes that the B-tree nodes are kept as linear arrays,
which means that either inserting into them will time
proportional to the fan-out, or searching them will.

[...]
 > I have no idea how B-trees compare to skip lists (the likely
 > contender) in terms of speed.

I'd expect Red-Black trees to be at least as good a contender.

 > Are there any *practical* applications for in-memory balanced data
 > structures (e.g. skip list, AVL tree, RB tree, B tree) ?

Yes, absolutely. Efficient ordered sub-ranges; efficient rank
queries; sustainable performance with adversarial inputs.


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


Re: Builtin classes list, set, dict reimplemented via B-trees

2005-09-14 Thread Tim Peters
[EMAIL PROTECTED]
> ...
> I've gotten bored and went back to one of my other projects:
> reimplementing the Python builtin classes list(), set(), dict(),
> and frozenset() with balanced trees (specifically, counted B-trees
> stored in memory).
>
> In short, this allows list lookup, insertion, deletion in O(log(N))
> time.  It allows the set and dictionary types to be maintained in
> order, and insert/lookup/remove operations here take O(log(N)) time
> as well.  Getting the k least or k greatest elements takes
> O(log(N)+k) time.

Note that BTrees for Python have been part of ZODB for many years:

Section 5.3, _BTrees Package_
http://www.zope.org/Wikis/ZODB/FrontPage/guide/node6.html

If you install ZODB, you can use its BTrees as in-memory data
structures without using any of the rest of ZODB.  If you want to
persist them, great, that's what ZODB is for.

Note that ZODB's are really B+ trees, so iterating over the smallest k
takes O(k) time.  As an extension to Python's mapping protocol, the
keys/values/items/iterkeys/itervalues/iteritems methods also accept
optional lower and upper bounds on the keys to return.

A gotcha:  For scalability in multiprocess database apps, ZODB's
BTrees do not store their size.  As a result, len(a_ZODB_BTree) takes
time linear in the number of elements.

> ...
> So my question is: are there any other *practical* applications of a
> B-tree based list/set/dict ?

Yes.

> In other words, is this module totally worth coding,

That's a different question entirely ;-)

> or is it just academic wankery and theoretical flim flam ? :)

It's probably not a way to get rich quick.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: working with VERY large 'float' and 'complex' types

2005-09-14 Thread Paul Rubin
"Todd Steury" <[EMAIL PROTECTED]> writes:
> or 1.#INDj. However I really need these numbers to be calculated (although 
> precision isn't key). Is there a way to get python to increase the size 
> limit of float and complex numbers? 

Python just uses machine doubles by default.  You might be able to edit
the source so it uses, say, 80-bit extended floats if you're on a machine
that supports them (like the x86).  Those do support larger exponents.

You could also use something like gmpy, which supports arbitrary size
and arbitrary precision numbers.  Of course it's slow by comparison.

> Since I learn best by example, how could one solve the following problem:
> 
> from math import exp
> >>>x=1000.
> >>>z=exp(x)
> 
> so that z returns an actual value

You could rearrange your formulas to not need such big numbers:

x = 1000.
log10_z = x / math.log(10)
c,m = divmod(log10_z, 1.)
print 'z = %.5fE%d' % (10.**c, m)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and SMB, again...

2005-09-14 Thread Atila Olah
Thank you, Larry, I'm figuring out the things right now.

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


Re: Python and SMB, again...

2005-09-14 Thread Atila Olah
Thank you, Larry, I'm figuring out things right now.

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


Re: Software bugs aren't inevitable

2005-09-14 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> It is a "mere implementation detail" that (for most computer systems, and
> most programming languages) stack space is at a premium and a deeply
> recursive function can run out of stack space while the heap still has
> lots of free memory.

Every serious FP language implementation optimizes tail calls and thus
using recursion instead of iteration doesn't cost any stack space and
it probably generates the exact same machine code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows Python 2.4: Unbuffered flag causes SyntaxError oninteractive sessions?

2005-09-14 Thread Lonnie Princehouse
Yes.  With the unbuffered flag, raw_input() strings on my box end in
\r.

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


Re: List of integers & L.I.S. (SPOILER)

2005-09-14 Thread Terry Reedy

"n00m" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Who is Raymond Hettinger?

The Python developer who, in the last few years, has perhaps been the most 
active in coding or recoding library modules, such as itertools and sets, 
in C.  He also partipates in development discussions, helps with 
SourceForge tracker items (RFEs, bugs, and patches) and occasionally posts 
here, especially about his modules, for which he is the expert.

Terry J. Reedy



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


Re: Interface with C

2005-09-14 Thread Eric Lavigne

> When this button is hit, it will send a code of 0 to the C
> program.
>
> ./mcp | python gui.py

Your pipe is backwards. Try this:
python gui.py | ./mcp

When your gui.py notices that a button got hit, it can just print the
number 0 (followed by a newline character) to standard output. This
becomes the input to ./mcp, which responds by sending a ping.

Of course, this only works if gui.py does not need to see the output of
./mcp

> Is there a way to do this with Python, to be able
> to read the output of the mcp program, and to
> send data to it, as if it were just a person at the
> computer converting?

Ouch, so you need two way interaction. Are you sure about this? Will
your gui program need to change its behavior based on the output of
mcp? If so, then the simple interface offered by pipes is no longer an
option. You will need to call mcp from within your script. To see how
this sort of thing is done, study the following short script:

# mimics the following shell command:
# debug\curve-fit output.txt

  import os

  inputfilename = 'input.txt'
  outputfilename = 'output.txt'

  inputfile = open(inputfilename,'r')
  outputfile = open(outputfilename,'w')
  inputstream,outputstream = os.popen2("debug\\curve-fit")
  inputstream.write(inputfile.read())
  inputfile.close()
  inputstream.close()
  outputfile.write(outputstream.read())
  outputstream.close() 
  outputfile.close()

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


Re: Windows Python 2.4: Unbuffered flag causes SyntaxError oninteractive sessions?

2005-09-14 Thread Michael Hoffman
Lonnie Princehouse wrote:

> Evidently the unbuffered flag not only makes stdin unbuffered, but it
> also forces it into binary mode.  I didn't realize that when I posted
> earlier.
> 
> So the SyntaxErrors arise because the interpreter isn't converting \r\n
> into \n because stdin is binary.  Not a bug, although it would be nice
> to have an "unbuffered text mode" flag too...

so if you do this:

 >>> z = raw_input()
zzz

Does z contain 'zzz\r'?

For me, it just contains 'zzz'.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Find day of week from month and year

2005-09-14 Thread Terry Reedy

> Laguna wrote:
>> I want to find the expiration date of stock options (3rd Friday of the
>> month) for an any give month and year.

>From year and month (and day=1) get the day of the week (n in [0,6]) of the 
first of the month using some version of the the standard formula (see 
below) and look up the third friday date in a precalculated 7-element list, 
or, with n=0 on Saturday, 3rd Friday is 21-n

Here is a translation of the guts of a 30-year-old Basic program:

def friday3(m,y): # ints
  if m <= 2:
m += 12
y -= 1
  d = 1
  n = d + 2*m + int(.6*(m+1)) + y + y//4 - y//100 + y//400 + 2
  n = int((n/7.0- n//7)*7.0 + .5)
  # n=0 is Saturday, making 3rd Friday the 21st.
  return 21 - n

>> Requirements:
>> d0 = expiration(9, 2005) # d0 would be 16
>> d1 = expiration(6, 2003) # d1 would be 20
>> d2 = expiration(2, 2006) # d2 would be 17

>>> for m,y in ((9,2005), (6,2003), (2,2006)): print friday3(m,y)
...
16
20
17

Terry J. Reedy



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


Re: PyGTK or wXPython?

2005-09-14 Thread Jarek Zgoda
Paul McNett napisał(a):

>> I would use wx, if it wasn't so dog slow on linux. Qt and GTK are much
>> faster, but each one has disadvantages. Finally, you get 3 GUI toolkits,
>> of which each claims to be "cross-platform", but each is working at
>> acceptable level of WTF only on one system (wx on Windows, Qt and GTK on
>> linux) and the most appealing (Qt) has no free version for Windows.
> 
> I must say, I haven't found wx to be slow on Linux at all. Slow on Mac,
> yes, but faster on Linux than on Windows (and getting much much better
> on Mac). The exception to this is the StyledTextControl, which is by far
> much faster on Windows, and with lots of styled text dog-slow on Linux.
> 
> Wx does use the native underlying toolkit for the platform (Qt is
> owner-drawn), which can cause some platform inconsistencies.

GTK is "native" on Gnome or Xfce desktops, so programs written with
PyGTK/wxPython may have shorten startup times than comparable PyQt
applications. On KDE the Qt toolkit is "native", so GTK and wx
applications would be much slower, as there will be need to load the
whole GUI toolkit library at your program startup.

-- 
Jarek Zgoda
http://jpa.berlios.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


packaging python for install.

2005-09-14 Thread J
Hi everyone,


I have posted a question on this topic before and already received some
useful advice. I am basically trying to package python with
an App that embedds the interpretor. I am also including numarray (i.e.
I have a #include  in my C++ code).  However it
looks like I have problems with numarray.

I have run the following:

>>python setup.py py2exe --includes numarray

where

>setup.py contains
>
>from distutils.core import setup
>import py2exe
>
>setup()

This produced the 'dist' directory including the library.zip file.
However there was also the following error message:

>The following modules appear to be missing
>['numarray._dotblas']

I renamed library.zip to python24.zip and changed the registry entry
PythonDir to c:\python24\dist... Then I started my app again. It seems
that native python (i.e. PyType_READY) worked fine, but a call to
numarray function PyArray_FromDimsAndData just crashes the App without
an error message.

I have also tried using

>>python setup.py py2exe -p numarray

without success. Has anyone packaged numarray before... any advice ?


Cheers
Jochen

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


Re: Python Search Engine app

2005-09-14 Thread Kent Johnson
gene tani wrote:
> Yes, there's a bunch.  Google for "query parser" + python, "porter
> stemming" "stopwords" "text indexer".  Maybe lucene has some python
> bindings, hmm?

At least two Python versions of Lucene:
http://pylucene.osafoundation.org/
http://divmod.org/projects/lupy

Kent

> 
> Harlin Seritt wrote:
> 
>>Hi,
>>
>>Is anyone aware of an available open-source/free search engine app
>>(something similar to HTDig) written in Python that is out there?
>>Googling has turned up nothing. Thought maybe I'd mine some of you
>>guys' minds on this.
>>
>>thanks,
>>
>>Harlin Seritt
>>Internet Villa: www.seritt.org
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Software bugs aren't inevitable

2005-09-14 Thread Steven D'Aprano
On Wed, 14 Sep 2005 14:32:17 +0200, Jerzy Karczmarczuk wrote:

> First of all, the recursive version of Fibonacci IS EXPONENTIAL in complexity,
> don't say such not-quite-truth as "not quite". 

Your correction is noted. I had compared the work done with 2**n, but of
course any constant greater than one can exhibit exponential growth.

Out of interest, the number of recursive calls (including the first
function call) made when calculating the nth Fibonacci number are
themselves part of a Fibonacci-like sequence. Look at the 1st order
differences:

n   Fib(n)  Calls  1st Diff
0:  0   1  N/A
1:  1   1  0
2:  1   3  2
3:  2   5  2
4:  3   9  4
5:  5   15 6
6:  8   25 10
7:  13  41 16
8:  21  67 26
9:  34  10942
10: 55  17768
11: 89  287110
12: 144 465178

Notice the pattern?


> But, what is more important:
> 
> If you don't know too much about the way the functional programming is
> used nowadays, please refrain from giving nonsensical examples, since
> NOBODY serious programs something in the style of your recursive version.

I never said that my recursive version was a practical implementation.
But it is a very common algorithm -- I have four or five textbooks at home
that give it. In many textbooks and programming courses, the first
algorithm given to introduce the principle of recursion is either
factorial or the Fibonacci sequence. For example:

http://www.math.pitt.edu/~wjl/nm99.html

gives the same naive recursive implementation in Fortran.

If you google for Fibonacci sequences, you will find dozens,
possibly hundreds, of implementations virtually identical to the one I
gave. Also significant numbers of Java apps that run slow for values of n
larger than 30 or 40 -- a good sign that they are using the naive
algorithm.

It is a rare under-graduate or secondary school textbook that suggests
that the naive algorithm is anything but a poor idea.


> Such anti-advertizing of recursion says less about the recursion
> than about yourself.

Yeah, whatever.


> Here you are a recursive version linear in n; it
> returns the two last Fibonacci numbers of the sequence
> 
> def fibo(n):
>   if n<2:
>  return (n-1,n)
>   else:
>  (a,b)=fibo(n-1)
>  return (b,a+b)

Ah, I like this algorithm! I'll add it to my collection. Thank you.


-- 
Steven.

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


Re: stdin and py2exe

2005-09-14 Thread Thomas Heller
"Mike Tammerman" <[EMAIL PROTECTED]> writes:

> Yes, it throws exceptions if I build the exe of the subprogram.py.
>
> So, is it possible to pipe some data to another py2exe'd application
> without a console.

I did this just some days ago.  It required a little bit of
experimenting.  This code executes the Windows XP ftp.exe console
program (but doesn't show a console), and reads its output. Here is the
relevant code snippet:

from subprocess import Popen, PIPE, STDOUT
# It seems subprocess doesn't open a console by default
# when run from a windows program
#
# Plus: For whatever reason, when running as py2exe'd GUI
# program, stdin=None doesn't work.  We HAVE to specify PIPE for 
stdin,
# and we HAVE to use '... < NUL', and then stdin.close().
p = Popen("ftp.exe -s:upload.txt %s < NUL" % self._address,
  cwd=os.path.join(util.get_main_dir(), "blah"),
  shell=True,
  stdin=PIPE,
  stdout=PIPE,
  stderr=STDOUT
  )
p.stdin.close()
text = ""
while 1:
data = p.stdout.readline()
if not data:
break

if p.wait():

return

The problem was that passing 'stdin=None' didn't work, for whatever
reason.  I don't think it is a py2exe problem although the comment above
may suggest it.

Hope that helps,

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


Re: How to make python24.dll smaller ?

2005-09-14 Thread Martin v. Löwis
Stormbringer wrote:
> Final result: a 1.1 MB python24.dll which works with my frozen apps and
> is not dependent on msvcr71.dll and compressed goes to around 440 KB.
> And I'm sure that depending on the project I still could trim some more
> modules out.

If you are building yourself, anyway, I recommend an even more drastic
approach (which, alas, requires more work also): build a static library
for all the extension modules, and then use freeze to generate the
config.c. Linking it all together will bring in just those modules which
are actually referenced in config.c, and freeze will guess what modules
to put into config.c based on import statements. You might be able
to trim it further by explicitly excluding modules on the freeze command
line if you happen to know that some import statements are never
executed in your application (this is actually worthwhile for the
Python modules as well).

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


Re: Windows Python 2.4: Unbuffered flag causes SyntaxError oninteractive sessions?

2005-09-14 Thread Lonnie Princehouse
After doing some more reading, I now think this isn't a bug.

Evidently the unbuffered flag not only makes stdin unbuffered, but it
also forces it into binary mode.  I didn't realize that when I posted
earlier.

So the SyntaxErrors arise because the interpreter isn't converting \r\n
into \n because stdin is binary.  Not a bug, although it would be nice
to have an "unbuffered text mode" flag too...

D'oh.

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


Re: improvements for the logging package

2005-09-14 Thread Trent Mick
[EMAIL PROTECTED] wrote]
> >> It does, in the "in-development" version of the documentation. Sorry it
> >> was not in the 2.4 releases :-(
> 
> Thomas> Maybe it can be backported to 2.4.2 - is there still time for 
> that?
> 
> Changed now in CVS.  When 2.4.2 is released it should be there.

Is this the same kind of thing as the (generally ill-regarded) change in
Python 2.2.x (for some x != 0) that added:
True, False = 0, 1
I may have the details wrong.

Now there is a feature in 2.4.x that wasn't in 2.4.(x-1), which could
cause surprises. I.e. I write code that uses the new thing, test it with
my 2.4.2 install, think that is works with 2.4.* and say so when I
distribute it. 

Maybe that is okay.  Just asking here because I don't keep up with
Python changes -- or sentiment on how to handle this kind of thing --
well enough.

Trent

-- 
Trent Mick
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: stdin and py2exe

2005-09-14 Thread Mike Tammerman
Yes, it throws exceptions if I build the exe of the subprogram.py.

So, is it possible to pipe some data to another py2exe'd application
without a console.

Mike

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


Re: Django Vs Rails

2005-09-14 Thread Jeff Shell
My opinion, as posted there, was pretty immediate and only going off of
surface values. I just saw in Django what I had seen too much of in my
own code. I've written similar things in Zope and Formulator that did
all sorts of fancy automatic 'admin screen' generation, DBMS CRUD
statements. I even applied those same tricks to LDAP with some success.
So some of what I saw with Django reminded me of code that I both loved
and hated - it made my data management work easy, but it was ugly and
hard to navigate and maintain, and I could never remember even my own
shortcuts and options of what to have in my nested dictionaries and
lists and tuples that defined all of these structures.

It was also an all-too-quick response in that I perceived, wrongly,
that Django was another Rails clone. I was quickly corrected on this,
and believe I posted a correction later. As I've said in some other
posts on my site - I don't really care much for the Python "Web
Frameworks" which go off and try to mimic the technology of the day.
I've been through competing with Perl, with Servlets, with J2EE, with
PHP/ASP, and now with Rails, and just about every implementation I've
seen of these has been underwhelming, to say the least. I myself am
guilty of writing an early WebObjects inspired toolkit back in '96.
Django is its own thing, and I give it credit for that. Some recent
changes to the Django model syntax make it more palatable to my tastes,
but I doubt that I'll personally be leaving Zope 2 or 3 for any of
these systems any time soon. Zope / Principia / Bobo have all served me
well for nearly a decade now, and Zope 3 makes ZODB based Zope
development so easy and powerful that I hope to never have need of an
ORM system again. These ORM tools like SQLObject and ActiveRecord still
seem best suited for writing applications from scratch. Ian Bicking and
Django people both have stated here that you can "conveniently generate
SQL/DDL to populate the DB". If that's the situation, an object
database like the ZODB or Durus may work just as well, without the
translation to SQL and back. ORM only gets interesting to me these days
when I have to map to to large scale pre-existing systems, and even
there I'm having better experiences with other styles of storage to
application data translation, validation, security, and management.

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


Re: Software bugs aren't inevitable

2005-09-14 Thread Steven D'Aprano
On Wed, 14 Sep 2005 11:28:02 -0400, Terry Reedy wrote:

> 
> "Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> Which works wonderfully as an academic exercise, but doesn't tend to work
>> so terribly well in the real world where the performance and
>> resource-requirement differences between iteration and recursion can be
>> significant.
> 
> I think your comparison is incomplete.

Yes, it is incomplete.

It seems that I've given the mistaken impression that I am opposed to
recursion in principle. I am not. Perhaps I should have qualified my
remarks by stating that sometimes recursion can be easier to comprehend
than iteration, more efficient and all those other goodies that developers
like their programs to be. A good example of a task that is frequently
better solved with recursion than with iteration is walking a binary tree.

But in the context of my response, I was replying to a paraphrased quote
from somebody who apparently believes that recursion is *always* better
than iteration. That is clearly not the case.

It is a "mere implementation detail" that (for most computer systems, and
most programming languages) stack space is at a premium and a deeply
recursive function can run out of stack space while the heap still has
lots of free memory. But those implementation details in the real world
make the difference between an elegant solution that runs like a lame duck
and an practical solution that has nothing going for it except the fact
that it works.

(And then there are the elegant solutions that are also practical. It is a
good day when you find yourself writing one of those.)

Recursion is frequently extravagant in its use of resources: if nothing
else, it takes resources to call a function, and recursion means you call
the same function over and over again. There is a reason why functional
programming never really took off.

Extravagance is not necessarily a bad thing -- if I thought it were, I
wouldn't be using a high-level object-oriented language like Python. But
it is important to be aware of those factors.


> Recursion and iteration are two syntaxes for the same operation: repetition 
> with variation.

Yes, in general anything that can be solved recursively can be solved
iteratively. Some classes of problems lend themselves naturally to one or
the other solution, but it is always possible (in principle at least) to
use either.


> Abstractly, these are two algorithms for the same function.  One runs in 
> exponential time because it wastefully calculates and tosses away an 
> exponential number of subvalues.  The other runs in linear time because it 
> calculates each subvalue once.  When one only wants Fib(n), and not the 
> sequence leading up to it, even this is wasteful, for large enough n, since 
> there is a third algorithm that caluculates Fib(n) directly by a simple 
> formula (something like the interger part of the golden ratio to the nth 
> power).

Yes. There are lots of algorithms that could be done, and they all have
their pros and cons. Biset's formula, for example, is mathematically
correct, but for large enough n, the "mere implementation detail" that
floats have a finite precision will cause that algorithm to give incorrect
answers. For "large enough", on my system I mean n=71.


> Now: I could (and probably someday will) write an iterative version of the 
> exponential algorithm (using an explicit stack) that calculates each 
> subvalue exactly as many times as the recursive version of that same 
> algorithm.  And I could compare it to a recursive version of the more 
> efficient linear algorithm (such as posted by Jerzy Karczmarczuk).  And I 
> could claim that this shows hows iteration can waste time compared to 
> recursion.

Of course it can. But you have to really *work* at getting the iterative
version to be as wasteful as the obvious recursive version.

> But that, I admit, would be an invalid conclusion.  And that, I claim,
> is also invalid when 'iteration' and 'recursion' are reversed, no matter
> how often repeated in texts and articles.  The difference is between the
> algorithms, not the differing syntactic expressions thereof.

Now you go too far. You are right that a change of algorithm will often
make a much bigger difference to performance than merely swapping from one
form of repetition to another. But you ignore those "mere implementation
details" that lead to exceptions like this one:

RuntimeError: maximum recursion depth exceeded

(eg calling Jerzy Karczmarczuk's efficiently recursive function with
n=1000, while my iterative version works for at least values of n an order
of magnitude larger.)

Yes, the maximum recursion depth in Python is an artificial limit. But
that artificial limit is built into Python specifically to protect you
from running into a real recursion limit based on the hardware and
architecture of your PC, with painful consequences.


-- 
Steven.

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

Re: Python on AIX 4.3.

2005-09-14 Thread David Gutierrez
Alessandro,
No, Im not trying to install a posix thread. I was just doing a straight 
forward installation in AIX 4..3.3.

David


From: Alessandro Bottoni <[EMAIL PROTECTED]>
Reply-To: [EMAIL PROTECTED]
To: python-list@python.org
Subject: Re: Python on AIX 4.3.
Date: Wed, 14 Sep 2005 16:32:46 GMT
MIME-Version: 1.0
Received: from smtp-vbr9.xs4all.nl ([194.109.24.29]) by mc7-f4.hotmail.com 
with Microsoft SMTPSVC(6.0.3790.211); Wed, 14 Sep 2005 09:36:44 -0700
Received: from bag.python.org (bag.python.org [194.109.207.14])by 
smtp-vbr9.xs4all.nl (8.13.3/8.13.3) with ESMTP id j8EGahbh078191for 
<[EMAIL PROTECTED]>; Wed, 14 Sep 2005 18:36:43 +0200 (CEST)(envelope-from 
[EMAIL PROTECTED])
Received: from bag.python.org (bag [127.0.0.1])by bag.python.org (Postfix) 
with ESMTP id EA1011E42DCfor <[EMAIL PROTECTED]>; Wed, 14 Sep 2005 
18:35:41 +0200 (CEST)
X-Message-Info: JGTYoYF78jEitB2IpXZKOzKsRwmxNvyoBOSEeaB+NVk=
Path: 
news.xs4all.nl!newsspool.news.xs4all.nl!transit.news.xs4all.nl!news.tele.dk!news.tele.dk!small.news.tele.dk!news.mailgate.org!nntp.infostrada.it!twister2.libero.it.POSTED!not-for-mail
Newsgroups: comp.lang.python
Mail-Copies-To: [EMAIL PROTECTED]
References: <[EMAIL PROTECTED]>
Lines: 32
User-Agent: KNode/0.8.2
NNTP-Posting-Host: 151.37.234.42
X-Complaints-To: [EMAIL PROTECTED]
X-Trace: twister2.libero.it 1126715566 151.37.234.42 (Wed,14 Sep 2005 
18:32:46 MET DST)
NNTP-Posting-Date: Wed, 14 Sep 2005 18:32:46 MET DST
Organization: [Infostrada]
Xref: news.xs4all.nl comp.lang.python:395365
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.6
Precedence: list
List-Id: General discussion list for the Python programming 
language
List-Unsubscribe: 
,
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: 
,
Errors-To: [EMAIL PROTECTED]
X-Virus-Scanned: by XS4ALL Virus Scanner
Return-Path: [EMAIL PROTECTED]
X-OriginalArrivalTime: 14 Sep 2005 16:36:45.0152 (UTC) 
FILETIME=[7E887E00:01C5B94A]

David Gutierrez wrote:

 > Hello Everyone,
 > I'm trying to install Python on an aix 4.3.3. but keep on getting a 
failed
 > attempt with the following errors.
 >
 > ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_lock
 > ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_unlock
 > ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_signal
 > ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_wait
 > ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_destroy
 > ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_destroy
 > ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_init
 > ld: 0711-317 ERROR: Undefined symbol: .pthread_cond_init
 > ld: 0711-317 ERROR: Undefined symbol: .pthread_self
 > ld: 0711-317 ERROR: Undefined symbol: .pthread_attr_init
 > ld: 0711-317 ERROR: Undefined symbol: .pthread_attr_setscope
 > ld: 0711-317 ERROR: Undefined symbol: .pthread_create
 > ld: 0711-317 ERROR: Undefined symbol: .pthread_attr_destroy
 > ld: 0711-317 ERROR: Undefined symbol: .pthread_detach
 > ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more
 > information.
 > collect2: ld returned 8 exit status
 > make: 1254-004 The error code from the last command is 1.

Are you trying to install a posix-thread- (pthread) -enabled Python
interpreter on a not-pthread machine? It looks like the pthread module is
missing.

HTH
---
Alessandro Bottoni
--
http://mail.python.org/mailman/listinfo/python-list


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


Re: stdin and py2exe

2005-09-14 Thread Thomas Heller
"Mike Tammerman" <[EMAIL PROTECTED]> writes:

> Hi,
>
> I want create a subprocess using Popen and pipe some input to it.
> Although everything works perfectly while executing python in, it
> doesn't work if I try with executables made by py2exe.
>
> I think, stdin is invalidated if the program becomes an executable.
> Because I get a "Bad file descriptor" exception in subprogram.py. I
> will be more than apreciated, if any suggestions occur.
>
> Thanks,
> Mike
>
> == main.py ==
> from subprocess import *
>
> pInput = Popen('python subprogram.py', stdin=PIPE, shell=True).stdin
> # pInput = Popen('subprogram.exe', stdin=PIPE, shell=True).stdin #
> doesn't work
>
> pInput.write('Data')
> pInput.close()
>
>
> == subprogram.py ==
> import sys
>
> input = sys.stdin.read()  # Throws a bad descriptor exception.
> print input

Can it be that you're building a windows exe of subprogram.py? I get the
error you describe when I do that,  for console programs it works -
both in the Python script and in the py2exe'd version.

This is, afaik, standard windows behaviour: GUI programs start with
stdin, stdout and stderr closed.

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


working with VERY large 'float' and 'complex' types

2005-09-14 Thread Todd Steury
Greetings Python'ers:

I'm just an amature who occasionally uses Python for complex mathematical 
models. The current model I'm working with occasionally generates really 
large numbers that are either "float" or "complex" types. These numbers are 
so large that I either get an overflow error, or some funky code like #INF 
or 1.#INDj. However I really need these numbers to be calculated (although 
precision isn't key). Is there a way to get python to increase the size 
limit of float and complex numbers? I should mention that I'm using a lot of 
pre-made modules and functions like math.exp() and scipy.special.erf() that 
don't seem to be able to use available types like "Decimal" or "FixedPoint" 
(especially since these don't seem to handle complex numbers).

Since I learn best by example, how could one solve the following problem:

from math import exp
>>>x=1000.
>>>z=exp(x)

so that z returns an actual value

Thanks in advance for any advice!

Todd 


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


HELP!! Accessing other machines with an IIS CGI script

2005-09-14 Thread paulp
Greetings,

I'm working on a CGI program that will run under MS IIS 5.0 and will
browse folders on three other machines, building HTML pages that will
provide links to these folders.

Essentially, the CGI will connect to each machine in turn, doing the
FindFirst/FindNext process based on the current criteria.  It will
select certain files/folders, and build an HTML page as it goes.

The premise is fine.  If I run the program from the command line, it
seems to work fine and I get my HTML code out.  I can copy the code
into a separate file, open it in the browser, and all appears right
with the world.

However, when I try to run the CGI from the browser itself, I get all
kinds of problems.  The first one I got was a 1312, "A specified logon
session does not exist.  It may have already been terminated."  After
doing some searching, I began to investigate impersonation of a logged
on user.  This produces a different error: 1314, "A required privilege
is not held by the client."

I've been arguing with this now for several days and the frustration
level is beginning to get quite high.  Has anyone else ever tried this?
 I find it hard to believe that I'm the first to do this.

Of course, one of my problems is that I'm neither an IIS guru nor an
Admin guru.  And we have neither here in the office.

I'm coding this in Python 2.4 and the Windows extensions.  I have a
number of other CGI programs in Python running under IIS that work
correctly, but those only do database accesses.  This one I'm trying to
put together is the first one to actually do file searches.

I have set the privileges for the logged on account on my IIS box for
SE_TCB_NAME, SE_CHANGE_NOTIFY_NAME and SE_ASSIGNPRIMARYTOKEN_NAME and
rebooted.  To no avail.  I'm not sure if there are additional
alterations that need to be done to the security policies or not.
Again, I'm not a guru.

If anyone can give me more information/guidance I would greatly
appreciate it.  If you need more information from me, I will do my best
to provide it.

TIA,

Paul

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


Re: List of integers & L.I.S. (SPOILER)

2005-09-14 Thread n00m
Got it! He is a kind of pythonic monsters.

Btw, why it's impossible to reply to old threads?
Namely, there're no more "Reply" link in them.
Only "Reply to author" etc.

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


  1   2   3   >