My Python-containing ado programs that ran before now give an r(7102); error: IndentationError: expected an indented block . . .. I wrote them last year in Release 17.0, but I thought that I'd used them as recently as earlier this summer (i.e., in the current release) without any trouble. When I went to use one today I discovered this new (mis)behavior.
I can get simple function definitions to run by using a reverse solidus and semicolon fix-up as shown in this post from April this year. For example, this
gives the error, but this
runs without error.
Unfortunately, slightly more complicated code, such as
still gives an error (although a different one) even with the reverse solidus-semicolon workaround. (That code snippet works as expected in my Python environment. Excuse the unusual choice of names—it's a test harness for another function that will call search() to access a search engine API.)
I've attached three files, indent_bug.ado, indent_bugbreaks.ado and test.py,* whiich I called in sequence from the command line
Only the first ado file shows the error. The resulting output is in the log file indent_bug.smcl, which is also attached.
Is anyone else experiencing this or is it something peculiar to my setup? Or am I misunderstanding something? I've Googled python indentation stata but haven't turned up much on the topic, excepting that thread linked to above.
* test.py contains the same code as in the auxiliary Python section of indent_bug.ado (shown in the first code block above). I've had to append a .txt extension to test.py in order to circumvent the forum's limitations on attachments' file-name extensions. To run the relevant line in the code just above, remove the second file name suffix (rename test.py.txt → test.py after downloading).
I can get simple function definitions to run by using a reverse solidus and semicolon fix-up as shown in this post from April this year. For example, this
Code:
*! indent_bug.ado program define indent_bug version 18.0 syntax python: test() end version 18.0 python: def test(): print("Here.") print(". . . and Here.") end
Code:
*! indent_bugbreaks.ado program define indent_bugbreaks version 18.0 syntax python: test() end version 18.0 python: def test(): \ print("Here."); \ print(". . . and Here.") end
Unfortunately, slightly more complicated code, such as
Code:
import json def search(keyword): with open("F:/" + keyword + ".json", "r") as f: response = json.load(f) return(response)
I've attached three files, indent_bug.ado, indent_bugbreaks.ado and test.py,* whiich I called in sequence from the command line
Code:
indent_bug indent_bugbreaks python script test.py, global python: test()
Is anyone else experiencing this or is it something peculiar to my setup? Or am I misunderstanding something? I've Googled python indentation stata but haven't turned up much on the topic, excepting that thread linked to above.
* test.py contains the same code as in the auxiliary Python section of indent_bug.ado (shown in the first code block above). I've had to append a .txt extension to test.py in order to circumvent the forum's limitations on attachments' file-name extensions. To run the relevant line in the code just above, remove the second file name suffix (rename test.py.txt → test.py after downloading).
Comment