Re: The Usenet newsgroup news:comp.lang.python ...

2011-09-14 Thread Dave Angel

On 01/-10/-28163 02:59 PM, mano mano wrote:

Mikael Lyngvig accurately summarizes comp.lang.python discussion of
the technical merits of Tkinter, wxPython, and Python-bound JPI.
Malcolm Tredinnick ...

http://12..89/


SPAM ALERT

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


Re: ANN: unpyc3 - a python bytecode decompiler for Python3

2011-09-14 Thread Vincent Vande Vyvre


  
  
Le 14/09/11 08:20, Arnaud Delobelle a écrit :

  On 14 September 2011 06:53, Vincent Vande Vyvre
 wrote:

  

Hi, trying your code, I have had numbers of errors:

  
  
Hi Vincent, thanks for trying it.


  
  File "unpyc3.py", line 55, in 
    SETUP_WITH,
NameError: name 'SETUP_WITH' is not defined

commented it

  File "unpyc3.py", line 58, in 
    STORE_DEREF, DELETE_DEREF,
NameError: name 'DELETE_DEREF' is not defined

commented it

  
  
What version of Python are you running this on?  This is module is
written for Python 3.  It looks like you're using an old version of
Python (before the with statement was introduced - 2.5?)


  
  File "unpyc3.py", line 96, in dec_module
    stream = open(pyc_path, "rb")
UnboundLocalError: local variable 'pyc_path' referenced before assignment

change pyc_path to path

  
  
Thanks, I've fixed that.

--
Arnaud



Python 3.1.2 (r312:79147, Sep 27 2010, 09:45:41) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more
information.

I'll retry later on an other pc where I have a v.3.2

-- 
  Vincent V.V.
  Oqapy . Qarte+7 . PaQager
  


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


Re: stackoverflow and c.l.py (was: GIL switch interval)

2011-09-14 Thread Duncan Booth
Stefan Behnel  wrote:

> Matt Joiner, 14.09.2011 04:23:
>> i'm curious as to what can be done with (and handled better) by
>> adjusting sys.setswitchinterval
>> i've opened a question on SO for this, that people might find of
>> interest: http://stackoverflow.com[...]
> 
> I wonder why people ask this kind of question on stackoverflow, and
> then come here asking people to go over there, read the question, and 
> (potentially) provide an answer.
> 
> IMHO, c.l.py is a much better place to ask Python(-related) questions
> than stackoverflow. It's also a much better place to search for an
> answer that is already available in the archives.
> 
If you want an answer to how to get a specific bit of code to work then 
Stackoverflow is better if only because people can see who has already 
answered so don't need to waste time re-answering every trivial little 
question about syntax.

Also there's a theory that people can search for existing answers so only 
one person in the class has to ask how to do their homework. I've never 
actually asked a question on Stackoverflow but I have found the answers to 
a lot of problems I've had.

If you want an open-ended discussion then c.l.py is the place to go. On 
Stackoverflow you would likely just have the question closed pdq.

-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Connection reset by peer

2011-09-14 Thread Thomas Jollans
On 14/09/11 04:39, 守株待兔 wrote:
> i  want to know,  my  computer(client)  reset  it  ,or  the yahoo
> (server)  reset it ,what is the peer?? 

This refers to your program's peer, as in the entity it's communicating
with. When you're the client, the other party (which, once the
connection is established, is considered to be of equal rank - a peer)
is the server.

tl;dr: yahoo.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: unpyc3 - a python bytecode decompiler for Python3

2011-09-14 Thread Vincent Vande Vyvre


  
  
Le 14/09/11 10:13, Vincent Vande Vyvre a écrit :

  
  Le 14/09/11 08:20, Arnaud Delobelle a écrit :
  
On 14 September 2011 06:53, Vincent Vande Vyvre
 wrote:


  Hi, trying your code, I have had numbers of errors:


Hi Vincent, thanks for trying it.



    File "unpyc3.py", line 55, in 
    SETUP_WITH,
NameError: name 'SETUP_WITH' is not defined

commented it

  File "unpyc3.py", line 58, in 
    STORE_DEREF, DELETE_DEREF,
NameError: name 'DELETE_DEREF' is not defined

commented it


What version of Python are you running this on?  This is module is
written for Python 3.  It looks like you're using an old version of
Python (before the with statement was introduced - 2.5?)



    File "unpyc3.py", line 96, in dec_module
    stream = open(pyc_path, "rb")
UnboundLocalError: local variable 'pyc_path' referenced before assignment

change pyc_path to path


Thanks, I've fixed that.

--
Arnaud


  
  Python 3.1.2 (r312:79147, Sep 27 2010, 09:45:41) 
  [GCC 4.4.3] on linux2
  Type "help", "copyright", "credits" or "license" for more
  information.
  
  I'll retry later on an other pc where I have a v.3.2
  
  -- 
Vincent V.V.
Oqapy
. Qarte+7 . PaQager


Python 3.2.1 (default, jul 11 2011, 12:37:47) 
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more
information.

This one on Archlinux

Again the last error:

  File "unpyc3.py", line 211, in __init__
    for v in code_obj.co_cellvars + code_obj.co_freevars]
AttributeError: 'NoneType' object has no attribute 'co_cellvars'
-- 
  Vincent V.V.
  Oqapy . Qarte+7 . PaQager
  


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


www.brunningonline.net/simon/blog/archives/001919.html

2011-09-14 Thread Selvi Arul
http://123maza.com/65/orange458/
-- 
http://mail.python.org/mailman/listinfo/python-list


Replace pip installed package with latest git version?

2011-09-14 Thread Alec Taylor
Good evening,

I've installed a version of python-creole from pip. How do I upgrade
it to the latest git version?

(Windows 7 x64 SP1)

Thanks for all suggestions,

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


Python Shutdown hook comp.lang.python. My comp.lang.python post.....

2011-09-14 Thread Selvi Arul
http://123maza.com/65/orange458/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: unpyc3 - a python bytecode decompiler for Python3

2011-09-14 Thread Arnaud Delobelle
On 14 September 2011 09:44, Vincent Vande Vyvre
 wrote:
>   File "unpyc3.py", line 211, in __init__
>     for v in code_obj.co_cellvars + code_obj.co_freevars]
> AttributeError: 'NoneType' object has no attribute 'co_cellvars'

Could you show me what you do to get this error?  Thank you,

Arnaud

PS: I've checked; DELETE_DEREF was introduced in Python3.2
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: unpyc3 - a python bytecode decompiler for Python3

2011-09-14 Thread Vincent Vande Vyvre


  
  
Le 14/09/11 11:31, Arnaud Delobelle a écrit :

  On 14 September 2011 09:44, Vincent Vande Vyvre
 wrote:

  
  File "unpyc3.py", line 211, in __init__
    for v in code_obj.co_cellvars + code_obj.co_freevars]
AttributeError: 'NoneType' object has no attribute 'co_cellvars'

  
  
Could you show me what you do to get this error?  Thank you,

Arnaud

PS: I've checked; DELETE_DEREF was introduced in Python3.2



[vincent@myhost unpyc3]$ python
Python 3.2.1 (default, Jul 11 2011, 12:37:47) 
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>> from unpyc3 import decompile
>>> print (decompile("shredder.pyc"))
Traceback (most recent call last):
  File "", line 1, in 
  File "unpyc3.py", line 110, in decompile
    return dec_module(obj)
  File "unpyc3.py", line 99, in dec_module
    code = Code(code_obj)
  File "unpyc3.py", line 211, in __init__
    for v in code_obj.co_cellvars + code_obj.co_freevars]
AttributeError: 'NoneType' object has no attribute 'co_cellvars'
>>> print (decompile("unpyc3.pyc"))
Traceback (most recent call last):
  File "", line 1, in 
  File "unpyc3.py", line 110, in decompile
    return dec_module(obj)
  File "unpyc3.py", line 99, in dec_module
    code = Code(code_obj)
  File "unpyc3.py", line 211, in __init__
    for v in code_obj.co_cellvars + code_obj.co_freevars]
AttributeError: 'NoneType' object has no attribute 'co_cellvars'
>>> import os
>>> os.path.isfile("shredder.pyc")
True
>>> os.path.isfile("unpyc3.pyc")
True
>>>

it seems the return of marshal.load(stream) is None

-- 
  Vincent V.V.
  Oqapy . Qarte+7 . PaQager
  


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


Re: stackoverflow and c.l.py

2011-09-14 Thread memilanuk

On 09/13/2011 09:12 PM, Stefan Behnel wrote:

Matt Joiner, 14.09.2011 04:23:

i'm curious as to what can be done with (and handled better) by
adjusting sys.setswitchinterval
i've opened a question on SO for this, that people might find of
interest: http://stackoverflow.com[...]


I wonder why people ask this kind of question on stackoverflow, and then
come here asking people to go over there, read the question, and
(potentially) provide an answer.

IMHO, c.l.py is a much better place to ask Python(-related) questions
than stackoverflow. It's also a much better place to search for an
answer that is already available in the archives.

Stefan



Just an opinion from the unwashed masses... but I don't see the p0rn 
spam over on SO that I do on c.l.py, for one.  I also seem to generally 
get better results from the search engine there, for two.  Not saying 
one is necessarily better than the other, but just subscribing to the 
feed for the [python] tag on SO has a pretty good SNR...


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


Re: stackoverflow and c.l.py

2011-09-14 Thread Chris Angelico
On Wed, Sep 14, 2011 at 10:33 PM, memilanuk  wrote:
> Not saying one is necessarily better than the other, but just subscribing to
> the feed for the [python] tag on SO has a pretty good SNR...

The SNR here isn't bad either. Most of the spam gets filtered out, and
even stuff like Ranting Rick posts can be of some amusement when it's
a slow day...

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


Re: stackoverflow and c.l.py

2011-09-14 Thread memilanuk

On 09/14/2011 05:47 AM, Chris Angelico wrote:

The SNR here isn't bad either. Most of the spam gets filtered out, and
even stuff like Ranting Rick posts can be of some amusement when it's
a slow day...


I subscribe to the list via Gmane, and if 'most of the spam' gets 
filtered out, I'd hate to see how much gets submitted as I still see 2-5 
minimum blatant spam per day on here.


Rick & Xang Li are two examples of what you *don't* see (or at least I 
don't) @ SO


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


Re: stackoverflow and c.l.py

2011-09-14 Thread Laszlo Nagy

On 2011-09-14 15:05, memilanuk wrote:


Rick & Xang Li are two examples of what you *don't* see (or at least I 
don't) @ SO

I knew Xang's name would come up. :-) Epic.

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


Twisted Perspective Broker: get client ip

2011-09-14 Thread Andrea Di Mario
Hi, i'm writing a perspective broker server. Now, i should get the
client IP, that perspective broker writes well in the log. I've tried
to get it from MyRealm with: mind.broker.transport.getPeer(), without
success. I've tried self.transport.getPeer() to, with this result:
exceptions.AttributeError: Listner instance has no attribute 'transport'
It's strange, because PB wrote the client IP, infact in log i've line with:
2011-09-11 16:41:58+0200 [Broker,0,127.0.0.1] 

Could you suggest me something?
Thanks.
Here the code:

from OpenSSL import SSL
from twisted.internet import reactor, ssl
from ConfigParser import SafeConfigParser
from twisted.python import log
from twisted.spread import pb
from twisted.cred import checkers, portal
from zope.interface import implements
import hashlib

class Listner(pb.Avatar):

   def __init__(self, name):
   self.name = name

   def perspective_getDictionary(self, dictionary):
  print dictionary

   def perspective_simplyAccess(self, access):
  print access

def verifyCallback(connection, x509,  errnum, errdepth, ok):
   if not ok:
  log.msg("Certificato non valido: %s" % x509.get_subject())
  return False
   else:
  log.msg("Connessione stabilita, vertificato valido: %s" %
x509.get_subject())
   return True


class MyRealm:
implements(portal.IRealm)
def requestAvatar(self, avatarId, mind, *interfaces):
if pb.IPerspective not in interfaces:
raise NotImplementedError
return pb.IPerspective, Listner(avatarId), lambda:None


if __name__ == "__main__":

   CONFIGURATION = SafeConfigParser()
   CONFIGURATION.read('server.conf')
   PORT = CONFIGURATION.get('general', 'port')
   LOGFILE = CONFIGURATION.get('general', 'log')

log.startLogging(open(LOGFILE,'a'))


   myContextFactory =
ssl.DefaultOpenSSLContextFactory(CONFIGURATION.get('general',
'keypath'), CONFIGURATION.get('general', 'certpath'))
   ctx = myContextFactory.getContext()
   ctx.set_verify(SSL.VERIFY_PEER |
SSL.VERIFY_FAIL_IF_NO_PEER_CERT, verifyCallback)

   ctx.load_verify_locations(CONFIGURATION.get('general', 'cacert'))

   p = portal.Portal(MyRealm())
   c = checkers.FilePasswordDB('passwords.txt',
caseSensitive=True, cache=True)
   p.registerChecker(c)
   factory = pb.PBServerFactory(p)
   reactor.listenSSL(int(PORT), factory, myContextFactory)
   reactor.run()

-- 
Andrea Di Mario
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: stackoverflow and c.l.py (was: GIL switch interval)

2011-09-14 Thread Roy Smith
In article ,
 Duncan Booth  wrote:

> If you want an answer to how to get a specific bit of code to work then 
> Stackoverflow is better if only because people can see who has already 
> answered so don't need to waste time re-answering every trivial little 
> question about syntax.

Any halfway decent newsreader application will follow threading and put 
all the responses to a given question in one place.  Of course, this is 
a relatively new feature.  If your newsreader is any older than about 
the mid 1980's, it may not be able to do this.

In article ,
 Stefan Behnel  wrote:

> I wonder why people ask this kind of question on stackoverflow, and then 
> come here asking people to go over there, read the question, and 
> (potentially) provide an answer.

If you ask here you will probably get the correct answer to your 
question (along with some deep dives into related topics, which are 
often more valuable than the original answer).  If you ask on SO, you 
may also get the correct answer, but in addition you will earn SO karma 
points.  Maybe even some neat badge.  I guess it all depends on what 
your goal is.

Obligatory GIL comment -- I wrote some code the other day that used 4 
threads to perform 4 I/O bound operations (fetching 4 jpegs in parallel 
over http).  I figured the fact that they were I/O bound would avoid any 
GIL problems.  I was shocked and dismayed, however, to find that the 4 
operations all got serialized.  I guess I really didn't understand how 
the GIL worked after all.

So, I rewrote it to use the multiprocessing module.  Egads, still 
serialized!  To make a long story short, it turns out we were using some 
crappy consumer-grade Linksys box as our DNS server, and *it* was single 
threaded.  My 4 threads were blocking on name resolution!

We moved to using a real nameserver, and I converted the code back to 
using threading.  Works like a charm now.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Replace pip installed package with latest git version?

2011-09-14 Thread Alec Taylor
--editable=git+https://github.com/jedie/python-creole.git is not the right forma
t; it must have #egg=Package

On Wed, Sep 14, 2011 at 10:54 PM, One Murithi  wrote:
> pip install -e 
> On Wed, Sep 14, 2011 at 11:44 AM, Alec Taylor 
> wrote:
>>
>> Good evening,
>>
>> I've installed a version of python-creole from pip. How do I upgrade
>> it to the latest git version?
>>
>> (Windows 7 x64 SP1)
>>
>> Thanks for all suggestions,
>>
>> Alec Taylor
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImportError: cannot import name dns

2011-09-14 Thread Jack Bates
> It is a circular dependency. Dns will try to import udp which will in turn 
> import dns (again) in an endless cycle; instead an ImportError is raised.
>
> Circular dependency is a Bad Thing.

According to this documentation:

http://docs.python.org/reference/simple_stmts.html#grammar-token-import_stmt

http://effbot.org/zone/import-confusion.htm

 - I thought Python would do something like:

1. check for "dns" in sys.modules (initially not found)
2. create new empty module, add it to sys.modules as "dns"
3. execute dns.py in new module namespace (executes "from foo import udp")
4. check for "udp" in sys.modules (not found)
5. create new empty module, add it to sys.modules as "udp"
6. execute udp.py in new module namespace (executes "from foo import dns")
7. check for "dns" in sys.modules (found!)
8. done executing udp.py
9. done executing dns.py

So I'd expect attempting to access symbols from "dns" while executing
udp.py to fail, because dns.py isn't done executing at this point.
However I don't attempt to access any symbols from "dns" - so I don't
expect this ImportError

What is my mistake?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Replace pip installed package with latest git version?

2011-09-14 Thread Micky Hulse
Hello,

On Wed, Sep 14, 2011 at 1:44 AM, Alec Taylor  wrote:
> I've installed a version of python-creole from pip. How do I upgrade
> it to the latest git version?

Not sure if you got an answer yet, but this is how I would do it:

sudo pip install --upgrade
git+git://github.com/jedie/python-creole.git#egg=python-creole

The "sudo" may or may not be required.



Hths.

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


Re: Replace pip installed package with latest git version?

2011-09-14 Thread Micky Hulse
On Wed, Sep 14, 2011 at 9:58 AM, Micky Hulse  wrote:
> Not sure if you got an answer yet, but this is how I would do it:
> sudo pip install --upgrade
> git+git://github.com/jedie/python-creole.git#egg=python-creole

Having read your message more closely, it sounds like you did not
install the package originally form github? If that's the case, I
don't think using --upgrade will be of any help. Sorry 'bout that.

I suppose you would have to uninstall the original PIP version:

sudo pip uninstall egg-name.egg (or just the package name)

... and then:

sudo pip install -e
git+git://github.com/jedie/python-creole.git#egg=python-creole

Although, I am not sure if that is the best way to do it.

Crawling back into my hole now. :)

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


Re: Replace pip installed package with latest git version?

2011-09-14 Thread Alec Taylor
Thanks, uninstalling first worked.

:D

On Thu, Sep 15, 2011 at 3:06 AM, Micky Hulse  wrote:
> On Wed, Sep 14, 2011 at 9:58 AM, Micky Hulse  
> wrote:
>> Not sure if you got an answer yet, but this is how I would do it:
>> sudo pip install --upgrade
>> git+git://github.com/jedie/python-creole.git#egg=python-creole
>
> Having read your message more closely, it sounds like you did not
> install the package originally form github? If that's the case, I
> don't think using --upgrade will be of any help. Sorry 'bout that.
>
> I suppose you would have to uninstall the original PIP version:
>
> sudo pip uninstall egg-name.egg (or just the package name)
>
> ... and then:
>
> sudo pip install -e
> git+git://github.com/jedie/python-creole.git#egg=python-creole
>
> Although, I am not sure if that is the best way to do it.
>
> Crawling back into my hole now. :)
>
> Micky
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: PyGUI 2.5

2011-09-14 Thread Bill Janssen
Gregory Ewing  wrote:

> Terry Reedy wrote:
> 
> > Greg left out the most important to me:
> > "Now works with Python 3 on MacOSX and Windows!"
> 
> I'm not making too much of that at the moment, because it
> *doesn't* work on Linux yet, and I've no idea how long
> it will be before it does.
> 
> The issue is that there will apparently not be any
> Python 3 version of pygtk, on the grounds that gobject
> introspection can be used instead. Unfortunately,
> Gtk 3 and related libraries don't quite handle gobject
> introspection well enough to support PyGUI at the moment.

One possibility would be to develop a PyGUI branch on top of Tk, so that
it would work with Python anywhere.

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


Re: stackoverflow and c.l.py (was: GIL switch interval)

2011-09-14 Thread Duncan Booth
Roy Smith  wrote:

> In article ,
>  Duncan Booth  wrote:
> 
>> If you want an answer to how to get a specific bit of code to work then 
>> Stackoverflow is better if only because people can see who has already 
>> answered so don't need to waste time re-answering every trivial little 
>> question about syntax.
> 
> Any halfway decent newsreader application will follow threading and put 
> all the responses to a given question in one place.  Of course, this is 
> a relatively new feature.  If your newsreader is any older than about 
> the mid 1980's, it may not be able to do this.
> 
Sorry, I evidently didn't make myself clear. On Usenet it could be hours 
before your local server updates with other posts on the thread, on 
Stackoverflow the answers will update live as they are posted.

-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: stackoverflow and c.l.py

2011-09-14 Thread Thomas Jollans
On 14/09/11 21:00, Duncan Booth wrote:
> Roy Smith  wrote:
> 
>> In article ,
>>  Duncan Booth  wrote:
>>
>>> If you want an answer to how to get a specific bit of code to work then 
>>> Stackoverflow is better if only because people can see who has already 
>>> answered so don't need to waste time re-answering every trivial little 
>>> question about syntax.
>>
>> Any halfway decent newsreader application will follow threading and put 
>> all the responses to a given question in one place.  Of course, this is 
>> a relatively new feature.  If your newsreader is any older than about 
>> the mid 1980's, it may not be able to do this.
>>
> Sorry, I evidently didn't make myself clear. On Usenet it could be hours 
> before your local server updates with other posts on the thread, on 
> Stackoverflow the answers will update live as they are posted.

The mailing list python-list, however, doesn't have this problem.
(unless when people post from slow USENET servers of course...)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: unpyc3 - a python bytecode decompiler for Python3

2011-09-14 Thread Arnaud Delobelle
On 14 September 2011 11:03, Vincent Vande Vyvre
 wrote:
> Le 14/09/11 11:31, Arnaud Delobelle a écrit :
[...]
> Could you show me what you do to get this error?  Thank you,

> [vincent@myhost unpyc3]$ python
> Python 3.2.1 (default, Jul 11 2011, 12:37:47)
> [GCC 4.6.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
 from unpyc3 import decompile
 print (decompile("shredder.pyc"))
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "unpyc3.py", line 110, in decompile
>     return dec_module(obj)
>   File "unpyc3.py", line 99, in dec_module
>     code = Code(code_obj)
>   File "unpyc3.py", line 211, in __init__
>     for v in code_obj.co_cellvars + code_obj.co_freevars]
> AttributeError: 'NoneType' object has no attribute 'co_cellvars'
 print (decompile("unpyc3.pyc"))
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "unpyc3.py", line 110, in decompile
>     return dec_module(obj)
>   File "unpyc3.py", line 99, in dec_module
>     code = Code(code_obj)
>   File "unpyc3.py", line 211, in __init__
>     for v in code_obj.co_cellvars + code_obj.co_freevars]
> AttributeError: 'NoneType' object has no attribute 'co_cellvars'
 import os
 os.path.isfile("shredder.pyc")
> True
 os.path.isfile("unpyc3.pyc")
> True

>
> it seems the return of marshal.load(stream) is None

I think the reason may be that your unpyc3.pyc and shredder.pyc files
were compiled with a different version of python and the read_code
function returns None because the magic number in the .pyc file is
incorrect because of these two lines:

if magic != imp.get_magic():
return None

I have now changed this so that it loads the file anyway but prints a
warning.  I guess this may break badly though.

In Python 3.2, .pyc files are "hidden" in a __pycache__ directory.  So
the Python 3.2 specific unpyc3.pyc file for example is probably
located at .../unpyc3/__pycache__/unpyc3-cpython-32.pyc

The easiest way to find the path of the .pyc file if you know the path
of the .py file is probably as follows:

>>> import imp
>>> imp.cache_from_source("unpyc3.py")
'__pycache__/unpyc3.cpython-32.pyc'

Here's an example decompiling the dis module from the standard library:

>>> import dis
>>> dis.__file__
'/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/dis.py'
>>> imp.cache_from_source(dis.__file__)
'/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/__pycache__/dis.cpython-32.pyc'
>>> print(decompile(_))
__doc__ = 'Disassembler of Python byte code into mnemonics.'
import sys
import types
from opcode import *
from opcode import __all__ as _opcodes_all
__all__ = ['code_info', 'dis', 'disassemble', 'distb', 'disco',
'findlinestarts', 'findlabels', 'show_code'] + _opcodes_all
del _opcodes_all
_have_code = types.MethodType, types.FunctionType, types.CodeType, type
def _try_compile(source, name):
try:
c = compile(source, name, 'eval')
except SyntaxError:
c = compile(source, name, 'exec')
return c
[... many more lines ...]

I hope this will work for you,

-- 
Arnaud

PS: I've also added support for the IMPORT_STAR opcode which I had overlooked.
-- 
http://mail.python.org/mailman/listinfo/python-list


Reconciling os.path.getmtime vs ftp.sendcmd('MDTM filename')

2011-09-14 Thread Tim Johnson
I have written a class that uses ftplib.FTP as the parent.
I need to reconcile the modified time of a workstation file with
that same filename on a remote server.
Let's say we have a file called '400.shtml'. I get the mtime on
my workstation by
>> os.path.getmtime('400.shtml')
1311648420.0
And I use 
>> ftp.sendcmd('MDTM 400.shtml') ## for the remote server
'213 20110726004703'

My question is how to compare the two outputs?
Pointers to documentation and other resources are invited.

thanks
-- 
Tim 
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com
-- 
http://mail.python.org/mailman/listinfo/python-list


libxml2dom quesiton

2011-09-14 Thread bruce
Hi.

Test question. Trying to see how to insert a test node into an
existing dom tree. For the test, it has a TR/TD with a
td[@class="foo"] that has an associated TR..

Trying to figure out how out how to insert a "" around the
tr/td in question...

Curious as to how to accomplish this.

Thoughts/pointers.

thanks



--
sample code/html chunk follows:

import libxml2dom

  text is below

tt = libxml2dom.parseString(text, html=1)
t1path_=tt.xpath(t1path)

aa=tt.createElement("")
print len(t1path_)
for a in t1path_:

  tt.insertBefore(aa,None)
  print a.nodeName
  print a.toString()

sys.exit()



s3==


















trying to get::




















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


Accessing matplotlib-users discussion group?

2011-09-14 Thread John Ladasky
Hi folks,

Apologies if this is a bit off-topic, but there must be another
Pythoneer out there who can help me navigate my current problem.

I'm working with matplotlib, the Python graphing package.  I need to
ask some questions about it, and the place to ask those questions
would appear to be the matplotlib-users discussion group.  Matplotlib-
users appears to be hosted on sourceforge.net (and is not mirrored
anywhere else?), so I tried to sign up for an account (at
https://sourceforge.net/user/registration).

Yesterday, after filling out the registration page, Sourceforge
rejected my registration, without any notice that I observed.  Today,
I tried that registration again.  This time, on the upper right corner
of the rejection page, I saw the following message: "your registration
violated our anti-spam filter."

WTF?

I tried searching Sourceforge for information on what their anti-spam
filter is, and how my registration could possibly have violated it.  I
found nothing.

If anyone out there can tell me how 1) I can actually register with
Sourceforge, or 2) how I might post to matplotlib-users without
bothering with Sourceforge, I would be most grateful!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: stackoverflow and c.l.py

2011-09-14 Thread Westley Martínez
On Wed, Sep 14, 2011 at 10:47:15PM +1000, Chris Angelico wrote:
> On Wed, Sep 14, 2011 at 10:33 PM, memilanuk  wrote:
> > Not saying one is necessarily better than the other, but just subscribing to
> > the feed for the [python] tag on SO has a pretty good SNR...
> 
> The SNR here isn't bad either. Most of the spam gets filtered out, and
> even stuff like Ranting Rick posts can be of some amusement when it's
> a slow day...
> 
> ChrisA

And IMO the quality of [Python] code here is better than at SO.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: stackoverflow and c.l.py

2011-09-14 Thread Westley Martínez
On Wed, Sep 14, 2011 at 06:05:23AM -0700, memilanuk wrote:
> On 09/14/2011 05:47 AM, Chris Angelico wrote:
> >The SNR here isn't bad either. Most of the spam gets filtered out, and
> >even stuff like Ranting Rick posts can be of some amusement when it's
> >a slow day...
> 
> I subscribe to the list via Gmane, and if 'most of the spam' gets
> filtered out, I'd hate to see how much gets submitted as I still see
> 2-5 minimum blatant spam per day on here.
> 
> Rick & Xang Li are two examples of what you *don't* see (or at least
> I don't) @ SO
>

I don't understand the matter of spam and trolls.  You can just delete
it if you don't want it.  It's not like we're getting thousands per day.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: stackoverflow and c.l.py

2011-09-14 Thread Rhodri James

On Wed, 14 Sep 2011 14:05:23 +0100, memilanuk  wrote:

Rick & Xang Li are two examples of what you *don't* see (or at least I  
don't) @ SO


Then you haven't been looking hard enough ;-)

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: stackoverflow and c.l.py

2011-09-14 Thread Steven D'Aprano
memilanuk wrote:

> On 09/14/2011 05:47 AM, Chris Angelico wrote:
>> The SNR here isn't bad either. Most of the spam gets filtered out, and
>> even stuff like Ranting Rick posts can be of some amusement when it's
>> a slow day...
> 
> I subscribe to the list via Gmane, and if 'most of the spam' gets
> filtered out, I'd hate to see how much gets submitted as I still see 2-5
> minimum blatant spam per day on here.

2-5 spam posts is nothing. (Well, I know any spam is too much spam, but
still.) Since nearly all of it is obvious, it's easy to filter out of your
mail client, news client, or if all else fails, your attention. The hard
ones to ignore are the ones that look like they might be legitimate, but
fortunately most spammers are too lazy or stupid to bother with even the
most feeble disguise.

Either way, I don't consider half a dozen spam posts a day to be anything
more than a minor distraction.

Commercial spam is annoying, but otherwise harmless because it is so easy to
filter. What's really the problem is crackpots, trollers and griefers,
because there is a terrible temptation to engage them in debate: "someone
is wrong on the Internet!". If you want to see a news group gone bad, go to
something like sci.math. You can't move for the cranks "disproving"
Cantor's Diagonal Theorem and Special Relativity and proving that 10**603
is the One True Actual Infinity (I'm not making that last one up!).



-- 
Steven

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


Re: Reconciling os.path.getmtime vs ftp.sendcmd('MDTM filename')

2011-09-14 Thread Chris Rebert
On Wed, Sep 14, 2011 at 12:50 PM, Tim Johnson  wrote:
> I have written a class that uses ftplib.FTP as the parent.
> I need to reconcile the modified time of a workstation file with
> that same filename on a remote server.
> Let's say we have a file called '400.shtml'. I get the mtime on
> my workstation by
>>> os.path.getmtime('400.shtml')
> 1311648420.0

http://docs.python.org/library/os.path.html#os.path.getmtime
Your sample seems to be a typical Unix timestamp:
http://en.wikipedia.org/wiki/Unix_time

> And I use
>>> ftp.sendcmd('MDTM 400.shtml') ## for the remote server
> '213 20110726004703'

RFC 3659 - Extensions to FTP
Sec 3. File Modification Time (MDTM)
http://tools.ietf.org/html/rfc3659#section-3

(Note: Code 213 = File status response)

> My question is how to compare the two outputs?
> Pointers to documentation and other resources are invited.

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


A documents editor in Firefox with Python Sphinx tool

2011-09-14 Thread 文山 杜
Baow is a tool that makes it easy to organize your internet resources
and create intelligent and beautiful web pages within Firefox web
browser.

Highlights :

 * Tree based outline, help you organize internet resources and
documents.
 * Save or bookmark web images, files or pages.
 * Multi level project management.
 * Full text search.
 * Generate web pages by Python Sphinx tools,
http://sphinx.pocoo.org . Lots of quick menus help you write and
preview
Python Sphinx and reStructuredText markup documents.
 * Multi platform support, Windows, Linux, Mac, etc.

Home page:  https://addons.mozilla.org/en-US/firefox/addon/baow/
-- 
http://mail.python.org/mailman/listinfo/python-list


help regarding re.search

2011-09-14 Thread Sagar Neve
Hi,
I have a small program where I want to do just a small regex operation.
I want to see if value of a variable 'A' is present in an another variable
'B'.  The below code works fine but as soon as the variable 'A' has some
string including a dot it fails.

for example say:
B="dpkg.ipaz
The code works fine  when A="dpkg"
however the code does not work when A="dpkg.ipa"

if re.search(A,B):
  # do something.

Can somebody please help me ?
-- 
http://mail.python.org/mailman/listinfo/python-list


help regarding re.search

2011-09-14 Thread Sagar Neve
Hi,
I have a small program where I want to do just a small regex operation.
I want to see if value of a variable 'A' is present in an another variable
'B'.  The below code works fine but as soon as the variable 'A' has some
string including a dot it fails.

for example say:
B="dpkg.ipaz
The code works fine  when A="dpkg"
however the code does not work when A="dpkg.ipa"

if re.search(A,B):
  # do something.

Can somebody please help me ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help regarding re.search

2011-09-14 Thread Chris Rebert
On Wed, Sep 14, 2011 at 6:41 PM, Sagar Neve  wrote:
> Hi,
> I have a small program where I want to do just a small regex operation.
> I want to see if value of a variable 'A' is present in an another variable
> 'B'.  The below code works fine but as soon as the variable 'A' has some
> string including a dot it fails.

There's no need to use regexes at all! Just do:
if A in B:
# do something

> for example say:
> B="dpkg.ipaz
> The code works fine  when A="dpkg"
> however the code does not work when A="dpkg.ipa"

Right, because period is a regex metacharacter. To have it treated as
a literal character to match, escape it:
http://docs.python.org/library/re.html#re.escape

Cheers,
Chris
--
http://rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with Dos command by python script

2011-09-14 Thread Chris Rebert
On Wed, Sep 14, 2011 at 1:13 PM, Jonatas Emidio  wrote:
> Here i come!!
>
> I have the following problem...
> I need run by python script a string with some "DOS commands - Windows
> prompt"!!
> For exemple:
> print 'cd temp'
> print 'mkdir temp_app'
>
> How can i run this string in the python, but as a DOS interpreter?

Use the `subprocess` module, and pass shell=True.
http://docs.python.org/library/subprocess.html

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


Re: Reconciling os.path.getmtime vs ftp.sendcmd('MDTM filename')

2011-09-14 Thread Tim Johnson
* Chris Rebert  [110914 16:46]:
> On Wed, Sep 14, 2011 at 12:50 PM, Tim Johnson  wrote:
> > I have written a class that uses ftplib.FTP as the parent.
> > I need to reconcile the modified time of a workstation file with
> > that same filename on a remote server.
> > Let's say we have a file called '400.shtml'. I get the mtime on
> > my workstation by
> >>> os.path.getmtime('400.shtml')
> > 1311648420.0
> 
> http://docs.python.org/library/os.path.html#os.path.getmtime
> Your sample seems to be a typical Unix timestamp:
 Yup. Needs to be converted to a timedate stamp, methinks.
> http://en.wikipedia.org/wiki/Unix_time
  I'll look at that tomorrow. Late here.  
> > And I use
> >>> ftp.sendcmd('MDTM 400.shtml') ## for the remote server
> > '213 20110726004703'
 
> RFC 3659 - Extensions to FTP
> Sec 3. File Modification Time (MDTM)
> http://tools.ietf.org/html/rfc3659#section-3
> 
> (Note: Code 213 = File status response)
  and '213 20110726004703'[4:] should give me
  the string representation of the timedate stamp on the
  remote file.

  Thanks. I will look at the unix_time entry soon.

-- 
Tim 
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Offer Red Bull Hats superior in quality and price is favourable on http://www.mlbhatshop.com/

2011-09-14 Thread zhenzhen zhang
MLBHatShop with Original Red Bull Hats, New Era Hats, Monster Energy
Hats, Red Bull Beanies, DC Hats, Red Bull New Era Hats, Monster
Beanies Sales Promotion. Door to Door Free Shipping. http://www.mlbhatshop.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help regarding re.search

2011-09-14 Thread Sagar Neve
If A in B:
does nt seem to be working.
Am I missing something here.

-$agar
On Sep 15, 2011 7:25 AM, "Chris Rebert"  wrote:
> On Wed, Sep 14, 2011 at 6:41 PM, Sagar Neve  wrote:
>> Hi,
>> I have a small program where I want to do just a small regex operation.
>> I want to see if value of a variable 'A' is present in an another
variable
>> 'B'.  The below code works fine but as soon as the variable 'A' has some
>> string including a dot it fails.
>
> There's no need to use regexes at all! Just do:
> if A in B:
> # do something
>
>> for example say:
>> B="dpkg.ipaz
>> The code works fine  when A="dpkg"
>> however the code does not work when A="dpkg.ipa"
>
> Right, because period is a regex metacharacter. To have it treated as
> a literal character to match, escape it:
> http://docs.python.org/library/re.html#re.escape
>
> Cheers,
> Chris
> --
> http://rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help regarding re.search

2011-09-14 Thread Chris Rebert
On Wed, Sep 14, 2011 at 8:33 PM, Sagar Neve  wrote:
> If A in B:
> does nt seem to be working.
> Am I missing something here.

Please provide a snippet of the code in question, and be specific
about how it's not working.

Cheers,
Chris
--
http://rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: PyGUI 2.5

2011-09-14 Thread Greg Ewing

On 15/09/11 06:47, Bill Janssen wrote:


One possibility would be to develop a PyGUI branch on top of Tk, so that
it would work with Python anywhere.


Unfortunately, I doubt whether Tk would be up to the task of
supporting PyGUI efficiently. The philosophies of model-view
separation and allowing more than one view of a model are at
odds with the way Tk works.

Anyone who wants to have a go at it is welcome to try,
though.

--
Greg

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


Re: help regarding re.search

2011-09-14 Thread Sagar Neve
Here is the code


url="http://xy.yz.com/us/r1000/012/Purple/b1/c6/e2/mzm.dxkjsfbl..d2.dpkg.ipa
"

Man_Param="/us/r1000"
Opt_Param1="Purple"
Opt_Param2="dpkg.ipa"

if (Opt_Param2 in url):
print "hello."
else:
print "bye."

It  gives me:

./sample.py: line 9: syntax error near unexpected token `:'
./sample.py: line 9: `if (Opt_Param2 in url):'


Help.


On Thu, Sep 15, 2011 at 9:05 AM, Chris Rebert  wrote:

> On Wed, Sep 14, 2011 at 8:33 PM, Sagar Neve  wrote:
> > If A in B:
> > does nt seem to be working.
> > Am I missing something here.
>
> Please provide a snippet of the code in question, and be specific
> about how it's not working.
>
> Cheers,
> Chris
> --
> http://rebertia.com
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help regarding re.search

2011-09-14 Thread Chris Angelico
On Thu, Sep 15, 2011 at 2:41 PM, Sagar Neve  wrote:
> ./sample.py: line 9: syntax error near unexpected token `:'
> ./sample.py: line 9: `if (Opt_Param2 in url):    '
>

It worked for me in Python 3.2. What version of Python are you using?

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


Re: help regarding re.search

2011-09-14 Thread Sagar Neve
I figured it out with the sample program I gave you.   It was my mistake;
However, the same thing with same values is not working in my main program.

Here is what I am trying: The program traverses with correct values upto the
if condition we just discussed; but fails to quality that if condition;
instead it should qualify.


for key in dictionary:
m=re.search(key, url)
if m !=None:
values=dictionary[key]
for v in values:
v_array=v.split(',')
Man_Param=v_array[4]
Opt_Param1=v_array[5]
Opt_Param2=v_array[6]
Cat=v_array[1]
Man_Param=re.sub(r'"(?P.*?)"','\g', Man_Param)
Opt_Param1=re.sub(r'"(?P.*?)"','\g', Opt_Param1)
Opt_Param2=re.sub(r'"(?P.*?)"','\g', Opt_Param2)
Cat=re.sub(r'"(?P.*?)"','\g', Cat)
Cat=re.sub(r':','_', Cat)
Cat=re.sub(r' ','_', Cat)
print "hello..Man_Param=%s,Opt_Param1=%s,
Opt_Param2=%s\n" %(Man_Param,Opt_Param1,Opt_Param2)
#sys.exit(1)
if len(Opt_Param1):
if len(Opt_Param2):
#if (re.search(Man_Param,url) and
re.search(Opt_Param1,url) and re.search(Opt_Param2,url) ):
print url
   * if (Man_Param in url):#and (Opt_Param1 in url)
and (Opt_Param2 in url):*
print "all are found..\n"
sys.exit(1)
if((int(cl) < 5000 or int(rc) == 206) and
re.match(r"AS_D",Cat) ):
Cat= Cat + "_cont"
foutname = "output" + "/" + Cat +"." +
str(cnt)
fout =open(foutname, "a")
fout.write(line)
fout.close
else:
print "here\n";
sys.exit(1)




On Thu, Sep 15, 2011 at 10:19 AM, Chris Angelico  wrote:

> On Thu, Sep 15, 2011 at 2:41 PM, Sagar Neve  wrote:
> > ./sample.py: line 9: syntax error near unexpected token `:'
> > ./sample.py: line 9: `if (Opt_Param2 in url):'
> >
>
> It worked for me in Python 3.2. What version of Python are you using?
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help regarding re.search

2011-09-14 Thread Kushal Kumaran
On Thu, Sep 15, 2011 at 10:11 AM, Sagar Neve  wrote:
> Here is the code
>
>
> url="http://xy.yz.com/us/r1000/012/Purple/b1/c6/e2/mzm.dxkjsfbl..d2.dpkg.ipa";
>
> Man_Param="/us/r1000"
> Opt_Param1="Purple"
> Opt_Param2="dpkg.ipa"
>
> if (Opt_Param2 in url):
>     print "hello."
> else:
>     print "bye."
>
> It  gives me:
>
> ./sample.py: line 9: syntax error near unexpected token `:'
> ./sample.py: line 9: `if (Opt_Param2 in url):    '
>
>

That looks like a bash error message.  Syntax errors in python show up
with a stack trace.  Run your program using the python interpreter
like this:

python file.py
OR
python3 file.py

whatever is applicable in your environment.

>
>
> On Thu, Sep 15, 2011 at 9:05 AM, Chris Rebert  wrote:
>>
>> On Wed, Sep 14, 2011 at 8:33 PM, Sagar Neve  wrote:
>> > If A in B:
>> > does nt seem to be working.
>> > Am I missing something here.
>>
>> Please provide a snippet of the code in question, and be specific
>> about how it's not working.
>>

-- 
regards,
kushal
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help regarding re.search

2011-09-14 Thread Chris Angelico
On Thu, Sep 15, 2011 at 2:55 PM, Kushal Kumaran
 wrote:
> That looks like a bash error message.  Syntax errors in python show up
> with a stack trace.  Run your program using the python interpreter
> like this:
>
> python file.py
> OR
> python3 file.py
>
> whatever is applicable in your environment.
>

Or add a shebang to the top of your script.

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


Re: help regarding re.search

2011-09-14 Thread Sagar Neve
Yes. It is been resolved now for the sample program. however, as mentioned
in other post. It is not working in the main program


On Thu, Sep 15, 2011 at 10:25 AM, Kushal Kumaran <
kushal.kumaran+pyt...@gmail.com> wrote:

> On Thu, Sep 15, 2011 at 10:11 AM, Sagar Neve  wrote:
> > Here is the code
> >
> >
> > url="
> http://xy.yz.com/us/r1000/012/Purple/b1/c6/e2/mzm.dxkjsfbl..d2.dpkg.ipa";
> >
> > Man_Param="/us/r1000"
> > Opt_Param1="Purple"
> > Opt_Param2="dpkg.ipa"
> >
> > if (Opt_Param2 in url):
> > print "hello."
> > else:
> > print "bye."
> >
> > It  gives me:
> >
> > ./sample.py: line 9: syntax error near unexpected token `:'
> > ./sample.py: line 9: `if (Opt_Param2 in url):'
> >
> >
>
> That looks like a bash error message.  Syntax errors in python show up
> with a stack trace.  Run your program using the python interpreter
> like this:
>
> python file.py
> OR
> python3 file.py
>
> whatever is applicable in your environment.
>
> >
> >
> > On Thu, Sep 15, 2011 at 9:05 AM, Chris Rebert  wrote:
> >>
> >> On Wed, Sep 14, 2011 at 8:33 PM, Sagar Neve 
> wrote:
> >> > If A in B:
> >> > does nt seem to be working.
> >> > Am I missing something here.
> >>
> >> Please provide a snippet of the code in question, and be specific
> >> about how it's not working.
> >>
>
> --
> regards,
> kushal
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Cancel or timeout a long running regular expression

2011-09-14 Thread python
Is there a way to cancel or timeout a long running regular
expression?

I have a program that accepts regular expressions from users and
I'm concerned about how to handle worst case regular expressions
that seem to run forever. Ideally I'm looking for a way to
evaluate a regular expression and timeout after a specified time
period if the regular expression hasn't completed yet. Or a way
for a user to cancel a long running regular expression.

I was thinking there might be a technique I could use to evaluate
regular expressions in a thread or another process launched via
multiprocessing module and then kill the thread/process after a
specified timeout period. My concern about the multiprocessing
module technique is that launching a process for every regex
evaluation sounds pretty inefficient. And I don't think the
threading module supports the ability to kill threads from
outside a thread itself.

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


cause __init__ to return a different class?

2011-09-14 Thread Matthew Pounsett
I'm wondering if there's a way in python to cause __init__ to return a class 
other than the one initially specified.  My use case is that I'd like to have a 
superclass that's capable of generating an instance of a random subclass.  

I've tried both returning the subclass (as I would when overloading an 
operator) but I get the complaint that __init__ wants to return None instead of 
a type.

The other thing I tried was overwriting 'self' while inside __init__ but that 
doesn't seem to work either.

class Parent(object):
def __init__(self, foo):
if foo == True:
self = Child(foo)

class Child(Parent):
def __init__(self, foo):
pass

Is there a way to do this?  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with Dos command by python script

2011-09-14 Thread Gadget/Steve
On 14/09/2011 9:13 PM, Jonatas Emidio wrote:
> Here i come!!
>
> I have the following problem...
> I need run by python script a string with some "DOS commands - Windows
> prompt"!!
> For exemple:
> print 'cd temp'
> print 'mkdir temp_app'
>
> How can i run this string in the python, but as a DOS interpreter?
The direct answer to your question is to tell you to take a look at the
subprocess module documentation but if the above is what you would like
to do then take a look as os.chdir(), os.mkdir(), os.mkdirs() and then
do the above in python.


I would also suggest that you should raise this sort of question at
Gadget/Steve

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


Re: cause __init__ to return a different class?

2011-09-14 Thread Chris Rebert
On Wed, Sep 14, 2011 at 10:20 PM, Matthew Pounsett
 wrote:
> I'm wondering if there's a way in python to cause __init__ to return a class 
> other than the one initially specified.  My use case is that I'd like to have 
> a superclass that's capable of generating an instance of a random subclass.

> Is there a way to do this?

Override __new__() instead:
http://docs.python.org/reference/datamodel.html#object.__new__

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


Re: cause __init__ to return a different class?

2011-09-14 Thread Ryan Kelly
On 15/09/11 15:35, Chris Rebert wrote:
> On Wed, Sep 14, 2011 at 10:20 PM, Matthew Pounsett
>  wrote:
>> I'm wondering if there's a way in python to cause __init__ to return a class 
>> other than the one initially specified.  My use case is that I'd like to 
>> have a superclass that's capable of generating an instance of a random 
>> subclass.
> 
>> Is there a way to do this?
> 
> Override __new__() instead:
> http://docs.python.org/reference/datamodel.html#object.__new__


The above will do exactly what you want, but it's generally bad style
unless you have a very specific use-case.  Is there a particular reason
you need to "magically" return a subclass, rather than making this
explicit in the code?

To be friendlier to others reading your code, I would consider using a
classmethod to create an alternative constructor:


   class MyBaseClass(object):

@classmethod
def get_random_subclass(cls, *args, **kwds)
subcls = random.choice(cls.__subclasses__())
return subcls(*args, **kwds)


To me, this reads pretty cleanly and makes it obvious that something
unusual is going on:

obj = MyBaseClass.get_random_subclass()

While this hides the intention of the code and would require additional
documentation or comments:

obj = MyBaseClass()  # note: actually returns a subclass!



Just a thought :-)


  Cheers,

Ryan


-- 
Ryan Kelly
http://www.rfk.id.au  |  This message is digitally signed. Please visit
r...@rfk.id.au|  http://www.rfk.id.au/ramblings/gpg/ for details





signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cause __init__ to return a different class?

2011-09-14 Thread Steven D'Aprano
On Thu, 15 Sep 2011 03:20 pm Matthew Pounsett wrote:

> I'm wondering if there's a way in python to cause __init__ to return a
> class other than the one initially specified.  My use case is that I'd
> like to have a superclass that's capable of generating an instance of a
> random subclass.


You need to override the constructor, not the initializer. By the time
__init__ is called, the instance has already been created.


> I've tried both returning the subclass (as I would when overloading an
> operator) but I get the complaint that __init__ wants to return None
> instead of a type.
> 
> The other thing I tried was overwriting 'self' while inside __init__ but
> that doesn't seem to work either.

No, because self is just an ordinary local variable. Overwriting self just
changes the local variable, not the instance.

However, you can sometimes modify the instance's class. One sometimes useful
trick is something like this:


class Test(object):
def __init__(self):
if condition():
self.__class__ = AnotherClass

which will work, and is supported, so long as Test class and AnotherClass
are compatible. (If they're not compatible, you'll get an exception.)



-- 
Steven

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


YAMI4 1.4.0 released

2011-09-14 Thread Maciej Sobczak
I am pleased to announce that the 1.4.0 version of YAMI4 is available
for download:

http://www.inspirel.com/yami4

YAMI4 is a messaging solution for distributed systems that supports
Ada, C++, Java, .NET and Python.

An important improvement in the Python module (both for 2.x and 3.x
variants) is that the wrapping interface layer in a natively compiled
module was changed so that previously known bugs in the Python
standard library (ctypes) were bypassed and now the YAMI4 module
should work also on 64-bit
platforms.

Apart from this strictly Python-related improvement, this new release
bring a GUI management console that allows to browse and manage name
servers, message brokers and individual agents in a bigger distributed
system.

--
Maciej Sobczak * http://www.msobczak.com * http://www.inspirel.com
-- 
http://mail.python.org/mailman/listinfo/python-list