|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Select Case to While
Tell me if this code will work. The following code is in Visual Basic, the code I need to know if it will work is the second code.
Code:
Select Case GetWORD(Mid(Data, 5, 2))
Case &H0
stuff..........
stuff..........
stuff..........
Code:
while GetWORD(data[5:2]):
while GetWORD(data[5:2]) == 0x00:
stuff......
stuff......
Now I'm not sure if this code will work, I need some help with it. I also have one mroe very quick question. Will msg[5:5] work? |
|
#2
|
||||
|
||||
|
Guessing that data is just a stream of characters then something like this perhaps is the python equivalent of your case structure:
Code:
word = data[5:7] #get a slice of 2 characters (at position 5 and 6 in the string)
if word == 'ab':
#do ab stuff
elif word == 'cb':
#do cb stuff
elif word == 'zh':
# do ...
else:
# do whatever
even if data was actaully read from a file of binary data it will still be treated as a big string of 8-bit characters on which you can apply slicing. You can always use the interactive shell to test things like msg[5:5] It works but produces nothing useful - the second index is the same as the first so the slice is zero length grim ![]()
__________________
*** Experimental Python Markup CGI V2 *** |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Select Case to While |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|