Mark Lawrence <breamore...@yahoo.co.uk> added the comment:

Please ensure tha I'm taken off of the email list as I've been banned from 
contributing to Python by Raymond Hettinger

________________________________
From: Amaury Forgeot d'Arc <rep...@bugs.python.org>
To: breamore...@yahoo.co.uk
Sent: Tue, 21 September, 2010 18:56:51
Subject: [issue1962] ctypes feature request: Automatic type conversion of input 
arguments to C functions

Amaury Forgeot d'Arc <amaur...@gmail.com> added the comment:

I don't think this should happen by default.
but what the user wants is already possible, by using the from_param() method.  
For example, the AutoStrParam type converts everything to a string (and a 
char*):

from ctypes import *

class AutoStrParam(c_char_p):
    @classmethod
    def from_param(cls, value):
        return str(value)

strlen = cdll.LoadLibrary('msvcrt').strlen
strlen.argtypes = [AutoStrParam]

print strlen(None)     # "None"          ->  4
print strlen(type)     # "<type 'type'>" -> 13

----------
nosy: +amaury.forgeotdarc

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue1962>
_______________________________________

----------
Added file: http://bugs.python.org/file18958/unnamed

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue1962>
_______________________________________
<html><head><style type="text/css"><!-- DIV {margin:0px;} 
--></style></head><body><div style="font-family:times new roman,new 
york,times,serif;font-size:12pt"><div>Please ensure tha I'm taken off of the 
email list as I've been banned from contributing to Python by Raymond 
Hettinger<br></div><div style="font-family: times new roman,new 
york,times,serif; font-size: 12pt;"><br><div style="font-family: 
arial,helvetica,sans-serif; font-size: 13px;"><font face="Tahoma" size="2"><hr 
size="1"><b><span style="font-weight: bold;">From:</span></b> Amaury Forgeot 
d'Arc &lt;rep...@bugs.python.org&gt;<br><b><span style="font-weight: 
bold;">To:</span></b> breamore...@yahoo.co.uk<br><b><span style="font-weight: 
bold;">Sent:</span></b> Tue, 21 September, 2010 18:56:51<br><b><span 
style="font-weight: bold;">Subject:</span></b> [issue1962] ctypes feature 
request: Automatic type conversion of input arguments to C 
functions<br></font><br><br>Amaury Forgeot d'Arc &lt;<a
 ymailto="mailto:amaur...@gmail.com"; 
href="mailto:amaur...@gmail.com";>amaur...@gmail.com</a>&gt; added the 
comment:<br><br>I don't think this should happen by default.<br>but what the 
user wants is already possible, by using the from_param() method.&nbsp; For 
example, the AutoStrParam type converts everything to a string (and a 
char*):<br><br>from ctypes import *<br><br>class 
AutoStrParam(c_char_p):<br>&nbsp; &nbsp; @classmethod<br>&nbsp; &nbsp; def 
from_param(cls, value):<br>&nbsp; &nbsp; &nbsp; &nbsp; return 
str(value)<br><br>strlen = cdll.LoadLibrary('msvcrt').strlen<br>strlen.argtypes 
= [AutoStrParam]<br><br>print strlen(None)&nbsp; &nbsp;  # "None"&nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; -&gt;&nbsp; 4<br>print strlen(type)&nbsp; &nbsp;  # 
"&lt;type 'type'&gt;" -&gt; 13<br><br>----------<br>nosy: 
+amaury.forgeotdarc<br><br>_______________________________________<br>Python 
tracker &lt;<a ymailto="mailto:rep...@bugs.python.org";
 href="mailto:rep...@bugs.python.org";>rep...@bugs.python.org</a>&gt;<br>&lt;<a 
href="http://bugs.python.org/issue1962"; 
target="_blank">http://bugs.python.org/issue1962</a>&gt;<br>_______________________________________<br></div></div>
</div><br>



      </body></html>
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to