Question: I'm trying to learn how to use the lambda function to resolve conflicts when inserting into a table with `rethinkdb` and `python`, like the last example on this [page](https://rethinkdb.com/api/python/insert/). I would like to compare a `timestamp` field between the `old_doc` and `new_doc` and keep the more recent document. 

```
r.table(import_table).insert(documents, conflict=lambda id, old_doc, new_doc: new_doc if new_doc['timestamp'] > old_doc['timestamp'] else old_doc).run()```

```

This gives the following error 

> 
> rethinkdb.errors.ReqlQueryLogicError: Expected type DATUM but found
>  FUNCTION
> 
> 
> 

I can't find much documentation on this error or using lambda functions for conflict resolution. Running something simpler like:

```
r.table(import_table).insert(documents, conflict=lambda id, old_doc, new_doc: new_doc).run()

```

gives the same error which makes me think that I'm not writing this correctly. Any help would be appreciated.

Answer: 
Try placing the full (absolute) path to your file in the `open()` statement:

```
fin = open("/full/working/path/to/the/file/input.txt","r") #(try C:/full/working/[...] for windows builds)

#continue code...

```

When using `open()`, python assumes the current working directory. Depending on what IDE your are using and how you are executing the file, this can produce unexpected results. If you're using notepad++ (which from the comments, it looks like you are), python might be opening the file in the program directory of notepad++, rather than in the directory that your .py file is located. Absolute paths fix this by forcing python to look in a very specific directory. I don't have notepad++ installed, but I have encountered this problem before on other low-powered IDEs.
You're calling readlines at every iteration, break that out of the for loop.

```
lines = file.readlines()
for line in lines:

```