Serial Monitor Error - writing a python script

File script = FileSystem.open("/tmp/example.py", FILE_WRITE);
script.print("#!/usr/bin/python\n");
script.print("import urllib2\n");
script.print("import ast\n");
script.print("r = urllib2.urlopen('https://example.api.call')\n"); //This line here <------------
script.print("a = r.read()\n");
script.print("y = ast.literal_eval(a)\n");
script.print("b = y['results'][0]['example']\n");  // indexing a dictionary that returns an int
script.print("print str(b)");

I’m trying to write a python script into the internal ram of the linino side of my Yun. I’ve tried more simple python scripts printing ints and strings and have been successful. When I enter the line of code with the arrow pointing toward it above, the python script won’t run correctly - nor will the serial monitor output the code script properly if I run this:

Process reading;
reading.begin("cat");
reading.addParameter("/tmp/example.py");
reading.run();
String output2 = "";

while(reading.available())
{
  output2 += (char)reading.read();
}
Serial.println(output2);

Serial Monitor outputs this:

#!/usr/bin/python
import urllib2
import ast
r = urllib2.urlopen('https://example.api

I’d really appreciate some help with this!
Thanks in advance!

to confirm the file correct wrote,

cat /tmp/example.py

at linino console.

before run "/tmp/example.py" you need using Process set permission

chmod 755 /tmp/example.py or

wrote "/tmp/example.py" without "#!/usr/bin/python\n" and run it as

/usr/bin/python  /tmp/example.py

Thanks for the response. I did see the permissions for the file to be executable, but I'll try your alternative method to invoke the script.

Does it look like there are any errors in how I created the example.py file?

You could confirm if it work by run it at

/usr/bin/python  /tmp/example.py

at linino console.