Yet another noob query here. Quotes like "never write the same code twice" have me trying to ferret out my mistakes; here's one I want to improve: code in main file:
if os.name == 'nt':
dosomething
another way:
if os.name == 'nt':
os_is_nt = True
if os_is_nt:
dosomething
another way, putting this function in an import
detectNT()
if os.name == 'nt':
return True
else:
return False
My belief is, without figuring out how to check any speed differences, is that I should cut it back to the original:
if os.name == 'nt':
dosomething
but my faith is weak, which is why I'm here.
Also, I'm thinking there's a way to find the local file separator..? I've written this:
def os_file_sep():
file_separator = "/"
if os.name == 'nt':
file_separator = "\\"
return file_separator
os moduleprobably does what you need already.os.pathmodule should take care of that for you with its methods likejoinos.path.sepandos.separe path separatorsjoinwas not workable. I see how I can do it now using theos.path.sep