<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Sharing variables between languages in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Sharing-variables-between-languages/m-p/4105639#M3655</link>
    <description>&lt;P&gt;I have no experience with, and have not heard about, using %%javascript before.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Perhaps you could use a Lakehouse file to read/write from?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When switching between spark.sql() (PySpark) and %%sql (SparkSQL) cells I have been able to use temporary views.&lt;/P&gt;</description>
    <pubDate>Sun, 18 Aug 2024 12:29:21 GMT</pubDate>
    <dc:creator>frithjof_v</dc:creator>
    <dc:date>2024-08-18T12:29:21Z</dc:date>
    <item>
      <title>Sharing variables between languages</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Sharing-variables-between-languages/m-p/4105398#M3651</link>
      <description>&lt;P&gt;Does anyone know how can I pass on a python variable to a js execution from one cell to another.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;E.g.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="smpa01_0-1723922595774.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1152634iE7AC64A9AED5DFAE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="smpa01_0-1723922595774.png" alt="smpa01_0-1723922595774.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, how can I pass on the the result of js execution to a succeeding python cell. I don't mind if I need to convert it to a string before sharing from cell to cell. I can always convert back a string to float pre process if I need to.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2024 21:47:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Sharing-variables-between-languages/m-p/4105398#M3651</guid>
      <dc:creator>smpa01</dc:creator>
      <dc:date>2024-08-17T21:47:03Z</dc:date>
    </item>
    <item>
      <title>Re: Sharing variables between languages</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Sharing-variables-between-languages/m-p/4105639#M3655</link>
      <description>&lt;P&gt;I have no experience with, and have not heard about, using %%javascript before.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Perhaps you could use a Lakehouse file to read/write from?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When switching between spark.sql() (PySpark) and %%sql (SparkSQL) cells I have been able to use temporary views.&lt;/P&gt;</description>
      <pubDate>Sun, 18 Aug 2024 12:29:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Sharing-variables-between-languages/m-p/4105639#M3655</guid>
      <dc:creator>frithjof_v</dc:creator>
      <dc:date>2024-08-18T12:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: Sharing variables between languages</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Sharing-variables-between-languages/m-p/4115388#M3738</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/24978"&gt;@smpa01&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems javascript is not an official supported language in the code cell of Fabric notebook. And it's a challenge to pass a variable between Pyspark code cell and JS code cell.&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vjingzhanmsft_1-1724403087042.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1156147i971AF667F257ACEC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vjingzhanmsft_1-1724403087042.png" alt="vjingzhanmsft_1-1724403087042.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As an alternative, you may use Python to execute the JS code. Some python libraries provide the functionality to call Javascript from Python. This makes it easier to pass variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I create a sample as below by using&amp;nbsp;&lt;SPAN&gt;js2py. Create a function in JS, then call this function by Python. We can pass python variables to the JS function and get the result into another python variable.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vjingzhanmsft_0-1724402995130.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1156146i52D4CAF523F92EF5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vjingzhanmsft_0-1724402995130.png" alt="vjingzhanmsft_0-1724402995130.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;import js2py

get_pow = js2py.eval_js('function get_pow(a, b) {return Math.pow(a, b)}')
result = get_pow(10, 3)
print(result)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;References:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/39096901/call-javascript-from-python" target="_blank" rel="noopener"&gt;Call Javascript from python - Stack Overflow&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/PiotrDabkowski/Js2Py" target="_blank" rel="noopener"&gt;GitHub - PiotrDabkowski/Js2Py: JavaScript to Python Translator &amp;amp; JavaScript interpreter written in 100% pure Python&lt;span class="lia-unicode-emoji" title=":rocket:"&gt;🚀&lt;/span&gt; Try it online:&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Jing&lt;BR /&gt;&lt;EM&gt;If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos! &lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Aug 2024 09:05:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Sharing-variables-between-languages/m-p/4115388#M3738</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-08-23T09:05:17Z</dc:date>
    </item>
    <item>
      <title>Re: Sharing variables between languages</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Sharing-variables-between-languages/m-p/4115755#M3747</link>
      <description>&lt;P&gt;I am not keen on running js in isolation in notebook cell, rather I want to be able to share variables to js from other languages so that I can ask js to do things it is best at and then pass on bak those to succedding cells to a different langugae. That is the big picture.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Aug 2024 12:55:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Sharing-variables-between-languages/m-p/4115755#M3747</guid>
      <dc:creator>smpa01</dc:creator>
      <dc:date>2024-08-23T12:55:47Z</dc:date>
    </item>
  </channel>
</rss>

