GUI and textfield

2007-11-10 Thread isabelle . bardelang
Hello,
I am trying to create a GUI in python/pylab (latest versions) with a
textfield. The information from the textfield shall be read out, if a
specific button is pressed. How can I create such textfield?
Thank Isabelle

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


Re: Looking for a good Python environment

2007-11-10 Thread jwelby
On Nov 7, 12:42 pm, "Colin J. Williams" <[EMAIL PROTECTED]> wrote:
> jwelby wrote:
...
>
> > I currently use Python Scripter as a lightweight editor for Windows.
>
> Could you elaborate on "lightweight"
> please? I find PyScripter to be a
> powerful editor/debugger combination.
>
> What functionality does Eclipse have
> that PyScripter does not?
>
> Colin W.
>

This is a fair question. I didn't phrase my post too well.

I find PyScripter does pretty much everything I need in terms of doing
actual development for Python. My use of 'lightweight' is by no means
a criticism of PyScripter - it's more of a compliment, as it refers to
the relatively modest demands that it makes on my system compared with
Eclipse, which can be hog.

The main reason I have used Eclipse for larger, team based, projects
is for the source control plug-ins. Eclipse has plug-in support for
cvs and svn. PyScripter may have this too - perhaps I've missed it.
(I'm away from my Windows box at the moment, otherwise I would check).
Of course, there are other ways to implement source control without it
needing to be integrated in the IDE, so even this need not put off
anyone who wants to use PyScripter with source control.

Summary - unless you need the added flexibility offered by Eclipse
plug-ins, PyScripter is a great tool for developing with Python on
Windows.

>
> > For project work I use Eclipse, which can be installed with PyDev and
> > other useful plug-ins already included if you choose a suitable
> > distribution of Easy Eclipse (http://www.easyeclipse.org/). There is a
> > distribution specifically for Python development, and also one for
> > LAMP, which includes a number of other components which will be of use
> > if you are developing for the web.


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


Image treshold

2007-11-10 Thread Johny
Can anyone give me an example how to apply a threshold value to an
image?

(everything above a certain brightness level becomes white, and
everything below the
 level becomes black.)

I was told I should use 256-item mapping table and pass it to the
"point" method.

But how should the 256-item mapping table  look like, if the threshold
is 18( found from the histogram)


Thank you for any hint.
L.

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


Re: Global variables within classes.

2007-11-10 Thread uestc_mahui
On 11 10 ,   5 48 , Donn Ingle <[EMAIL PROTECTED]> wrote:

> ## == API in another module perhaps ===
> Class Stack:
>  def push(self,stuff):
>   pass
>
> Class Canvas:
>  def do(self):
>   s.push("data") #I don't feel right about 's' here.
>
> Class Thing:
>  def buzz(self):
>   print s.pop(0)
>
> ## == User space code area ===
> s = Stack() #I want to avoid this direct naming to 's'
> c = Canvas()
> c.push("bozo")
> t = Thing()
> t.buzz()
>
> Hope that makes more sense.
> \d


If you mean that all instances of Class Canvas and Thing will share
the *same* Stack, I think we can do it kind of like this:
## == API in another module perhaps ===
class Stack:
list = []
def push(self, item):
self.list.append(item)
def pop(self):
item = self.list[-1]
del self.list[-1]
return item

class Canvas:
def __init__(self):
self.s = Stack()
def push(self, item):
self.s.push(item)

class Thing:
def __init__(self):
self.s = Stack()
def buzz(self):
print self.s.pop()

## == User space code area ===
c = Canvas()
c.push("bozo")
t = Thing()
t.buzz()

or: if you want a pair of instances of class Canvas and class Thing
share
the *same* instance of class Stack, maybe we can make it like this:
## == API in another module perhaps ===
class Stack:
def __init__(self):
self.list = []
def push(self, item):
self.list.append(item)
def pop(self):
item = self.list[-1]
del self.list[-1]
return item

class Canvas:
def __init__(self, stack = Stack()):
self.s = stack
def push(self, item):
self.s.push(item)
def getStack(self):
return self.s

class Thing:
def __init__(self, stack = Stack()):
self.s = stack
def buzz(self):
print self.s.pop()
def getStack(self):
return self.s
## == User space code area ===
c = Canvas()
c.push("bozo")
t = Thing(c.getStack())   #associate t with c
t.buzz()

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


Re: Python IDE

2007-11-10 Thread D.Hering
On Nov 3, 9:11 am, Simon Pickles <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have recently moved from Windows XP to Ubuntu Gutsy.
>
> I need a Python IDE and debugger, but have yet to find one as good as
> Pyscripter for Windows. Can anyone recommend anything? What are you all
> using?
>
> Coming from a Visual Studio background, editing text files and using the
> terminal to execute them offends my sensibilities :)
>
> Thanks
>
> Si

Eric4 is and excellent graphical IDE with built-in debugger, profiler,
project management, a RAD Qt4 builder (Qt designer), and all sorts of
other goodies.

http://www.die-offenbachs.de/eric/index.html

IMO, it's the way to go for Python development.
And since I prefer KDE (Kubuntu) over Gnome (Ubuntu) there's an even
greater attraction! Gotta love KDE.

-dieter

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


Re: Looking for a good Python environment

2007-11-10 Thread Paul Rudin
jwelby <[EMAIL PROTECTED]> writes:


> This is a fair question. I didn't phrase my post too well.
>
> I find PyScripter does pretty much everything I need in terms of doing
> actual development for Python. My use of 'lightweight' is by no means
> a criticism of PyScripter - it's more of a compliment, as it refers to
> the relatively modest demands that it makes on my system compared with
> Eclipse, which can be hog.
>
> The main reason I have used Eclipse for larger, team based, projects
> is for the source control plug-ins. Eclipse has plug-in support for
> cvs and svn. PyScripter may have this too - perhaps I've missed it.
> (I'm away from my Windows box at the moment, otherwise I would check).
> Of course, there are other ways to implement source control without it
> needing to be integrated in the IDE, so even this need not put off
> anyone who wants to use PyScripter with source control.
>
> Summary - unless you need the added flexibility offered by Eclipse
> plug-ins, PyScripter is a great tool for developing with Python on
> Windows.

I'm not sure if you count emacs as "lightweight" but it's certainly
less resource hungry than eclipse/pydev, and does have integrated
cvs/svn functionality.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python IDE

2007-11-10 Thread TheFlyingDutchman
On Nov 3, 6:11 am, Simon Pickles <[EMAIL PROTECTED]> wrote:

> Coming from a Visual Studio background, editing text files and using the
> terminal to execute them offends my sensibilities :)

YOu should take a look at Wing IDE Professional - www.wingware.com


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


Re: Writing a CGI to query DB

2007-11-10 Thread TheFlyingDutchman
On Nov 9, 8:33 pm, Bighead <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am currently working on a CGI deployed on an Apache server, which,
> given an arbitrary SQL, fetches raw data from a remote DB server and
> return them in a HTML page. This CGI works fine on quick SQLs.
>
> But when I try to run a slow SQL on this CGI, through a Squid Proxy, I
> always get the Error message from Squid: Zero Sized Reply, after 5
> minutes.
>
> The SQL itself is correct, since I have tried it directly on the DB
> server. So what do you think might cause the problem? Thank you.

Slow SQL = query that takes a long time? How long does the query take
if you run it on the same machine as the DB server without a Squid
Proxy?

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


Re: Returning actual argument expression to a function call?

2007-11-10 Thread Paddy
On Nov 10, 6:54 am, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:

> In the second example, if you are trying to capture the expression "0.4
> +1", I don't think that is possible. As far as I know, there is no way
> for the called function to find out how its arguments were created. I
> think if you need that, you need to create your own parser.
>
> --
> Steven.

Unfortunately Steven, its exactly the expression that I want
rather than the expression result.

Thanks for your attempt, and I will try and make myself clearer
in the future (allthough I did take time over my initial post).

- Paddy.


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


Re: Portrait of a "real life" __metaclass__

2007-11-10 Thread Mark Shroyer
On 2007-11-10, Jonathan Gardner <[EMAIL PROTECTED]> wrote:
> On Nov 9, 7:12 pm, Mark Shroyer <[EMAIL PROTECTED]> wrote:
>> I guess this sort of falls under the "shameless plug" category, but
>> here it is: Recently I used a custom metaclass in a Python program
>> I've been working on, and I ended up doing a sort of write-up on it,
>> as an example of what a "real life" __metaclass__ might do for those
>> who may never have seen such a thing themselves.
>>
>> http://markshroyer.com/blog/2007/11/09/tilting-at-metaclass-windmills/
>>
>> So what's the verdict?  Incorrect?  Missed the point completely?
>> Needs to get his head checked?  I'd love to hear what
>> comp.lang.python has to (anthropomorphically) say about it.
>>
>
> Kinda wordy.

Yeah, my fingers sort of latch onto the keyboard sometimes and just
won't let go.  Sorry about that ;)

> Let me see if I got the point:
>
> - You already had a bunch of classes that did age matching on date
> time objects.
>
> - You were building a class that matched emails.
>
> - You wanted to reuse the code for age matching to do email matching
> (based on the message's age)
>
> - So you wrote a metaclass that replaced the match() method with a
> proxy that would either dispatch to the old match() method (if it was
> a datetime object) or dispatch to the new match() method (which
> matched based on the message's date.)

Close, but not quite.  The proxy *always* dispatches to
AgeSpec.match(), but if the result of that method is an AgeSpec
itself, then the proxy wraps the result back up in a Matcher, which
works out rather conveniently for the rest of the application.

> Sounds Java-y, if that's even a word.

Yeah, you pretty much nailed my original background right there.  On
the other hand, I've also done a lot of work in Perl and C, and
pride myself on striving not to resort to OO patterns where they
aren't really useful.  So let me try to defend my reasoning, if it
is in fact defensible...

> Too many classes, not enough functions. You can tell you are doing
> Java in Python when you feel the urge to give everything a name
> that is a noun, even if it is completely based of a verb, such as
> "matcher". My opinion is that if you want to talk about doing
> something in Python such as matching, starting writing functions
> that match and forget the classes. Classes are for real nouns,
> nouns that can do several distinct things.
>
> What would I have done? I wouldn't have had an age matching class. I
> would have had a function that, given the datetime and a range
> specification, would return true or false. Then I would've written
> another function for matching emails. Again, it takes a specification
> and the email and returns true or false.

There isn't much difference between

  match_calendar_month(2007, 11, message)

and

  m = CalendarMonthMatcher(2007, 11)
  m.match(message)

so of course you're right that, were that all I'm doing with these
matchers, it would be a waste to implement them as classes.  But
take for example two of my app's mailbox actions -- these aren't
their real names, but for clarity let's call them ArchiveByMonth and
SaveAttachmentsByMonth.  The former moves messages from previous
months into an archival mbox file ./archives//MM.mbox
corresponding to each message's month, and the latter saves message
attachments into a directory ./attachments//MM/.  Each of these
actions would work by using either match_calendar_month() or
CalendarMonthMatcher().match() to perform its action on all messages
within a given month; then it iterates through previous months and
repeats until there are no more messages left to be processed.

In my object-oriented implementation, this iteration is performed by
calling m.previous() on the current matcher, much like the
simplified example in my write-up.  Without taking the OO approach,
on the other hand, both types of actions would need to compute the
previous month themselves; sure that's not an entirely burdensome
task, but it really seems like the wrong place for that code to
reside.  (And if you tackle this by writing another method to return
the requisite (year, month) tuple, and apply that method alongside
wherever match_calendar_month() is used...  well, at that point
you're really just doing object-oriented code without the "class"
keyword.)

Furthermore, suppose I want to save attachments by week instead of
month: I could then hand the SaveAttachmentsByPeriod action a
WeekMatcher instead of a MonthMatcher, and the action, using the
matcher's common interface, does the job just as expected.  (This is
an actual configuration file option in the application; the nice
thing about taking an OO approach to this app is that there's a very
straightforward mapping between the configuration file syntax and
the actual implementation.)

It could be that I'm still "thinking in Java," as you rather
accurately put it, but here the object-oriented approach seems
genuinely superior -- cleaner and, well, with better enca

Re: Returning actual argument expression to a function call?

2007-11-10 Thread Paddy
On Nov 10, 7:02 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Sat, 10 Nov 2007 03:03:00 -0300, Paddy <[EMAIL PROTECTED]>
> escribió:
>
>
>
> > Hi,
> > # If I have a function definition
> > def f1(arg):
> >   global capturecall
> >   if capturecall:
> >  ...
> >   do_normal_stuff(arg)
>
> > # and its later use:
> > def f2():
> >   ...
> >   return f1(a  and (b or c))
>
> > # But also to do:
> > capturecall = True
> > result = f2()
> > # And get the same result, but also save the actual
> > # calling arguments to f1 either as a string:
> > #   "a  and (b or c))"
> > # Or a code object computing a and(b or c)
>
> Would be enough to have the source line text?
>
> 
> def extract_caller_info():
>  import sys, traceback
>  return traceback.extract_stack(sys._getframe(2), limit=1)
>
> def f1(arg):
>if capturecall:
>   print extract_caller_info()
># do_normal_stuff(arg)
>
> def f2():
>a,b,c = 1,0,3
>return f1(a and (b or c))
>
> capturecall = True
> result = f2()
> 
>
> output is like this:
> [('test1.py', 12, 'f2', 'return f1(a and (b or c))')]
>
> source file name, line number, function name, source line text.
>
> > P.S. You might also have multiple calls where I
> > would need to capture each individual argument
> > expression of f1 e.g:
> > def f3():
> >   ...
> >   return f1(a and b) or e or f1(c and d)
>
> Tell your users that they'll have better results if those two calls are
> split on different lines:
>
> def f3():
> return (f1(a and b)
> or e
> or f1(c and d))
>
> Output:
> [('test1.py', 18, 'f3', 'return (f1(a and b)')]
> [('test1.py', 20, 'f3', 'or f1(c and d))')]
>
> --
> Gabriel Genellina


Thanks Gabriel, that will alow me to move forward.

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

Re: Global variables within classes.

2007-11-10 Thread Donn Ingle
Very interesting reply. I must ask a few questions, interleaved:

> If you mean that all instances of Class Canvas and Thing will share
> the *same* Stack, I think we can do it kind of like this:
What's the difference between "same Stack" and "same instance of Stack"? I
thought I knew what an instance was, but this code has made me doubt my
basics.

> class Stack:
> list = []
Okay, this has me a little weirded-out. How is this different from putting
it in: 
def __init__(self):
self.list = []
?
I see from tests that it is different, but I don't quite grok it. Who owns
the list ref?

> def pop(self):
> item = self.list[-1]
> del self.list[-1]
> return item
Is there some reason you do all that and not a self.list.pop(0)?
 
> class Canvas:
> def __init__(self):
> self.s = Stack()
Surely this makes a unique instance within Canvas such that it's a new
Stack?

> class Thing:
> def __init__(self):
> self.s = Stack()
Same question again -- my brain is telling me this is *another* Stack and
not the same one that it's in Canvas at all.

It looks like it could work for me, but I gotta get it in my head first :)

 
> or: if you want a pair of instances of class Canvas and class Thing
> share
> the *same* instance of class Stack, maybe we can make it like this:
> c = Canvas()
> c.push("bozo")
> t = Thing(c.getStack())   #associate t with c
> t.buzz()
This one I understand better because it does not imply anything - it's
easier to follow and it's where my head is at with Python, but your first
example is a whole new world.

Thanks for the post!
\d

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


Event handling and Late Binding

2007-11-10 Thread swellfr
Hi,
I have a component that i can only access through late binding.
This is working fine , i can use all the exposed methods , but i can't
register (/don't know how to ) event handlers for this component. Is
there someone that knows how to do it or who can spot me a example.

Thx

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


Re: Global variables within classes.

2007-11-10 Thread Duncan Booth
Donn Ingle <[EMAIL PROTECTED]> wrote:

>> class Stack:
>> list = []
> Okay, this has me a little weirded-out. How is this different from
> putting it in: 
> def __init__(self):
> self.list = []
> ?
> I see from tests that it is different, but I don't quite grok it. Who
> owns the list ref?
> 

The first creates an attribute of the class, the second creates an 
attribute in the instance.

When you access an attribute of an instance but the instance does not have 
an attribute with the required name Python looks for the attribute in the 
class instead. So in the first case it would look as though each instance 
has a 'list' attribute, but it is the same value shared between all 
instances. In the second case each instance has its own 'list' attribute.

Actually the lookup is somewhat more complex than that when you use new-
style classes (and you should always use new-style classes): properties (or 
other objects with a 'get' method) are class attributes but take precedence 
over instance attributes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Global variables within classes.

2007-11-10 Thread Donn Ingle
> The first creates an attribute of the class, the second creates an
> attribute in the instance.

Given that, can you clarify this:

class Test:
attribute = "original value"

class Bob:
def __init__(self):
self.ref = Test()

class Jim:
def __init__(self):
self.ref = Test()

b = Bob()
j = Jim()

print b.ref.attribute #prints "original value"

b.ref.attribute = "haschanged"
## Where is the value "haschanged" going here?
print b.ref.attribute # print "haschanged"

print j.ref.attribute #prints "original value"
## If it changed and an attribute of the Class, then
## why is it back to "original value" ?

> Actually the lookup is somewhat more complex than that when you use new-
> style classes (and you should always use new-style classes): properties
> (or other objects with a 'get' method) are class attributes but take
> precedence over instance attributes.
What is a 'get' method? Do you mean it should get all Java-esque with
getBlah and setBlah for every little thing?

I have been hearing about "new classes" for a while but there's no clarity
in the Python docs (that I can find). Have you any references for me? I
thought they were the standard by now anyway. I've only been pythoning
since 2.3 anyway.


\d

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


Re: Some "pythonic" suggestions for Python

2007-11-10 Thread Neil Cerutti
On 2007-11-10, Terry Reedy <[EMAIL PROTECTED]> wrote:
> I think you can regard 'No do statement' as rejected.  Some
> consider the non-proliferation of loop constructs a feature.  I
> believe this includes GvR.

Non-providing of the standard loop constructs, yes. But loop
constructs are plenty proliferate.

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


Extended date and time

2007-11-10 Thread Jeremy Sanders
Hi - I need to add support to a program for dates and times. The built-in
Python library seems to be okay for many purposes, but what I would like
would be Unix epoch style times (seconds relative to some date), covering a
large period from the past to the future. What would be nice would be a
library which can take floating point seconds from an epoch.

Does anyone know of a library which can convert from human style dates and
times to a floating point epoch and back again? I expect I could fudge the
fractional seconds with the built-in library, but I can't see how to get
dates in the past.

Thanks, Jeremy.

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Returning actual argument expression to a function call?

2007-11-10 Thread Piet van Oostrum
> Paddy <[EMAIL PROTECTED]> (P) wrote:

>P> Hi,
>P> # If I have a function definition
>P> def f1(arg):
>P>   global capturecall
>P>   if capturecall:
>P>  ...
>P>   do_normal_stuff(arg)

>P> # and its later use:
>P> def f2():
>P>   ...
>P>   return f1(a  and (b or c))

>P> # I would like to do:
>P> capturecall = False
>P> result = f2()
>P> # And get the equivalent of do_normal_stuff(a and(b or c))

>P> # But also to do:
>P> capturecall = True
>P> result = f2()
>P> # And get the same result, but also save the actual
>P> # calling arguments to f1 either as a string:
>P> #   "a  and (b or c))"
>P> # Or a code object computing a and(b or c)


>P> # I caould change f1 to expect a function instead and do:
>P> def f1b(arg):
>P>   global capturecall
>P>   if capturecall:
>P>  save(arg)
>P>   return do_normal_stuff(arg())

>P> # And then use it like this:
>P> def f2b():
>P>   ...
>P>   return f1b(lambda : (a  and (b or c)) )

>P> # The problem is that for my application to work,
>P> # Python newbies would have to write lambda when they
>P> # know they are after the result. Its my program
>P> # that would require the lambda (or def), which
>P> # is a distraction from their problem.

>P> Any ideas on implementing f1 so I can do f2?

With Python this can't be done without either quoting the expression (make
a string out of it) or using a lambda. Lisp and C# can do this kind of thing.
-- 
Piet van Oostrum <[EMAIL PROTECTED]>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Bitmap editor and File-saving

2007-11-10 Thread Johnston Jiaa
In my Python program (using Tkinter), I would like to have a window  
where the user will be able to draw a simple picture.  I don't know  
where to begin.. can somehow give me a general idea how to do  
something like this?

Also, I'd like for the program to save that picture along with some  
text.  What would be the best way to go about doing this?  Is  
pickling a viable option?

Thanks in advance,
Johnston
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Image treshold

2007-11-10 Thread Scott David Daniels
Johny wrote:
> Can anyone give me an example how to apply a threshold value to an
> image?
> (everything above a certain brightness level becomes white, and
> everything below the level becomes black.)
> I was told I should use 256-item mapping table and pass it to the
> "point" method.
> But how should the 256-item mapping table  look like, if the threshold
> is 18( found from the histogram)

Sounds like homework.  You have the tools, and are close to the answer.
Experiment and look at the results.

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


security code whit python

2007-11-10 Thread [EMAIL PROTECTED]
hii my friends;
I want to create picture of security code.can i do it ?
if yes,how , which module will help me?
have you got a example that can create a picture whit my name
pls help me
thansk
oruc

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


Re: easy 3D graphics for rendering geometry?

2007-11-10 Thread Scott David Daniels
gsal wrote:
> By the way, VPython crashes my computer rather easily:
> 
> - launch the editor
> - open python file
> - press F5 to run
> - when the graphical windows appears, attempt to manipulate (drag or
> resize)
> - the computer looses it...

Well, what kind of computer, what version of everything (OS, Python,
VPython), what display card, 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Global variables within classes.

2007-11-10 Thread Marc 'BlackJack' Rintsch
On Sat, 10 Nov 2007 17:00:13 +0200, Donn Ingle wrote:

>> The first creates an attribute of the class, the second creates an
>> attribute in the instance.
> 
> Given that, can you clarify this:
> 
> class Test:
> attribute = "original value"
> 
> class Bob:
> def __init__(self):
> self.ref = Test()
> 
> class Jim:
> def __init__(self):
> self.ref = Test()
> 
> b = Bob()
> j = Jim()
> 
> print b.ref.attribute #prints "original value"
> 
> b.ref.attribute = "haschanged"
> ## Where is the value "haschanged" going here?

To *instance* of `Test` you created and bound to `b.ref`.

> print b.ref.attribute # print "haschanged"
> 
> print j.ref.attribute #prints "original value"
> ## If it changed and an attribute of the Class, then
> ## why is it back to "original value" ?

Because the *instance* of `Test` bound to `j.ref` does not have
`attribute` it is looked up in the *class* `Test`.

>> Actually the lookup is somewhat more complex than that when you use new-
>> style classes (and you should always use new-style classes): properties
>> (or other objects with a 'get' method) are class attributes but take
>> precedence over instance attributes.
> What is a 'get' method? Do you mean it should get all Java-esque with
> getBlah and setBlah for every little thing?

Good $GOD no!  He's talking about the `__get__` method on properties. Read
the docs for the built in `property()` function.  It's a nice mechanism to
actually avoid all those getters and setters because you can turn "simple"
attributes into "computed" attributes without changing the API of the
objects.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy 3D graphics for rendering geometry?

2007-11-10 Thread Scott David Daniels
gsal wrote:
> I actually did look at VPython last weekend. I managed to draw a
> soccer field, a few players, move them around and even record/play-
> back playsI was very impressed on how easy it was to learn not
> only VPython, but Python in the first...I did not know any python,
> either.

By the way, to get you completely hooked (I took a while to notice),
try adding the following to your soccer program:

 import visual

 

 if __name__ == '__main__':
 visual.scene.stereo = 'passive'
 visual.scene.stereodepth = 1
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Extension Building Network

2007-11-10 Thread kyosohma
On Nov 9, 11:32 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Fri, 09 Nov 2007 13:30:03 -0300, <[EMAIL PROTECTED]> escribió:
>
> > On Nov 9, 10:02 am, Tim Golden <[EMAIL PROTECTED]> wrote:
> >> [EMAIL PROTECTED] wrote:
> >> > The hardest part was finding accurate information. Most people on the
> >> > user groups have been unhelpful or sarcastic.
>
> >> That's a shame to hear. Because you were building on Windows?
> >> Or for some other reason? (I ask because, even here on the
> >> Python lists, reactions like "Get a working O/S" are not unknown
> >> in answer to questions like "How do I... on Windows?")
>
> > I don't think it was because of Windows, but because I was asking
> > about how to use Visual Studio. I've had classes in it, but intro
> > classes in Comp Sci don't teach you how to compile. One of the people
> > on this list told me to go read Microsoft's docs.
>
> Was that me? In this message?
> 
> (Note that you were asking "how do I use VS to compile an exe?", not "how
> do I build a Python extension?")
> I'm sorry if you feel the response was somewhat rude, I apologize in that
> case. It was not intended at all.
>
> --
> Gabriel Genellina

I am at fault as well. What I thought was clear obviously wasn't to
you. I almost always like your answers, so when you said that, it
seemed pretty snippy to me. I try to be as unambiguous and clear as I
can be when posting, but I sometimes lapse in this regard. Sorry!

Mike

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

Re: Global variables within classes.

2007-11-10 Thread Donn Ingle
Included again for clarity:
>> class Test:
>> attribute = "original value"
>> 
>> class Bob:
>> def __init__(self):
>> self.ref = Test()
>> 
>> class Jim:
>> def __init__(self):
>> self.ref = Test()
>> 
>> b = Bob()
>> j = Jim()
>> 
>> print b.ref.attribute #prints "original value"
>> b.ref.attribute = "haschanged"
>> ## Where is the value "haschanged" going here?
> 
> To *instance* of `Test` you created and bound to `b.ref`.
> 
I don't follow you here. I *think* you are saying I created a *new* (on the
fly) ref within b that is also called 'attrib', so that it's kind of
shadowing the original 'attribute' ref (the so-called class attribute.)
?

>> print b.ref.attribute # print "haschanged"
>> 
>> print j.ref.attribute #prints "original value"
>> ## If it changed and an attribute of the Class, then
>> ## why is it back to "original value" ?
> 
> Because the *instance* of `Test` bound to `j.ref` does not have
> `attribute` it is looked up in the *class* `Test`.
Okay, I sort of see that. It's not a property of 'j' so it looks upwards
into the class. 
This is kind of weird. It's not clear like Python usually is. Is this
something intentional or did it 'fall through the cracks'? I mean, can one
rely on it or will it be 'fixed'?
 
> Good $GOD no!  
:D

> He's talking about the `__get__` method on properties. Read 
> the docs for the built in `property()` function.  
Okay, I'll go have a look.

Thx
\d


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


String/Decimal issues

2007-11-10 Thread Mike Howarth

Hi

Seem to be having a bit of brainfreeze this evening.

Basically I'm reducing an array of prices like so:
>> subtotal = reduce(operator.add, itemprices)

This gives me a string of '86.00.00' which I am trying to use with decimal
objects. Python 2.4 is not particularly happy with this.

Additionally I can't simply convert the string to a decimal as it would be
invalid given it has multiple decimal points.

Being relatively new to python, I'm not sure how I could round the string or
similar. Anyone got any ideas?
-- 
View this message in context: 
http://www.nabble.com/String-Decimal-issues-tf4783150.html#a13683811
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: Python IDE

2007-11-10 Thread Joe Riopel
On Nov 3, 2007 10:28 AM, BartlebyScrivener <[EMAIL PROTECTED]> wrote:
> Try the free trial of Komodo
>
> http://www.activestate.com/Products/komodo_ide/

Komodo Edit is free
http://www.activestate.com/Products/komodo_edit/

Open Komodo is free and open source:
http://www.openkomodo.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String/Decimal issues

2007-11-10 Thread Marc 'BlackJack' Rintsch
On Sat, 10 Nov 2007 09:02:01 -0800, Mike Howarth wrote:

> Basically I'm reducing an array of prices like so:
>>> subtotal = reduce(operator.add, itemprices)

Take a look at the built in `sum()` function.

> This gives me a string of '86.00.00' which I am trying to use with decimal
> objects.

So what the heck is in `itemprices`!?

> Being relatively new to python, I'm not sure how I could round the string or
> similar. Anyone got any ideas?

You can't round strings.  Maybe that's the problem here: data types.  Are
you sure you have numbers that you are adding and not strings or something!?

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Global variables within classes.

2007-11-10 Thread Marc 'BlackJack' Rintsch
On Sat, 10 Nov 2007 18:53:08 +0200, Donn Ingle wrote:

> Included again for clarity:
>>> class Test:
>>> attribute = "original value"
>>> 
>>> class Bob:
>>> def __init__(self):
>>> self.ref = Test()
>>> 
>>> class Jim:
>>> def __init__(self):
>>> self.ref = Test()
>>> 
>>> b = Bob()
>>> j = Jim()
>>> 
>>> print b.ref.attribute #prints "original value"
>>> b.ref.attribute = "haschanged"
>>> ## Where is the value "haschanged" going here?
>> 
>> To *instance* of `Test` you created and bound to `b.ref`.
>> 
> I don't follow you here. I *think* you are saying I created a *new* (on the
> fly) ref within b that is also called 'attrib', so that it's kind of
> shadowing the original 'attribute' ref (the so-called class attribute.)
> ?

In the `__init__()` of `Bob` you created an instance of `Test`.  You can't
create a `ref`, that's just a name of an attribute on `Bob` instances. 
Then you bind the attribute `attribute` of that instance to the string
"haschanged".  This assignment creates the attribute because `Test`
*instances* don't have such an attribute.  And yes this `attribute`
shadows the class `attribute` as the lookup rules are instance -> class ->
base classes.

>>> print b.ref.attribute # print "haschanged"
>>> 
>>> print j.ref.attribute #prints "original value"
>>> ## If it changed and an attribute of the Class, then
>>> ## why is it back to "original value" ?
>> 
>> Because the *instance* of `Test` bound to `j.ref` does not have
>> `attribute` it is looked up in the *class* `Test`.
> Okay, I sort of see that. It's not a property of 'j' so it looks upwards
> into the class.

Its not an attribute of `j.ref`!

Here's a little ASCII art showing the situation after your code was
executed::

  Names  |Objects
  ---+-
 |+--+
  Test -->|   |  ++
 ||attribute--->|   |
 |+--+  |"original value"|
 |  ++
 |
 |+--+
  j ->| |   +--+
 ||ref  >||
 |+--+   +--+
 |
 |
 |+--+
  b ->| |   +--+
 ||ref  >||   ++
 |+--+   |attribute>|   |
 |   +--+   |"haschanged"|
 |  ++

On the left are the names in the module's namespace and on the right are
the objects in memory.  From the `Test` objects there's also a reference
to the `class` that's bound to the name `Test` in the Module that is not
shown in the "drawing" but necessary to look up attributes in the class of
the instances.

> This is kind of weird. It's not clear like Python usually is. Is this
> something intentional or did it 'fall through the cracks'? I mean, can one
> rely on it or will it be 'fixed'?

Don't think so.  It's a surprise for many but then class attributes are
not that common in code or they even use this "gotcha" for
immutable default values.  As long a the value isn't changed the default
value is just referenced from the class then and not every instance.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Coding Help

2007-11-10 Thread rishiyoor
I need help coding my flowchart. The C's are conditions, the S's are
statements. The statements do not affect the conditions except for S5
which is an increment for C0. The left is True, and the right is
False.

I would probably use a while loop (or for loop without S5) for the
first condition C0, and I am thinking of evaluating the rest of the
conditions using if statements. But if I use if-statements, I am not
able to accomodate the breaks.

Program
   ├───┐
   ┌─< C0 >─┐  │
   │|  │
   │┌< C1 >──┐ │
   │  ┌───< C2 >┐   ┌──< C3 >─┐│
   │  │┌─< C4 >─┐  [S1]   ││
   │  │   [S2] [S3] └┬┘│
   │  │││┌─< C4 >─┐│
   │  │││   [S4]  ││
   │  │││└───┬┘│
   │  └───┬┴┴┘ │
   │ [S5]  │
   │  └┘
Program
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Global variables within classes.

2007-11-10 Thread Donn Ingle
Thanks for your time and patience Marc, that was some hotshot ascii art.
I'll have to take some time to digest this.

\d

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


Re: Returning actual argument expression to a function call?

2007-11-10 Thread Paddy
On Nov 10, 3:44 pm, Piet van Oostrum <[EMAIL PROTECTED]> wrote:
> With Python this can't be done without either quoting the expression (make
> a string out of it) or using a lambda. Lisp and C# can do this kind of thing.


I'd like to propose we add '() to Python. Pronounced tick-
brackets, it
surrounds an expression which is compiled into an anonymous function.

I have not thought this through apart from knowing that this is one
more
step towards Lisp heaven and submit no code as the implementation
will be trivial ;-)

Of course if my suggestion is not welcomed with open arms then this
is
Pythons last chance to escape terminal decline



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


Re: Coding Help

2007-11-10 Thread Marc 'BlackJack' Rintsch
On Sat, 10 Nov 2007 09:45:47 -0800, rishiyoor wrote:

> I need help coding my flowchart. The C's are conditions, the S's are
> statements. The statements do not affect the conditions except for S5
> which is an increment for C0. The left is True, and the right is
> False.
> 
> I would probably use a while loop (or for loop without S5) for the
> first condition C0, and I am thinking of evaluating the rest of the
> conditions using if statements. But if I use if-statements, I am not
> able to accomodate the breaks.
> 
> Program
>├───┐
>┌─< C0 >─┐  │
>│|  │
>│┌< C1 >──┐ │
>│  ┌───< C2 >┐   ┌──< C3 >─┐│
>│  │┌─< C4 >─┐  [S1]   ││
>│  │   [S2] [S3] └┬┘│
>│  │││┌─< C4 >─┐│
>│  │││   [S4]  ││
>│  │││└───┬┘│
>│  └───┬┴┴┘ │
>│ [S5]  │
>│  └┘
> Program

Sounds pretty much like homework to me.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Global variables within classes.

2007-11-10 Thread Marc 'BlackJack' Rintsch
On Sat, 10 Nov 2007 17:39:04 +, Marc 'BlackJack' Rintsch wrote:

> On Sat, 10 Nov 2007 18:53:08 +0200, Donn Ingle wrote:
 print b.ref.attribute # print "haschanged"
 
 print j.ref.attribute #prints "original value"
 ## If it changed and an attribute of the Class, then
 ## why is it back to "original value" ?
>>> 
>>> Because the *instance* of `Test` bound to `j.ref` does not have
>>> `attribute` it is looked up in the *class* `Test`.
>> Okay, I sort of see that. It's not a property of 'j' so it looks upwards
>> into the class.
> 
> Its not an attribute of `j.ref`!

Oops, this should read:  It's not an attribute of `j`, but `j.ref`.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coding Help

2007-11-10 Thread Florian Lindner
Marc 'BlackJack' Rintsch wrote:

> On Sat, 10 Nov 2007 09:45:47 -0800, rishiyoor wrote:
> 
>> I need help coding my flowchart. The C's are conditions, the S's are
>> statements. The statements do not affect the conditions except for S5
>> which is an increment for C0. The left is True, and the right is
>> False.
>> 
>> I would probably use a while loop (or for loop without S5) for the
>> first condition C0, and I am thinking of evaluating the rest of the
>> conditions using if statements. But if I use if-statements, I am not
>> able to accomodate the breaks.
>> 
>> Program
>>├───┐
>>┌─< C0 >─┐  │
>>│|  │
>>│┌< C1 >──┐ │
>>│  ┌───< C2 >┐   ┌──< C3 >─┐│
>>│  │┌─< C4 >─┐  [S1]   ││
>>│  │   [S2] [S3] └┬┘│
>>│  │││┌─< C4 >─┐│
>>│  │││   [S4]  ││
>>│  │││└───┬┘│
>>│  └───┬┴┴┘ │
>>│ [S5]  │
>>│  └┘
>> Program
> 
> Sounds pretty much like homework to me.

It's nothing bad ask about help for a homework as long as noone expects to
get the entire solution.

To the OP: What is your problem?

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

Re: Python Extension Building Network

2007-11-10 Thread M.-A. Lemburg
On 2007-11-10 01:44, [EMAIL PROTECTED] wrote:
>>> The directions for MinGW were usually only partially correct. So I
>>> went through the two sets of directions I found (links on the site)
>>> and mixed and matched until I got it right.
>>> There are no directions on how to use Visual Studio 2003 that I've
>>> found, just some old free edition. those directions were incompatible
>>> with VS2003. I'll post VS2003's correct usage eventually, but it's
>>> basically just installing it and then using distutils.
>> Getting VS2003 ready to compile Python extensions is really easy:
>>
>> 1. open a command shell
>> 2. run vcvars32.bat
>> 3. make sure the Python version you are targetting is on the
>>PATH
>> 4. "python setup.py bdist_wininst" or "python setup.py bdist_msi"
>> 5. pick up the installer in the build\ directory.
>>
> 
> 
> I didn't need to run vcvars32.bat to make mine work. But that's good
> to know...I think.
> 
> 
>> Note: bdist_msi is only available in Python 2.5 and later.
>>
>> You need VC6 if you want to compile extensions for Python 1.5-2.3
>> and VC7.1 for Python 2.4 and later.
>>
> 
> I was aware of that you needed VC6 for 2.3, but I didn't realize it
> went that far back. And I knew you needed 7.1 for 2.4 and 2.5, but
> I've heard that they're moving to VS2005 soon.

AFAIK, Martin (who's building the Windows installers for Python)
is going to skip VS2005 and go straight for VS2008, but I may be
wrong.

> Thanks for the feedback, Marc-Andre!

You're welcome :-)

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Nov 10 2007)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coding Help

2007-11-10 Thread rishiyoor
Well, its not homework, and if you don't want to be a tutor, you can
be a consultant and earn a lot of money.

Here is how I thought of solving this, but it does not work:

While C0 is false
  if C1
if C2

now what?

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


Re: Coding Help

2007-11-10 Thread Carsten Haese
On Sat, 2007-11-10 at 11:54 -0800, [EMAIL PROTECTED] wrote:
> Well, its not homework, and if you don't want to be a tutor, you can
> be a consultant and earn a lot of money.
> 
> Here is how I thought of solving this, but it does not work:
> 
> While C0 is false
>   if C1
> if C2
> 
> now what?

Maybe it would help you if you added an S6 that does nothing underneath
the "C2 is true" branch of your flow chart.

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Re: Coding Help

2007-11-10 Thread rishiyoor
On Nov 10, 3:20 pm, Carsten Haese <[EMAIL PROTECTED]> wrote:

>
> Maybe it would help you if you added an S6 that does nothing underneath
> the "C2 is true" branch of your flow chart.
>
> --
> Carsten Haesehttp://informixdb.sourceforge.net

Think I found a sequence of statements that would work

if C1
  if C2
  else
if C4
  S2
else
  S3
else
  if C3
S1
  if C5  # This should be C5. There is an error in the chart.
S4

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


Re: Python Extension Building Network

2007-11-10 Thread kyosohma
On Nov 10, 1:12 pm, "M.-A. Lemburg" <[EMAIL PROTECTED]> wrote:
> On 2007-11-10 01:44, [EMAIL PROTECTED] wrote:
>
>
>
> >>> The directions for MinGW were usually only partially correct. So I
> >>> went through the two sets of directions I found (links on the site)
> >>> and mixed and matched until I got it right.
> >>> There are no directions on how to use Visual Studio 2003 that I've
> >>> found, just some old free edition. those directions were incompatible
> >>> with VS2003. I'll post VS2003's correct usage eventually, but it's
> >>> basically just installing it and then using distutils.
> >> Getting VS2003 ready to compile Python extensions is really easy:
>
> >> 1. open a command shell
> >> 2. run vcvars32.bat
> >> 3. make sure the Python version you are targetting is on the
> >>PATH
> >> 4. "python setup.py bdist_wininst" or "python setup.py bdist_msi"
> >> 5. pick up the installer in the build\ directory.
>
> > I didn't need to run vcvars32.bat to make mine work. But that's good
> > to know...I think.
>
> >> Note: bdist_msi is only available in Python 2.5 and later.
>
> >> You need VC6 if you want to compile extensions for Python 1.5-2.3
> >> and VC7.1 for Python 2.4 and later.
>
> > I was aware of that you needed VC6 for 2.3, but I didn't realize it
> > went that far back. And I knew you needed 7.1 for 2.4 and 2.5, but
> > I've heard that they're moving to VS2005 soon.
>
> AFAIK, Martin (who's building the Windows installers for Python)
> is going to skip VS2005 and go straight for VS2008, but I may be
> wrong.
>
> > Thanks for the feedback, Marc-Andre!
>
> You're welcome :-)
>
> --
> Marc-Andre Lemburg
> eGenix.com
>
> Professional Python Services directly from the Source  (#1, Nov 10 2007)>>> 
> Python/Zope Consulting and Support ...http://www.egenix.com/
> >>> mxODBC.Zope.Database.Adapter ...http://zope.egenix.com/
> >>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/
>
> 
>
>  Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 
>
>eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
> D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
>Registered at Amtsgericht Duesseldorf: HRB 46611

Is it okay if I take your instructions for VS2003 and use them on my
website? I'll modify them slightly, but it'll be mostly the same.

Mike

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


Re: security code whit python

2007-11-10 Thread [EMAIL PROTECTED]
is there anybody here !!!

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


Re: Looking for a good Python environment

2007-11-10 Thread PyScripter
PyScripter provides integrated version control, via TortoiseSVN or
TortoiseCVS and the File Explorer.

On Nov 10, 11:21 am, jwelby <[EMAIL PROTECTED]> wrote:
> On Nov 7, 12:42 pm, "Colin J. Williams" <[EMAIL PROTECTED]> wrote:
>
> > jwelby wrote:
> ...
>
> > > I currently use Python Scripter as a lightweight editor for Windows.
>
> > Could you elaborate on "lightweight"
> > please? I findPyScripterto be a
> > powerful editor/debugger combination.
>
> > What functionality does Eclipse have
> > thatPyScripterdoes not?
>
> > Colin W.
>
> This is a fair question. I didn't phrase my post too well.
>
> I findPyScripterdoes pretty much everything I need in terms of doing
> actual development for Python. My use of 'lightweight' is by no means
> a criticism ofPyScripter- it's more of a compliment, as it refers to
> the relatively modest demands that it makes on my system compared with
> Eclipse, which can be hog.
>
> The main reason I have used Eclipse for larger, team based, projects
> is for the source control plug-ins. Eclipse has plug-in support for
> cvs and svn.PyScriptermay have this too - perhaps I've missed it.
> (I'm away from my Windows box at the moment, otherwise I would check).
> Of course, there are other ways to implement source control without it
> needing to be integrated in the IDE, so even this need not put off
> anyone who wants to usePyScripterwith source control.
>
> Summary - unless you need the added flexibility offered by Eclipse
> plug-ins,PyScripteris a great tool for developing with Python on
> Windows.
>
>
>
> > > For project work I use Eclipse, which can be installed with PyDev and
> > > other useful plug-ins already included if you choose a suitable
> > > distribution of Easy Eclipse (http://www.easyeclipse.org/). There is a
> > > distribution specifically for Python development, and also one for
> > > LAMP, which includes a number of other components which will be of use
> > > if you are developing for the web.


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


Re: security code whit python

2007-11-10 Thread Thorsten Kampe
* [EMAIL PROTECTED] (Sat, 10 Nov 2007 21:15:13 -)
> is there anybody here !!!

The Internet has gone home. Come again tomorrow...

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


Re: security code whit python

2007-11-10 Thread [EMAIL PROTECTED]
wha :S

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


Re: security code whit python

2007-11-10 Thread paulC
On 10 Nov, 16:04, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> hii my friends;
> I want to create picture of security code.can i do it ?
> if yes,how , which module will help me?
> have you got a example that can create a picture whit my name
> pls help me
> thansk
> oruc


You may find the Python Imaging Library (PIL) useful. See
http://www.pythonware.com/products/pil/. It has an extensive handbook
which includes drawing text on to an image.

regards, Paul Clinch

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


Re: String/Decimal issues

2007-11-10 Thread Ben Finney
Mike Howarth <[EMAIL PROTECTED]> writes:

> Basically I'm reducing an array of prices like so:
> >> subtotal = reduce(operator.add, itemprices)
> 
> This gives me a string of '86.00.00'

You haven't shown what the input is; what is the value of 'itemprices'
before this line?

When I use floating-point numbers, I get this::

>>> import operator
>>> itemprices = [24.68, 12.34, 36.90]
>>> itemprices
[24.68, 12.34, 36.899]
>>> subtotal = reduce(operator.add, itemprices)
>>> subtotal
73.9199987

When I use the Decimal type, I get this::

>>> import operator
>>> from decimal import Decimal
>>> itemprices = [Decimal("24.68"), Decimal("12.34"), Decimal("36.93")]
[Decimal("24.68"), Decimal("12.34"), Decimal("36.93")]
>>> subtotal = reduce(operator.add, itemprices)
>>> subtotal
Decimal("73.95")

So I suspect your 'itemprices' sequence is composed of values of some
other type. Please show your equivalent of the above sessions so we
can see what's happening.

-- 
 \ "Don't be afraid of missing opportunities. Behind every failure |
  `\  is an opportunity somebody wishes they had missed."  -- Jane |
_o__)  Wagner, via Lily Tomlin |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: security code whit python

2007-11-10 Thread [EMAIL PROTECTED]
have you got any example?pls :S

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


Re: security code whit python

2007-11-10 Thread Wildemar Wildenburger
[EMAIL PROTECTED] wrote:
> I want to create picture of security code.can i do it ?

I don't know what you mean by "security code".

I take it you want to create technical diagrams, from a sort of 
algorithmic description?

PIL might help you, as paulC pointed out. It works on raster images 
(bitmaps).

pYx is a tool library for vector graphics and scientific plots. Maybe 
that can help. I've produced nice looking graphics of search-trees 
within about 60 minutes of installing it.

This example is copied right from the pyx site:

from pyx import *
c = canvas.canvas()
c.text(0, 0, "Hello, world!") # Put oruccim here, if you want
c.stroke(path.line(0, 0, 2, 0))
c.writeEPSfile("hello")
c.writePDFfile("hello")

http://pyx.sourceforge.net/>

/W

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


Populating a dictionary, fast

2007-11-10 Thread Michael Bacarella

The id2name.txt file is an index of primary keys to strings.  They look like 
this:

11293102971459182412:Descriptive unique name for this record\n
950918240981208142:Another name for another record\n

The file's properties are:

# wc -l id2name.txt

8191180 id2name.txt
# du -h id2name.txt
517Mid2name.txt

I'm loading the file into memory with code like this:

id2name = {}
for line in iter(open('id2name.txt').readline,''):
id,name = line.strip().split(':')
id = long(id)
id2name[id] = name

This takes about 45 *minutes*

If I comment out the last line in the loop body it takes only about 30 
_seconds_ to run.
This would seem to implicate the line id2name[id] = name as being 
excruciatingly slow.

Is there a fast, functionally equivalent way of doing this?

(Yes, I really do need this cached.  No, an RDBMS or disk-based hash is not 
fast enough.)



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


Re: Bitmap editor and File-saving

2007-11-10 Thread paulC
On 10 Nov, 15:44, Johnston Jiaa <[EMAIL PROTECTED]> wrote:
> In my Python program (using Tkinter), I would like to have a window
> where the user will be able to draw a simple picture.  I don't know
> where to begin.. can somehow give me a general idea how to do
> something like this?
>
> Also, I'd like for the program to save that picture along with some
> text.  What would be the best way to go about doing this?  Is
> pickling a viable option?
>
> Thanks in advance,
> Johnston

The Canvas widget provides structured graphics facilities for
Tkinter.
At http://infohost.nmt.edu/tcc/help/pubs/tkinter.pdf is a useful
manual.

Regards, Paul Clinch


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


A JEW hacker in California admits distributing malware that let him steal usernames and passwords for Paypal accounts.

2007-11-10 Thread zionist . news
A Jew hacker in California admits distributing malware that let him
steal usernames and passwords for Paypal accounts.

http://www.pcworld.com/article/id,139507-c,cybercrime/article.html

The Jews and Israelis the top notch WHITE COLLAR CRIMINALS, YET, they
are harassing MOSLEMS in CALIFORNIA. Do you know why ? BECAUSE ALL THE
POLITICIANS ARE IN THEIR POCKET. Most senators and congressmen are the
same ASHKENAZI KHAZAR JEWS.
Tom Lantos and Diane Feinstein are two of the most crooked senators
from CALIFORNIA and both Ashkenazi and khazar.

LAPD to RACIALLY PROFILE MOSLEMS:
http://www.latimes.com/news/local/la-me-lapd9nov09,0,1646403.story?page=2&coll=la-home-center

LAPD to build data on Muslim areas

Anti-terrorism unit wants to identify sites 'at risk' for extremism.
By Richard Winton, Jean-Paul Renaud and Paul Pringle, Los Angeles
Times Staff Writers
November 9, 2007
An extensive mapping program launched by the LAPD's anti-terrorism
bureau to identify Muslim enclaves across the city sparked outrage
Thursday from some Islamic groups and civil libertarians, who
denounced the effort as an exercise in racial and religious profiling.

Los Angeles Police Department Deputy Chief Michael P. Downing, who
heads the bureau, defended the undertaking as a way to help Muslim
communities avoid the influence of those who would radicalize Islamic
residents and advocate "violent, ideologically-based extremism."

"We are seeking to identify at-risk communities," Downing said in an
interview Thursday evening. "We are looking for communities and
enclaves based on risk factors that are likely to become
isolated. . . . We want to know where the Pakistanis, Iranians and
Chechens are so we can reach out to those communities."

Downing added that the Muslim Public Affairs Council has embraced the
vaguely defined program "in concept." The group's executive director,
Salam Al-Marayati, said Thursday that it wanted to know more about the
plan and had a meeting set with the LAPD next week.

"We will work with the LAPD and give them input, while at the same
time making sure that people's civil liberties are protected," said Al-
Marayati, who commended Downing for being "very forthright in his
engagement with the Muslim community."

Others condemned the project, however.

"We certainly reject this idea completely," said Shakeel Syed,
executive director of the Islamic Shura Council of Southern
California. "This stems basically from this presumption that there is
homogenized Muslim terrorism that exists among us."

Syed said he is a member of Police Chief William J. Bratton's forum of
religious advisors, but had not been told of the community mapping
program. "This came as a jolt to me," Syed said.

Hussam Ayloush, who leads the Los Angeles chapter of the Council on
American-Islamic Relations, said the mapping "basically turns the LAPD
officers into religious political analysts, while their role is to
fight crime and enforce the laws."

During Oct. 30 testimony before Congress, Downing described the
program broadly as an attempt to "mitigate radicalization." At that
time, he said law enforcement agencies nationwide faced "a vicious,
amorphous and unfamiliar adversary on our land."

Downing and other law enforcement officials said police agencies
around the world are dealing with radical Muslim groups that are
isolated from the larger community, making potential breeding groups
for terrorism. He cited terror cells in Europe as well as the case of
some Muslim extremists in New Jersey arrested in May for allegedly
planning to bomb Ft. Dix.

"We want to map the locations of these closed, vulnerable communities,
and in partnership with these communities . . . help [weave] these
enclaves into the fabric of the larger society," he said in his
testimony.

"To do this, we need to go into the community and get to know peoples'
names," he said. "We need to walk into homes, neighborhoods, mosques
and businesses."

To assemble the mapping data, Downing said in an interview Thursday,
the LAPD intends to enlist USC's Center for Risk and Economic Analysis
of Terrorism Events, which was founded four years ago with $12 million
in federal funds.

In 2003, university officials said the center would focus on threats
to power plants, telecommunications and transportation systems.

It recently was tapped to strengthen security at Los Angeles
International Airport.

Downing said the effort would not involve spying on neighborhoods. He
said it would identify groups, not individuals.

"This has nothing to do with intelligence," he said, comparing it to
market research.

But in his congressional testimony, Downing said the LAPD hoped to
identify communities that "may be susceptible to violent,
ideologically-based extremism and then use a full-spectrum approach
guided by an intelligence-led strategy."

Downing told lawmakers the program would "take a deeper look at the
history, demographics, language, culture, ethnic breakdown,
socioeconomic status and social intera

Re: Writing a CGI to query DB

2007-11-10 Thread paulC
On 10 Nov, 04:33, Bighead <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am currently working on a CGI deployed on an Apache server, which,
> given an arbitrary SQL, fetches raw data from a remote DB server and
> return them in a HTML page. This CGI works fine on quick SQLs.
>
> But when I try to run a slow SQL on this CGI, through a Squid Proxy, I
> always get the Error message from Squid: Zero Sized Reply, after 5
> minutes.
>
> The SQL itself is correct, since I have tried it directly on the DB
> server. So what do you think might cause the problem? Thank you.

This sounds a lot like an apache server configuration problem. From
the squid FAQ;

11.51 Why do I sometimes get ``Zero Sized Reply''?

This happens when Squid makes a TCP connection to an origin server,
but for some reason, the connection is closed before Squid reads any
data. Depending on various factors, Squid may be able to retry the
request again. If you see the ``Zero Sized Reply'' error message, it
means that Squid was unable to retry, or that all retry attempts also
failed.

The apache server has a default TimeOut of 300 seconds.

This question might be more usefully answered by the apache user
group.

Regards, Paul Clinch

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


Re: Populating a dictionary, fast

2007-11-10 Thread Ben Finney
Michael Bacarella <[EMAIL PROTECTED]> writes:

> id2name = {}
> for line in iter(open('id2name.txt').readline,''):
> id,name = line.strip().split(':')
> id = long(id)
> id2name[id] = name
> 
> This takes about 45 *minutes*
> 
> If I comment out the last line in the loop body it takes only about
> 30 _seconds_ to run.  This would seem to implicate the line
> id2name[id] = name as being excruciatingly slow.

Or, rather, that the slowdown is caused by allocating these items in a
dictionary at all.

Dictionaries are implemented very efficiently in Python, but there
will still be overhead in inserting millions of distinct items. Of
course, if you just throw each item away instead of allocating space
for it, the loop will run very quickly.

> Is there a fast, functionally equivalent way of doing this?

You could, instead of individual assignments in a 'for' loop, try
letting the 'dict' type operate on a generator::

input_file = open("id2name.txt")
id2name = dict(
(long(id), name) for (id, name) in
line.strip().split(":") for line in input_file
)

All that code inside the 'dict()' call is a "generator expression"; if
you don't know what they are yet, have a read of Python's
documentation on them. It creates a generator which will spit out
key+value tuples to be fed directly to the dict constructor as it
requests them.

That allows the generator to parse each item from the file exactly as
the 'dict' constructor needs it, possibly saving some extra "allocate,
assign, discard" steps. Not having your data set, I can't say if it'll
be significantly faster.

-- 
 \  "Compulsory unification of opinion achieves only the unanimity |
  `\ of the graveyard."  -- Justice Roberts in 319 U.S. 624 (1943) |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: security code whit python

2007-11-10 Thread Paul Rubin
Wildemar Wildenburger <[EMAIL PROTECTED]> writes:
> [EMAIL PROTECTED] wrote:
> > I want to create picture of security code.can i do it ?
> I don't know what you mean by "security code".

I think that means a captcha (www.captcha.net).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Populating a dictionary, fast

2007-11-10 Thread Steven D'Aprano
On Sat, 10 Nov 2007 13:56:35 -0800, Michael Bacarella wrote:

> The id2name.txt file is an index of primary keys to strings.  They look
> like this:
> 
> 11293102971459182412:Descriptive unique name for this record\n
> 950918240981208142:Another name for another record\n
> 
> The file's properties are:
> 
> # wc -l id2name.txt
> 
> 8191180 id2name.txt
> # du -h id2name.txt
> 517Mid2name.txt
> 
> I'm loading the file into memory with code like this:
> 
> id2name = {}
> for line in iter(open('id2name.txt').readline,''):
> id,name = line.strip().split(':')
> id = long(id)
> id2name[id] = name

That's an awfully complicated way to iterate over a file. Try this 
instead:

id2name = {}
for line in open('id2name.txt'):
id,name = line.strip().split(':')
id = long(id)
id2name[id] = name


On my system, it takes about a minute and a half to produce a dictionary 
with 8191180 entries.


> This takes about 45 *minutes*
> 
> If I comment out the last line in the loop body it takes only about 30
> _seconds_ to run. This would seem to implicate the line id2name[id] =
> name as being excruciatingly slow.

No, dictionary access is one of the most highly-optimized, fastest, most 
efficient parts of Python. What it indicates to me is that your system is 
running low on memory, and is struggling to find room for 517MB worth of 
data.


> Is there a fast, functionally equivalent way of doing this?
> 
> (Yes, I really do need this cached.  No, an RDBMS or disk-based hash is
> not fast enough.)

You'll pardon me if I'm skeptical. Considering the convoluted, weird way 
you had to iterate over a file, I wonder what other less-than-efficient 
parts of your code you are struggling under. Nine times out of ten, if a 
program runs too slowly, it's because you're using the wrong algorithm.



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


Re: Populating a dictionary, fast

2007-11-10 Thread Paul Rubin
Michael Bacarella <[EMAIL PROTECTED]> writes:
> Is there a fast, functionally equivalent way of doing this?
> 
> (Yes, I really do need this cached.  No, an RDBMS or disk-based hash
> is not fast enough.)

As Steven says maybe you need to add more ram to your system.  The
memory overhead of dictionary cells is considerable.  If worse comes
to worse you could concoct some more storage-efficient representation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String/Decimal issues

2007-11-10 Thread Steven D'Aprano
On Sat, 10 Nov 2007 09:02:01 -0800, Mike Howarth wrote:

> Hi
> 
> Seem to be having a bit of brainfreeze this evening.
> 
> Basically I'm reducing an array of prices like so:
>>> subtotal = reduce(operator.add, itemprices)
> 
> This gives me a string of '86.00.00' which I am trying to use with
> decimal objects. Python 2.4 is not particularly happy with this.

Let me guess... your test data is:

itemprices = ['86.0', '0.00']

What happens if you use test data like this?

itemprices = ['86.0', '0.00', '1.99', '12.03']



The first problem that you have is that your prices are strings. Is that 
deliberate? This is not necessarily a fault.

Your second problem is that the + operator concatenates strings, not adds 
them. "1.0" + "2.0" = "1.02.0", not "3.0". This, on the other hand, is 
absolutely a fault. Your code is producing invalid data.


> Additionally I can't simply convert the string to a decimal as it would
> be invalid given it has multiple decimal points.

Yes. Rather than trying to fix the invalid data after it is produced, you 
should fix your code so it doesn't produce the wrong answer in the first 
place.


> Being relatively new to python, I'm not sure how I could round the
> string or similar. Anyone got any ideas?


This is NOT the answer you NEED, but this is the answer you ask for. To 
cut out the extra decimal places, use this:

>>> subtotal = '86.00.00'
>>> subtotal[:-3]
'86.00'

Now that I've told you how to do it, let me re-iterate that you shouldn't 
do it. Your problem isn't that your result has an extra ".00" at the end 
of the result. Your problem is that your result is WRONG. Fix the result 
in the first place.

I'd be looking at something like this:


# start with a list of strings
itemprices = ['86.0', '0.00', '1.99', '12.03']
# convert them into decimal objects
itemprices = map(decimal.Decimal, itemprices)
# and add them
subtotal = sum(itemprices)



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


Re: Valgrind and Python

2007-11-10 Thread Esa A E Peuha
Jean-Paul Calderone <[EMAIL PROTECTED]> writes:

> Did you use the suppression file?

No, I didn't, because I was testing Valgrind on binaries that happened
to be installed on a Linux machine, and had no reason to treat Python
specifically.  I see that README.valgrind explains why Python reads
memory from apparently random addresses, so it seems there's nothing to
worry about.

-- 
Esa Peuha
student of mathematics at the University of Helsinki
http://www.helsinki.fi/~peuha/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Populating a dictionary, fast

2007-11-10 Thread Michael Bacarella
> That's an awfully complicated way to iterate over a file. Try this 
> instead:

>
> id2name = {}
> for line in open('id2name.txt'):
>id,name = line.strip().split(':')
>id = long(id)
>id2name[id] = name
>
> > This takes about 45 *minutes*
> > 
> On my system, it takes about a minute and a half to produce a
 dictionary 
> with 8191180 entries.

Doing something similar on my system is very fast as well.

$ cat dict-8191180.py

#!/usr/bin/python



v = {}

for i in xrange(8191180):

v[i] = i


$ time ./dict-8191180.py

real0m5.877s
user0m4.953s
sys 0m0.924s

But...

> > If I comment out the last line in the loop body it takes only about
 30
> > _seconds_ to run. This would seem to implicate the line id2name[id] =
> > name as being excruciatingly slow.
>
> No, dictionary access is one of the most highly-optimized, fastest,
 most 
> efficient parts of Python. What it indicates to me is that your system
 is 
> running low on memory, and is struggling to find room for 517MB worth
 of 
> data.


If only it were so easy.




$ free


 total   used   free sharedbuffers cached


Mem:   739024421034485286796  0  389961982756


-/+ buffers/cache:  816967308548


Swap:  2096472  102802086192





Here's your Python implementation running as badly as mine did.



$ wc -l id2name.txt

8191180 id2name.txt



$ cat cache-id2name.py

#!/usr/bin/python



id2name = {}

for line in open('id2name.txt'):

id,name = line.strip().split(':',1)

id = long(id)

id2name[id] = name



$ time ./cache-id2name.py

^C

I let it go 30 minutes before killing it since I had to leave.  Here it is in 
top before I did the deed.


PID USER  PR  NI  VIRT  RES  SHR S %CPU %MEMTIME+  COMMAND

18802 root  25   0 1301m 1.2g 1148 R 99.9 17.1  36:05.99 cache-id2name.p



36 minutes, 05.99 seconds.



To rule out the file reading/parsing logic as culprit, here's same thing, but 
with

dictionary insertion removed.



$ cat nocache-id2name.py

#!/usr/bin/python



id2name = {}

for line in open('id2name.txt'):

id,name = line.strip().split(':',1)

id = long(id)



$ time ./nocache-id2name.py



real0m33.518s

user0m33.070s

sys 0m0.415s





Here's a Perl implementation running very fast.



$ cat cache-id2name.pl

#!/usr/bin/perl



my %id2name = ();

my $line;

my $id;

my $name;

open(F,") {

chomp($line);

($id,$name) = split(/:/,$line,1);

$id = int($id);

$id2name{$id} = $name;

}



$ time ./cache-id2name.pl



real0m46.363s

user0m43.730s

sys 0m2.611s





So, you think the Python's dict implementation degrades towards O(N)

performance when it's fed millions of 64-bit pseudo-random longs?




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


python - an eggs...

2007-11-10 Thread bruce
Hi...

I have a python script/app that i'm dealing with. It uses Durus, which
installs as an egg.

I'm trying to figure out how to modify any of the underlying source files or
the egg, short of modifying the original source file, and then having to
reinstall the egg via "python setup.py install"...

I'm relatively new to python/egg(s), but I can't seem to find a way to
accomplish this via the 'net.

I've looked in the Install file, as well as the setup.py thinking that I
migt be able to find a way to simply build the app, and to have the required
scripts installed under the "/usr/lib/python2.4/site-packages" tree as the
other pyhon apps/scripts are

The app I'm working with is Durus 3.7. I've got the tar.gz uncompressed, but
the only thing I get is an egg file, which gets installed/placed under the
"site-packages" dir.

Any help/pointers/etc.. would be helpful!!

Thanks


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


Re: A JEW hacker in California admits distributing malware that let him steal usernames and passwords for Paypal accounts.

2007-11-10 Thread zionist . news
On Nov 10, 2:22 pm, "Frank Arthur" <[EMAIL PROTECTED]> wrote:
> <[EMAIL PROTECTED]> wrote in message
>
> news:[EMAIL PROTECTED]
>
> >A Jew hacker in California admits distributing malware that let him
> > steal usernames and passwords for Paypal accounts.
>
> 83 Newspapers reported the "Hacker story" and not one mentioned the
> word Jew.
> Who but a madman would say what the hacker's religion was- IF he knew!
>
> Los Angeles hacker to plead guilty to infecting 250,000 computers to
> steal identities
>
> The Associated PressPublished: November 10, 2007
>
>   E-Mail Article
>
> LOS ANGELES: A computer security consultant accused of installing
> malicious software to create an army of up to 250,000 "zombie"
> computers so he could steal identities and access bank accounts will
> plead guilty to four federal charges.
>
> John Schiefer, 26, of Los Angeles, agreed Friday to plead guilty to
> accessing protected computers to conduct fraud; disclosing illegally
> intercepted electronic communications; wire fraud and bank fraud, the
> U.S. Attorney's office said.
>

Listen to Mr Benjamin Freedman's speech on google. He calls the
ASHKENAZI KHAZARS by the label "the so called jews". Jew is not a
religion anymore. The Khazars dont practice the Torah. According to
Neturei Karta, they are now only a race, a power group or zionists. We
will still use the word jew because it is pithy, but we mean by it
zionists as the Neturei Karta say or "the so called jews" as Mr
Benjamin Freedman says.

Having clarified that, it is quite clear that the MISCHIEFER, John
Schiefer, 26 of LOS ANGELES who pleaded guilty is a KHAZAR, ASHKENAZI.
That is his race and we bring it out only because according to the 911
truth research, the event was a controlled demolition. Explosives were
used and the whole ownership and security of the building was in the
hands of the non-islamics. Larry Silverstein is an ASHKENAZI KHAZAR
jew.

Professor Steven Jones has found the residue of thermate in the dust
of the buildings. KMnO4 residue, ie high amounts of SULFUR, potassium,
manganese, and the iron dust particles are SPHERICAL. Which means that
they saw a very high temperature above the melting point.

You can lie as much as you want. The physics and the circumstantial
evidence cannot hide your lie.

The anthrax mailer was NOT an Islamic.

Otherwise the FBI must produce the criminal with out ANY ambiguity.

Also, what about the 5 dancing ISRAELIS and the VAN WITH EXPLOSIVES on
the WASHINGTON BRIDGE. Show us the ARABS who were in the VAN. They
were Israelis trying to blow  up the George Washington Bridge, and put
the blame on ARABS.

The police caught these people. I have great respect for the POLICE
who do their jobs honestly.


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


Re: Writing a CGI to query DB

2007-11-10 Thread Bighead
On Nov 10, 7:18 pm, TheFlyingDutchman <[EMAIL PROTECTED]> wrote:
> On Nov 9, 8:33 pm, Bighead <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > I am currently working on a CGI deployed on an Apache server, which,
> > given an arbitrary SQL, fetches raw data from a remote DB server and
> > return them in a HTML page. This CGI works fine on quick SQLs.
>
> > But when I try to run a slow SQL on this CGI, through a Squid Proxy, I
> > always get the Error message from Squid: Zero Sized Reply, after 5
> > minutes.
>
> > The SQL itself is correct, since I have tried it directly on the DB
> > server. So what do you think might cause the problem? Thank you.
>
> Slow SQL = query that takes a long time? How long does the query take
> if you run it on the same machine as the DB server without a Squid
> Proxy?


It takes 10 minutes to run this SQL. Squid's error message pops up in
about 5 minutes.

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


Re: Writing a CGI to query DB

2007-11-10 Thread Bighead
On Nov 11, 6:20 am, paulC <[EMAIL PROTECTED]> wrote:
> On 10 Nov, 04:33, Bighead <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > I am currently working on a CGI deployed on an Apache server, which,
> > given an arbitrary SQL, fetches raw data from a remote DB server and
> > return them in a HTML page. This CGI works fine on quick SQLs.
>
> > But when I try to run a slow SQL on this CGI, through a Squid Proxy, I
> > always get the Error message from Squid: Zero Sized Reply, after 5
> > minutes.
>
> > The SQL itself is correct, since I have tried it directly on the DB
> > server. So what do you think might cause the problem? Thank you.
>
> This sounds a lot like an apache server configuration problem. From
> the squid FAQ;
>
> 11.51 Why do I sometimes get ``Zero Sized Reply''?
>
> This happens when Squid makes a TCP connection to an origin server,
> but for some reason, the connection is closed before Squid reads any
> data. Depending on various factors, Squid may be able to retry the
> request again. If you see the ``Zero Sized Reply'' error message, it
> means that Squid was unable to retry, or that all retry attempts also
> failed.
>
> The apache server has a default TimeOut of 300 seconds.
>
> This question might be more usefully answered by the apache user
> group.
>
> Regards, Paul Clinch


Thank you.
TimeOut of 300 seconds, does it mean that the connection will be
closed by remote Apache server if the server does not provide any data
in 300 seconds? So I can just let the server generate data
continuously, and the connection will not be cut off, right?

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


Re: Populating a dictionary, fast

2007-11-10 Thread Steven D'Aprano
On Sat, 10 Nov 2007 17:18:37 -0800, Michael Bacarella wrote:


> So, you think the Python's dict implementation degrades towards O(N)
> performance when it's fed millions of 64-bit pseudo-random longs?

No.

Here's my sample file:

$ wc -l id2name.txt
8191180 id2name.txt
$ ls -lh id2name.txt
-rw-rw-r-- 1 steve steve 371M 2007-11-11 14:00 id2name.txt

And the results of reading it into a dict (code follows below):

$ time ./slurp_dict.py
Starting at Sun Nov 11 14:26:51 2007
Line 0
Line 100
Line 200
Line 300
Line 400
Line 500
Line 600
Line 700
Line 800
Items in dict: 8191180
Completed import at Sun Nov 11 14:29:31 2007
Starting to delete dict...


Traceback (most recent call last):
  File "./slurp_dict.py", line 20, in 
del id2name
KeyboardInterrupt

real35m52.334s
user1m17.663s
sys 0m16.758s


Notice that the dict is completely read into memory in just two and a 
half minutes. The script then tries to delete the dict, and 32 minutes 
later is still struggling. That's the point I got sick of waiting and 
interrupted the script.

Conclusion: it's a memory issue, or maybe a garbage collection issue, not 
a problem with dicts.




Here's my code for creating the key:value file in the first place:

#!/usr/bin/python
"""Make a big file of 64-bit integer keys plus random values."""

bits64 = 2**64
import random
template = '%d:This is a bunch of text...\n'
fp = open('id2name.txt', 'w')
for i in xrange(8191180):
fp.write(template % random.randint(0, bits64))
fp.close()

###

And here's my code for slurping it in to a dict:

#!/usr/bin/python
"""Read a big file into a dict."""

import gc
import time
print "Starting at %s" % time.asctime()
flag = gc.isenabled()
gc.disable()
id2name = {}
for n, line in enumerate(open('id2name.txt', 'r')):
if n % 100 == 0:
# Give feedback.
print "Line %d" % n
id,name = line.strip().split(':', 1)
id = long(id)
id2name[id] = name
print "Items in dict:", len(id2name)
print "Completed import at %s" % time.asctime()
print "Starting to delete dict..."
del id2name
print "Completed deletion at %s" % time.asctime()
if flag:
gc.enable()
print "Finishing at %s" % time.asctime()

###


So, what can you do? Given that I'm not willing to do any more unpaid 
experimentation for you, here are my suggestions, in no particular order:

(1) Presumably you don't want to run your app with the garbage collector 
turned off. You might still want to play around with the gc module to see 
what you can learn.

(2) More memory will help avoid paging. If you can't get more memory, try 
more virtual memory. It will still be slow, but at least the operating 
system doesn't have to try moving blocks around as much.

(3) Are you sure you need all eight-million-plus items in the cache all 
at once?

(4) There are lots of algorithms out there for dealing with data too big 
to fit into main memory. Do some research.

(5) There is a data structure designed for dealing with tens of millions 
of records at once. It is called "a database". If you can't find a better 
algorithm, and refuse to use an existing RDBMS, I suspect you're going to 
end up inventing a primitive, inefficient, buggy database which is no 
faster than existing systems out there.



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


System exit hanging in Leopard

2007-11-10 Thread Tony Mullen
Hello,

(I posted this once before, but haven't gotten a response.  This is a
pretty heavy traffic mailing list, so it's hardly surprising, but I'm
going to bump the question in case anybody has seen or can replicate
(or not replicate) this issue.  Thx)

I'm using Tkinter to create widgets in Python 2.5 on OS X 10.5.  When
I call root.quit or sys.exit in any way, the following traceback
appears, after which the application stops responding and just gives
the spinning rainbow cursor.  The IDLE editor and the Python shell
remain responsive, and I can kill the application from the command
line, but not any other way.  I don't see anything problematic in the
traceback, but I don't think that the application should be hanging
like this.

Is this likely a Leopard-related issue?

Thanks for any responses,

Tony

Traceback (most recent call last):
 File "/Users/tonymullen/Documents/ui", line 11, in 
   widget.mainloop()
 File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk/Tkinter.py",
line 1023, in mainloop
   self.tk.mainloop(n)
 File 
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk/Tkinter.py",
line 1405, in __call__
   raise SystemExit, msg
SystemExit

-- 
Tony Mullen
Department of Computer Science, Tsuda College
2-1-1 Tsudamachi, Kodairashi
Tokyo 187-8577, Japan
Tel: +81-42-342-5482
-- 
http://mail.python.org/mailman/listinfo/python-list


Join DOWNLOAD CENTRE

2007-11-10 Thread Cope
Post your softwares and other digital products here. Note that your
post must be downloadable.

Cope,
Owner.
http://groups.google.co.in/group/download-centre

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


Re: Python Extension Building Network

2007-11-10 Thread Yu-Xi Lim
[EMAIL PROTECTED] wrote:
> Hi,
> 
> I am trying to get a small group of volunteers together to create
> Windows binaries for any Python extension developer that needs them,
> much like the package/extension builders who volunteer their time to
> create Linux RPMs.
> 
> Mike
> 

It's not entirely clear to me what you're compiling. Most of the modules 
you have there do not have native code. I'm guessing your main focus is 
building .exe installers for Windows users.

If it's just installers of pure Python code, why the extra effort of 
using both VS and MingW? AFAIK, they both yield functionally identical 
results---the exact same .py files get installed.

I'm also not sure how big a task this is or the issues involved, but 
here's my take based on what I've read:

Throwing more manpower at the task is not the solution. The actual 
process can be and SHOULD BE highly automated. All that's needed are a 
proper distutils script, and proper tests. Both responsibilities should 
fall on the shoulders of the module authors, though I guess experienced 
volunteers can help out with the former.

If the module is pure Python, there should be little need for testing 
the installer specifically on Windows. If there's a failure, then the 
module itself is buggy (e.g. making platform-specific assumptions) or 
there's similar problem with the install script.

For a large number of modules on PyPI, building the installer is trivial 
(assuming pure Python, and a setup script). Compiling them can be easily 
automated: 1) check PyPI for updates 2) download the latest update 3) 
build the .exe 3) upload to a website. All that remains is the need for 
some hardware (a build farm) and the occasional manual intervention.

If I'm not mistaken, distutils can build Windows installers on other 
platforms. Maybe you could set up a Linux LiveCD with the necessary 
tools installed and distribute that. Module authors who want to build 
Windows installers can easily use that CD. Volunteers wanting to help 
can do so easily without having to repeat the task of setting up the 
toolchain separately.


I've done some work as a port maintainer (aka package maintainer) for 
FreeBSD. The BSD port system is somewhat closer to PEAK's Easy Install, 
however binary packages (similar to RPMs or DEBs) are also available. 
The port maintainer's job is solely to ensure that the Makefile (build 
script) is working and up to date. The actual testing of the code is 
done by the authors of the software itself and the port maintainer only 
ensures that the install script works right. Binary packages are built 
by an automated system using a cluster of computers for various 
architectures and supported OS versions. Errors during builds are sent 
to to port maintainers.

A similar system is used for most Linux distributions with a central 
repository for packages.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Populating a dictionary, fast

2007-11-10 Thread Yu-Xi Lim
Steven D'Aprano wrote:
> (2) More memory will help avoid paging. If you can't get more memory, try 
> more virtual memory. It will still be slow, but at least the operating 
> system doesn't have to try moving blocks around as much.
> 

Based on his previous post, it would seem he has 7GB of RAM (with about 
5GB free) and 2GB of swap. I don't think RAM is the issue.

Maybe there's something wrong with his specific Python installation. 
What version is it and was it compiled by him?
-- 
http://mail.python.org/mailman/listinfo/python-list


Pyzzle development?

2007-11-10 Thread John Salerno
Does anyone happen to know what's going on with the development of the 
Pyzzle engine (for creating Myst-like games with Python)? Seems stalled 
for a long time, but I'm not sure if it's just been abandoned.

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


Re: Populating a dictionary, fast

2007-11-10 Thread Paul Rubin
Michael Bacarella <[EMAIL PROTECTED]> writes:
> If only it were so easy.

I think I know what's going on, the dictionary updates are sending the
GC into quadratic behavior.  Try turning off the GC:

import gc
gc.disable()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy 3D graphics for rendering geometry?

2007-11-10 Thread gsal
On Nov 10, 11:13 am, Scott David Daniels <[EMAIL PROTECTED]>
wrote:
>
> Well, what kind of computer, what version of everything (OS, Python,
> VPython), what display card, 

Windows XP Professional
Version 2002, Service Pack 2
1.4GHz, 512MB

ATI MOBILITY RADEON 9000

Python 2.5, VPython 2.5

gsal

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


Re: Join DOWNLOAD CENTRE

2007-11-10 Thread Danyelle Gragsone
Why?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: security code whit python

2007-11-10 Thread [EMAIL PROTECTED]
On 10 Kas m, 23:57, Wildemar Wildenburger
<[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > I want to create picture of security code.can i do it ?
>
> I don't know what you mean by "security code".
>
> I take it you want to create technical diagrams, from a sort of
> algorithmic description?
>
> PIL might help you, as paulC pointed out. It works on raster images
> (bitmaps).
>
> pYx is a tool library for vector graphics and scientific plots. Maybe
> that can help. I've produced nice looking graphics of search-trees
> within about 60 minutes of installing it.
>
> This example is copied right from the pyx site:
>
> from pyx import *
> c = canvas.canvas()
> c.text(0, 0, "Hello, world!") # Put oruccim here, if you want
> c.stroke(path.line(0, 0, 2, 0))
> c.writeEPSfile("hello")
> c.writePDFfile("hello")
>
> http://pyx.sourceforge.net/>
>
thank you
but it said """
Traceback (most recent call last):
  File "", line 1, in 
c.text(0, 0, "Hello, world!")
  File "C:\web\apache\python\lib\pyx\canvas.py", line 309, in text
return self.insert(self.texrunner.text(x, y, atext, *args,
**kwargs))
  File "C:\web\apache\python\lib\pyx\text.py", line 1199, in text
self.execute(expr, self.defaulttexmessagesdefaultrun +
self.texmessagesdefaultrun + texmessages)
  File "C:\web\apache\python\lib\pyx\text.py", line 899, in execute
self.fontmap = dvifile.readfontmap(self.fontmaps.split())
  File "C:\web\apache\python\lib\pyx\dvifile.py", line 386, in
readfontmap
raise RuntimeError("cannot find font mapping file '%s'" %
filename)
RuntimeError: cannot find font mapping file 'psfonts.map'
"""
I have setuped pyx i wonder i have mistake?

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


Re: Portrait of a "real life" __metaclass__

2007-11-10 Thread Jonathan Gardner
On Nov 10, 3:34 am, Mark Shroyer <[EMAIL PROTECTED]> wrote:
> On 2007-11-10, Jonathan Gardner <[EMAIL PROTECTED]> wrote:
> > What would I have done? I wouldn't have had an age matching class. I
> > would have had a function that, given the datetime and a range
> > specification, would return true or false. Then I would've written
> > another function for matching emails. Again, it takes a specification
> > and the email and returns true or false.
>
> There isn't much difference between
>
>   match_calendar_month(2007, 11, message)
>
> and
>
>   m = CalendarMonthMatcher(2007, 11)
>   m.match(message)

Yes, there isn't a world of difference between the two. But there is a
world of difference between those and:

   match(message, before=date(2007, 12, 1), after=date(2007, 11, 1))

And you can add parameters as needed. In the end, you may have a lot
of parameters, but only one match function and only one interface.

>  But take for example two of my app's mailbox actions -- these aren't
> their real names, but for clarity let's call them ArchiveByMonth and
> SaveAttachmentsByMonth.  The former moves messages from previous
> months into an archival mbox file ./archives//MM.mbox
> corresponding to each message's month, and the latter saves message
> attachments into a directory ./attachments//MM/.  Each of these
> actions would work by using either match_calendar_month() or
> CalendarMonthMatcher().match() to perform its action on all messages
> within a given month; then it iterates through previous months and
> repeats until there are no more messages left to be processed.
>
> In my object-oriented implementation, this iteration is performed by
> calling m.previous() on the current matcher, much like the
> simplified example in my write-up.  Without taking the OO approach,
> on the other hand, both types of actions would need to compute the
> previous month themselves; sure that's not an entirely burdensome
> task, but it really seems like the wrong place for that code to
> reside.  (And if you tackle this by writing another method to return
> the requisite (year, month) tuple, and apply that method alongside
> wherever match_calendar_month() is used...  well, at that point
> you're really just doing object-oriented code without the "class"
> keyword.)
>
> Furthermore, suppose I want to save attachments by week instead of
> month: I could then hand the SaveAttachmentsByPeriod action a
> WeekMatcher instead of a MonthMatcher, and the action, using the
> matcher's common interface, does the job just as expected.  (This is
> an actual configuration file option in the application; the nice
> thing about taking an OO approach to this app is that there's a very
> straightforward mapping between the configuration file syntax and
> the actual implementation.)
>
> It could be that I'm still "thinking in Java," as you rather
> accurately put it, but here the object-oriented approach seems
> genuinely superior -- cleaner and, well, with better encapsulated
> functionality, to use the buzzword.
>

Or it could be that you are confusing two things with each other.

Let me try to explain it another way. Think of all the points on a
grid that is 100x100. There are 10,000 points, right? If you wanted to
describe the position of a point, you could name each point. You'd
have 10,000 names. This isn't very good because people would have to
know all 10,000 names to describe a point in your system. But it is
simple, and it is really easy to implement. But hey, we can just
number the points 0 to  and it gets even simpler, right?

OR you could describe the points as an (x,y) pair. Now people only
have to remember 200 different names--100 for the columns, 100 for the
rows. Then if you used traditional numbers, they'd only have to be
able to count to 100.

Computer science is full of things like this. When you end up with
complexity, it is probably because you are doing something wrong. My
rule of thumb is if I can't explain it all in about 30 seconds, then
it is going to be a mystery to everyone but myself no matter how much
documentation I write.

How do you avoid complexity? You take a step back, identify patterns,
or pull different things apart from each other (like rows and
columns), and try to find the most basic principles to guide the
entire system.

The very fact that you are talking about months (and thus days and
weeks and years and centuries, etc...) and not generic dates means you
have some more simplifying to do in your design elsewhere as well.

Rewrite the SaveAttachmentsByMonth so that it calls a more generic
SaveAttachmentsByDateRange function. Or better yet, have it
FilterEmailsByDateRange and ExtractAttachment and SaveAttachment. Or
even better, have it FilterEmailsBySpecification(date_from=X,
date_to=Y) and SaveAttachmentl.

Do you see the point? Your big function SaveAttachmentsByMonth is kind
of like point number 735. It's easier to describe it as the point at
(7,35) than as a single number. It's bett