Python Forum
Use Variables Generated from Functions in different files to use on the main file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use Variables Generated from Functions in different files to use on the main file
#1
I have a question. I am new in python and this is my 1st time to use python forum. I made lots of research in internet but I couldn't find what I am looking for. I will be very happy if you guide me to learn this issue to solve.

"Use Variables Generated from Functions etc in different files to use on the main file as a condition to do something"

Let's say we have three python files and two of them will be called in the main python file to print their values. But I would like to use that called values in the main.py file to do something else. A basic example; or you can add functions which return a value to see in the main.py to use that variable as a if condition to do something.

# config_x.py
x = 0
# mod_x.py
import config_x
config_x.x = 5
# main.py
import config_x
import mod_x
print(config_x.x) # It will show us 5 in the python shell

#I want to use that value of 5 to do something else in the main.py
new_x = config_x.x
if(new_x == 5):
   print("DO SOMETHING")
However, when I try something like that in the main.py, nothing is generated in python shell as DO SOMETHING print. Would you show me how we can do such thing ? thank you very much.
Reply


Messages In This Thread
Use Variables Generated from Functions in different files to use on the main file - by AykutRobotics - Jan-01-2019, 01:04 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 13 865 Apr-24-2024, 05:47 AM
Last Post: Bronjer
  How can i combine these two functions so i only open the file once? cubangt 4 867 Aug-14-2023, 05:04 PM
Last Post: snippsat
  HOW TO USE C# GENERATED DLL davide_vergnani 2 1,656 Jun-12-2023, 03:35 PM
Last Post: davide_vergnani
  File path by adding various variables Mishal0488 2 1,040 Apr-28-2023, 07:17 PM
Last Post: deanhystad
  Can I get some clarification on importing functions from external files. wh33t 3 908 Feb-25-2023, 08:07 PM
Last Post: deanhystad
  delete all files and subdirectory from a main folder mg24 7 1,625 Oct-28-2022, 07:55 AM
Last Post: ibreeden
  python run all py files from main py file mg24 6 1,346 Oct-12-2022, 04:41 AM
Last Post: mg24
  using variables with functions imported from different files. Scordomaniac 3 1,281 May-24-2022, 10:53 AM
Last Post: deanhystad
  Formating generated .data file to XML malcoverc 3 1,358 Apr-14-2022, 09:41 PM
Last Post: malcoverc
  Storing variables into one file for use in multiple Jupyter notebooks devansing 1 1,745 Feb-05-2022, 10:04 AM
Last Post: ibreeden

Forum Jump:

User Panel Messages

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