Site Sponsors:
ASCII Strings in Python 3 
Since Python decided to convert to Unicode, the default string encoding is no longer ASCII.

In as much as the vast majority of the world is still working with ASCII text however, lots of people are being frustrated.

In an effort to stem the frustration, allow me to share an example. Written in Python3, feel free to use this little ditty to inspire-power your own (whatever) to ASCII filtering & conversions:


def mk_printable(str_data):
result = bytearray(str_data, "utf-8")
for ss, code in enumerate(result):
if code < 32:
result[ss] = 0x20
continue
if code > 126:
result[ss] = 0x20
continue
return str(result, "utf-8")


In addition to converting a "whatever" string to UTF-8, note that the above routine will also map non-ascii encodings to an ASCII 'SPACE' character (0x20 in the above.)

We also leave the final conversion to UTF8 to Python's str() built-in function.


Enjoy the journey!

-Rn



[ add comment ] ( 182 views )   |  permalink
Staples Asks: "Do you have a surprising tip for improving productivity?" 
I wish I was the first one to note it, but it was Thomas Monson who brought the idea that "when performance is measured, performance improves" into my bailiwick.

Yet to force people to be more obsessed with recording what they do is one very sure way to demoralize & intimidate just about everyone!

But to answer the question of how to improve productivity, on a PERSONAL level I have discovered that privately micro-blogging about what I do every day is the best way to ensure that I am always productive. Over time, voluntarily choosing to record what I do not only encourages me to do many more things, but in the technical world using tools like the "About Time" software allows me to diagnose though technical problems, as well as to generate the related reporting.

You can read more about "About Time" on the download page.

[ add comment ] ( 252 views )   |  permalink  |  related link

<<First <Back | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | Next> Last>>