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 <rep...@bugs.python.org><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 <<a
ymailto="mailto:amaur...@gmail.com"
href="mailto:amaur...@gmail.com">amaur...@gmail.com</a>> 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. 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> @classmethod<br> def
from_param(cls, value):<br> return
str(value)<br><br>strlen = cdll.LoadLibrary('msvcrt').strlen<br>strlen.argtypes
= [AutoStrParam]<br><br>print strlen(None) # "None"
-> 4<br>print strlen(type) #
"<type 'type'>" -> 13<br><br>----------<br>nosy:
+amaury.forgeotdarc<br><br>_______________________________________<br>Python
tracker <<a ymailto="mailto:rep...@bugs.python.org"
href="mailto:rep...@bugs.python.org">rep...@bugs.python.org</a>><br><<a
href="http://bugs.python.org/issue1962"
target="_blank">http://bugs.python.org/issue1962</a>><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