I\'m writing a small method to replace some text in a file. The only argument I need is the new text, as it is always the same file and text to be replaced.
I\'m hav
So from previous answers we now know that id is a Unicode string, which makes cmd1 a Unicode string, which os.system() is converting to a byte string for execution in the default encoding.
a) I suggest using subprocess rather than os.system()
b) I suggest not using the name of a built-in function as a variable (id).
c) I suggest explicitly encoding the string to a byte string before executing:
if isinstance(cmd,unicode):
cmd = cmd.encode("UTF-8")
d) For Lennart Regebro's suggestion add:
assert type(cmd1) == type(cmd2)
after
print cmd1 == cmd2