Reputation: 506
What are the possible reasons for a different interpretation of a given python code?
I have a code which I can execute with no errors on a computer, but which outputs errors on another one. The python versions are the same (2.7.12). The encoding of the scripts are the same. I wonder what could explain this because these are the only two reasons I see for a different code interpretation.
Here is what the code looks like, using luigi (here is only a part of the code) :
class ExampleClass(luigi.postgres.CopyToTable):
def rows(self):
"""
Return/yield tuples or lists corresponding to each row to be inserted.
"""
with self.input()['Data'].open('r') as fobj:
for line in fobj:
yield line.strip('\n').split('\t')
When I run the whole code on the computer where i do have an error (which is caused by the lines I wrote above), I get this :
IndentationError: unexpected indent
And there is, indeed, a mix of spaces and tabs in the code. It is easy to solve, no problem here, but my question is about : What could explain that difference in the interpretation?
Upvotes: -1
Views: 150
Reputation: 309
As the error says
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: malformed \N character escape
The line in question is this one:
cursor.copy_expert('copy ' + self.table + ' from stdin with header csv delimiter \'' + self.column_separator + '\' null \'''\\N''\' quote \'''\"''\' ', file)
Your "N" should be lowercase otherwise it doesn't count as a newline character. Try this:
cursor.copy_expert('copy ' + self.table + ' from stdin with header csv delimiter \'' + self.column_separator + '\' null \'''\\\n''\' quote \'''\"''\' ', file)
Upvotes: -1