Re: finding out the call (and not only the caller)

2007-10-08 Thread [EMAIL PROTECTED]
On Oct 7, 2:47 pm, "Francesco Guerrieri" <[EMAIL PROTECTED]>
wrote:
> Hi,
>
> Today I've been thinking a bit about the "python internals". Inspired
> by this recipe:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66062
> I found out a little problem which haven't been able to solve.
> In short, is there a way to find out how a given name lookup was started?

If you constrain the problem, yes, it's possible.  However, the
solution below is limited to CPython and has other limits.

> It is not enough to know the name of the caller as given by the recipe.
>
> a little example:
> import inspect
>
> class test(object):
> def __init__(self, a_list):
> self.my_list = a_list
> def info(self):
> for counter, item in
> enumerate(inspect.getouterframes(inspect.currentframe())):
> print counter, item
> return self.my_list
>  data = property(info)
>
> if __name__ == '__main__':
> a = test([,])
> def g(a_seq):
> for item in a_seq:
> print item, '\n'
> g(a.data)
>
> This prints
> 0 (, 'myfile.py', 10, 'info', ['
> for counter, item in
> enumerate(inspect.getouterframes(inspect.currentframe())):\n'], 0)
> 1 (, 'myfile.py', 38, '', ['
> g(a.data)\n'], 0)
> 
> 
>
> What I would like is a reference to g itself, and not only to
> '' which is the caller according to f_code.co_name.
> I thought of manually parsing the string 'g(a.data)\n' to extract
> the name but I'm sure that it would be a rather fragile approach, and
> so I decided that it was time to ask for help :-)
> To 'get a feeling', I tried to disassemble the code:
>
> code = compile('g(a.data)', 'test', 'single')
> dis.dis(code)
>
> and this is the result
>
> 0 LOAD_NAME0 (g)
> 3 LOAD_NAME1 (a)
> 6 LOAD_ATTR2 (data)
> 9 CALL_FUNCTION1
> 12 PRINT_EXPR
> 13 LOAD_CONST   0 (None)
> 16 RETURN_VALUE
>
> So ... I'm looking for the first name loaded. Is there a reference to
> it, somewhere?

#!/usr/bin/python

import sys, opcode


def WhoCalledMe(a, *args, **kwargs):
  # Get the calling frame and the bytecode index of the last
instruction.
  f = sys._getframe(1)
  lasti = f.f_lasti
  code = f.f_code.co_code

  # TODO: Needs to be extended for the other 3 variants of
CALL_FUNCTION.
  assert ord(code[lasti]) == opcode.opmap['CALL_FUNCTION']
  # Get the number of arguments the function was called with.
  num_args = ord(code[lasti+1])
  num_kwargs = ord(code[lasti+2])

  # Get the instruction that loaded the object being called.
  # Work backwards from the function call.  3 is the size of each
LOAD_* op
  # (assuming EXTENDED_ARG is not used).  1 for the previous opcode,
  # number of positional arguments, and 2 for kwargs (1 for the name,
  # 1 for the value).
  i = lasti - 3 * (1 + num_args + 2 * num_kwargs)
  # Again, this assumes EXTENDED_ARG is not used.
  load_index = ord(code[i+1]) + (ord(code[i+2]) << 8)

  # Another assumption that isn't always true, but convenient for our
case.
  opname = opcode.opname[ord(code[i])]
  assert opname.startswith('LOAD_')

  # Get the name of the variable and its value.
  name = value = None
  if opname in ('LOAD_FAST', 'LOAD_NAME'):
try:
  name = f.f_code.co_varnames[load_index]
  value = f.f_locals[name]
except LookupError:
  assert opname == 'LOAD_NAME'
  # opname must be LOAD_NAME and the variable is a global, ignore
it.

  if opname in ('LOAD_GLOBAL', 'LOAD_NAME') and not name:
try:
  name = f.f_code.co_names[load_index]
  value = f.f_globals[name]
except LookupError:
  print 'Uh-oh.  Should have found the name in globals.'
  # TODO: handle LOAD_CONST, LOAD_DEREF and LOAD_CLOSURE.

  print 'Called by', name, 'value is', value


def main():
  WhoCalledMe(0)

  MeDammit = WhoCalledMe
  MeDammit(1, k1=1, k2=2)


if __name__ == '__main__':
  main()

  WhoCalledMe(0)

  MeDammit = WhoCalledMe
  MeDammit(1, k1=1, k2=2)

# end of script

If you run the scrit above, it should print something like:

Called by WhoCalledMe value is 
Called by MeDammit value is 
Called by WhoCalledMe value is 
Called by MeDammit value is 

The code doesn't handle all the cases (e.g., nested functions), but
gives you an idea of what can be done and where to look for the info
(ie, in the stack frame and how to parse the byte codes to some
extent).  For nested functions, look in co_consts.

Bytecodes are specific to CPython.  This code won't work on
IronPython, Jython, or PyPy.  This code really shouldn't be used for
production.  However, it demonstrates some of the info available.

n

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


Re: The fundamental concept of continuations

2007-10-08 Thread gnuist006
On Oct 8, 11:09 pm, "." <[EMAIL PROTECTED]> wrote:
> On Tue, 09 Oct 2007 05:15:49 +, gnuist006 wrote:
> > Again I am depressed to encounter a fundamentally new concept that I
> > was all along unheard of. Its not even in paul graham's book where i
> > learnt part of Lisp. Its in Marc Feeley's video.
>
> > Can anyone explain:
>
> > (1) its origin
>
> One of the lambda papers, I think.  I don't remember which.
>
> > (2) its syntax and semantics in emacs lisp, common lisp, scheme
>
> elisp and Common Lisp don't have them (although sbcl and maybe others user
> continuations internally).  In scheme CALL-WITH-CURRENT-CONTINUATION takes
> a function of one argument, which is bound to the current continuation.
> Calling the continuation on some value behaves like
> CALL-WITH-CURRENT-CONTINUATION returning that value.  So
>  (call/cc (lambda (k) (k 42))) => 42
> You can think of it as turning the whatever would happen after call/cc
> was called into a function.  The most practical use for continuations in
> implementing control structures, though there are some other neat tricks
> you can play with them.
>
> > (3) Is it present in python and java ?
>
> Certainly not Java, I dunno about Python.  I've never seen someone use
> them in Python, but the pythonistas seem to want to add everything but a
> decent lambda to their language so I wouldn't be surprised if someone had
> added a call/cc.  Ruby has it.
>
> > (4) Its implementation in assembly. for example in the manner that
> > pointer fundamentally arises from indirect addressing and nothing new.
> > So how do you juggle PC to do it.
>
> You have Lisp in Small Pieces.  Read Lisp in Small Pieces.
>
> > (5) how does it compare to and superior to a function or subroutine
> > call. how does it differ.
>
> You use them like a function call.  You can also use them like
> setjmp/longjmp in C.  You can implement coroutines with them, or
> events, or simulate non-determinism or write things like ((call/cc call/cc)
> (call/cc call/cc)) and make your head explode, use it like goto's inbred
> second cousin or in general whatever perverse things you might like to do
> with the flow of control in your program.
>
>
>
> > Thanks a lot.
>
> > (6) any good readable references that explain it lucidly ?
>
> Lisp in Small Pieces for implementation details,  the Scheme Programming
> Language for examples.

which lambda paper ?

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


Re: The fundamental concept of continuations

2007-10-08 Thread gnuist006
On Oct 8, 11:07 pm, Bakul Shah <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
>
>  > Again I am depressed to encounter a fundamentally new concept that I
>  > was all along unheard of.
>
> The concept is 37 years old.  Wadsworth in his "Continuation
> Revisited" paper says he & Strachey were struggling with
> extending the technique of denotational semantics to describe
> jumps and not finding a satisfactory answer.  Then, in his
> words:
>
>in October 1970 Strachey showed me a paper "Proving
>algorithms by tail functions" by Mazurkiewicz [2] which he
>had obtained from an IFIP WG2.2 meeting. Just the phrase
>"tail functions" in the title was enough -- given the
>experience of our earlier struggles -- for the ideas to
>click into place! The (meaning of the) "rest of the program"
>was needed as an argument to the semantic functions -- just
>so those constructs that did not use it, like jumps, could
>throw it anyway. The term "continuation" was coined as
>capturing the essence of this extra argument (though I
>often wished to have a shorter word!) and the rest, as they
>say, is history.
>
>  > Its not even in paul graham's book where i
>  > learnt part of Lisp. Its in Marc Feeley's video.
>  >
>  > Can anyone explain:
>  >
>  > (1) its origin
>  > (2) its syntax and semantics in emacs lisp, common lisp, scheme
>  > (3) Is it present in python and java ?
>  > (4) Its implementation in assembly. for example in the manner that
>  > pointer fundamentally arises from indirect addressing and nothing new.
>  > So how do you juggle PC to do it.
>  > (5) how does it compare to and superior to a function or subroutine
>  > call. how does it differ.
>  >
>  > Thanks a lot.
>  >
>  > (6) any good readable references that explain it lucidly ?
>
> You might like this one:
>
> http://www.intertwingly.net/blog/2005/04/13/Continuations-for-Curmudg...

thanks for the link but can you plz upload the paper so we can also
get it.

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


Re: The fundamental concept of continuations

2007-10-08 Thread gnuist006
On Oct 8, 10:59 pm, Barb Knox <[EMAIL PROTECTED]> wrote:

>
> Lambda calculus.  Instead of function A returning to its caller, the
> caller provides an additional argument (the "continuation") which is a
> function B to be called by A with A's result(s).  In pure "continuation
> style" coding, nothing ever "returns" a result.
>
> It is easy to mechanically transform normal function-style lambda
> calculus into continuation-style, but the reverse is not so.
>

Explanation and reference please

>
> You can have a "spaghetti stack", or keep continuation data-structures
> in the heap.

A picture, diagram? a picture is worth a thousand words


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


Re: The fundamental concept of continuations

2007-10-08 Thread .
On Tue, 09 Oct 2007 05:15:49 +, gnuist006 wrote:

> Again I am depressed to encounter a fundamentally new concept that I
> was all along unheard of. Its not even in paul graham's book where i
> learnt part of Lisp. Its in Marc Feeley's video.
> 
> Can anyone explain:
> 
> (1) its origin
One of the lambda papers, I think.  I don't remember which.

> (2) its syntax and semantics in emacs lisp, common lisp, scheme
elisp and Common Lisp don't have them (although sbcl and maybe others user
continuations internally).  In scheme CALL-WITH-CURRENT-CONTINUATION takes
a function of one argument, which is bound to the current continuation. 
Calling the continuation on some value behaves like
CALL-WITH-CURRENT-CONTINUATION returning that value.  So 
 (call/cc (lambda (k) (k 42))) => 42
You can think of it as turning the whatever would happen after call/cc
was called into a function.  The most practical use for continuations in
implementing control structures, though there are some other neat tricks
you can play with them.

> (3) Is it present in python and java ?
Certainly not Java, I dunno about Python.  I've never seen someone use
them in Python, but the pythonistas seem to want to add everything but a
decent lambda to their language so I wouldn't be surprised if someone had
added a call/cc.  Ruby has it.

> (4) Its implementation in assembly. for example in the manner that
> pointer fundamentally arises from indirect addressing and nothing new.
> So how do you juggle PC to do it.
You have Lisp in Small Pieces.  Read Lisp in Small Pieces.

> (5) how does it compare to and superior to a function or subroutine
> call. how does it differ.
You use them like a function call.  You can also use them like
setjmp/longjmp in C.  You can implement coroutines with them, or
events, or simulate non-determinism or write things like ((call/cc call/cc)
(call/cc call/cc)) and make your head explode, use it like goto's inbred
second cousin or in general whatever perverse things you might like to do
with the flow of control in your program. 

> 
> Thanks a lot.
> 
> (6) any good readable references that explain it lucidly ?

Lisp in Small Pieces for implementation details,  the Scheme Programming
Language for examples.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The fundamental concept of continuations

2007-10-08 Thread Bakul Shah
[EMAIL PROTECTED] wrote:
 > Again I am depressed to encounter a fundamentally new concept that I
 > was all along unheard of.

The concept is 37 years old.  Wadsworth in his "Continuation
Revisited" paper says he & Strachey were struggling with
extending the technique of denotational semantics to describe
jumps and not finding a satisfactory answer.  Then, in his
words:

   in October 1970 Strachey showed me a paper "Proving
   algorithms by tail functions" by Mazurkiewicz [2] which he
   had obtained from an IFIP WG2.2 meeting. Just the phrase
   "tail functions" in the title was enough -- given the
   experience of our earlier struggles -- for the ideas to
   click into place! The (meaning of the) "rest of the program"
   was needed as an argument to the semantic functions -- just
   so those constructs that did not use it, like jumps, could
   throw it anyway. The term "continuation" was coined as
   capturing the essence of this extra argument (though I
   often wished to have a shorter word!) and the rest, as they
   say, is history.

 > Its not even in paul graham's book where i
 > learnt part of Lisp. Its in Marc Feeley's video.
 >
 > Can anyone explain:
 >
 > (1) its origin
 > (2) its syntax and semantics in emacs lisp, common lisp, scheme
 > (3) Is it present in python and java ?
 > (4) Its implementation in assembly. for example in the manner that
 > pointer fundamentally arises from indirect addressing and nothing new.
 > So how do you juggle PC to do it.
 > (5) how does it compare to and superior to a function or subroutine
 > call. how does it differ.
 >
 > Thanks a lot.
 >
 > (6) any good readable references that explain it lucidly ?

You might like this one:

http://www.intertwingly.net/blog/2005/04/13/Continuations-for-Curmudgeons
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: property question

2007-10-08 Thread George Sakkis
On Oct 9, 1:20 am, "Manu Hack" <[EMAIL PROTECTED]> wrote:
> hi all,
>
> If I have a class A with A.x, A.y, A.z.  A.y and A.z are property and
> in order to compute the value of them, A.y depends on A.x while A.z
> depends on A.y and A.x.  If I call A.y, and A.z, the value A.y would
> be computed twice.  Is there a smart way to avoid that as to A.y will
> be recomputed only if A.x has been changed?  Now I can define more
> variables to keep track of what is changed but when there are more
> variables and the dependency becomes more involved it could be very
> complicated.  Thanks a lot.
>
> Manu

I haven't needed to use it myself so far, but PyCells (http://
pycells.pdxcb.net/) seems it might fit the bill.

George

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


Re: pytz has so many timezones!

2007-10-08 Thread Sanjay
> It's not clear at all from the OPs post exactly what functionality he
> is trying to derive from the timezone. Since timezones (obviously)
> contain more information than just the GMT offset (otherwise we
> wouldn't even have them), he may very well want to use the timezone
> given by the user to display correct local time to them. In this case,
> the actual, correct, political timezone is important, not just the GMT
> offset.

I am developing a website which would be accessed by members all over
the world. They can exchange data having some time fields, say
'schedule for next meeting'. Whenever somebody feeds some time field,
my application converts it to UTC and stores in the database. Later,
when the data is to be displayed to some member, the application
converts it to his local time, and displays the data.

thanks
Sanjay

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


Re: The fundamental concept of continuations

2007-10-08 Thread Barb Knox
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:

> Again I am depressed to encounter a fundamentally new concept that I
> was all along unheard of.

Don't be depressed about that.  There are countless concepts out there 
they you haven't yet heard of.

> Its not even in paul graham's book where i
> learnt part of Lisp. Its in Marc Feeley's video.
> 
> Can anyone explain:
> 
> (1) its origin

Lambda calculus.  Instead of function A returning to its caller, the 
caller provides an additional argument (the "continuation") which is a 
function B to be called by A with A's result(s).  In pure "continuation 
style" coding, nothing ever "returns" a result.

It is easy to mechanically transform normal function-style lambda 
calculus into continuation-style, but the reverse is not so.

> (2) its syntax and semantics in emacs lisp, common lisp, scheme
> (3) Is it present in python and java ?

Java, sort of.  For example, the Run interface.
Python, I don't know.

> (4) Its implementation in assembly. for example in the manner that
> pointer fundamentally arises from indirect addressing and nothing new.
> So how do you juggle PC to do it.

You can have a "spaghetti stack", or keep continuation data-structures 
in the heap.

> (5) how does it compare to and superior to a function or subroutine
> call. how does it differ.

This sounds like homework.  What do you have so far?

> Thanks a lot.
> 
> (6) any good readable references that explain it lucidly ?

Google?

-- 
---
|  BBBb\ Barbara at LivingHistory stop co stop uk
|  B  B   aa rrr  b |
|  BBB   a  a   r bbb   |Quidquid latine dictum sit,
|  B  B  a  a   r b  b  |altum viditur.
|  BBBaa a  r bbb   |   
-
-- 
http://mail.python.org/mailman/listinfo/python-list


more information for making money

2007-10-08 Thread panguohua
www.space666.com



good!!!

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


ANN: M2Crypto 0.18.1

2007-10-08 Thread Heikki Toivonen
M2Crypto is the most complete Python wrapper for OpenSSL featuring RSA,
DSA, DH, HMACs, message digests, symmetric ciphers (including AES); SSL
functionality to implement clients and servers; HTTPS extensions to
Python's httplib, urllib, and xmlrpclib; unforgeable HMAC'ing
AuthCookies for web session management; FTP/TLS client and server;
S/MIME; ZServerSSL: A HTTPS server for Zope and ZSmime: An S/MIME
messenger for Zope.

http://chandlerproject.org/Projects/MeTooCrypto

Changelog:

- Redo build fix when OpenSSL configured without Elliptic Curves (EC),
see also INSTALL file. This affects at least Fedora Core systems.

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


property question

2007-10-08 Thread Manu Hack
hi all,

If I have a class A with A.x, A.y, A.z.  A.y and A.z are property and
in order to compute the value of them, A.y depends on A.x while A.z
depends on A.y and A.x.  If I call A.y, and A.z, the value A.y would
be computed twice.  Is there a smart way to avoid that as to A.y will
be recomputed only if A.x has been changed?  Now I can define more
variables to keep track of what is changed but when there are more
variables and the dependency becomes more involved it could be very
complicated.  Thanks a lot.

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


how to get rgbdata

2007-10-08 Thread sajanjoseph
Hi i am a newbie to python and PIL. can anyone tell me how to get
rgbdata from a jpeg image using PIL
as a double[] . is there an equiv method to java's
BufferedImage.getRGB(0,0,width,height,rgbdata,0,width) ?

if anyone can advise pls do
sj

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


The fundamental concept of continuations

2007-10-08 Thread gnuist006
Again I am depressed to encounter a fundamentally new concept that I
was all along unheard of. Its not even in paul graham's book where i
learnt part of Lisp. Its in Marc Feeley's video.

Can anyone explain:

(1) its origin
(2) its syntax and semantics in emacs lisp, common lisp, scheme
(3) Is it present in python and java ?
(4) Its implementation in assembly. for example in the manner that
pointer fundamentally arises from indirect addressing and nothing new.
So how do you juggle PC to do it.
(5) how does it compare to and superior to a function or subroutine
call. how does it differ.

Thanks a lot.

(6) any good readable references that explain it lucidly ?

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


Query

2007-10-08 Thread ritu sharma
Hi ,

I am using linked server to fetch data from Oracle database.

Now ,I have to use  FPN_STATUS='A'  in the query. Kindly tell me if there is
an escape sequence for  ' .

FROM OPENQUERY(FPDWH,
 'SELECT
  WGFP_OWN.GRS_FILE_PLAN_VERSION.FVN_STATUS FPN_STAT_CODE,
   WGFP_OWN.GRS_FILE_PLAN_STATUS.FPS_NAME FPN_STAT_NAME,
   WGFP_OWN.GRS_FILE_PLAN_VERSION.FVN_STAT_UPD_BY FPN_STAT_UPD_BY,

 FROM
   WGFP_OWN.GRS_FILE_PLAN_VERSION,
   WGFP_OWN.GRS_FILE_PLAN,
   WGFP_OWN.GRS_FILE_PLAN_STATUS,
   WGFP_OWN.GRS_SECTOR,
  (SELECT A.FVN_FPN_ID AS FPN_NO, A.FVN_ID AS FVN_ID
FROM WGFP_OWN.GRS_FILE_PLAN_VERSION A, WGFP_OWN.GRS_FILE_PLAN B
  WHERE B.FPN_ID = A.FVN_FPN_ID
  AND A.FVN_VERSION=1
  AND (A.FVN_FPN_ID) NOT IN
 (SELECT C.FVN_FPN_ID AS FPN_NO_A
   FROM WGFP_OWN.GRS_FILE_PLAN_VERSION C, WGFP_OWN.GRS_FILE_PLAN D
   WHERE D.FPN_ID = C.FVN_FPN_ID
   AND C.FVN_STATUS ='A')
   UNION
   SELECT A.FVN_FPN_ID AS FPN_NO, A.FVN_ID AS FVN_ID
FROM WGFP_OWN.GRS_FILE_PLAN_VERSION A, WGFP_OWN.GRS_FILE_PLAN B
 WHERE B.FPN_ID = A.FVN_FPN_ID
 AND *A.FVN_STATUS ='A' --- Any alternative for ' character
*--GROUP BY A.FVN_FPN_ID
) FVN_MAX

Now ,I have to use  FPN_STATUS='A'  in the query. Kindly tell me if there is
an escape sequence for  ' .

Hoping for an early reply.


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

Re: pytz has so many timezones!

2007-10-08 Thread [EMAIL PROTECTED]
On Oct 8, 8:27?pm, "Nicholas Bastin" <[EMAIL PROTECTED]> wrote:
> On 10/8/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > > What do you mean by "the military" and why do you think they're
> > > authoritative on the topic of timezones?
>
> > Because they publish maps?
>
> I'm not sure what this has to do with it.

Maybe you've never had to navigate?

>
> > > but as far as I know they don't define timezones.
>
> > Ok, maybe they don't define them. But they get them from somewhere
> > and the zones are labeled A-Z (don't ask which letter isn't used).
> > Zone Z is equivalent to GMT and the time is refered to as Zulu time.
>
> They get them from NATO.  NGO's outside of NATO do not use NATO time
> zones for describing time data, mostly because NATO doesn't care about
> daylight savings time.  Works fine for the military, but not so well
> for your civilian users.
>
> > That's 25 zones, not 400. Under that system there are no half-hour
> > offset zones, no zones based on sunset and no lunatic GMT+13 zones.
>
> Yes, but lucky for us, we live in the real world, so we have to deal
> with 400 time zones.  The reality is that people LIVE in those
> 'lunatic' time zones, and software needs to address that.

WHY must we accomodate the ignorant? Why not cut them off
from the Internet until they get their act together? Don't
people get mad at Microsoft for breaking standards? People like
you are to blame for accomodating broken standards. "Oh, no,
we can't afford to lose those three potential customers who
live on an island in Kiribati!"

>
> If I schedule a meeting with someone in Indiana, and I'm in Ohio,
> they're in the same military time zone, but they don't observe
> daylight savings time, so in fact our times are different.  Users
> probably want our applications to handle these problems.

Isn't that what they call a "locale"?

>
> > > Since timezones (obviously)
> > > contain more information than just the GMT offset
>
> > Of course. But the GMT offset could be used to filter his list
> > of 400 choices, couldn't it?
>
> Sortof.  First, your user has to understand what GMT is,

And you start that education by learning the 25 timezones.
Then when you understand that, you can then learn about locales.

> so that's
> already going to cause problems.   Secondly, you need to handle time
> zones which drift from different GMT offsets depending on the time of
> year.  

It helps to know what you're drifting from.

> At the very least your algorithm needs to be greedy.

How good an algorithm do you think the OP will come up
with if he doesn't understand why his list has 400 items
or has any clue how to reduce it?

>
> > Agreed. But if someone gave me a list of 400 choices, I would look
> > for some way to reduce the list to a manageable choice. Isn't that
> > what the OP wants?
>
> > Why not teach him the truth, starting from the top level? Shouldn't
> > you teach him to fish rather than just give him one?
>
> Because the truth is that there are upwards of 400 different time
> zones,

Locales.

> accounting for local custom and law.  The military can
> conveniently ignore that, but we as application writers cannot.

But you can safely ignore the basis of the 400 locales?

>
> There is no central authority which defines global time zones.  The
> functional definition of a time zone is merely a geographical area of
> the earth that has adopted the same local time rules.

So, you can live your life with functional definations,
never bothering to learn any theory? Is code monkey all you
aspire to?

>
> --
> Nick


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


Re: why did MIT drop scheme for python in intro to computing?

2007-10-08 Thread gnuist006
On Oct 8, 9:04 pm, Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2007-10-09, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > Does scheme have a gui library?
>
> Yes.  It had a far, far better Tk binding than Python.
>
>  http://kaolin.unice.fr/STk/
>
> I've used both for real-world applications, and STk was _miles_
> ahead of tkinter.  It was a real, native binding to the Tk
> library rather than something stuck together with TCL.  GUI
> widgets were real Scheme objects that acted the way one
> expected them to, rather than wrapped TCL objects.
>
> However, Tk has been largely abandoned in favor of a native
> GTK+ binding
>
>  http://www.stklos.org/
>
> --
> Grant Edwards   grante Yow!  You should all JUMP
>   at   UP AND DOWN for TWO HOURS
>visi.comwhile I decide on a NEW
>CAREER!!

Comparing apples with apples, how do you compare the scheme
gui library with wxpython ? Isnt it better than Tkinter ?

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


Re: why did MIT drop scheme for python in intro to computing?

2007-10-08 Thread Grant Edwards
On 2007-10-09, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> Does scheme have a gui library?

Yes.  It had a far, far better Tk binding than Python.

  http://kaolin.unice.fr/STk/

I've used both for real-world applications, and STk was _miles_
ahead of tkinter.  It was a real, native binding to the Tk
library rather than something stuck together with TCL.  GUI
widgets were real Scheme objects that acted the way one
expected them to, rather than wrapped TCL objects.

However, Tk has been largely abandoned in favor of a native
GTK+ binding

  http://www.stklos.org/

-- 
Grant Edwards   grante Yow!  You should all JUMP
  at   UP AND DOWN for TWO HOURS
   visi.comwhile I decide on a NEW
   CAREER!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-10-08 Thread Wade Ward



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

> This thread of conversation also popped into my head when I was waiting in 
> line at the Starbucks in the building in which I work.  I've been ordering 
> a lot of Americanos lately.  I always ask for a small Americano and the 
> person taking my order always calls out my drink as a "tall". With respect 
> to Starbucks, calling a beverage which comes in the shortest cup used in 
> the store a "tall" has a perfectly well defined meaning.  But that doesn't 
> make it any less ridiculous.  Of course, it was mentioned elsewhere in 
> this thread that context is important.  And it is.  To use the Starbucks 
> analogy, for someone to criticize Starbucks because their tall drinks 
> really are actually quite short would be ignoring the significance of the 
> context of Starbucks' abuse of the English language.  But, again, that 
> doesn't make Starbuck's use of the word any less ridiculous.  However, at 
> least at Starbucks, when I use the "wrong" word, they don't start 
> lecturing me.  They know what I mean and simply go ahead and translate it 
> to Starbucks newspeak.

I, as a tall Americano, have always taken ordering the smallest espresso 
beverage possible as something describing the preference of the orderer, as 
opposed to the beverage itself.

-- 
wade ward
"Your boyfriend is not my boyfriend, doll."


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


Re: Memory leak/gc.get_objects()/Improved gc in version 2.5

2007-10-08 Thread Terry Reedy

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

Questions like this about memory consumption should start with the 
information printed by the interactive interpreter on startup and 
additional info about whether the binary is from stock CPython or has 3rd 
party modules compiled in.  The latter are typically the source of real 
problems. 



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


Re: why did MIT drop scheme for python in intro to computing?

2007-10-08 Thread gnuist006
On Oct 8, 1:23 pm, [EMAIL PROTECTED] (Brian Harvey) wrote:
> "Kjetil S. Matheussen" <[EMAIL PROTECTED]> writes:
>
> >I don't think your speculations makes very much sence.
>
> Amen.
>
> And, in any case, there's no need to speculate.  MIT has published, on their
> web site, pages and pages of rationale for the new curriculum.
>
> The most important point, imho, is that the programming language was the
> /least/ important aspect of the decision.  The most important aspect was
> the move to an application-based (rather than topic-based) organization
> of the curriculum.  The details flow out of that big shift of focus.

Where is the logic ?

python = application based ?
scheme = topic based ?

Does python have continuations ?

Is python progress or regress to the fortran style of natural
language ?

Dont they both have a great IDE in eclipse with respective plugins?

Does scheme have a gui library?

I really dont follow the logic.

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


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-10-08 Thread Damien Kick
Wildemar Wildenburger wrote:
> Frank Goenninger wrote:
>> On 2007-09-29 01:27:04 +0200, Damien Kick <[EMAIL PROTECTED]> said:
>>
>>> If you were referring to the "free" in "free Mumia Abu Jamal", I 
>>> would agree with you.  I don't think anyone would imagine that this 
>>> phrase meant that someone was going to get Mumia Abu Jamal gratis.  
>>> Like it or not, "free software" referring to "free as in beer" is 
>>> probably the most common interpretation of the phrase for a native 
>>> English speaker. [...]
>>
>> Fully true for non-native English speakers as well. Just did the "wife 
>> test" also - she is a pure software user - and yes, free is "no money, 
>> do what you want" and that's it.

I should have used the phrase "fluent English speaker"...

>> I *never* use the term "free" if I don't want to imply "free beer" 
>> (which is a Good Thing and as such highly valuated - ask any 
>> Bavarian). Using "free" as by FSF or any other lawyer-style 6 pixel 
>> font printed phrasing is pure perfidiousness.
>>
> I appearantly missed a lot of that conversation, but what is your point? 
> While I agree that the word "free" implies "free of monetary cost" to 
> many people societies, that is by no means set in stone [...].

For some odd reason, this reminded me of an old episode of Mork & Mindy:

http://www.salon.com/ent/movies/feature/1999/09/03/robin/";>
What made Mork think eggs could fly? And yet when he tried to release 
them from the tyranny of gravity ("Fly, be free!"), flinging them into 
the air only to have them land with a soft thwack, it seemed like 
nothing so much as a stroke of loopy brilliance.


The term "free eggs" can only sensibly mean one thing, eggs which can be 
obtained without an exchange of money.  To think of it meaning anything 
else--"fly, be free!"--is comedy (or not, depending on one's opinion of 
Mork & Mindy).  When Free Software Foundationistas try to insist on the 
phrase "free software" meaning anything other than the obvious 
interpretation of the term it is annoying (or not, depending on one's 
opinion of RMS's skills as a wordsmith).  I've got this great mental 
image of some farcical Free Software Liberation Army running around, 
removing hard drives from boxen, and throwing them in the air with the 
moral imperative to "fly, be free!"

> But that aside: The word free with respect to the FSF and GPL have a 
> perfectly well defined meaning. People may misunderstand that from not 
> knowing the definition but that doesnt make it any less well defined.

This thread of conversation also popped into my head when I was waiting 
in line at the Starbucks in the building in which I work.  I've been 
ordering a lot of Americanos lately.  I always ask for a small Americano 
and the person taking my order always calls out my drink as a "tall". 
With respect to Starbucks, calling a beverage which comes in the 
shortest cup used in the store a "tall" has a perfectly well defined 
meaning.  But that doesn't make it any less ridiculous.  Of course, it 
was mentioned elsewhere in this thread that context is important.  And 
it is.  To use the Starbucks analogy, for someone to criticize Starbucks 
because their tall drinks really are actually quite short would be 
ignoring the significance of the context of Starbucks' abuse of the 
English language.  But, again, that doesn't make Starbuck's use of the 
word any less ridiculous.  However, at least at Starbucks, when I use 
the "wrong" word, they don't start lecturing me.  They know what I mean 
and simply go ahead and translate it to Starbucks newspeak.

> Again, why this discussion?

Hello, Pot?  This is the kettle.  You are so black.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Adding extra modules to a Pyinstaller build

2007-10-08 Thread GaryLee
> I need to add several Python standard modules to a Pyinstaller
> project. The modules are not (and cannot be) explicitly imported in my
> project script, so is there a way to add them to my .spec file in
> order to allow Pyinstaller to search for them in PYTHONPATH and add
> them to the project?

Have you read the "Listing Hidden Imports" section in the PyInstaller
document?
Check this out.
http://pyinstaller.hpcf.upr.edu/docs/Manual_v1.1.html#listing-hidden-imports

Regards,
Gary

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


Re: pytz has so many timezones!

2007-10-08 Thread Nicholas Bastin
On 10/8/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > What do you mean by "the military" and why do you think they're
> > authoritative on the topic of timezones?
>
> Because they publish maps?

I'm not sure what this has to do with it.

> > but as far as I know they don't define timezones.
>
> Ok, maybe they don't define them. But they get them from somewhere
> and the zones are labeled A-Z (don't ask which letter isn't used).
> Zone Z is equivalent to GMT and the time is refered to as Zulu time.

They get them from NATO.  NGO's outside of NATO do not use NATO time
zones for describing time data, mostly because NATO doesn't care about
daylight savings time.  Works fine for the military, but not so well
for your civilian users.

> That's 25 zones, not 400. Under that system there are no half-hour
> offset zones, no zones based on sunset and no lunatic GMT+13 zones.

Yes, but lucky for us, we live in the real world, so we have to deal
with 400 time zones.  The reality is that people LIVE in those
'lunatic' time zones, and software needs to address that.

If I schedule a meeting with someone in Indiana, and I'm in Ohio,
they're in the same military time zone, but they don't observe
daylight savings time, so in fact our times are different.  Users
probably want our applications to handle these problems.

> > Since timezones (obviously)
> > contain more information than just the GMT offset
>
> Of course. But the GMT offset could be used to filter his list
> of 400 choices, couldn't it?

Sortof.  First, your user has to understand what GMT is, so that's
already going to cause problems.   Secondly, you need to handle time
zones which drift from different GMT offsets depending on the time of
year.  At the very least your algorithm needs to be greedy.

> Agreed. But if someone gave me a list of 400 choices, I would look
> for some way to reduce the list to a manageable choice. Isn't that
> what the OP wants?
>
> Why not teach him the truth, starting from the top level? Shouldn't
> you teach him to fish rather than just give him one?

Because the truth is that there are upwards of 400 different time
zones, accounting for local custom and law.  The military can
conveniently ignore that, but we as application writers cannot.

There is no central authority which defines global time zones.  The
functional definition of a time zone is merely a geographical area of
the earth that has adopted the same local time rules.

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


Re: weakrefs and bound methods

2007-10-08 Thread Bruno Desthuilliers
Mathias Panzenboeck a écrit :

About the lost weakref problem: in Python, methods are just tiny 
wrappers around the object, class and function created at lookup time 
(yes, on *each* lookup) (and WWAI, they are by the function object 
itself, which implements the descriptor protocol).

> When I change the class Wrapper to following, the class Foo works:
> 
> class Wrapper(object):
>   def __init__(self,x):
>   self.func_name = x.func_name
>   self.x = weakref.ref(x.im_self)

>   def __call__(self,*args,**kwargs):
>   x = self.x()
>   if x is None:
>   print "lost reference"
>   else:
>   return getattr(x,self.func_name)(*args,**kwargs)

Anyway, the whole thing looks quite baroque to me - and I'm known for my 
immoderate appetite for brain-melting features

If I understand correctly, you're doing all this to avoid circular 
references while keeping track of a list of methods to call ?

If yes, then you're thru much pain for nothing. Mostly because there are 
  other much more simpler solutions. The first one is obviously to use 
names and getattr. In it's most naïve implementation, this would look like:

class Foo(object):
 def __init__(self):
self._methods = set()
self._methods.add('_foo')

 def _foo(self):
print "_foo"

 def callMethods(self):
 for name in self._methods:
  meth = getattr(self, name, None)
  if callable(meth):
  meth()




Now if _methods is supposed to have the same content class-wise (which 
is the case in your exemple), no need to have it as an instance method:

class Foo(object):
 _methods = set('_foo')

 def _foo(self):
print "_foo"

 def callMethods(self):
 for name in self._methods:
  meth = getattr(self, name, None)
  if callable(meth):
  meth()

We could go further, like using a decorator to mark methods to add to 
_methods, and a metaclass to set the whole thing up, but this would 
probably be overkill. Unless there are other requirements, I'd 
personnaly stop here.

Oh, and yes, while we're at it : Python usually knows how to deal with 
circular references

> But that's ugly. 

Indeed.

> Any better idea?

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


Re: pytz has so many timezones!

2007-10-08 Thread [EMAIL PROTECTED]
On Oct 8, 3:27 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
> On 10/8/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > On Oct 8, 1:00 pm, "J. Clifford Dyer" <[EMAIL PROTECTED]> wrote:
> > > On Mon, Oct 08, 2007 at 10:41:03AM -0700, [EMAIL PROTECTED] wrote 
> > > regarding Re: pytz has so many timezones!:
>
> > > > On Oct 8, 2:32 am, Sanjay <[EMAIL PROTECTED]> wrote:
> > > > > Hi All,
>
> > > > > I am using pytz.common_timezones to populate the timezone combo box of
> > > > > some user registration form. But as it has so many timezones (around
> > > > > 400),
>
> > > > There are only 25 timezones: -12, -11, ... -1, 0 (GMT), +1, ... +11,
> > > > +12.
>
> > > > A handful of countries set their clocks offset by a half hour,
> > > > but those aren't timezones.
>
> > > I'm sorry.  By what even vaguely useful definition of "Timezone" is it 
> > > not a timezone if it's offset by half an hour?
>
> > The miltary doesn't recognize them as timezones. They'll make
> > a not that the local time observed doesn't match the timezone,
> > but they don't call it a seperate timezone.
>
> What do you mean by "the military" and why do you think they're
> authoritative on the topic of timezones?

Because they publish maps?

> The US timekeeping authority
> is a branch of the US Navy,

Isn't that "the military"?

> but as far as I know they don't define timezones.

Ok, maybe they don't define them. But they get them from somewhere
and the zones are labeled A-Z (don't ask which letter isn't used).
Zone Z is equivalent to GMT and the time is refered to as Zulu time.

That's 25 zones, not 400. Under that system there are no half-hour
offset zones, no zones based on sunset and no lunatic GMT+13 zones.

You'll never learn to run without first learning how to walk.

>
>
>
>
> > > > The 400 you're seeing are duplications based on locality. Of the 86
> > > > shown in Windows, all but 33 are dulplicate references to the same
> > > > timezones.
>
> > > > For example, Windows has seperate listings for
>
> > > > Central America
> > > > Central Time (US & Canada)
> > > > Guadalahara, Mexico City, Monterry - New
> > > > Guadalahara, Mexico City, Monterry - Old
> > > > Saskatchewan
>
> > > > but they are all GMT-6
>
> > > Those are non-duplicate (and perhaps inaccurate, I'm not sure).  US time 
> > > switches from standard to Daylight Savings earlier than Mexico, and 
> > > switches back later, as of this year.
>
> > Duplicate timezones doesn't mean duplicate time,
> > as you point out. Does the OP want to know the truth
> > or does he want to know something he can understand.
>
> > > Reducing them to a single time zone will result in aberrant functionality 
> > > in one or more locales.
>
> > I would hardly think that's an issue on the user registration
> > form the OP is trying to create.
>
> It's not clear at all from the OPs post exactly what functionality he
> is trying to derive from the timezone.

Yep, we can't read his mind.

> Since timezones (obviously)
> contain more information than just the GMT offset

Of course. But the GMT offset could be used to filter his list
of 400 choices, couldn't it?

> (otherwise we
> wouldn't even have them), he may very well want to use the timezone
> given by the user to display correct local time to them. In this case,
> the actual, correct, political timezone is important, not just the GMT
> offset.

Agreed. But if someone gave me a list of 400 choices, I would look
for some way to reduce the list to a manageable choice. Isn't that
what the OP wants?

Why not teach him the truth, starting from the top level? Shouldn't
you teach him to fish rather than just give him one?

>
> > > Cheers,
> > > Cliff
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list

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


Re: pytz has so many timezones!

2007-10-08 Thread [EMAIL PROTECTED]
On Oct 8, 3:23 pm, "J. Clifford Dyer" <[EMAIL PROTECTED]> wrote:
> On Mon, Oct 08, 2007 at 01:12:32PM -0700, [EMAIL PROTECTED] wrote regarding 
> Re: pytz has so many timezones!:
>
> >  [ I wrote ]
> > > Reducing them to a single time zone will result in aberrant functionality 
> > > in one or more locales.
>
> > I would hardly think that's an issue on the user registration
> > form the OP is trying to create.
>
> You don't think that it's an issue that the OPs users will complain about 
> their time being inaccurate?  If I register in what we in the US call Eastern 
> Time Zone, I don't want to have to switch to Atlantic time zone just because 
> the form designer couldn't be bothered to include a time zone that actually 
> matched the function of the clocks in my area.  

That wasn't my point. If you know you're in GMT-5 and your computer
knows you're in GMT-5, why do you have to peruse a list of 400
choices,
most of which don't match your GMT offset?

>
> Pedantry about the definition of a time zone is not going to win you points 
> with irate users.  

Fine. Then make the user scroll through 400 choices. See how many
points that gets you.

>
> Cliff


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


Memory leak/gc.get_objects()/Improved gc in version 2.5

2007-10-08 Thread crazy420fingers
I'm running a python program that simulates a wireless network
protocol for a certain number of "frames" (measure of time).  I've
observed the following:

1. The memory consumption of the program grows as the number of frames
I simulate increases.

To verify this, I've used two methods, which I invoke after every
frame simulated:

--  Parsing the /proc//status file as in:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286222
--  Using ps vg | grep python | awk '!/grep/ {print " ",$8}'  in an
os.system() call.

The memory usage vs. frame number graph shows some big "jumps" at
certain points, and, after a large number of frames, shows a steady
upward slope

2. I think I've verified that the objects I instantiate are actually
freed-- I'm therefore assuming that this "leak" is "caused" by
python's garbage collection mechanism. I count the number of objects I
generate that are being tracked by gc as follows:

gc.collect()
objCount = {}
objList = gc.get_objects()
for obj in objList:
if getattr(obj, "__class__", None):
name = obj.__class__.__name__
if objCount.has_key(name):
objCount[name] += 1
else:
objCount[name] = 1

for name in objCount:
print name, " :", objCount[name]

   del objList

Running this snippet every hundred frames or so, shows that the number
of objects managed by gc is not growing.

I upgraded to Python 2.5. in an attempt to solve this problem. The
only change in my observations from version 2.4 is that the absolute
memory usage level seems to have dropped. However, I still see the
jumps in memory usage at the same points in time.

Can anybody explain why the memory usage shows significant jumps (~200
kB or ~500 kb) over time (i.e. "frames") even though there is no
apparent increase in the objects managed by gc? Note that I'm calling
gc.collect() regularly.

Thanks for your attention,

Arvind

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


Re: pytz has so many timezones!

2007-10-08 Thread [EMAIL PROTECTED]
On Oct 8, 5:48 pm, "J. Cliff Dyer" <[EMAIL PROTECTED]> wrote:
> On 10/8/07, *J. Clifford Dyer* <[EMAIL PROTECTED]
>
> > wrote:
>
> On Mon, Oct 08, 2007 at 01:13:24PM -0700, [EMAIL PROTECTED]
>  wrote regarding Re: pytz has so many
> timezones!:
> >
> > On Oct 8, 1:03 pm, Carsten Haese < [EMAIL PROTECTED]
> > wrote:
> > > On Mon, 2007-10-08 at 10:41 -0700, [EMAIL PROTECTED]
>  wrote:
> > > > For example, Windows has seperate listings for
> > >
> > > > Central America
> > > > Central Time (US & Canada)
> > > > Guadalahara, Mexico City, Monterry - New
> > > > Guadalahara, Mexico City, Monterry - Old
> > > > Saskatchewan
> > >
> > > > but they are all GMT-6
> > >
> > > But they could have different rules for Daylight Saving Time.
> >
> > Which only matters if you're setting your clock.
> >
>
> Maybe this is where I'm not understanding you:  Do you have another
> use for setting a timezone?  The only thing a time zone does, as far
> as I can tell, is set clocks relative to a shared conception of time.
>
> --
>http://mail.python.org/mailman/listinfo/python-list
>
>
>
>
>
> > How about a calendar entry: I've got six people in places all over the
> > world to get on the phone together.  If the app doesn't know their
> > notion of a time zone, that will never happen.
>
> > How about financial transactions: time-stamping transactions that move
> > around the world seems pretty useful to me.  How do I know when said
> > transaction started if I can't convert the user's time into the
> > server's time?
>
> > Timezone is just another localization setting.  It is no different
> > than language or keyboard layout.  It is a piece of data that
> > describes the "world" the user lives in.  Unfortunately, DST makes
> > them very complex because DST is determined by the country and can
> > change from year to year.  I think the US' DST change this year had
> > more of a real-world impact than Y2K (of course, people actually
> > planned for Y2K, but that is a different story :).
>
> > tj
>
> OK.  Those all make sense, but I think they contradict mensanator's
> statement that DST and half-hour offsets "only matter[] if you're
> setting your clock."  None of those are meaningful with 25 generic time
> zones, which was what I was trying to understand.  Under what normal
> circumstances (outside of the US military creating an approximation for
> their own internal usage) could 25 tzs be a useful abstraction?

It's how the world goes around.

Some people can't see the forest for the trees.

Is it obvious from all this timezone crap that

 - a day lasts 48 hours?

 - it can never be the same day everywhere in the world
   simultaneously?

Isn't that just as important for worldwide transactions
as Daylight Savings Time (or lack thereof)?

Perhaps, once the basics

are understood, the details won't be so confusing.

>
> Cheers,
> Cliff

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


Re: Convert obejct string repr to actual object

2007-10-08 Thread Michael Spencer
Tor Erik Sønvisen wrote:
> Hi,
> 
> I've tried locating some code that can recreate an object from it's
> string representation...
> The object in question is really a dictionary containing other
> dictionaries, lists, unicode strings, floats, ints, None, and
> booleans.
> 
> I don't want to use eval, since I can't trust the source sending the
> object I'm sure someone must have had the same need and created
> code for it... Maybe Pypy has what I need??? Haven't looked though...
> 
> Regards,
> Tor Erik
> 
> PS: The string repr is created by a server outside of my control...

This recipe should get you most of what you need:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469

HTH

Michael

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


Re: pytz has so many timezones!

2007-10-08 Thread J. Cliff Dyer
On 10/8/07, *J. Clifford Dyer* <[EMAIL PROTECTED]
> wrote:

On Mon, Oct 08, 2007 at 01:13:24PM -0700, [EMAIL PROTECTED]
 wrote regarding Re: pytz has so many
timezones!:
>
> On Oct 8, 1:03 pm, Carsten Haese < [EMAIL PROTECTED]
> wrote:
> > On Mon, 2007-10-08 at 10:41 -0700, [EMAIL PROTECTED]
 wrote:
> > > For example, Windows has seperate listings for
> >
> > > Central America
> > > Central Time (US & Canada)
> > > Guadalahara, Mexico City, Monterry - New
> > > Guadalahara, Mexico City, Monterry - Old
> > > Saskatchewan
> >
> > > but they are all GMT-6
> >
> > But they could have different rules for Daylight Saving Time.
>
> Which only matters if you're setting your clock.
>

Maybe this is where I'm not understanding you:  Do you have another
use for setting a timezone?  The only thing a time zone does, as far
as I can tell, is set clocks relative to a shared conception of time.


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





> How about a calendar entry: I've got six people in places all over the
> world to get on the phone together.  If the app doesn't know their
> notion of a time zone, that will never happen.
>
> How about financial transactions: time-stamping transactions that move
> around the world seems pretty useful to me.  How do I know when said
> transaction started if I can't convert the user's time into the
> server's time?
>
> Timezone is just another localization setting.  It is no different
> than language or keyboard layout.  It is a piece of data that
> describes the "world" the user lives in.  Unfortunately, DST makes
> them very complex because DST is determined by the country and can
> change from year to year.  I think the US' DST change this year had
> more of a real-world impact than Y2K (of course, people actually
> planned for Y2K, but that is a different story :).
>
> tj
>


OK.  Those all make sense, but I think they contradict mensanator's
statement that DST and half-hour offsets "only matter[] if you're
setting your clock."  None of those are meaningful with 25 generic time
zones, which was what I was trying to understand.  Under what normal
circumstances (outside of the US military creating an approximation for
their own internal usage) could 25 tzs be a useful abstraction?

Cheers,
Cliff

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


Re: Python + Shoutpy + Twisted Locks

2007-10-08 Thread John Nagle
Chris Mellon wrote:
> On 10/7/07, Michel Albert <[EMAIL PROTECTED]> wrote:
>> On Oct 6, 4:21 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
>>> En Fri, 05 Oct 2007 04:55:55 -0300, exhuma.twn <[EMAIL PROTECTED]> escribi?:
>>>
 [...] What I found
 is that "libshout" is blocking, which should be fine as the whole
 thing runs in it's separate thread. But the application hangs
 nevertheless while streaming. This effectively blocks out the other
 thread that checks the player status, which then fails to append new
 songs to the queue. So only one song is played when streaming.
 The other threads in my application run fine and don't block the rest
 of the app. So I guess, that the main problem is that blocking occurs
 "outside" the python world and "inside" the libshout world.
>>> Only one thread at a time may be executing Python code; the Global
>>> Interpreter Lock (GIL) ensures the mutual exclusion. Extension modules
>>> (written in C) may use the macros
>>> Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS to release/acquire the GIL
>>> before/after an external blocking call.
>>> I don't know libshout, or how you are doing the binding python-libshout,
>>> but if your analysis is correct it means that the code is not releasing
>>> the GIL at the appropiate points.
>>>
>>> --
>>> Gabriel Genellina
>> Hmmm... ok. I suppose rewriting the whole thing using twisted's
>> deferreds could then solve the problem. Which are basically nothing
>> more than callbacks with a weird name ;) Unfortunately this means that
>> I have to re-think a lot. But in the end I suppose it will pay off.
>>
>> Thanks for taking the time and reading my little essay Gabriel ;)
>>
> 
> Using Twisted won't help if the libshout calls are really blocking the
> main thread.

 Right.

 The whole point of Twisted is that you can't do anything that takes
very long in a Twisted thread, or the whole server will stall.  If you
try to do something ongoing, like streaming, in a Twisted server, you
have to have long-running threads of your own and a scheduling system
to coordinate them with the Twisted threads.

 libshout's "nonblocking" mode isn't very nonblocking.  See

https://trac.xiph.org/browser/icecast/trunk/libshout/examples/nonblocking.c

There's a thread in a loop during playout.  All "nonblocking" seems to do is
defer the waiting from shout_write() to shout_sync().

 It looks like you'll need a separate thread for each stream being played
out, on top of the Twisted machinery.  Or a completely event-driven version
of "libshout" designed for Twisted.

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


Re: Convert obejct string repr to actual object

2007-10-08 Thread Steven D'Aprano
On Mon, 08 Oct 2007 21:19:50 +0200, Tor Erik Sønvisen
wrote:

> I don't want to use eval, since I can't trust the source sending the
> object I'm sure someone must have had the same need and created code
> for it... Maybe Pypy has what I need??? Haven't looked though...


For the benefit of those who think they can make eval "safe", start here:

http://effbot.org/zone/librarybook-core-eval.htm


Here's a good solution:

http://effbot.org/zone/simple-iterator-parser.htm



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

Re: Variable scoping rules in Python?

2007-10-08 Thread MRAB
On Oct 8, 4:06 pm, Bruno Desthuilliers  wrote:
> [EMAIL PROTECTED] a écrit :
>
> > Ok, I'm relatively new to Python (coming from C, C++ and Java).  I'm
> > working on a program that outputs text that may be arbitrarily long,
> > but should still line up, so I want to split the output on a specific
> > column boundary.
>
> FWIW :http://docs.python.org/lib/module-textwrap.html
>
>
>
>
>
> >  Since I might want to change the length of a column,
> > I tried defining the column as a constant (what I would have made a
> > "#define" in C, or a "static final" in Java).  I defined this at the
> > top level (not within a def), and I reference it inside a function.
> > Like this:
>
> > COLUMNS = 80
>
> > def doSomethindAndOutputIt( ):
> >   ...
> >   for i in range( 0, ( len( output[0] ) / COLUMNS ) ):
> > print output[0][ i * COLUMNS : i * COLUMNS + ( COLUMNS - 1 ) ]
> > print output[1][ i * COLUMNS : i * COLUMNS + ( COLUMNS - 1 ) ]
> > ..
>
> > etc. etc.  It works fine, and splits the output on the 80-column
> > boundary just like I want.
>
> > Well, I decided that I wanted "COLUMNS = 0" to be a special "don't
> > split anywhere" value, so I changed it to look like this:
>
> > COLUMNS = 80
>
> > def doSomethindAndOutputIt( ):
> >   ...
> >   if COLUMNS == 0:
> > COLUMNS = len( output[ 0 ] )
>
> >   for i in range( 0, ( len( output[0] ) / COLUMNS ) ):
> > print output[0][ i * COLUMNS : i * COLUMNS + ( COLUMNS - 1 ) ]
> > print output[1][ i * COLUMNS : i * COLUMNS + ( COLUMNS - 1 ) ]
> > ..
>
> Since you don't want to modify a global (and even worse, a CONSTANT),
> the following code may be a bit cleaner:
>
> def doSomethindAndOutputIt( ):
>...
>if COLUMNS == 0:
>   columns = len( output[ 0 ] )
>else:
>   columns = COLUMNS
>for i in range( 0, ( len( output[0] ) / COLUMNS ) ):
>   print output[0][ i * columns : i * columns + ( columns - 1 ) ]
>..
>
[snip]
range() can accept 3 arguments (start, stop and step) so you could
write:

for i in range( 0, len( output[0] ), columns ):
   print output[0][ i : i + columns ]
..

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

Re: pytz has so many timezones!

2007-10-08 Thread Travis Jensen
How about a calendar entry: I've got six people in places all over the world
to get on the phone together.  If the app doesn't know their notion of a
time zone, that will never happen.

How about financial transactions: time-stamping transactions that move
around the world seems pretty useful to me.  How do I know when said
transaction started if I can't convert the user's time into the server's
time?

Timezone is just another localization setting.  It is no different than
language or keyboard layout.  It is a piece of data that describes the
"world" the user lives in.  Unfortunately, DST makes them very complex
because DST is determined by the country and can change from year to year.
I think the US' DST change this year had more of a real-world impact than
Y2K (of course, people actually planned for Y2K, but that is a different
story :).

tj

On 10/8/07, J. Clifford Dyer <[EMAIL PROTECTED]> wrote:
>
> On Mon, Oct 08, 2007 at 01:13:24PM -0700, [EMAIL PROTECTED] wrote
> regarding Re: pytz has so many timezones!:
> >
> > On Oct 8, 1:03 pm, Carsten Haese <[EMAIL PROTECTED]> wrote:
> > > On Mon, 2007-10-08 at 10:41 -0700, [EMAIL PROTECTED] wrote:
> > > > For example, Windows has seperate listings for
> > >
> > > > Central America
> > > > Central Time (US & Canada)
> > > > Guadalahara, Mexico City, Monterry - New
> > > > Guadalahara, Mexico City, Monterry - Old
> > > > Saskatchewan
> > >
> > > > but they are all GMT-6
> > >
> > > But they could have different rules for Daylight Saving Time.
> >
> > Which only matters if you're setting your clock.
> >
>
> Maybe this is where I'm not understanding you:  Do you have another use
> for setting a timezone?  The only thing a time zone does, as far as I can
> tell, is set clocks relative to a shared conception of time.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Travis Jensen
[EMAIL PROTECTED]
http://cmssphere.blogspot.com/
Software Maven * Philosopher-in-Training * Avenged Nerd
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: round-trip from egg to code and back to egg

2007-10-08 Thread John Nagle
Bruno Desthuilliers wrote:
> Catherine a écrit :
>> Three possibilities come to mind -
>>
>> 1. I'm missing something simple
> 
> Probably. I'd say, something like unzip .egg !-)

That's generally the solution to "egg" files.  They usually
do the wrong thing, and the "egg" system is still in beta.
They're really .zip files, so just unzip them and ignore the
"egg" crap.

My experience is that every .egg file adds about a half
hour of headaches to an install, since you have to figure
out why it didn't work, or why Python is still using the
old version, or something.

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


Re: pytz has so many timezones!

2007-10-08 Thread Joe Holloway
On 10/8/07, Sanjay <[EMAIL PROTECTED]> wrote:
> 2. Mapping the timezones to countries is a nice idea. Any idea how to
> go about it - I mean whether I have to collect the data manually and
> do it, or some better way is available - will help me a lot.

You might find some good information by brushing up on the Olson time
zone database:

http://en.wikipedia.org/wiki/Zoneinfo
http://www.twinsun.com/tz/tz-link.htm
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert obejct string repr to actual object

2007-10-08 Thread Diez B. Roggisch
Tor Erik Sønvisen schrieb:
> Hi,
> 
> I've tried locating some code that can recreate an object from it's
> string representation...
> The object in question is really a dictionary containing other
> dictionaries, lists, unicode strings, floats, ints, None, and
> booleans.
> 
> I don't want to use eval, since I can't trust the source sending the
> object I'm sure someone must have had the same need and created
> code for it... Maybe Pypy has what I need??? Haven't looked though...


Try using simplejson.

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


Re: Python + Shoutpy + Twisted Locks

2007-10-08 Thread Chris Mellon
On 10/7/07, Michel Albert <[EMAIL PROTECTED]> wrote:
> On Oct 6, 4:21 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> > En Fri, 05 Oct 2007 04:55:55 -0300, exhuma.twn <[EMAIL PROTECTED]> escribi?:
> >
> > > [...] What I found
> > > is that "libshout" is blocking, which should be fine as the whole
> > > thing runs in it's separate thread. But the application hangs
> > > nevertheless while streaming. This effectively blocks out the other
> > > thread that checks the player status, which then fails to append new
> > > songs to the queue. So only one song is played when streaming.
> >
> > > The other threads in my application run fine and don't block the rest
> > > of the app. So I guess, that the main problem is that blocking occurs
> > > "outside" the python world and "inside" the libshout world.
> >
> > Only one thread at a time may be executing Python code; the Global
> > Interpreter Lock (GIL) ensures the mutual exclusion. Extension modules
> > (written in C) may use the macros
> > Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS to release/acquire the GIL
> > before/after an external blocking call.
> > I don't know libshout, or how you are doing the binding python-libshout,
> > but if your analysis is correct it means that the code is not releasing
> > the GIL at the appropiate points.
> >
> > --
> > Gabriel Genellina
>
> Hmmm... ok. I suppose rewriting the whole thing using twisted's
> deferreds could then solve the problem. Which are basically nothing
> more than callbacks with a weird name ;) Unfortunately this means that
> I have to re-think a lot. But in the end I suppose it will pay off.
>
> Thanks for taking the time and reading my little essay Gabriel ;)
>


Using Twisted won't help if the libshout calls are really blocking the
main thread. You need to fix the libshout wrapper to release the GIL
when it makes blocking C calls.

I also believe that Twisted has a native (perhaps only
semi-functional?) shoutcast protocol implementation, so a pure-python
implementation might be possible as well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: csv module and Unicode

2007-10-08 Thread Robert Dailey
Wow; I guess this is a REAL problem! I would have thought that something as
common as Unicode CSV would have been supported by SOMEONE.

On 10/5/07, Robert Dailey <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> According to the Python 2.5 documentation, Unicode is not supported
> through the CSV module. Is there some third-party CSV module I can use that
> has Unicode support? Thanks.
>
-- 
http://mail.python.org/mailman/listinfo/python-list

ANN: NUCULAR fielded text searchable indexing

2007-10-08 Thread aaron . watters
ANNOUNCE:
  NUCULAR fielded text searchable indexing

Nucular is a system for creating disk based full text indices
for fielded data. It can be accessed via a Python API
or via a suite of command line interfaces.

Nucular is intended to help store and retrieve
searchable information in a manner somewhat similar
to the way that "www.hotjobs.com" stores and
retrieves job descriptions, for example.

Nucular archives fielded documents and retrieves them
based on field value, field prefix, field word prefix,
or full text word prefix, or combinations of these.

Features:

 -- Nucular is very light weight. Updates and accesses
do not require any server process or other system
support such as shared memory locking.

 -- Nucular supports concurrency. Arbitrary concurrent
updates and accesses by multiple processes or threads
are supported, with no possible locking issues.

 -- Nucular indexes and retrieves large collections quickly.

Read more and download at:
   http://nucular.sourceforge.net

Online demos:

http://www.xfeedme.com/nucular/gut.py/go
http://www.xfeedme.com/nucular/mondial.py/go

I hope you like!
   -- Aaron Watters

===
I don't know ka-RAH-tee
But I know ka-RAY-zee
   -- James Browne

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


Re: pytz has so many timezones!

2007-10-08 Thread Chris Mellon
On 10/8/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> On Oct 8, 1:00 pm, "J. Clifford Dyer" <[EMAIL PROTECTED]> wrote:
> > On Mon, Oct 08, 2007 at 10:41:03AM -0700, [EMAIL PROTECTED] wrote regarding 
> > Re: pytz has so many timezones!:
> >
> >
> >
> > > On Oct 8, 2:32 am, Sanjay <[EMAIL PROTECTED]> wrote:
> > > > Hi All,
> >
> > > > I am using pytz.common_timezones to populate the timezone combo box of
> > > > some user registration form. But as it has so many timezones (around
> > > > 400),
> >
> > > There are only 25 timezones: -12, -11, ... -1, 0 (GMT), +1, ... +11,
> > > +12.
> >
> > > A handful of countries set their clocks offset by a half hour,
> > > but those aren't timezones.
> >
> > I'm sorry.  By what even vaguely useful definition of "Timezone" is it not 
> > a timezone if it's offset by half an hour?
>
> The miltary doesn't recognize them as timezones. They'll make
> a not that the local time observed doesn't match the timezone,
> but they don't call it a seperate timezone.
>

What do you mean by "the military" and why do you think they're
authoritative on the topic of timezones? The US timekeeping authority
is a branch of the US Navy, but as far as I know they don't define
timezones.

> >
> > > The 400 you're seeing are duplications based on locality. Of the 86
> > > shown in Windows, all but 33 are dulplicate references to the same
> > > timezones.
> >
> > > For example, Windows has seperate listings for
> >
> > > Central America
> > > Central Time (US & Canada)
> > > Guadalahara, Mexico City, Monterry - New
> > > Guadalahara, Mexico City, Monterry - Old
> > > Saskatchewan
> >
> > > but they are all GMT-6
> >
> > Those are non-duplicate (and perhaps inaccurate, I'm not sure).  US time 
> > switches from standard to Daylight Savings earlier than Mexico, and 
> > switches back later, as of this year.
>
> Duplicate timezones doesn't mean duplicate time,
> as you point out. Does the OP want to know the truth
> or does he want to know something he can understand.
>
> > Reducing them to a single time zone will result in aberrant functionality 
> > in one or more locales.
>
> I would hardly think that's an issue on the user registration
> form the OP is trying to create.
>

It's not clear at all from the OPs post exactly what functionality he
is trying to derive from the timezone. Since timezones (obviously)
contain more information than just the GMT offset (otherwise we
wouldn't even have them), he may very well want to use the timezone
given by the user to display correct local time to them. In this case,
the actual, correct, political timezone is important, not just the GMT
offset.

> >
> > Cheers,
> > Cliff
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pytz has so many timezones!

2007-10-08 Thread J. Clifford Dyer
On Mon, Oct 08, 2007 at 01:13:24PM -0700, [EMAIL PROTECTED] wrote regarding Re: 
pytz has so many timezones!:
> 
> On Oct 8, 1:03 pm, Carsten Haese <[EMAIL PROTECTED]> wrote:
> > On Mon, 2007-10-08 at 10:41 -0700, [EMAIL PROTECTED] wrote:
> > > For example, Windows has seperate listings for
> >
> > > Central America
> > > Central Time (US & Canada)
> > > Guadalahara, Mexico City, Monterry - New
> > > Guadalahara, Mexico City, Monterry - Old
> > > Saskatchewan
> >
> > > but they are all GMT-6
> >
> > But they could have different rules for Daylight Saving Time.
> 
> Which only matters if you're setting your clock.
> 

Maybe this is where I'm not understanding you:  Do you have another use for 
setting a timezone?  The only thing a time zone does, as far as I can tell, is 
set clocks relative to a shared conception of time.


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


Re: pytz has so many timezones!

2007-10-08 Thread J. Clifford Dyer
On Mon, Oct 08, 2007 at 01:12:32PM -0700, [EMAIL PROTECTED] wrote regarding Re: 
pytz has so many timezones!:
>  [ I wrote ]
> > Reducing them to a single time zone will result in aberrant functionality 
> > in one or more locales.
> 
> I would hardly think that's an issue on the user registration
> form the OP is trying to create.
> 

You don't think that it's an issue that the OPs users will complain about their 
time being inaccurate?  If I register in what we in the US call Eastern Time 
Zone, I don't want to have to switch to Atlantic time zone just because the 
form designer couldn't be bothered to include a time zone that actually matched 
the function of the clocks in my area.  

Pedantry about the definition of a time zone is not going to win you points 
with irate users.  

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


Re: pytz has so many timezones!

2007-10-08 Thread [EMAIL PROTECTED]
On Oct 8, 1:03 pm, Carsten Haese <[EMAIL PROTECTED]> wrote:
> On Mon, 2007-10-08 at 10:41 -0700, [EMAIL PROTECTED] wrote:
> > For example, Windows has seperate listings for
>
> > Central America
> > Central Time (US & Canada)
> > Guadalahara, Mexico City, Monterry - New
> > Guadalahara, Mexico City, Monterry - Old
> > Saskatchewan
>
> > but they are all GMT-6
>
> But they could have different rules for Daylight Saving Time.

Which only matters if you're setting your clock.

>
> --
> Carsten Haesehttp://informixdb.sourceforge.net


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


Re: pytz has so many timezones!

2007-10-08 Thread [EMAIL PROTECTED]
On Oct 8, 1:00 pm, "J. Clifford Dyer" <[EMAIL PROTECTED]> wrote:
> On Mon, Oct 08, 2007 at 10:41:03AM -0700, [EMAIL PROTECTED] wrote regarding 
> Re: pytz has so many timezones!:
>
>
>
> > On Oct 8, 2:32 am, Sanjay <[EMAIL PROTECTED]> wrote:
> > > Hi All,
>
> > > I am using pytz.common_timezones to populate the timezone combo box of
> > > some user registration form. But as it has so many timezones (around
> > > 400),
>
> > There are only 25 timezones: -12, -11, ... -1, 0 (GMT), +1, ... +11,
> > +12.
>
> > A handful of countries set their clocks offset by a half hour,
> > but those aren't timezones.
>
> I'm sorry.  By what even vaguely useful definition of "Timezone" is it not a 
> timezone if it's offset by half an hour?  

The miltary doesn't recognize them as timezones. They'll make
a not that the local time observed doesn't match the timezone,
but they don't call it a seperate timezone.

>
> > The 400 you're seeing are duplications based on locality. Of the 86
> > shown in Windows, all but 33 are dulplicate references to the same
> > timezones.
>
> > For example, Windows has seperate listings for
>
> > Central America
> > Central Time (US & Canada)
> > Guadalahara, Mexico City, Monterry - New
> > Guadalahara, Mexico City, Monterry - Old
> > Saskatchewan
>
> > but they are all GMT-6
>
> Those are non-duplicate (and perhaps inaccurate, I'm not sure).  US time 
> switches from standard to Daylight Savings earlier than Mexico, and switches 
> back later, as of this year.  

Duplicate timezones doesn't mean duplicate time,
as you point out. Does the OP want to know the truth
or does he want to know something he can understand.

> Reducing them to a single time zone will result in aberrant functionality in 
> one or more locales.

I would hardly think that's an issue on the user registration
form the OP is trying to create.

>
> Cheers,
> Cliff


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


Facebook app give feedback -Send birthday cards to buds http://apps.facebook.com/groupcards/start

2007-10-08 Thread fringo
Facebook app give feedback -Send birthday cards to buds
http://apps.facebook.com/groupcards/start

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


Re: Don't use __slots__

2007-10-08 Thread Hrvoje Niksic
Steven D'Aprano <[EMAIL PROTECTED]> writes:

> Well, I've read the thread, and I've read the thread it links to,
> and for the life of me I'm still no clearer as to why __slots__
> shouldn't be used except that:
[...]
> But is there actually anything *harmful* that can happen if I use
> __slots__?

Here is one harmful consequence: __slots__ breaks multiple
inheritance:

class A(object):
  __slots__ = ['a', 'b']

class B(object):
  __slots__ = ['c']

class AB(A, B):
  pass

Traceback (most recent call last):
  File "", line 1, in 
TypeError: Error when calling the metaclass bases
multiple bases have instance lay-out conflict

Even if A and B had the exact same slots, for example ['a', 'b'], it
wouldn't make a difference.  AB explicitly setting __slots__ to
something like ['a', 'b', 'c'] doesn't help either.  But that is only
a technical answer to your technical question which misses the real
problem people like Aahz and Guido have with __slots__.  (I don't
claim to represent them, of course, the following is my
interpretation.)

The backlash against __slots__ is a consequence of it being so easy to
misunderstand what __slots__ does and why it exists.  Seeing __slots__
has led some people to recommend __slots__ to beginners as a way to
"catch spelling mistakes", or as a way to turn Python's classes into
member-declared structures, a la Java.  For people coming from Java
background, catching mistakes as early as possible is almost a dogma,
and they are prone to accept the use of __slots__ (and living with the
shortcomings) as a rule.

Python power users scoff at that because it goes against everything
that makes Python Python.  Use of __slots__ greatly reduces class
flexibility, by both disabling __dict__ and __weakref__ by default,
and by forcing a tight instance layout that cripples inheritance.
With people using __slots__ for the majority of their classes, it
becomes much harder for 3rd-party code to attach an unforeseen
attribute to an existing object.  Even with single inheritance,
__slots__ has unintuitive semantics because subclasses automatically
get __dict__ and __weakref__, thereby easily breaking the "benefits"
of their use.

__slots__ is a low-level tool that allows creation of dict-less
objects without resorting to Python/C.  As long as one understands it
as such, there is no problem with using it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert obejct string repr to actual object

2007-10-08 Thread Chris Mellon
On 10/8/07, Tor Erik Sønvisen <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I've tried locating some code that can recreate an object from it's
> string representation...
> The object in question is really a dictionary containing other
> dictionaries, lists, unicode strings, floats, ints, None, and
> booleans.
>
> I don't want to use eval, since I can't trust the source sending the
> object I'm sure someone must have had the same need and created
> code for it... Maybe Pypy has what I need??? Haven't looked though...
>
> Regards,
> Tor Erik
>
> PS: The string repr is created by a server outside of my control...
> --


You'll need to write your own parser. PyParsing has an example that
can parse much of the Python syntax, you can probably extract the
object-literal parts of that and use it as a base for your
implementation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert obejct string repr to actual object

2007-10-08 Thread Carsten Haese
On Mon, 2007-10-08 at 21:19 +0200, Tor Erik Sønvisen wrote:
> Hi,
> 
> I've tried locating some code that can recreate an object from it's
> string representation...
> The object in question is really a dictionary containing other
> dictionaries, lists, unicode strings, floats, ints, None, and
> booleans.
> 
> I don't want to use eval, since I can't trust the source sending the
> object.

You could still use eval, but run a separate algorithm first to make
sure the string is "legal." For example, you could whip up a simple
PyParsing grammar to restrict the set of allowable strings, or compile
the string into byte code and inspect the byte code to look for red
flags like LOAD_NAME (with a name other than None) and CALL_FUNCTION.

HTH,

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


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


Convert obejct string repr to actual object

2007-10-08 Thread Tor Erik Sønvisen
Hi,

I've tried locating some code that can recreate an object from it's
string representation...
The object in question is really a dictionary containing other
dictionaries, lists, unicode strings, floats, ints, None, and
booleans.

I don't want to use eval, since I can't trust the source sending the
object I'm sure someone must have had the same need and created
code for it... Maybe Pypy has what I need??? Haven't looked though...

Regards,
Tor Erik

PS: The string repr is created by a server outside of my control...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: WARNING ABOUT ROGUE OPERATORS Re: The secret of hand compiling LISP/Scheme

2007-10-08 Thread thermate
If you sheeple are ignorant of what I say, look at this link:
and the papers therein.

911blogger.com
st911.org
stj911.org

(1) Why did FBI bastards not catch the ANTHRAX mailer?
(2) Why did building 7 commit suicide?
(3) Where is the Pentagon video, of the plane hitting it ?

On Oct 8, 11:30 am, [EMAIL PROTECTED] wrote:
> This William D Clinger is a YANK MOTHER F*CKER, a 911 controlled
> demolition operator group member or a ROGUE bastard in FBI whose
> job and RACIST tendency is to CONTROL FREEDOM of information.
> These MOTHERF*CKERS using fake accounts use "FULL LONG NAMES"
> to FOOL simple and honest people that they are some genuine
> people. They have multiple accounts and their sole job is to
> derail conversations on the threads where there is exchange of
> knowledge. That is their FULL TIME JOB. They use ebooks from
> where they cut and paste to look they have multiple specialities
> but this could be even 3 bastards working full time daily with
> 150 nicks and accounts all automated.
>
> Please look at my articles on google. just click my profile on
> groups.google.com to find out the potent truth I have written.
>
> I am sure you have seen that video of a student being tasered
> in University of Florida because these bastards hate our freedoms.
>
> These are corporatist bastards whose whole goal is to keep the
> public ignorant. THESE MOTHERFUCKERS hid the anthrax mailer who
> was really one of them. THE FBI Bastards never caught the anthrax
> mailer based in the USA>
>
> On Oct 8, 1:55 am, William D Clinger <[EMAIL PROTECTED]> wrote:
>
>
>
> > The gnuist wrote:
> > > Many years ago I went to an MIT prof on a technique I had become aware
> > > of. Its not McCarthy. When I asked him for his class notes on the
> > > subject to self-study, first he stared at me as if I was some kind of
> > > thief. Then as we were coming down to the first floor of the high
> > > voltage lab, I asked him why didnt he publish it? He said, and these
> > > are exact words: "you can make us as much guilty as you want, but we
> > > did not publish it."
>
> > An MIT prof who is not fluent in English and is also not
> > McCarthy?  That narrows it down.
>
> > > You may want to be clear about SI and SC.
> > > what language is source interpreter written in?
> > > what language is source compiler written in?
>
> > It doesn't matter.
>
> > > I would actually prefer that there was no environment
> > > available like no C compiler.
>
> > That doesn't matter either.
>
> > > All the processes would have to be created.
> > > Plz note that I am neither a CS nor a logician.
>
> > Nor does that.
>
> > > I prefer detailed treatment of this subject that is actually useful.
>
> > It would be hard to improve upon the advice that Jens gave
> > you.  I will add this:  If you don't have a compiler SC for
> > the language in which SI is written, then you have to write
> > SC before you hand-simulate it (or execute it, if you happen
> > to have a compiler for the language in which SC is written).
>
> > I will also add this:  If SC is written in the same language
> > as SI, then hand-simulating SC on SC itself gives you an
> > executable compiler, which you can then use to compile SI.
>
> > Been there, done that.
>
> > Will- Hide quoted text -
>
> - Show quoted text -


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


Re: Cross platform way of finding number of processors on a machine?

2007-10-08 Thread Lawrence Oluyede
Nicholas Bastin <[EMAIL PROTECTED]> wrote:
> This is really bad on linux.  You really want to parse /proc/cpuinfo
> because HT 'cpus' are almost useless, and can be bad in situations
> where you try to treat them as general purpose cpus.

I'm not the author of the library. I think you should address these bug
reports elsewhere...

-- 
Lawrence, oluyede.org - neropercaso.it
"It is difficult to get a man to understand 
something when his salary depends on not
understanding it" - Upton Sinclair
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pytz has so many timezones!

2007-10-08 Thread andrew clarke
On Mon, Oct 08, 2007 at 12:32:19AM -0700, Sanjay wrote:

> I am using pytz.common_timezones to populate the timezone combo box of
> some user registration form. But as it has so many timezones (around
> 400), it is a bit confusing to the users. Is there a smaller and more
> practical set? If not, some suggestions on how to handle the
> registration form effectively would help me a lot.

Use something like:

for zone in common_timezones:
  continent, region = zone.split('/')

Then have two list boxes, one for the continent and the other for the region.

[Australia  ]

[Melbourne  ]

('Continent' is probably not the right word.)

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


WARNING ABOUT ROGUE OPERATORS Re: The secret of hand compiling LISP/Scheme

2007-10-08 Thread thermate
This William D Clinger is a YANK MOTHER F*CKER, a 911 controlled
demolition operator group member or a ROGUE bastard in FBI whose
job and RACIST tendency is to CONTROL FREEDOM of information.
These MOTHERF*CKERS using fake accounts use "FULL LONG NAMES"
to FOOL simple and honest people that they are some genuine
people. They have multiple accounts and their sole job is to
derail conversations on the threads where there is exchange of
knowledge. That is their FULL TIME JOB. They use ebooks from
where they cut and paste to look they have multiple specialities
but this could be even 3 bastards working full time daily with
150 nicks and accounts all automated.

Please look at my articles on google. just click my profile on
groups.google.com to find out the potent truth I have written.

I am sure you have seen that video of a student being tasered
in University of Florida because these bastards hate our freedoms.

These are corporatist bastards whose whole goal is to keep the
public ignorant. THESE MOTHERFUCKERS hid the anthrax mailer who
was really one of them. THE FBI Bastards never caught the anthrax
mailer based in the USA>

On Oct 8, 1:55 am, William D Clinger <[EMAIL PROTECTED]> wrote:
> The gnuist wrote:
> > Many years ago I went to an MIT prof on a technique I had become aware
> > of. Its not McCarthy. When I asked him for his class notes on the
> > subject to self-study, first he stared at me as if I was some kind of
> > thief. Then as we were coming down to the first floor of the high
> > voltage lab, I asked him why didnt he publish it? He said, and these
> > are exact words: "you can make us as much guilty as you want, but we
> > did not publish it."
>
> An MIT prof who is not fluent in English and is also not
> McCarthy?  That narrows it down.
>
> > You may want to be clear about SI and SC.
> > what language is source interpreter written in?
> > what language is source compiler written in?
>
> It doesn't matter.
>
> > I would actually prefer that there was no environment
> > available like no C compiler.
>
> That doesn't matter either.
>
> > All the processes would have to be created.
> > Plz note that I am neither a CS nor a logician.
>
> Nor does that.
>
> > I prefer detailed treatment of this subject that is actually useful.
>
> It would be hard to improve upon the advice that Jens gave
> you.  I will add this:  If you don't have a compiler SC for
> the language in which SI is written, then you have to write
> SC before you hand-simulate it (or execute it, if you happen
> to have a compiler for the language in which SC is written).
>
> I will also add this:  If SC is written in the same language
> as SI, then hand-simulating SC on SC itself gives you an
> executable compiler, which you can then use to compile SI.
>
> Been there, done that.
>
> Will


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


Re: Don't use __slots__ (was Re: Problem of Readability of Python)

2007-10-08 Thread Steven Bethard
Aahz wrote:
> In article <[EMAIL PROTECTED]>,
> Steven Bethard  <[EMAIL PROTECTED]> wrote:
>> You can use __slots__  [...]
> 
> Aaaugh!  Don't use __slots__!
> 
> Seriously, __slots__ are for wizards writing applications with huuuge
> numbers of object instances (like, millions of instances).

You clipped me saying that __slots__ are for performance tweaks:

 You can use __slots__ to make objects consume less memory and have
 slightly better attribute-access performance. Classes for objects
 that need such performance tweaks should start like...

I fully agree that __slots__ are for applications with huge numbers of 
instances. But if you have that situation, you really do want to be 
using __slots__.

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


Re: Variable scoping rules in Python?

2007-10-08 Thread Paul Hankin
On Oct 8, 3:17 pm, [EMAIL PROTECTED] wrote:
> Ok, I'm relatively new to Python (coming from C, C++ and Java).  I'm
> working on a program that outputs text that may be arbitrarily long,
> but should still line up, so I want to split the output on a specific
> column boundary.  Since I might want to change the length of a column,
> I tried defining the column as a constant (what I would have made a
> "#define" in C, or a "static final" in Java).  I defined this at the
> top level (not within a def), and I reference it inside a function.
> Like this:
>
> COLUMNS = 80
>
> def doSomethindAndOutputIt( ):
>   ...
>   if COLUMNS == 0:
> COLUMNS = len( output[ 0 ] )

Often it's better to make your global 'constant' an optional argument,
especially if certain values have special meanings to your function.

def doSomethingAndOutputIt(columns = 80):
...
columns = columns or len(output[0])

--
Paul Hankin

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


HCL Technologies:Software Engineer/Senior software Engineer ..:: JobMaguz Update ::..

2007-10-08 Thread janaki . parasuraman
..:: Job Update from JobMaguz ::..

Today's Highlighted Job:
HCL Technologies:Software Engineer/Senior software Engineer
http://www.jobmaguz.com/viewFresherJobs.aspx?jobid=981&cycle=1

26 jobs posted today in JobMaguz

Jobs posted today:

Freshers Section
HCL Technologies:Software Engineer/Senior software Engineer
http://www.jobmaguz.com/viewFresherJobs.aspx?jobid=981&cycle=1

Willis Trinity recruits Freshers (ITES)
http://www.jobmaguz.com/viewFresherJobs.aspx?jobid=980&cycle=1

INTERNET PROTOCOL ENGG [Telecom Software] - ZTE Corporation
http://www.jobmaguz.com/viewFresherJobs.aspx?jobid=978&cycle=1

Plexus Microelectronics Pte Ltd
http://www.jobmaguz.com/viewFresherJobs.aspx?jobid=977&cycle=1

Saviance Technologies
http://www.jobmaguz.com/viewFresherJobs.aspx?jobid=975&cycle=1

More: www.jobmaguz.com/freshers.aspx


Experienced Section
Ansys Fluent India Pvt. Ltd
http://www.jobmaguz.com/viewExperiencedJobs.aspx?jobid=985&cycle=1

Keane:Support Professionals
http://www.jobmaguz.com/viewExperiencedJobs.aspx?jobid=984&cycle=1

 PTC Software India Pvt Ltd
http://www.jobmaguz.com/viewExperiencedJobs.aspx?jobid=982&cycle=1

Siyaram Silk Mills Ltd
http://www.jobmaguz.com/viewExperiencedJobs.aspx?jobid=979&cycle=1

i-flex Solutions - 13th Sept 2007 - Mumbai - Oracle Pl/SQL
http://www.jobmaguz.com/viewExperiencedJobs.aspx?jobid=965&cycle=1

More: www.jobmaguz.com/experienced.aspx


Referral Section
More: www.jobmaguz.com/referrals.aspx


Happy Job Hunting!!

..:: Team JobMaguz ::..

FOR REGULAR JOB UPDATES
--
Join our Orkut community
http://www.orkut.com/Community.aspx?cmm=29823377

Subscribe our fresher jobs' Feed
http://www.feedburner.com/fb/a/emailverifySubmit?feedId=1038318

Subscribe our experienced jobs' Feed
http://www.feedburner.com/fb/a/emailverifySubmit?feedId=1039530
--

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


Re: pytz has so many timezones!

2007-10-08 Thread Carsten Haese
On Mon, 2007-10-08 at 10:41 -0700, [EMAIL PROTECTED] wrote:
> For example, Windows has seperate listings for
> 
> Central America
> Central Time (US & Canada)
> Guadalahara, Mexico City, Monterry - New
> Guadalahara, Mexico City, Monterry - Old
> Saskatchewan
> 
> but they are all GMT-6

But they could have different rules for Daylight Saving Time.

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


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


Re: pytz has so many timezones!

2007-10-08 Thread J. Clifford Dyer
On Mon, Oct 08, 2007 at 10:41:03AM -0700, [EMAIL PROTECTED] wrote regarding Re: 
pytz has so many timezones!:
> 
> On Oct 8, 2:32 am, Sanjay <[EMAIL PROTECTED]> wrote:
> > Hi All,
> >
> > I am using pytz.common_timezones to populate the timezone combo box of
> > some user registration form. But as it has so many timezones (around
> > 400),
> 
> There are only 25 timezones: -12, -11, ... -1, 0 (GMT), +1, ... +11,
> +12.
> 
> A handful of countries set their clocks offset by a half hour,
> but those aren't timezones.
> 

I'm sorry.  By what even vaguely useful definition of "Timezone" is it not a 
timezone if it's offset by half an hour?  

> 
> The 400 you're seeing are duplications based on locality. Of the 86
> shown in Windows, all but 33 are dulplicate references to the same
> timezones.
> 
> For example, Windows has seperate listings for
> 
> Central America
> Central Time (US & Canada)
> Guadalahara, Mexico City, Monterry - New
> Guadalahara, Mexico City, Monterry - Old
> Saskatchewan
> 
> but they are all GMT-6
> 

Those are non-duplicate (and perhaps inaccurate, I'm not sure).  US time 
switches from standard to Daylight Savings earlier than Mexico, and switches 
back later, as of this year.  Reducing them to a single time zone will result 
in aberrant functionality in one or more locales.

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


mailman.bounces

2007-10-08 Thread kalin mintchev

hi all..

i'm a bit confused by the bounces behavior of mailman. the idea is that
each address from which a bounce comes back should be immediately removed
from the list. right now they are not. or testing i'm purposely putting
addresses that do not exist. in the mail log i get:

stat=Deferred: Connection timed out with dd.com

is that considered 'soft' or 'hard' bounce severity. is it considered
bounce at all?

here are the relevant settings:

Should Mailman perform automatic bounce processing?  => Yes

The maximum member bounce score before the member's subscription is
disabled. This value can be a floating point number. => 0.0  (tested 1.0
and 0.1 also)

The number of days after which a member's bounce information is discarded,
if no new bounces have been received in the interim. This value must be an
integer. => 7

How many Your Membership Is Disabled warnings a disabled member should get
before their address is removed from the mailing list. Set to 0 to
immediately remove an address from the list once their bounce score
exceeds the threshold. This value must be an integer.  => 0


thanks

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


Re: pytz has so many timezones!

2007-10-08 Thread [EMAIL PROTECTED]
On Oct 8, 2:32 am, Sanjay <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> I am using pytz.common_timezones to populate the timezone combo box of
> some user registration form. But as it has so many timezones (around
> 400),

There are only 25 timezones: -12, -11, ... -1, 0 (GMT), +1, ... +11,
+12.

A handful of countries set their clocks offset by a half hour,
but those aren't timezones.

And there is one country whose clock setting is the product of
a diseased mind (GMT+13), but that isn't a timezone either.

The 400 you're seeing are duplications based on locality. Of the 86
shown in Windows, all but 33 are dulplicate references to the same
timezones.

For example, Windows has seperate listings for

Central America
Central Time (US & Canada)
Guadalahara, Mexico City, Monterry - New
Guadalahara, Mexico City, Monterry - Old
Saskatchewan

but they are all GMT-6

> it is a bit confusing to the users. Is there a smaller and more
> practical set?

Filter the list by location.

> If not, some suggestions on how to handle the
> registration form effectively would help me a lot.
>
> thanks
> Sanjay


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


Re: How to create a file on users XP desktop

2007-10-08 Thread Julius
On Monday 08 October 2007 17:11:25 Tim Golden wrote:
> [EMAIL PROTECTED] wrote:
> > On Oct 8, 9:19 am, goldtech <[EMAIL PROTECTED]> wrote:
> >>> from win32com.shell import shell, shellcon
> >>> desktop = shell.SHGetFolderPath (0, shellcon.CSIDL_DESKTOP, 0, 0)
> >>> 
> >>
> >> Tim,
> >>
> >> How did you learn Win32com?
> >>
> >> Other than the O'Reilly book, I've never found a lot of
> >> documentation.
> >>
> >> Trying to browse COM in PythonWin is tough - there's tons of stuff in
> >> there. I've never been able to find the Win32com classes, methods,
> >> usage examples when I browse COM in PythonWin.
> >>
> >> For example where is, shell.SHGetFolderPath and shellcon.CSIDL_DESKTOP
> >> officially documented?
> >>
> >> Did you learn from using Visual C++ or VB? How did you learn this
> >> stuff?
> >>
> >> Thanks,
> >> Lee G.
> >
> > Pretty much the only place to learn stuff that's not in the PyWin32
> > docs is on one of the MSDN sites. Yes, that can suck. Here's the
> > general page: http://msdn2.microsoft.com/en-us/default.aspx
> >
> > You can google for them too to get direct links to the MSDN page.
> >
> > The ActiveState Python (AKA ActivePython) has an IDE that allows you
> > to browse the COM module. It also has a help file that allows you to
> > browse the PyWin32 docs locally. I think you can download that without
> > downloading ActivePython.
> >
> > Mike
>
> FWIW, the pywin32 distribution itself also comes with a local
> .chm file. But aside from that, there have been several abortive
> attempts -- including by Mike & myself! -- to get some kind of
> online help going for pywin32, but nothing's really gained traction,
> and we've all got more interesting things to be doing...
>
> One point to bear in mind that, more or less, the pywin32 stuff
> just wraps the MS API really closely, mostly doing just enough
> of the messy plumbing to present the API "objects" as Python
> objects. That's to say: find out how to do it from a C++ or VB
> or Delphi tutorial and translating into Python often isn't hard.
>
> As it happens I've been using Windows APIs for a few years,
> so I have a bit of a head start. But I've answered quite
> a few questions on python-win32 by putting the subject line
> into Google, picking a likely-looking response and translating
> it into Python.
>
> In this case ("How to create a file on users XP desktop") the
> question was too broad and tended to throw up user-oriented
> answers. I tried a few permutations, including limiting the
> search to msdn.microsoft.com, none of which showed much on the
> first couple of pages. A search of the pywin32.chm files does
> point in the right direction, but the fact is that the shell
> functionality exposed by Windows which does this kind of
> stuff is non-intuitive.
>
> While I think everyone agrees that the Windows side of Python
> could benefit from more and better docs, the general answer to:
> How do I do X in Python under Windows? is: How do I X under Windows?
>
> TJG
--
Free version Zoner Photo Studio 9 - http://www.zps9.com/

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


Re: changes on disk not visible to script ?

2007-10-08 Thread Nick Craig-Wood
Bruce <[EMAIL PROTECTED]> wrote:
>  On 8 Okt, 15:56, Richie Hindle <[EMAIL PROTECTED]> wrote:
> > [Bruce]
> >
> > > f.close()
> > > cmd = "echo %s | %s"%(argument_file,the_program)
> >
> > Either: you are a VB programmer and you've actually typed "f.close" rather
> > than "f.close()",
> 
>  You are right, I forgot the () in f.close() !
>  thanks for pointing that out.
> 
>  VB programmer!? Thats really harsh..

I used to make that mistake a lot as an ex-perl programmer.  I think
ruby is the same.

pychecker will warn about it though.

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


Re: Variable scoping rules in Python?

2007-10-08 Thread Steven D'Aprano
On Mon, 08 Oct 2007 07:17:36 -0700, joshua.davies wrote:

> I went back and re-read chapter 13 of "Learning Python", which talks
> about variable scoping rules, and I can't figure out why Python is
> saying this variable in Unbound.  It works if I insert:
> 
>   global COLUMNS
> 
> before the "if" statement... but I don't understand why.  Is the
> interpreter scanning my entire function definition before executing it,
> recognizing that I *might* assign COLUMNS to a value, and deciding that
> it's a local on that basis?

Almost right, but not quite.

You are right that Python decides that COLUMNS is local, but you're wrong 
about when that decision gets made. Python does not re-scan your function 
every time you execute it, but only once, when it is compiled.

Compiling the function might take one pass of the source code, or two, or 
a thousand for all we know; that's an irrelevant detail of interest only 
to compiler designers and the chronically curious. What's important is 
that once the function is compiled, the decision is already made about 
whether COLUMNS is local or not, and the virtual machine that executes 
your function only needs to interpret the byte-code in a single pass.



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


[OT] Re: Variable scoping rules in Python?

2007-10-08 Thread Peter Otten
joshua.davies wrote:

> Ok, I'm relatively new to Python (coming from C, C++ and Java).  I'm
> working on a program that outputs text that may be arbitrarily long,
> but should still line up, so I want to split the output on a specific
> column boundary.  Since I might want to change the length of a column,
> I tried defining the column as a constant (what I would have made a
> "#define" in C, or a "static final" in Java).  I defined this at the
> top level (not within a def), and I reference it inside a function.
> Like this:
> 
> COLUMNS = 80
> 
> def doSomethindAndOutputIt( ):
>   ...
>   for i in range( 0, ( len( output[0] ) / COLUMNS ) ):
> print output[0][ i * COLUMNS : i * COLUMNS + ( COLUMNS - 1 ) ]
> print output[1][ i * COLUMNS : i * COLUMNS + ( COLUMNS - 1 ) ]
> ..
> 
> etc. etc.  It works fine, and splits the output on the 80-column
> boundary just like I want.

Just in case it's not intentional: You'll lose every 80th character as
python intervals do not include the upper bound. The same problem
affects the for loop -- e. g. when output[0] has less than COLUMNS
columns nothing is printed:

>>> range(0, 79/80)
[]

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


Re: Really basic problem

2007-10-08 Thread Diez B. Roggisch
Zentrader wrote:

> You can use Python's decimal class if floating point arithmetic is not
> exact enough

This is a misleading statement. While it's true that decimal can be more
precise in the sense that smaller fractions are representable, the
underlying problem of certain values not being representable properly &
leading to rounding errors still exists:



>>> import decimal
>>> d = decimal.Decimal
>>> d("1") / d("3")
Decimal("0.")
>>> otrd = d("1") / d("3")
>>> otrd * 3
Decimal("0.")
>>> otrd * d("3")
Decimal("0.")
>>>


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


Adding extra modules to a Pyinstaller build

2007-10-08 Thread Craig
Hello all:

I need to add several Python standard modules to a Pyinstaller
project. The modules are not (and cannot be) explicitly imported in my
project script, so is there a way to add them to my .spec file in
order to allow Pyinstaller to search for them in PYTHONPATH and add
them to the project?

Regards,
Craig

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


Re: Really basic problem

2007-10-08 Thread Zentrader
You can use Python's decimal class if floating point arithmetic is not
exact enough

import decimal
status = decimal.Decimal( 0 )
for i in range(10):
   status += decimal.Decimal( "0.1" )
   if status == decimal.Decimal( "0.1" ):
   print status
   elif status == decimal.Decimal( "0.2" ):
   print status
   elif status == decimal.Decimal( "0.3" ):
   print status
   elif status == decimal.Decimal( "0.4" ):
   print status
   elif status == decimal.Decimal( "0.5" ):
   print status
   elif status == decimal.Decimal( "0.6" ):
   print status
   elif status == decimal.Decimal( "0.7" ):
   print status
   elif status == decimal.Decimal( "0.8" ):
   print status
   elif status == decimal.Decimal( "0.9" ):
   print status
   elif status == decimal.Decimal( "1.0" ):
   print status
   else:
   print "status not equal -->", status

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


Re: changes on disk not visible to script ?

2007-10-08 Thread Richie Hindle
[Bruce]
> VB programmer!? Thats really harsh..

No offence intended!  8-)

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


Re: How to create a file on users XP desktop

2007-10-08 Thread kyosohma
On Oct 8, 10:11 am, Tim Golden <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > On Oct 8, 9:19 am, goldtech <[EMAIL PROTECTED]> wrote:
> >>> from win32com.shell import shell, shellcon
> >>> desktop = shell.SHGetFolderPath (0, shellcon.CSIDL_DESKTOP, 0, 0)
> >>> 
> >> Tim,
>
> >> How did you learn Win32com?
>
> >> Other than the O'Reilly book, I've never found a lot of
> >> documentation.
>
> >> Trying to browse COM in PythonWin is tough - there's tons of stuff in
> >> there. I've never been able to find the Win32com classes, methods,
> >> usage examples when I browse COM in PythonWin.
>
> >> For example where is, shell.SHGetFolderPath and shellcon.CSIDL_DESKTOP
> >> officially documented?
>
> >> Did you learn from using Visual C++ or VB? How did you learn this
> >> stuff?
>
> >> Thanks,
> >> Lee G.
>
> > Pretty much the only place to learn stuff that's not in the PyWin32
> > docs is on one of the MSDN sites. Yes, that can suck. Here's the
> > general page:http://msdn2.microsoft.com/en-us/default.aspx
>
> > You can google for them too to get direct links to the MSDN page.
>
> > The ActiveState Python (AKA ActivePython) has an IDE that allows you
> > to browse the COM module. It also has a help file that allows you to
> > browse the PyWin32 docs locally. I think you can download that without
> > downloading ActivePython.
>
> > Mike
>
> FWIW, the pywin32 distribution itself also comes with a local
> .chm file. But aside from that, there have been several abortive
> attempts -- including by Mike & myself! -- to get some kind of
> online help going for pywin32, but nothing's really gained traction,
> and we've all got more interesting things to be doing...
>
> One point to bear in mind that, more or less, the pywin32 stuff
> just wraps the MS API really closely, mostly doing just enough
> of the messy plumbing to present the API "objects" as Python
> objects. That's to say: find out how to do it from a C++ or VB
> or Delphi tutorial and translating into Python often isn't hard.
>
> As it happens I've been using Windows APIs for a few years,
> so I have a bit of a head start. But I've answered quite
> a few questions on python-win32 by putting the subject line
> into Google, picking a likely-looking response and translating
> it into Python.
>
> In this case ("How to create a file on users XP desktop") the
> question was too broad and tended to throw up user-oriented
> answers. I tried a few permutations, including limiting the
> search to msdn.microsoft.com, none of which showed much on the
> first couple of pages. A search of the pywin32.chm files does
> point in the right direction, but the fact is that the shell
> functionality exposed by Windows which does this kind of
> stuff is non-intuitive.
>
> While I think everyone agrees that the Windows side of Python
> could benefit from more and better docs, the general answer to:
> How do I do X in Python under Windows? is: How do I X under Windows?
>
> TJG

I'm planning on working on that PyWin32 site some more this fall/
winter. Unfortunately, I shouldn't have volunteered my time during the
summer as I have very irregular a/c at home, and thus it was very
uncomfortable to use my PC when I was off work. Lame maybe, but I
dislike using a computer when it's above 90 degrees and the humidity
is higher than 70%. Bleh!

Sorry about that. I am experimenting with MediaWiki to see if it's any
faster than MoinMoin. If you know of a fast, easy-to-use wiki that's
better than both of those, let me know.

Mike

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


Re: weakrefs and bound methods

2007-10-08 Thread Chris Mellon
On 10/8/07, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> On Mon, 08 Oct 2007 04:06:55 +, Michele Simionato wrote:
>
> > > Hmmm... I'm not sure I understand how a with statement is meant to
> > > replace class.__del__ in practice. It seems to me that the two things
> > > have different uses. with is useful when you create an object, do
> > > something with it, dispose of it in an orderly fashion, and then
> > > continue. How does that help when you create an unknown number of
> > > long-lasting objects where you can't predict how and when they will be
> > > disposed of?
>
> [snip]
>
> >> Now, I don't think the above is feasible. What am I missing?
> >
> > Rename your __del__ to close and call it explicitely:
> >
> > p.close()
> > alist[3].close()
> > alist[853].close()
> > alist[701].close()
>
> Well, that utterly sucks. If I wanted to call finalizers explicitly, I'd
> be writing in C.
>
> You say that using __del__ leads to hard-to-debug "bombs in my code
> waiting to explode at some unknown moment". Maybe so -- but so does
> explicitly managing resources by hand in the way you suggest, and quite
> frankly, I suspect I'd have a hell of a lot fewer bugs by relying on
> __del__ and the garbage collector than I would from managing resources
> manually in a big project.
>

The point that is being made is that "relying on __del__" is stupid,
because __del__ isn't reliable. It's akin to a Java finalizer - there
is no guarantee that it will be called at all. So you can use __del__,
and have to be continually aware of the dangers of circular references
and  refcounting, or you use explicit finalizers, or you can use
context managers. If you have arbitrary numbers of long-lived,
potentially self-referential objects that you can't control in any
other way, you're screwed - you're going to *have* to have a manual
destruction somewhere.
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Pyrex 0.9.6.1

2007-10-08 Thread Greg Ewing
Pyrex 0.9.6.1 is now available:

   http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/

This version fixes a few minor problems that turned
up in the initial 0.9.6 release.

What is Pyrex?
--

Pyrex is a language for writing Python extension modules.
It lets you freely mix operations on Python and C data, with
all Python reference counting and error checking handled
automatically.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: tkinter question

2007-10-08 Thread Hamilton, William
> -Original Message-
> From: Kevin Walzer
> 
> See
http://www.codebykevin.com/blosxom/business/phynchronicity-new.png:
> this is an application I develop. The layout is all handled by "pack"
> and paned windows. Where you you use "grid" in a layout like this?
> 

I'd use a three row grid, with the middle row containing a frame with
another grid in it.  I don't try to create a single massive grid that
manages everything, I break it up into subgrids of related widgets.

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


Re: How to create a file on users XP desktop

2007-10-08 Thread Tim Golden
[EMAIL PROTECTED] wrote:
> On Oct 8, 9:19 am, goldtech <[EMAIL PROTECTED]> wrote:
>>> from win32com.shell import shell, shellcon
>>> desktop = shell.SHGetFolderPath (0, shellcon.CSIDL_DESKTOP, 0, 0)
>>> 
>> Tim,
>>
>> How did you learn Win32com?
>>
>> Other than the O'Reilly book, I've never found a lot of
>> documentation.
>>
>> Trying to browse COM in PythonWin is tough - there's tons of stuff in
>> there. I've never been able to find the Win32com classes, methods,
>> usage examples when I browse COM in PythonWin.
>>
>> For example where is, shell.SHGetFolderPath and shellcon.CSIDL_DESKTOP
>> officially documented?
>>
>> Did you learn from using Visual C++ or VB? How did you learn this
>> stuff?
>>
>> Thanks,
>> Lee G.
> 
> Pretty much the only place to learn stuff that's not in the PyWin32
> docs is on one of the MSDN sites. Yes, that can suck. Here's the
> general page: http://msdn2.microsoft.com/en-us/default.aspx
> 
> You can google for them too to get direct links to the MSDN page.
> 
> The ActiveState Python (AKA ActivePython) has an IDE that allows you
> to browse the COM module. It also has a help file that allows you to
> browse the PyWin32 docs locally. I think you can download that without
> downloading ActivePython.
> 
> Mike

FWIW, the pywin32 distribution itself also comes with a local
.chm file. But aside from that, there have been several abortive
attempts -- including by Mike & myself! -- to get some kind of
online help going for pywin32, but nothing's really gained traction,
and we've all got more interesting things to be doing...

One point to bear in mind that, more or less, the pywin32 stuff
just wraps the MS API really closely, mostly doing just enough
of the messy plumbing to present the API "objects" as Python
objects. That's to say: find out how to do it from a C++ or VB
or Delphi tutorial and translating into Python often isn't hard.

As it happens I've been using Windows APIs for a few years,
so I have a bit of a head start. But I've answered quite
a few questions on python-win32 by putting the subject line
into Google, picking a likely-looking response and translating
it into Python.

In this case ("How to create a file on users XP desktop") the
question was too broad and tended to throw up user-oriented
answers. I tried a few permutations, including limiting the
search to msdn.microsoft.com, none of which showed much on the
first couple of pages. A search of the pywin32.chm files does
point in the right direction, but the fact is that the shell
functionality exposed by Windows which does this kind of
stuff is non-intuitive.

While I think everyone agrees that the Windows side of Python
could benefit from more and better docs, the general answer to:
How do I do X in Python under Windows? is: How do I X under Windows?

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


Re: Variable scoping rules in Python?

2007-10-08 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
> Ok, I'm relatively new to Python (coming from C, C++ and Java).  I'm
> working on a program that outputs text that may be arbitrarily long,
> but should still line up, so I want to split the output on a specific
> column boundary.

FWIW :
http://docs.python.org/lib/module-textwrap.html


>  Since I might want to change the length of a column,
> I tried defining the column as a constant (what I would have made a
> "#define" in C, or a "static final" in Java).  I defined this at the
> top level (not within a def), and I reference it inside a function.
> Like this:
> 
> COLUMNS = 80
> 
> def doSomethindAndOutputIt( ):
>   ...
>   for i in range( 0, ( len( output[0] ) / COLUMNS ) ):
> print output[0][ i * COLUMNS : i * COLUMNS + ( COLUMNS - 1 ) ]
> print output[1][ i * COLUMNS : i * COLUMNS + ( COLUMNS - 1 ) ]
> ..
> 
> etc. etc.  It works fine, and splits the output on the 80-column
> boundary just like I want.
> 
> Well, I decided that I wanted "COLUMNS = 0" to be a special "don't
> split anywhere" value, so I changed it to look like this:
> 
> COLUMNS = 80
> 
> def doSomethindAndOutputIt( ):
>   ...
>   if COLUMNS == 0:
> COLUMNS = len( output[ 0 ] )
 >
>   for i in range( 0, ( len( output[0] ) / COLUMNS ) ):
> print output[0][ i * COLUMNS : i * COLUMNS + ( COLUMNS - 1 ) ]
> print output[1][ i * COLUMNS : i * COLUMNS + ( COLUMNS - 1 ) ]
> ..

Since you don't want to modify a global (and even worse, a CONSTANT), 
the following code may be a bit cleaner:

def doSomethindAndOutputIt( ):
   ...
   if COLUMNS == 0:
  columns = len( output[ 0 ] )
   else:
  columns = COLUMNS
   for i in range( 0, ( len( output[0] ) / COLUMNS ) ):
  print output[0][ i * columns : i * columns + ( columns - 1 ) ]
   ..


> Now, when I run it, I get the following error:
> 
> Traceback (most recent call last):
>   File "Test.py", line 140, in ?
> doSomethingAndOutput( input )
>   File "Test.py", line 123, in doSomethingAndOutput
> if COLUMNS == 0:
> UnboundLocalError: local variable 'COLUMNS' referenced before
> assignment
> 
> I went back and re-read chapter 13 of "Learning Python", which talks
> about variable scoping rules, and I can't figure out why Python is
> saying this variable in Unbound.  It works if I insert:
> 
>   global COLUMNS
> 
> before the "if" statement... but I don't understand why.  Is the
> interpreter scanning my entire function definition before executing
> it, recognizing that I *might* assign COLUMNS to a value, and deciding
> that it's a local on that basis?

You name it. That's *exactly* what happens.

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


Re: Tkinter text widget

2007-10-08 Thread goldtech
After some Google searching I found "ScrolledText", this does what I
want :^)


from Tkinter import *
from ScrolledText import ScrolledText
root = Tk()
text = ScrolledText(root, font=("Courier"))
ScrolledText
text.pack()
i='123456789abcdefghijklmnopqrstuvwxyz\n'
for x in range(30):
text.insert(END, "%3d " % x + i)
text.config(state=DISABLED)
mainloop()

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


www.yedil.com best hindi entertainment site

2007-10-08 Thread diprat7
www.yedil.com best hindi entertainment site
with vidoes,photo sharing,photo rating features
its really gona rock you
www.yedil.com

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


Re: Override 'and' and 'or'

2007-10-08 Thread Andrew Durdin
On 10/7/07, Dekker <[EMAIL PROTECTED]> wrote:
>
> Well I think it is not possible what I wanted to achieve. By
> overriding the "and" and "or" keyword I wanted to return a new object:
>
> SqlValueInt(4) and SqlValueInt(5) --> SqlOpAnd(SqlValueInt(4),
> SqlValueInt(5))

PEP 335 is a proposal to allow overriding of the logical 'and', 'or' operators:

See  and the discussion of
it at 

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


Re: How to create a file on users XP desktop

2007-10-08 Thread kyosohma
On Oct 8, 9:19 am, goldtech <[EMAIL PROTECTED]> wrote:
> > from win32com.shell import shell, shellcon
>
> > desktop = shell.SHGetFolderPath (0, shellcon.CSIDL_DESKTOP, 0, 0)
>
> > 
>
> Tim,
>
> How did you learn Win32com?
>
> Other than the O'Reilly book, I've never found a lot of
> documentation.
>
> Trying to browse COM in PythonWin is tough - there's tons of stuff in
> there. I've never been able to find the Win32com classes, methods,
> usage examples when I browse COM in PythonWin.
>
> For example where is, shell.SHGetFolderPath and shellcon.CSIDL_DESKTOP
> officially documented?
>
> Did you learn from using Visual C++ or VB? How did you learn this
> stuff?
>
> Thanks,
> Lee G.

Pretty much the only place to learn stuff that's not in the PyWin32
docs is on one of the MSDN sites. Yes, that can suck. Here's the
general page: http://msdn2.microsoft.com/en-us/default.aspx

You can google for them too to get direct links to the MSDN page.

The ActiveState Python (AKA ActivePython) has an IDE that allows you
to browse the COM module. It also has a help file that allows you to
browse the PyWin32 docs locally. I think you can download that without
downloading ActivePython.

Mike

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


Re: Howto Launch a windows application ?

2007-10-08 Thread Hyuga
On Oct 3, 5:39 pm, stef mientki <[EMAIL PROTECTED]> wrote:
>
> from subprocess import *
>
> cmd =[]
> cmd.append ( 'D:\\PIC-tools\\JALxxx\\jalv2_3.exe' )
> cmd.append ( '-long-start' )
> cmd.append ( '-d')
> cmd.append ( '-clear' )
> cmd.append ( '-sD:\\PIC-tools\\JAL\\libs2' )
> cmd.append ( 'd:\\pic-tools\\jal\\programs\\test_rs232\\test_rs232_hw.jal' )
> cmd.append ( '>d:\\data_actueel\\d7_test_browser\\temp.log' )

This is sort of aside from your original question, but I should also
point out how unnecessary all those 'cmd.append's are.  You can
initialize the list all at once simply like so:

cmd =['D:\\PIC-tools\\JALxxx\\jalv2_3.exe',
  '-long-start',
  '-d',
  '-clear',
  '-sD:\\PIC-tools\\JAL\\libs2',
  'd:\\pic-tools\\jal\\programs\\test_rs232\\test_rs232_hw.jal',
  '>d:\\data_actueel\\d7_test_browser\\temp.log']

Hyuga

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


Re: changes on disk not visible to script ?

2007-10-08 Thread Nick Craig-Wood
Bruce <[EMAIL PROTECTED]> wrote:
>  I am trying to have my script automate a task, by using os.system, but
>  I cant get it to work.
> 
>  manually, outside the script I can do this thing by
> 
>  C:\echo argument_file | the_program
> 
>  This works very well when argument_file is created before my script is
>  started
> 
>  In the script I try to do it like this:
>  f = open("argument_file",'w')
>  f.write(argument)
>  f.close()
>  cmd = "echo %s | %s"%(argument_file,the_program)
>  os.system(cmd)
> 
>  The script works if the argument_file is already in the directory
>  before os.system(cmd), but the script must create argument_file before
>  using os.system. Problem is the_program cannot find argument_file or
>  the_program cannot find anything inside argument_file.

Send some real code, plus a sequence of steps to be followed to
replicate the problem and you'll get some real help.  The above is
just too vague.

The above code has a syntax error in it so obviously isn't from
working code.

PS I really doubt the problem is windows not seeing the created file...

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


Re: Variable scoping rules in Python?

2007-10-08 Thread Diez B. Roggisch
 [EMAIL PROTECTED] wrote:

> Ok, I'm relatively new to Python (coming from C, C++ and Java).  I'm
> working on a program that outputs text that may be arbitrarily long,
> but should still line up, so I want to split the output on a specific
> column boundary.  Since I might want to change the length of a column,
> I tried defining the column as a constant (what I would have made a
> "#define" in C, or a "static final" in Java).  I defined this at the
> top level (not within a def), and I reference it inside a function.
> Like this:
> 
> COLUMNS = 80
> 
> def doSomethindAndOutputIt( ):
>   ...
>   for i in range( 0, ( len( output[0] ) / COLUMNS ) ):
> print output[0][ i * COLUMNS : i * COLUMNS + ( COLUMNS - 1 ) ]
> print output[1][ i * COLUMNS : i * COLUMNS + ( COLUMNS - 1 ) ]
> ..
> 
> etc. etc.  It works fine, and splits the output on the 80-column
> boundary just like I want.
> 
> Well, I decided that I wanted "COLUMNS = 0" to be a special "don't
> split anywhere" value, so I changed it to look like this:
> 
> COLUMNS = 80
> 
> def doSomethindAndOutputIt( ):
>   ...
>   if COLUMNS == 0:
> COLUMNS = len( output[ 0 ] )
> 
>   for i in range( 0, ( len( output[0] ) / COLUMNS ) ):
> print output[0][ i * COLUMNS : i * COLUMNS + ( COLUMNS - 1 ) ]
> print output[1][ i * COLUMNS : i * COLUMNS + ( COLUMNS - 1 ) ]
> ..
> 
> Now, when I run it, I get the following error:
> 
> Traceback (most recent call last):
>   File "Test.py", line 140, in ?
> doSomethingAndOutput( input )
>   File "Test.py", line 123, in doSomethingAndOutput
> if COLUMNS == 0:
> UnboundLocalError: local variable 'COLUMNS' referenced before
> assignment
> 
> I went back and re-read chapter 13 of "Learning Python", which talks
> about variable scoping rules, and I can't figure out why Python is
> saying this variable in Unbound.  It works if I insert:
> 
>   global COLUMNS
> 
> before the "if" statement... but I don't understand why.  Is the
> interpreter scanning my entire function definition before executing
> it, recognizing that I *might* assign COLUMNS to a value, and deciding
> that it's a local on that basis?

Yep. That's essentially it. Because python has no explicit variable
declaration, it looks on the left hand side of assignments to determine the
locals. 

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


Re: How to create a file on users XP desktop

2007-10-08 Thread goldtech

> from win32com.shell import shell, shellcon
>
> desktop = shell.SHGetFolderPath (0, shellcon.CSIDL_DESKTOP, 0, 0)
>
> 

Tim,

How did you learn Win32com?

Other than the O'Reilly book, I've never found a lot of
documentation.

Trying to browse COM in PythonWin is tough - there's tons of stuff in
there. I've never been able to find the Win32com classes, methods,
usage examples when I browse COM in PythonWin.

For example where is, shell.SHGetFolderPath and shellcon.CSIDL_DESKTOP
officially documented?

Did you learn from using Visual C++ or VB? How did you learn this
stuff?

Thanks,
Lee G.

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


Variable scoping rules in Python?

2007-10-08 Thread joshua . davies
Ok, I'm relatively new to Python (coming from C, C++ and Java).  I'm
working on a program that outputs text that may be arbitrarily long,
but should still line up, so I want to split the output on a specific
column boundary.  Since I might want to change the length of a column,
I tried defining the column as a constant (what I would have made a
"#define" in C, or a "static final" in Java).  I defined this at the
top level (not within a def), and I reference it inside a function.
Like this:

COLUMNS = 80

def doSomethindAndOutputIt( ):
  ...
  for i in range( 0, ( len( output[0] ) / COLUMNS ) ):
print output[0][ i * COLUMNS : i * COLUMNS + ( COLUMNS - 1 ) ]
print output[1][ i * COLUMNS : i * COLUMNS + ( COLUMNS - 1 ) ]
..

etc. etc.  It works fine, and splits the output on the 80-column
boundary just like I want.

Well, I decided that I wanted "COLUMNS = 0" to be a special "don't
split anywhere" value, so I changed it to look like this:

COLUMNS = 80

def doSomethindAndOutputIt( ):
  ...
  if COLUMNS == 0:
COLUMNS = len( output[ 0 ] )

  for i in range( 0, ( len( output[0] ) / COLUMNS ) ):
print output[0][ i * COLUMNS : i * COLUMNS + ( COLUMNS - 1 ) ]
print output[1][ i * COLUMNS : i * COLUMNS + ( COLUMNS - 1 ) ]
..

Now, when I run it, I get the following error:

Traceback (most recent call last):
  File "Test.py", line 140, in ?
doSomethingAndOutput( input )
  File "Test.py", line 123, in doSomethingAndOutput
if COLUMNS == 0:
UnboundLocalError: local variable 'COLUMNS' referenced before
assignment

I went back and re-read chapter 13 of "Learning Python", which talks
about variable scoping rules, and I can't figure out why Python is
saying this variable in Unbound.  It works if I insert:

  global COLUMNS

before the "if" statement... but I don't understand why.  Is the
interpreter scanning my entire function definition before executing
it, recognizing that I *might* assign COLUMNS to a value, and deciding
that it's a local on that basis?

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


Re: changes on disk not visible to script ?

2007-10-08 Thread Bruce
On 8 Okt, 15:56, Richie Hindle <[EMAIL PROTECTED]> wrote:
> [Bruce]
>
> > f.close()
> > cmd = "echo %s | %s"%(argument_file,the_program)
>
> Either: you are a VB programmer and you've actually typed "f.close" rather
> than "f.close()",
>
> Or: you meant "type" (or "cat") rather than "echo",
>
> Or: I need a new crystal ball.  8-)
>
> --
> Richie Hindle
> [EMAIL PROTECTED]

You are right, I forgot the () in f.close() !
thanks for pointing that out.

VB programmer!? Thats really harsh..

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


Re: Tkinter text widget

2007-10-08 Thread goldtech
On Oct 7, 11:00 am, Simon Forman <[EMAIL PROTECTED]> wrote:
> On Oct 6, 11:18 pm, goldtech <[EMAIL PROTECTED]> wrote:
>
>
>
> > I thought the "DISABLED" made it so I could not edit it. But it also
> > makes it so I can not scroll down. If you make the window smaller than
> > the content then try to put a cursor in there to use up/down arrow you
> > can't.
>
> > What I want is not to be able to change text content, but no other
> > action is disabled. Is this complicated to do?
>
> > Thanks.
>
> > from Tkinter import *
> > root = Tk()
> > text = Text(root, font=("Courier"))
> > text.pack()
> > i='123456789abcdefghijklmnopqrstuvwxyz\n'
> > for x in range(30):
> > text.insert(END, i)
> > text.config(state=DISABLED)
> > mainloop()
>
> I just tried this script.  You can select text and if you drap the
> selection outside the window then scrolling occurs, also Tk's default
> behavior of scrolling with the middle button still works (i.e. click-
> and-drag with the middle button to scroll.)

Yes, if I depress the mouse's scroll wheel (the middle button) I can
drag the content up/down. Interesting...I didn't know that. But I
can't select, XP Python 2.1.

I'll try adding scroll bars. Thanks.

...snip...

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


Re: Don't use __slots__ (was Re: Problem of Readability of Python)

2007-10-08 Thread Diez B. Roggisch
Steven D'Aprano wrote:

> On Mon, 08 Oct 2007 15:15:36 +0200, Diez B. Roggisch wrote:
> 
>>> Well, I've read the thread, and I've read the thread it links to, and
>>> for the life of me I'm still no clearer as to why __slots__ shouldn't
>>> be used except that:
>>> 
>>> 1 Aahz and Guido say __slots__ are teh suxxor;
>>> 
>>> 2 rumour (?) has it that __slots__ won't make it into Python 3.0;
>>> 
>>> 3 inheritance from classes using __slots__ doesn't inherit the slot-
>>> nature of the superclass.
>>> 
>>> 
>>> Point 1 is never to be lightly dismissed, but on the other hand Guido
>>> doesn't like reduce(), and I'm allergic to "Cos I Said So" arguments.
>>> 
>>> History is full of things which were invented for one purpose being
>>> used for something else. So, that being the case, suppose I accept that
>>> using __slots__ is not the best way of solving the problem, and that
>>> people of the skill and experience of Guido and Aahz will roll their
>>> eyes and snicker at me.
>>> 
>>> But is there actually anything *harmful* that can happen if I use
>>> __slots__?
>> 
>> Point 3 clearly is harmful.
> 
> No, it is DIFFERENT, not harmful. At worst, it's a "gotcha" -- a really
> well-documented gotcha.

To the casual observer? I doubt it. I wasn't aware of that until a recent
discussion about slots. But then, I've so far _never_ felt the need to  use
them...
 
> 
>> As is the fact that __slots__ gives you
>> troubles if you e.g. pass objects to code that tries to set arbitrary
>> attributes on an object.
> 
> You mean like this?
> 
 x = 1
 x.label = "foo"
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'int' object has no attribute 'label'
> 
> I guess that means ints and floats and strings and tuples and lists are
> all harmful too, yes?

You are very well aware that I was talking about complex objects. And I
didn't say that they are harmful, but that using __slots__ to constrain
object attribute will lead to surprising results here in comparison to
the "usual" behavior. And with usual I mean
most-of-the-classes-work-that-way. Which might be considered as reason to
_not_ do it. But you are free to limit yourself, be my guest.

>> The question is: what does a slot buy you for this kind of problem?
> 
> Simplicity and explicitness.

Where is that more simple? Additional notation that will lead to
runtime-errors, the same way misspelled attribute-names do?

And yes, it is more explicit. As are interfaces, and type declarations. 

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


Re: How to create a file on users XP desktop

2007-10-08 Thread kyosohma
On Oct 7, 12:30 pm, Tim Golden <[EMAIL PROTECTED]> wrote:
> Tim Chase wrote:
> >> You are assuming the system is not localized, that won't work if you
> >> distribute your applications internationally. In my system it is not
> >> "Desktop", it is "Escritorio", and I guess it will vary with every
> >> locale. Does someone know a way to find out what name does the desktop
> >> have?
>
> > I believe you need to read the Desktop value from
>
> > """
> > HKEY_CURRENT_USER\software\microsoft\windows\currentversion\explorer\shell
> > folders
> > """
>
> > which should (in my understanding) hold the full path of the
> > particular folder(s) of interest at that location, including
> > across localizations.
>
> > -tkc
>
> Ideally, use the shell API exposed by pywin32:
>
> 
> from win32com.shell import shell, shellcon
>
> desktop = shell.SHGetFolderPath (0, shellcon.CSIDL_DESKTOP, 0, 0)
>
> 
>
> For slight convenience:
>
>http://timgolden.me.uk/python/winshell.html
>
> TJG

What happened to your winshell module? I would have thought it perfect
for this.

http://timgolden.me.uk/python/winshell.html

Mike

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


Re: changes on disk not visible to script ?

2007-10-08 Thread Richie Hindle
[Bruce]
> f.close()
> cmd = "echo %s | %s"%(argument_file,the_program)

Either: you are a VB programmer and you've actually typed "f.close" rather
than "f.close()",

Or: you meant "type" (or "cat") rather than "echo",

Or: I need a new crystal ball.  8-)

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: changes on disk not visible to script ?

2007-10-08 Thread kyosohma
On Oct 8, 8:27 am, Bruce <[EMAIL PROTECTED]> wrote:
> Hi,
> I am trying to have my script automate a task, by using os.system, but
> I cant get it to work.
>
> manually, outside the script I can do this thing by
>
> C:\echo argument_file | the_program
>
> This works very well when argument_file is created before my script is
> started
>
> In the script I try to do it like this:
> f = open("argument_file",'w')
> f.write(argument)
> f.close()
> cmd = "echo %s | %s"%(argument_file,the_program)
> os.system(cmd)
>
> The script works if the argument_file is already in the directory
> before os.system(cmd), but the script must create argument_file before
> using os.system. Problem is the_program cannot find argument_file or
> the_program cannot find anything inside argument_file.
>
> The python script cannot see changes on disk. In the "My computer"
> window, if I do a refresh, I can see the argument_file is created
> during the script. I have also tried delays with time.sleep right
> after creating the file, but still no success.


You can test for the existence of the file using os.path.exists() to
prove whether or not Python can "see" the file. You can also have
Python read the file and show what it finds, if anything. I think you
can flush data to the file before closing it...


>
> Is there some way to around this? must use windows I`m afraid.

If the path to the file or the program's executable has spaces in it,
you may have issues. If so, you'll need to put double quotes around
the path(s) and single or triple quote the string. Also, you might try
it with the subprocess module.

Hopefully that gave you some ideas.

Mike


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


Re: How to create a file on users XP desktop

2007-10-08 Thread goldtech

> from win32com.shell import shell, shellcon
>
> desktop = shell.SHGetFolderPath (0, shellcon.CSIDL_DESKTOP, 0, 0)
>
> 
>

I have a general problem with using win32com. It's the documentation.
I never know what is available, what classes, methods, what they do.
Even some of the existing documentation admits existing documentation
is scant e.g. "you're just expected to know".

Other than the O'Reilly book. People say to browse COM with PythonWin.
When I try this I'm confronted with a dizzying array, there's tons of
stuff in there. Where's  win32com? If I find it will there be a
synopsis on each class, each classes methods? Will there be usage
examples?

If I'm wrong please educate me.

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


Re: pytz has so many timezones!

2007-10-08 Thread Sanjay
> Windows timezone selector only lists about 80 timezones. But why force
> the user to select timezone? Let them select from a list of countries
> and then infer the timezone from that data. With multiple alternatives
> for countries with more than one timezone, United States EST, United
> States PST and so on.

> I think the problem is displaying a dropdown list of timezones. People
> have little idea of how their timezones are called; it would be better
> to list countries, which are many but nicely alphabetized, and map the
> country to its only timezone, or for the few large countries with more
> than a TZ offer a choice later.

Thanks for the suggestions!

1. I am unable to understand how Windows manages with only 80 whereas
pytz has 400. Understanding this can be a nice clue for my work. Any
insights?
2. Mapping the timezones to countries is a nice idea. Any idea how to
go about it - I mean whether I have to collect the data manually and
do it, or some better way is available - will help me a lot.

thanks
Sanjay

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


changes on disk not visible to script ?

2007-10-08 Thread Bruce
Hi,
I am trying to have my script automate a task, by using os.system, but
I cant get it to work.

manually, outside the script I can do this thing by

C:\echo argument_file | the_program

This works very well when argument_file is created before my script is
started

In the script I try to do it like this:
f = open("argument_file",'w')
f.write(argument)
f.close()
cmd = "echo %s | %s"%(argument_file,the_program)
os.system(cmd)

The script works if the argument_file is already in the directory
before os.system(cmd), but the script must create argument_file before
using os.system. Problem is the_program cannot find argument_file or
the_program cannot find anything inside argument_file.

The python script cannot see changes on disk. In the "My computer"
window, if I do a refresh, I can see the argument_file is created
during the script. I have also tried delays with time.sleep right
after creating the file, but still no success.

Is there some way to around this? must use windows I`m afraid.

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


Re: Don't use __slots__ (was Re: Problem of Readability of Python)

2007-10-08 Thread Steven D'Aprano
On Mon, 08 Oct 2007 15:15:36 +0200, Diez B. Roggisch wrote:

>> Well, I've read the thread, and I've read the thread it links to, and
>> for the life of me I'm still no clearer as to why __slots__ shouldn't
>> be used except that:
>> 
>> 1 Aahz and Guido say __slots__ are teh suxxor;
>> 
>> 2 rumour (?) has it that __slots__ won't make it into Python 3.0;
>> 
>> 3 inheritance from classes using __slots__ doesn't inherit the slot-
>> nature of the superclass.
>> 
>> 
>> Point 1 is never to be lightly dismissed, but on the other hand Guido
>> doesn't like reduce(), and I'm allergic to "Cos I Said So" arguments.
>> 
>> History is full of things which were invented for one purpose being
>> used for something else. So, that being the case, suppose I accept that
>> using __slots__ is not the best way of solving the problem, and that
>> people of the skill and experience of Guido and Aahz will roll their
>> eyes and snicker at me.
>> 
>> But is there actually anything *harmful* that can happen if I use
>> __slots__?
> 
> Point 3 clearly is harmful. 

No, it is DIFFERENT, not harmful. At worst, it's a "gotcha" -- a really 
well-documented gotcha.


> As is the fact that __slots__ gives you
> troubles if you e.g. pass objects to code that tries to set arbitrary
> attributes on an object.

You mean like this?

>>> x = 1
>>> x.label = "foo"
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'int' object has no attribute 'label'

I guess that means ints and floats and strings and tuples and lists are 
all harmful too, yes?



> The question is: what does a slot buy you for this kind of problem?

Simplicity and explicitness.



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


RE: Really basic problem

2007-10-08 Thread Andreas Tawn
> > I guess this means that Python has some concept of "close 
> enough", but
> > I'll have to defer to someone more knowledgeable to explain that.
> 
> No, not really, except in the sense that any floating point 
> calculation 
> will be necessarily imprecise in that sense.
[snip]
> So typing 0.3 is the same as typing 0.2 or 
> 0.30001 as far as floating point binary values 
> are concerned.
> 
> (Although note that these results are platform dependent. 
> Your mileage 
> may vary.)
> 
> -- 
> Steven
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 

After some caffeine and a head-smack, I realise that you're absolutely
right and I just made the same mistake as the OP (doh).

It does demonstrate just how sneaky floating point representations are
though.

Cheers,

Andreas Tawn
Lead Technical Artist
Ubisoft Reflections
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Don't use __slots__ (was Re: Problem of Readability of Python)

2007-10-08 Thread Diez B. Roggisch
Steven D'Aprano wrote:

> On Sun, 07 Oct 2007 21:27:31 -0700, Aahz wrote:
> 
>> In article <[EMAIL PROTECTED]>, Steven
>> Bethard  <[EMAIL PROTECTED]> wrote:
>>>
>>>You can use __slots__  [...]
>> 
>> Aaaugh!  Don't use __slots__!
>> 
>> Seriously, __slots__ are for wizards writing applications with huuuge
>> numbers of object instances (like, millions of instances).  For an
>> extended thread about this, see
>> 
>> http://groups.google.com/group/comp.lang.python/browse_thread/
> thread/8775c70565fb4a65/0e25f368e23ab058
> 
> Well, I've read the thread, and I've read the thread it links to, and for
> the life of me I'm still no clearer as to why __slots__ shouldn't be used
> except that:
> 
> 1 Aahz and Guido say __slots__ are teh suxxor;
> 
> 2 rumour (?) has it that __slots__ won't make it into Python 3.0;
> 
> 3 inheritance from classes using __slots__ doesn't inherit the slot-
> nature of the superclass.
> 
> 
> Point 1 is never to be lightly dismissed, but on the other hand Guido
> doesn't like reduce(), and I'm allergic to "Cos I Said So" arguments.
> 
> History is full of things which were invented for one purpose being used
> for something else. So, that being the case, suppose I accept that using
> __slots__ is not the best way of solving the problem, and that people of
> the skill and experience of Guido and Aahz will roll their eyes and
> snicker at me.
> 
> But is there actually anything *harmful* that can happen if I use
> __slots__?

Point 3 clearly is harmful. As is the fact that __slots__ gives you troubles
if you e.g. pass objects to code that tries to set arbitrary attributes on
an object. While this might be frowned upon, it can be useful in situations
where you e.g. link GUI-code/objects with data-objects: instead of creating
cumbersome, explicit mappings (as you have to in C/C++/Java) or wrappers,
just set a well-named property.

The question is: what does a slot buy you for this kind of problem? And
while arguing with "then I can't set an attribute I didn't want to be set"
is certainly possible, it ultimately leads to the darn
static-vs-dynamic-discussion. Which we might spare us this time.

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


python graphics

2007-10-08 Thread [EMAIL PROTECTED]
hello all
i researching a graphics table with python.haeve you got this how it
have got design and fast making
thanks for your help

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


Re: Pil image module, "mode" bug..

2007-10-08 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

> On Oct 7, 8:17 pm, Michal Bozon <[EMAIL PROTECTED]> wrote:
>> On Sun, 07 Oct 2007 09:02:09 -0700, Abandoned wrote:
>> > On Oct 7, 4:47 pm, Michal Bozon <[EMAIL PROTECTED]> wrote:
>> >> On Sun, 07 Oct 2007 06:03:06 -0700, Abandoned wrote:
>> >> > Hi..
>> >> > I find the picture color with:
>> >> > im=Image.open("/%s" %name)
>> >> > color=im.mode   #p=black & beyaz rgb=color L=grey
>>
>> >> > This usually work true but in these pictures:
>> >> >http://malatya.meb.gov.tr/images/alt/ilsis_logo.gif
>> >> >http://malatya.meb.gov.tr/images/meb.gif
>>
>> >> > Say me P (black&white) but these pictures are color..
>>
>> >> > What is the reason of this ?
>>
>> >> > I'm sorry my bad english
>>
>> >> P does mean palette, black&white is a special case of palette, with
>> >> two colors.
>>
>> > How can i understand the picture color ? (black &white or color or
>> > grey)
>>
>> If you know how to work with RGB images, you can convert the image
>> from the palette mode easily:
>>
>> img2 = img.convert(mode='RGB')
>>
>> Anyway, always is helpful to read the tutorial or basic documentation..
>> ;)
>>
>>  MB- Hide quoted text -
>>
>> - Show quoted text -
> 
> no no no this is not professionalism

What professionalism? This isn't a paid support service, you are aware of
that?

> are there anybody who know that

Who knows what? That PIL has e.g. a histogram-function that delivers what
you need (after some thinking, I suggest you try and see at it's output
with various source images)

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


Re: Pil image module, "mode" bug..

2007-10-08 Thread [EMAIL PROTECTED]
On Oct 7, 8:17 pm, Michal Bozon <[EMAIL PROTECTED]> wrote:
> On Sun, 07 Oct 2007 09:02:09 -0700, Abandoned wrote:
> > On Oct 7, 4:47 pm, Michal Bozon <[EMAIL PROTECTED]> wrote:
> >> On Sun, 07 Oct 2007 06:03:06 -0700, Abandoned wrote:
> >> > Hi..
> >> > I find the picture color with:
> >> > im=Image.open("/%s" %name)
> >> > color=im.mode   #p=black & beyaz rgb=color L=grey
>
> >> > This usually work true but in these pictures:
> >> >http://malatya.meb.gov.tr/images/alt/ilsis_logo.gif
> >> >http://malatya.meb.gov.tr/images/meb.gif
>
> >> > Say me P (black&white) but these pictures are color..
>
> >> > What is the reason of this ?
>
> >> > I'm sorry my bad english
>
> >> P does mean palette, black&white is a special case of palette, with two
> >> colors.
>
> > How can i understand the picture color ? (black &white or color or
> > grey)
>
> If you know how to work with RGB images, you can convert the image
> from the palette mode easily:
>
> img2 = img.convert(mode='RGB')
>
> Anyway, always is helpful to read the tutorial or basic documentation.. ;)
>
>  MB- Hide quoted text -
>
> - Show quoted text -

no no no this is not professionalism
are there anybody who know that

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


  1   2   >