Jump to content

Is it possible?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
jivkoss

jivkoss

    Newbie

  • Members
  • PipPip
  • 28 posts
I write a long program that I'm gonna split in 4-5 parts. The mother program will use the other daughter programs (which are also modules) by importing them. Is it possible to have a variable in the mother program that the other daughter programs will also use?
For example:
#mother program

a = 5

import daughter1


#daughter1 program

b = 6

c = a + b

print c


This of course is not working, it says 'variable a is not defined' or smth like that. Is it possible somehow to use the variable a in the 2 programs?

#2
Sinipull

Sinipull

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 386 posts
You can save the information into the file and access it from the other program.

#3
Somelauw

Somelauw

    Newbie

  • Members
  • PipPip
  • 18 posts
Yes, on top of the daughter program, write
from __main__ import a

It is better to make a function in the daughter program and pass a to it as a parameter.