Download ascii to hex python 3 for windows 7 64bit

Convert string to hex (Python recipe) by Mykola Kharechko

Qoute string converting each char to hex repr and back

7 comments

list comprehensions. Though your snippet is nice, you should really have a look at least comprehensions. With a few built-in methods you can reduce your 8 lines of code (which is pretty slow because of the "extra work" I guess) to one:

The builtin string-method "join" joins every element of the list to the string by re-using the string. ";;".join(['a', 'b', 'c']) would result in 'a;;b;;c'. Note that you can enhance the speed of the above snippet by replacing the [] with () what will change it from a list comprehension to a generator. Same enhancements can be done with your second function.

encode and decode. this functionality already exists with the encodings library (which is built-in):

base 16 int conversion. The hex() and int() builtins should do everything you need.

Nevermind, I should've read the original post more closely. As the other commenter said, str.encode() and str.decode() do the same thing as your code.

atoi() is deprecated. you should use int() instead

Even though modern Python implementations have .encode and .decode, old versions (pre v2) don't.

My current Python platform (Telit GC864) runs on v1.5.2, with absolutely no option to upgrade.

On Python 3.x, this is depricated. The hex codec has been removed because it made absolutely no sense (thanks to Lennart Regebro on Stack Overflow). (You are not changed the codec of an 8-bit string, you are rather converting it, so using a "hex" codec is weird to say the least). Rather, the proper way to do this is:

Required Modules

  • (none specified)

Other Information and Tasks

  • Licensed under the PSF License
  • Viewed 341376 times
  • Revision 1

Code Recipes

Feedback & Information

ActiveState

© 2017 ActiveState Software Inc. All rights reserved. ActiveState®, Komodo®, ActiveState Perl Dev Kit®, ActiveState Tcl Dev Kit®, ActivePerl®, ActivePython®, and ActiveTcl® are registered trademarks of ActiveState. All other marks are property of their respective owners.