December 4th, 2004, 05:39 PM
A Few Visual Basic to Python Questions
I just had a few Visual Basic to Python questions that I really need help with. Heres a small list:
Left() and Right()
The last thing I need help with is converting the following line of code to Python from VIsual Basic.
CopyMemory ByVal Result, Value, 2
I have no clue whatsoever how to get Python to do something like that line. Whatever you can help me with, just show me what to do. Thanks.
December 4th, 2004, 05:45 PM
Dude, I dunno VB, but I see those are character and string methods, so browse online docs for those modules...
Am I supposed to sign here?
December 4th, 2004, 06:36 PM
>>> b = g.lower()
>>> print b
this is built-in in python
i am pretty sure it's exactly the same in python as vb.
as for your CopyMemory question...i don't remember ever using that function in vb, but if i find anything on it ill post back.
if you haven't already been here, it's a nice source of python info.: http://diveintopython.org/toc/index.html
Last edited by jacktasia; December 4th, 2004 at 06:49 PM.
December 4th, 2004, 07:00 PM
Ok, thanks so much for the help jacktasia, I'll try them out in a minute. As for CopyMemory, I myself don't know how often it gets used, but I do know that all Visual Basic and C++ programemrs use it in their PacketBuffers for sending Packets to Battle.net (I'm only assuming you know what battle.net is).
December 5th, 2004, 05:20 AM
CopyMemory in VB is used to move blocks of data around, similar to C's memcpy function.
There is no equivalent in Python, since it is not normally used for manipulating memory directly.
There are other ways of achieving the same effect, for example using the array module to create your memory buffers and using indexing and slicing to copy bytes around.
Notice that this is slightly different from the CopyMemory function - the characters on the end of 'a' are moved up by the operation instead of overwritten.
>>> import array
>>> a = array.array('c', 'hello world')
>>> b = array.array('c', 'goodbye cruel')
>>> a[0:5] = b
array('c', 'goodbye cruel world')
There are other ways of achieving the same thing - you could create your data in strings and use the struct module to convert it to something that could be passed to a C function. There is also the xdrlib module, but I have never used that.
Dave - The Developers' Coach