Python Forum
How can I import a variable from another script without executing it
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I import a variable from another script without executing it
#11
Sounds like you're running two different programs at different times (that "other script" has run and exited before "3rd script" runs). If so, the dataframe is gone and has to be recreated.

If you want to process some data and reuse the result multiple times, that generally means you need to do one of :
  • Run them in the same process
  • After processing the data, save it to disk in already-processed form and read it back quickly (like a database)
  • Process the data and keep it in memory, and have the second script talk to the first process (IPC) and request the data
ThomasFab likes this post
Reply
#12
(May-04-2022, 02:45 PM)bowlofred Wrote: Sounds like you're running two different programs at different times (that "other script" has run and exited before "3rd script" runs). If so, the dataframe is gone and has to be recreated.

If you want to process some data and reuse the result multiple times, that generally means you need to do one of :
  • Run them in the same process
  • After processing the data, save it to disk in already-processed form and read it back quickly (like a database)
  • Process the data and keep it in memory, and have the second script talk to the first process (IPC) and request the data


That´s perfectly what i want, thank you! Cool
Do you have some buzzwords oder functions for the second two points i could google?
Reply
#13
Python docs have a section on IPC. In general it's more work because you have to manage a client/server interaction. https://docs.python.org/3/library/ipc.html

For external storage, maybe you could just write the information to disk. First attempt could be to just store it as JSON. If that's not performant enough, you could try a simple database like https://docs.python.org/3/library/sqlite...le-sqlite3.
ThomasFab likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trouble with threading and reading variable from a different script Lembas 14 3,079 Apr-26-2023, 11:21 PM
Last Post: Lembas
Video doing data treatment on a file import-parsing a variable EmBeck87 15 2,916 Apr-17-2023, 06:54 PM
Last Post: EmBeck87
  Problem executing a script on a remote host tester_V 3 2,483 Sep-26-2021, 04:25 AM
Last Post: tester_V
  Using import in python script offline - HELP!! blackhatter1001001 1 2,267 Jul-25-2021, 05:57 AM
Last Post: ndc85430
  Import output from python script to another varietyjones 1 1,919 Oct-12-2020, 09:07 PM
Last Post: bowlofred
  Use dynamic variable from parallel running python script Sicksym 0 1,856 May-15-2020, 02:52 PM
Last Post: Sicksym
  [split] script: remove all "carriage return" from my json variable pete 2 2,816 May-05-2020, 03:22 PM
Last Post: deanhystad
  Using variable from a class in another .py script keegan_010 4 3,004 Mar-25-2020, 07:47 AM
Last Post: keegan_010
  Import and variable level tazalapizza 1 1,758 Mar-16-2019, 07:47 PM
Last Post: Larz60+
  script: remove all "carriage return" from my json variable mfran2002 4 11,231 Feb-20-2019, 05:07 AM
Last Post: mfran2002

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020