Site Sponsors:
German Notation & Problematic File Names 
For years I have been popularizing the idea of using "German Notation." Formerly known as "Nazi Notation," far from conjuring-up the image of unpleasantness, I use the term whimsically; When one hears it, my hope is that we think more of "Sergent Schultz" (I know nothing!:) or "Colonel Klink" - rather than Adolph Hitler?

Ironically, in as much as standards like PEP-8 remind many software developers of the more dark-size of what being a "Nazi" was all about, the idea is that there can be far better ways to name things like variables and member functions?

Indeed, rather than blindly following the edicts of any dictator - benevolent or not - when using such a typeless language as Python, perhaps one might like to use Hungarian Notation? --Surely prefixing simple characters like a lower-case 's' for string, 'i' for integer ... or merely dropping vowels & double consonants ... can create far more succinctly-informative mnemonics?

Oh well - rather than memorize any type of rigidly defined view over how people should all be writing code the same way, by way of introducing a nice way to use keywords and built-ins as variable names, note our scattering of a simple "z" prefix around in the following code:

import os

count = 0
zRoot = "/"
print("Parsing", zRoot)
for zPath, zDirs, zFiles in os.walk(zRoot):
for zFile in zFiles:
file = os.path.join(zPath, zFile)
nodes = os.path.split(file)
for node in nodes:
if is_good_node_name(node) is False:
count += 1

print("Found", count, "potential problems.")

Honoring the freedom to do what - IMHO - makes for a far better single-word mnemonic experience, allow me to complete the above example by presenting the balance of the code:

bad_chars = bytearray(":?*<>|\\/\"", "utf8")

def is_clascii(str_data):
for ss, ch in enumerate(str_data):
code = ord(ch)
if code < 32:
return False
if code > 126:
return False
return True

def is_good_node_name(str_data):
global bad_chars
str_data2 = bytearray(str_data, "utf8")
for ss, ch in enumerate(str_data2):
for ref in bad_chars:
if ref == ch:
return False
return is_clascii(str_data)

Designed to rummage around zRoot so as to find zFile that might create a problem for your cross-platform file-transferal activities (Linux? Windows? OS/X? AIX?,) my hope is that you will find the above Ptyhon3 example to be of use in planning escape attempts for our comrades in-arms in a 'Stalag near you!

Enjoy the Journey.


[ view entry ] ( 367 views )   |  permalink  |  related link
Cloud, Client, & Browser Concepts 
For those who are entering the software and / or software testing world, here is an excerpt from our new "Testing Success" training offering.

I have been informed that there are even some new ideas for experienced software developers / testers, as well ... :)



[ view entry ] ( 427 views )   |  permalink  |  related link
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
if code > 126:
result[ss] = 0x20
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!


[ view entry ] ( 514 views )   |  permalink

<<First <Back | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | Next> Last>>