OpenersPrimaryExamplesSection(Spacer1)Examples  (6)

OpenersExampleSection0(Spacer1)Basic Examples  (6)

Import a simple string:

ImportString["'hello world'","PythonExpression"]

Import a list:

ImportString["[1,'h',True,None,1.2]","PythonExpression"]

Export to a string:

ExportString[Range[10],"PythonExpression"]

Import a dictionary as a Wolfram Language list:

ImportString["{'a':1,'b':2}","PythonExpression"]

Export an (RefLink[Association, paclet:ref/Association]) as a Python dictionary:

ExportString[<|"a"->1,"b"->2|>,"PythonExpression"]

Import the result of evaluating external code in Python:

ImportString[ExternalEvaluate["Python"->"String","'hello world'"],"PythonExpression"]

Confirm it is the same as using the "ReturnType" of (StringTypeLink["Expression", paclet:ref/interpreter/Expression]):

%==ExternalEvaluate["Python"->"Expression","'hello world'"]

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Importing & Exporting, paclet:guide/ImportingAndExporting])}})}})