pickling instances of metaclass generated classes

2011-12-29 Thread lars van gemerden
Hello,

Can someone help me with the following:

I am using metaclasses to make classes and these classes to make
instances. Now I want to use multiprocessing, which needs to pickle
these instances.

Pickle cannot find the class definitions of the instances. I am trying
to add a line to the __new__ of the metaclass to add the new class
under the right name in the right module/place, so pickle can find
it.

Is this the right approach? Can anyone explain to me where/how to add
these classes for pickle to find and maybe why?

Thanks in advance,

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


Re: Help in rotate 13 program

2011-12-29 Thread Peter Otten
Sayantan Datta wrote:

> please help me, this code doesn't work,
> the output file comes out to be empty. How do i fix it? and where is it
> going wrong?

I don't know if that's a copy-n-paste error: the indentation of

>   if __name__ == '__main__' :
> for line in sys.stdin :
>   for char in line :
> sys.stdout.write(rotate13_letter(char))

should be

if __name__ == '__main__':
for line in sys.stdin:
for char in line:
sys.stdout.write(rotate13_letter(char))


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


Re: Help in rotate 13 program

2011-12-29 Thread Chris Angelico
On Thu, Dec 29, 2011 at 10:48 PM, Sayantan Datta  wrote:
>     for line in sys.stdin :
>       for char in line :
> sys.stdout.write(rotate13_letter(char))
>
> cat sample.html | python rot13.py rot13.html

You're reading from stdin, which is correct, but you're writing to
stdout and not redirecting it. You need to put an arrow before
rot13.html to indicate redirection:

cat sample.html | python rot13.py >rot13.html

Note though that 'cat' is superfluous here; all you need to do is
redirect input:
python rot13.py rot13.html

Hope that helps!

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


Re: About instance.name look up order

2011-12-29 Thread Kev Dwyer
Prim wrote:

> First, sorry about my poor english.
> Put these in IPython under ubuntu.
> 
-
> class C:
> def __init__(self):
> self.x = 1
> def print(self):
> print self.x
> c = C()
> c.x --> 1, so c.x mean a attr of c named 'x'
> c.print() --> pirnt 1, so c.print mean a method of c named 'print'
> 
-
> class C:
> def __init__(self):
> self.x = 1
> def x(self):
> print 'x method'
> def y(self):
> print 'y method'
> c = C()
> c.x --> 1
> c.x() --> TypeError: 'int' object is not callable
> c.y --> bound method C.y
> #Q1: instance.name will get the attr first, than method?
> 
-
> class C:
> def x(self):
> print 'x method'
> def __getattr__(self, attr):
> print 'in __getattr__ method'
> return attr
> c = C()
> c.x --> print in __getattr__ method, then throw TypeError: 'str'
> object is not callable
> c.x() --> print in __getattr__ method, x method 2 lines
> #Q2: why c.x would get a exception?
> 
> t = c.x
> t --> print in __getattr__ method, then throw TypeError: 'str' object
> is not callable
> t() --> print x method
> t = c.x() --> print x method, t == None
> #Q3 why t=c.x() and c.x() output different?
> 
> #Q4, if when I define the class use property too, then instance.name
> look up order would be?
> 
> Thanks for your reply.

Hello,

Python always looks for attributes in the instance first, then in the class,
and then in the class's superclasses.  In your first example, by defining
"x" in C.__init__ you are creating an instance attribute named "x".  When 
the attribute c.x is requested, Python finds an attribute "x" in the 
instance and returns it; the method "x" is found in the class, but the 
attribute lookup does not proceed this far.

Try looking at C.__dict__ and c.__dict__ in the interpreter to see how the 
attributes are stored.  

See also 
http://docs.python.org/reference/datamodel.html#customizing-attribute-access

Cheers

Kev


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


Re: logging.getLogger( __name__ )

2011-12-29 Thread Ben Finney
Ram  writes:

> How does this line work?

What line? Please present some code in an example that we can run. Make
the example as small as possible so it's clear what you are asking about.

-- 
 \   “See, in my line of work you gotta keep repeating things over |
  `\   and over and over again, for the truth to sink in; to kinda |
_o__)   catapult the propaganda.” —George W. Bush, 2005-05 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Good notation for showing MVC interactions (i.e. Django)

2011-12-29 Thread Alec Taylor
An example of a BPMN2 diagram with swimlanes, which I created for a
project: http://i40.tinypic.com/262r6nr.jpg

What I am looking for is something suited towards showing architecture
bounds and the interactions between each section of MVC.

> I find that when thinking something through at the whiteboard with
> another developer, the most common diagram I'll use is a UML sequence
> diagram.  I drew one on the wall just yesterday.  Here's one
> (http://www.panix.com/~roy/SongzaSessionHandoff.pdf) I did up a bit
> fancier a while ago while working through a gnarly design problem.
>

That's a good notation, and one which I will use for RESTful API modelling.

I sometimes use use-case diagrams and quite rarely also use class
diagrams and ER Diagrams.

I use BPMN2 to show logic to both technical and non-technical team-members.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which libraries for Python 2.5.2 [SOLVED]

2011-12-29 Thread W. eWatson

On 12/29/2011 9:44 AM, Ian Kelly wrote:

On Thu, Dec 29, 2011 at 10:04 AM, Dennis Lee Bieber
  wrote:

On Thu, 29 Dec 2011 09:54:48 -0500, Dennis Lee Bieber
  wrote:

Talking to myself..



   According to the pop-up I get (Win7) when supplying an invalid
argument,


Maybe regsrv32 was rewritten for Win7 64bit -- and assumed folks
would run it from the start dialog (or file search in Win7) since the
error messages do pop-up in windows, even when running in a command
shell.


As far as I know, it's always been like that.
Well, I thought I'd take the PC to a computer shop to see why when I 
move windows they shake a bit.  The technician took about 2 minutes to 
show me uninstalled devices under System Devices. He thought they should 
be fixed. The system was showing lots of device errors. They wanted $75 
to repair it, but I told them a friend who will use the PC will have to 
decide that.


This PC belonged to my wife at one time for 5 years. She had put Linux 
on it, but she no longer needed it. I restored it to XP Home. When I 
told her where the problems were she found a driver DVD, so I'm using it 
now to fill in the gaps. Maybe it'll get by the dll problem. It 
certainly is adding a VGA driver, so I think the window wobbles may get 
fixed.


Well, it now works w/o any difficulty. It was the incomplete install 
that did it. It now has acrobat, wallpaper, etc, like most XP systems. 
No more wobbles! Yea!


Thanks to all that helped.




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


Re: Get Class properties

2011-12-29 Thread Emeka
Chris,

Thanks a million!

Regards,
Emeka

On Thu, Dec 29, 2011 at 1:27 AM, Chris Angelico  wrote:

> On Wed, Dec 28, 2011 at 11:13 PM, Emeka  wrote:
> > Hello All,
> >
> > I have seen what I am looking for.. __dict__.
> >
>
> Yep! You may also want to look at the dir() function.
>
> Chris Angelico
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
*Satajanus  Nig. Ltd


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


Re: Help in rotate 13 program

2011-12-29 Thread Robert Kern

On 12/29/11 11:48 AM, Sayantan Datta wrote:

cat sample.html | python rot13.py rot13.html


cat sample.html | python rot13.py > rot13.html

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: pickling instances of metaclass generated classes

2011-12-29 Thread Robert Kern

On 12/29/11 9:55 AM, lars van gemerden wrote:

Hello,

Can someone help me with the following:

I am using metaclasses to make classes and these classes to make
instances. Now I want to use multiprocessing, which needs to pickle
these instances.

Pickle cannot find the class definitions of the instances. I am trying
to add a line to the __new__ of the metaclass to add the new class
under the right name in the right module/place, so pickle can find
it.

Is this the right approach? Can anyone explain to me where/how to add
these classes for pickle to find and maybe why?


Can you post some code (preferably pared down to a minimal example that fails)? 
I'm not really clear on what you are doing. I would expect that a class defined 
by a class statement would usually work fine unless if the metaclass is doing 
something particularly weird to it.


In any case, you can probably just explicitly register a reduction function for 
each type using copy_reg.pickle():


http://docs.python.org/library/copy_reg

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: Which libraries for Python 2.5.2

2011-12-29 Thread Ian Kelly
On Thu, Dec 29, 2011 at 10:04 AM, Dennis Lee Bieber
 wrote:
> On Thu, 29 Dec 2011 09:54:48 -0500, Dennis Lee Bieber
>  wrote:
>
>        Talking to myself..
>
>>
>>       According to the pop-up I get (Win7) when supplying an invalid
>>argument,
>>
>        Maybe regsrv32 was rewritten for Win7 64bit -- and assumed folks
> would run it from the start dialog (or file search in Win7) since the
> error messages do pop-up in windows, even when running in a command
> shell.

As far as I know, it's always been like that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Where does this readOne() method come from?

2011-12-29 Thread tinnews
Chris Angelico  wrote:
> On Thu, Dec 29, 2011 at 6:04 AM,   wrote:
> > In the (rather sparse) documentation for the vobject package it has,
> > in the section about parsing iCalendar objects, the following:-
> >
> >    >>> parsedCal = vobject.readOne(icalstream)
> 
> Presumably you have this vobject package. Assuming it's installed
> correctly, all you need to do is:
> 
> import vobject
> 
> and then vobject.readOne should be available.
> 
Digging harder into the epydoc documentation I finally found
vobject.vobject.readOne().

However having twice been befuddled by vobject, once when using it for
vCard and this time using it for vCal I've decided to move back to the
python-icalendar I was using before.

The only reason I tried to use vobject is that it's in the Ubuntu
repositories (I doing this on an xubuntu system), but it doesn't
appear to have a current maintainer and python-icalendar does so even
though it's a 'manual' install I'm sticking with python-icalendar.

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


Which library for audio playback ?

2011-12-29 Thread Jérôme
I'm writing a small application that plays sound through the speakers. The
sounds are juste sine waves of arbitrary frequency I create in the code, not
sample .wav files.

I didn't expect the choice for an audio library to be that complicated. There
are several libraries, and none of them seems to be *the* reference.

Searching the web, I found these resources :

http://wiki.python.org/moin/Audio
http://wiki.python.org/moin/PythonInMusic

* I privileged ALSA to OSS as I read elsewhere that OSS is deprecated, or on
  its way to be. (And JACK is not widely installed, apart from specific
  applications (audio work).)

* Then, I picked the alsaaudio library (http://pyalsaaudio.sourceforge.net/).
  I don't remember exactly why. I think the project had the most recent
  updates. I don't think any project claims to be (let alone aims at being)
  complete.

I'm wondering if I made a sensible choice.

There are other libraries, including the following two that are platform
independent :

* PyAudiere (http://pyaudiere.org/), OSS , not packaged for debian
* PyAudio (http://people.csail.mit.edu/hubert/pyaudio/)

What solution would you recommend ?

Are there other criterions I should take into account ?

Thanks.

-- 
Jérôme
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help in rotate 13 program

2011-12-29 Thread Chris Angelico
On Fri, Dec 30, 2011 at 3:25 AM, Sayantan Datta  wrote:
> did that, but the output file is still empty? Does the fault lie somewhere
> else?

I'm not sure if it's a copy-paste problem, but check your indentation:
your "if __name__" line seems to be indented, it should be flush left.
Indentation makes it part of the function, so your script will define
a function and never call it.

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


About instance.name look up order

2011-12-29 Thread Prim
First, sorry about my poor english.
Put these in IPython under ubuntu.
-
class C:
def __init__(self):
self.x = 1
def print(self):
print self.x
c = C()
c.x --> 1, so c.x mean a attr of c named 'x'
c.print() --> pirnt 1, so c.print mean a method of c named 'print'
-
class C:
def __init__(self):
self.x = 1
def x(self):
print 'x method'
def y(self):
print 'y method'
c = C()
c.x --> 1
c.x() --> TypeError: 'int' object is not callable
c.y --> bound method C.y
#Q1: instance.name will get the attr first, than method?
-
class C:
def x(self):
print 'x method'
def __getattr__(self, attr):
print 'in __getattr__ method'
return attr
c = C()
c.x --> print in __getattr__ method, then throw TypeError: 'str'
object is not callable
c.x() --> print in __getattr__ method, x method 2 lines
#Q2: why c.x would get a exception?

t = c.x
t --> print in __getattr__ method, then throw TypeError: 'str' object
is not callable
t() --> print x method
t = c.x() --> print x method, t == None
#Q3 why t=c.x() and c.x() output different?

#Q4, if when I define the class use property too, then instance.name
look up order would be?

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


Re: Help in rotate 13 program

2011-12-29 Thread Sayantan Datta
On Thu, Dec 29, 2011 at 5:34 PM, Chris Angelico  wrote:

> On Thu, Dec 29, 2011 at 10:48 PM, Sayantan Datta 
> wrote:
> > for line in sys.stdin :
> >   for char in line :
> > sys.stdout.write(rotate13_letter(char))
> >
> > cat sample.html | python rot13.py rot13.html
>
> You're reading from stdin, which is correct, but you're writing to
> stdout and not redirecting it. You need to put an arrow before
> rot13.html to indicate redirection:
>
> cat sample.html | python rot13.py >rot13.html
>
> Note though that 'cat' is superfluous here; all you need to do is
> redirect input:
> python rot13.py rot13.html
>
> Hope that helps!
>
> Chris Angelico
> --
> http://mail.python.org/mailman/listinfo/python-list
>

did that, but the output file is still empty? Does the fault lie somewhere
else?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which libraries for Python 2.5.2

2011-12-29 Thread W. eWatson

On 12/29/2011 6:54 AM, Dennis Lee Bieber wrote:

On Wed, 28 Dec 2011 21:56:59 -0800, "W. eWatson"
  wrote:



It didn't like that either. Got "msvcp71.dll was located but the dll
server entry was not found. File could not be registered."

Arguments are /u,/s/i/n.


According to the pop-up I get (Win7) when supplying an invalid
argument,

/n - do not call DllRegisterServer; this option must be used with /i
and that reads
/i - Call DllInstall passing it an optional [cmdline]; when used
with /u calls dll uninstall

So.. If the register server entry point was not found, maybe you
should try with /i/n to make it call the /other/ registration entry
point.

Well, it's worth a try. However, what "other" entry point.




{And, in line with the other commentators; I don't even use start/run
for the command shell -- I use the shell often enough to have put a
dedicated shortcut on the start menu itself (and have since added
PowerShell shortcuts). Only thing I use start/run with is the registry
editor (regedt32 or regedit) and to start the despised Internet Explorer
(iexplore, which has otherwise been removed from direct mouse access) --
in short; only programs with GUI interfaces get started from start/run}


To keep it simple, I now just enter cmd, and work there.  I'm not 
usually working with these low level operations. Occasionally, I use 
some of the network commands.


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


Good notation for showing MVC interactions (i.e. Django)

2011-12-29 Thread Alec Taylor
Good morning,

I'm developing various websites and functionality to cater to various
different use-cases up in Django.

Is there a good notation for showing what behaviour is at each stage,
i.e. using swimlanes?

I use BPMN 2 notation for everything, but I feel I am overusing this,
and that there would be a more suitable one for this.

Thanks for all suggestions,

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


Help in rotate 13 program

2011-12-29 Thread Sayantan Datta
please help me, this code doesn't work,
the output file comes out to be empty. How do i fix it? and where is it
going wrong?

==rot13.py==
#!/usr/bin/env python

import sys
import string

CHAR_MAP=dict(zip(string.ascii_lowercase, string.ascii_lowercase[13:26] +
string.ascii_lowercase[0:13]))
def rotate13_letter(letter) :
  """
  Return the 13-char rotation of a letter
  """
  do_upper = False
  if letter.isupper() :
do_upper = True
  letter = letter.lower()
  if letter not in CHAR_MAP :
return letter
  else :
letter = CHAR_MAP[letter]
if do_upper :
  letter=letter.upper()
return letter
  if __name__ == '__main__' :
for line in sys.stdin :
  for char in line :
sys.stdout.write(rotate13_letter(char))


===sample.html===

   
   Hello, World! 
   
   
  
  Hi there, all of you earthlings
  
  
  Take us to your leader.
  
  



===TERMINAL
this is what i run in the terminal,
cat sample.html | python rot13.py rot13.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which libraries for Python 2.5.2

2011-12-29 Thread W. eWatson

On 12/29/2011 9:04 AM, Dennis Lee Bieber wrote:

On Thu, 29 Dec 2011 09:54:48 -0500, Dennis Lee Bieber
  wrote:

Talking to myself..

It's the best way to get people to listen to you. :-)




According to the pop-up I get (Win7) when supplying an invalid
argument,


Maybe regsrv32 was rewritten for Win7 64bit -- and assumed folks
would run it from the start dialog (or file search in Win7) since the
error messages do pop-up in windows, even when running in a command
shell.
I'm installing Python on an XP PC that's 5 years old. This PC I'm 
writing from is Win7.

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


Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-29 Thread Eelco
On Dec 28, 11:29 pm, Lie Ryan  wrote:
> On 12/28/2011 11:08 PM, Eelco wrote:
>
> > I personally feel any performance benefits are but a plus; they are
> > not the motivating factor for this idea. I simply like the added
> > verbosity and explicitness, thats the bottom line.
>
> Any performance benefits are a plus, I agree, as long as it doesn't make
> my language looks like Perl. Now get off my lawn!

Im no perl expert, but it says on the wikipedia page a common
criticism is its overuse of otherwise meaningless special characters;
and I would agree; I puked a little in my mouth looking at the code
samples.

I would argue that the use of single special characters to signal a
relatively complex and uncommon construct is exactly what I am trying
to avoid with this proposal.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: About instance.name look up order

2011-12-29 Thread Ian Kelly
On Thu, Dec 29, 2011 at 9:07 AM, Prim  wrote:
> class C:
>    def x(self):
>        print 'x method'
>    def __getattr__(self, attr):
>        print 'in __getattr__ method'
>        return attr
> c = C()
> c.x --> print in __getattr__ method, then throw TypeError: 'str'
> object is not callable
> c.x() --> print in __getattr__ method, x method 2 lines
> #Q2: why c.x would get a exception?

I'm not sure exactly what's going on there, but as a general rule you
should use new-style classes, not classic classes, which are
deprecated and have been removed in Python 3.  In Python 2 if you
define a class without any base classes, you get a classic class.  To
define C as a new-style class in Python 2, derive it from object (or
another new-style class):

>>> class C(object):
... def x(self):
... print 'x method'
... def __getattr__(self, attr):
... print 'in __getattr__ method'
... return attr
...
>>> c = C()
>>> c.x
>
>>> c.x()
x method

Note that in this case __getattr__ never gets called because the name
was found using the normal lookup mechanism.  You would need to use
__getattribute__ if you want it to be called unconditionally.

> #Q4, if when I define the class use property too, then instance.name
> look up order would be?

You can't use properties in classic classes.  In a new-style class, if
you access a property, then any instance attribute with the same name
is ignored and can't be set in the first place.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-29 Thread Eelco
On Dec 29, 2:23 pm, Steven D'Aprano  wrote:
> On Thu, 29 Dec 2011 03:55:14 -0800, Eelco wrote:
> > I would argue that the use of single special characters to signal a
> > relatively complex and uncommon construct is exactly what I am trying to
> > avoid with this proposal.
>
> This would be the proposal to change the existing
>
>     head, *tail = sequence
>
> to your proposed:
>
>     head, tail:: = ::sequence
>
> (when happy with the default list for tail), or
>
>     head, tail::tuple = ::sequence
>
> to avoid an explicit call to "tail = tuple(tail)" after the unpacking.
>
> Either way, with or without an explicit type declaration on the left hand
> side, you are increasing the number of punctuation characters from one to
> four. If your aim is to minimize the number of punctuation characters,
> you're doing it wrong.
>
> --
> Steven

The goal is not to minimize the number of (special) characters to
type. To goal is to minimize the number of special characters which
are hard to interpret at a glance. I would prefer : over ::, but both
are a single special character construct. Adding those characters once
more on the rhs is similarly, not an increase in the number of
concepts employed; merely a more explicit form of the same construct.

And besides, I dont much like 'head, tail:: = ::sequence'. I threw
that out there to appease the terseness advocates, but to me it
largely defeats the purpose, because indeed it is hardly any different
from the original. I like the explicit mentioning of the collection
type to be constructed; that is what really brings it more towards
'for line in file' explicit obviousness to my mind.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-29 Thread Steven D'Aprano
On Thu, 29 Dec 2011 03:55:14 -0800, Eelco wrote:

> I would argue that the use of single special characters to signal a
> relatively complex and uncommon construct is exactly what I am trying to
> avoid with this proposal.

This would be the proposal to change the existing

head, *tail = sequence

to your proposed:

head, tail:: = ::sequence

(when happy with the default list for tail), or

head, tail::tuple = ::sequence

to avoid an explicit call to "tail = tuple(tail)" after the unpacking.

Either way, with or without an explicit type declaration on the left hand 
side, you are increasing the number of punctuation characters from one to 
four. If your aim is to minimize the number of punctuation characters, 
you're doing it wrong.


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


Re: Help in rotate 13 program

2011-12-29 Thread Dave Angel

On 12/29/2011 11:25 AM, Sayantan Datta wrote:

On Thu, Dec 29, 2011 at 5:34 PM, Chris Angelico  wrote:


On Thu, Dec 29, 2011 at 10:48 PM, Sayantan Datta
wrote:

 for line in sys.stdin :
   for char in line :
sys.stdout.write(rotate13_letter(char))

cat sample.html | python rot13.py rot13.html

You're reading from stdin, which is correct, but you're writing to
stdout and not redirecting it. You need to put an arrow before
rot13.html to indicate redirection:

cat sample.html | python rot13.py>rot13.html

Note though that 'cat' is superfluous here; all you need to do is
redirect input:
python rot13.pyrot13.html

Hope that helps!

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


did that, but the output file is still empty? Does the fault lie somewhere
else?

Both Peter and Chris pointed out that you have the if __name__ == 
"__main__" line indented.  If that's true in your actual file, then the 
program does nothing useful.


Why not run it without output redirection, and see what it displays?  
And stick an unindented print line in there, just to see it do something.




--

DaveA

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


Re: pickling instances of metaclass generated classes

2011-12-29 Thread Ian Kelly
On Thu, Dec 29, 2011 at 2:55 AM, lars van gemerden  wrote:
> Hello,
>
> Can someone help me with the following:
>
> I am using metaclasses to make classes and these classes to make
> instances. Now I want to use multiprocessing, which needs to pickle
> these instances.
>
> Pickle cannot find the class definitions of the instances. I am trying
> to add a line to the __new__ of the metaclass to add the new class
> under the right name in the right module/place, so pickle can find
> it.
>
> Is this the right approach? Can anyone explain to me where/how to add
> these classes for pickle to find and maybe why?

It sounds like you're trying to do something like this?

>>> class MetaClass(type):
... pass
...
>>> instance = MetaClass('', (object,), {})()
>>> instance
<__main__. object at 0x00CC00F0>
>>> import pickle
>>> pickle.dumps(instance)
Traceback (most recent call last):
  File "", line 1, in 
  File "c:\python27\lib\pickle.py", line 1374, in dumps
Pickler(file, protocol).dump(obj)
  File "c:\python27\lib\pickle.py", line 224, in dump
self.save(obj)
  File "c:\python27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
  File "c:\python27\lib\pickle.py", line 401, in save_reduce
save(args)
  File "c:\python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
  File "c:\python27\lib\pickle.py", line 562, in save_tuple
save(element)
  File "c:\python27\lib\pickle.py", line 295, in save
self.save_global(obj)
  File "c:\python27\lib\pickle.py", line 748, in save_global
(obj, module, name))
pickle.PicklingError: Can't pickle '>:
it's not found as __main__.


Yeah, pickle's not going to work with anonymous classes.  As you
suggest, you could dynamically add the classes to the module namespace
so that pickle.dumps will find them, but bear in mind that they will
also have to exist when calling pickle.loads, so you will need to be
able to reconstruct the same anonymous classes before unpickling later
on.

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


PySide / PyQt autocompletion in IDEs

2011-12-29 Thread Merwin

Hi,

I would like to work with PyQt / PySide, but there is a small problem : 
methods arguments are not completed by IDE's autocompletion.


When, typing "PySide.", I correctly get the module's attributes, but 
when I want to see what arguments are expected to a constructor / 
method, all I get is *args, **kwargs.


I perfectly understand why this happen, but do you know a way to get 
around this ?


I spend more time looking for arguments in Qt's documentation than 
effectively programming, which is a problem :-/


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


Augmented online documentation

2011-12-29 Thread Aryeh Leib Taurog
I have created for myself a small google chrome extension which
generates a treeview toc pane of the online python docs as well as the
matplotlib docs.  This is intended to facilitate doc navigation, much
the same way the navigation pane in a chm viewer does.

Read more and install it at https://bitbucket.org/altaurog/sphdoctoc/overview

enjoy,
Aryeh Leib Taurog
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Py-dea: Streamline string literals now!

2011-12-29 Thread Lie Ryan

On 12/29/2011 12:44 PM, Dan Sommers wrote:

On Wed, 28 Dec 2011 22:54:16 +, Steven D'Aprano wrote:


On Wed, 28 Dec 2011 11:36:17 -0800, Rick Johnson wrote:


The point is people, we should be using string delimiters that are
ANYTHING besides " and '. Stop being a sheep and use your brain!


"ANYTHING", hey?

I propose we use ئ and ร as the opening and closing string delimiters.
Problem solved!


Why stop at pre-determined, literal delimiters?  That's way too easy on
the parser, whether that parser is a computer or a person.

__string_delimiter__ = Ω  # magic syntax; no quotes needed

x = ΩhelloΩ

__string_delimiter__ = #  # that first # isn't a comment marker

x = # this isn't a comment; it's part of the string
this is a multi-line string
#

__string_delimiter__ = ''  # the delimiter is delimited by whitespace
# now I can have comments, again, too

x = ''"hello"''  # now x contains two double-quote characters

I'm sure that the implementation is trivial, and it's so much easier to
write strings that contain quotes (not to mention how easy it is to read
those strings back later).


right and you can generalize this idea even further

__comment_marker__ = $
__string_delimiter__ = [#, %]
$ also, even further
__comment_marker_keyword = #__my_own_comment_marker__%
__my_own_comment_marker__ = [&, *]
__assignment_symbol__ = <-
__attribute_delimiter__ <- -> & for attributes *
__call_delimiter__ = [!,@]
l = []
l->append!5@

you're a genius!!

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


Re: Py-dea: Streamline string literals now!

2011-12-29 Thread Chris Angelico
On Fri, Dec 30, 2011 at 10:19 AM, Lie Ryan  wrote:
> right and you can generalize this idea even further

Don't stop generalizing. Everything should be custom.
http://rosuav.com/1/?id=683

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


Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-29 Thread Lie Ryan

On 12/30/2011 12:23 AM, Steven D'Aprano wrote:

On Thu, 29 Dec 2011 03:55:14 -0800, Eelco wrote:


I would argue that the use of single special characters to signal a
relatively complex and uncommon construct is exactly what I am trying to
avoid with this proposal.


This would be the proposal to change the existing

 head, *tail = sequence

to your proposed:

 head, tail:: = ::sequence

(when happy with the default list for tail), or

 head, tail::tuple = ::sequence

to avoid an explicit call to "tail = tuple(tail)" after the unpacking.

Either way, with or without an explicit type declaration on the left hand
side, you are increasing the number of punctuation characters from one to
four. If your aim is to minimize the number of punctuation characters,
you're doing it wrong.


Another drawback of it is that it looks misleadingly similar to C++ 
namespace notation.


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


Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-29 Thread Chris Angelico
On Fri, Dec 30, 2011 at 10:24 AM, Lie Ryan  wrote:
> Another drawback of it is that it looks misleadingly similar to C++
> namespace notation.

Granted, but I don't see that as a drawback. The current notation is
just as similar to C's pointer-dereference notation, but that hasn't
led people to think that tail holds a pointer to the location where
something should be stored.

This would be a serious concern with notations that are common across
many languages (eg "x*y" to mean multiplication, which isn't strictly
what mathematics uses), but with language-specific notations,
especially such brief ones, it's understood that there'll be
duplication.

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


Re: db agnostic admin for Flask?

2011-12-29 Thread umchaselee
I was considering building an admin that would consist of two components, a 
totally separate HTML/CSS/JS frontend that presumed API endpoints, and a 
backend written in Tornado (similar to Flask in a lot of ways) that caught all 
of the presumed endpoints and performed the db operations.  The idea of 
separating them is to make the frontend portable across backends so that a 
backend could be written in Tornado/Flask/Django/RoR(*shudder*)/whatever you 
want as long as it followed the conventions leading to the API endpoints.  I've 
seen a couple backends out there but haven't been too happy with any of them, 
and I haven't found any doing something like this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help in rotate 13 program

2011-12-29 Thread Sayantan Datta
On Thu, Dec 29, 2011 at 10:09 PM, Dave Angel  wrote:

> On 12/29/2011 11:25 AM, Sayantan Datta wrote:
>
>> On Thu, Dec 29, 2011 at 5:34 PM, Chris Angelico  wrote:
>>
>>  On Thu, Dec 29, 2011 at 10:48 PM, Sayantan Datta
>>> wrote:
>>>
 for line in sys.stdin :
   for char in line :
 sys.stdout.write(rotate13_**letter(char))

 cat sample.html | python rot13.py rot13.html

>>> You're reading from stdin, which is correct, but you're writing to
>>> stdout and not redirecting it. You need to put an arrow before
>>> rot13.html to indicate redirection:
>>>
>>> cat sample.html | python rot13.py>rot13.html
>>>
>>> Note though that 'cat' is superfluous here; all you need to do is
>>> redirect input:
>>> python rot13.pyrot13.**html
>>>
>>> Hope that helps!
>>>
>>> Chris Angelico
>>> --
>>> http://mail.python.org/**mailman/listinfo/python-list
>>>
>>>  did that, but the output file is still empty? Does the fault lie
>> somewhere
>> else?
>>
>>  Both Peter and Chris pointed out that you have the if __name__ ==
> "__main__" line indented.  If that's true in your actual file, then the
> program does nothing useful.
>
> Why not run it without output redirection, and see what it displays?  And
> stick an unindented print line in there, just to see it do something.
>
>
>
> --
>
> DaveA
>
>
hmm, yes, it was, noticed it right now. Huh, i made such a silly mistake..
Anyway, thanks a lot. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Generating sin/square waves sound

2011-12-29 Thread Paulo da Silva
Hi,
Sorry if this is a FAQ, but I have googled and didn't find any
satisfatory answer.

Is there a simple way, preferably multiplataform (or linux), of
generating sinusoidal/square waves sound in python?

Thanks for any answers/suggestions.
-- 
http://mail.python.org/mailman/listinfo/python-list