Allow communication between multiple python files

I am using github to store my code so heruku can use it

My question is how would I create two python scripts in github and have one store all the static data and allow the other script to read from the first script?

Also would I need to update my 'Procfile'. All I currently have in there is 'worker: python' where main is one of my scripts. I would like to add another script called ''

Here is my github if it helps:

I'm fairly new to all this so a more explained answer would be appreciated


1 answer

  • answered 2018-06-24 23:55 Frynio

    The answer to your question is fairly simple:

    In the file you can store your variables simply like this:

    a = 3
    b = "Some text"

    In some other file, lets say you can then import them:

    from staticData import a
    from staticData import b

    And then you can use them however you want.

    P.S If you want to change the value of those variables in one function and then preserve this value in other functions, you have two ways:

    Either import module and reference variables like this:

    import staticData
    staticData.a = 10
    staticData.b = "changed the text"

    or you can use global (especially if referencing from a function)