Re: 22, invalid agument error

2006-09-07 Thread Infinite Corridor

Justin Ezequiel wrote:
sockobj.bind(('',40007))

 tried on my N6600 with same error

 try using your phone's IP instead of the empty string ''

 tried sockobj.bind(('127.0.0.1',40007)) and did not get an error

I didn't get an error either, but the whole thing hangs up, and I am
forced to abort the program. This has happend quite a few times
already.
Did it work for you normally?

Thanks

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


Re: 22, invalid agument error

2006-09-07 Thread Infinite Corridor

kondal wrote:
 sockobj.bind(('',40007))
 
  tried on my N6600 with same error
 
  try using your phone's IP instead of the empty string ''
 
  tried sockobj.bind(('127.0.0.1',40007)) and did not get an error

 In general sockets layer bind with null host makes it pick the address
 from arp resolution and null in port makes it pick a random number as a
 source port. This is reason bind call is not required for client
 connections.

 I think Python for S60 has some problem in sockets layer for the bind
 function. Best is to remove the bind call in the client program as
 people will test with this senario in general.

Well the bind call is in the server program, not the client. I want to
run the server program on the cellphone.
Any idea how to fix it?

Thanks!

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


Re: sending emails using python

2006-09-07 Thread Sybren Stuvel
sridhar enlightened us with:
 iam having user account on an exchangeserver.
 with that can i send an email using python?

 if iam using the following code iam getting error


 fromAddress = '[EMAIL PROTECTED]'
 toAddress = '[EMAIL PROTECTED]'
 msg = Subject: Hello\n\nThis is the body of the message.
   

You need \r\n\r\n there. Line-ends in email messages should be DOS
line-ends.

 Traceback (most recent call last):
   File
 C:\sridhar\Beginning_Python\Beginning_Python\Chapter16\tryitout\InitialMailExample.py,
 line 5, in ?
 server = smtplib.SMTP(hstmsg002,25)
   File C:\Python24\lib\smtplib.py, line 244, in __init__
 (code, msg) = self.connect(host, port)
   File C:\Python24\lib\smtplib.py, line 307, in connect
 (code, msg) = self.getreply()
   File C:\Python24\lib\smtplib.py, line 351, in getreply
 raise SMTPServerDisconnected(Connection unexpectedly closed)
 SMTPServerDisconnected: Connection unexpectedly closed

Well that's useless. You could install a network sniffer
(http://www.ethereal.com/) and find out what's actually sent over the
network connection, and where things go wrong.

Sybren
-- 
Sybren Stüvel
Stüvel IT - http://www.stuvel.eu/
-- 
http://mail.python.org/mailman/listinfo/python-list


Question about subclassing and overriding methods

2006-09-07 Thread Frank Millman
Hi all

Assume a simple class -

class Test(object):
def __init__(self,x):
self.x = x
def getx(self):
print self.x

Test(1).getx()
Test(2).getx()
Test(3).getx()

As expected, the results are 1,2,3

Assume a slight variation, where given a particular condition I want a
particular method to behave differently. I know that I could subclass,
but for various reasons I preferred to do it this way -

class Test(object):
def __init__(self,x,y=False):
self.x = x
if y:
self.getx = self.getx2
def getx(self):
print self.x
def getx2(self):
print self.x * 2

Test(1).getx()
Test(2,True).getx()
Test(3).getx()

As expected, the results are 1,4,3

Now assume a subclass of the above class, where I want the method to
behave diferently again -

class Test2(Test):
def __init__(self,x,y=False):
Test.__init__(self,x,y)
def getx(self):
print self.x*3

Test2(1).getx()
Test2(2,True).getx()
Test2(3).getx()

Here I was hoping that the results would be 3,6,9 but they are 3,4,9.

I thought that getx in Test2 would override getx in Test, even if getx
in Test has been replaced by getx2, but clearly that is not happening.
Can someone explain why.

Thanks

Frank Millman

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


Re: python vs java

2006-09-07 Thread Bruno Desthuilliers
Jason wrote:
 Bruno Desthuilliers wrote:
 With a GUI ? If so, you probably want to check out wxPython or PyGTK
 (wxPython will also buy you MacOS X IIRC, and wil perhaps be easier to
 install on Windows).
 
 Just a warning: wxPython does operate slightly differently between Mac
 OS X, Linux, and Windows.  The differences are usually minor and easy
 to clean up in a cross-platform manner, but be aware that you need to
 test on all platforms that you're going to release on.

I don't think one could pretend writing a cross-platform application
without testing it on all targeted platforms.

(snip)
-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about subclassing and overriding methods

2006-09-07 Thread Frank Millman

Frank Millman wrote:
 Hi all

 Assume a simple class -

 class Test(object):
 def __init__(self,x):
 self.x = x
 def getx(self):
 print self.x

 Test(1).getx()
 Test(2).getx()
 Test(3).getx()

 As expected, the results are 1,2,3

 Assume a slight variation, where given a particular condition I want a
 particular method to behave differently. I know that I could subclass,
 but for various reasons I preferred to do it this way -

 class Test(object):
 def __init__(self,x,y=False):
 self.x = x
 if y:
 self.getx = self.getx2
 def getx(self):
 print self.x
 def getx2(self):
 print self.x * 2

 Test(1).getx()
 Test(2,True).getx()
 Test(3).getx()

 As expected, the results are 1,4,3

 Now assume a subclass of the above class, where I want the method to
 behave diferently again -

 class Test2(Test):
 def __init__(self,x,y=False):
 Test.__init__(self,x,y)
 def getx(self):
 print self.x*3

 Test2(1).getx()
 Test2(2,True).getx()
 Test2(3).getx()

 Here I was hoping that the results would be 3,6,9 but they are 3,4,9.


Ok, on reflection I more or less understand what is happening, and I
have found an ugly workaround -

class Test2(Test):
   def __init__(self,x,y=False):
getx = self.getx
Test.__init__(self,x,y)
self.getx = getx
def getx(self):
print self.x*3

Test2(1).getx()
Test2(2,True).getx()
Test2(3).getx()

Now I get 3,6,9 as intended.

I would still appreciate any comments, especially if someone can
suggest a better approach.

Thanks

Frank

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


Re: Question about subclassing and overriding methods

2006-09-07 Thread Bruno Desthuilliers
Frank Millman wrote:
 Hi all
 
 Assume a simple class -
 
 class Test(object):
 def __init__(self,x):
 self.x = x
 def getx(self):
 print self.x
 
 Test(1).getx()
 Test(2).getx()
 Test(3).getx()
 
 As expected, the results are 1,2,3
 
 Assume a slight variation, where given a particular condition I want a
 particular method to behave differently. I know that I could subclass,
 but for various reasons I preferred to do it this way -
 
 class Test(object):
 def __init__(self,x,y=False):
 self.x = x
 if y:
 self.getx = self.getx2
 def getx(self):
 print self.x
 def getx2(self):
 print self.x * 2
 
 Test(1).getx()
 Test(2,True).getx()
 Test(3).getx()
 
 As expected, the results are 1,4,3
 
 Now assume a subclass of the above class, where I want the method to
 behave diferently again -
 
 class Test2(Test):
 def __init__(self,x,y=False):
 Test.__init__(self,x,y)
 def getx(self):
 print self.x*3
 
 Test2(1).getx()
 Test2(2,True).getx()
 Test2(3).getx()
 
 Here I was hoping that the results would be 3,6,9

Why ???

 but they are 3,4,9.

Yes, obviously.

 I thought that getx in Test2 would override getx in Test,

It does.

 even if getx
 in Test has been replaced by getx2, 

This replacement happens at instance initialisation time - ie, after
the class object have been created. If you don't want this to happen,
either skip the call to Test.__init__ in Test2.__init__, or make this
call with False as second param, or redefine getx2 in Test2. Or go for a
saner design...

 but clearly that is not happening.
 Can someone explain why.

Test2(2,True) calls Test2.__init__() with a Test2 instance 'self' and
y=True. Test2.__init__() then calls Test.__init__() with the same
instance and y=True. So the branch:
 if y:
   self.getx = self.getx2
is executed on the Test2 instance.

I don't see what puzzle you here.

 Thanks
 
 Frank Millman
 


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: threading support in python

2006-09-07 Thread Antoon Pardon
On 2006-09-06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Paul Rubin wrote:
 [EMAIL PROTECTED] [EMAIL PROTECTED] writes:
  (1) I think is here to stay, if you're going to tell programmers that
  their destructors can't make program-visible changes (e.g. closing the
  database connection when a dbconn is destroyed), that's a _huge_ change
  from current practice that needs serious debate.

 We had that debate already (PEP 343).  Yes, there is some sloppy
 current practice by CPython users that relies on the GC to close the
 db conn.

 This point is unrelated to with or ref-counting.  Even the standard
 library will close file objects when they are GC'd.

This is not totally true. My experience is that if you use the
tarfile module any tarfile that was opened for appending or
writing risks being corrupted if it isn't closed explicedly.

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


Re: sending emails using python

2006-09-07 Thread Tim Williams
On 07/09/06, Sybren Stuvel [EMAIL PROTECTED] wrote:
 sridhar enlightened us with:
  iam having user account on an exchangeserver.
  with that can i send an email using python?
 
  if iam using the following code iam getting error
 
  Traceback (most recent call last):
File
  C:\sridhar\Beginning_Python\Beginning_Python\Chapter16\tryitout\InitialMailExample.py,
  line 5, in ?
  server = smtplib.SMTP(hstmsg002,25)
File C:\Python24\lib\smtplib.py, line 244, in __init__
  (code, msg) = self.connect(host, port)
File C:\Python24\lib\smtplib.py, line 307, in connect
  (code, msg) = self.getreply()
File C:\Python24\lib\smtplib.py, line 351, in getreply
  raise SMTPServerDisconnected(Connection unexpectedly closed)
  SMTPServerDisconnected: Connection unexpectedly closed

 Well that's useless. You could install a network sniffer
 (http://www.ethereal.com/) and find out what's actually sent over the
 network connection, and where things go wrong.

Have you verified that you are allowed to use SMTP on this server ?
Can you send email via it using outlook express or a similar POP3/IMAP
mail client?

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


Convert to big5 to unicode

2006-09-07 Thread GM
Dear all,

Could you all give me some guide on how to convert my big5 string to
unicode using python? I already knew that I might use cjkcodecs or
python 2.4 but I still don't have idea on what exactly I should do.
Please give me some sample code if you could. Thanks a lot

Regards,

Gary

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

Re: Question about subclassing and overriding methods

2006-09-07 Thread Frank Millman

Bruno Desthuilliers wrote:
 Frank Millman wrote:

 This replacement happens at instance initialisation time - ie, after
 the class object have been created. If you don't want this to happen,
 either skip the call to Test.__init__ in Test2.__init__, or make this
 call with False as second param, or redefine getx2 in Test2. Or go for a
 saner design...


Thanks, Bruno, you gave me the clue to a less ugly workaround.

In my particular case, when I do subclass Test, y is always True.
Therefore I can rewrite it like this -

class Test2(Test):
def __init__(self,x):
Test.__init__(self,x,True)
def getx2(self):
print x*3

As you suggested, I redefine getx2 instead of getx, and it works as I
want.

Slightly less insane, I hope ;-)

Frank

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


Re: string search and modification

2006-09-07 Thread Jim Britain
On 06 Sep 2006 13:23:43 -0700, Paul Rubin
http://[EMAIL PROTECTED] wrote:

Jim Britain [EMAIL PROTECTED] writes:
 I would like to match [123.123.123.123] (including the qualifying
 brackets), but be able to simply return the contents, without the
 brackets.


  p=r'\[((\d{1,3}\.){3}\d{1,3})\]'
  m = 'dsl-kk-dynamic-013.38.22.125.touchtelindia.net [125.22.38.13] (may 
  be'
  g=re.search(p,m)
  g.group(1)
'125.22.38.13'

g.group(1) matches the stuff in the first set of parens, which excludes
the square brackets.

Final integration:

def identifyHost(self):
for line in self.fileContents:
if re.search(throttling, line.lower()):
  p=r'\[((\d{1,3}\.){3}\d{1,3})\]'
  ip=re.search(p,line)
  if ip.group(1) in self.ignoreList:
continue
  if not ip.group(1) in self.banList:
 self.banList.append(ip.group(1))


Thanks for the help.
Jim
-- 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getting quick arp request

2006-09-07 Thread Ben Sizer
kondal wrote:
  Something is limiting the TCP/IP connections from my python program at
  10 maximum at the same time.
  I do not see this limit in my code.
  I did not bumped over the 4226 error.
 
  = Where does this limit come from.
  = How can I overcome it.

 You can just edit it by creating a new key in the registry.

 HKEY_LOCAL_MACHINE - SYSTEM - CurrentControlSet - Services -Tcpip -
 Parameters

 Create a DWORD key named TcpNumConnections and set the value to
 00fe or 16777214.

That's the maximum number of connections, which is unlikely to be what
he's running up against. It's more likely the original poster is
hitting the max number of half-open connections, which is limited to 10
(exactly the figure he's seeing). Perhaps the 4226 event just isn't
appearing for some reason. I've had that myself sometimes.

There is an unofficial OS-level patch for this behaviour at this
address: http://www.lvllord.de/?lang=enurl=downloads

No idea if it works or if it's safe, but many people use it.

-- 
Ben Sizer

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


de/-encoding problem?

2006-09-07 Thread seppl43
Hello,

I'm writing a SOAP-client using SOAPpy for a JAVA-Application (JIRA).
When I try to send attachments, the incoming files are not decoded
correctly. They have about 1.5% more bytes.

What I'm doing is this:

file_obj = file(path to file,'rb')
cont = file_obj.read()
cont64 = base64.encodestring(cont)
chararray1 = array.array('c')
chararray1.fromstring(cont64)
file_obj.close()

# using the method of jira's SOAP-interface
add =
jira_soap.addAttachmentsToIssue(auth,issue_id,[filename],[chararray1])


This is the WSDL-description of that method:

wsdl:message name=addAttachmentsToIssueRequest
  wsdl:part name=in0 type=xsd:string/
  wsdl:part name=in1 type=xsd:string/
  wsdl:part name=in2 type=impl:ArrayOf_xsd_string/
  wsdl:part name=in3 type=impl:ArrayOf_xsd_base64Binary/
   /wsdl:message

Does anybody know, why the files are not de-/encoded correctly?
Thanks for help.

Seppl

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


Re: sending emails using python

2006-09-07 Thread Steve Holden
Sybren Stuvel wrote:
 sridhar enlightened us with:
 
iam having user account on an exchangeserver.
with that can i send an email using python?

if iam using the following code iam getting error


fromAddress = '[EMAIL PROTECTED]'
toAddress = '[EMAIL PROTECTED]'
msg = Subject: Hello\n\nThis is the body of the message.
 

 
 You need \r\n\r\n there. Line-ends in email messages should be DOS
 line-ends.
 
This is untrue for the Python smtplib, though correct according to the 
RFCs. The SMTP.data() method uses a locally-declared function called 
quotedata() to ensure the correct line endings, so using \n will 
result in the same message as using \r\n.
 
Traceback (most recent call last):
  File
C:\sridhar\Beginning_Python\Beginning_Python\Chapter16\tryitout\InitialMailExample.py,
line 5, in ?
server = smtplib.SMTP(hstmsg002,25)
  File C:\Python24\lib\smtplib.py, line 244, in __init__
(code, msg) = self.connect(host, port)
  File C:\Python24\lib\smtplib.py, line 307, in connect
(code, msg) = self.getreply()
  File C:\Python24\lib\smtplib.py, line 351, in getreply
raise SMTPServerDisconnected(Connection unexpectedly closed)
SMTPServerDisconnected: Connection unexpectedly closed
 
 
 Well that's useless. You could install a network sniffer
 (http://www.ethereal.com/) and find out what's actually sent over the
 network connection, and where things go wrong.
 
Useless it might be, but it's a lot more clueful than some questions we 
see, so it seems a little dismissive just to say it's useless - the OP 
has provided the traceback, which is so often missing in questions from 
newbies, and has correctly localized the error to a small chunk of code.

True, the error message isn't particularly helpful in these 
circumstances, but it probably represents an accurate description (from 
the client's point of view) about what's happening, in which case an 
Ethereal trace will provide little more data than the traceback. I 
suppose it'll tell you whether the server is sending RST or FIN to 
terminate the connection, but it won't give much insight into why.

We might hazard a guess that the connection is being closed because 
there is no SMTP server running on the named host, or (less likely) it 
requires authentication. Unfortunately when I try to connect to a 
non-existent SMTP server on an existent host I see

socket.error: (113, 'Software caused connection abort')

under both 2.4.3 and 2.5b2. Alas I don't have ready access to a server 
that requires authentication (my servers authenticate senders by POP 
access IIRC). So I can't reproduce this error.

Perhaps the SMTP server is strapped down to accepting connections from 
specific IP addresses by some firewall? It would probably be a good idea 
to have a chat with the server's administrator to see if they can 
suggest what might be going wrong.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: No ValueError for large exponents?

2006-09-07 Thread Duncan Booth
Robin Becker [EMAIL PROTECTED] wrote:

 enigmadude wrote:
 As many have heard, IronPython 1.0 was released. When I was looking
 through the listed differences between CPython and IronPython, the
 document mentioned that using large exponents such as 10 **
 735293857239475 will cause CPython to hang, whereas IronPython will
 raise a ValueError. Trying this on my own machine, it did indeed seem
 to cause CPython to hang. In cases such as this, should this be
 considered a bug in the CPython implementation that needs to be fixed?
 Or is there a reason for this, such as consideration of future changes
 and language definition vs language implementation, etc.?
 
 I suspect the hang may be python actually trying to work out the
 1 followed by 735293857239475 zeroes. Perhaps IronPython has a forward 
 looking algorithm that knows when to give up early.

My guess would be that IronPython preallocates sufficient memory for the 
resulting string, so will fail immediately, and CPython must be trying to 
grow the string dynamically.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No ValueError for large exponents?

2006-09-07 Thread Georg Brandl
enigmadude wrote:
 As many have heard, IronPython 1.0 was released. When I was looking
 through the listed differences between CPython and IronPython, the
 document mentioned that using large exponents such as 10 **
 735293857239475 will cause CPython to hang, whereas IronPython will
 raise a ValueError.

What message does that value error have?

If it's a memory issue, the operation should raise MemoryError (at
least in CPython).

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


Re: IronPython 1.0 released today!

2006-09-07 Thread Super Spinner
Congrats on reaching 1.0, Jim.

BTW, here's a John Udell screencast of Jim demo'ing IronPython.  Among
other things, it shows IronPython integrating with Visual Studio,
Monad, C#, VB.NET, and WPF.  It's a great video.
http://weblog.infoworld.com/udell/2006/08/30.html#a1515

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


Re: 22, invalid agument error

2006-09-07 Thread Justin Ezequiel
Infinite Corridor wrote:
 Justin Ezequiel wrote:
 
  tried sockobj.bind(('127.0.0.1',40007)) and did not get an error

 I didn't get an error either, but the whole thing hangs up, and I am
 forced to abort the program. This has happend quite a few times
 already.
 Did it work for you normally?


am unable to test as my current PCs do not have bluetooth (yet)
sorry

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


Re: Convert to big5 to unicode

2006-09-07 Thread xiejw
Install the codecs. In Debain, you can do :
 apt-get install python-cjkcodecs

Then, it is easy to encode ( I use 'gb2312' ) :

 str = '我们'
 u = unicode(str,'gb2312')

The convertion is done and you can get the string of UTF-8:
 str_utf8 = u.encode(utf-8)

You can get the original string:
 str_gb = u.encode(gb2312)


GM 写道:

 Dear all,

 Could you all give me some guide on how to convert my big5 string to
 unicode using python? I already knew that I might use cjkcodecs or
 python 2.4 but I still don't have idea on what exactly I should do.
 Please give me some sample code if you could. Thanks a lot
 
 Regards,
 
 Gary

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

Re: CONSTRUCT -

2006-09-07 Thread Georg Brandl
Steve Holden wrote:

 I am not a (python) domain expert.
 
 Thus I am asking here for available standard-solutions, before I
 implement an own solution.
 
 There is no standard solution for the problem you mention.

Because it's not a problem for most people ;)

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


Accessing Add/Remove Programs Details

2006-09-07 Thread Phoe6
Hi all,

I have to uninstall an application and  I don't find the uninstaller,
the option available to me is to access Add/Remove Programs, select the
application and remove from there.

I am trying to automate this task using Python:
1) Get the Application Name
2) Access the Add/Remove Program details and check if the application
is present.
3) If present, then uninstall it.

I want to understand the Python Win32 modules/calls that would helpful
to me in this direction. Are there any?  I don't want to do it as GUI
automation using dogtail, as I want to maintain a homogeneous execution
environment of only CLI.

Please share your ideas as how I can go about with accessing Add/Remove
(appwiz.cpl) details in windows using python + python win 32
extensions.

Thanks.
Senthil

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


Re: [ANN] IronPython 1.0 released today!

2006-09-07 Thread Chris
Diez B. Roggisch wrote:
 Chris wrote:
 
 Jim Hugunin wrote:
 I'm extremely happy to announce that we have released IronPython 1.0
 today!
  http://www.codeplex.com/IronPython
 snip

 I'm no code guru but it sounds interesting. So can I import numpy,
 scipy, matplotlib, wxpython etc like I do now with CPython and expect,
 short of a few tweaks, that my code will work?
snip
 No, you can't. I'm not sure if there are any bridging attempts being made,
 but in this respect IronPython is the same as Jython - a completely
 different runtime which executes its own byte-code. 
 
 Diez
Disappointing because, apart from python itself, what I find amazing is 
the wealth of additional packages that, by association, come to be 
considered part of python. Anyway thanks for saving me from some 
fruitless explorations.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Accessing Add/Remove Programs Details

2006-09-07 Thread Tim Golden
[Phoe6]

| I have to uninstall an application and  I don't find the uninstaller,
| the option available to me is to access Add/Remove Programs, 
| select the
| application and remove from there.
| 
| I am trying to automate this task using Python:
| 1) Get the Application Name
| 2) Access the Add/Remove Program details and check if the application
| is present.
| 3) If present, then uninstall it.
| 
| I want to understand the Python Win32 modules/calls that would helpful
| to me in this direction. Are there any?  I don't want to do it as GUI
| automation using dogtail, as I want to maintain a homogeneous 
| execution
| environment of only CLI.

Not actually tried it myself, but WMI looks like a useful
candidate here:

Bit of an example (the other way round) here:
http://tgolden.sc.sabren.com/python/wmi_cookbook.html#install-a-product

and perhaps you need something like 
this (altho' obviously more sophisticated):
code
import wmi

appname = Python 2.4.3
c = wmi.WMI ()
for product in c.Win32_Product (Caption=appname):
  print product.Caption
  # product.Uninstall ()

/code

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Freetype 2 Bindings

2006-09-07 Thread Leon
Hi,

Has anybody experimented with this python binding for Freetype2
(http://www.satzbau-gmbh.de/staff/abel/ft2/index.html) ? I'm hoping to
learn more about using text in pyOpenGl by creating textures from
glyphs generated by Freetype2. I downloaded and installed the bindings,
and with the download came an example (render.py) which renders a
string to an image, when I run the example without modifying the code,
only the first character of a string I feed it appears in the image and
blank spaces are present for the rest of the characters (you'll see
what I mean if you run render.py). I'm pretty sure it's the part of the
code in the example that defines the kerning, but I'm new to Freetype2,
and I tried following the documentation and changing the code, but I
can't pinpoint the exact problem. If you have experience programming
with Freetype2 and can figure out this out, please help, I'll be
forever grateful.

Thanks,
Leon

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


help with unicode email parse

2006-09-07 Thread neoedmund
i want to get the subject from email and construct a filename with the
subject.
but tried a lot, always got error like this:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 4:
ordinal not in range(128)


msg = email.message_from_string( text )
title = decode_header( msg[Subject] )
title= title[0][0]
#title=title.encode(utf8)
print title
fn = +path+/+stamp+-+title+.mail


the variable text  come from sth like this:
( header, msg, octets ) = a.retr( i )
text= list2txt( msg )
def list2txt( l ):
return reduce( lambda x, y:x+\r\n+y, l )

anyone can help me out? thanks.

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


Re: getting quick arp request

2006-09-07 Thread Steve Holden
Ben Sizer wrote:
 kondal wrote:
 
Something is limiting the TCP/IP connections from my python program at
10 maximum at the same time.
I do not see this limit in my code.
I did not bumped over the 4226 error.

= Where does this limit come from.
= How can I overcome it.

You can just edit it by creating a new key in the registry.

HKEY_LOCAL_MACHINE - SYSTEM - CurrentControlSet - Services -Tcpip -
Parameters

Create a DWORD key named TcpNumConnections and set the value to
00fe or 16777214.
 
 
 That's the maximum number of connections, which is unlikely to be what
 he's running up against. It's more likely the original poster is
 hitting the max number of half-open connections, which is limited to 10
 (exactly the figure he's seeing). Perhaps the 4226 event just isn't
 appearing for some reason. I've had that myself sometimes.
 
 There is an unofficial OS-level patch for this behaviour at this
 address: http://www.lvllord.de/?lang=enurl=downloads
 
 No idea if it works or if it's safe, but many people use it.
 
Is it relevant to point out that the ARP protocol is a connectionless 
network-layer protocol, so it would seem a little bogus of the Microsoft 
stack to apply TCP control parameters to it.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: sending emails using python

2006-09-07 Thread Max M
sridhar wrote:
 iam having user account on an exchangeserver.
 with that can i send an email using python?
 
 if iam using the following code iam getting error
 
 
 fromAddress = '[EMAIL PROTECTED]'
 toAddress = '[EMAIL PROTECTED]'
 msg = Subject: Hello\n\nThis is the body of the message.
 import smtplib
 server = smtplib.SMTP(hstmsg002,25)
 server.sendmail(fromAddress, toAddress, msg)


Do yourself a favor and use the email module to construct your messages 
with. Constructing messages by hand can lead you into so many traps. 
Especially if you are using international characters in you messages.


-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science

Phone:  +45 66 11 84 94
Mobile: +45 29 93 42 96
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help with unicode email parse

2006-09-07 Thread Diez B. Roggisch
neoedmund schrieb:
 i want to get the subject from email and construct a filename with the
 subject.
 but tried a lot, always got error like this:
 UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 4:
 ordinal not in range(128)
 
 
   msg = email.message_from_string( text )
   title = decode_header( msg[Subject] )
   title= title[0][0]
   #title=title.encode(utf8)
   print title
   fn = +path+/+stamp+-+title+.mail
 
 
 the variable text  come from sth like this:
 ( header, msg, octets ) = a.retr( i )
 text= list2txt( msg )
 def list2txt( l ):
   return reduce( lambda x, y:x+\r\n+y, l )
 
 anyone can help me out? thanks.

Where does the exception occur?

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


Re: getting quick arp request

2006-09-07 Thread Richard Brodie

Steve Holden [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

 Is it relevant to point out that the ARP protocol is a connectionless 
 network-layer 
 protocol.

Not really, since the program uses normal TCP socket connections.
The feature is working exactly as designed - to slow down TCP scans.
The arp requests are just a consequence of the TCP scan. 


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


Re: sending emails using python

2006-09-07 Thread Steve Holden
Max M wrote:
 sridhar wrote:
 
iam having user account on an exchangeserver.
with that can i send an email using python?

if iam using the following code iam getting error


fromAddress = '[EMAIL PROTECTED]'
toAddress = '[EMAIL PROTECTED]'
msg = Subject: Hello\n\nThis is the body of the message.
import smtplib
server = smtplib.SMTP(hstmsg002,25)
server.sendmail(fromAddress, toAddress, msg)
 
 
 
 Do yourself a favor and use the email module to construct your messages 
 with. Constructing messages by hand can lead you into so many traps. 
 Especially if you are using international characters in you messages.
 
 
Good advice. However, since the error is occurring in the SMTP() call a 
malformed message is clearly not the cause of this particular problem.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: getting quick arp request

2006-09-07 Thread Steve Holden
Richard Brodie wrote:
 Steve Holden [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
 
 
Is it relevant to point out that the ARP protocol is a connectionless 
network-layer 
protocol.
 
 
 Not really, since the program uses normal TCP socket connections.
 The feature is working exactly as designed - to slow down TCP scans.
 The arp requests are just a consequence of the TCP scan. 
 
 
Ah. Right. Now you mention that (and force me to read the code :-) I see 
it's a horizontal scan of the FTP service port, and the subject line is 
really a misnomer. Thanks.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Convert to big5 to unicode

2006-09-07 Thread John Machin
xiejw topposted:
 Install the codecs. In Debain, you can do :
  apt-get install python-cjkcodecs

With Windows  2.4, no extra installation step is required.

| Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
on win32
|  bc = '\xb1i'
|  unicode(bc, 'big5')
| u'\u5f35'
| 

HTH,
John


 Then, it is easy to encode ( I use 'gb2312' ) :

  str = '我们'
  u = unicode(str,'gb2312')

 The convertion is done and you can get the string of UTF-8:
  str_utf8 = u.encode(utf-8)

 You can get the original string:
  str_gb = u.encode(gb2312)


 GM 写道:

  Dear all,
 
  Could you all give me some guide on how to convert my big5 string to
  unicode using python? I already knew that I might use cjkcodecs or
  python 2.4 but I still don't have idea on what exactly I should do.
  Please give me some sample code if you could. Thanks a lot
  
  Regards,
  
  Gary

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

Re: sending emails using python

2006-09-07 Thread Sybren Stuvel
Steve Holden enlightened us with:
 This is untrue for the Python smtplib, though correct according to
 the RFCs. The SMTP.data() method uses a locally-declared function
 called quotedata() to ensure the correct line endings, so using \n
 will result in the same message as using \r\n.

Ah, wonderful.

 Useless it might be, but it's a lot more clueful than some questions
 we see, so it seems a little dismissive just to say it's useless -
 the OP has provided the traceback, which is so often missing in
 questions from newbies, and has correctly localized the error to a
 small chunk of code.

I agree with you. My remark might indeed have sounded harsher than
intended. It referred to the traceback itself, not the posting of the
traceback. That was rather useful.

 Ethereal trace will provide little more data than the traceback.

I don't know until I see it. Perhaps the socket is closed in response
to something the client sends. That can be seen in the Ethereal trace.

 I suppose it'll tell you whether the server is sending RST or FIN to
 terminate the connection, but it won't give much insight into why.

A quick peek in the SMTP logfiles should tell you that.

 Perhaps the SMTP server is strapped down to accepting connections from 
 specific IP addresses by some firewall?

In that case I'd expect the SMTP server to simply ignore the
connection attempt and cause a timeout in the connecting phase. I
wouldn't expect a connection to be created and then closed again,
which is what I read in the posted traceback.

 It would probably be a good idea to have a chat with the server's
 administrator to see if they can suggest what might be going wrong.

Good idea indeed. Another idea would be to use something like netcat
or telnet to connect to the port and see what happens if you manually
type an SMTP connection.

Sybren
-- 
Sybren Stüvel
Stüvel IT - http://www.stuvel.eu/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sending emails using python

2006-09-07 Thread Sybren Stuvel
Tim Williams enlightened us with:
 Can you send email via it using outlook express or a similar
 POP3/IMAP mail client?

Wouldn't you use a SMTP client to send email?

Sybren
-- 
Sybren Stüvel
Stüvel IT - http://www.stuvel.eu/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help with unicode email parse

2006-09-07 Thread John Machin
neoedmund wrote:
 i want to get the subject from email and construct a filename with the
 subject.
 but tried a lot, always got error like this:
 UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 4:
 ordinal not in range(128)


   msg = email.message_from_string( text )
   title = decode_header( msg[Subject] )
   title= title[0][0]
   #title=title.encode(utf8)

Why is that commented out?

   print title
   fn = +path+/+stamp+-+title+.mail


 the variable text  come from sth like this:
 ( header, msg, octets ) = a.retr( i )
 text= list2txt( msg )
 def list2txt( l ):
   return reduce( lambda x, y:x+\r\n+y, l )

 anyone can help me out? thanks.

Not without a functional crystal ball.

You could help yourself considerably by (1) working out which line of
code the problem occurs in [the traceback will tell you that] (2)
working out which string is being decoded into Unicode, and has '\xe9'
as its 5th byte. Either that string needs to be decoded using something
like 'latin1' [should be specified in the message headers] rather than
the default 'ascii', or the code has a deeper problem ...

If you can't work it out for yourself, show us the exact code that ran,
together with the traceback. If (for example) title is the problem,
insert code like:
print 'title=', repr(title)
and include that in your next post as well.

HTH,
John

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


Re: string search and modification

2006-09-07 Thread John Machin

Jim Britain wrote:


 Final integration:

 def identifyHost(self):
 for line in self.fileContents:
 if re.search(throttling, line.lower()):
   p=r'\[((\d{1,3}\.){3}\d{1,3})\]'
   ip=re.search(p,line)

A prudent pessimist might test for the complete absence of an IP
address:
if not ip:
print Huh? # or whatever

   if ip.group(1) in self.ignoreList:
 continue
   if not ip.group(1) in self.banList:
  self.banList.append(ip.group(1))
 


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


Re: sending emails using python

2006-09-07 Thread Brendon Towle

On Sep 7, 2006, at 3:50 AM, sridhar  
[EMAIL PROTECTED]wrote:


 iam having user account on an exchangeserver.
 with that can i send an email using python?

 if iam using the following code iam getting error


 fromAddress = '[EMAIL PROTECTED]'
 toAddress = '[EMAIL PROTECTED]'
 msg = Subject: Hello\n\nThis is the body of the message.
 import smtplib
 server = smtplib.SMTP(hstmsg002,25)
 server.sendmail(fromAddress, toAddress, msg)

 error:

 Traceback (most recent call last):
   File
 C:\sridhar\Beginning_Python\Beginning_Python\Chapter16\tryitout 
 \InitialMailExample.py,
 line 5, in ?
 server = smtplib.SMTP(hstmsg002,25)
   File C:\Python24\lib\smtplib.py, line 244, in __init__
 (code, msg) = self.connect(host, port)
   File C:\Python24\lib\smtplib.py, line 307, in connect
 (code, msg) = self.getreply()
   File C:\Python24\lib\smtplib.py, line 351, in getreply
 raise SMTPServerDisconnected(Connection unexpectedly closed)
 SMTPServerDisconnected: Connection unexpectedly closed


I saw a similar error when I was not following the server's  
authentication protocol -- either failing to authenticate when it  
wanted it, or authenticating when it didn't want it. Here's the code  
I use -- tested on both an Exchange server and on Comcast's SMTP  
servers. It assumes some globals (in all caps) which you need to set  
first.

def emailGivenString(host=SMTP_HOST, fromAddr=FROM_ADDR,
  toAddr=TO_ADDR, subject='', body='', auth=False):
 server = smtplib.SMTP(host)
 if auth:
 server.login('username', 'password')
 outMessage = 'From: %s\rTo: %s\rSubject: %s\r%s' %
  (FROM_HEADER, TO_HEADER, subject, body)
 server.sendmail(fromAddr, toAddr, outMessage)

If this doesn't work, I second the previous suggestion of talking to  
the server admin.

B.

--
Brendon Towle, Ph.D.   [EMAIL PROTECTED]  +1-412-362-1530
“Debugging is twice as hard as writing the code in the first place.  
Therefore,
if you write the code as cleverly as possible, you are, by  
definition, not
smart enough to debug it.” – Brian W. Kernighan


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


Re: sending emails using python

2006-09-07 Thread Tim Williams
On 07/09/06, Sybren Stuvel [EMAIL PROTECTED] wrote:
 Tim Williams enlightened us with:
  Can you send email via it using outlook express or a similar
  POP3/IMAP mail client?

 Wouldn't you use a SMTP client to send email?

Outlook Express *is* a mail client that uses SMTP as the outbound protocol.

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


Re: IronPython on Mono howto

2006-09-07 Thread Nick Craig-Wood
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
  Okay, here we go:
[snip]

Thanks for those good instructions - they worked well!

I tried running a test program under mono/linux.

I found I needed to add

  import sys
  sys.path.append(/usr/lib/python2.4)

As per the FAQ to the code.  Setting this in an environment var would
be nice but I didn't find one.

The code then ran fine.  (Its a test suite for my sudoku solver.)

  $ mono ipy.exe ~/Python/sudoku.py -t
  ...
  --
  Ran 11 tests in 5.533s

Compared to

  $ python2.4 ~/Python/sudoku.py -t
  ...
  --
  Ran 11 tests in 1.637s

It seems to take about a second to start IronPython vs ~15 ms for
Python2.4, eg

  $ time mono ipy.exe -c pass

  real0m1.034s
  user0m1.000s
  sys 0m0.036s

  $ time python2.4 -c pass

  real0m0.015s
  user0m0.008s
  sys 0m0.007s

Over all I'm very impressed - it is great to have a new implemention
of Python.  I'm not sure mono is showing it off to its full extent
though!

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


Re: getting quick arp request

2006-09-07 Thread seb
Thank you all for the reply,

**
More tests :
***

1) I tried to input the D-word with the parameters and I did not see
anychanged (checked with process explorer. The limit of the
simultaneous connexion is always 10.

2)
I have applied the patch from
http://www.lvllord.de/?lang=enurl=downloads .
I could see that this improved the simultaneous sockets up to roughly
50.
This is enough for me.

3)
Since during the scan the first protocol used (and packet capteures) is
using the arp protocol, the subject may be indeed a misnomer.


Question :
*
1)
I am not fully confident to apply the patch from
http://www.lvllord.de/?lang=enurl=downloads .on computers other than
mine.
Is there another solution ?

2)
Still without the above patch on windows, the software angry ip scan
for example managed to output a lot of more socket connection. How is
it possible ?

Regards.
Sebastien.

Steve Holden wrote:
 Richard Brodie wrote:
  Steve Holden [EMAIL PROTECTED] wrote in message
  news:[EMAIL PROTECTED]
 
 
 Is it relevant to point out that the ARP protocol is a connectionless 
 network-layer
 protocol.
 
 
  Not really, since the program uses normal TCP socket connections.
  The feature is working exactly as designed - to slow down TCP scans.
  The arp requests are just a consequence of the TCP scan.
 
 
 Ah. Right. Now you mention that (and force me to read the code :-) I see
 it's a horizontal scan of the FTP service port, and the subject line is
 really a misnomer. Thanks.

 regards
   Steve
 --
 Steve Holden   +44 150 684 7255  +1 800 494 3119
 Holden Web LLC/Ltd  http://www.holdenweb.com
 Skype: holdenweb   http://holdenweb.blogspot.com
 Recent Ramblings http://del.icio.us/steve.holden

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


Re: Where are the source files for the Python FAQs?

2006-09-07 Thread A.M. Kuchling
On Thu, 07 Sep 2006 04:43:38 GMT, 
Eriol [EMAIL PROTECTED] wrote:
 Dave Kuhlman wrote:
 
 Can someone tell me the location of the reST source files for the
 Python FAQs.  I have not been able to find them.
 
 https://svn.python.org/www/trunk/pydotorg/doc/faq/ 

Caution: I intend to switch to generating the FAQs from Fredrik
Lundh's wiki at pyfaq.infogami.com ; it's just a matter of when I find
the time to deploy the necessary scripts on python.org.  At that point
the master source for the FAQs would be available in XML format, not
reST.

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


Re: iso creation for python backup script

2006-09-07 Thread Neil Cerutti
On 2006-09-07, John Purser [EMAIL PROTECTED] wrote:
 Windows itself (2000+) comes with it's own backup solution that
 might even support burning to disk.  I haven't used MS in a
 year or so but it might be worth looking at.

That worked OK for me until the backup solution bundled with XP
turned out to be incompatible with the one bundled with 95. I had
to get a third-party software solution to access my old backups.

You might as well start with a third-party solution to begin
with.

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


Re: python vs java

2006-09-07 Thread Felipe Almeida Lessa
2006/9/7, Bruno Desthuilliers [EMAIL PROTECTED]:
 I don't think one could pretend writing a cross-platform application
 without testing it on all targeted platforms.

E.g: while creating a free software, you may not have an Apple
computer but you may want to be *possible* to run your program there.
You don't test it, but you *think* it runs there. Not everybody has a
spare MacOS X to test apps.

Of course, if your software *needs* to run in some particular OS then
you have to test on it.

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


Re: getting quick arp request

2006-09-07 Thread Daniel Nogradi
 2)
 Still without the above patch on windows, the software angry ip scan
 for example managed to output a lot of more socket connection. How is
 it possible ?

This angry ip scan thing is written in Java, perhaps you can find it
out from the source:

http://svn.sourceforge.net/viewvc/ipscan/ipscan/src/net/azib/ipscan/
-- 
http://mail.python.org/mailman/listinfo/python-list


mac address

2006-09-07 Thread DarkBlue
Hello

Is it possible to get the mac address of a device 
with python 2.4 using code which works in wxp and linux 
rather than requiring some code for windows and some
other code for linux ?

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


Re: getting quick arp request

2006-09-07 Thread Ben Sizer
seb wrote:
 I am not fully confident to apply the patch from
 http://www.lvllord.de/?lang=enurl=downloads .on computers other than
 mine.

Fully understandable.

 Is there another solution ?

I believe it is possible to overwrite the .dll that SP2 gives you with
the older one. Obviously you lose any other bug fixes or enhancements
Microsoft put in there. I don't remember the actual file in question,
sorry. And I don't suppose this is much more acceptable than the
previous 'solution'.

 Still without the above patch on windows, the software angry ip scan
 for example managed to output a lot of more socket connection. How is
 it possible ?

It sends an ICMP ping to each address first, meaning it doesn't have to
waste time on trying a TCP connection to a host that doesn't respond.
This leads to fewer half-open connections.

It may also be that it implements part of its own TCP/IP stack, and
accessing the ethernet card directly, but I don't know how practical
that is for you. Ethereal and nmap appear to do this; you might want to
browse their open source code, and/or ask on their mailing lists or
forums.

-- 
Ben Sizer

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


How to build extensions on Windows?

2006-09-07 Thread Kevin D.Smith
I've written a simple Python extension for UNIX, but I need to get it 
working on Windows now.  I'm having some difficulties figuring out how 
to do this.  I've seen web pages that say that MS Visual Studio is 
required, and other that say that's not true, that MinGW will work.  
Then there is Mike Fletcher's web page 
(http://www.vrplumber.com/programming/mstoolkit/) that describes in 
detail how to build extensions, but most of the links to external 
software are no longer valid.  I think it's safe to say that I am 
completely lost, as there appears to be no authoritative, up-to-date 
description on how to make this work.

-- 
Kevin D. Smith

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


Re: sending emails using python

2006-09-07 Thread Grant Edwards
On 2006-09-07, Sybren Stuvel [EMAIL PROTECTED] wrote:
 Tim Williams enlightened us with:
 Can you send email via it using outlook express or a similar
 POP3/IMAP mail client?

 Wouldn't you use a SMTP client to send email?

I would, but I don't use exchange server. :)

The one exchange server I used in the past didn't accept SMTP
mail.

-- 
Grant Edwards   grante Yow!  I have the power
  at   to HALT PRODUCTION on all
   visi.comTEENAGE SEX COMEDIES!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to build extensions on Windows?

2006-09-07 Thread Lawrence Oluyede
Kevin D. Smith [EMAIL PROTECTED] wrote:
 Then there is Mike Fletcher's web page 
 (http://www.vrplumber.com/programming/mstoolkit/) that describes in 
 detail how to build extensions, but most of the links to external 
 software are no longer valid.  I think it's safe to say that I am 
 completely lost, as there appears to be no authoritative, up-to-date 
 description on how to make this work.

I managed to set up a compilation toolchain in Windows following that
tutorial so what's your problem?

I installed MS .NET 1.1 and its SDK, the Platform SDK for Windows 2003
sever and the mstoolkit (you have to borrow it from somewhere because
it's not available anymore)
Then I hacked distutils and all worked well.

The only issue is to find the MS Toolkit 2003...

-- 
Lawrence - http://www.oluyede.org/blog
Nothing is more dangerous than an idea
if it's the only one you have - E. A. Chartier
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sending emails using python

2006-09-07 Thread Hari Sekhon




Grant Edwards wrote:

  On 2006-09-07, Sybren Stuvel [EMAIL PROTECTED] wrote:
  
  
Tim Williams enlightened us with:


  Can you send email via it using outlook express or a similar
POP3/IMAP mail client?
  

Wouldn't you use a SMTP client to send email?

  
  
I would, but I don't use exchange server. :)

The one exchange server I used in the past didn't accept SMTP
mail.

  

errr, I used to admin Exchange, if it does accept SMTP then how could
it function as a live mail server?


Hari Sekhon


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

Re: change property after inheritance

2006-09-07 Thread Steven Bethard
David Isaac wrote:
 Le mercredi 06 septembre 2006 16:33,  Alan Isaac a écrit :
 Suppose a class has properties and I want to change the
 setter in a derived class. If the base class is mine, I can do this:
 http://www.kylev.com/2004/10/13/fun-with-python-properties/
 Should I? (I.e., is that a good solution?)
 
 Maric Michaud [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 Why not ? This ontroduce the notion of public getter a la C++/Java while
 the
 property is overloadable by itself (as below), but it's correct design
 IMHO.
 
 More support for lambda, it seems...

Well, lambda's not going away[1], but there's no *need* for lambda here. 
  It could be written as::

 class Base(object):
 def __init__(self):
 self.foo = None

 def getFoo(self):
 return self.__foo

 def setFoo(self, val):
 self.__foo = val

 def _prop_get_foo(self):
 return self.getFoo()

 def _prop_set_foo(self, val):
 return self.setFoo(val)

 foo = property(fget=_prop_get_foo, fset=_prop_set_foo)

[1] http://www.python.org/dev/peps/pep-3099/

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


Re: IronPython on Mono howto

2006-09-07 Thread skip

sanxiyn For those of us who have never used IronPython or Mono, is
sanxiyn there a quick start document laying about somewhere?  It wasn't
sanxiyn clear to me where to even look.

sanxiyn Okay, here we go:
...

Thanks.  Worked like a charm.  Like others I noticed the apparent
performance drop.  I presume that's more a comment on the state of
optimization in Mono than on IronPython itself.

One thing I did find especially annoying though was that none of the editing
keys worked.  DELETE, BACKSPACE, Ctrl-U.  All just inserted themselves.
Ctrl-D didn't exit.  (I had to raise SystemExit to exit.)

Is this a known problem?  Is it a Mono thing or an IronPython thing?  Any
workaround?

Thx,

Skip

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


3 Simple Questions About Python/IDLE

2006-09-07 Thread Omar
1) why don't python / idle use numbered lines in their scripting, like
basic?  how do you keep track of large batches of code without them?

2) in IDLE, how do you save a program such that it can be run, say from
windows the run function?

3) are most of you doing your script editing in IDLE or something more
fully featured?

4) how are you importing previously written blocks of code into your
code?  cut and paste?  what is the best way to organize snippets of
code?

thanks, peeps

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


Re: IronPython 1.0 - Bugs or Features?

2006-09-07 Thread Claudio Grondi
Super Spinner wrote:
 IronPython is a .NET language, so does that mean that it invokes the
 JIT before running actual code?  If so, then simple short scripts
 would take longer with IronPython busy starting itself loading .NET
 and invoking the JIT.  This effect would be less noticable, the longer
 the program is.  But I'm just guessing; I've not used IronPython.
 
The time of loading IronPython seem to pay out at the end if the script 
takes a longer time to run, so you are most probably right. I am a bit 
surprised, that the difference is not that big (e.g. at least half the 
time) as I have expected from a JIT concept ... :

code
# import psyco
# psyco.full()

def arccot(x, unity):
 sum = xpower = unity // x
 n = 3
 sign = -1
 while 1:
 xpower = xpower // (x*x)
 term = xpower // n
 if not term:
 break
 sum += sign * term
 sign = -sign
 n += 2
 return sum

def pi(digits):
 print '  start of setting unity value ...',
 unity = 10**(digits + 10)
 print '  set unity value, starting arccot() ... ',
 pi = 4 * (4*arccot(5, unity) - arccot(239, unity))
 return pi // 10**10


f = file(pi-decimal-10digits.out,wb)
f.write(str(pi(10)))

print 
   PC:  Pentium 4,  2.8 GHz,  Windows XP SP2
   writing 100.000 digits of Pi to a file takes using:
 CPython 2.4.2  : 2 min 41 s (of CPU time)
 CPython+Psyco  : 2 min 45 s (of CPU time)
 IronPython 1.0 : 1 min 48 s (of CPU time)

/code

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


Re: 3 Simple Questions About Python/IDLE

2006-09-07 Thread Claudio Grondi
Omar wrote:
 1) why don't python / idle use numbered lines in their scripting, like
 basic?  how do you keep track of large batches of code without them?
 
 2) in IDLE, how do you save a program such that it can be run, say from
 windows the run function?
 
 3) are most of you doing your script editing in IDLE or something more
 fully featured?
 
 4) how are you importing previously written blocks of code into your
 code?  cut and paste?  what is the best way to organize snippets of
 code?
 
 thanks, peeps
 
1) Python is very different from what you expect being experienced in 
programming with Basic. My recommendation: don't hesitate to take the 
time to read the Python manual.
2) Double click on saved Python script (hope you are able to save a 
file? Haven't you detected that you can edit and run a file in IDLE?)
3) Plain text editor or IDLE are good. For more see Python website - 
there are plenty options to choose from.
4) using 'import' (see recommendation in 1))

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


Re: Refactor a buffered class...

2006-09-07 Thread George Sakkis
Michael Spencer wrote:
 George Sakkis wrote:
  Michael Spencer wrote:
 
  Here's a small update to the generator that allows optional handling of 
  the head
  and the tail:
 
  def chunker(s, chunk_size=3, sentry=., keep_first = False, keep_last = 
  False):
   buffer=[]
 ...
 
  And here's a (probably) more efficient version, using a deque as a
  buffer:
 

 Perhaps the deque-based solution is more efficient under some conditions, but
 it's significantly slower for all the cases I tested:

First off, if you're going to profile something, better use the
standard timeit module rather than a quick, dirty and most likely buggy
handmade function. From Dive into python: The most important thing
you need to know about optimizing Python code is that you shouldn't
write your own timing function.. As it turns out, none of chunk_size,
words_per_group and word_length are taken into account in your tests;
they all have their default values. By the way, word_length is
irrelevant since the input is already a sequence, not a big string to
be split.

Second, the output of the two functions is different, so you're not
comparing apples to apples:
 s =  this .  is a . test to . check if it . works . well . it looks . like 
 .
 for c in chunkerMS(s.split(), keep_last=True, keep_first=True): print c
...
['this', '.']
['this', '.', 'is', 'a', '.']
['this', '.', 'is', 'a', '.', 'test', 'to', '.']
['is', 'a', '.', 'test', 'to', '.', 'check', 'if', 'it', '.']
['test', 'to', '.', 'check', 'if', 'it', '.', 'works', '.']
['check', 'if', 'it', '.', 'works', '.', 'well', '.']
['works', '.', 'well', '.', 'it', 'looks', '.']
['well', '.', 'it', 'looks', '.', 'like', '.']
['it', 'looks', '.', 'like', '.']
['like', '.']
 for c in chunkerGS(s.split(), keep_last=True, keep_first=True): print c
...
['this']
['this', 'is a']
['this', 'is a', 'test to']
['is a', 'test to', 'check if it']
['test to', 'check if it', 'works']
['check if it', 'works', 'well']
['works', 'well', 'it looks']
['well', 'it looks', 'like']
['it looks', 'like']
['like']

Third, and most important for the measured difference, is that the
performance hit in my function came from joining the words of each
group (['check', 'if', 'it'] - 'check if it') every time it is
yielded. If the groups are left unjoined as in Michael's version, the
results are quite different:

* chunk_size=3
chunkerGS: 0.98 seconds
chunkerMS: 1.04 seconds
* chunk_size=30
chunkerGS: 0.98 seconds
chunkerMS: 1.17 seconds
* chunk_size=300
chunkerGS: 0.98 seconds
chunkerMS: 2.44 seconds

As expected, the deque solution is not affected by chunk_size. Here is
the full test:

# chunkers.py
from itertools import islice
from collections import deque

def chunkerMS(s, chunk_size=3, sentry=., keep_first = False,
keep_last = False):
 buffer=[]
 sentry_count = 0
 for item in s:
 buffer.append(item)
 if item == sentry:
 sentry_count += 1
 if sentry_count  chunk_size:
 if keep_first:
 yield buffer
 else:
 yield buffer
 del buffer[:buffer.index(sentry)+1]
 if keep_last:
 while buffer:
 yield buffer
 del buffer[:buffer.index(sentry)+1]

def chunkerGS(seq, sentry='.', chunk_size=3, keep_first=False,
keep_last=False):
buf = deque()
iterchunks = itersplit(seq,sentry)
for chunk in islice(iterchunks, chunk_size-1):
buf.append(chunk)
if keep_first:
yield buf
for chunk in iterchunks:
buf.append(chunk)
yield buf
buf.popleft()
if keep_last:
while buf:
yield buf
buf.popleft()

def itersplit(seq, sentry='.'):
# split the iterable `seq` on each `sentry`
buf = []
for x in seq:
if x != sentry:
buf.append(x)
else:
yield buf
buf = []
if buf:
yield buf

def make_seq(groups=1000, words_per_group=3, sentry='.'):
 group = ['w']*words_per_group
 group.append(sentry)
 return group*groups


if __name__ == '__main__':
import timeit
for chunk_size in 3,30,300:
print * chunk_size=%d % chunk_size
for func in chunkerGS,chunkerMS:
name = func.__name__
t = timeit.Timer(
for p in %s(s, chunk_size=%d, keep_last=True,
keep_first=True):pass %
(name,chunk_size),
from chunkers import make_seq,chunkerGS,chunkerMS;
s=make_seq(groups=5000, words_per_group=500))
print %s: %.2f seconds % (name, min(t.repeat(3,1)))

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


Re: sending emails using python

2006-09-07 Thread Tim Williams
On 07/09/06, Hari Sekhon [EMAIL PROTECTED] wrote:

  Grant Edwards wrote:
  On 2006-09-07, Sybren Stuvel
 [EMAIL PROTECTED] wrote:


  Tim Williams enlightened us with:


  Can you send email via it using outlook express or a similar
 POP3/IMAP mail client?

  Wouldn't you use a SMTP client to send email?

  I would, but I don't use exchange server. :)

 The one exchange server I used in the past didn't accept SMTP
 mail.


  errr, I used to admin Exchange, if it does accept SMTP then how could it
 function as a live mail server?

Did you mean *doesn't accept*  ??

There are a couple of possibilities at least,   of the top of my head:

* The IMC / IMS  (smtp connector) is located on a different server
within its Exchange organisation,  or a DMZ'ed exchange server that is
only used for SMTP.

* The server doesn't accept SMTP from local IP ranges,  only from
external (ie inbound email)

Outlook / Exchange clients use MAPI,  internal SMTP is only a
requirement if you have non-MAPI clients sending email through the
server.

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


Re: How to build extensions on Windows?

2006-09-07 Thread Sybren Stuvel
Kevin D  Smith enlightened us with:
 I've written a simple Python extension for UNIX, but I need to get
 it working on Windows now.  I'm having some difficulties figuring
 out how to do this.

I had to do the same, and I didn't get much result. My solution:
install Cygwin, use the Python that comes with that, and use gcc just
like you're used to. Works like a charm, but the compiled extension is
incompatible with the regular Windows Pythons from python.org and
ActiveState.

Sybren
-- 
Sybren Stüvel
Stüvel IT - http://www.stuvel.eu/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [ANN] IronPython 1.0 released today!

2006-09-07 Thread Felipe Almeida Lessa
2006/9/5, Jim Hugunin [EMAIL PROTECTED]:
 I'm extremely happy to announce that we have released IronPython 1.0 today!
  http://www.codeplex.com/IronPython

Does IronPython runs Twisted?

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


Re: 3 Simple Questions About Python/IDLE

2006-09-07 Thread Omar
thanks

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


Re: 4 Simple Questions About Python/IDLE

2006-09-07 Thread Omar
thanks.

i have saved and double clicked as suggested.  when I save and double
click a simple hello program, the bw python shell briefly comes up,
then disappears. is this how it should work?

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


Re: 4 Simple Questions About Python/IDLE

2006-09-07 Thread Diez B. Roggisch
Omar schrieb:
 thanks.
 
 i have saved and double clicked as suggested.  when I save and double
 click a simple hello program, the bw python shell briefly comes up,
 then disappears. is this how it should work?

Yes. because when your program terminates, the shell terminates. Or 
would you prefer it sticking around, cluttering screen space?

If you want it to stay,  make your program require a key-press in the 
end. something like this:

raw_input(press return)


Diez


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


Returned mail: see transcript for details

2006-09-07 Thread Automatic Email Delivery Software
This message was undeliverable due to the following reason(s):

Your message could not be delivered because the destination server was
unreachable within the allowed queue period. The amount of time
a message is queued before it is returned depends on local configura-
tion parameters.

Most likely there is a network problem that prevented delivery, but
it is also possible that the computer is turned off, or does not
have a mail system running right now.

Your message was not delivered within 6 days:
Host 65.118.43.228 is not responding.

The following recipients could not receive this message:
python-list@python.org

Please reply to [EMAIL PROTECTED]
if you feel this message to be in error.



Deleted0.txt 
Description: Binary data
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: 4 Simple Questions About Python/IDLE

2006-09-07 Thread Larry Bates
Omar wrote:
 thanks.
 
 i have saved and double clicked as suggested.  when I save and double
 click a simple hello program, the bw python shell briefly comes up,
 then disappears. is this how it should work?
 
Yes, that is how it should work.  Program is doing what you
told it to.  print hello program and exit (which closes the window).
If you want it to pause put something after the print like:

t=raw_input('Hit return to continue')

This way the program will pause until you hit return.

Good luck.

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


PyGTK - Rollover Buttons

2006-09-07 Thread Gepi Solo
Hi, I'm a python newbie, coming from PHP  Perl. I'm developing client-server 
applications with a GUI. I'm trying to realize rollover buttons with images 
as background. I mean... I want to create a class which permit to create 
buttons with various shapes, (for instance something like this: OO with 
a label and an image in the central part), that change their color/shapes 
when they have the focus on.
I split the image of the shape into 3 parts: left, center (which have to 
resize with the label in the button) and right.
I thought to Create an  EventBox (with the callback function connected to 
it).
Inside this EventBox I'd put a HBox with 3 elements: left image, another 
EventBox in the center, and the right image.
The EventBox in the center should have the central part of the shape-image 
as background and the Label of the button (and evenually an icon).

Am I right?? I don't know if it's the right way... I didn't find anything 
on this topic on Google. Anyway if it's the right way... I don't know how:
1. To put the central image as background in the inner EventBox(does the 
background image behave like in html tables where it repeats itself until 
it fill all the available space?)
2. To change all the images to realize the rollover effect
3. Trying to add an EventBox to the main window I noticed that it's grey 
and it covers the background image of the window. If I realize the button 
using the EventBox I'd like to see the window background image outside the 
shape of the button... (I don't know if it's clear... :) ) 

thanx in advance.
G.


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


the same strings, different utf-8 repr values?

2006-09-07 Thread slowness . chen
I have two files:

test.py:
--
# -*- encoding : utf8 -*-
print 'in this file', repr('中文')

# tt.txt is saved as utf8 encoding
f = file('tt.txt')
line1 = f.readline().strip()
print 'another file', repr(line1)
---

tt.txt:

中文
test
---
run test.py and I get the following output:
in this file '\xe4\xb8\xad\xe6\x96\x87'
another file '\xef\xbb\xbf\xe4\xb8\xad\xe6\x96\x87'

and I cann't encode line1 like:
   line1.decode('utf8').encode('gbk')
get this error:
UnicodeEncodeError: 'gbk' codec can't encode character u'\ufeff' in
position 0:
illegal multibyte sequence

why did I get the different repr values?

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

Re: change property after inheritance

2006-09-07 Thread George Sakkis
Steven Bethard wrote:

 David Isaac wrote:
  Le mercredi 06 septembre 2006 16:33,  Alan Isaac a écrit :
  Suppose a class has properties and I want to change the
  setter in a derived class. If the base class is mine, I can do this:
  http://www.kylev.com/2004/10/13/fun-with-python-properties/
  Should I? (I.e., is that a good solution?)
 
  Maric Michaud [EMAIL PROTECTED] wrote in message
  news:[EMAIL PROTECTED]
  Why not ? This ontroduce the notion of public getter a la C++/Java while
  the
  property is overloadable by itself (as below), but it's correct design
  IMHO.
 
  More support for lambda, it seems...

 Well, lambda's not going away[1], but there's no *need* for lambda here.
   It could be written as::

Sure, it *could*; whether it *should* is a different issue. I can't
imagine a case for absolute *need* of lambda, but there are several
cases where it is probably the best way, such as the one of this
thread.

George

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


xmingw and f2py

2006-09-07 Thread Flavio
Hi,

has anyone tried to build extensions for win32 on Linux using xmingw?

I need to use f2py to compile code for the win32 platform and I want to
do this in Linux. I googled aroung but could not find any documentation
on this.

For those who dont know xmingw is a port to linux of  mingw.

any help is appreciated.

Flávio

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


Re: sending emails using python

2006-09-07 Thread Grant Edwards
On 2006-09-07, Tim Williams [EMAIL PROTECTED] wrote:

  Wouldn't you use a SMTP client to send email?

  I would, but I don't use exchange server. :)

 The one exchange server I used in the past didn't accept SMTP
 mail.

 errr, I used to admin Exchange, if it does accept SMTP then
 how could it function as a live mail server?

 Did you mean *doesn't accept* ??

One presumes he did.

 There are a couple of possibilities at least, of the top of my
 head:

 * The IMC / IMS (smtp connector) is located on a different
   server within its Exchange organisation, or a DMZ'ed
   exchange server that is only used for SMTP.

 * The server doesn't accept SMTP from local IP ranges, only
   from external (ie inbound email)

I believe it was the latter.  I'm pretty sure there was only
one server.  When I first started at that company it did accept
SMTP connections on it's internal network interface.

 Outlook / Exchange clients use MAPI, internal SMTP is only a
 requirement if you have non-MAPI clients sending email through
 the server.

And BOFH was horrified by non-MS software, so he shut off IMAP
support and SMTP support on the internal network as a way to
force everybody to switch to Outlook.

-- 
Grant Edwards   grante Yow!  This ASEXUAL
  at   PIG really BOILS
   visi.commy BLOOD... He's
   so... so... URGENT!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 4 Simple Questions About Python/IDLE

2006-09-07 Thread Omar
thank you genteman.

however, its not working :(

I resaved it, but same thing.

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


Method resolution for super(Class, obj).

2006-09-07 Thread ddtl
Hello everybody.

Consider the following code:


class A(object):
def met(self):
print 'A.met'
class B(A):
def met(self):
print 'B.met'
super(B,self).met()
class C(A):
def met(self):
print 'C.met'
super(C,self).met()
class D(B,C):
def met(self):
print 'D.met'
super(D,self).met()
d = D()
d.met()


When executed, it prints:

D.met
B.met
C.met
A.met

The book (Python in a nutshell, 2nd edition) explains:

The solution is to use built-in type super. super(aclass, obj), 
which returns a special superobject of object obj. When we look 
up an attribute (e.g., a method) in this superobject, the lookup 
begins after class aclass in obj's MRO.

But I don't understand - MRO means that when attribute is found 
somewhere in hierarchy, the search for it stops, that is: when 
d.met() is executed, it is supposed to print 'D met', call 
super(D,self).met() which should resolve met() to be B's attribute, 
and after B's met() is executed, we should be done. Why does the 
lookup proceeds from B to C as though met() wasn't found in B? 
Indeed, lookup order (according to a new-style MRO) is B, then C 
and at last A (because of a diamond inheritance), but only when 
attribute is not found in B it is looked up in C, and only if it 
is not found neither in B nor in C it is looked up in A...

What is different here?

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


Re: sending emails using python

2006-09-07 Thread Hari Sekhon




Grant Edwards wrote:

  On 2006-09-07, Tim Williams [EMAIL PROTECTED] wrote:

  
  

   Wouldn't you use a SMTP client to send email?

 I would, but I don't use exchange server. :)

The one exchange server I used in the past didn't accept SMTP
mail.

errr, I used to admin Exchange, if it does accept SMTP then
how could it function as a live mail server?
  

Did you mean *doesn't accept* ??

  
  
One presumes he did.

  
  
There are a couple of possibilities at least, of the top of my
head:

* The IMC / IMS (smtp connector) is located on a different
  server within its Exchange organisation, or a DMZ'ed
  exchange server that is only used for SMTP.

* The server doesn't accept SMTP from local IP ranges, only
  from external (ie inbound email)

  
  
I believe it was the latter.  I'm pretty sure there was only
one server.  When I first started at that company it did accept
SMTP connections on it's internal network interface.

  
  
Outlook / Exchange clients use MAPI, internal SMTP is only a
requirement if you have non-MAPI clients sending email through
the server.

  
  
And BOFH was horrified by non-MS software, so he shut off IMAP
support and SMTP support on the internal network as a way to
force everybody to switch to Outlook.

  

I did mean *doesn't accept*, sorry was in a rush...

BOFH? 

lol

If he were a better op then perhaps he would be using unix based system
himself and wouldn't be so discriminating... but then you can't hope
for the world with windows only "techies"... although in fairness,
Exchange and Outlook is a great combination...

you could always try ximian's exchange connector for evolution, I
managed to get some emails with that...

but anyway, ot...


Hari Sekhon




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

Wrapper for EMC SYMAPI library

2006-09-07 Thread Ellinghaus, Lance
Title: Wrapper for EMC SYMAPI library






Has anyone ever created a python wrapper for the EMC SYMAPI library???


Any information would be very much appreciated!!


Thank you,

Lance Ellinghaus



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

Re: 4 Simple Questions About Python/IDLE

2006-09-07 Thread Larry Bates
Omar wrote:
 thank you genteman.
 
 however, its not working :(
 
 I resaved it, but same thing.
 
Please post some code so we can actually do something more than
read your mind.  You can also run the program from a shell
instead of from idle to see what happens.

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


Using Beautiful Soup to entangle bookmarks.html

2006-09-07 Thread Francach
Hi,

I'm trying to use the Beautiful Soup package to parse through the
bookmarks.html file which Firefox exports all your bookmarks into.
I've been struggling with the documentation trying to figure out how to
extract all the urls. Has anybody got a couple of longer examples using
Beautiful Soup I could play around with?

Thanks,
Martin.

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


Re: Using Beautiful Soup to entangle bookmarks.html

2006-09-07 Thread Diez B. Roggisch
Francach schrieb:
 Hi,
 
 I'm trying to use the Beautiful Soup package to parse through the
 bookmarks.html file which Firefox exports all your bookmarks into.
 I've been struggling with the documentation trying to figure out how to
 extract all the urls. Has anybody got a couple of longer examples using
 Beautiful Soup I could play around with?

Why do you use BeautifulSoup on that? It's generated content, and I 
suppose it is well-formed, most probably even xml. So use a standard 
parser here, better yet somthing like lxml/elementtree

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


Re: IronPython on Mono howto

2006-09-07 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], skip wrote:

 One thing I did find especially annoying though was that none of the editing
 keys worked.  DELETE, BACKSPACE, Ctrl-U.  All just inserted themselves.
 Ctrl-D didn't exit.  (I had to raise SystemExit to exit.)
 
 Is this a known problem?  Is it a Mono thing or an IronPython thing?  Any
 workaround?

The `boo` shell and the `Nemerle` shell can be quit with Ctrl-D under
Mono, so I guess it's an `IronPython` thing.

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


Re: 4 Simple Questions About Python/IDLE

2006-09-07 Thread Omar
sure...

 print hello world
hello world
 t=raw_input('Hit return to continue')

I'm saving it as helloworld11, then double clicking the icon I saved
it as.

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


RE: mac address

2006-09-07 Thread Tim Golden
| Is it possible to get the mac address of a device 
| with python 2.4 using code which works in wxp and linux 
| rather than requiring some code for windows and some
| other code for linux ?

I'm fairly sure the answer's no. It wouldn't be beyond
the wit of man to produce a library with conditional
imports or checks against the sys.platform etc. which
did sensible things. If you Google the archives for this
group you'll see similar questions a few times in the
past, so maybe there are some starting points for you
there. (On Win32 I'd use WMI, but that's just because...)

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: 4 Simple Questions About Python/IDLE

2006-09-07 Thread Omar
okay...

I got to work using the SCITE editor with

print hello world # here we are once again
raw_input(press return) 

cool!

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


Re: sending emails using python

2006-09-07 Thread Steve Holden
Hari Sekhon wrote:
[...]
 
 BOFH?
 
Bas**rd Operator From Hell
 lol
 
Indeed.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: [ANN] IronPython 1.0 released today!

2006-09-07 Thread Aahz
In article [EMAIL PROTECTED],
Jim Hugunin  [EMAIL PROTECTED] wrote:

I'm extremely happy to announce that we have released IronPython 1.0 today!
 http://www.codeplex.com/IronPython

Congrats!
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

I support the RKAB
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 4 Simple Questions About Python/IDLE

2006-09-07 Thread John Purser
Omar,

The '' were causing the problem I would guess.  Those are the
interactive interpreter's prompts, not python.  Saving a python session
like that is a starting place for creating code, not the finished
product.

You might also want to save the file as helloworld11.py before double
clicking it.

Again, these problems indicate that you're not ready to even start
coding until you've read a good intro text.

John Purser

On Thu, 2006-09-07 at 09:11 -0700, Omar wrote:
 okay...
 
 I got to work using the SCITE editor with
 
 print hello world   # here we are once again
 raw_input(press return) 
 
 cool!
 

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


Re: 4 Simple Questions About Python/IDLE

2006-09-07 Thread Omar
I'm working through a tutorial,
http://swaroopch.info/text/Byte_of_Python:Control_Flow, and I sorta
can't get through the tutorial without overcoming these little
speedbumps.  This is why I'm asking these questions.

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


Re: How to build extensions on Windows?

2006-09-07 Thread Kevin D.Smith
On 2006-09-07 09:28:42 -0400, [EMAIL PROTECTED] (Lawrence Oluyede) said:

 Kevin D. Smith [EMAIL PROTECTED] wrote:
 Then there is Mike Fletcher's web page 
 (http://www.vrplumber.com/programming/mstoolkit/) that describes in 
 detail how to build extensions, but most of the links to external 
 software are no longer valid.  I think it's safe to say that I am 
 completely lost, as there appears to be no authoritative, up-to-date 
 description on how to make this work.
 
 I managed to set up a compilation toolchain in Windows following that
 tutorial so what's your problem?
 
 I installed MS .NET 1.1 and its SDK, the Platform SDK for Windows 2003
 sever and the mstoolkit (you have to borrow it from somewhere because
 it's not available anymore)
 Then I hacked distutils and all worked well.
 
 The only issue is to find the MS Toolkit 2003...


So in other words, what you're saying is that the only issue I have 
left is the exact issue that I described in my initial post that you 
claimed isn't a problem...  Great!  I guess I'l get right down to work 
compiling that extension now.

-- 
Kevin D. Smith

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


Re: Unicode string handling problem

2006-09-07 Thread Richard Schulman
Many thanks for your help, John, in giving me the tools to work
successfully in Python with Unicode from here on out.

It turns out that the Unicode input files I was working with (from MS
Word and MS Notepad) were indeed creating eol sequences of \r\n, not
\n\n as I had originally thought. The file reading statement that I
was using, with unpredictable results, was

#in_file =
codecs.open(c:\\pythonapps\\in-graf2.my,rU,encoding=utf-16LE)

This was reading to the \n on first read (outputting the whole line,
including the \n but, weirdly, not the preceding \r). Then, also
weirdly, the next readline would read the same \n again, interpreting
that as the entirety of a phantom second line. So each input file line
ended up producing two output lines.

Once the mode string rU was dropped, as in

in_file =
codecs.open(c:\\pythonapps\\in-graf2.my,encoding=utf-16LE)

all suddenly became well: no more doubled readlines, and one could see
the \r\n termination of each line.

This behavior of rU was not at all what I had expected from the
brief discussion of it in _Python Cookbook_. Which all goes to point
out how difficult it is to cook challenging dishes with sketchy
recipes alone. There is no substitute for the helpful advice of an
experienced chef.

-Richard Schulman
 (remove xx for email reply)

On 5 Sep 2006 22:29:59 -0700, John Machin [EMAIL PROTECTED]
wrote:

Richard Schulman wrote:
[big snip]

 The BOM is little-endian, I believe.
Correct.

 in_file = codecs.open(filepath, mode, encoding=utf16???)

 Right you are. Here is the output produced by so doing:

You don't say which encoding you used, but I guess that you used
utf_16_le.


 type 'unicode'
 u'\ufeffINSERT INTO [...] VALUES\N'

Use utf_16 -- it will strip off the BOM for you.

 type 'unicode'
 u'\n'
 0   [The counter value]

[snip]
 Yes, it did. Many thanks! Now I've got to figure out the best way to
 handle that \n\n at the end of each row, which the program is
 interpreting as two rows.

Well we don't know yet exactly what you have there. We need a byte dump
of the first few bytes of your file. Get into the interactive
interpreter and do this:

open('yourfile', 'rb').read(200)
(the 'b' is for binary, in case you are on Windows)
That will show us exactly what's there, without *any* EOL
interpretation at all.


 That represents two surprises: first, I
 thought that Microsoft files ended as \n\r ;

Nah. Wrong on two counts. In text mode, Microsoft *lines* end in \r\n
(not \n\r); *files* may end in ctrl-Z aka chr(26) -- an inheritance
from CP/M.

U ... are you saying the file has \n\r at the end of each row?? How
did you know that if you didn't know what if any BOM it had??? Who
created the file

 second, I thought that
 Python mode rU was supposed to be the universal eol handler and
 would handle the \n\r as one mark.

Nah again. It contemplates only \n, \r, and \r\n as end of line. See
the docs. Thus \n\r becomes *two* newlines when read with rU.

Having \n\r at the end of each row does fit with your symptoms:

|  bom = u\ufeff
|  guff = '\n\r'.join(['abc', 'def', 'ghi'])
|  guffu = unicode(guff)
|  import codecs
|  f = codecs.open('guff.utf16le', 'wb', encoding='utf_16_le')
|  f.write(bom+guffu)
|  f.close()

|  open('guff.utf16le', 'rb').read()  see exactly what we've got

|
'\xff\xfea\x00b\x00c\x00\n\x00\r\x00d\x00e\x00f\x00\n\x00\r\x00g\x00h\x00i\x00'

|  codecs.open('guff.utf16le', 'r', encoding='utf_16').read()
| u'abc\n\rdef\n\rghi' # Look, Mom, no BOM!

|  codecs.open('guff.utf16le', 'rU', encoding='utf_16').read()
| u'abc\n\ndef\n\nghi'  U means \r - \n

|  codecs.open('guff.utf16le', 'rU', encoding='utf_16_le').read()
| u'\ufeffabc\n\ndef\n\nghi' # reproduces your second
experience

|  open('guff.utf16le', 'rU').readlines()
| ['\xff\xfea\x00b\x00c\x00\n', '\x00\n', '\x00d\x00e\x00f\x00\n',
'\x00\n', '\x00
| g\x00h\x00i\x00']
|  f = open('guff.utf16le', 'rU')
|  f.readline()
| '\xff\xfea\x00b\x00c\x00\n'
|  f.readline()
| '\x00\n' # reproduces your first experience
|  f.readline()
| '\x00d\x00e\x00f\x00\n'
| 

If that file is a one-off, you can obviously fix it by
throwing away every second line. Otherwise, if it's an ongoing
exercise, you need to talk sternly to the file's creator :-)

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


Tkinter listbox:get

2006-09-07 Thread vedran_dekovic
Hi,
I need help about Tkinter.I want,when somebody click on some item in
listbox,then
in new entry widget must write that item

Regards,
Vedran

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


Random image downloader for newsgroups (first script)

2006-09-07 Thread Kim
Random image downloader for specified newsgroup. Hi I'm writing a small script 
that will download random images from a specified newsgroup. I've imported yenc 
into the script but I can't open the image or save it. This is my first script 
so be gentle!

Heres the script


random group downloader
import nntplib
import string, random
import mimetools
import StringIO
import rfc822
import sys, base64
import os
import email
import errno
import mimetypes


SERVER = news.server.co.uk #Insert news server here
GROUP  = alt.binaries.pictures.blah #newsgroup will go here

# connect to server
server = nntplib.NNTP(SERVER)

resp, count, first, last, name = server.group(GROUP)

for i in range(10):
try:
id = random.randint(int(first), int(last))
resp, id, message_id, text = server.article(str(id))
except (nntplib.error_temp, nntplib.error_perm):
pass # no such message (maybe it was deleted?)
else:
break # found a message!
else:
raise SystemExit

text = string.join(text, \n)
file = StringIO.StringIO(text)

msg = mimetools.Message(file)

#display message information
#print File type, =, msg.gettype()
#print Encoding, =, msg.getencoding()
#print plist, =, msg.getplist()

message = rfc822.Message(file)

for k, v in message.items():
print k, =, v

file = message.fp.read()

def yenc_decode(file):
# ifind body/i
while 1:
line = file.readline()
if not line:
return None
if line[:7] == =ybegin:
break
# iextract data/i
buffer = []
while 1:
line = file.readline()
if not line or line[:5] == =yend:
break
if line[-2:] == \r\n:
line = line[:-2]
elif line[-1:] in \r\n:
line = line[:-1]
data = string.split(line, =)
buffer.append(string.translate(data[0], yenc42))
for data in data[1:]:
data = string.translate(data, yenc42)
buffer.append(string.translate(data[0], yenc64))
buffer.append(data[1:])
return buffer
#the following should write to a text file
#inp = (file,r)
#outp = open(text.txt,w)
#for line in file:
#outp.write(line)
#print file
#outp.close()



--=  Posted using GrabIt  =
--=  Binary Usenet downloading made easy =-
-=  Get GrabIt for free from http://www.shemes.com/  =-

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


Random news downloader (first script!)

2006-09-07 Thread Kim
Random image downloader for specified newsgroup. Hi I'm writing a small script 
that will download random images from a specified newsgroup. I've imported yenc 
into the script but I can't open the image or save it. This is my first script 
so be gentle!

Heres the script


random group downloader
import nntplib
import string, random
import mimetools
import StringIO
import rfc822
import sys, base64
import os
import email
import errno
import mimetypes


SERVER = news.server.co.uk #Insert news server here
GROUP  = alt.binaries.pictures.blah #newsgroup will go here

# connect to server
server = nntplib.NNTP(SERVER)

resp, count, first, last, name = server.group(GROUP)

for i in range(10):
try:
id = random.randint(int(first), int(last))
resp, id, message_id, text = server.article(str(id))
except (nntplib.error_temp, nntplib.error_perm):
pass # no such message (maybe it was deleted?)
else:
break # found a message!
else:
raise SystemExit

text = string.join(text, \n)
file = StringIO.StringIO(text)

msg = mimetools.Message(file)

#display message information
#print File type, =, msg.gettype()
#print Encoding, =, msg.getencoding()
#print plist, =, msg.getplist()

message = rfc822.Message(file)

for k, v in message.items():
print k, =, v

file = message.fp.read()

def yenc_decode(file):
# ifind body/i
while 1:
line = file.readline()
if not line:
return None
if line[:7] == =ybegin:
break
# iextract data/i
buffer = []
while 1:
line = file.readline()
if not line or line[:5] == =yend:
break
if line[-2:] == \r\n:
line = line[:-2]
elif line[-1:] in \r\n:
line = line[:-1]
data = string.split(line, =)
buffer.append(string.translate(data[0], yenc42))
for data in data[1:]:
data = string.translate(data, yenc42)
buffer.append(string.translate(data[0], yenc64))
buffer.append(data[1:])
return buffer
#the following should write to a text file
#inp = (file,r)
#outp = open(text.txt,w)
#for line in file:
#outp.write(line)
#print file
#outp.close()



--=  Posted using GrabIt  =
--=  Binary Usenet downloading made easy =-
-=  Get GrabIt for free from http://www.shemes.com/  =-


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


Re: Convert to big5 to unicode

2006-09-07 Thread Richard Schulman
On 7 Sep 2006 01:27:55 -0700, GM [EMAIL PROTECTED] wrote:

Could you all give me some guide on how to convert my big5 string to
unicode using python? I already knew that I might use cjkcodecs or
python 2.4 but I still don't have idea on what exactly I should do.
Please give me some sample code if you could. Thanks a lot

Gary, I used this Java program quite a few years ago to convert
various Big5 files to UTF-16. (Sorry it's Java not Python, but I'm a
very recent convert to the latter.) My newsgroup reader has messed the
formatting up somewhat. If this causes a problem, email me and I'll
send you the source directly.

-Richard Schulman

/*  This program converts an input file of one encoding format to
an output file of 
 *  another format. It will be mainly used to convert Big5 text
files to Unicode text files.
 */   

import java.io.*;
public class ConvertEncoding
{   public static void  main(String[] args)
{   String outfile =null;
try
{convert(args[0], args[1],  BIG5,
UTF-16LE);
}
//  Or, at command line:
//  convert(args[0], args[1], GB2312,
UTF8);
//  or numerous variations thereon. Among possible
choices for input or output:
//  GB2312, BIG5, UTF8, UTF-16LE.
The last named is MS UCS-2 format.
//  I.e., input file,output file,
input encoding, output encoding
catch (Exceptione)
{   System.out.print(e.getMessage());
System.exit(1);
}
 }

public static void convert(String infile, String outfile,
String from, String to) 
 throws IOException,UnsupportedEncodingException
{   // set up byte streams
InputStream in;
if (infile  !=  null)
in = new FileInputStream(infile);
else
in = System.in;

OutputStream out;
if (outfile != null)
out = new FileOutputStream(outfile);
else
out = System.out;

 // Set up character stream
Reader r =  new BufferedReader(new
InputStreamReader(in, from));
Writer w =  new BufferedWriter(new
OutputStreamWriter(out, to));

 w.write(\ufeff); // This character signals
Unicode in the NT environment
char[] buffer   = new char[4096];
int len;
while((len = r.read(buffer)) != -1) 
w.write(buffer, 0, len);
r.close();
w.flush();
w.close();
}
}
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [ANN] IronPython 1.0 released today!

2006-09-07 Thread Lawrence Oluyede
Felipe Almeida Lessa [EMAIL PROTECTED] wrote:
 Does IronPython runs Twisted?

I really don't think so. They don't have many needed modules, like
select :-)

-- 
Lawrence - http://www.oluyede.org/blog
Nothing is more dangerous than an idea
if it's the only one you have - E. A. Chartier
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to build extensions on Windows?

2006-09-07 Thread Lawrence Oluyede
Kevin D. Smith [EMAIL PROTECTED] wrote:
 So in other words, what you're saying is that the only issue I have 
 left is the exact issue that I described in my initial post that you 
 claimed isn't a problem...  Great!  I guess I'l get right down to work
 compiling that extension now.

What I mean is that you have to find a way to get the toolkit. I don't
think MS will sue you if you borrow the compiler from a friend or
download it. Otherwise you can try with MingW I guess...

-- 
Lawrence - http://www.oluyede.org/blog
Nothing is more dangerous than an idea
if it's the only one you have - E. A. Chartier
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to build extensions on Windows?

2006-09-07 Thread Jason
Kevin D. Smith wrote:
 I've written a simple Python extension for UNIX, but I need to get it
 working on Windows now.  I'm having some difficulties figuring out how
 to do this.  I've seen web pages that say that MS Visual Studio is
 required, and other that say that's not true, that MinGW will work.
 Then there is Mike Fletcher's web page
 (http://www.vrplumber.com/programming/mstoolkit/) that describes in
 detail how to build extensions, but most of the links to external
 software are no longer valid.  I think it's safe to say that I am
 completely lost, as there appears to be no authoritative, up-to-date
 description on how to make this work.

 --
 Kevin D. Smith

I don't know about MinGW, but you can get the Microsoft compilers by
installing Visual C++ 2005 Express.  I'm guessing the old toolkit is
deprecated.  While you must register each Visual Studio Express module
that you download, I don't think the actual command-line tools are
encumbered.

Why not try it out and let us know how it goes?

(Visual Studio 2005 Express:
http://msdn.microsoft.com/vstudio/express/)

--Jason

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


Printing Documents

2006-09-07 Thread defcon8
How can I print html documents in Python on Windows?

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


Re: python vs java

2006-09-07 Thread Jason
Felipe Almeida Lessa wrote:
 2006/9/7, Bruno Desthuilliers [EMAIL PROTECTED]:
  I don't think one could pretend writing a cross-platform application
  without testing it on all targeted platforms.

 E.g: while creating a free software, you may not have an Apple
 computer but you may want to be *possible* to run your program there.
 You don't test it, but you *think* it runs there. Not everybody has a
 spare MacOS X to test apps.

Ah, but those with the Intel Apples can run Linux, Windows, and Mac OS
X at the same time!  *grin*

Actually, that's how I'm working on my wx/Python application.  I write
it under Mac OS X and occasionally pull it into my Windows and Ubuntu
virtual machines for further testing.

 Of course, if your software *needs* to run in some particular OS then
 you have to test on it.

Certainly.  And this point should be emphasized for any cross-platform
language, especially for folk who may not have done such development
before.  The write once, run everywhere phrase does have a footnote.
Python's documentation is very good at pointing out what is platform
independent and what isn't, but other packages are not as thorough.

--Jason

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


Re: Using Beautiful Soup to entangle bookmarks.html

2006-09-07 Thread waylan

Diez B. Roggisch wrote:
 suppose it is well-formed, most probably even xml.

Maybe not. Otherwise, why would there be a script like this one[1]?
Anyway, I found that and other scripts that work with firefox
bookmarks.html files with a quick search [2]. Perhaps you will find
something there that is helpful.

[1]:
http://www.physic.ut.ee/~kkannike/english/prog/python/util/bookmarks/code/bookmarks.py
[2]: http://www.google.com/search?q=firefox+bookmarks.html+python

Waylan

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


Re: Method resolution for super(Class, obj).

2006-09-07 Thread Jason

ddtl wrote:
 Hello everybody.

 Consider the following code:


 class A(object):
 def met(self):
 print 'A.met'
 class B(A):
 def met(self):
 print 'B.met'
 super(B,self).met()
 class C(A):
 def met(self):
 print 'C.met'
 super(C,self).met()
 class D(B,C):
 def met(self):
 print 'D.met'
 super(D,self).met()
 d = D()
 d.met()


 When executed, it prints:

 D.met
 B.met
 C.met
 A.met

 The book (Python in a nutshell, 2nd edition) explains:

 The solution is to use built-in type super. super(aclass, obj),
 which returns a special superobject of object obj. When we look
 up an attribute (e.g., a method) in this superobject, the lookup
 begins after class aclass in obj's MRO.

 But I don't understand - MRO means that when attribute is found
 somewhere in hierarchy, the search for it stops, that is: when
 d.met() is executed, it is supposed to print 'D met', call
 super(D,self).met() which should resolve met() to be B's attribute,
 and after B's met() is executed, we should be done. Why does the
 lookup proceeds from B to C as though met() wasn't found in B?
 Indeed, lookup order (according to a new-style MRO) is B, then C
 and at last A (because of a diamond inheritance), but only when
 attribute is not found in B it is looked up in C, and only if it
 is not found neither in B nor in C it is looked up in A...

 What is different here?

Let's examine what the mro order is for class D:
 D.mro()
[class '__main__.D', class '__main__.B', class '__main__.C',
class '__mai
n__.A', type 'object']

When you call d.met(), the call dispatches to the D.met() method.
After printing out 'D.met', you use super() to get the next class in
the mro order, and call that class's met method.

As shown with the mro(), the class after D is B.  So B.met() is called.
 Normally, we would be done.  But take a look at B's method!

 class B(A):
 def met(self):
 print 'B.met'
 super(B,self).met()

B.met calls super, and invokes the next met method!  So, the code does
exactly what you've asked it to do, and searches for the next class
after B in the mro list: class C.  You are then invoking met method of
that class.  So, class B is calling class C's met method.

Class C also uses super, and calls the resulting met method on the
result as well.  This finds class A as the next class in the mro list,
and invokes the met method on it as well.

When you get to A's met method, you aren't calling another met method,
so the print statements end.

If you want the dispatch to end at B's method, comment out the
'super(B,self).met()' line:
 class B2(A):
... def met(self):
... print 'B2.met'

Alternatively, you could do away with using super entirely, and
actively call the superclass method that you want:
 class D2(B2, C):
... def met(self):
... print 'D2.met'
... B2.met(self)  # Invoke B2's method directly
...
 d2 = D2()
 d2.met()
D2.met
B2.met

You don't need super() to call a superclass method.  It can help with
complex class heirarchies, but most single-descendent class structures
don't need it.  Either way, when designing a class heirarchy, you
should either always use super() or never use super().  Mixing
non-super-using and super-using can give you problems.

(Rhetorical Q: Does this make me more or less super?)

--Jason

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


Automate Web Configuration

2006-09-07 Thread D
I would like to write a program that will automate the configuation of
a firewall or router via HTTPS.  So, I need to import the applicable
certificate, and be able to configure the unit as if I was
typing/selecting the appropriate fields manually using a web browser.
If there is a command-line based tool that would allow me to do this, I
would be more than willing to give it a try.  Otherwise, is there a
Python library that would do the same?  Thanks.

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


Re: Method resolution for super(Class, obj).

2006-09-07 Thread ddtl
On 7 Sep 2006 10:42:54 -0700, in comp.lang.python you wrote:

Let's examine what the mro order is for class D:
 D.mro()
[class '__main__.D', class '__main__.B', class '__main__.C',
class '__mai
n__.A', type 'object']

When you call d.met(), the call dispatches to the D.met() method.
After printing out 'D.met', you use super() to get the next class in
the mro order, and call that class's met method.

As shown with the mro(), the class after D is B.  So B.met() is called.
 Normally, we would be done.  But take a look at B's method!

 class B(A):
 def met(self):
 print 'B.met'
 super(B,self).met()

B.met calls super, and invokes the next met method!  So, the code does
exactly what you've asked it to do, and searches for the next class
after B in the mro list: class C.

But when super(B,self).met() is invoked, isn't it supposed to look
at MRO order of *B*, which is:

(class '__main__.B', class '__main__.A', type 'object')

and B doesn't have any relation with C, that is: A's met() is the to
be called as a result. In effect, what you say impies that a call to
super() is context dependant - if super(B,self).met() is invoked as
a result of a call to D().met(), the effect is different from the effect 
of a call to B().met(). But a documentation of a super() doesn't mention
anything like that (or at least I didn't find it), and it seems a 
significant piece of information. Doesn't it imply that there should 
be another explanation?

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


  1   2   3   >