Skip to content

Instantly share code, notes, and snippets.

Last active August 23, 2023 20:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Custom extractor for PyCharm - copy tables to a list of dicts
import static com.intellij.openapi.util.text.StringUtil.escapeStringCharacters as escapeStr
QUOTE = "\""
NEWLINE = System.getProperty("line.separator")
def record(columns, dataRow) {
OUT.append(" {").append(NEWLINE)
columns.eachWithIndex { column, idx ->
def skipQuote = dataRow.value(column).toString().isNumber() || dataRow.value(column) == null
def stringValue = dataRow.value(column) == null ? "None" : FORMATTER.format(dataRow, column)
OUT.append(" ")
.append(": ")
.append(skipQuote ? "": QUOTE).append(escapeStr(stringValue)).append(skipQuote ? "": QUOTE)
OUT.append(" },").append(NEWLINE)
OUT.append("data = [").append(NEWLINE)
ROWS.each { row -> record(COLUMNS, row) }
Copy link

Docs for 'installing' this extractor:

You can then copy a table (left) and paste it as valid Python (right):

Copied from with handling for None and quotes added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment