None in comparison

2008-07-17 Thread r . grimm
Hello,
I'm a little confused about None in comparison.

>>> id ( None )
3086100672L
>>> id ( 1 )
134541104
>>> None < 1
True
>>>

I thought, the id of the object is the last comparison criterion.
Therefore, None must be greater then 1.
Where is the behaviour of the comparison defined?. In the __cmp__ of
int. Or in the global cmp Function?

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


Re: How to process a very large (4Gb) tarfile from python?

2008-07-17 Thread Uwe Schmitt
On 17 Jul., 22:21, Lars Gustäbel <[EMAIL PROTECTED]> wrote:
>
> > Maybe we should post this issue to python-dev mailing list.
> > Parsing large tar-files is not uncommon.
>
> This issue is known and was fixed for Python 3.0, 
> seehttp://bugs.python.org/issue2058.

The proposed patch does not avoid caching the previous values of the
iterator, it just
reduces the size of each cached object.
It would be nice to be able to avoid caching on demand, which would
make
iteration independent of the size of the tar file.

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


Re: storing references instead of copies in a dictionary

2008-07-17 Thread John Machin
On Jul 18, 4:26 pm, castironpi <[EMAIL PROTECTED]> wrote:
> I delicately ask for an example in natural language and daily life in
> which we change what object a name refers to,

her, him, it, ... i.e. any pronoun
--
http://mail.python.org/mailman/listinfo/python-list


Re: interpreter vs. compiled

2008-07-17 Thread castironpi
On Jul 17, 11:39 pm, Kay Schluehr <[EMAIL PROTECTED]> wrote:
> On 18 Jul., 01:15, castironpi <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Jul 17, 5:37 pm, I V <[EMAIL PROTECTED]> wrote:
>
> > > On Thu, 17 Jul 2008 15:08:17 -0700, castironpi wrote:
> > > > The Python disassembly is baffling though.
>
> > >  y= 3
> > >  dis.dis('x=y+1')
>
> > > You can't disassemble strings of python source (well, you can, but, as
> > > you've seen, the results are not meaningful). You need to compile the
> > > source first:
>
> > > >>> code = compile('y=x+1','-', 'single')
> > > >>> dis.dis(code)
>
> > >   1           0 LOAD_NAME                0 (x)
> > >               3 LOAD_CONST               0 (1)
> > >               6 BINARY_ADD
> > >               7 STORE_NAME               1 (y)
> > >              10 LOAD_CONST               1 (None)
> > >              13 RETURN_VALUE
>
> > > You may well find these byte codes more meaningful. Note that there is a
> > > list of opcodes athttp://docs.python.org/lib/bytecodes.html
>
> > Oh.  How is the stack represented?
>
> As a pointer to a pointer of PyObject structs.
>
> > Does it keep track of which stack
> > positions (TOS, TOS1, etc.) are in what registers?  Does stack
> > manipulation consume processor cycles?
>
> Python does not store values in registers. It stores locals in arrays
> and accesses them by position ( you can see the positional index in
> the disassembly right after the opcode name ) and globals / object
> attributes in dicts.
>
> For more information you might just download the source distribution
> and look for src/Python/ceval.c. This file contains the main
> interpreter loop.

Oh.  I was interpreting, no pun, that the column of numbers to the
left indicated how many processor cycles were consumed in each
operation.  It doesn't quite make sense, unless BINARY_ADD can refer
to memory outside of the registers, which I doubt on the basis that
two addresses would have to fit into a single operation, plus the
architecture opcode.  Given that, what does that column indicate?

I'm intimidated by the source but I may look.
--
http://mail.python.org/mailman/listinfo/python-list


Re: storing references instead of copies in a dictionary

2008-07-17 Thread castironpi
On Jul 17, 7:36 pm, bgeddy <[EMAIL PROTECTED]> wrote:
> bgeddy wrote:
> > castironpi wrote:
> >> On Jul 17, 10:05 am, mk <[EMAIL PROTECTED]> wrote:
>  def f2(arg):
>      return "f2 "+arg
>  def f1(arg):
>      return "f1 "+arg
>  a={"1":"f1","2":"f2"}
>  print [eval(x[1])(x[0]) for x in a.items()]
>  def f2(arg):
>      return "New f2 "+arg
>  print [eval(x[1])(x[0]) for x in a.items()]
> >>> Neat trick, if probably dangerous in some circumstances. Anyway, thanks,
> >>> I didn't think of that.
>
>  Don't know if this is any use to you..
> >>> At least I learned something. :-)
>
> >> You want consistent access to a changing variable.  Wrap it in an
> >> object:
>
> > a= Blank( )
> > a.ref= 'X'
> > a.ref
> >> 'X'
> > b= a
> > b.ref
> >> 'X'
> > a.ref= 'Y'
> > b.ref
> >> 'Y'
>
> > My "old fashioned" programing paradigms think of this in terms of
> > "pointers", a throw back to my schooling in 'C'. I find this general
> > form of problem to be common across languages and in some ways hard to
> > express in python. The whole idea of labels bound to objects is quite
> > alien to traditional terminology. I find one of the main attractions of
> > python is this new mindset that the language makes you adopt - a
> > different set of tools are at hand for the old school programmer.
>
> > castironpi - please give an example of what you are thinking as I find
> > this interesting. preferably post some brief example code.
>
> castironpi  - please forgive the double post but my newsreader didn't
> display your code correctly.. Doh !! Anyway - a nice way of addressing
> the problem. However the OP's post revolved around having a rewritable
> set of "labels" - which could be recorded at one time and when re
> referenced the new definitions of those labels would be used. For
> example a "collection" (list,dictionary,tuple) could be made of these
> "labels" and then the underlying code accessed by the labels changed. If
> the code was now ran indirectly by referencing the list then the new
> code would be ran. These building blocks are how parsers are built and
> the basis of language.
> I can see how you form two ways of addressing the variable but can't
> figure how this fits the original problem. Please elaborate for my
> ignorance.
>
> EdH.

In the OP's post, we have:

def f1(): print 'f1'
def f2(): print 'f2'
funs= [ f1, f2 ]
def f1(): print 'new f1'

They wanted funs[ 0 ] to contain this new function / new definition
too.

Another language might permit:
def funs[ 0 ](): print 'new f1'

Python allows:

def f1(): print 'new f1'
funs[ 0 ]= f1

and

@rebind( funs, 0 )
def f1(): print 'new f1'

and

@rebind_named( funs, 'funA' )
def f1(): print 'new f1'

in the case funs was a dictionary or class or class instance.
Functions remain to be first class objects; their definition syntax is
merely restricted over normal assignments.

To access "whatever 'f1' is pointing to right now", the only way is
with eval, which you showed.

Spealman's solution can accomplish redefinition, but only provided
calling signature and closure, among others, don't change.  If they
do, you have to reassign those, too, and possibly more:

>>> dir( f )
[snip]
'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc',
'func_globals', 'func_name'

Roughly the same in 3.0.  It's an option.

> These building blocks are how parsers are built and
> the basis of language.

To address this, I observe altered references are easy for computers.
Suppose:

#--NOT PYTHON--
def f1(): print 'f1'
008902 f1:  0x008934
def f1(): print 'new f1'
008902 f1:  0x008938

'f1()' calls the function the address of which is stored at 008902 in
each case: f1 (at 008934) in the first case, and new f1 (at 008938) in
the second.

Python eliminates that combination from the syntax, which strengthens
object-name identity, at the cost of a slightly longer workaround
(a.ref= f1) for keeping names but changing objects.  In this sense,
the only 'pointer' per se is the string name of an object, scoped by a
namespace-- eval( 'f1', spaceA ).

I delicately ask for an example in natural language and daily life in
which we change what object a name refers to, or hold that Python
conforms to natural language better than computer-native mutable
pointers and references.
--
http://mail.python.org/mailman/listinfo/python-list


Re: % sign in python?

2008-07-17 Thread Tim Roberts
Steven Howe <[EMAIL PROTECTED]> wrote:

>Terry Reedy wrote:
>>
>> korean_dave wrote:
>>> What does this operator do? Specifically in this context
>>>
>>> test.log( "[[Log level %d: %s]]" % ( level, msg ), description )
>
>I thought, in this contexted, it was  mapping operator.

What??

Python does not have a "mapping operator".  It has a "map" function, but no
equivalent operator.

% is either the string formatting operator (when the left-hand operand is a
string) or the modulo operator (when the left-hand operand is a number).
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How can i use a variable without define it ?

2008-07-17 Thread Tim Roberts
zhw <[EMAIL PROTECTED]> wrote:
>Ben Finney <[EMAIL PROTECTED]> >wrote:
>>
>> What problem are you trying to solve?
>
>I an sorry, I can't tell you.

That's nonsense.  No one is asking you to reveal the design of your
company's next product.  However, you have some overall problem you are
trying to solve, and you have focused in on one POSSIBLE solution. Instead,
tell us about the PROBLEM, and we'll offer good solutions.

>If you can't give a solution, just ignore it!

NO ONE will be able to give you a solution, because you have not described
the problem.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list


Re: singletons

2008-07-17 Thread Lawrence D'Oliveiro
In message
<[EMAIL PROTECTED]>, Craig
Allen wrote:

> On Jul 16, 7:01 pm, Lawrence D'Oliveiro <[EMAIL PROTECTED]
> central.gen.new_zealand> wrote:
>>
>> >>> class TehLibrary(object) :
>>
>> ... @classmethod
>> ... def __new__(self, cls) :
>> ... return self
>>
>> >>> s = TehLibrary()
>> >>> s == TehLibrary()
>>
>> True
> 
> That's great, I simply didn't find that when looking. Thanks!

Also note that

s == TehLibrary

will be true (the instance equals the class). I assume that doesn't matter
for your purposes. :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Converting from local -> UTC

2008-07-17 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Gabriel
Genellina wrote:

> Note that I used %s everywhere (it's just a placeholder, not a format) ...

>From /usr/lib64/python2.5/site-packages/MySQLdb/cursors.py, lines 150-151:

   if args is not None:
query = query % db.literal(args)

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


paypal wholesale men jordans 13 (paypal accept)(www goodsaler com

2008-07-17 Thread cheaplv
paypal wholesale men jordans (paypal accept)(www goodsaler com

paypal wholesale men jordans 1 (paypal accept)(www goodsaler com


paypal wholesale men jordans 2 (paypal accept)(www goodsaler com


paypal wholesale men jordans 3 (paypal accept)(www goodsaler com


paypal wholesale men jordans 4 (paypal accept)(www goodsaler com


paypal wholesale men jordans 5 (paypal accept)(www goodsaler com


paypal wholesale men jordans 6 (paypal accept)(www goodsaler com


paypal wholesale men jordans 7 (paypal accept)(www goodsaler com


paypal wholesale men jordans 8 (paypal accept)(www goodsaler com


paypal wholesale men jordans 9 (paypal accept)(www goodsaler com


paypal wholesale men jordans 10 (paypal accept)(www goodsaler com


paypal wholesale men jordans 11 (paypal accept)(www goodsaler com


paypal wholesale men jordans 12 (paypal accept)(www goodsaler com


paypal wholesale men jordans 13 (paypal accept)(www goodsaler com


paypal wholesale men jordans 14 (paypal accept)(www goodsaler com


paypal wholesale men jordans 15 (paypal accept)(www goodsaler com


paypal wholesale men jordans 16 (paypal accept)(www goodsaler com


paypal wholesale men jordans 17 (paypal accept)(www goodsaler com


paypal wholesale men jordans (paypal accept)(www goodsaler com


paypal wholesale men jordans 1 (paypal accept)(www goodsaler com


paypal wholesale men jordans 2 (paypal accept)(www goodsaler com


paypal wholesale men jordans 3 (paypal accept)(www goodsaler com


paypal wholesale men jordans 4 (paypal accept)(www goodsaler com


paypal wholesale men jordans 5 (paypal accept)(www goodsaler com


paypal wholesale men jordans 6 (paypal accept)(www goodsaler com


paypal wholesale men jordans 7 (paypal accept)(www goodsaler com


paypal wholesale men jordans 8 (paypal accept)(www goodsaler com


paypal wholesale men jordans 9 (paypal accept)(www goodsaler com


paypal wholesale men jordans 10 (paypal accept)(www goodsaler com


paypal wholesale men jordans 11 (paypal accept)(www goodsaler com


paypal wholesale men jordans 12 (paypal accept)(www goodsaler com


paypal wholesale men jordans 13 (paypal accept)(www goodsaler com


paypal wholesale men jordans 14 (paypal accept)(www goodsaler com


paypal wholesale men jordans 15 (paypal accept)(www goodsaler com


paypal wholesale men jordans 16 (paypal accept)(www goodsaler com


paypal wholesale men jordans 17 (paypal accept)(www goodsaler com


paypal wholesale men jordans (paypal accept)(www goodsaler com


paypal wholesale men jordans 1 (paypal accept)(www goodsaler com


paypal wholesale men jordans 2 (paypal accept)(www goodsaler com


paypal wholesale men jordans 3 (paypal accept)(www goodsaler com


paypal wholesale men jordans 4 (paypal accept)(www goodsaler com


paypal wholesale men jordans 5 (paypal accept)(www goodsaler com


paypal wholesale men jordans 6 (paypal accept)(www goodsaler com


paypal wholesale men jordans 7 (paypal accept)(www goodsaler com


paypal wholesale men jordans 8 (paypal accept)(www goodsaler com


paypal wholesale men jordans 9 (paypal accept)(www goodsaler com


paypal wholesale men jordans 10 (paypal accept)(www goodsaler com


paypal wholesale men jordans 11 (paypal accept)(www goodsaler com


paypal wholesale men jordans 12 (paypal accept)(www goodsaler com


paypal wholesale men jordans 13 (paypal accept)(www goodsaler com


paypal wholesale men jordans 14 (paypal accept)(www goodsaler com


paypal wholesale men jordans 15 (paypal accept)(www goodsaler com


paypal wholesale men jordans 16 (paypal accept)(www goodsaler com


paypal wholesale men jordans 17 (paypal accept)(www goodsaler com


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


wholesale p u m a sneaker(paypal accept)(www goodsaler com)paypal

2008-07-17 Thread 14789
wholesale p u m a sneaker(paypal accept)(www goodsaler
com)paypal
wholesale p u m a sneaker(paypal accept)(www goodsaler
com)paypal
wholesale p u m a sneaker(paypal accept)(www goodsaler
com)paypal
wholesale p u m a sneaker(paypal accept)(www goodsaler
com)paypal
wholesale p u m a sneaker(paypal accept)(www goodsaler
com)paypal
wholesale p u m a sneaker(paypal accept)(www goodsaler
com)paypal
wholesale p u m a sneaker(paypal accept)(www goodsaler com)paypal
wholesale p u m a sneaker(paypal accept)(www goodsaler
com)paypal
wholesale p u m a sneaker(paypal accept)(www goodsaler
com)paypal
wholesale p u m a sneaker(paypal accept)(www goodsaler
com)paypal
wholesale p u m a sneaker(paypal accept)(www goodsaler
com)paypal
wholesale p u m a sneaker(paypal accept)(www goodsaler
com)paypal
--
http://mail.python.org/mailman/listinfo/python-list


wholesale n i k e sneaker(paypal accept)(www all-wholesaler com)paypal

2008-07-17 Thread 14789
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with MySQLdb and mod_python

2008-07-17 Thread John Nagle

Cyril Bazin wrote:

Thanks for your reply

The apache log contains lines like :

[Tue Jul 15 23:31:01 2008] [notice] mod_python (pid=11836,
interpreter='www.toto.fr'): Importing module
'/usr/local/apache2/htdocs/intranet/courrier/test.py'
[Tue Jul 15 23:31:02 2008] [notice] child pid 11836 exit signal
Segmentation fault (11)
[Tue Jul 15 23:31:19 2008] [notice] mod_python (pid=11764,
interpreter='www.toto.fr'): Importing module
'/usr/local/apache2/htdocs/intranet/courrier/test.py'
[Tue Jul 15 23:31:19 2008] [notice] child pid 11764 exit signal
Segmentation fault (11)

I think the problem comes from the MySQLdb module.
If I can't find another solution, I think I will downgrade the MySQLdb
version to 1.2.1


   Sounds like version hell.  mod_python and MySQLdb have to be
compiled with exactly the same compiler for this to work.

   mod_python is usually troublesome.   Python doesn't really have
quite enough isolation to run multiple unrelated instances reliably.
We use FCGI, which has the isolation of CGI but doesn't reload the
application for every transaction.  Also, it's easier to debug if
CPython is crashing.

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


Re: interpreter vs. compiled

2008-07-17 Thread Kay Schluehr
On 18 Jul., 01:15, castironpi <[EMAIL PROTECTED]> wrote:
> On Jul 17, 5:37 pm, I V <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Thu, 17 Jul 2008 15:08:17 -0700, castironpi wrote:
> > > The Python disassembly is baffling though.
>
> >  y= 3
> >  dis.dis('x=y+1')
>
> > You can't disassemble strings of python source (well, you can, but, as
> > you've seen, the results are not meaningful). You need to compile the
> > source first:
>
> > >>> code = compile('y=x+1','-', 'single')
> > >>> dis.dis(code)
>
> >   1   0 LOAD_NAME0 (x)
> >   3 LOAD_CONST   0 (1)
> >   6 BINARY_ADD
> >   7 STORE_NAME   1 (y)
> >  10 LOAD_CONST   1 (None)
> >  13 RETURN_VALUE
>
> > You may well find these byte codes more meaningful. Note that there is a
> > list of opcodes athttp://docs.python.org/lib/bytecodes.html
>
> Oh.  How is the stack represented?

As a pointer to a pointer of PyObject structs.

> Does it keep track of which stack
> positions (TOS, TOS1, etc.) are in what registers?  Does stack
> manipulation consume processor cycles?

Python does not store values in registers. It stores locals in arrays
and accesses them by position ( you can see the positional index in
the disassembly right after the opcode name ) and globals / object
attributes in dicts.

For more information you might just download the source distribution
and look for src/Python/ceval.c. This file contains the main
interpreter loop.

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


RELEASED Python 2.6b2 and 3.0b2

2008-07-17 Thread Barry Warsaw

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On behalf of the Python development team and the Python community, I  
am happy to announce the second beta releases of Python 2.6 and Python  
3.0.


Please note that these are beta releases, and as such are not suitable  
for production environments.  We continue to strive for a high degree  
of quality, and these releases are intended to freeze the feature set  
for Python 2.6 and 3.0.


From now until the planned final releases in October 2008, we will be  
fixing known problems and stabilizing these new Python versions.  You  
can help by downloading and testing them, providing feedback and  
hopefully helping to fix bugs.  You can also use these releases to  
determine how changes in 2.6 and 3.0 might impact you.


ONLY ONE MORE BETA RELEASE IS PLANNED, so now is a great time to  
download the releases and try them with your code.  If you find things  
broken or incorrect, please submit bug reports at


http://bugs.python.org

For more information and downloadable distributions, see the Python  
2.6 website:


http://www.python.org/download/releases/2.6/

and the Python 3.0 web site:

http://www.python.org/download/releases/3.0/

See PEP 361 for release schedule details:

http://www.python.org/dev/peps/pep-0361/

Enjoy,
- -Barry

Barry Warsaw
[EMAIL PROTECTED]
Python 2.6/3.0 Release Manager
(on behalf of the entire python-dev team)

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (Darwin)

iQCVAwUBSIARKHEjvBPtnXfVAQL7AQQAjPSbfKz2Oh/au/hPzS4x2IR5/R6FVe+g
o9UYrONNRKJ14UHpbZRzvIvw/4G3PdpzzGxjYFIhVGEesEGJnMzT3YdkMHt4NW9d
HOZxL3hseGbTdpUJPCsIkNG+4hX7iuY3NSV81Z75LGAL4tqbooGqwwUslXMT5f8s
lRrZUcBRKZ0=
=ju6s
-END PGP SIGNATURE-
--
http://mail.python.org/mailman/listinfo/python-list


Re: storing references instead of copies in a dictionary

2008-07-17 Thread John Machin
On Jul 18, 10:36 am, bgeddy <[EMAIL PROTECTED]> wrote:
[snip]
> the OP's post revolved around having a rewritable
> set of "labels" - which could be recorded at one time and when re
> referenced the new definitions of those labels would be used. For
> example a "collection" (list,dictionary,tuple) could be made of these
> "labels" and then the underlying code accessed by the labels changed. If
> the code was now ran indirectly by referencing the list then the new
> code would be ran.

This notion is as dangerous and ludicrous as the COBOL ALTER verb.

> These building blocks are how parsers are built and
> the basis of language.

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


Re: interpreter vs. compiled

2008-07-17 Thread Terry Reedy



castironpi wrote:

On Jul 17, 5:37 pm, I V <[EMAIL PROTECTED]> wrote:


Oh.  How is the stack represented?


As usual, as successive locations in memory.
I have the impression that CPython uses the same stack C does.
While conceptually, CPython may put objects on the stack, I am pretty 
sure it actually stacks references (C pointers) to objects in heap memory.


> Does it keep track of which stack

positions (TOS, TOS1, etc.) are in what registers?


I am sure they are not in registers, just normal memory.
The C code that implements bytecodes to act on stack values will use 
registers just like any other C code.  So using registers for the stack 
would get in the way.  Of course, the C code might load pointers on the 
stack into address registers when actually needed.  But this depends on 
the address scheme of a particular processor and how the C code is 
compiled to its object code.



Does stack manipulation consume processor cycles?


Of course.  For much more, you should peruse the CPython source.

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


Re: storing references instead of copies in a dictionary

2008-07-17 Thread bgeddy

bgeddy wrote:

castironpi wrote:

On Jul 17, 10:05 am, mk <[EMAIL PROTECTED]> wrote:

def f2(arg):
return "f2 "+arg
def f1(arg):
return "f1 "+arg
a={"1":"f1","2":"f2"}
print [eval(x[1])(x[0]) for x in a.items()]
def f2(arg):
return "New f2 "+arg
print [eval(x[1])(x[0]) for x in a.items()]

Neat trick, if probably dangerous in some circumstances. Anyway, thanks,
I didn't think of that.


Don't know if this is any use to you..

At least I learned something. :-)


You want consistent access to a changing variable.  Wrap it in an
object:


a= Blank( )
a.ref= 'X'
a.ref

'X'

b= a
b.ref

'X'

a.ref= 'Y'
b.ref

'Y'

My "old fashioned" programing paradigms think of this in terms of 
"pointers", a throw back to my schooling in 'C'. I find this general 
form of problem to be common across languages and in some ways hard to 
express in python. The whole idea of labels bound to objects is quite 
alien to traditional terminology. I find one of the main attractions of 
python is this new mindset that the language makes you adopt - a 
different set of tools are at hand for the old school programmer.


castironpi - please give an example of what you are thinking as I find 
this interesting. preferably post some brief example code.


castironpi  - please forgive the double post but my newsreader didn't 
display your code correctly.. Doh !! Anyway - a nice way of addressing 
the problem. However the OP's post revolved around having a rewritable 
set of "labels" - which could be recorded at one time and when re 
referenced the new definitions of those labels would be used. For 
example a "collection" (list,dictionary,tuple) could be made of these 
"labels" and then the underlying code accessed by the labels changed. If 
the code was now ran indirectly by referencing the list then the new 
code would be ran. These building blocks are how parsers are built and 
the basis of language.
I can see how you form two ways of addressing the variable but can't 
figure how this fits the original problem. Please elaborate for my 
ignorance.


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


Re: storing references instead of copies in a dictionary

2008-07-17 Thread bgeddy

castironpi wrote:

On Jul 17, 10:05 am, mk <[EMAIL PROTECTED]> wrote:

def f2(arg):
return "f2 "+arg
def f1(arg):
return "f1 "+arg
a={"1":"f1","2":"f2"}
print [eval(x[1])(x[0]) for x in a.items()]
def f2(arg):
return "New f2 "+arg
print [eval(x[1])(x[0]) for x in a.items()]

Neat trick, if probably dangerous in some circumstances. Anyway, thanks,
I didn't think of that.


Don't know if this is any use to you..

At least I learned something. :-)


You want consistent access to a changing variable.  Wrap it in an
object:


a= Blank( )
a.ref= 'X'
a.ref

'X'

b= a
b.ref

'X'

a.ref= 'Y'
b.ref

'Y'

My "old fashioned" programing paradigms think of this in terms of 
"pointers", a throw back to my schooling in 'C'. I find this general 
form of problem to be common across languages and in some ways hard to 
express in python. The whole idea of labels bound to objects is quite 
alien to traditional terminology. I find one of the main attractions of 
python is this new mindset that the language makes you adopt - a 
different set of tools are at hand for the old school programmer.


castironpi - please give an example of what you are thinking as I find 
this interesting. preferably post some brief example code.

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


Re: Pickle and wx.TextCtrl

2008-07-17 Thread Gabriel Genellina

En Thu, 17 Jul 2008 09:40:29 -0300, <[EMAIL PROTECTED]> escribi�:


The way you read the file is rather strange -mixing calls to readline and
pickle.load- I'd write the data using pickle.dump calls *only* and then
read it using pickle.load calls *only*.

I used 13.1.7 Example of the Python Library Referencebut.  Got an error
message when I did not have the readline() statement.


The example doesn't have any readline(). Make sure you open the file in  
binary format ('wb' or 'rb').
If you have a list of objects: just write the list. It takes a single call  
to pickle.dump(), and later, a single call to picle.load()
If you have too many objects and don't want to save/load all of them at  
once, write them one at a time using pickle.dump(element, output_file,  
-1), ending with a sentinel value (e.g. None): pickle.dump(None, ...)

You may read them again using something like this:

pfile = open(..., 'rb')
while True:
  element = pickle.load(pfile)
  if element is None: break
  do_something_with(element)
pfile.close()

Ensure that you can save and load your data using a simple script,  
*before* writing the GUI.


--
Gabriel Genellina

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

Re: x, = y (???)

2008-07-17 Thread alex23
On Jul 18, 8:01 am, DaveM <[EMAIL PROTECTED]> wrote:
> On Thu, 17 Jul 2008 17:32:30 -0400, Terry Reedy <[EMAIL PROTECTED]> wrote:
> > >>> *x, = [3]
> > >>> x
> >[3]
>
> What does *x signify?

Mostly that Terry is using Python 3.0.

See: http://www.python.org/dev/peps/pep-3132/

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


Re: Converting from local -> UTC

2008-07-17 Thread Gabriel Genellina
En Wed, 16 Jul 2008 15:00:50 -0300, Keith Hughitt  
<[EMAIL PROTECTED]> escribi�:



Thanks Gabriel!

That helps clear things up for me. The above method works very well. I
only have one remaining question:
How can I pass a datetime object to MySQL?'

So far, what I've been doing is building the query as a string, for
example:

query = "INSERT INTO image VALUES(%d, %d, %s, '%s')" % (id, meas,
date, 'jpg')
cursor.execute(query)


That's not a good idea, in general (among other problems: what if any text  
contains a quote? ever heard of "sql injection"?). Use this form instead:


query = "INSERT INTO image VALUES(%s, %s, %s, %s)"
cursor.execute(query, (id, meas, date, 'jpg'))

Note that I used %s everywhere (it's just a placeholder, not a format) and  
the execute method receives two arguments, the second being a tuple  
containing the desired values.


--
Gabriel Genellina

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

Re: interpreter vs. compiled

2008-07-17 Thread castironpi
On Jul 17, 5:37 pm, I V <[EMAIL PROTECTED]> wrote:
> On Thu, 17 Jul 2008 15:08:17 -0700, castironpi wrote:
> > The Python disassembly is baffling though.
>
>  y= 3
>  dis.dis('x=y+1')
>
> You can't disassemble strings of python source (well, you can, but, as
> you've seen, the results are not meaningful). You need to compile the
> source first:
>
> >>> code = compile('y=x+1','-', 'single')
> >>> dis.dis(code)
>
>   1           0 LOAD_NAME                0 (x)
>               3 LOAD_CONST               0 (1)
>               6 BINARY_ADD          
>               7 STORE_NAME               1 (y)
>              10 LOAD_CONST               1 (None)
>              13 RETURN_VALUE
>
> You may well find these byte codes more meaningful. Note that there is a
> list of opcodes athttp://docs.python.org/lib/bytecodes.html

Oh.  How is the stack represented?  Does it keep track of which stack
positions (TOS, TOS1, etc.) are in what registers?  Does stack
manipulation consume processor cycles?  Here is what I'm thinking:

LOAD_NAME: stack= [ x ]
reg0: x
tos: reg0
LOAD_CONST: stack= [ 1, x ]
reg0: x
reg1: 1
tos: reg1
BINARY_ADD: stack= [ x+ 1, x ]
reg0: x
reg1: x+ 1
tos: reg1
STORE_NAME: y= [ x+ 1], stack= same
reg0: x
reg1: x+ 1
tos: reg1

I may be totally off.
--
http://mail.python.org/mailman/listinfo/python-list


Importing different versions of a module

2008-07-17 Thread mercado mercado
I have two versions of a script on my machine. One version is for new
development and the other version is a production version.  This script
imports a module from a different directory, and this module again has two
versions (a development version and a production version).  What I want is
for the development script to import the development module, and the
production script to import the production module, without making any
changes to the code in the script.

For example, suppose the development script is in ~/dev/rss.py, and the
production script is in ~/prod/rss.py.  I want the dev version to import
/usr/lib/python2.5/site-packages/lib_dev/parse.py, and the prod version to
import usr/lib/python2.5/site-packages/lib_prod/parse.py.

My first instinct was to place a .pth file in ~/dev that points to
/usr/lib/python2.5/site-packages/lib_dev, and a .pth file in ~/prod that
points to /usr/lib/python2.5/site-packages/lib_prod, but it seems that
site.py doesn't look at .pth files in the current working directory.  My
next attempt was to create a symbolic link in ~/dev called parse.py,
pointing to /usr/lib/python2.5/site-packages/lib_dev/parse.py, and a
symbolic link in ~/prod called parse.py, pointing to
/usr/lib/python2.5/site-packages/lib_prod/parse.py, but that didn't work
either.

Can anybody suggest a way to achieve my goal?  Thanks in advance.
--
http://mail.python.org/mailman/listinfo/python-list

Re: interpreter vs. compiled

2008-07-17 Thread I V
On Thu, 17 Jul 2008 15:08:17 -0700, castironpi wrote:
> The Python disassembly is baffling though.
> 
 y= 3
 dis.dis('x=y+1')

You can't disassemble strings of python source (well, you can, but, as 
you've seen, the results are not meaningful). You need to compile the 
source first:

>>> code = compile('y=x+1','-', 'single')
>>> dis.dis(code)
  1   0 LOAD_NAME0 (x)
  3 LOAD_CONST   0 (1)
  6 BINARY_ADD  
  7 STORE_NAME   1 (y)
 10 LOAD_CONST   1 (None)
 13 RETURN_VALUE

You may well find these byte codes more meaningful. Note that there is a 
list of opcodes at http://docs.python.org/lib/bytecodes.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: singletons

2008-07-17 Thread Craig Allen
On Jul 17, 2:15 am, Uwe Schmitt <[EMAIL PROTECTED]>
wrote:
> On 17 Jul., 00:20, Craig Allen <[EMAIL PROTECTED]> wrote:
>
>
>
> > I have several classes in our system which need to act like
> > singletons, they are libraries of data classifications, and other such
> > libraries of configurations for the system which need to be global.
> > ...
>
> > Is it pythonic?
>
> My approach in this situation is to use the Borg pattern instead
> of singeltons. This is really pythonic, very simple and usefull.
>
> Look athttp://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531
> The german wikipedia shows another solution using 
> metaclasse:http://de.wikipedia.org/wiki/Singleton_(Entwurfsmuster)#Das_Borg-Pattern
>
> Greetings, Uwe

thanks uwe, doing some searching I ran into the borg pattern this
morning. Definitely relevant.

Thanks again and all for the feedback, I feel much reassured about the
options when this sort of thing is required.
--
http://mail.python.org/mailman/listinfo/python-list


Re: % sign in python?

2008-07-17 Thread Jordan
On Jul 17, 3:42 pm, Terry Reedy <[EMAIL PROTECTED]> wrote:
> korean_dave wrote:
> > What does this operator do? Specifically in this context
>
> > test.log( "[[Log level %d: %s]]" % ( level, msg ), description )
>
> > (Tried googling and searching, but the "%" gets interpreted as an
> > operation and distorts the search results)
>
> Having seen a number of comments like this over the years (about the
> difficulty of searching for symbol meanings), I just started, last
> night, a symbol index listing nearly all Python syntax uses of
> non-alpha-or-digit ascii symbols.  When I finish and upload it
> somewhere, I will post an announcement with the link.
>
> tjr

That sounds great Terry!  I look forward to seeing this.

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


Re: Using Tcl extensions with Python?

2008-07-17 Thread Guilherme Polo
On Thu, Jul 17, 2008 at 6:48 PM, C Martin <[EMAIL PROTECTED]> wrote:
> How do you setup a Tcl extension to be accessible through Python? I
> understand that I'll have to use native Tcl calls to use it (tk.call()
> etc), but I can't figure out where to put the files or how to
> initialize them so I can call them.
>
> The package I would like to use is TkPNG: 
> http://www.muonics.com/FreeStuff/TkPNG/
>

You can put them anywhere, but if it is on tcl's auto_path then you
just need a call to "package require tkpng". To check what directories
are part of auto_path, start tclsh and enter "set auto_path".

Follows a sample code to demonstrate how to load the required package:

import Tkinter

root = Tkinter.Tk()
tkpnglib = "/usr/lib/tkpng0.9"
root.tk.eval("""
global auto_path
lappend auto_path {%s}""" % tkpnglib)

root.tk.eval("package require tkpng")

If tkpng were installed in some directory belonging to auto_path, then
you wouldn't need that call to tk.eval.

And.. for tkpng specifically, you won't need tk.call to use it, you
just need to create your images using Tkinter.PhotoImage with a "png"
type.

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



-- 
-- Guilherme H. Polo Goncalves
--
http://mail.python.org/mailman/listinfo/python-list


interpreter vs. compiled

2008-07-17 Thread castironpi
I'm curious about some of the details of the internals of the Python
interpreter:

I understand C from a hardware perspective.

x= y+ 1;

Move value from place y into a register
Add 1 to the value in the register
Move the addition's result to place x

The Python disassembly is baffling though.

>>> y= 3
>>> dis.dis('x=y+1')
  0 SETUP_LOOP  31037 (to 31040)
  3 STORE_SLICE+3
  4 <49>

What are SETUP_LOOP and STORE_SLICE?  What are these instructions?
--
http://mail.python.org/mailman/listinfo/python-list


Re: x, = y (???)

2008-07-17 Thread DaveM
On Thu, 17 Jul 2008 17:32:30 -0400, Terry Reedy <[EMAIL PROTECTED]> wrote:


> >>> *x, = [3]
> >>> x
>[3]

What does *x signify?

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


Re: Converting from local -> UTC

2008-07-17 Thread M.-A. Lemburg

On 2008-07-17 22:43, Dennis Lee Bieber wrote:

On Thu, 17 Jul 2008 19:55:44 +0200, "M.-A. Lemburg" <[EMAIL PROTECTED]>
declaimed the following in comp.lang.python:



Use binding parameters and it should work:

query = "INSERT INTO image VALUES(%d, %d, %s, '%s')"


If this is MySQLdb interface:

query = "INSERT INTO image VALUES(%s, %s, %s, '%s')"

... only %s is valid; all values have been converted to escaped/quoted
string before getting to the substitution.


Right. I forgot to replace the %d's with %s's. The line should read:

query = "INSERT INTO image VALUES(%s, %s, %s, %s)"

--
Marc-Andre Lemburg
eGenix.com

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


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


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


Re: Babelfish translation ...

2008-07-17 Thread Stef Mientki

thanks Stefan,

both lxml and threading works perfect.
One small problem, "with_tail" was not recognized as a valid keyword.

cheers,
Stef

Stefan Behnel wrote:

Stef Mientki  gmail.com> writes:
  

Although it works functionally,
it can take lots of time waiting for the translation.

What I basically do is, after selecting a new string to be translated:

kwds = { 'trtext' : line_to_be_translated, 'lp' :'en_nl'}
soup = BeautifulSoup (urlopen(url, urlencode ( kwds ) ) )
translation= soup.find ( 'div', style='padding:0.6em;' ).string
self.Editor_Babel.SetLabel ( translation )



You should give lxml.html a try.

http://codespeak.net/lxml/

It can parse directly from HTTP URLs (no need to go through urlopen), and it 
frees the GIL while parsing, so it will become efficient to create a little 
Thread that doesn't do more than parsing the web site, as in (untested):


  def read_bablefish(text, lang, result):
  url = BABLEFISH_URL + '?' + urlencode({'trtext':text, 'lp':lang})
  page = lxml.html.parse(url)
  for div in page.iter('div'):
   style = div.get('style')
   if style is not None and 'padding:0.6em;' in style:
   result.append(
  lxml.html.tostring(div, method="text", with_tail=False))

  result = []
  thread = threading.Thread(target=read_bablefish,
args=("...", "en_nl", result))
  thread.start()
  while thread.isAlive():
  # ... do other stuff
  if result:
  print result[0]

Stefan


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


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


Using Tcl extensions with Python?

2008-07-17 Thread C Martin
How do you setup a Tcl extension to be accessible through Python? I
understand that I'll have to use native Tcl calls to use it (tk.call()
etc), but I can't figure out where to put the files or how to
initialize them so I can call them.

The package I would like to use is TkPNG: 
http://www.muonics.com/FreeStuff/TkPNG/

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


Re: x, = y (???)

2008-07-17 Thread Terry Reedy



kj wrote:



I just came across an assignment of the form

  x, = y

where y is a string (in case it matters).

1. What's the meaning of the comma in the LHS of the assignment?
2. How could I have found this out on my own?


1.Experiment with the interactive interpreter.  It is sooo easy.

>>> x, = '1'
>>> x
'1'
>>> x, = '12'
Traceback (most recent call last):
  File "", line 1, in 
x, = '12'
ValueError: too many values to unpack
>>> x,y = '12'
>>> x,y
('1', '2')
>>> x, = 3
Traceback (most recent call last):
  File "", line 1, in 
x, = 3
TypeError: 'int' object is not iterable
>>> *x, = [3]
>>> x
[3]

2. Read the Python docs which come with the interpreter.
LanguageReference/SimpleStatements/AssignmentStatements:
"If the target list is a comma-separated list of targets:
...
Else: The object must be a sequence with the same number of items as 
there are targets in the target list, and the items are assigned, from 
left to right, to the corresponding targets."

which is exactly the behavior observed above.

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


Re: unpacking with default values

2008-07-17 Thread Terry Reedy



McA wrote:


Do you know the "protocol" used by python while unpacking?
Is it a direct assingnment? Or iterating?


In CPython, at least, both, just as with normal unpack and multiple 
assignment.  The iterable is unpacked into pieces by iterating (with 
knowledge of the number of targets and which is the catchall).  The 
targets are then directly bound.


>>> from dis import dis
# first standard assignment
>>> dis(compile("a,b,c = range(3)", '','single'))
  1   0 LOAD_NAME0 (range)
  3 LOAD_CONST   0 (3)
  6 CALL_FUNCTION1
  9 UNPACK_SEQUENCE  3
 12 STORE_NAME   1 (a)
 15 STORE_NAME   2 (b)
 18 STORE_NAME   3 (c)
 21 LOAD_CONST   1 (None)
 24 RETURN_VALUE
# now starred assignment
>>> dis(compile("a,b,*c = range(3)", '','single'))
  1   0 LOAD_NAME0 (range)
  3 LOAD_CONST   0 (3)
  6 CALL_FUNCTION1
  9 UNPACK_EX2
 12 STORE_NAME   1 (a)
 15 STORE_NAME   2 (b)
 18 STORE_NAME   3 (c)
 21 LOAD_CONST   1 (None)
 24 RETURN_VALUE

The only difference is UNPACK_EX (tended) instead of UNPACK_SEQUENCE.
Tne UNPACK_EX code is not yet in the dis module documentation.
But a little reverse engineering reveals the parameter meaning:
a,*b,c and *a,b,c give parameters 257 and 512 instead of 2.
Separating 2,257,512 into bytes gives 0,2; 1,1; 2,0.
a,*b and *a,b give 1, 256 or 0,1; 1,0.  The two bytes
are the number of targets after and before the starred target.

Terry Jan Reedy


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


Re: How to process a very large (4Gb) tarfile from python?

2008-07-17 Thread Lars Gustäbel
On Thu, Jul 17, 2008 at 10:39:23AM -0700, Uwe Schmitt wrote:
> On 17 Jul., 17:55, Terry Carroll <[EMAIL PROTECTED]> wrote:
> > On Thu, 17 Jul 2008 06:14:45 -0700 (PDT), Uwe Schmitt
> >
> > <[EMAIL PROTECTED]> wrote:
> > >I had a look at tarfile.py in my current Python 2.5 installations
> > >lib path. The iterator caches TarInfo objects in a list
> > >tf.members . If you only want to iterate and you  are not interested
> > >in more functionallity, you could use "tf.members=[]" inside
> > >your loop. This is a dirty hack !
> >
> > Thanks, Uwe.  That works fine for me.  It now reads through all 2.5
> > million members, in about 30 minutes, never going above a 4M working
> > set.
> 
> Maybe we should post this issue to python-dev mailing list.
> Parsing large tar-files is not uncommon.

This issue is known and was fixed for Python 3.0, see
http://bugs.python.org/issue2058.

-- 
Lars Gustäbel
[EMAIL PROTECTED]

Es genügt nicht nur, keine Gedanken zu haben,
man muß auch unfähig sein, sie auszudrücken.
(anonym)
--
http://mail.python.org/mailman/listinfo/python-list


Re: x, = y (???)

2008-07-17 Thread Duncan Booth
kj <[EMAIL PROTECTED]> wrote:

> I still don't get it.  If we write 
> 
>   y  = 'Y'
>   x, = y
> 
> what's the difference now between x and y?  And if there's no
> difference, what's the point of performing such "unpacking"?

None whatsoever when the string has only one character, but with 2 
characters it becomes an obfuscated way of checking that there was only one 
character:

>>> x, = 'a'
>>> x, = 'ab'

Traceback (most recent call last):
  File "", line 1, in 
x, = 'ab'
ValueError: too many values to unpack
--
http://mail.python.org/mailman/listinfo/python-list


Re: decorating a method in multiple child classes

2008-07-17 Thread Duncan Booth
[EMAIL PROTECTED] wrote:

> I wish to decorate all of the CX.func() in the same way.  One way to
> do this is to add a decorator to each of the derived classes.  But
> this is tedious and involves modifying multiple files.
> 
> Is there a way to modify the parent class and have the same effect?
> Or some other way neater than the above?
> 

Use a metaclass.

>>> def decorate(f):
print "decorating", f
return f

>>> class meta(type):
def __init__(self, name, bases, dictionary):
if 'func' in dictionary:
dictionary['func'] = decorate(dictionary['func'])
type.__init__(self, name, bases, dictionary)


>>> class P(object):
__metaclass__ = meta


>>> class C1(P):
def func(self): pass


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


Re: x, = y (???)

2008-07-17 Thread Matthew Woodcraft
kj wrote:
> I still don't get it.  If we write 
>
>  y  = 'Y'
>  x, = y
>
> what's the difference now between x and y?  And if there's no
> difference, what's the point of performing such "unpacking"?

If y really is is a string, I think it's likely that the line you came
across was a typo.

In the case you give above, there's no difference at the end between x
and y.

If y had length other than 1, the second line would raise an exception,
so it's not the same as plain "x = y". But if that's the intended effect,
it's a daft way to write it.

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


XML Parsing: Expat Error

2008-07-17 Thread Gerth, William D
Hey all, I'm simply trying to get my feet wet with XML parsing, and I
tried to just do something simple with ElementTree, just throw the XML
tags from a file into a list.  The code is as follows (and may be
wrong):

 

import glob

import xml.etree.ElementTree as ET

 

tree = ET.parse('nameofFilehere').getroot()

list = []

for branch in tree:

this = {}

for child in branch.getchildren():

this[child.tag] = child.text

list.append(this)

 

Every time I run the program, I get this error:

 

Traceback (most recent call last):

  File "nameofFilehere", line 4, in 

coords = ET.parse('nameofFilehere').getroot()

  File "C:\Program Files\Python25\Lib\xml\etree\ElementTree.py", line
862, in parse

tree.parse(source, parser)

  File "C:\Program Files\Python25\Lib\xml\etree\ElementTree.py", line
587, in parse

self._root = parser.close()

  File "C:\Program Files\Python25\Lib\xml\etree\ElementTree.py", line
1254, in close

self._parser.Parse("", 1) # end of data

xml.parsers.expat.ExpatError: no element found: line 3, column 0

 

What can I do to fix this, if anything?  My overall goal has been to
simply get the text of the XML document into a text file, but even that
has failed (I get naught but gibberish), so any help would be
appreciated.

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

Re: % sign in python?

2008-07-17 Thread Steven Howe

Terry Reedy wrote:



korean_dave wrote:

What does this operator do? Specifically in this context

test.log( "[[Log level %d: %s]]" % ( level, msg ), description )

(Tried googling and searching, but the "%" gets interpreted as an
operation and distorts the search results)


Having seen a number of comments like this over the years (about the 
difficulty of searching for symbol meanings), I just started, last 
night, a symbol index listing nearly all Python syntax uses of 
non-alpha-or-digit ascii symbols.  When I finish and upload it 
somewhere, I will post an announcement with the link.


tjr

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


I thought, in this contexted, it was  mapping operator.
sph
--
http://mail.python.org/mailman/listinfo/python-list


Re: x, = y (???)

2008-07-17 Thread Jonathan Gardner
On Jul 17, 12:55 pm, kj <[EMAIL PROTECTED]> wrote:
> what's the point of performing such "unpacking"?

record = [name, address, telephone]

...

name, address, telephone = record
--
http://mail.python.org/mailman/listinfo/python-list


Re: x, = y (???)

2008-07-17 Thread Jonathan Gardner
On Jul 17, 12:55 pm, kj <[EMAIL PROTECTED]> wrote:
> I still don't get it.  If we write
>
>   y  = 'Y'
>   x, = y
>
> what's the difference now between x and y?  And if there's no
> difference, what's the point of performing such "unpacking"?
>

Try:

  y = "abc"
  x, = y

You were unpacking y into ('Y',)
--
http://mail.python.org/mailman/listinfo/python-list


Re: x, = y (???)

2008-07-17 Thread Chris Mellon
On Thu, Jul 17, 2008 at 2:55 PM, kj <[EMAIL PROTECTED]> wrote:
> In <[EMAIL PROTECTED]> Erik Max Francis <[EMAIL PROTECTED]> writes:
>
>>kj wrote:
>
>>> I just came across an assignment of the form
>>>
>>>   x, = y
>>>
>>> where y is a string (in case it matters).
>>>
>>> 1. What's the meaning of the comma in the LHS of the assignment?
>
>>It's unpacking a 1-tuple:
>
>>   (x,) = y
>
>>The parentheses here are not necessary and are sometimes left out.
>
> I still don't get it.  If we write
>
>  y  = 'Y'
>  x, = y
>
> what's the difference now between x and y?  And if there's no
> difference, what's the point of performing such "unpacking"?
>
> TIA!

>>> y = (1,)
>>> y
(1,)
>>> x, = y
>>> x
1
>>>
--
http://mail.python.org/mailman/listinfo/python-list


decorating a method in multiple child classes

2008-07-17 Thread 1x7y2z9

Say, we have a (parent) class P.
It has N child classes C1(P), C2(P) ... CN(P)

Each of the child classes defines (differently) a method func().

I wish to decorate all of the CX.func() in the same way.  One way to
do this is to add a decorator to each of the derived classes.  But
this is tedious and involves modifying multiple files.

Is there a way to modify the parent class and have the same effect?
Or some other way neater than the above?

Thanks.



visual:
class P(object):
   ...

class C1(P):
def func(self, ...):
...

class C2(P):
def func(self, ...):
...
--
http://mail.python.org/mailman/listinfo/python-list


Re: x, = y (???)

2008-07-17 Thread kj
In <[EMAIL PROTECTED]> Erik Max Francis <[EMAIL PROTECTED]> writes:

>kj wrote:

>> I just came across an assignment of the form
>> 
>>   x, = y
>> 
>> where y is a string (in case it matters).
>> 
>> 1. What's the meaning of the comma in the LHS of the assignment?

>It's unpacking a 1-tuple:

>   (x,) = y

>The parentheses here are not necessary and are sometimes left out.

I still don't get it.  If we write 

  y  = 'Y'
  x, = y

what's the difference now between x and y?  And if there's no
difference, what's the point of performing such "unpacking"?

TIA!

kynn


-- 
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
--
http://mail.python.org/mailman/listinfo/python-list


RE: properly delete item during "for item in..."

2008-07-17 Thread Reedick, Andrew


> -Original Message-
> From: [EMAIL PROTECTED] [mailto:python-
> [EMAIL PROTECTED] On Behalf Of Ratko
> Sent: Thursday, July 17, 2008 12:27 PM
> To: python-list@python.org
> Subject: properly delete item during "for item in..."
> 
> Say you have something like this:
> 
> for item in myList:
>del item
> 
> Would this actually delete the item from the list or just decrement
> the reference counter because the item in myList is not associated
> with name "item" anymore (but still is with myList[itemIndex])? In
> other words, is "item" a temporary reference to myList[itemIndex] or
> is it actually that reference that myList has stored?
> 
> I am not sure if this question even makes any sense anymore. I've been
> using python for years and never had any problems (and I don't now
> either) but now that I had to revisit c++/STL, I had to deal about
> these issues and was wondering how python does it.
> 


Walk the list backwards when deleting.



master = ['a', 'b', 'c', 'd', 'e', 'f', 'g']


print "Deletes nothing"
a = master[:]
print a
for i in a:
del i
print a

print
print

print "Deletes safely from end"
a = master[:]
print a
for i in range(len(a)-1, -1, -1):
print i
if i % 2 == 0:
print "removing ", master[i]
del a[i]
print "", a,
if master[i] in a:
print "Ooops, deleted wrong thing...",
print
print a

print
print

print "Delete from front.  Deletes wrong things and throws an
exception..."
a = master[:]
print a
#for i in range(len(a)-1, -1, -1):
for i in range(len(a)):
print i
if i % 2 == 0:
print "removing ", master[i]
del a[i]
print "", a,
if master[i] in a:
print "Ooops, deleted wrong thing...",
print
print a


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


Re: % sign in python?

2008-07-17 Thread Terry Reedy



korean_dave wrote:

What does this operator do? Specifically in this context

test.log( "[[Log level %d: %s]]" % ( level, msg ), description )

(Tried googling and searching, but the "%" gets interpreted as an
operation and distorts the search results)


Having seen a number of comments like this over the years (about the 
difficulty of searching for symbol meanings), I just started, last 
night, a symbol index listing nearly all Python syntax uses of 
non-alpha-or-digit ascii symbols.  When I finish and upload it 
somewhere, I will post an announcement with the link.


tjr

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


Re: properly delete item during "for item in..."

2008-07-17 Thread Ratko
> > For dictionaries we can just iterate over values() or items() as
> > opposed to itervalues() or iteritems() since that's technically a copy
> > of values or items in the dict, right?
>
> No!  In fact the whole point of iteritems and itervalues and iterkeys is
> that they *DO NOT* make copies, so changing the dictionary out from
> under them is a programming error.
>
> If you use dict.items(), dict.keys() or dict.values(), then you're OK,
> because these methods  *do* create new lists for both.


That's what I meant, it just didn't come across correctly I guess.
Thanks for clarifying these issues. I think I have a better
understanding now.
R
--
http://mail.python.org/mailman/listinfo/python-list


Re: storing references instead of copies in a dictionary

2008-07-17 Thread castironpi
On Jul 17, 10:05 am, mk <[EMAIL PROTECTED]> wrote:
> > def f2(arg):
> >     return "f2 "+arg
>
> > def f1(arg):
> >     return "f1 "+arg
>
> > a={"1":"f1","2":"f2"}
> > print [eval(x[1])(x[0]) for x in a.items()]
> > def f2(arg):
> >     return "New f2 "+arg
> > print [eval(x[1])(x[0]) for x in a.items()]
>
> Neat trick, if probably dangerous in some circumstances. Anyway, thanks,
> I didn't think of that.
>
> > Don't know if this is any use to you..
>
> At least I learned something. :-)

You want consistent access to a changing variable.  Wrap it in an
object:

>>> a= Blank( )
>>> a.ref= 'X'
>>> a.ref
'X'
>>> b= a
>>> b.ref
'X'
>>> a.ref= 'Y'
>>> b.ref
'Y'
>>>

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


Re: x, = y (???)

2008-07-17 Thread Erik Max Francis

kj wrote:


I just came across an assignment of the form

  x, = y

where y is a string (in case it matters).

1. What's the meaning of the comma in the LHS of the assignment?
2. How could I have found this out on my own?

(Regarding (2) above, I consulted the index of several Python
reference books but I could not find the answer to (1).  I hope to
find a better Python reference!)


It's unpacking a 1-tuple:

(x,) = y

The parentheses here are not necessary and are sometimes left out.

--
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
 San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
  The United States, while they wish for war with no nation, will buy
   peace with none. -- James Madison
--
http://mail.python.org/mailman/listinfo/python-list


wholesale air bape sneaker(paypal accept)(www all-wholesaler com)paypal

2008-07-17 Thread hyh_david
paypal wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale air bape sneak

wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal

2008-07-17 Thread hyh_david
paypal wholesale adidas sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneaker(paypal accept)(www all-wholesaler com)paypal
wholesale adidas sneak

wholesale n i k e sneaker(paypal accept)(www all-wholesaler com)paypal

2008-07-17 Thread hyh_david
paypal wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e sneaker(paypal accept)(www all-wholesaler
com)paypal
wholesale n i k e snea

x, = y (???)

2008-07-17 Thread kj



I just came across an assignment of the form

  x, = y

where y is a string (in case it matters).

1. What's the meaning of the comma in the LHS of the assignment?
2. How could I have found this out on my own?

(Regarding (2) above, I consulted the index of several Python
reference books but I could not find the answer to (1).  I hope to
find a better Python reference!)

TIA!

kynn

-- 
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Rotating a cube

2008-07-17 Thread norseman

J-Burns wrote:

Hello. Need some help here. I have a 4*4 cube. So the equation of the
cube becoming:

  x + 4*y + 16*z

Now i want to rotate this cube 90 degrees anticlockwise( a right
rotation). How can i do that? The rotation must take place with the
axis of rotation being the straight line through the center of the
cube and perpendicular to the "xz-plane." The axis are aligned in this
fashion:

   y
   |
   |
   | x
  /
/
  z

Moreover, also tell me how to perform a rotation with the axis of
rotation being the straight line through the center of the cube and
perpendicular to the "yz-plane."

Essentially, I need the equations of the lines after the rotation has
been done in both cases.
Is there a built in Python function for this?
--
http://mail.python.org/mailman/listinfo/python-list


==

OH-Boy!

1)  a regular cube is dimensioned having three mutually perpendicular 
axis, each of same length.  The 4x4 would be for a plane.

2) Clockwise IS Angles Right. (Rotate to right.)
   Normal Angles Right would put zero at +Y, 90 at +X as viewed from +Z.
   Norman Angles Right would put zero at +Z, 90 at +Y as viewed from +X.
   Normal Angles Right would put zero at +Z, 90 at -X as viewed from +Y.
(there are six faces, finish the defs for the rest.)
3) Normally all rotations are defined as pivoting about the 0,0,0 point.
   To use center of a plane or other pivot point is to add offsets.
4) Sequence of rotations controls final spatial orientation.

As for finding a cube handling graphic in the standard package download, 
I did not. Somebody else can answer if there is a full blown Python 
vector graphic package.


At a minimum you need to define a:
rotational routine that handles N 3D points as a single bundle.
The usual routines consider each rotation as being about a single axis.
It computes all N corners each time.
	translation routine that moves N 3D points as a single bundle along a 
single 3D vector.

It computes all N corners each time.
	scaler routine that expands/contracts the relative distances between 
the N 3D points using vectors from the computed 3D center.

It computes all N corners each time.
Some pre-/post routines to put things together to get the desired 
effects.

If N=0 (the nothing) there is nothing to do.
If N=1 (the point) there is no rotation or scale.
If N>1 (the line,plane,box,sphere,torus,etc.) then use all three.
(a sphere can be computed as three points of an isosceles triangle in 
which the third side can equal the other two. The points then are used 
to create a circle (ellipse) which is rotated about the third side.
In case it isn't obvious - the perpendicular bisector of the third side 
is the center of the sphere. To track a point on a sphere is simply to 
use 4 points. 0,1,2 are triangle and 3 is the point. Do your thing on 
all 4, use 0,1,2 to remake sphere and 3 will be right place.)


The Chemical Rubber Company's Handbook of Physics and Chemistry is a 
good starting point for the equations.  Johnny, George, Willie and I 
also used a few Celestial Mechanics books from the Library when we wrote 
those in assembly in the long ago and far away. (back in the '60s on the 
other side of the continent.)  Sorry, but the punch cards disappeared 
long ago and access to CAD programs deletes my need to re-write them.



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


Re: Rotating a cube

2008-07-17 Thread Ryan Smith
Have you taken the time to solve the problem for the 2D case?

I can't say my code is correct or even good python, but this was my
attempt at the 2D case, maybe it will give you some ideas.

http://code.google.com/p/rs-wxpython-nooberdev/source/browse/rectangle.py

For the rest of c.l.p, criticism is welcome :-)

Regards,
Ryan

On Jul 17, 2:11 am, J-Burns <[EMAIL PROTECTED]> wrote:
> On Jul 17, 12:53 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>
> > J-Burns wrote:
> > > Is there a built in Python function for this?
>
> > for answering questions that have nothing to do with programming, and
> > looks quite a bit like homework?  don't think they've added that one yet.
>
> > maybe you should look for a geometry newsgroup/forum?
>
> > 
>
> I meant to ask how would you do this in Python... :S

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


Re: Need Python Programmer (preferentially in Los Angeles)

2008-07-17 Thread robnhood00
Fair enough.
All details of the project will be disclosed so a proper bid can be
put in place.  I just need an experienced Python Programmer and I'll
put you in direct contact with the client and I won't even take a
referral fee.  I just want the project completed.
Thanks again,
Rob

On Jul 16, 6:01 am, Scott David Daniels <[EMAIL PROTECTED]> wrote:
> robnhood00 wrote:
> > I need apythonprogrammer that can integrate graphics into an
> > existingpythonapplication.  The application is a basic application
> > and the job should be pretty easy for an experiencedPython
> > programmer.  Los Angeles programmer is preferred but this can
> > obviously be done from anywhere.
> > Please contact me at [EMAIL PROTECTED] is you can help me.
> > Thank you.
>
> I get worried when I hear people tell me that a job they don't know
> how to do "should be pretty easy," but at least it is better than
> "should only take a week."  What I'd rather hear is, "seems like it
> is a simple job."
>
> Beware of customers who know something will take little effort
> without being able to characterize that effort.
>
> --Scott David Daniels
> [EMAIL PROTECTED]

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


Re: properly delete item during "for item in..."

2008-07-17 Thread Gary Herron

Ratko wrote:

On Jul 17, 9:57 am, mk <[EMAIL PROTECTED]> wrote:
  

Gary Herron wrote:


You could remove the object from the list with
 del myList[i]
if you knew i.  HOWEVER, don't do that while looping through the list!
Changing a list's length will interact badly with the for loop's
indexing through the list, causing the loop to mis the element following
the deleted item.
  

Jumping into a thread, I know how not to do it, but not how to do it
properly?

Iterating over a copy may _probably_ work:

 >>> t=['a', 'c', 'b', 'd']
 >>>
 >>> for el in t[:]:
del t[t.index(el)]

 >>> t
[]

However, is it really safe? Defining safe as "works reliably in every
corner case for every indexable data type"?

Con: suppose the data structure t is really, really big. Just deleting
some items from t temporarily doubles the memory consumption.





Would this work (safely) then? It does in my test cases but that of
course doesn't prove it works in a general case...

for item in myList:
myList.remove(item)
  


No.  Same problem,  The for loop iterates through the list by keeping 
and incrementing an internal index.  Any modification of the list does 
not change the index correspondingly.


One proper way:
newList = []
for item in myList:
 if ... whatever...
newList.append(item)
myList = newList

Another, using list comprehension (it's the same thing really as the above):
myList = [item for item in myList if ... whatever...]






For dictionaries we can just iterate over values() or items() as
opposed to itervalues() or iteritems() since that's technically a copy
of values or items in the dict, right?
  


No!  In fact the whole point of iteritems and itervalues and iterkeys is 
that they *DO NOT* make copies, so changing the dictionary out from 
under them is a programming error.


If you use dict.items(), dict.keys() or dict.values(), then you're OK, 
because these methods  *do* create new lists for both.


Gary Herron



R

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


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


Re: unpacking with default values

2008-07-17 Thread Gary Herron

McA wrote:

On 17 Jul., 18:33, Gary Herron <[EMAIL PROTECTED]> wrote:
  

In Python 2.x, you can't do that directly, but you should be able to
create a function that lengthens or shortens an input tuple of arguments
to the correct length so you can do:

  a,c,b = fix(1,2)
  d,e,f = fix(1,2,3,4)

However, the function won't know the length of the left hand side
sequence, so it will have to be passed in as an extra parameter or hard
coded.



Hi Gary,

thank you for the answer.
Do you know the "protocol" used by python while unpacking?
Is it a direct assingnment? Or iterating?
  


Both I think, but what do you mean by *direct* assignment?


Best regards
Andreas Mock
--
http://mail.python.org/mailman/listinfo/python-list
  


It RHS of such an assignment can be any iterable (I think).  Lets test:
(The nice thing about an interactive Python session, it that it's really 
easy to test.)



>>> L = [1,2,3]
>>> a,b,c=L
>>> a,b=L
Traceback (most recent call last):
 File "", line 1, in 
ValueError: too many values to unpack
>>> a,b,c,d=L
Traceback (most recent call last):
 File "", line 1, in 
ValueError: need more than 3 values to unpack

>>> G = (f for f in [1,2,3])   # A generator expression
>>> a,b,c = G
>>> G = (f for f in [1,2,3])   # A generator expression
>>> a,b = G
Traceback (most recent call last):
 File "", line 1, in 
ValueError: too many values to unpack
>>> G = (f for f in [1,2,3])   # A generator expression
>>> a,b,c,d = G
Traceback (most recent call last):
 File "", line 1, in 
ValueError: need more than 3 values to unpack


I'd call that direct assignment with values supplied by any iterable.

Gary Herron





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


Re: Converting from local -> UTC

2008-07-17 Thread M.-A. Lemburg

On 2008-07-16 20:00, Keith Hughitt wrote:

Thanks Gabriel!

That helps clear things up for me. The above method works very well. I
only have one remaining question:
How can I pass a datetime object to MySQL?'

So far, what I've been doing is building the query as a string, for
example:

query = "INSERT INTO image VALUES(%d, %d, %s, '%s')" % (id, meas,
date, 'jpg')
cursor.execute(query)


Use binding parameters and it should work:

query = "INSERT INTO image VALUES(%d, %d, %s, '%s')"
cursor.execute(query, (id, meas, date, 'jpg'))

Database interfaces typically do not support timezones, so I'm not
sure why you are making things more complicated by adding a timezone
to the date/time value.


This works fine for regular datetime objects, which are passed as
strings similar
to: "2003-10-01 00:00:00." When incorporating a timezone, however, the
resulting string
is of the form "2003-10-01 00:00:00+00:00." Unfortunately, MySQL does
not recognize
the offset.

I know you said you don't use MySQL, but how would you do something
execute a similar query
on the database you normally interface with?




Thanks,
Keith


On Jul 15, 12:04 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
En Mon, 14 Jul 2008 12:06:30 -0300,KeithHughitt  
<[EMAIL PROTECTED]> escribió:





On Jul 12, 12:52 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
En Fri, 11 Jul 2008 15:42:37 -0300,KeithHughitt  
<[EMAIL PROTECTED]> escribió:

I am having a little trouble figuring out how to convert a python
datetime to UTC. I have a UTC date (e.g. 2008-07-11 00:00:00). I would
like to create a UTC date so that when I send it to MySQL (which
treats all dates at local dates by default), it will already have
incorporated the proper UTC offset. I've tried looking through the
docshttp://python.active-venture.com/lib/datetime-datetime.html), but
have not had any luck.
You have to use a "timezone aware" datetime object. If all you want is  
to  
store an UTC date, the tzinfo demo classes that you can find in the  
Python  
docs at  may be enough.

Thanks for advice Gabriel. I downloaded the tzinfo demo class, saved
it as
UTC.py and imported it. I'm still not exactly sure how to use it
though. It looks like
the file already creates an instance of the UTC tzinfo class (line 20:
"utc = UTC()"),
however, when I try to test it out in the interpreter, it cannot be
found. I'm new
to python, and there is probably something obvious I'm missing, but do
you have any ideas?
The import statement in Python doesn't behave the same way as similar  
statements in other languages - and it may be confusing you. I'll try to  
explain it using this example.

You have:
- a *file* UTC.py, containing the source code for the *module* UTC. It  
contains:

- a *class* definition (UTC) and
- an *instance* of that class, utc.

--- begin UTC.py ---If you pass a "timezone aware" datetime object as a SQL 
parameter
class UTC(tzinfo):
   ...
utc = UTC()
...
--- end UTC.py ---


Here is what I'm attempting:
 output begin =
Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import datetime, UTC
Here you have imported the *module* UTC. That is, the name UTC now refers  
to a newly created module just loaded from the UTC.py file.



t = datetime.datetime(2008, 7, 14, 00, 00, 00, UTC())

Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'module' object is not callable
The error comes from UTC(): UTC is a module, UTC() is attempting to "call"  
it, and since modules are not callable objects, we get a TypeError.



utc

Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'utc' is not defined
The *only* name we have imported so far is UTC - the module. Lowercase utc  
isn't defined.



utc = UTC()

Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'module' object is not callable

Same as above...

Ok, how to solve it? We know that UTC refers to the *module* with the same  
name. To get the *class* inside that module, use UTC.UTC - try again in  
the interpreter. To create a new instance of that class, you can use  
UTC.UTC(). To obtain the instance already created in the UTC module, use  
UTC.utc


**OR**

Import those names explicitely:

py> from UTC import UTC

In this case the name UTC refers to the *class* inside the module.
In this particular example it may be confusing - both have the same name.  
Another example from the standard library: the poplib module contains a  
POP3 class, so after executing this line:


py> from poplib import POP3

the name POP3 refers to that class. The poplib module itself isn't  
directly available.

Back to the UTC module, you could use:

py> from UTC import utc

and now utc refers to the *instance* already created inside the module.  
This last form may be the most convenient in your case:


py> import datetime
p

RE: Unusual Exception Behaviour

2008-07-17 Thread Robert Rawlins
>> That's seriously weird. What's your Python version and platform? On my 
>> Windows and Linux machines, with more recent Python versions the above 
>> trick works flawlessly.
>>
>> Check your environment, namely PYTHON* variables. There may be 
>> something causing this behaviour. Unset them.
>>
>> Check the first line of your scripts. If you're calling wrong Python 
>> interpreter (there may be more than one in the system for some 
>> reason), this may cause it.
>>
>> You could also try setting up PYTHONINSPECT environment variable or 
>> run the python interpreter with -i option before program filename, 
>> which drops you into an interactive shell upon exception or 
>> termination of a program.
>>
>> This behavior is seriously unusual for Python. Maybe you have some old 
>> / buggy version?
> 
> Thanks for that MK. I'm using Debian with Python 2.5 from the stable apt
repository, installed > but a couple of days ago. I'll be sure to look into
those other elements you suggested also. > > I'm not sure if it bares any
resemblance but this application runs a gobject mainloop and uses > > dbus
quite extensively.
>
> Don't think this might have something to do with the way I have my loggers
configured do you? > > For some reason it sits in my mind that this issue
started when I moved my logging > > > >  > > > configuration from
programmatic into a config file, I can't be totally sure of that though.
>
> I've attached the config file that I use, does it all look ok to you? I
wonder if the way I've > not added any handles/formatters to my root logger
might be causing beef?
>
> This is certainly a strange one.

Ok, Just to add a little interest, when I comment out the configuration line
for my logging, like so:

#logging.config.fileConfig("/myapp/configuration/logging.conf")

It appears to throw the exceptions as normal :-) :-s

Sounds as if it's a conflict with my logging configuration, I wonder what
though.

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


Re: How to process a very large (4Gb) tarfile from python?

2008-07-17 Thread Uwe Schmitt
On 17 Jul., 17:55, Terry Carroll <[EMAIL PROTECTED]> wrote:
> On Thu, 17 Jul 2008 06:14:45 -0700 (PDT), Uwe Schmitt
>
> <[EMAIL PROTECTED]> wrote:
> >I had a look at tarfile.py in my current Python 2.5 installations
> >lib path. The iterator caches TarInfo objects in a list
> >tf.members . If you only want to iterate and you  are not interested
> >in more functionallity, you could use "tf.members=[]" inside
> >your loop. This is a dirty hack !
>
> Thanks, Uwe.  That works fine for me.  It now reads through all 2.5
> million members, in about 30 minutes, never going above a 4M working
> set.

Maybe we should post this issue to python-dev mailing list.
Parsing large tar-files is not uncommon.

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


Re: bad recursion, still works

2008-07-17 Thread mdsherry
On Jul 17, 8:27 am, Jeff <[EMAIL PROTECTED]> wrote:
> Thanks, that made things very clear.  I like that technique for adding
> memoization via the parameter.  That is clever.  It would be nice if
> there were a way to have multiple functions close over a shared local
> variable in Python, like let-binding in lisp.

Is this something like what you're looking for?

>>> def functionmaker():
... shared = []
... def addnumber():
... shared.append(3)
... return shared
... def addletter():
... shared.append('f')
... return shared
... return addnumber, addletter
...
>>> addnumber, addletter = functionmaker()
>>> addnumber()
[3]
>>> addletter()
[3, 'f']
--
http://mail.python.org/mailman/listinfo/python-list


Re: property getter with more than 1 argument?

2008-07-17 Thread Roy H. Han
I don't understand what you're trying to do here.


On Thu, Jul 17, 2008 at 10:57 AM, mk <[EMAIL PROTECTED]> wrote:
>
> It seems like getter is defined in such way that it passes only 'self':
>
>
> class FunDict(dict):
>def __init__(self):
>self.fundict = dict()
>
>def fget(self, fun):
>return fundict[fun.func_name]
>
>def fset(self, newfun):
>self.fundict[newfun.func_name] = newfun
>
>newfun = property (fget, fset)
>
>
 a=FunDict()

 a.newfun=f1

 a.newfun('f1')
>
> Traceback (most recent call last):
>  File "", line 1, in 
>a.newfun('f1')
> TypeError: fget() takes exactly 2 arguments (1 given)
>
>
>
> Is it possible to pass more than one argument to fget function?
>
> I know: I can define a function with property name ('newfun' in the example)
> and call it with more arguments. But then I do not get the benefits of
> setter and property in general!
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: unpacking with default values

2008-07-17 Thread McA
On 17 Jul., 18:33, Gary Herron <[EMAIL PROTECTED]> wrote:
>
> In Python 2.x, you can't do that directly, but you should be able to
> create a function that lengthens or shortens an input tuple of arguments
> to the correct length so you can do:
>
>   a,c,b = fix(1,2)
>   d,e,f = fix(1,2,3,4)
>
> However, the function won't know the length of the left hand side
> sequence, so it will have to be passed in as an extra parameter or hard
> coded.

Hi Gary,

thank you for the answer.
Do you know the "protocol" used by python while unpacking?
Is it a direct assingnment? Or iterating?

Best regards
Andreas Mock
--
http://mail.python.org/mailman/listinfo/python-list


Re: properly delete item during "for item in..."

2008-07-17 Thread Duncan Booth
mk <[EMAIL PROTECTED]> wrote:

> Iterating over a copy may _probably_ work:
> 
> >>> t=['a', 'c', 'b', 'd']
> >>>
> >>> for el in t[:]:
>  del t[t.index(el)]
> 
>  
> >>> t
> []
> 
> 
> However, is it really safe? Defining safe as "works reliably in every 
> corner case for every indexable data type"?

No, because you cannot necessarily copy every indexable data type using 
t[:], and not all types will support index. Also it is inefficient to 
delete from the start of the list.

If you are working with a list and deleting every object:

del t[:]

will suffice.

If you don't want to delete everything then you could do:

for index, el in enumerate(reversed(t)):
if not wewant(el):
   del t[index]

but the pythonic way is just:

 t[:] = [ el for el in t if wewant(el) ]

or if you just want the filtered list and don't care about updating the 
original:

 t = [ el for el in t if wewant(el) ]


> Con: suppose the data structure t is really, really big. Just deleting 
> some items from t temporarily doubles the memory consumption.

No it doesn't. Copying a list doesn't copy any of the elements in the list, 
it just copies the references to those element.
--
http://mail.python.org/mailman/listinfo/python-list


RE: Unusual Exception Behaviour

2008-07-17 Thread Robert Rawlins
> That's seriously weird. What's your Python version and platform? On my 
> Windows and Linux machines, with more recent Python versions the above 
> trick works flawlessly.
>
> Check your environment, namely PYTHON* variables. There may be something 
> causing this behaviour. Unset them.
>
> Check the first line of your scripts. If you're calling wrong Python 
> interpreter (there may be more than one in the system for some reason), 
> this may cause it.
>
> You could also try setting up PYTHONINSPECT environment variable or run 
> the python interpreter with -i option before program filename, which 
> drops you into an interactive shell upon exception or termination of a 
> program.
>
> This behavior is seriously unusual for Python. Maybe you have some old / 
> buggy version?

Thanks for that MK. I'm using Debian with Python 2.5 from the stable apt
repository, installed but a couple of days ago. I'll be sure to look into
those other elements you suggested also. I'm not sure if it bares any
resemblance but this application runs a gobject mainloop and uses dbus quite
extensively.

Don't think this might have something to do with the way I have my loggers
configured do you? For some reason it sits in my mind that this issue
started when I moved my logging configuration from programmatic into a
config file, I can't be totally sure of that though.

I've attached the config file that I use, does it all look ok to you? I
wonder if the way I've not added any handles/formatters to my root logger
might be causing beef?

This is certainly a strange one.

Robert


simple_loggingconf.conf
Description: Binary data
--
http://mail.python.org/mailman/listinfo/python-list

Re: Unusual Exception Behaviour

2008-07-17 Thread mk

http://linux.byexamples.com/archives/365/python-convey-the-exception-traceba
ck-into-log-file/

if __name__=="__main__":
 try:
 main()
 except:
 print "Trigger Exception, traceback info forward to log file."
 traceback.print_exc(file=open("errlog.txt","a"))
 sys.exit(1)



I've just given this solution a shot but I still seem to get the same
result, it suddenly starts dumping the log data to the command line, and
nothing gets printed in error.txt apart from the keyboard interrupt from
when I kill the application.


That's seriously weird. What's your Python version and platform? On my 
Windows and Linux machines, with more recent Python versions the above 
trick works flawlessly.


Check your environment, namely PYTHON* variables. There may be something 
causing this behaviour. Unset them.


Check the first line of your scripts. If you're calling wrong Python 
interpreter (there may be more than one in the system for some reason), 
this may cause it.


You could also try setting up PYTHONINSPECT environment variable or run 
the python interpreter with -i option before program filename, which 
drops you into an interactive shell upon exception or termination of a 
program.



For some reason the exceptions don't seem to be raised properly so obviously
aren't being caught at this higher level.

So confusing.


This behavior is seriously unusual for Python. Maybe you have some old / 
buggy version?





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


Re: properly delete item during "for item in..."

2008-07-17 Thread Ratko
On Jul 17, 9:57 am, mk <[EMAIL PROTECTED]> wrote:
> Gary Herron wrote:
> > You could remove the object from the list with
> >  del myList[i]
> > if you knew i.  HOWEVER, don't do that while looping through the list!
> > Changing a list's length will interact badly with the for loop's
> > indexing through the list, causing the loop to mis the element following
> > the deleted item.
>
> Jumping into a thread, I know how not to do it, but not how to do it
> properly?
>
> Iterating over a copy may _probably_ work:
>
>  >>> t=['a', 'c', 'b', 'd']
>  >>>
>  >>> for el in t[:]:
> del t[t.index(el)]
>
>  >>> t
> []
>
> However, is it really safe? Defining safe as "works reliably in every
> corner case for every indexable data type"?
>
> Con: suppose the data structure t is really, really big. Just deleting
> some items from t temporarily doubles the memory consumption.



Would this work (safely) then? It does in my test cases but that of
course doesn't prove it works in a general case...

for item in myList:
myList.remove(item)


For dictionaries we can just iterate over values() or items() as
opposed to itervalues() or iteritems() since that's technically a copy
of values or items in the dict, right?


R

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


Re: properly delete item during "for item in..."

2008-07-17 Thread mk

Gary Herron wrote:

You could remove the object from the list with
 del myList[i]
if you knew i.  HOWEVER, don't do that while looping through the list!  
Changing a list's length will interact badly with the for loop's 
indexing through the list, causing the loop to mis the element following 
the deleted item.


Jumping into a thread, I know how not to do it, but not how to do it 
properly?


Iterating over a copy may _probably_ work:

>>> t=['a', 'c', 'b', 'd']
>>>
>>> for el in t[:]:
del t[t.index(el)]


>>> t
[]


However, is it really safe? Defining safe as "works reliably in every 
corner case for every indexable data type"?



Con: suppose the data structure t is really, really big. Just deleting 
some items from t temporarily doubles the memory consumption.


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


RE: Unusual Exception Behaviour

2008-07-17 Thread Robert Rawlins
Hi MK,

>>Robert Rawlins wrote:
>>
>> I certainly like that implementation for logging the exceptions, however,
at
>> the moment I don't even know where the exceptions are occurring, or what
>> type they are, could I still use this method to log any and all
exceptions
>> raised in the application? 

> Remember, Google is your friend, here's the crux of the method without 
> the fancy schmancy sugar coating:
>
>
http://linux.byexamples.com/archives/365/python-convey-the-exception-traceba
ck-into-log-file/
>
> if __name__=="__main__":
>  try:
>  main()
>  except:
>  print "Trigger Exception, traceback info forward to log file."
>  traceback.print_exc(file=open("errlog.txt","a"))
>  sys.exit(1)
>

I've just given this solution a shot but I still seem to get the same
result, it suddenly starts dumping the log data to the command line, and
nothing gets printed in error.txt apart from the keyboard interrupt from
when I kill the application.

For some reason the exceptions don't seem to be raised properly so obviously
aren't being caught at this higher level.

So confusing.

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


Re: properly delete item during "for item in..."

2008-07-17 Thread Gary Herron

Ratko wrote:

Say you have something like this:

for item in myList:
   del item

Would this actually delete the item from the list or just decrement
the reference counter because the item in myList is not associated
with name "item" anymore (but still is with myList[itemIndex])? In
other words, is "item" a temporary reference to myList[itemIndex] or
is it actually that reference that myList has stored?
  


The 'del' statement does not delete an object, it deletes a reference to 
an object.  In this case, the variable item is deleted from the scope, 
and the referred-to object will have its reference counter decremented 
by 1.  (But, as you surmise, not to zero, because the list will still 
reference it.)


You could remove the object from the list with
 del myList[i]
if you knew i.  HOWEVER, don't do that while looping through the list!  
Changing a list's length will interact badly with the for loop's 
indexing through the list, causing the loop to mis the element following 
the deleted item.


Gary Herron


I am not sure if this question even makes any sense anymore. I've been
using python for years and never had any problems (and I don't now
either) but now that I had to revisit c++/STL, I had to deal about
these issues and was wondering how python does it.

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


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


Re: properly delete item during "for item in..."

2008-07-17 Thread Marc 'BlackJack' Rintsch
On Thu, 17 Jul 2008 09:27:27 -0700, Ratko wrote:

> for item in myList:
>del item
> 
> Would this actually delete the item from the list or just decrement
> the reference counter because the item in myList is not associated
> with name "item" anymore (but still is with myList[itemIndex])? In
> other words, is "item" a temporary reference to myList[itemIndex] or
> is it actually that reference that myList has stored?

The latter.  Names are always bound to objects, you can't bind a name to
another name or reference in Python.

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


Re: Python Behind a Squid Corporate Proxy on Windows

2008-07-17 Thread Larry Hale
Err, the line above should be:

proxy_handler = urllib2.ProxyHandler( { "http": "http://
myusername:[EMAIL PROTECTED]:3128" } )

(Sorry!  :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: unpacking with default values

2008-07-17 Thread Gary Herron

McA wrote:

Hi all,

probably a dumb question, but I didn't find something elegant for my
problem so far.
In perl you can unpack the element of a list to variables similar as
in python
(a, b, c = [0, 1, 2]), but the number of variables need not to fit the
number
of list elements.
That means, if you have less list elements variables are filled with
'undef' (None in python), if you have more list elements as necessary
the rest is ignored.

How can I achieve this behaviour with python in an elegant and fast
way?

Best regards
Andreas Mock
--
http://mail.python.org/mailman/listinfo/python-list
  


Python 3.0 has something a bit like this.  Excess values can be bound 
(as a list) to the last variable:


 a,b,*c = [1,2,3,4,5]

will result in c containing [3,4,5].

In Python 2.x, you can't do that directly, but you should be able to 
create a function that lengthens or shortens an input tuple of arguments 
to the correct length so you can do:


 a,c,b = fix(1,2)
 d,e,f = fix(1,2,3,4)

However, the function won't know the length of the left hand side 
sequence, so it will have to be passed in as an extra parameter or hard 
coded.



Gary Herron

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


properly delete item during "for item in..."

2008-07-17 Thread Ratko
Say you have something like this:

for item in myList:
   del item

Would this actually delete the item from the list or just decrement
the reference counter because the item in myList is not associated
with name "item" anymore (but still is with myList[itemIndex])? In
other words, is "item" a temporary reference to myList[itemIndex] or
is it actually that reference that myList has stored?

I am not sure if this question even makes any sense anymore. I've been
using python for years and never had any problems (and I don't now
either) but now that I had to revisit c++/STL, I had to deal about
these issues and was wondering how python does it.

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


Re: Unusual Exception Behaviour

2008-07-17 Thread mk

Robert Rawlins wrote:


I certainly like that implementation for logging the exceptions, however, at
the moment I don't even know where the exceptions are occurring, or what
type they are, could I still use this method to log any and all exceptions
raised in the application? 


Sure.

I'm a little confused as to how I can modify that

implementation to do so.


Remember, Google is your friend, here's the crux of the method without 
the fancy schmancy sugar coating:


http://linux.byexamples.com/archives/365/python-convey-the-exception-traceback-into-log-file/

if __name__=="__main__":
try:
main()
except:
print "Trigger Exception, traceback info forward to log file."
traceback.print_exc(file=open("errlog.txt","a"))
sys.exit(1)


This will obviously capture every exception happening in the main() 
function.


The drawback of this method is that you cannot capture the  error 
message / object accompanying the exception, as you normally can do 
while capturing specific exception:


>>> import sys
>>> import traceback

>>> def anindextoofar(alist):
print alist[10]


>>> shortlist=range(1,10)
>>>
>>> try:
anindextoofar(shortlist)
except IndexError, err:
print err
traceback.print_exc(file=sys.stdout)


list index out of range
Traceback (most recent call last):
  File "", line 2, in 
  File "", line 2, in anindextoofar
IndexError: list index out of range




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


Python Behind a Squid Corporate Proxy on Windows

2008-07-17 Thread Larry Hale
Greetings, Pythonistas!

My employer has a Squid Proxy between my Python programs and The
Internet.

I've searched high-and-low, and can only find examples online of how
to do basic authentication to connect TO an external Web Server, but
not how to go THROUGH a (corporate) Proxy, thus my question here.
I've tried all sorts of permutations based on my findings, but
(obviously) nothing's working for me.  I've come across conflicting
information, including that urllib2 can't/won't do what I'm needing,
though this statement was a couple years old.

I'm running Python 2.5 on Windows XP SP2 64-bit.  The Proxy is Squid
(don't know what version, but can find out if this is relevant).

urllib2 grabs the Proxy info fine: 'http': 'http://webfilter.xyz.local:
3128' (.getproxies()).  There's the obvious necessity of telling
"something" my ID/pass *somehow*.

An example of one iteration:

##

import urllib2

proxy_handler = urllib2.ProxyHandler( { "http": "http://
myusername:@webfilter.xyz.local:3128" } )
opener= urllib2.build_opener( proxy_handler )

urllib2.install_opener( opener )

response = opener.open( "http://python.org"; )

print response

##

I've tried situations using HTTPPasswordMgrWithDefaultRealm and its
add_password method, also to no avail.  (Again, THIS sort of thing
seems related to the -external- Web Server, _not_ going *through* a
Proxy.  'Course, I could be wrong.  But if I am, I couldn't get this
to work, either.  ;)

I've looked at what's happening with Wireshark; Py/my program/urllib2
makes the initial page request, Proxy replies HTTP Error 407: Proxy
Authentication Required, and Py/my program/urllib2 simply stops at
that, reporting the message/error.

Please forgive me; I've been programming in Python for a few years
now, but never had to deal with Web Proxies.  I *have* tried to RTFMs,
but the "documentation" for non-basic stuffs with urllib2 is... uh...
well, I'm sure ye olde pro's know...  :)


Cheers, and *any* help would be appreciated!
-Larry
--
http://mail.python.org/mailman/listinfo/python-list


unpacking with default values

2008-07-17 Thread McA
Hi all,

probably a dumb question, but I didn't find something elegant for my
problem so far.
In perl you can unpack the element of a list to variables similar as
in python
(a, b, c = [0, 1, 2]), but the number of variables need not to fit the
number
of list elements.
That means, if you have less list elements variables are filled with
'undef' (None in python), if you have more list elements as necessary
the rest is ignored.

How can I achieve this behaviour with python in an elegant and fast
way?

Best regards
Andreas Mock
--
http://mail.python.org/mailman/listinfo/python-list


RE: Unusual Exception Behaviour

2008-07-17 Thread Robert Rawlins
Hi Mk,

> Why not capture exceptions themselves to a log file?
>
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/466332

Thanks for the reply mate, I appreciate you getting back to me so quickly.

I certainly like that implementation for logging the exceptions, however, at
the moment I don't even know where the exceptions are occurring, or what
type they are, could I still use this method to log any and all exceptions
raised in the application? I'm a little confused as to how I can modify that
implementation to do so.

Robert

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


Re: How to process a very large (4Gb) tarfile from python?

2008-07-17 Thread Terry Carroll
On Thu, 17 Jul 2008 06:14:45 -0700 (PDT), Uwe Schmitt
<[EMAIL PROTECTED]> wrote:

>I had a look at tarfile.py in my current Python 2.5 installations
>lib path. The iterator caches TarInfo objects in a list
>tf.members . If you only want to iterate and you  are not interested
>in more functionallity, you could use "tf.members=[]" inside
>your loop. This is a dirty hack !

Thanks, Uwe.  That works fine for me.  It now reads through all 2.5
million members, in about 30 minutes, never going above a 4M working
set.


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


Re: Unusual Exception Behaviour

2008-07-17 Thread mk
I have looked through the application for any unusual or bare try/except 
blocks that don’t actually do anything with the except just in case any 
of them are causing the issue but can’t seem to see any.


Why not capture exceptions themselves to a log file?

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/466332



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


Unusual Exception Behaviour

2008-07-17 Thread Robert Rawlins
Hello Chaps,

 

I have an unusual situation with my application which I've also seen once or
twice in the past but never found a solution too. Basically the application
stops properly reporting Exceptions when they are thrown.

 

My application logs extensively to a file using the python logging module,
when an exception is throw all the log data starts being thrown to the
command prompt instead of the file, however, I don't get any actual
exception information output.

 

I have looked through the application for any unusual or bare try/except
blocks that don't actually do anything with the except just in case any of
them are causing the issue but can't seem to see any.

 

This little issue makes debugging my application VERY hard, when running the
app I can see it crash, but I get no information as to where the exception
is being thrown from, as you can imagine, quite frustrating.

 

Even when throwing my own exceptions just for testing like so:

 

Raise Exception, "This is a test exception."

 

In certain parts of the application it doesn't print the exception to
screen, but all subsequent requests to the logger seem to print out at the
command prompt.

 

I would really love some suggestions on what might be causing this.

 

Cheers,

 

Robert

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

Re: Javascript - Python RSA encryption interoperability

2008-07-17 Thread Paul Rubin
Evren Esat Ozkan <[EMAIL PROTECTED]> writes:
> I'm trying to encrypt a string with RSA. But it needs to be compitable
> with Dave's JavaScript RSA implementation*. 

What exactly are you trying to do?  That Javascript implementation
looks like bad news.  If you're trying to secure a web page, use SSL,
don't mess around with trying to encrypt it with Javascript.
--
http://mail.python.org/mailman/listinfo/python-list


Re: storing references instead of copies in a dictionary

2008-07-17 Thread mk



def f2(arg):
return "f2 "+arg

def f1(arg):
return "f1 "+arg

a={"1":"f1","2":"f2"}
print [eval(x[1])(x[0]) for x in a.items()]
def f2(arg):
return "New f2 "+arg
print [eval(x[1])(x[0]) for x in a.items()]


Neat trick, if probably dangerous in some circumstances. Anyway, thanks, 
I didn't think of that.



Don't know if this is any use to you..


At least I learned something. :-)




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


Re: Good HTML Parser

2008-07-17 Thread Stefan Behnel
Chris wrote:
> Can anyone recommend a good HTML/XHTML parser, similar to
> HTMLParser.HTMLParser or htmllib.HTMLParser, but able to intelligently
> know that certain tags, like , are implicitly closed? I need to
> iterate through the entire DOM, building up a DOM path, but the stdlib
> parsers aren't calling handle_endtag() for any implicitly closed tags.
> I looked at BeautifulSoup, but it only seems to work by first parsing
> the entire document, then allowing you to query the document
> afterwards. I need something like a SAX parser.

Try lxml.html. It's very memory friendly and extremely fast, so you may end up
without any reason to use SAX anymore.

http://codespeak.net/lxml/

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


Re: how to debug python's extend module written in c/c++ on windows

2008-07-17 Thread fang
Dear Diez:

   I see. I appreciate your help really.


best regards


fang

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


Re: Python embedding question (2).

2008-07-17 Thread Carl Banks
On Jul 17, 9:57 am, Thomas Troeger <[EMAIL PROTECTED]>
wrote:
> > I'd say that PyGame could be a solution.
>
> > Or otherwise you could do your own audio/graphics programming (you don't
> > tell us which OS you use, but there exist python modules that allow you
> > to do barebones graphics & sound programming on linux...).
>
> After some more reading I've stumbled over pyglet. Any experiences with
> it? It seems it does a lot of cool things, if anyone has used it more
> intensely I'd be happy to hear if the following things can be done:
>
> - Linux framebuffer (16, 24 bpp) display of 2d graphics with overlays
> (i.e. menues, contextual areas that pop up etc.). I don't have X on the
> embedded device, just the regular framebuffer.
> - alpha blending of several layers.
> - rendering of TTF fonts and unicode, for example display of arabic text
> (which renders from right to left) and mixed text support like in the
> unicode bidirectional algorithm.
> - hardware caching of bitmaps for faster graphics operations (needed for
> tool tips or similar tasks).
>
> I'll try to find that out myself (I'm pretty excited about the thing
> already ^^), but I'd be happy to hear of people who have used it already.

Pyglet runs on top of OpenGL, which might have performance problems on
an embedded device, if OpenGL or Mesa is even supported.  If it's
supported, I suspect performance will be adequate for 2D drawing.  It
almost certainly is the lightest solution you can find.


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


property getter with more than 1 argument?

2008-07-17 Thread mk


It seems like getter is defined in such way that it passes only 'self':


class FunDict(dict):
def __init__(self):
self.fundict = dict()

def fget(self, fun):
return fundict[fun.func_name]

def fset(self, newfun):
self.fundict[newfun.func_name] = newfun

newfun = property (fget, fset)


>>> a=FunDict()
>>>
>>> a.newfun=f1
>>>
>>> a.newfun('f1')

Traceback (most recent call last):
  File "", line 1, in 
a.newfun('f1')
TypeError: fget() takes exactly 2 arguments (1 given)



Is it possible to pass more than one argument to fget function?

I know: I can define a function with property name ('newfun' in the 
example) and call it with more arguments. But then I do not get the 
benefits of setter and property in general!


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


Re: storing references instead of copies in a dictionary

2008-07-17 Thread mk

Uwe Schmitt wrote:

Python stores references in dictionaries and does not copy ! (unless
you explicitly use the copy module) !

In your case the entry in the dictionary is a reference to the same
object which f1 references, that is the object at 0xb7f0ba04.

If you now say "f1=...:" then f1 references a new object
at 0xb7f0b994, and the entry in your dictionary still references
the "old" object at 0xb7f0ba04.


Erm, I theoretically knews that, I guess I suffered temporary insanity 
when I wrote "copies" of objects. To me it seems that Python actually 
stores _labels_ referencing _objects_. Here, the problem was that the 
label in the dictionary led to the "old" object.



I do not know any method to automatically update your dictionary
as there is no possibility to overload the assignement operator "=".
But may be somebody can teach me a new trick :-)


Theoretically I could define a class inheriting from dictionary and 
define a property with a setter (and getter). But I would still have to 
update the attribute manually, so plain dictionary is just as good.


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


Re: storing references instead of copies in a dictionary

2008-07-17 Thread bgeddy

mk wrote:

Calvin Spealman wrote:

To your actual problem... Why do you wanna do this anyway? If you want
to change the function in the dictionary, why don't you simply define
the functions you'll want to use, and change the one you have bound to
the key in the dictionary when you want to change it? In other words,
define them all at once, and then just d['1'] = new_f1. What is wrong
with that?


Well, basically nothing except I need to remember I have to do that.

Suppose one does that frequently in a program. It becomes tedious. I 
think I will define some helper function then:


 >>> def helper(fundict, newfun):
... fundict[newfun.func_name] = newfun
...

_If_ there were some shorter and still "proper" way to do it, I'd use 
it. If not, no big deal.



For completeness:

def new_f1(arg):
return "NEW f1 " + arg
f1.func_code = new_f1.func_code

Don't use that unless you really have to and I nearly promise that you 
don't.


I promise I won't use it. :-) It seems like a 'wrong thing to do'.




Well it's probably totally "non pythonic" but this does what you want:

def f2(arg):
return "f2 "+arg

def f1(arg):
return "f1 "+arg

a={"1":"f1","2":"f2"}
print [eval(x[1])(x[0]) for x in a.items()]
def f2(arg):
return "New f2 "+arg
print [eval(x[1])(x[0]) for x in a.items()]

Don't know if this is any use to you..

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


twistedmatrix

2008-07-17 Thread Białystok
Hi.
I'm newbie in Twisted.
Can anyone explain how does twisted server work? What happens after
reactor.listenTCP running?

I've got many connections from one client (one connection-one socket),
each of them is served by class serve(Protocol).

every protocol owns transport
every transport owns socket

for me it's obvious that protocol returning data to client should use
it's own socket
but
transport.write(data) writes data into buffer
what happens then?

when my server handles two requests from one client (one by one) it
writes first data part to buffer, then second part ... and then writes
back to socket.
what more
it buffers data when I start many clients and sends it to last one.

help me? please?

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


Re: % sign in python?

2008-07-17 Thread Roy H. Han
The percent sign is a placeholder.

For example, if
level = 1
msg = 'look'

Then
'[[Log level %d: %s]]' % ( level, msg )
becomes
'[[Log level 1: look]]'

%d means insert an integer
%s means insert a string

You can also use dictionaries.
d = {'string1': 'hey', 'string2': 'you'}
Then
'%(string1)s %(string2)s' % d
becomes 'hey you'


On Thu, Jul 17, 2008 at 10:33 AM, korean_dave <[EMAIL PROTECTED]> wrote:
> What does this operator do? Specifically in this context
>
> test.log( "[[Log level %d: %s]]" % ( level, msg ), description )
>
> (Tried googling and searching, but the "%" gets interpreted as an
> operation and distorts the search results)
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to debug python's extend module written in c/c++ on windows

2008-07-17 Thread Diez B. Roggisch
fang wrote:

> Dear Diez:
> 
> It is attaching a C-debugger to python. I can attach python-
> debugger(for example:wingIDE) to c-debugger(for example:VS2008), but I
> cannot attach VS2008 to wingIDE. I need both python statement and c
> statement can be single-step debugged.

AFAIK that's not possible. First of all, *don't* attach VS2008 to WingIDE,
use VS2008 to start a python-interpreter with commandline-args (at least
that's how it works for me in gdb)

And then write only small python-scripts that expose an actual error in the
DLL, and debug these.

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


Re: % sign in python?

2008-07-17 Thread Robert Bossy

korean_dave wrote:

What does this operator do? Specifically in this context

test.log( "[[Log level %d: %s]]" % ( level, msg ), description )

(Tried googling and searching, but the "%" gets interpreted as an
operation and distorts the search results)
  

It's the string formatting operator:
   http://docs.python.org/lib/typesseq-strings.html


Btw, a good place to start searching would be:
   http://docs.python.org/lib/lib.html
especially:
   http://docs.python.org/lib/genindex.html

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


% sign in python?

2008-07-17 Thread korean_dave
What does this operator do? Specifically in this context

test.log( "[[Log level %d: %s]]" % ( level, msg ), description )

(Tried googling and searching, but the "%" gets interpreted as an
operation and distorts the search results)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Babelfish translation ...

2008-07-17 Thread Stefan Behnel
Stef Mientki  gmail.com> writes:
> Although it works functionally,
> it can take lots of time waiting for the translation.
> 
> What I basically do is, after selecting a new string to be translated:
> 
> kwds = { 'trtext' : line_to_be_translated, 'lp' :'en_nl'}
> soup = BeautifulSoup (urlopen(url, urlencode ( kwds ) ) )
> translation= soup.find ( 'div', style='padding:0.6em;' ).string
> self.Editor_Babel.SetLabel ( translation )

You should give lxml.html a try.

http://codespeak.net/lxml/

It can parse directly from HTTP URLs (no need to go through urlopen), and it 
frees the GIL while parsing, so it will become efficient to create a little 
Thread that doesn't do more than parsing the web site, as in (untested):

  def read_bablefish(text, lang, result):
  url = BABLEFISH_URL + '?' + urlencode({'trtext':text, 'lp':lang})
  page = lxml.html.parse(url)
  for div in page.iter('div'):
   style = div.get('style')
   if style is not None and 'padding:0.6em;' in style:
   result.append(
  lxml.html.tostring(div, method="text", with_tail=False))

  result = []
  thread = threading.Thread(target=read_bablefish,
args=("...", "en_nl", result))
  thread.start()
  while thread.isAlive():
  # ... do other stuff
  if result:
  print result[0]

Stefan


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


Re: Python embedding question (2).

2008-07-17 Thread Thomas Troeger

I'd say that PyGame could be a solution.

Or otherwise you could do your own audio/graphics programming (you don't 
tell us which OS you use, but there exist python modules that allow you 
to do barebones graphics & sound programming on linux...).


After some more reading I've stumbled over pyglet. Any experiences with 
it? It seems it does a lot of cool things, if anyone has used it more 
intensely I'd be happy to hear if the following things can be done:


- Linux framebuffer (16, 24 bpp) display of 2d graphics with overlays 
(i.e. menues, contextual areas that pop up etc.). I don't have X on the 
embedded device, just the regular framebuffer.

- alpha blending of several layers.
- rendering of TTF fonts and unicode, for example display of arabic text 
(which renders from right to left) and mixed text support like in the 
unicode bidirectional algorithm.
- hardware caching of bitmaps for faster graphics operations (needed for 
tool tips or similar tasks).


I'll try to find that out myself (I'm pretty excited about the thing 
already ^^), but I'd be happy to hear of people who have used it already.


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


Re: storing references instead of copies in a dictionary

2008-07-17 Thread mk

Calvin Spealman wrote:

To your actual problem... Why do you wanna do this anyway? If you want
to change the function in the dictionary, why don't you simply define
the functions you'll want to use, and change the one you have bound to
the key in the dictionary when you want to change it? In other words,
define them all at once, and then just d['1'] = new_f1. What is wrong
with that?


Well, basically nothing except I need to remember I have to do that.

Suppose one does that frequently in a program. It becomes tedious. I 
think I will define some helper function then:


>>> def helper(fundict, newfun):
... fundict[newfun.func_name] = newfun
...

_If_ there were some shorter and still "proper" way to do it, I'd use 
it. If not, no big deal.



For completeness:

def new_f1(arg):
return "NEW f1 " + arg
f1.func_code = new_f1.func_code

Don't use that unless you really have to and I nearly promise that you don't.


I promise I won't use it. :-) It seems like a 'wrong thing to do'.


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


  1   2   >