Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 4th, 2004, 06:39 PM
Yegg`'s Avatar
Yegg` Yegg` is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Dec 2004
Location: Meriden, Connecticut
Posts: 1,731 Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Weeks 6 Days 4 h 5 m 27 sec
Reputation Power: 83
Send a message via AIM to Yegg`
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.

Reply With Quote
  #2  
Old December 4th, 2004, 06:45 PM
Boki's Avatar
Boki Boki is offline
A wanna-be guru of some sort
Dev Shed Novice (500 - 999 posts)
 
Join Date: Sep 2004
Location: Either online or offline
Posts: 624 Boki User rank is Sergeant (500 - 2000 Reputation Level)Boki User rank is Sergeant (500 - 2000 Reputation Level)Boki User rank is Sergeant (500 - 2000 Reputation Level)Boki User rank is Sergeant (500 - 2000 Reputation Level)Boki User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 4 h 7 m 13 sec
Reputation Power: 14
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?

Reply With Quote
  #3  
Old December 4th, 2004, 07:36 PM
jacktasia jacktasia is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2004
Location: Lawrence, Kansas [KU]
Posts: 1,559 jacktasia User rank is Corporal (100 - 500 Reputation Level)jacktasia User rank is Corporal (100 - 500 Reputation Level)jacktasia User rank is Corporal (100 - 500 Reputation Level)jacktasia User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 14 h 4 m 35 sec
Reputation Power: 9
Send a message via AIM to jacktasia
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.

Reply With Quote
  #4  
Old December 4th, 2004, 08:00 PM
Yegg`'s Avatar
Yegg` Yegg` is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Dec 2004
Location: Meriden, Connecticut
Posts: 1,731 Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Weeks 6 Days 4 h 5 m 27 sec
Reputation Power: 83
Send a message via AIM to Yegg`
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).

Reply With Quote
  #5  
Old December 5th, 2004, 06:20 AM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,254 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 8 h 9 m
Reputation Power: 265
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > A Few Visual Basic to Python Questions


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT