Skip to main content
Minor editorial change.
Source Link
LouisB
  • 12.8k
  • 1
  • 22
  • 34

Have you considered using SetDelayed (:=) to define script? Here is an example that is coded for Windows:

linPy = "'import datetime; print datetime.datetime.now()'";
winPy = "\"import datetime; print datetime.datetime.now()\"";
cmd = "!python -c "  winPy ;
script := Import[cmd, "String"]

Linux users would use the "linPy" expression instead of "winPy". With the above definitions, script is updated whenever it is referenced. For example, execute the following command a few times and you will see an updated value each time:

First@StringTake[script, {18 ;;}]

Of course, you would substitute your own python command.

For a continuously updated display you could use something like the following:

Dynamic[x]
continueDisplay = True;
Button["Stop", continueDisplay = False]
While[continueDisplay,
 x = First@StringTake[script, {18 ;;}];
 ]

The While-loop will be terminated when you press the "stop" button. The problem with continuous update is that you can't keep working in the notebook. Using the RunScheduledTask is a better solution:

Dynamic[x]
delaySeconds = 2;
task = RunScheduledTask[x = First@StringTake[script, {18 ;;}], delaySeconds];

The scheduled task waits 2 seconds, runs the Python script and updates the displayed value of x. It allows you to keep working in the same notebook. To terminate the scheduled task, evaluate RemoveScheduledTask[task];

Have you considered using SetDelayed (:=) to define script? Here is an example that is coded for Windows:

linPy = "'import datetime; print datetime.datetime.now()'";
winPy = "\"import datetime; print datetime.datetime.now()\"";
cmd = "!python -c "  winPy ;
script := Import[cmd, "String"]

Linux users would use the "linPy" expression instead of "winPy". With the above definitions, script is updated whenever it is referenced. For example, execute the following command a few times and you will see an updated value each time:

First@StringTake[script, {18 ;;}]

Of course, you would substitute your own python command.

For a continuously display you could use something like the following:

Dynamic[x]
continueDisplay = True;
Button["Stop", continueDisplay = False]
While[continueDisplay,
 x = First@StringTake[script, {18 ;;}];
 ]

The While-loop will be terminated when you press the "stop" button. The problem with continuous update is that you can't keep working in the notebook. Using the RunScheduledTask is a better solution:

Dynamic[x]
delaySeconds = 2;
task = RunScheduledTask[x = First@StringTake[script, {18 ;;}], delaySeconds];

The scheduled task waits 2 seconds, runs the Python script and updates the displayed value of x. It allows you to keep working in the same notebook. To terminate the scheduled task, evaluate RemoveScheduledTask[task];

Have you considered using SetDelayed (:=) to define script? Here is an example that is coded for Windows:

linPy = "'import datetime; print datetime.datetime.now()'";
winPy = "\"import datetime; print datetime.datetime.now()\"";
cmd = "!python -c "  winPy ;
script := Import[cmd, "String"]

Linux users would use the "linPy" expression instead of "winPy". With the above definitions, script is updated whenever it is referenced. For example, execute the following command a few times and you will see an updated value each time:

First@StringTake[script, {18 ;;}]

Of course, you would substitute your own python command.

For a continuously updated display you could use something like the following:

Dynamic[x]
continueDisplay = True;
Button["Stop", continueDisplay = False]
While[continueDisplay,
 x = First@StringTake[script, {18 ;;}];
 ]

The While-loop will be terminated when you press the "stop" button. The problem with continuous update is that you can't keep working in the notebook. Using the RunScheduledTask is a better solution:

Dynamic[x]
delaySeconds = 2;
task = RunScheduledTask[x = First@StringTake[script, {18 ;;}], delaySeconds];

The scheduled task waits 2 seconds, runs the Python script and updates the displayed value of x. It allows you to keep working in the same notebook. To terminate the scheduled task, evaluate RemoveScheduledTask[task];

added 8 characters in body
Source Link
LouisB
  • 12.8k
  • 1
  • 22
  • 34

Have you considered using SetDelayed (:=) to define script? Here is an example that is coded for Windows:

linPy = "'import datetime; print datetime.datetime.now()'";
winPy = "\"import datetime; print datetime.datetime.now()\"";
cmd = "!python -c "  winPy ;
script := Import[cmd, "String"]

Linux users would use the "linPy" expression instead of "winPy". With the above definitions, script is updated whenever it is referenced. For example, execute the following command a few times and you will see an updated value each time:

First@StringTake[script, {18 ;;}]

Of course, you would substitute your own python command.

For a continuously display you could use something like the following:

Dynamic[x]
continueDisplay = True;
Button["Stop", continueDisplay = False]
While[continueDisplay,
 x = First@StringTake[script, {18 ;;}];
 ]

The While-loop will be terminated when you press the "stop" button. The problem with continuous update is that you can't keep working in the notebook. Using the RunScheduledTask is a better solution:

Dynamic[x]
delaySeconds = 2;
task = RunScheduledTask[x = First@StringTake[script, {18 ;;}], delaySeconds];

The scheduled task waits 2 seconds, runs the Python script and updates the displayed value of x. It allows you to keep working in the same notebook. to terminated To terminate the scheduled task, evaluate RemoveScheduledTask[task];

Have you considered using SetDelayed (:=) to define script? Here is an example that is coded for Windows:

linPy = "'import datetime; print datetime.datetime.now()'";
winPy = "\"import datetime; print datetime.datetime.now()\"";
cmd = "!python -c "  winPy ;
script := Import[cmd, "String"]

Linux users would use the "linPy" expression instead of "winPy". With the above definitions, script is updated whenever it is referenced. For example, execute the following command a few times and you will see an updated value each time:

First@StringTake[script, {18 ;;}]

Of course, you would substitute your own python command.

For a continuously display you could use something like the following:

Dynamic[x]
continueDisplay = True;
Button["Stop", continueDisplay = False]
While[continueDisplay,
 x = First@StringTake[script, {18 ;;}];
 ]

The While-loop will be terminated when you press the "stop" button. The problem with continuous update is that you can't keep working in the notebook. Using the RunScheduledTask is a better solution:

Dynamic[x]
delaySeconds = 2;
task = RunScheduledTask[x = First@StringTake[script, {18 ;;}], delaySeconds];

The scheduled task waits 2 seconds, runs the Python script and updates the displayed value of x. It allows you to keep working in the same notebook. to terminated the scheduled task, RemoveScheduledTask[task];

Have you considered using SetDelayed (:=) to define script? Here is an example that is coded for Windows:

linPy = "'import datetime; print datetime.datetime.now()'";
winPy = "\"import datetime; print datetime.datetime.now()\"";
cmd = "!python -c "  winPy ;
script := Import[cmd, "String"]

Linux users would use the "linPy" expression instead of "winPy". With the above definitions, script is updated whenever it is referenced. For example, execute the following command a few times and you will see an updated value each time:

First@StringTake[script, {18 ;;}]

Of course, you would substitute your own python command.

For a continuously display you could use something like the following:

Dynamic[x]
continueDisplay = True;
Button["Stop", continueDisplay = False]
While[continueDisplay,
 x = First@StringTake[script, {18 ;;}];
 ]

The While-loop will be terminated when you press the "stop" button. The problem with continuous update is that you can't keep working in the notebook. Using the RunScheduledTask is a better solution:

Dynamic[x]
delaySeconds = 2;
task = RunScheduledTask[x = First@StringTake[script, {18 ;;}], delaySeconds];

The scheduled task waits 2 seconds, runs the Python script and updates the displayed value of x. It allows you to keep working in the same notebook. To terminate the scheduled task, evaluate RemoveScheduledTask[task];

Added the RunScheduledTask method.
Source Link
LouisB
  • 12.8k
  • 1
  • 22
  • 34

Have you considered using SetDelayed (:=) to define script? Here is an example that is coded for Windows:

linPy = "'import datetime; print datetime.datetime.now()'";
winPy = "\"import datetime; print datetime.datetime.now()\"";
cmd = "!python -c "  winPy ;
script := Import[cmd, "String"]

Linux users would use the "linPy" expression instead of "winPy". With the above definitions, script is updated whenever it is referenced. For example, execute the following command a few times and you will see an updated value each time:

First@StringTake[script, {18 ;;}]

Of course, you would substitute your own python command.

For a continuouscontinuously display you could use something like the following:

Dynamic[x]
continueDisplay = True;
Button["Stop", continueDisplay = False]
While[continueDisplay,
 x = First@StringTake[script, {18 ;;}];
 ]

The While-loop will be terminated when you press the "stop" button. The problem with continuous update is that you can't keep working in the notebook. Using the RunScheduledTask is a better solution:

Dynamic[x]
delaySeconds = 2;
task = RunScheduledTask[x = First@StringTake[script, {18 ;;}], delaySeconds];

The scheduled task waits 2 seconds, runs the Python script and updates the displayed value of x. It allows you to keep working in the same notebook. to terminated the scheduled task, RemoveScheduledTask[task];

Have you considered using SetDelayed (:=) to define script? Here is an example that is coded for Windows:

linPy = "'import datetime; print datetime.datetime.now()'";
winPy = "\"import datetime; print datetime.datetime.now()\"";
cmd = "!python -c "  winPy ;
script := Import[cmd, "String"]

Linux users would use the "linPy" expression instead of "winPy". With the above definitions, script is updated whenever it is referenced. For example, execute the following command a few times and you will see an updated value each time:

First@StringTake[script, {18 ;;}]

Of course, you would substitute your own python command.

For a continuous display you could use something like the following:

Dynamic[x]
continueDisplay = True;
Button["Stop", continueDisplay = False]
While[continueDisplay,
 x = First@StringTake[script, {18 ;;}];
 ]

The While-loop will be terminated when you press the "stop" button.

Have you considered using SetDelayed (:=) to define script? Here is an example that is coded for Windows:

linPy = "'import datetime; print datetime.datetime.now()'";
winPy = "\"import datetime; print datetime.datetime.now()\"";
cmd = "!python -c "  winPy ;
script := Import[cmd, "String"]

Linux users would use the "linPy" expression instead of "winPy". With the above definitions, script is updated whenever it is referenced. For example, execute the following command a few times and you will see an updated value each time:

First@StringTake[script, {18 ;;}]

Of course, you would substitute your own python command.

For a continuously display you could use something like the following:

Dynamic[x]
continueDisplay = True;
Button["Stop", continueDisplay = False]
While[continueDisplay,
 x = First@StringTake[script, {18 ;;}];
 ]

The While-loop will be terminated when you press the "stop" button. The problem with continuous update is that you can't keep working in the notebook. Using the RunScheduledTask is a better solution:

Dynamic[x]
delaySeconds = 2;
task = RunScheduledTask[x = First@StringTake[script, {18 ;;}], delaySeconds];

The scheduled task waits 2 seconds, runs the Python script and updates the displayed value of x. It allows you to keep working in the same notebook. to terminated the scheduled task, RemoveScheduledTask[task];

Added the section that describes the continuous display.
Source Link
LouisB
  • 12.8k
  • 1
  • 22
  • 34
Loading
added 62 characters in body
Source Link
LouisB
  • 12.8k
  • 1
  • 22
  • 34
Loading
Source Link
LouisB
  • 12.8k
  • 1
  • 22
  • 34
Loading