|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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:
LCase() Mid() Left() and Right() Chr() 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. |
|
#2
|
||||
|
||||
|
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?
|
|
#3
|
|||
|
|||
|
LCase()
Code:
>>> g="ABC" >>> b = g.lower() >>> print b abc http://www.python.org/doc/current/l...ng-methods.html Mid(),Left(),Right() this is built-in in python Code:
>>> k="ABCDEFG" >>> k[0:3] 'ABC' >>> k[2:5] 'CDE' >>> k[-4:-1] 'DEF' chr() i am pretty sure it's exactly the same in python as vb. Code:
>>> chr(65) 'A' 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. <edit> if you haven't already been here, it's a nice source of python info.: http://diveintopython.org/toc/index.html </edit>
__________________
Jack --------- use code tags become vegetarian python? yes, sir! unarm.org get firefox If I helped you then please click the " " in the upper right-hand corner of my post.
Last edited by jacktasia : December 4th, 2004 at 07:49 PM. |
|
#4
|
||||
|
||||
|
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).
|
|
#5
|
|||
|
|||
|
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. e.g. Code:
>>> import array
>>> a = array.array('c', 'hello world')
>>> b = array.array('c', 'goodbye cruel')
>>> a[0:5] = b
>>> a
array('c', 'goodbye cruel world')
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. 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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > A Few Visual Basic to Python Questions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|