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
#8
Also, I don't think I understand what part of your import is "not working" in your first attempt. Can you make a reproducible example that shows the error? When I do something similar, it seems to import fine. I'm not sure how mine differs from your attempt.

b01_import.py
import pandas as pd
global df

if True:
    df = pd.DataFrame([3, 2, 1])
plot.py
from b01_import import df

print(df)
Output:
0 0 3 1 2 2 1
Reply


Messages In This Thread
RE: How can I import a variable from another script without executing it - by bowlofred - May-04-2022, 07:52 AM

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