ninia / jep

Embed Python in Java
Other
1.3k stars 147 forks source link

Getting IndentationError on with statement #443

Closed pdutta777 closed 1 year ago

pdutta777 commented 1 year ago

I am trying to write an indented "with" statement, and getting this error: Exception in thread "main" jep.JepException: <class 'IndentationError'>: ('expected an indented block', ('<string>', 1, 54, "with pa.OSFile('/tmp/sparkless.arrow', 'wb') as sink:\n"))

The code block is:

pyjep.exec("with pa.OSFile('/tmp/dummy.arrow', 'wb') as sink:")
pyjep.exec("  with pa.ipc.new_file(sink, df.tbl.schema) as writer:")
pyjep.exec("    for batch in df.tbl.to_batches():")
pyjep.exec("      writer.write(batch)")

Is there another way to do this? This is with jep 4.1.0

bsteffensmeier commented 1 year ago

You will need to pass the entire statement into the exec at the same time, like this:

pyjep.exec("with pa.OSFile('/tmp/dummy.arrow', 'wb') as sink:\n" +
           "  with pa.ipc.new_file(sink, df.tbl.schema) as writer:\n" +
           "    for batch in df.tbl.to_batches():\n" +
           "      writer.write(batch)\n")
pdutta777 commented 1 year ago

Thank you. This is working