![]() You don’t have to unpack complicated map() expressions to read it. There’s a single logical operation per line of code. Something like this seems more natural to me: components = You should also split your code into intermediate steps – it makes it easier to disentangle and debug the individual parts. They’re much more Pythonic, and generally much easier to read. ![]() (I’m not confident I’ve got this right, but it’s much easier to check when the parts are named and referenced than before.) Now it’s much easier to check whether the implementation matches the spec. ![]() # we need to reverse the stream returned by unhexlify().īinascii.hexlify, (data1, data2, data3, data4a, data4b)))) Working from Microsoft’s specification, I think I was able to work out what all the slices were, and then I put them in named variables: # The Microsoft GUID format has four named fields. In hex_to_guid, you’re packing too much into that final line, and it’s not obvious what any of the components mean. If you ever look back over this code, it’ll be easier if you have this reference alongside the function. ![]() """Convert a hex string to a Microsoft GUID""" Something as simple as: def hex_to_guid(hex): The single English sentence in your questions is a big help to understanding the purpose of these functions, and where I might find more information, but it’s not attached to the code. This could definitely be easier to follow. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |