Re: Internet Explorer 8 beta release

2008-03-06 Thread M�ta-MCI (MVP)
Hi!


>  compliance with the W3C standard 

Ouarf!  Ouarf! 
which navigator has been compatible with CSS-3, left for several years?
And, it's only ONE point...

@-salutations

Michel Claveau

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


Re: Python GDB Wrapper

2008-03-06 Thread Martin v. Löwis
> Has anyone does this before ? Even some basic idea or code as to how
> to proceed would be great.

Have you seen Misc/gdbinit?

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


Re: Ncurses not found - embedded linux

2008-03-06 Thread Peter Otten
blaine wrote:

>> > I hope this is trivial, and I apologize ahead of time if so.  Would
>> > this perhaps be a compilation issue? Something we have to turn on in
>> > the python compile?
>>
>> Usually, you need not only the libraries but also the headers at
>> compilation time. Most probably these were missing.
>>
>> Diez
> 
> Thank you for our response.  Do you mean that the ncurses header
> should be in /usr/include upon compilation of python?  Will python
> automatically pick up on these headers, or would I need to change
> compilation options? Thanks! -Blaine

Just rerun the ./configure script -- it should detect the presence of the
required header file automatically. If all went well you'll see "yes" three
times:

$ sudo aptitude install ncurses-dev
[...]
$ ./configure > tmp.txt
[...]
$ grep ncurses tmp.txt
checking ncurses.h usability... yes
checking ncurses.h presence... yes
checking for ncurses.h... yes


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


Re: Python GDB Wrapper

2008-03-06 Thread Daniel Bonekeeper
On Fri, Mar 7, 2008 at 4:01 AM, Raja <[EMAIL PROTECTED]> wrote:
> Hi,
> I am trying to develop a  a GDB wrapper script in python which is
>  able to extract a stack trace and all relevant data.
>
>  Has anyone does this before ? Even some basic idea or code as to how
>  to proceed would be great.
>
>  Thanks,
>  Raja.
>  --
>  http://mail.python.org/mailman/listinfo/python-list
>

You mean extract the information from core dump files that gdb interprets ?
Check out stuff like ELF, Dwarf 3 (http://dwarf.freestandards.org/)
and gdb sources.

-- 
What this world needs is a good five-dollar plasma weapon.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python GDB Wrapper

2008-03-06 Thread Raja
Hi,
I am trying to develop a  a GDB wrapper script in python which is
able to extract a stack trace and all relevant data.

Has anyone does this before ? Even some basic idea or code as to how
to proceed would be great.

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


Regarding an exciting opportunity in PYTHON at Hyderabad

2008-03-06 Thread Nat
We have been looking for Senior Professional based at Hyderabad for
one of our clients which an upcoming Product development company based
out of hyderabad .

I would appreciate if you can repond back with your profile at
[EMAIL PROTECTED] would get back to you with complete details and
accordingly we can go ahead.


Job Description:
Need to have 2-4 years of experience.
Should have strong understanding of Project management and SDLC.
Technology is flexible. Can have experience in either of  python(C, C+
+),Java or .NET.



Thanks and Regards

Natraj.J

Möbius Consulting Pvt. Ltd.

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


the problem of import module

2008-03-06 Thread [EMAIL PROTECTED]
follow the dive into python
-
>>> import sys
>>> sys.path
>>> sys.path.append('E:\achieve\book\diveintopython-pdfzh-cn-5.4b\diveintopythonzh-cn-5.4b\py')
-
I append the filepath of <>'s examples into
sys.path,but
-
>>> sys.path
['C:\\Python25\\Lib\\idlelib', 'C:\\WINDOWS\\system32\\python25.zip',
'C:\\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-
win', 'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\
\site-packages', 'E:\x07chieve\x08ook\\diveintopython-pdfzh-cn-5.4b\
\diveintopythonzh-cn-5.4b\\py']
>>> import fileinfo#fileinfo is a module in the path

Traceback (most recent call last):
 File "", line 1, in 
   import fileinfo
ImportError: No module named fileinfo

-
Can anyone tell me the reason of the above and how to add  paths to
python path except adding them in the enviroment path.
Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help on file storage for split multi part download

2008-03-06 Thread coolman . guron
On Mar 7, 1:38 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> En Thu, 06 Mar 2008 14:34:27 -0200, <[EMAIL PROTECTED]> escribi�:
>
> > storage class which can write the file splits that are currently being
> > downloaded to the disk. this is exactly what other download
> > accelerators do, i guess.
>
> > can this be done using the python file class?? i am pretty good at
> > handling file uploads (at server end) this is the first time i have to
> > think the other way round.
>
> Uh, unless I misundersand you, a standard file object is enough. First
> create a file with the required size (open(...,'wb'), seek(n-1),
> write(chr(0))). For each downloaded chunk you have to know its position in
> the file; then just seek() and write() it.
>
> --
> Gabriel Genellina

well yes its possible to use the file class that way.

BUT the thing thats going in my mind is thread safety. i plan to start
each part of the file download in a different thread. and then when
each thread had downloaded more than 100kb (or eof or boundary
reached) write the buffer to the disk. can this be achieved using
mutex ? i have never shared objects between threads.

is there a way to write this without using threads at all ???
-- 
http://mail.python.org/mailman/listinfo/python-list

jython jmx tutorials?

2008-03-06 Thread pythonNEWB
I am looking to try to build a simple, generic tool for basic
monitoring and gathering of config information from java app servers
such as weblogic (I know WLST is there, but I want the exercise and
for it to work with more than just weblogic), tomcat and jboss using
jython and jmx.  Can anyone recommend any docs or sites that might
have any useful info on those topics that might help me get started? I
have been using python for a year or two now, but my java skills are
pretty beginner...

TIA.

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


Re: Looking for very light weight template library (not framework)

2008-03-06 Thread Bernard
Cheetah! Cheetah! Cheetah!

On 6 mar, 20:56, "Malcolm Greene" <[EMAIL PROTECTED]> wrote:
> New to Python and looking for a template library that allows Python
> expressions embedded in strings to be evaluated in place. In other words
> something more powerful than the basic "%(variable)s" or "$variable"
> (Template) capabilities.
>
> I know that some of the web frameworks support this type of template
> capability but I don't need a web framework, just a library that
> supports embedded expression evaluation.
>
> Use case:
>
> myOutput = """\
>
> The total cost is {{invoice.total}}.
>
> This order will be shipped to {{invoice.contact}} at the following
> address:
>
> {{invoice.address}}
>
> This order was generated at {{some date/time expression}}
> """
>
> Any suggestions appreciated.
>
> Malcolm

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


Fwd: OT: Failed saving throw

2008-03-06 Thread Michael Wieher
build a tomb?

...or raid one?

-- Forwarded message --
From: Aahz <[EMAIL PROTECTED]>
Date: 5 Mar 2008 07:36:37 -0800
Subject: OT: Failed saving throw
To: python-list@python.org

For anyone who hasn't heard, E. Gary Gygax died yesterday.  Some people
think we should build a tomb in his honor.  ;-)
--
Aahz ([EMAIL PROTECTED])   <*>
http://www.pythoncraft.com/

"All problems in computer science can be solved by another level of
indirection."  --Butler Lampson

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

Re: Looking for very light weight template library (not framework)

2008-03-06 Thread Jeff McNeil
Cheetah (http://www.cheetahtemplate.org/) and Mako
(http://www.makotemplates.org/) come to mind.  Isn't there some long
running joke about new Python programmers creating their own template
language or something, too? =)

I know you said you don't want a web framework, but I've always been a
fan of Django templates in that they don't really allow you to do too
much inside the template itself. That seems to help keep a lot of
ex-PHP/JSP/ASP programmers I know honest.


On 3/6/08, Erik Max Francis <[EMAIL PROTECTED]> wrote:
> Malcolm Greene wrote:
>
>  > New to Python and looking for a template library that allows Python
>  > expressions embedded in strings to be evaluated in place. In other words
>  > something more powerful than the basic "%(variable)s" or "$variable"
>  > (Template) capabilities.
>  >
>  > I know that some of the web frameworks support this type of template
>  > capability but I don't need a web framework, just a library that
>  > supports embedded expression evaluation.
>
> ...
>  > Any suggestions appreciated.
>
>  EmPy may work:
>
> http://www.alcyone.com/software/empy/
>
>  Your template would look something like:
>
>
>  myOutput = """\
>
>  The total cost is @invoice.total.
>
>  This order will be shipped to @invoice.contact at the following
>  address:
>
>  @invoice.address
>
>
> This order was generated at @time.ctime()
>  """
>
>  This could be instrumented with something as simple as:
>
>   >>> import em, time
>
>  >>> myOutput = """\
>  ...
>  ... The total cost is @invoice.total.
>  ...
>  ... This order will be shipped to @invoice.contact at the following
>  ... address:
>  ...
>  ... @invoice.address
>  ...
>
> ... This order was generated at @time.ctime()
>  ... """
>   >>>
>   >>> class Invoice: pass
>  ...
>   >>> invoice = Invoice()
>   >>> invoice.total = "$123.45"
>   >>> invoice.contact = "Jack McCoy"
>   >>> invoice.address = "1 Police Plaza\nNew York City, NY"
>   >>> print em.expand(myOutput, globals())
>
>  The total cost is $123.45.
>
>  This order will be shipped to Jack McCoy at the following
>  address:
>
>  1 Police Plaza
>  New York City, NY
>
>  This order was generated at Thu Mar  6 18:41:58 2008
>
>
>  --
>  Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
>   San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
>There's a reason why we / Keep chasing morning
> -- Sandra St. Victor
>
> --
>  http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for very light weight template library (not framework)

2008-03-06 Thread Carl Banks
On Mar 6, 8:56 pm, "Malcolm Greene" <[EMAIL PROTECTED]> wrote:
> New to Python and looking for a template library that allows Python
> expressions embedded in strings to be evaluated in place. In other words
> something more powerful than the basic "%(variable)s" or "$variable"
> (Template) capabilities.
>
> I know that some of the web frameworks support this type of template
> capability but I don't need a web framework, just a library that
> supports embedded expression evaluation.
>
> Use case:
>
> myOutput = """\
>
> The total cost is {{invoice.total}}.
>
> This order will be shipped to {{invoice.contact}} at the following
> address:
>
> {{invoice.address}}
>
> This order was generated at {{some date/time expression}}
> """
>
> Any suggestions appreciated.


You could do something like this with a single function.  For
instance:


import re

def apply_template(text,env):
def eval_in_env(m):
return str(eval(m.group(1),env))
return re.sub(r"{{(.*?)}}",eval_in_env,text)


Where env is a dict with the variables you want to evaluate (locals()
could be a good choice for this).

Standard warning about usage of eval: don't use this with untrusted
input or Bad Things can happen.


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


Re: access to base class __init__

2008-03-06 Thread Sam
Dennis Lee Bieber wrote:

> 
> I'm not sure why you need to subclass from threading.Thread if all
> the thread control is being done internal to this class. Subclassing
> means being able to do things like:
> 
Well it was the first thing that occured to me how to have 
private data for each thread ( IP, PORT , CURDIR if I decide to serve
files. ) although I did come across some private_data CLASS in the docs.


> mySH = client_socket_handler(some, args)
> ...
> mySh.start()

hope I can call self.start() from __init__() or self.socket_handler()

> 
> ...   ie; instances of your class behave just like an extended instance of
> the Thread class; but the user of this class never sees that it IS a
> thread. I believe the other facet is that when subclassing from Thread,
> one overloads the run() method AS the target instead of passing some
> other function as a target argument and letting the parent run() method
> call it.
> 
> 
> So why not just make the thread an attribute of the class instead.
> 
> 
Maybe that would be clearer. Starting to wonder if I could return thread 
name this way, then  again, I think part reason for this aproach was the
fact that once started it could finish/crash  all on it's lonesome and 
it's instance could wait for garbage collection.

>> self.socket = cs
>> self.rhost_addr = remote_address
>> print "client_socket_handler.__init__(): ", self.socket,
>> self.rhost_addr
>> #t1 = threading.Thread( None,self.socket_handler, None, (5,78) )
>> #t1.start()
> 
> Which is about what you were doing here, but should have used
> self.t1 =...
> self.t1.start()
> 
Well this shouldn't realy be here just stuff I pasted over.
Which brings me to a question how to start my thread internaly. 
Once I managed to call __init__() I should be able to call 
self.start() nicht var? or is it vahr?

>> self.start()
>> print "client_socket_handler.__init__(): ", self.socket,
>> self.rhost_addr
>> print "client_socket_handler.__init__(): enumerate()",
>> threading.enumerate()
>> 
>> def socket_handler( self, invar, indict ):
> 
> You aren't passing any arguments to this method.
> 
>> threadname = self.getName()
>> print "\"%s started\"" % threadname
>> print "client_socket_handler.socket_handler() invar: ", invar
>> instr = self.socket.recv( 500 )
>> #print instr
>> req_lines = string.split( instr, "\r" )
>> for line in req_lines:
>> line.strip( "\n")
> 
> What do you expect the behavior to be if a new-line is embedded and
> not adjacent to a carriage return?
> 
oops:
#handle macs
self.socket.send( "500 Inferior systems not permited.\r\n" )
self.socket.close()

Heh. Besides I don't think NL is permisible as line separator. 
the command is at the beginnign and I don't expect to support 
any multitude of tags.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for very light weight template library (not framework)

2008-03-06 Thread Erik Max Francis
Malcolm Greene wrote:

> New to Python and looking for a template library that allows Python
> expressions embedded in strings to be evaluated in place. In other words
> something more powerful than the basic "%(variable)s" or "$variable"
> (Template) capabilities.
> 
> I know that some of the web frameworks support this type of template
> capability but I don't need a web framework, just a library that
> supports embedded expression evaluation.
...
> Any suggestions appreciated.

EmPy may work:

http://www.alcyone.com/software/empy/

Your template would look something like:

myOutput = """\

The total cost is @invoice.total.

This order will be shipped to @invoice.contact at the following
address:

@invoice.address

This order was generated at @time.ctime()
"""

This could be instrumented with something as simple as:

 >>> import em, time
 >>> myOutput = """\
...
... The total cost is @invoice.total.
...
... This order will be shipped to @invoice.contact at the following
... address:
...
... @invoice.address
...
... This order was generated at @time.ctime()
... """
 >>>
 >>> class Invoice: pass
...
 >>> invoice = Invoice()
 >>> invoice.total = "$123.45"
 >>> invoice.contact = "Jack McCoy"
 >>> invoice.address = "1 Police Plaza\nNew York City, NY"
 >>> print em.expand(myOutput, globals())

The total cost is $123.45.

This order will be shipped to Jack McCoy at the following
address:

1 Police Plaza
New York City, NY

This order was generated at Thu Mar  6 18:41:58 2008

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
   There's a reason why we / Keep chasing morning
-- Sandra St. Victor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Flash interface for a python program

2008-03-06 Thread Kay Schluehr
On 7 Mrz., 01:46, icarus <[EMAIL PROTECTED]> wrote:
> Is it possible to call an external python program, through a Flash
> interface?
>
> Meaning, I create a Flash window with a button.  When I press that
> button, it automagically invokes the external python program.  Is that
> possible? Any books/online tutorials you can recommend
> me?
>
> I guess I'm looking for alternatives in the area of GUI development.

You might look at PyAMF for data-bindings.

http://pyamf.org/

An alternative is mentioned in the Flex/Python articles by Bruce
Eckel.

http://www.artima.com/weblogs/viewpost.jsp?thread=208528

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


Looking for very light weight template library (not framework)

2008-03-06 Thread Malcolm Greene
New to Python and looking for a template library that allows Python
expressions embedded in strings to be evaluated in place. In other words
something more powerful than the basic "%(variable)s" or "$variable"
(Template) capabilities.

I know that some of the web frameworks support this type of template
capability but I don't need a web framework, just a library that
supports embedded expression evaluation.

Use case:

myOutput = """\

The total cost is {{invoice.total}}.

This order will be shipped to {{invoice.contact}} at the following
address:

{{invoice.address}}

This order was generated at {{some date/time expression}}
"""

Any suggestions appreciated.

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


Re: Difference between 'function' and 'method'

2008-03-06 Thread castironpi
On Mar 6, 7:10 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> En Thu, 06 Mar 2008 22:56:33 -0200, <[EMAIL PROTECTED]> escribió:
>
> > On Mar 6, 5:35 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
>
> >> p = P()
> >> print p.bar.func_name # -> bar
> >> p.bar.im_func.anotherattribute = 1
> >> print p.bar.anotherattribute # -> 1
>
> >> (the attribute must be set on the *function* itself if you want it to  
> >> be  
> >> somewhat persistent; methods are usually volatile objects)
>
> > You read my mind.
>
> You could try to write in a way that reading your mind isn't necesary...
>
> > I was just getting:
> >    assert p.bar is p.bar
> > and failing.
>
> > But if you set them on im_func, instances don't have their own.
>
> Instances don't have their own methods either. What do you actually want  
> to do? If you need a method with per-instance attributes, that looks like  
> another object to me.

Hi, great thanks for giving me your ear this far.

First of all, -I have it working-.  But the design isn't encapsulated
quite right.  Here's what I have.  69 lines, so I'll ask to post it
first.  The gist is:

class ISS( SS, metaclass= autonaming ):
message= MessageDec()
@message
def user_act( msg, self, change ):
print( 'user act self change',
msg, self, change )

IncomingServer... but it originally came from 'clientsideserver.'

iss= ISS()

class OSS( SS, metaclass= autonaming ):
message= MessageDec()
user_act= message.out()

oss= OSS()

oss.message is a abstraction class that writes the method name into a
string, then sends it to OSS... outgoingserver or serverside.

Now that I'm writing it, and this is important, -to- the -newsgroup-,
I realize you could do it with a simple wrapper... include the
function name in parameters and call the pickler and send.

OSS then looks like this:

def something_happens( *ar ):
self.user_act( something_about( *ar ) )

So the message.out() instance pickles ( 'user_act', ar ) and sends
it.  Then iss.incoming receives it, unpickles that string, gets
'user_act' from self, and invokes.

The cool part is the declaration of user_act= message.out(), which
uses a metaclass to assign its own name, and returns a function which
includes the object in its signature.  Cool.

Yes it's working and a little slack.  However-: this is the cool
part.  I'd like messages to know which instance they came from, and
perform the sending & receiving encapsulated on their own--- not to
subclass class SS( Sending ): with various behaviors: that is, to
assign them as class attributes rather than superclasses.

The dreaming comes in here--- I'd like the class to look just like
this.  Tell me it's possible.

And I changed my mind on posting the code, here's the whole thing.
Just get SS.send and SS.incoming into MessageDec.  har har har har
har.  Change anything before class OSS:.  How does a weak reference
lookup in doublebound sound?



from functools import wraps
import pickle

class doublebound:
__slots__ = ( '_func', 'assname', '_orig' )
def __init__( self, func ):
@wraps( func )
def f( *ar, **kws ):
return func( self, *ar, **kws )
self.assname= None
self._func, self._orig= f, func
def __get__( self, instance, owner ):
return self._func.__get__( instance, owner )

class autonaming( type ):
def __init__( self, name, bases, namespace ):
for k,v in namespace.items():
if isinstance( v, doublebound ):
v.assname= k

class Sending:
def send( *ar, **kws ): raise NotImplemented

class MessageDec:
def __call__( self, fun ):
return doublebound( fun )
def out( self ):
return doublebound( self._send )
def _send( self, message, other, *ar, **kws ):
return other.send(
message.assname, *ar, **kws )

class SS( Sending ):
def send( self, methn, *ar, **kws ):
transpmessage= methn, ar, kws
transpstr= pickle.dumps( transpmessage )
self.far.incoming( transpstr )
def incoming( self, transpstr ):
transpmessage= pickle.loads( transpstr )
methn, ar, kws= transpmessage
meth= getattr( self, methn )
meth( *ar, **kws )

class OSS( SS, metaclass= autonaming ):
message= MessageDec()
user_act= message.out()
somethingelse= message.out()
@message
def amessage( msg, self, *change ):
print( 'something else', change )

class ISS( SS, metaclass= autonaming ):
message= MessageDec()
@message
def user_act( msg, self, change ):
print( 'user act self change',
msg, self, change )
@message
def s

Re: Difference between 'function' and 'method'

2008-03-06 Thread Gabriel Genellina
En Thu, 06 Mar 2008 22:56:33 -0200, <[EMAIL PROTECTED]> escribió:
> On Mar 6, 5:35 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
>>
>> p = P()
>> print p.bar.func_name # -> bar
>> p.bar.im_func.anotherattribute = 1
>> print p.bar.anotherattribute # -> 1
>>
>> (the attribute must be set on the *function* itself if you want it to  
>> be  
>> somewhat persistent; methods are usually volatile objects)
>
> You read my mind.

You could try to write in a way that reading your mind isn't necesary...

> I was just getting:
>assert p.bar is p.bar
> and failing.
>
> But if you set them on im_func, instances don't have their own.

Instances don't have their own methods either. What do you actually want  
to do? If you need a method with per-instance attributes, that looks like  
another object to me.

-- 
Gabriel Genellina

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


Re: While executing the class definition which object is referenced by the first argument of the class method, Y r Object attributes not allowed as default arguments

2008-03-06 Thread Gabriel Genellina
En Thu, 06 Mar 2008 22:48:42 -0200, Krishna <[EMAIL PROTECTED]>  
escribi�:

 class Test(object):
> ... def __init__(self):
> ... self.a= 2
> ... def func(self, k = self.a):
> ... print k
> ...
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "", line 4, in Test
> NameError: name 'self' is not defined

>
> In the 'definition of the class', what would the first argument 'self'
> in the methods evaluate to; when we have an object defined, it is
> bound to the object reference, but what happens while the class
> definition is executed, which I believe happens when the module
> containing the class definition is imported

Function default arguments are evaluated when the function is defined  
(when the class is defined, in this case) so "self" itself has not a  
value. Try this instead:

 def func(self, k=None):
 if k is None:
 k = self.a
 print k

If None is an allowed argument, use a special marker instead:

_marker=object()
...

 def func(self, k=_marker):
 if k is _marker:
 k = self.a
 ...

-- 
Gabriel Genellina

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

Re: How to Encode String of Raw UTF-8 into Unicode?

2008-03-06 Thread Henry Chang
Awesome, that works.  Thank you so much!  My confusion of the
different format made this harder than it should.

On Thu, Mar 6, 2008 at 4:53 PM, Gabriel Genellina
<[EMAIL PROTECTED]> wrote:
> En Thu, 06 Mar 2008 22:43:58 -0200, Henry Chang <[EMAIL PROTECTED]>
>  escribi�:
>
>
>  > Suppose I start out with a raw string of utf-8 code points.
>
>  "utf-8 code points"???
>  Looks like a utf-8 encoded string, and then written in hex format.
>
>
>  >   raw_string = "68656E727963"
>  >
>  > I can coerce it into proper unicode format by slicing out two
>  > characters at a time.
>  >
>  >   unicode_string = u"\x68\x65\x6E\x72\x79\x63"
>  >
>  >   >>>  print unicode_proper
>  >   >>> henry
>  >
>  > My question: is there an existing function that can do this (without
>  > having to manually slicing the raw text string)?
>
>  Two steps: first decode from hex to string, and then from utf8 string to
>  unicode:
>
>  py> raw_string = "68656E727963"
>  py> raw_string.decode("hex")
>  'henryc'
>  py> raw_string.decode("hex").decode("utf8")
>  u'henryc'
>
>  --
>  Gabriel Genellina
>
>  --
>  http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Difference between 'function' and 'method'

2008-03-06 Thread castironpi
On Mar 6, 5:35 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> En Wed, 05 Mar 2008 02:57:58 -0200, <[EMAIL PROTECTED]> escribi�:
>
>
>
>
>
> >> > > >> >> Can you overload -type-'s decision of what to 'bind'?...  
> >> whenever it
> >> > > >> >> is it makes it.
>
> >> > > >> Use delegation instead of inheritance. This class is almost  
> >> > > >> indistinguishable from a true function (when used as a method):
>
> >> Notwithstanding.  Now bar has a name.
> > Now func has it.
>
> > from functools import wraps
> > class myfunction:
> >     __slots__ = ('func','name')
> >     #
> >     def __init__(self, func):
> >       @wraps( func )
> >       def f( *ar, **kws ):
> >          return func( self, *ar, **kws )
> >       object.__setattr__(self, 'func', f)
> >       object.__setattr__(self, 'name', None)
> >     #
> >     def __get__(self, instance, owner):
> >         print( "__get__ called for",instance )
> >         return self.func.__get__(instance, owner)
> >     #
> >     def __getattr__(self, name):
> >       return getattr(self.func, name)
> >     #
> >     def __setattr__(self, name, value):
> >       object.__setattr__(self.func, name, value)
>
> > class mymeta( type ):
> >     def __init__( self, name, bases, namespace ):
> >         for k,v in namespace.items():
> >             if isinstance( v, myfunction ):
> >                 v.name= k
>
> > class P( metaclass= mymeta ):
> >     def foo(self, x): print( 'foo',x )
> >     #
> >     @myfunction
> >     def bar( fob,self, x): print( 'bar',fob,x )
>
> > p= P()
> > p.foo( 0 )
> > p.bar( 1 )
> > print( p.bar )
> > print( p.bar.name )
>
> Mmm, looks too complicated and I don't see any advantage over the original  
> code. Functions already know their (original) name: func_name. If `name`  
> was just an example, note that functions already have writeable attributes  
> too, and my code exposes them as well. This should work with that version  
> (untested):
>
> p = P()
> print p.bar.func_name # -> bar
> p.bar.im_func.anotherattribute = 1
> print p.bar.anotherattribute # -> 1
>
> (the attribute must be set on the *function* itself if you want it to be  
> somewhat persistent; methods are usually volatile objects)

You read my mind.

I was just getting:
   assert p.bar is p.bar
and failing.

But if you set them on im_func, instances don't have their own.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to Encode String of Raw UTF-8 into Unicode?

2008-03-06 Thread Gabriel Genellina
En Thu, 06 Mar 2008 22:43:58 -0200, Henry Chang <[EMAIL PROTECTED]>  
escribi�:

> Suppose I start out with a raw string of utf-8 code points.

"utf-8 code points"???
Looks like a utf-8 encoded string, and then written in hex format.

>   raw_string = "68656E727963"
>
> I can coerce it into proper unicode format by slicing out two
> characters at a time.
>
>   unicode_string = u"\x68\x65\x6E\x72\x79\x63"
>
>   >>>  print unicode_proper
>   >>> henry
>
> My question: is there an existing function that can do this (without
> having to manually slicing the raw text string)?

Two steps: first decode from hex to string, and then from utf8 string to  
unicode:

py> raw_string = "68656E727963"
py> raw_string.decode("hex")
'henryc'
py> raw_string.decode("hex").decode("utf8")
u'henryc'

-- 
Gabriel Genellina

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

While executing the class definition which object is referenced by the first argument of the class method, Y r Object attributes not allowed as default arguments

2008-03-06 Thread Krishna
>>> class Test(object):
... def __init__(self):
... self.a= 2
... def func(self, k = self.a):
... print k
...
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 4, in Test
NameError: name 'self' is not defined
>>>

In the 'definition of the class', what would the first argument 'self'
in the methods evaluate to; when we have an object defined, it is
bound to the object reference, but what happens while the class
definition is executed, which I believe happens when the module
containing the class definition is imported

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


Flash interface for a python program

2008-03-06 Thread icarus
Is it possible to call an external python program, through a Flash
interface?

Meaning, I create a Flash window with a button.  When I press that
button, it automagically invokes the external python program.  Is that
possible? Any books/online tutorials you can recommend
me?

I guess I'm looking for alternatives in the area of GUI development.

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


How to Encode String of Raw UTF-8 into Unicode?

2008-03-06 Thread Henry Chang
Hi everyone,

Suppose I start out with a raw string of utf-8 code points.

  raw_string = "68656E727963"

I can coerce it into proper unicode format by slicing out two
characters at a time.

  unicode_string = u"\x68\x65\x6E\x72\x79\x63"

  >>>  print unicode_proper
  >>> henry

My question: is there an existing function that can do this (without
having to manually slicing the raw text string)?

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


Re: Ncurses not found - embedded linux

2008-03-06 Thread blaine
> > I hope this is trivial, and I apologize ahead of time if so.  Would
> > this perhaps be a compilation issue? Something we have to turn on in
> > the python compile?
>
> Usually, you need not only the libraries but also the headers at
> compilation time. Most probably these were missing.
>
> Diez

Thank you for our response.  Do you mean that the ncurses header
should be in /usr/include upon compilation of python?  Will python
automatically pick up on these headers, or would I need to change
compilation options? Thanks! -Blaine
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Internet Explorer 8 beta release

2008-03-06 Thread Matt Nordhoff
Colin J. Williams wrote:
> Isn't compliance with the W3C standard 
> the best way of achieving multiple
> browser rendering?

Exactly. IE 8 is supposed to be significantly less horrible. It won't
catch up completely, but perhaps by IE 9 it will.

Or this is all a joke, Microsoft buys Opera and shuts them down.

(Anyway, I marked the OP as spam.)
-- 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Classes and modules are singletons?

2008-03-06 Thread Gabriel Genellina
En Thu, 06 Mar 2008 20:45:09 -0200, <[EMAIL PROTECTED]> escribi�:

> I'd like to question the source of the definition of C.__eq__.
>
> Observation:
>
 class C: pass
> ...
 class D: pass
> ...
 C== D
> False
>
> What is different about them?  I've created two empty classes, nothing
> more.

Their __name__ attribute?
Types are compared by their memory addresses, not by contents, and that's  
enough and efficient for most people. If you require something different,  
use a metaclass.

-- 
Gabriel Genellina

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

Re: Internet Explorer 8 beta release

2008-03-06 Thread Colin J. Williams
shsha wrote:
> Internet Explorer 8 beta release is for developers, and Microsoft's
> Dean Hachamovitch promised at MIX08 that IE8 will make it easier to
> build Web sites for multiple browsers and stop wasting developers'
> time. Microsoft's IE8 features Activities for looking up information
> and Webslices to watch portions of Web sites for updates.
> 
> more about MS
> 
> http://www.toptechnews.com/story.xhtml?story_id=0120013PBF8O
> 
> _
> get wild all the action http://www.getaction4ever.com

Isn't compliance with the W3C standard 
the best way of achieving multiple
browser rendering?

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


How to clear a list (3 ways).

2008-03-06 Thread francois . petitjean

Consider the following code :
#!/usr/bin/env python
# -*- coding: latin_1 -*-

"""
container.py  how to clear a container
"""

class Container(object):
def __init__(self):
self.elts = {}
self.parts = []
def clear(self):
self.elts.clear()  #  for a dictionary it's clear :-)
self.parts = []   #  (1)
 #  self.parts[:] = []#  (2)
 #  del self.parts[:] #  (3)
def __len__(self):
return len(self.parts)
def add_predicate(self, part):
"""return True if part should be added (to override)"""
return True
def add(self, part):
"""return True if part is added"""
res = self.add_predicate(part)
if res:
self.parts.append(part)
self.elts[str(part)] = part # or wahtever
return res
def replace_parts(self, values):
"""return True if all values are added/replaced"""
acceptable = all(map(self.add_predicate, values))  # FIXME
itertools.imap ?
if not acceptable:
return acceptable
self.parts[:] = values
# TODO elts
return acceptable

Container1 = Container

class Container2(Container):
def clear(self):
self.elts.clear()  #  for a dictionary it's clear :-)
self.parts[:] = []#  (2)

class Container3(Container):
def clear(self):
self.elts.clear()  #  for a dictionary it's clear :-)
del self.parts[:] #  (3)


Solution (1) is somewhat broken  (see the test_container.rst hereafter) but
often used. For instance in configobj we have
def clear(self):
"""
A version of clear that also affects scalars/sections
Also clears comments and configspec.

Leaves other attributes alone :
depth/main/parent are not affected
"""
dict.clear(self)
self.scalars = []
self.sections = []
self.comments = {}
self.inline_comments = {}
self.configspec = {}

What idiom do you use (and prefer) ?


test_container.rst  can be used like this :
>>> import doctest
>>> doctest.testfile('test_container.rst', encoding='latin_1')
(nfails, ntests) is printed.
===
test_container.rst
===

>>> from container import Container1, Container2, Container3
>>> cont1 = Container1()
>>> cont1.add(1)
True
>>> cont1.add(2)
True
>>> cont1.add(3)
True
>>> parts = cont1.parts
>>> parts
[1, 2, 3]

The client has cached the parts attribute.
Solution (1) is not robust, is the parts attribute in the public API ?
>>> cont1.clear()
>>> parts
[1, 2, 3]
>>> cont1.parts, parts
([], [1, 2, 3])

We now have two different objects.

>>> cont2 = Container2()
>>> cont2.add(21)
True

>>> cont2.add(22)
True
>>> cont2.add(23)
True
>>> parts2 = cont2.parts
>>> parts2
[21, 22, 23]
>>> cont2.clear()
>>> parts2
[]
>>> cont1.parts, parts
([], [1, 2, 3])

>>> cont3 = Container3()
>>> cont3.add(31)
True
>>> cont3.add(32)
True
>>> parts3 = cont3.parts
>>> cont3.add(33)
True
>>> parts3
[31, 32, 33]
>>> cont3.clear()
>>> parts3
[]

Test de replace_parts

>>> cont3 = Container3()
>>> len(cont3)
0
>>> parts3 = cont3.parts
>>> cont3.add(30)
True
>>> parts3
[30]
>>> cont3.replace_parts( (31, 32, 33) )
True
>>> parts3
[31, 32, 33]
>>>


Regards.
   NOTICE: This message contains information which is confidential and the
   copyright of our company or a third  party. If you are not the intended
   recipient of this message please delete it and destroy all copies. If
   you
   are the intended recipient of this message you should not disclose or
   distribute this message to third parties without the consent of our
   company. Our company does not represent, warrant and/or guarantee that
   the integrity of this message has been maintained nor that the
   communication is free of virus, interception or interference. The
   liability of our company is limited by our General Conditions of
   Services.
   Nota : Ce message contient des informations confidentielles propriété de
   notre société et/ou d'un tiers. Si vous n’êtes pas parmi les
   destinataires désignés de ce message, merci de l'effacer ainsi que
   toutes ses copies. Si vous êtes parmi les destinataires désignés de ce
   message, prière de ne pas le divulguer ni de le transmettre à des tiers
   sans l’accord de notre société. Notre société ne peut garantir que
   l’intégrité de ce message a été préservée ni que la présente
   communication est sans virus, interception ou interférence. La
   responsabilité de notre société est limitée par nos Conditions Générales
   de Services.-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Classes and modules are singletons?

2008-03-06 Thread castironpi
On Mar 6, 3:24 pm, [EMAIL PROTECTED] (Aahz) wrote:
> In article <[EMAIL PROTECTED]>,
> Steven D'Aprano  <[EMAIL PROTECTED]> wrote:
>
>
>
> >I accept my question about classes being singletons is not well-formed,
> >not even in my own mind. I guess one way of asking is, for any two class
> >objects (not instances) C1 and C2, does "C1 == C2" imply "C1 is C2"?
>
> Even that stricture fails under the presence of metaclasses.  ;-)  But
> answering your real question, I don't remember off-hand the required
> sequence, but it is possible to import a class two different ways such
> that the classes are not the object.  This can cause problems with e.g.
> pickle.  Within a single module, given a class defined only once within
> that module, the class will be a singleton.
> --
> Aahz ([EMAIL PROTECTED])           <*>        http://www.pythoncraft.com/
>
> "All problems in computer science can be solved by another level of    
> indirection."  --Butler Lampson

I'd like to question the source of the definition of C.__eq__.

Observation:

>>> class C: pass
...
>>> class D: pass
...
>>> C== D
False

What is different about them?  I've created two empty classes, nothing
more.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Protocol for thread communication

2008-03-06 Thread castironpi
> > Does anyone have any recommended ideas/ways of implementing a proper
> > control and status protocol for communicating with threads?  I have a
> > program that spawns a few worker threads, and I'd like a good, clean way
> > of communicating the status of these threads back to the main thread.
> > Each thread (wrapped in a very simple class) has only a few states, and
> > progress levels in those states.  And sometimes they can error out,
> > although if the main thread knew about it, it could ask the thread to
> > retry (start over).  How would any of you do this?  A callback method
> > that the thread can call (synchronizing one-way variables isn't a
> > problem)?  A queue?  How would the main thread check these things?
> > Currently the main thread is polling some simple status variables.  This
> > works, and polling will likely continue to be the simplest and easiest
> > way, but simple status variables are very limited.  Are there any
> > pythonic patterns people have developed for this.

There is the PyThreadState_SetAsyncExc API.  "To prevent naive misuse,
you must write your own C extension to call this."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Classes and modules are singletons?

2008-03-06 Thread castironpi
On Mar 6, 2:57 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> On Thu, 06 Mar 2008 11:06:50 -0800, castironpi wrote:
> > On Mar 6, 8:30 am, Carl Banks <[EMAIL PROTECTED]> wrote:
> >> Anyway, the answer to what you are probably asking is No.  Try this:
>
> >> >>>import module
> >> >>>c1 = module.Someclass
> >> >>>reload(module)
> >> >>>c2 = module.Someclass
> >> >>>c1 is c2
>
> > What about
>
>  o= object()
>  b1= o.someattr
>  reload( o )
>  b2= o.someattr
>  b1 is b2
>
> > ?
>
> You are really a bit thick, a troll, or a bot.

The point was, that's one difference between classes and modules: you
can't reload classes plonk.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: system32 directory

2008-03-06 Thread Gabriel Genellina
En Thu, 06 Mar 2008 19:15:17 -0200, Robert Dailey <[EMAIL PROTECTED]>  
escribi�:

> On Thu, Mar 6, 2008 at 2:42 AM, Tim Golden <[EMAIL PROTECTED]> wrote:
>>
>>  >>> import win32api
>>  >>> win32api.GetSystemDirectory ()
>> 'C:\\WINDOWS\\system32'
>
> I was aiming to figure out if the standard modules shipped with Python  
> could
> do this already before I started using 3rd party libraries. Thanks.

Use ctypes then:

py> from ctypes import *
py> windll.kernel32.GetSystemDirectoryA
<_FuncPtr object at 0x00A0F918>
py> GetSystemDirectory = windll.kernel32.GetSystemDirectoryA
py> buffer = create_string_buffer(260)
py> GetSystemDirectory(buffer, sizeof(buffer))
19
py> buffer.value
'C:\\WINDOWS\\system32'

-- 
Gabriel Genellina

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

Re: system32 directory

2008-03-06 Thread Mike Driscoll
On Mar 6, 3:49 pm, Trent Mick <[EMAIL PROTECTED]> wrote:
> > I was aiming to figure out if the standard modules shipped with Python
> > could do this already before I started using 3rd party libraries. Thanks.
>
> You could also manage it with the ctypes module, if you consider that
> standard: it is in the python.org and ActivePython distros as of Python 2.5.
>
> Cheers,
> Trent
>
> --
> Trent Mick
> trentm at activestate.com

As I understand it, ActivePython includes PyWin32 by default, unlike
the "Official" Python distro.

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


Re: Python on the renderfarm

2008-03-06 Thread Mike Driscoll
On Mar 6, 3:35 pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote:
> It is fairly well know that cinematic digital effects are most often
> rendered on *nix machines with efficient numeric 
> code.http://www.linuxjournal.com/article/9951
>
> But Python sometimes has a role too:  from the middile of the above link
>
> '''
> Tippett Studio: Linux Python Pipeline
> JET is a proprietary Python-based system comprising software tools and
> scripts used to implement a visual effects and animation pipeline. "A
> visual effects and animation pipeline is an assembly line of software used
> to organize, automate and facilitate the creation of computer-generated
> imagery", says Darling. "The JET tool is highly customizable, featuring
> XML-based user-interface templates that can be modified to suit specific
> types of artists or production needs. JET uses modular template chunks to
> perform each of the tasks in the pipeline, such as rendering or
> compositing. The templates are implemented as Python objects and are
> centrally located. JET is not only implemented entirely in Python, but it's
> also used to generate Python scripts automatically. These custom scripts
> form unique pipelines for each computer graphics job to run on the
> renderfarm."
>
> '''

That's neat. Phil Tippett has been one of my favorite Special Effects
people and now he's using my favorite programming language too.
Hopefully Python will make Tippett more productive than ILM!

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


Re: system32 directory

2008-03-06 Thread Trent Mick
> I was aiming to figure out if the standard modules shipped with Python 
> could do this already before I started using 3rd party libraries. Thanks.

You could also manage it with the ctypes module, if you consider that 
standard: it is in the python.org and ActivePython distros as of Python 2.5.

Cheers,
Trent

-- 
Trent Mick
trentm at activestate.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Python on the renderfarm

2008-03-06 Thread Terry Reedy
It is fairly well know that cinematic digital effects are most often 
rendered on *nix machines with efficient numeric code.
http://www.linuxjournal.com/article/9951

But Python sometimes has a role too:  from the middile of the above link

'''
Tippett Studio: Linux Python Pipeline
JET is a proprietary Python-based system comprising software tools and 
scripts used to implement a visual effects and animation pipeline. “A 
visual effects and animation pipeline is an assembly line of software used 
to organize, automate and facilitate the creation of computer-generated 
imagery”, says Darling. “The JET tool is highly customizable, featuring 
XML-based user-interface templates that can be modified to suit specific 
types of artists or production needs. JET uses modular template chunks to 
perform each of the tasks in the pipeline, such as rendering or 
compositing. The templates are implemented as Python objects and are 
centrally located. JET is not only implemented entirely in Python, but it's 
also used to generate Python scripts automatically. These custom scripts 
form unique pipelines for each computer graphics job to run on the 
renderfarm.”

'''





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

Re: What is a class?

2008-03-06 Thread Gabriel Genellina
En Thu, 06 Mar 2008 14:40:47 -0200, <[EMAIL PROTECTED]> escribi�:

> On Mar 6, 12:17 am, "Daniel Fetchinson" <[EMAIL PROTECTED]>
> wrote:
>>
>> > What does exec( open( 'modA.py' ).read() ) do?
>>
>
> A more appropriate formulation of the 'question behind the words'
> would have been, 'are there any weird corner cases in which it doesn't
> import modA?  I recognize it doesn't on .pyc and .pyd files, but you
> could say exec( open( 'modA.py' ).read() ) ==> import modA, even if
> import modA =!=> exec( open( 'modA.py' ).read() ) all the time.

Then write the question that way. Working crystall balls are hard to find  
nowadays...

They're different; no module object is created by the exec statement.
When the import machinery determines that certain module isn't already  
loaded, and that the .py version has to be used, it does something like  
this:

newmodule = sys.modules[modulename] = ModuleType(modulename)
# constructor sets __name__ and a null __doc__
newmodule.__builtins__ = current builtins
newmodule.__file__ = filename
code = read from filename and compile it
exec code in newmodule.__dict__

> However, a way of asking that's more direct would have been, "Wait...
> can't you create multiple module instances like that?", but since
> we've already seen successful loadings of at least the builtins,
> that's been treated.

There are ways to create many instances of the same module, but not using  
a plain import statement, or using the API in the intended way.

> Maybe you even hear the right thing if I say,
> "Does exec( open( 'modA.py' ).read() ) do the things of import modA?"

Only in part, as you can see above.

> Yes, I can read the docs, but no, I can't check every possible
> combination of modules.
> The idea behind a singleton is to ensure something.  You want non-
> primary instances impossible to create.  However, if (wording got
> tangled here) for singleton A, if class B does the same thing, just
> has different allocations-- it's own-- then A is still a singleton.
> The writer of B hasn't defeated or contradicted the letter or spirit
> of A.
>
> OP's question might have come from a variety of perspectives.  In some
> ways yes, in others no.  That is, if you try to reinstantiate modA,
> you get the same instance.  But if you try really hard, you get a new
> one.  Are you looking for an extension to import modA that won't
> return an instance that is old?
>
> So far, I know this: modules and classes are both namespaces.  Are
> those singletons?

Strictly speaking, neither classes nor modules are singletons; classes are  
instances of type, and modules are instances of their type, and there are  
many instances of each. We can consider "qualified singletons", where we  
want to have a single instance of a class given certain attributes.

In that sense, modules are "named" singletons; Python tries to ensure  
that, given a module name, the module object returned is always the same  
one - even if you spell the name in different ways. The import statement,  
the __import__ builtin, the imp module, the PyImport_AddModule C function,  
all of them try to ensure that. Of course there are ways to shoot yourself  
in the foot -by example, creating a new module "in the fly" with  
PyModule_New-

On the contrary, classes have no such restrictions. Of course, for classes  
defined at the global level in a module, you can't have two of them with  
the same name, but that's just because the module namespace can't hold two  
values for a single name. But you can create classes dinamically, or  
define them inside a function, or... lots of ways of creating many  
instances of the "same" class, and Python won't enforce them to be always  
the same object.

So, I'd say that modules are named singletons, and classes aren't  
singletons at all.

-- 
Gabriel Genellina

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

Re: OT: Failed saving throw

2008-03-06 Thread Aahz
In article <[EMAIL PROTECTED]>,
Dennis Lee Bieber  <[EMAIL PROTECTED]> wrote:
>On 5 Mar 2008 07:36:37 -0800, [EMAIL PROTECTED] (Aahz) declaimed the
>following in comp.lang.python:
>>
>> For anyone who hasn't heard, E. Gary Gygax died yesterday.  Some people
>> think we should build a tomb in his honor.  ;-)
>
>   Just a tomb? Commission Disney to build a whole dungeon with the
>tomb somewhere inside... Of course, they'd want to charge admission 

You're apparently missing the reference to Tomb of Horrors.  ;-)
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"All problems in computer science can be solved by another level of 
indirection."  --Butler Lampson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Classes and modules are singletons?

2008-03-06 Thread Aahz
In article <[EMAIL PROTECTED]>,
Steven D'Aprano  <[EMAIL PROTECTED]> wrote:
>
>I accept my question about classes being singletons is not well-formed, 
>not even in my own mind. I guess one way of asking is, for any two class 
>objects (not instances) C1 and C2, does "C1 == C2" imply "C1 is C2"?

Even that stricture fails under the presence of metaclasses.  ;-)  But
answering your real question, I don't remember off-hand the required
sequence, but it is possible to import a class two different ways such
that the classes are not the object.  This can cause problems with e.g.
pickle.  Within a single module, given a class defined only once within
that module, the class will be a singleton.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"All problems in computer science can be solved by another level of 
indirection."  --Butler Lampson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a string to the most probable type

2008-03-06 Thread Luis M . González
On 6 mar, 11:27, Pierre Quentel <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I would like to know if there is a module that converts a string to a
> value of the "most probable type" ; for instance :
> - if the string is "abcd" the value is the same string "abcd"
> - string "123" : value = the integer 123
> - string "-1.23" (or "-1,23" if the locale for decimals is ,) : value
> = the float -1.23
> - string "2008/03/06" (the format is also locale-dependant) : value =
> datetime.date(2008,03,06)
>
> Like in spreadsheets, special prefixes could be used to force the
> type : for instance '123 would be converted to the *string* "123"
> instead of the *integer* 123
>
> I could code it myself, but this wheel is probably already invented
>
> Regards,
> Pierre

>>> def convert(x):
if '.' in x:
try: return float(x)
except ValueError: return x
else:
try: return int(x)
except: return x


>>> convert('123')
123
>>> convert('123.99')
123.98
>>> convert('hello')
'hello'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: system32 directory

2008-03-06 Thread Robert Dailey
On Thu, Mar 6, 2008 at 2:42 AM, Tim Golden <[EMAIL PROTECTED]> wrote:
>
> 
> First thing to do when asking "How do I do X in Python under Windows?"
> is to stick -- python X -- into Google and you get, eg:
>
>
> http://aspn.activestate.com/ASPN/docs/ActivePython/2.2/PyWin32/win32api__GetSystemDirectory_meth.html
>
> which suggests that the win32api module from the pywin32 modules has
> the function you need.
> 
>
> And sure enough...
>
> 
> Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
> (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> import win32api
>  >>> win32api.GetSystemDirectory ()
> 'C:\\WINDOWS\\system32'
>  >>>
> 
>
> TJG
>

I was aiming to figure out if the standard modules shipped with Python could
do this already before I started using 3rd party libraries. Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Internet Explorer 8 beta release

2008-03-06 Thread shsha
Internet Explorer 8 beta release is for developers, and Microsoft's
Dean Hachamovitch promised at MIX08 that IE8 will make it easier to
build Web sites for multiple browsers and stop wasting developers'
time. Microsoft's IE8 features Activities for looking up information
and Webslices to watch portions of Web sites for updates.

more about MS

http://www.toptechnews.com/story.xhtml?story_id=0120013PBF8O

_
get wild all the action http://www.getaction4ever.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bit twiddling floating point numbers

2008-03-06 Thread [EMAIL PROTECTED]
On Mar 6, 11:00 am, Bryan Olson <[EMAIL PROTECTED]> wrote:
> Mark Dickinson wrote:
> > Jeff Goldfin wrote:
> >> I can pack and unpack a float into a long
> >> e.g.
> >> struct.unpack('I',struct.pack('f',0.123))[0]
> >> but then I'm not sure how to work with the resulting long.
>
> >> Any suggestions?
>
> > One alternative to using struct is to use math.ldexp and math.frexp:
>
>  m, e = frexp(pi)
>  m
> > 0.78539816339744828
>  e
> > 2
>  int(m*2**53)
> > 7074237752028440L
>
> > Then you can do your bit twiddling on int(m*2**53), before using
> > ldexp to 'repack' the float.
>
> Ah, those are handy. Jeff described his problem: "In particular,
> I would like to round my float to the n most significant bits."
> I think this works:
>
>from math import frexp, ldexp, floor
>
>def round_mantissa(x, nbits):
>shifter = 1 << nbits
>(m, e) = frexp(x)
>m = floor(m * shifter + 0.5) / shifter
>return ldexp(m, e)
>
> --
> --Bryan
Thanks for the help - your function seems to fit the bill even better
than gmpy since I don't need an external module. In my case I'll use
m = floor(m * shifter) / shifter instead of m = floor(m * shifter +
0.5) / shifter

Jeff

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


Re: Classes and modules are singletons?

2008-03-06 Thread Marc 'BlackJack' Rintsch
On Thu, 06 Mar 2008 11:06:50 -0800, castironpi wrote:

> On Mar 6, 8:30 am, Carl Banks <[EMAIL PROTECTED]> wrote:
>> Anyway, the answer to what you are probably asking is No.  Try this:
>>
>> >>>import module
>> >>>c1 = module.Someclass
>> >>>reload(module)
>> >>>c2 = module.Someclass
>> >>>c1 is c2
> 
> What about
> 
 o= object()
 b1= o.someattr
 reload( o )
 b2= o.someattr
 b1 is b2
> 
> ?

You are really a bit thick, a troll, or a bot.

*plonk*

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

Re: help on file storage for split multi part download

2008-03-06 Thread Gabriel Genellina
En Thu, 06 Mar 2008 14:34:27 -0200, <[EMAIL PROTECTED]> escribi�:

> storage class which can write the file splits that are currently being
> downloaded to the disk. this is exactly what other download
> accelerators do, i guess.
>
> can this be done using the python file class?? i am pretty good at
> handling file uploads (at server end) this is the first time i have to
> think the other way round.

Uh, unless I misundersand you, a standard file object is enough. First  
create a file with the required size (open(...,'wb'), seek(n-1),  
write(chr(0))). For each downloaded chunk you have to know its position in  
the file; then just seek() and write() it.

-- 
Gabriel Genellina

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

Re: Py-Extension Irregularity

2008-03-06 Thread Michael Wieher
Ah.  Well, that is true =)

Still, the fact of the file-pointer shifting more than 16-increments to the
right is insane.  Its a simple read(&struct,16) command.

but you're right, the problem might lie elsewhere.  I forgot that using 0
for a sentinel value in two places can confuse a complier (let alone me.)

I ended up fixing it by resetting the file-pointer to zero on re-entry, and
then manually fseeking() to the correct location each time.  Its one extra
command per iteration, but not a huge speed issue.
I feel bad using a global file object, but its that or I open/close it every
time I call the funct.

Thanks for pointing out that bit of confusion =)

2008/3/6, Gabriel Genellina <[EMAIL PROTECTED]>:
>
> En Thu, 06 Mar 2008 13:54:44 -0200, Michael Wieher
> <[EMAIL PROTECTED]> escribi�:
>
>
> > Observe.
> >
> > Python Code Snippet:
> > 
> > ...
> >  66 while i < (self.nPCodes):
> >  67# print "%s:%s" % (self.nPCodes,i)
> >  68 (c,l,sn,f,fn,sz) = tabmodule.getQuestion(i,self.mx3Path)
> >  69 if _debug and sz>0:
> >  70 _newPtrLoc = tabmodule.getMx3Ptr()
> >  71 _diff = _newPtrLoc-_oldPtrLoc
> >  72 _oldPtrLoc = _newPtrLoc
> >  73 if _diff>16:
> >  74 print _diff
> > 
> >
> > C++ Code Snippet:
> > ---
> > 189 static PyObject*
> > 190 tabmodule_getMx3Ptr(PyObject * self, PyObject * args) {
> > 191 int a;
> > 192 a=mx3File.tellg();
> > 193 return Py_BuildValue("i",a);
> > 194 }
> > ...
> >
> > 189 PyObject *
> > 190 tabmodule_getQuestion(PyObject * self, PyObject * args) {
> > 
> > 208mx3File.read((char*)&m_mdx,16);
> > 
> > 237 //if(m_mdx.size==0)
> > 238 return Py_BuildValue("ii",0,0,0,0,0,0);
> > 239 //return Py_BuildValue("ii",m_mdx.compression,
> > m_mdx.location,
> > m_mdx.stacknotes, m_mdx.file, m_mdx.footnote, m_mdx.size);
> > }
> >
> > Output==
> > [EMAIL PROTECTED]:~/MRI/tabModule$ ./tabModule.py
> > [EMAIL PROTECTED]:~/MRI/tabModule$
> >
> > None.  (ie: the _diff is always 16 or less, which is what is SHOULD be,
> > in
> > fact, it is always 16.)
>
>
> Why do you assert that? With those commented out lines, the last item
> returned by getQuestion (sz) is always 0; nothing is printed because sz==0
> and the python code never enters the outer if. From that evidence I can't
> say anything about _diff.
>
>
> > Observe
> >
> > 237 if(m_mdx.size==0)
> > 238 return Py_BuildValue("ii",0,0,0,0,0,0);
> > 239 return Py_BuildValue("ii",m_mdx.compression, m_mdx.location,
> > m_mdx.stacknotes, m_mdx.file, m_mdx.footnote, m_mdx.size);
> >
> > By uncommenting line 237 and 239, we see:
> > ...
> > 64
> > 80
> > 32
> > 32
> > 32
> > 48
> > 128
> > 160
> > 32
> > 32
> > 64
> > 
> >
> > Most of the numbers are still 16, but _diff is often larger than 16, by
> > some
> > multiple.
>
>
> I'd print m_mdx values in the C++ source.
>
>
> > How in Buddah's name is returning a Py_BuildValue() affecting a file
> > pointer
> > that isn't being used at all in the function
>
>
> I don't think this is the cause...
>
> --
> Gabriel Genellina
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Altering imported modules

2008-03-06 Thread Tro
On Wednesday 05 March 2008, Bruno Desthuilliers wrote:
> Tro a écrit :
> > Hi, list.
> >
> > I've got a simple asyncore-based server. However, I've modified the
> > asyncore module to allow me to watch functions as well as sockets. The
> > modified asyncore module is in a specific location in my project and is
> > imported as usual from my classes.
> >
> > Now I'd like to use the tlslite library, which includes an asyncore mixin
> > class. However, tlslite imports "asyncore", which doesn't include my own
> > modifications.
> >
> > I'd like to know if it's possible to make tlslite load *my* asyncore
> > module without changing any of the tlslite code.
>
> Not sure this apply to your case (depends on how asyncore is implemented
> and the exact "modifications"), but monkeypatching is a possible solution.
>
> http://en.wikipedia.org/wiki/Monkey_patch
> http://wiki.zope.org/zope2/MonkeyPatch
> http://mail.python.org/pipermail/python-dev/2008-January/076194.html

Ooh. I didn't know this technique had a name. But that's basically how I'm 
modifying the built-in asyncore in my own class. I override its poll() and 
poll2() methods to do something extra.

However, the issue with tlslite is that it imports the regular asyncore 
instead of the one I wrote, which means that I'd have to somehow monkeypatch 
its "import" statement. I'm guessing that means simply monkeypatching both 
the original asyncore module AND the tlslite module's asyncore attribute with 
my own version.

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


Re: Converting a string to the most probable type

2008-03-06 Thread rockingred
On Mar 6, 3:20 pm, George Sakkis <[EMAIL PROTECTED]> wrote:
> On Mar 6, 9:27 am, Pierre Quentel <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > Hi,
>
> > I would like to know if there is a module that converts a string to a
> > value of the "most probable type" ; for instance :
> > - if the string is "abcd" the value is the same string "abcd"
> > - string "123" : value = the integer 123
> > - string "-1.23" (or "-1,23" if the locale for decimals is ,) : value
> > = the float -1.23
> > - string "2008/03/06" (the format is also locale-dependant) : value =
> > datetime.date(2008,03,06)
>
> > Like in spreadsheets, special prefixes could be used to force the
> > type : for instance '123 would be converted to the *string* "123"
> > instead of the *integer* 123
>
> > I could code it myself, but this wheel is probably already invented
>
> Maybe, but that's a so domain-specific and easy to code wheel that
> it's no big deal reinventing.
>
> George- Hide quoted text -
>
> - Show quoted text -

Actually you could probably write your own code very easily, a couple
of try/except clauses.  I would recommend you try int() first, then
try float(), then try date check and when all else fails leave it a
string.  However, it may be an interesting challenge for those who are
willing to make the attempt.  "Define Cell/Field contents".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Py-Extension Irregularity

2008-03-06 Thread Gabriel Genellina
En Thu, 06 Mar 2008 13:54:44 -0200, Michael Wieher  
<[EMAIL PROTECTED]> escribi�:

> Observe.
>
> Python Code Snippet:
> 
> ...
>  66 while i < (self.nPCodes):
>  67# print "%s:%s" % (self.nPCodes,i)
>  68 (c,l,sn,f,fn,sz) = tabmodule.getQuestion(i,self.mx3Path)
>  69 if _debug and sz>0:
>  70 _newPtrLoc = tabmodule.getMx3Ptr()
>  71 _diff = _newPtrLoc-_oldPtrLoc
>  72 _oldPtrLoc = _newPtrLoc
>  73 if _diff>16:
>  74 print _diff
> 
>
> C++ Code Snippet:
> ---
> 189 static PyObject*
> 190 tabmodule_getMx3Ptr(PyObject * self, PyObject * args) {
> 191 int a;
> 192 a=mx3File.tellg();
> 193 return Py_BuildValue("i",a);
> 194 }
> ...
>
> 189 PyObject *
> 190 tabmodule_getQuestion(PyObject * self, PyObject * args) {
> 
> 208mx3File.read((char*)&m_mdx,16);
> 
> 237 //if(m_mdx.size==0)
> 238 return Py_BuildValue("ii",0,0,0,0,0,0);
> 239 //return Py_BuildValue("ii",m_mdx.compression,  
> m_mdx.location,
> m_mdx.stacknotes, m_mdx.file, m_mdx.footnote, m_mdx.size);
> }
>
> Output==
> [EMAIL PROTECTED]:~/MRI/tabModule$ ./tabModule.py
> [EMAIL PROTECTED]:~/MRI/tabModule$
>
> None.  (ie: the _diff is always 16 or less, which is what is SHOULD be,  
> in
> fact, it is always 16.)

Why do you assert that? With those commented out lines, the last item  
returned by getQuestion (sz) is always 0; nothing is printed because sz==0  
and the python code never enters the outer if. From that evidence I can't  
say anything about _diff.

> Observe
>
> 237 if(m_mdx.size==0)
> 238 return Py_BuildValue("ii",0,0,0,0,0,0);
> 239 return Py_BuildValue("ii",m_mdx.compression, m_mdx.location,
> m_mdx.stacknotes, m_mdx.file, m_mdx.footnote, m_mdx.size);
>
> By uncommenting line 237 and 239, we see:
> ...
> 64
> 80
> 32
> 32
> 32
> 48
> 128
> 160
> 32
> 32
> 64
> 
>
> Most of the numbers are still 16, but _diff is often larger than 16, by  
> some
> multiple.

I'd print m_mdx values in the C++ source.

> How in Buddah's name is returning a Py_BuildValue() affecting a file  
> pointer
> that isn't being used at all in the function

I don't think this is the cause...

-- 
Gabriel Genellina

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

Re: Converting a string to the most probable type

2008-03-06 Thread George Sakkis
On Mar 6, 9:27 am, Pierre Quentel <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I would like to know if there is a module that converts a string to a
> value of the "most probable type" ; for instance :
> - if the string is "abcd" the value is the same string "abcd"
> - string "123" : value = the integer 123
> - string "-1.23" (or "-1,23" if the locale for decimals is ,) : value
> = the float -1.23
> - string "2008/03/06" (the format is also locale-dependant) : value =
> datetime.date(2008,03,06)
>
> Like in spreadsheets, special prefixes could be used to force the
> type : for instance '123 would be converted to the *string* "123"
> instead of the *integer* 123
>
> I could code it myself, but this wheel is probably already invented

Maybe, but that's a so domain-specific and easy to code wheel that
it's no big deal reinventing.

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


Re: Exploring Attributes and Methods

2008-03-06 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
> Hi,
>  Is there a python command that allows me to extract the names (not
> values) of the attributes of a class.
> 
> example
> 
> Class Sample:
> fullname = 'Something'
> 
> How can I know that this class has an attribute called 'fullname'?
> 
> I hope my question is clear.

The question others have answered already. But I have one for you: you 
are aware that these kind of variables are *class variables*, NOT 
*instance variables*, as they are created like this:


class Foo(object):
 def __init__(self):
 self.fullname = "something"


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


Re: Ncurses not found - embedded linux

2008-03-06 Thread Diez B. Roggisch
blaine schrieb:
> Hello Everyone!
>   I am hoping that someone out there can help me out with this
> problem.  We are using a gumstix platform to develop an embedded
> system.  All that really matters is that it is an ARM processor
> running an embedded linux, details to follow.  Gumstix has its own
> kernel tree that we cross compile for the system.  We do have python,
> and it has all of the modules that I need except for one.  I need
> ncurses (module curses).  I can't seem to figure out how to get it to
> work - and the only documentation I can find is for Windows (because
> windows doesn't have ncurses).  We have enabled ncurses support in the
> kernel menu, and that has not helped.  I can't seem to trace down
> where we would 'enable' ncurses support?  All other modules seem to
> work that I've tried (termios, sys, os, etc.)
> 
> Output from python:
> [EMAIL PROTECTED] ~]# python
> , Feb 20 2008, 11:07:36)
> [GCC 4.1.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
 import curses
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "/usr/lib/python2.4/curses/__init__.py", line 15, in ?
> from _curses import *
> ImportError: No module named _curses
> 
> [EMAIL PROTECTED] ~]# uname -a
> Linux gumstix 2.6.21gum #1 Tue Mar 4 15:31:07 EST 2008 armv5tel
> unknown
> 
> [EMAIL PROTECTED] lib]# ls /usr/lib/*curses*
> /usr/lib/libcurses.a@   /usr/lib/libncurses.a   /usr/lib/
> libncurses.so@
> 
> [EMAIL PROTECTED] lib-dynload]# ls _*
> _bisect.so* _codecs_tw.so*  _random.so*
> _codecs_cn.so*  _csv.so*_socket.so*
> _codecs_hk.so*  _heapq.so*  _testcapi.so*
> _codecs_iso2022.so* _hotshot.so*_weakref.so*
> _codecs_jp.so*  _locale.so*
> _codecs_kr.so*  _multibytecodec.so*
> 
> I hope this is trivial, and I apologize ahead of time if so.  Would
> this perhaps be a compilation issue? Something we have to turn on in
> the python compile?

Usually, you need not only the libraries but also the headers at 
compilation time. Most probably these were missing.

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


Re: Python CGI & Webpage with an Image

2008-03-06 Thread Bryan Olson
rodmc wrote:
> [...] I have played around a bit more
> so that both the image and HTML file are in the public_html folder.
> They are called via python using a relative URL, and have permissions
> set to 755. Within the HTML file the image is accessed using just
> "banner.jpg". The actual page displays ok except for the image - so it
> has the same problem as before. However when the same page is
> displayed without running through a CGI it displays perfectly.

Is the cgi script in the same directory? The user's browser looks
for the jpg relative to the URL it used to get the page, which in
the case of the CGI script is the path to the script, not the
path to the html file.

If server logs are hard to get or read, try my runcgi.py script:

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


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


Re: Data aggregation

2008-03-06 Thread petr . jakes . tpc
On Mar 6, 7:44 pm, John Nagle <[EMAIL PROTECTED]> wrote:
> vedranp wrote:
> > I would like to avoid the step of taking data out from database in
> > order to process it.
>
> You can probably do this entirely within SQL.  Most SQL databases,
> including MySQL, will let you put the result of a SELECT into a new
> table.
>
> John Nagle
I agree,

maybe following can help

http://tinyurl.com/32colp

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


Re: List all files using FTP

2008-03-06 Thread Simon Brunning
On Thu, Mar 6, 2008 at 6:11 PM, jay graves <[EMAIL PROTECTED]> wrote:
> On Mar 6, 10:46 am, Anders Eriksson <[EMAIL PROTECTED]> wrote:
>  > I need to list all the files on my FTP account (multiple subdirectories). I
>  > don't have shell access to the account.
>  > anyone that has a program that will do this?
>
>  Not offhand, but you can look at the ftpmirror.py script for
>  inspiration.
>  It should be in your Tools/scripts/ subdirectory of your Python
>  installation.

This might be of use:



-- 
Cheers,
Simon B.
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Ncurses not found - embedded linux

2008-03-06 Thread blaine
Hello Everyone!
  I am hoping that someone out there can help me out with this
problem.  We are using a gumstix platform to develop an embedded
system.  All that really matters is that it is an ARM processor
running an embedded linux, details to follow.  Gumstix has its own
kernel tree that we cross compile for the system.  We do have python,
and it has all of the modules that I need except for one.  I need
ncurses (module curses).  I can't seem to figure out how to get it to
work - and the only documentation I can find is for Windows (because
windows doesn't have ncurses).  We have enabled ncurses support in the
kernel menu, and that has not helped.  I can't seem to trace down
where we would 'enable' ncurses support?  All other modules seem to
work that I've tried (termios, sys, os, etc.)

Output from python:
[EMAIL PROTECTED] ~]# python
, Feb 20 2008, 11:07:36)
[GCC 4.1.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import curses
Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib/python2.4/curses/__init__.py", line 15, in ?
from _curses import *
ImportError: No module named _curses

[EMAIL PROTECTED] ~]# uname -a
Linux gumstix 2.6.21gum #1 Tue Mar 4 15:31:07 EST 2008 armv5tel
unknown

[EMAIL PROTECTED] lib]# ls /usr/lib/*curses*
/usr/lib/libcurses.a@   /usr/lib/libncurses.a   /usr/lib/
libncurses.so@

[EMAIL PROTECTED] lib-dynload]# ls _*
_bisect.so* _codecs_tw.so*  _random.so*
_codecs_cn.so*  _csv.so*_socket.so*
_codecs_hk.so*  _heapq.so*  _testcapi.so*
_codecs_iso2022.so* _hotshot.so*_weakref.so*
_codecs_jp.so*  _locale.so*
_codecs_kr.so*  _multibytecodec.so*

I hope this is trivial, and I apologize ahead of time if so.  Would
this perhaps be a compilation issue? Something we have to turn on in
the python compile?

Thank you,
Blaine Booher
University of Cincinnati
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Class context execution problems

2008-03-06 Thread Gabriel Genellina
En Thu, 06 Mar 2008 11:04:26 -0200, Marcelo de Moraes Serpa  
<[EMAIL PROTECTED]> escribi�:

> I'm using a class in a conext other than the subpackage in which it is
> located and I'm getting template lookup errors.
>
> This class expects to find a .pt file in a directory relative to its
> package. However, this class is normally used by other classes in the  
> same
> namespace.
>
> class ObjectWidget:
>  template = "templates/objectwidget.pt"
>
> However, I needed to import this class (ObjectWidget) from a class  
> outside
> its namespace(package). Now, I think the class is running in the context  
> of
> the file that is using it and so, the
> the class not finding the .pt file (I think becouse the class file is  
> being
> contextualized to the currently running one which is outside the browser
> subpackage)

No, it's not. The globals() (i.e., the "context") are of the imported  
module itself, not of the caller. The error probably lies on how that  
template attribute is converted into a full path; post that code.
As an example, this is a rather safe way, even if the program uses  
os.chdir():

basepath = os.path.abspath(os.path.dirname(__file__))

class ObjectWidget:
 template = "templates/objectwidget.pt"

 def open(self):
 fn = os.path.join(basepath, template)
 print fn

-- 
Gabriel Genellina

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

Re: Exploring Attributes and Methods

2008-03-06 Thread [EMAIL PROTECTED]
On Mar 7, 12:30 am, "Terry Reedy" <[EMAIL PROTECTED]> wrote:
> <[EMAIL PROTECTED]> wrote in message
>
> news:[EMAIL PROTECTED]
> | Hi,
> | Is there a python command that allows me to extract the names (not
> | values) of the attributes of a class.
> |
> | example
> |
> | Class Sample:
> |fullname = 'Something'
> |
> | How can I know that this class has an attribute called 'fullname'?
>
> >>> class C: a = 1
> >>> dir(C)
>
> ['__doc__', '__module__', 'a']

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


Re: What is a class?

2008-03-06 Thread castironpi
On Mar 6, 1:03 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> On Mar 5, 7:50 pm, [EMAIL PROTECTED] wrote:
>
> > What is a class that is not a module?
>
> A class is a bag of stuff and a namespace :)
>
> J.

A module is a bag of stuff and a namespace.  Different stuff.

{ '__module__', '__weakref__'}
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exploring Attributes and Methods

2008-03-06 Thread Paul McGuire
On Mar 6, 1:14 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Hi,
>  Is there a python command that allows me to extract the names (not
> values) of the attributes of a class.
>
> example
>
> Class Sample:
>     fullname = 'Something'
>
> How can I know that this class has an attribute called 'fullname'?
>
> I hope my question is clear.
> Thanks

If you had posted actual working code, "Class" would be all lower case
("class").  But we get the drift (in general, though, when posting
questions about examples from your code, best to copy-paste the actual
code, not a paraphrasing of it):

print Sample.__dict__.keys()

prints:

['__module__', 'fullname', '__doc__']


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


Re: Exploring Attributes and Methods

2008-03-06 Thread Tim Chase
> Class Sample:
> fullname = 'Something'
> 
> How can I know that this class has an attribute called 'fullname'?

with the builtin hasattr() function :)

 >>> class Sample: fullname='Something'
...
 >>> hasattr(Sample, 'fullname')
True

-tkc


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


Re: Exploring Attributes and Methods

2008-03-06 Thread Terry Reedy

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| Hi,
| Is there a python command that allows me to extract the names (not
| values) of the attributes of a class.
|
| example
|
| Class Sample:
|fullname = 'Something'
|
| How can I know that this class has an attribute called 'fullname'?

>>> class C: a = 1

>>> dir(C)
['__doc__', '__module__', 'a'] 



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


Re: Better grammar.txt

2008-03-06 Thread Jeroen Ruigrok van der Werven
-On [20080306 19:21], member thudfoo ([EMAIL PROTECTED]) wrote:
>An error occurred while loading
>http://www.martinrinehart.com/articles/python-grammar.html:
>Unknown host www.martinrinehart.com

Works for me.

-- 
Jeroen Ruigrok van der Werven  / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
Possession is nine points of the law...
-- 
http://mail.python.org/mailman/listinfo/python-list

Exploring Attributes and Methods

2008-03-06 Thread [EMAIL PROTECTED]
Hi,
 Is there a python command that allows me to extract the names (not
values) of the attributes of a class.

example

Class Sample:
fullname = 'Something'

How can I know that this class has an attribute called 'fullname'?

I hope my question is clear.
Thanks


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


Re: Classes and modules are singletons?

2008-03-06 Thread castironpi
On Mar 6, 8:30 am, Carl Banks <[EMAIL PROTECTED]> wrote:
> On Mar 5, 8:44 pm, Steven D'Aprano <[EMAIL PROTECTED]
>
> cybersource.com.au> wrote:
> > But what about classes? Are they singletons? Obviously classes aren't
> > Singleton classes, that is, given an arbitrary class C you can create
> > multiple instances of C. But what about class objects themselves? I've
> > found a few odd references to "classes are singletons", but nothing in
> > the language reference.
>
> Probably because "singleton" is the wrong word.  A singleton means
> there is one instance of a type; classes are instances of "type" which
> can have many instances so classes are not singletons.
>
> Anyway, the answer to what you are probably asking is No.  Try this:
>
> >>>import module
> >>>c1 = module.Someclass
> >>>reload(module)
> >>>c2 = module.Someclass
> >>>c1 is c2

What about

>>> o= object()
>>> b1= o.someattr
>>> reload( o )
>>> b2= o.someattr
>>> b1 is b2

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


Re: What is a class?

2008-03-06 Thread [EMAIL PROTECTED]
On Mar 5, 7:50 pm, [EMAIL PROTECTED] wrote:
> What is a class that is not a module?

A class is a bag of stuff and a namespace :)



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


HURRICANE ANDREW 1992 Rare & Raw Footage

2008-03-06 Thread Whoshaq
HURRICANE ANDREW 1992 Rare & Raw Footage

Parts 1 thru 7:

http://www.youtube.com/watch?v=zKGMQFWWJ0g
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Data aggregation

2008-03-06 Thread John Nagle
vedranp wrote:

> I would like to avoid the step of taking data out from database in
> order to process it.

You can probably do this entirely within SQL.  Most SQL databases,
including MySQL, will let you put the result of a SELECT into a new
table.

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


Re: Please keep the full address

2008-03-06 Thread castironpi
> > > > I'm talking about castironpi.  I find his posts a waste of my time
>
> > > "His" posts?
>
> > Whatever.  I'm too old to worry about searching for politically correct,
> > gender neutral pronouns.
>
> I'm pretty sure even the most PC people wouldn't suggest using a
> masculine pronoun for an inanimate objects.
>
> (Ok, some probably would.)
>
> Carl Banks

Traceback (most recent call last):
  File "", line 1, in 
AssertionError: Hey, that's not nice.
>>>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Identifying messages in a thread (was: Please keep the full address)

2008-03-06 Thread castironpi
On Mar 6, 10:47 am, "D'Arcy J.M. Cain" <[EMAIL PROTECTED]> wrote:
> On Thu, 6 Mar 2008 07:58:06 -0800 (PST)
>
> Carl Banks <[EMAIL PROTECTED]> wrote:
> > > I don't want to have to tag every thread.  I just want to *plonk*
> > > certain posters.
>
> > > Anyway, I'll live with Google's failings I guess.
>
> > Sounds like you need better filtering.
>
> > A decent news filter should be able not only kill a poster, but also
> > all followups to that poster recursively.
>
> Actually, I am reading this as a mailing list and since I run Unix and
> procmail I am sure that I could set something up if it really starts to
> be annoying.  So far the simple filters deal with all but a smattering
> of problem postings so I don't need to expend the time.

The Google Groups reader doesn't always let you see new replies to
really old messages, something they should change (this means you).
But there is an 'active old threads', but it doesn't catch every one.
I want to read those plonk.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dual look-up on keys?

2008-03-06 Thread castironpi
> Actually, there's another data structure I was working on (a year ago
> now) that's tangentially related, so if you guys want me to hold off
> on that one til you or I is satisfied on the company-product map, I
> will!  Otherwise, I'll just post it here and leave it to you.
> (Knowing myself, something tells me I'll try to formulate it later on
> today regardless.  Heh heh heh.  If that's not the most virtuous way
> to ask for help, then I might have inherited from TroubleMaker at some
> point up the line.)

My other question still open, the idea was a collision detector.  But
it's been done.

Ideally, subdivide space varying with objects' positions up to a
tolerance.  On motion, redivide.  Each tile, hexes, triangles, or
squares, can access the other objects in itself-- and only detect
collisions among those.  Objects can span multiple tiles.  For large
object sets, zero detections made per cycle best case, but still all
of them worst.  It amounts to a tree structure in which child nodes
are keyed geometrically-- grid.NWcorner.NEcorner gets you the second
column, first row in a 4x4 grid.  grid.NWcorner.NEcorner.SWcorner gets
you the third column, second row, in an 8x8 grid, and by that point,
there are 63 tiles other objects might be in that you know aren't in
yours.  A tile is a leaf if there are no objects in it.

Question is, how rare/common is the subset of object configurations in
which the optimizations weigh out?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Better grammar.txt

2008-03-06 Thread member thudfoo
On 3/5/08, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
>  > It includes three corrections to grammar.txt (imagnumber, xor_expr and
>  > and_expr) that I've reported.
>
>
> Make that four corrections. Add augop.
>
> --
>  http://mail.python.org/mailman/listinfo/python-list
>
An error occurred while loading
http://www.martinrinehart.com/articles/python-grammar.html:
Unknown host www.martinrinehart.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking if a variable is a dictionary

2008-03-06 Thread Neil Cerutti
On Thu, Mar 6, 2008 at 12:17 PM, Guillermo
<[EMAIL PROTECTED]> wrote:
> > You can also get the dynamic polymorphism without invoking inheritance
>  > by specifying a protocol that the values in your dict must implement,
>  > instead. Protocols are plentiful in Python, perhaps more popular than
>  > type hierarchies.
>
>  I'm used to languages with stricter rules than Python. I've read a bit
>  about Python protocols, but where could I get some more info on
>  implementation details? Sounds very interesting.

A protocol is just an interface that an object agrees to implement. In
your case, you would state that every object stored in your special
dict must implement the to_tagged_value method with certain agreeable
semantics.

Python implements sequence types, mapping types, iterators, file
streams, and other things with protocols.

For example, iterators must support the "next" and and "__iter__" methods.

Using a protocol instead instead of a type hierarchy requires less
boring boilerplate, and I suppose in Python will usuallly be
preferable except when you want to inherit implementation as well as
interface. In that case, inheritance often saves boilerplate cide
rather than increases it.

It's also misnomered as duck-typing (clearly it should be nomed quack-typing).

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


Re: List all files using FTP

2008-03-06 Thread jay graves
On Mar 6, 10:46 am, Anders Eriksson <[EMAIL PROTECTED]> wrote:
> I need to list all the files on my FTP account (multiple subdirectories). I
> don't have shell access to the account.
> anyone that has a program that will do this?

Not offhand, but you can look at the ftpmirror.py script for
inspiration.
It should be in your Tools/scripts/ subdirectory of your Python
installation.

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


Re: Data aggregation

2008-03-06 Thread jay graves
On Mar 6, 10:28 am, vedranp <[EMAIL PROTECTED]> wrote:
> So, group by DATE, COUNTRY, ZIP and CITY and sum (or do some

You are s close.  Look up itertools.groupby
Don't forget to sort your data first.

http://aspn.activestate.com/ASPN/search?query=groupby&x=0&y=0§ion=PYTHONCKBK&type=Subsection
http://mail.python.org/pipermail/python-list/2006-June/388004.html


> From some little experience with Perl, I think this is managable with
> double hash tables (1: basic hash with key/value = CITY/pointer-to-
> other-hash, 2: hash table with values for CITY1), so I assume that
> there would be also a way in Python, maybe with dictionaries? Any
> ideas?

Sometimes it makes sense to do this with dictionaries.  For example,
if you need to do counts on various combinations of columns.

count of unique values in column 'A'
count of unique values in column 'C'
count of unique combinations of columns 'A' and 'B'
count of unique combinations of columns 'A' and 'C'
count of unique combinations of columns 'B' and 'C'
in all cases, sum(D) and avg(E)

Since I need 'C' by itself, and 'A' and 'C' together, I can't just
sort and break on 'A','B','C'.

HTH
...
jay graves
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Please keep the full address

2008-03-06 Thread Carl Banks
On Mar 6, 11:41 am, "D'Arcy J.M. Cain" <[EMAIL PROTECTED]> wrote:
> On Thu, 6 Mar 2008 08:00:58 -0800 (PST)
>
> Carl Banks <[EMAIL PROTECTED]> wrote:
> > > I'm talking about castironpi.  I find his posts a waste of my time
>
> > "His" posts?
>
> Whatever.  I'm too old to worry about searching for politically correct,
> gender neutral pronouns.


I'm pretty sure even the most PC people wouldn't suggest using a
masculine pronoun for an inanimate objects.


(Ok, some probably would.)

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


Re: Checking if a variable is a dictionary

2008-03-06 Thread Guillermo
> You can also get the dynamic polymorphism without invoking inheritance
> by specifying a protocol that the values in your dict must implement,
> instead. Protocols are plentiful in Python, perhaps more popular than
> type hierarchies.

I'm used to languages with stricter rules than Python. I've read a bit
about Python protocols, but where could I get some more info on
implementation details? Sounds very interesting.

Regards,

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


Re: Dual look-up on keys?

2008-03-06 Thread castironpi
On Mar 6, 5:16 am, Bryan Olson <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Bryan Olson wrote:
> >> How can we efficiently implement an abstract data type, call it
> >> 'DoubleDict', where the state of a DoubleDict is a binary
> >> relation, that is, a set of pairs (x, y); and the operations on
> >> a DoubleDict are those on a Python set, plus:
>
> >>      find_by_first(self, x):  return [y where (x, y) in DoubleDict]
>
> >>      find_by_second(self, y):  return [x where (x, y) in DoubleDict]
> > It gets hairier if you have an element that isn't a first or second
> > necessarily.
>
> >       find_by_other(self, x): return [y where (x, y) in DoubleDict or
> > (y, x) in DoubleDict]
>
> Do you need all three find_by's, or are the pairs actually
> unordered, so you just need to find partners? Are the relations
> many-to-many, and if so do you want duplicates removed?
>
> As programming exercises, the variants are all reasonable and
> possibly interesting. I was just trying to answer the call to
> nail down the problem statement.

You've helped me nail down the problem in my post.  It was that I was
trying to ask two questions at once.  (He had at -least- one
question!).  The first was from an old piece of code I wrote that
simply wanted to know what the object that's storing the combination
of A and B was, so frozenset([A,B]) works perfectly, and I'm satisfied
as for that one.

But the second one, which was interefering with my own thoughts, was
another one.

The company was selling multiple products at multiple sites.
Softdrink A at store 1, softdrink B at store 1, softdrink B at store
2.  My 'add' operation, 'say store N sold softdrink S' always had two
lines and I really hated it.  It worked, of course, but still.  I felt
like it was a stain.

I was asking if anyone knows how to tie it, but it was kind of
intimidating seeing how the implementation worked already.

> Do you need all three find_by's, or are the pairs actually
> unordered, so you just need to find partners? Are the relations
> many-to-many, and if so do you want duplicates removed?

The first one was, find the information I already have about a
partnership.

> As programming exercises, the variants are all reasonable and
> possibly interesting. I was just trying to answer the call to
> nail down the problem statement.

Which is now something I can do.

Actually, there's another data structure I was working on (a year ago
now) that's tangentially related, so if you guys want me to hold off
on that one til you or I is satisfied on the company-product map, I
will!  Otherwise, I'll just post it here and leave it to you.
(Knowing myself, something tells me I'll try to formulate it later on
today regardless.  Heh heh heh.  If that's not the most virtuous way
to ask for help, then I might have inherited from TroubleMaker at some
point up the line.)
-- 
http://mail.python.org/mailman/listinfo/python-list


List all files using FTP

2008-03-06 Thread Anders Eriksson
Hello,

I need to list all the files on my FTP account (multiple subdirectories). I
don't have shell access to the account.

anyone that has a program that will do this?

// Anders
-- 
English is not my first, or second, language
so anything strange, or insulting, is due to
the translation.
Please correct me so I may improve my English!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Identifying messages in a thread (was: Please keep the full address)

2008-03-06 Thread D'Arcy J.M. Cain
On Thu, 6 Mar 2008 07:58:06 -0800 (PST)
Carl Banks <[EMAIL PROTECTED]> wrote:
> > I don't want to have to tag every thread.  I just want to *plonk*
> > certain posters.
> >
> > Anyway, I'll live with Google's failings I guess.
> 
> Sounds like you need better filtering.
> 
> A decent news filter should be able not only kill a poster, but also
> all followups to that poster recursively.

Actually, I am reading this as a mailing list and since I run Unix and
procmail I am sure that I could set something up if it really starts to
be annoying.  So far the simple filters deal with all but a smattering
of problem postings so I don't need to expend the time.

-- 
D'Arcy J.M. Cain <[EMAIL PROTECTED]> |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is a class?

2008-03-06 Thread castironpi
On Mar 6, 12:17 am, "Daniel Fetchinson" <[EMAIL PROTECTED]>
wrote:
> > > Where to begin?
>
> > What does exec( open( 'modA.py' ).read() ) do?
>
> The most appropriate list to ask those questions is:
>
> http://mail.python.org/mailman/listinfo/tutor

Thanks for the reference.  I'm basically experienced with Python, but
I may read there too.

I asked the question mostly rhetorically.  Like when people
ask, who cares, or who knows.  They don't want the answer unless
there is one. 

A more appropriate formulation of the 'question behind the words'
would have been, 'are there any weird corner cases in which it doesn't
import modA?  I recognize it doesn't on .pyc and .pyd files, but you
could say exec( open( 'modA.py' ).read() ) ==> import modA, even if
import modA =!=> exec( open( 'modA.py' ).read() ) all the time.

However, a way of asking that's more direct would have been, "Wait...
can't you create multiple module instances like that?", but since
we've already seen successful loadings of at least the builtins,
that's been treated.  Maybe you even hear the right thing if I say,
"Does exec( open( 'modA.py' ).read() ) do the things of import modA?"
Yes, I can read the docs, but no, I can't check every possible
combination of modules.

The idea behind a singleton is to ensure something.  You want non-
primary instances impossible to create.  However, if (wording got
tangled here) for singleton A, if class B does the same thing, just
has different allocations-- it's own-- then A is still a singleton.
The writer of B hasn't defeated or contradicted the letter or spirit
of A.

OP's question might have come from a variety of perspectives.  In some
ways yes, in others no.  That is, if you try to reinstantiate modA,
you get the same instance.  But if you try really hard, you get a new
one.  Are you looking for an extension to import modA that won't
return an instance that is old?

So far, I know this: modules and classes are both namespaces.  Are
those singletons?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Please keep the full address

2008-03-06 Thread D'Arcy J.M. Cain
On Thu, 6 Mar 2008 08:00:58 -0800 (PST)
Carl Banks <[EMAIL PROTECTED]> wrote:
> > I'm talking about castironpi.  I find his posts a waste of my time
> 
> "His" posts?

Whatever.  I'm too old to worry about searching for politically correct,
gender neutral pronouns.

-- 
D'Arcy J.M. Cain <[EMAIL PROTECTED]> |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
-- 
http://mail.python.org/mailman/listinfo/python-list


help on file storage for split multi part download

2008-03-06 Thread coolman . guron
HI everyone on this group!

i am want to write a split part downloading software for use in some
projects. (something like a download accelerator)

what i think i need is ( my brain is totally exausted at this moment
so pls ignore any typos i make)

storage class which can write the file splits that are currently being
downloaded to the disk. this is exactly what other download
accelerators do, i guess.

can this be done using the python file class?? i am pretty good at
handling file uploads (at server end) this is the first time i have to
think the other way round.

any code samples would be greatly appreciated.

thanks
binary-j
django web developer

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


Data aggregation

2008-03-06 Thread vedranp
Hi,

I have a case where I should aggregate data from the CSV file, which
contains data in this way:

DATETIMECOUNTRY ZIP CITYVALUE1  VALUE2  VALUE3
21.2.2008   00:00   A   1000CITY1   1   2   3
21.2.2008   00:00   A   1000CITY2   4   5   6
21.2.2008   00:00   A   1000CITY3   7   8   9
21.2.2008   00:00   A   1000CITY4   1   2   3
21.2.2008   00:15   A   1000CITY1   4   5   6
21.2.2008   00:15   A   1000CITY2   7   8   9
21.2.2008   00:15   A   1000CITY3   1   2   3
21.2.2008   00:15   A   1000CITY4   4   5   6
21.2.2008   00:00   A   2000CITY10  7   8   9
21.2.2008   00:00   A   2000CITY20  1   2   3
21.2.2008   00:00   A   2000CITY30  4   5   6
21.2.2008   00:00   A   2000CITY40  1   2   3
21.2.2008   00:15   A   2000CITY10  7   8   9
21.2.2008   00:15   A   2000CITY20  1   2   3
21.2.2008   00:15   A   2000CITY30  4   5   6
21.2.2008   00:15   A   2000CITY40  1   2   3

I need to aggregate data from file1, so the result would be a CSV file
(file2) in this format:

DATECOUNTRY ZIP CITYSumOfVALUE1 SumOfVALUE2 SumOfVALUE3 
formula1
21.2.2008   A   1000CITY1   5   7   9   12
21.2.2008   A   1000CITY2   11  13  15  24
21.2.2008   A   1000CITY3   8   10  12  18
21.2.2008   A   1000CITY4   5   7   9   12
21.2.2008   A   2000CITY10  14  16  18  30
21.2.2008   A   2000CITY20  2   4   6   6
21.2.2008   A   2000CITY30  8   10  12  18
21.2.2008   A   2000CITY40  2   4   6   6

So, group by DATE, COUNTRY, ZIP and CITY and sum (or do some
calculation) the values and do some calculation from summed fields
(e.g.: formula1 = SumOfVALUE1+SumOfVALUE2). I am able to do this by
first loading file1 in SQL, perform a query there, which returns the
file2 results and then load it back in the SQL in the different table.

I would like to avoid the step of taking data out from database in
order to process it. I would like to process the file1  in Python and
load the result (file2) in SQL.

>From some little experience with Perl, I think this is managable with
double hash tables (1: basic hash with key/value = CITY/pointer-to-
other-hash, 2: hash table with values for CITY1), so I assume that
there would be also a way in Python, maybe with dictionaries? Any
ideas?

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


Re: Does python support working with password protected zip files?

2008-03-06 Thread Greg Armer
On 3/6/08, Malcolm Greene <[EMAIL PROTECTED]> wrote:
> I'm new to Python and trying to figure out how to read and write to
>  password protected zip files.
>
>  I can work with plain zip files no problem.
>
>  I've googled this topic and am coming up empty except for a post on
>  Nabbler.com that seemed to imply that password protected zip files
>  may(???) be supported in Python 2.6 and ads for a commercial Windows
>  (only) zip component from chilkat.com.
>
>  Any suggestions?

Hi Malcolm,

I just had to do some with with this myself and eventually resorted to
simply using a popen() call to the system unzip utility with the
-Ppass command line option.



def _unzipdata(self):
print "[~] Processing zip file %s..." % self.zipfile
# Create temporary directory
os.mkdir('_temp')

# Unzip password protected zipfile to _temp
os.chdir('_temp')
os.popen("unzip -P%s ../%s" % (self.password, self.zipfile), "r")
return True


While this is not ideal, i could not find any other alternatives.

Hope that helps.

--
Greg Armer

Entropy has us outnumbered.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hi

2008-03-06 Thread Michael L Torrie
[EMAIL PROTECTED] wrote:
> Hello
> 
> can u plz tell how to send and read msg from device(telit-863-GPS) and
> the coding is in python.
> 
> if this can happen then plz send the source code to my mail account

Sounds like a new development model.  You should patent this.  Just
e-mail lists with cryptic requests for code, then combine the resulting
fragments into one executable.  In fact, if you do it in chain letter
form, you can get code even faster.  I heard a rumor once that's how
Windows Me was originally built.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is a class?

2008-03-06 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :

> And white to play.  What does exec( open( 'modA.py' ).read() ) do?

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


Re: for-else

2008-03-06 Thread Jeffrey Barish
Terry Reedy wrote:

> A for-loop is equivalent to a while loop with the condition 'iterator is
> not exhausted'.  So do_else when that condition is false -- the iterator
> is exhausted.

I think that this is the most important statement in this thread.  As others
have expressed, I too found for-else surprising when I first encountered
it.  It made sense to me when I analogized for with if:

for x in range(5):
do_something()
else:
do_something_else()

means

do_something repeatedly when the condition (iterator not exhausted) is true
and do_something_else when the condition is not true, just as

if condition:
do_something()
else:
do_something_else()

means do_something once when the condition is true and do_something_else
when the condition is not true.  I find it elegant that Python does not
introduce additional keywords to deal with situations that are comparable.
-- 
Jeffrey Barish

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


Re: Please keep the full address

2008-03-06 Thread Carl Banks
On Mar 5, 8:07 pm, "D'Arcy J.M. Cain" <[EMAIL PROTECTED]> wrote:
> On Wed, 5 Mar 2008 14:00:17 -0800 (PST)
>
> Mike Driscoll <[EMAIL PROTECTED]> wrote:
> > What are you talking about? I didn't change the address at all. I'm
> > not even sure what you mean. Are you talking about the post subject
> > line (which I have never touched in any post)? If you're talking about
> > the OP's email address, that's Google's fault for cropping them.
>
> I'm talking about castironpi.  I find his posts a waste of my time

"His" posts?


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


Does python support working with password protected zip files?

2008-03-06 Thread Malcolm Greene
I'm new to Python and trying to figure out how to read and write to
password protected zip files.

I can work with plain zip files no problem.

I've googled this topic and am coming up empty except for a post on
Nabbler.com that seemed to imply that password protected zip files
may(???) be supported in Python 2.6 and ads for a commercial Windows
(only) zip component from chilkat.com.

Any suggestions?

Thank you,
Malcolm
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Identifying messages in a thread (was: Please keep the full address)

2008-03-06 Thread Carl Banks
On Mar 5, 8:11 pm, "D'Arcy J.M. Cain" <[EMAIL PROTECTED]> wrote:
> On Thu, 06 Mar 2008 09:36:29 +1100
>
> Ben Finney <[EMAIL PROTECTED]> wrote:
> > > Those of us who identify the time wasters would also like to drop
> > > the responses to their posts and changing the address makes this
> > > impossible.
>
> > Not at all. AFAIK the messages from Google mail correctly include the
> > 'In-Reply-To' field or the 'References' field in the message header.
> > So, you can know by those fields whether a message is part of a thread
> > you've previously identified.
>
> I don't want to have to tag every thread.  I just want to *plonk*
> certain posters.
>
> Anyway, I'll live with Google's failings I guess.

Sounds like you need better filtering.

A decent news filter should be able not only kill a poster, but also
all followups to that poster recursively.

(No, I don't know of any that do that either.)


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


Py-Extension Irregularity

2008-03-06 Thread Michael Wieher
Observe.

Python Code Snippet:

...
 66 while i < (self.nPCodes):
 67# print "%s:%s" % (self.nPCodes,i)
 68 (c,l,sn,f,fn,sz) = tabmodule.getQuestion(i,self.mx3Path)
 69 if _debug and sz>0:
 70 _newPtrLoc = tabmodule.getMx3Ptr()
 71 _diff = _newPtrLoc-_oldPtrLoc
 72 _oldPtrLoc = _newPtrLoc
 73 if _diff>16:
 74 print _diff


C++ Code Snippet:
---
189 static PyObject*
190 tabmodule_getMx3Ptr(PyObject * self, PyObject * args) {
191 int a;
192 a=mx3File.tellg();
193 return Py_BuildValue("i",a);
194 }
...

189 PyObject *
190 tabmodule_getQuestion(PyObject * self, PyObject * args) {

208mx3File.read((char*)&m_mdx,16);

237 //if(m_mdx.size==0)
238 return Py_BuildValue("ii",0,0,0,0,0,0);
239 //return Py_BuildValue("ii",m_mdx.compression, m_mdx.location,
m_mdx.stacknotes, m_mdx.file, m_mdx.footnote, m_mdx.size);
}

Output==
[EMAIL PROTECTED]:~/MRI/tabModule$ ./tabModule.py
[EMAIL PROTECTED]:~/MRI/tabModule$

None.  (ie: the _diff is always 16 or less, which is what is SHOULD be, in
fact, it is always 16.)

Observe

237 if(m_mdx.size==0)
238 return Py_BuildValue("ii",0,0,0,0,0,0);
239 return Py_BuildValue("ii",m_mdx.compression, m_mdx.location,
m_mdx.stacknotes, m_mdx.file, m_mdx.footnote, m_mdx.size);

By uncommenting line 237 and 239, we see:
...
64
80
32
32
32
48
128
160
32
32
64


Most of the numbers are still 16, but _diff is often larger than 16, by some
multiple.

How in Buddah's name is returning a Py_BuildValue() affecting a file pointer
that isn't being used at all in the function
-- 
http://mail.python.org/mailman/listinfo/python-list

Pydev 1.3.14 Released

2008-03-06 Thread Fabio Zadrozny
Hi All,

Pydev and Pydev Extensions 1.3.14 have been released

Details on Pydev Extensions: http://www.fabioz.com/pydev
Details on Pydev: http://pydev.sf.net
Details on its development: http://pydev.blogspot.com

Release Highlights in Pydev Extensions:
-

* Local renames: scoping issues.
* Local renames: comments/strings only renamed in local scope for
local variable.
* False positive: undefined variable: a base-class could be flagged as
undefined if used in a method scope.
* Remote Debugger: easier way to specify path translations between a
remote machine and a local machine (constant must be set in
org.python.pydev.debug/pysrc/pydevd_file_utils.py -- see comments on
module) .


Release Highlights in Pydev:
--

* Outline view: patch by Laurent Dore: better icons for different
types of fields methods.
* Outline view: patch by Laurent Dore: more filters.
* PyLint: working dir is the directory of the analyzed file.
* Project explorer: fixed bug on integration with Dynamic Web Project.
* Extract method: fixed bug when trying to refactor structure: a = b = xxx.
* Generate constructor using fields: working for classes that derive
from builtin classes.
* Override methods: working for classes that derive from builtin classes.
* Debugger can use psyco for speedups: see
http://pydev.blogspot.com/2008/02/pydev-debugger-and-psyco-speedups.html.
* Debugger: shows parent frame when stepping in a return event.
* Go to previous/next method: (Ctrl+Shift+Up/Down): does not rely on
having a correct parse anymore.
* Auto-formatting: No space after comma if next char is new line.
* Code Completion: Handling completions from attribute access in
classes (accessed from outside of the class).
* Auto-indent: Better handling when indenting to next tab position
within the code.
* Caches: Some places were recreating the cache used during a
completion request instead of using the available one (which could
have a memory impact on some situations).



What is PyDev?
---

PyDev is a plugin that enables users to use Eclipse for Python and
Jython development -- making Eclipse a first class Python IDE -- It
comes with many goodies such as code completion, syntax highlighting,
syntax analysis, refactor, debug and many others.


Cheers,

-- 
Fabio Zadrozny
--
Software Developer

ESSS - Engineering Simulation and Scientific Software
http://www.esss.com.br

Pydev Extensions
http://www.fabioz.com/pydev

Pydev - Python Development Enviroment for Eclipse
http://pydev.sf.net
http://pydev.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking if a variable is a dictionary

2008-03-06 Thread Neil Cerutti
On Thu, Mar 6, 2008 at 8:06 AM, Guillermo
<[EMAIL PROTECTED]> wrote:
>  I want to iterate recursively a dictionary whose elements might be
>  strings or nested tuples or dictionaries and then convert values to a
>  tagged format according to some rules.
>
>  d = {'a':"i'm a", 'b':(1,2,3),'c':{'a':"i'm a",'x':"something",'y':
>  ('a','b','c')}}

This could be solved with dynamic polymorphism instead of
introspection, which  might simplify things depending on how your
dictionary is constructed.

class Value(object):
  def to_tagged_format(self):
 raise NotImplementedError

class StringValue(Value):
  def to_tagged_format(self):
...

class Tuplevalue(Value):
  def to_tagged_format(self):
...
class DictValue(Value):
  def to_tagged_format(self):
...


for k, v in d.iteritems():
  d[k] = v.to_tagged_format()

You can also get the dynamic polymorphism without invoking inheritance
by specifying a protocol that the values in your dict must implement,
instead. Protocols are plentiful in Python, perhaps more popular than
type hierarchies.

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


Re: Licence confusion: distributing MSVC?71.DLL

2008-03-06 Thread jim-on-linux


> > If someone has worked their way through
> > this maze before and has an answer, I'd
> > be keen to hear it.

This is what someone wrote  on 1-21-2007
to this help site about this pain in the a... 
MSVCR71 stuff.

" I believe this problem doesn't exist. 
Licensees of Python are permitted
to redistribute mscvr71.dll, as long as they 
redistribute it in order
to support pythonxy.dll. The EULA says

# You also agree not to permit further 
distribution of the
# Redistributables by your end users except 
you may permit further
# redistribution of the Redistributables by 
your distributors to your
# end-user customers if your distributors 
only distribute the
# Redistributables in conjunction with, and 
as part of, the Licensee
# Software, you comply with all other terms 
of this EULA, and your
# distributors comply with all restrictions 
of this EULA that are
# applicable to you.

In this text, "you" is the licensee of VS 
2003 (i.e. me, redistributing
msvcr71.dll as part of Python 2.5), and the 
"Redistributable" is
msvcr71.dll. The "Licensee Software" is "a 
software application product
developed by you that adds significant and 
primary functionality to the
Redistributables", i.e. python25.dll.

IANAL; this is not legal advise."


jim-on-linux
http://www.inqvista.com











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


Re: Checking if a variable is a dictionary

2008-03-06 Thread Bruno Desthuilliers
Jeffrey Seifried a écrit :
(snip)
> if type(a)==type({}):
> print 'a is a dictionary'

This instanciates a dict, call type() on it, and discard the dict - 
which is useless since the dict type is a builtin. Also, when you want 
to test identity, use an identity test.

if type(a) is dict:
print "blah blah blah"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking if a variable is a dictionary

2008-03-06 Thread Bruno Desthuilliers
Guillermo a écrit :
> Wow, I think I'm gonna like this forum. Thank you all for the prompt
> answers!

Welcome onboard !-)

>> What makes you say you "need" to know this ? Except for a couple corner
>> cases, you usually don't need to care about this. If you told us more
>> about the actual problem (instead of asking about what you think is the
>> solution), we might be of more help...
> 
> Good point.
> 
> I want to iterate recursively a dictionary whose elements might be
> strings or nested tuples or dictionaries and then convert values to a
> tagged format according to some rules.

If you're absolutely definitively 101% sure that you'll never have 
anything else in your dict - IOW : this dict is an internal part of your 
module, produced by the module and consumed by the module -, then it 
*might* be one of the corner cases where testing type (either directly 
or - preferably - via isinstance) is the right thing to do.

> d = {'a':"i'm a", 'b':(1,2,3),'c':{'a':"i'm a",'x':"something",'y':
> ('a','b','c')}}
> 
> I'm just designing the algorithm, but I think Python dictionaries can
> hold any kind of sequence?

Any Python object (which include classes, modules, functions etc) can be 
used as value.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >