« first day (927 days earlier)   

7:44 AM
Hello @JohnRennie sir :-)
Are you free?
 
I'm answering a question at the moment.
 
Okay sir
 
If you want to post your question I'll look at it as soon as I'm free.
 
I want to do this in python. I have received a bytestream which I have stored in dvu using memory view dvu = memoryview(message). Now starting at a particular index, I want to read a 32 bit integer as in JS is done below:
dvu.getInt32(depthPosition, true)
Can't figure out how to do this
Not able to access the python chat room also due to less reputation :-(
 
Hi :-)
Are you trying to pass data from Javascript to Python?
 
7:58 AM
No sir, trying to replicate that JS code in python
 
Ah, OK. Where is the data coming from? i.e. how is your Python program getting the data?
 
From a websocket
dvu = memoryview(message)
message comes from the websocket.
I now want to read a 32 bit integer starting from index 1, means dvu[1:5]
 
8:15 AM
@JohnRennie No sir, giving 0 for any input.
I need functions for even reading 8/16-bit integers and floats starting at a particular index.
 
I'd have to see code to comment. This isn't something I've done in Python.
 
Yes sir, sending, will take a few minutes.
message = b'?\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x003s}D\xa8\x16fSZ\xa3\x07\x00\x01?\x16\x00\x00\x00\x9a\xa9~D\x9f5\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00f\xb6\x81D3s}D\x00\x00\x82D\x00\x00yD\xd7\xa3\xb0\xbf3fb\xc133\x85D\x00 \xeeC\x00
 
8:35 AM
Can you post a Python program that I can run to see what happens? I can't run the code about because I don't know what modules are needed.
 
Yes sir, you can run the above code after saving as python file.
All modules are inbuilt.
 
message = b'?\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x003s}D\xa8\x16fSZ\xa3\x07\x00\x01?\x16\x00\x00\x00\x9a\xa9~D\x9f5\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00f\xb6\x81D3s}D\x00\x00\x82D\x00\x00yD\xd7\xa3\xb0\xbf3fb\xc133\x85D\x00 \xeeC\x00
 
Yes sir, 63 is the correct output
means dvu.getint8 is same as data[0]
 
I don't know anything about memoryview in Python. I can try and Google it, but that will tale time and I'll have to do that later.
 
Sir is there any way I can post in the python chat room? I have to somehow do this before 3:30.
 
8:45 AM
Do you have any questions or answers I can upvote?
 
Yes sir, I have one question but would it be ok to do so?
 
No-one is going to care :-)
But I can only upvote you one question i.e. add +10 to your rep. Will that be enough? I can't remember what rep you need to post in the chat.
 
1
Q: NodeJS Response to Client Side Request - HTTP

LearnerI have created a HTTP server in NodeJS using the http.createServer(...) function. From a client side JavaScript file, I have sent a query using the POST method on the localhost url. The server has successfully received the data from the client but now I am unable to send a response for e.g, a mes...

 
Actually if you can post here I don't understand why you can't post in the Python chat ...
Ah, I had already upvoted that ...
 
@JohnRennie Yes sir, one would be ok. Stack overflow rating is 11 and here it is >20
@JohnRennie Possible on the answer?
 
8:54 AM
@Learner Done!
 
Thank you very much sir :-) 🙏🙏
 
Can you do this?
D:\rhs\Python>python
Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> message = b'?\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0
@Learner Would that work for you?
@Learner This:
>>> a = 12345678
>>> b = a.to_bytes(a, "little")
>>> c = memoryview(b)
>>> c[0] + (c[1]<<8) + (c[2]<<16) + (c[3]<<24)
12345678
 
9:25 AM
@JohnRennie Trying sir, just a minute
@JohnRennie It's working sir! :-)
Trying for others as well
And what if we want getFloat32?
 
97
Q: Convert Bytes to Floating Point Numbers?

CristianI have a binary file that I have to parse and I'm using Python. Is there a way to take 4 bytes and convert it to a single precision floating point number?

 
print(struct.unpack('f', bytes(data[position:position+4])))
Can't thank you enough sir :-) 🙏
It's working
 
OK :-)
That probably works for int as well.
 
Yes sir, trying
Working sir :-)
`print(struct.unpack('i', bytes(data[position+5:position+9])))`
Just had to use bytes() while unpacking
 
9:41 AM
I think the struct module is the official way to do this sort of thing.
 
Yes sir
Any progress on the permutation question sir :-) ?
 
I won't be looking at the permutation question. It seems like it will take a lot of time and right now I'm pretty busy.
 
Ah no sir, just asking, I'll take a look at the solution now :-) It's already taken up a lot of time
Bye sir :-) Thank you very much 🙏
 
Bye :-)
 

« first day (927 days earlier)