Python Forum
Passing Variables between files. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Passing Variables between files. (/thread-30348.html)



Passing Variables between files. - victorTJ - Oct-16-2020

I have these two files
Main.py
# Script displays my organizations I have access to.
import os

os.chdir('/Users/virgi/Dropbox/Dropbox-Work/Wing Files/Development/Utils')

from menu_option import api_key
from menu_option import  organization_id

my_org =  dashboard.organizations.getOrganizations()

print(my_org)
choice.py
# script sets the correct environment variables
import meraki 

# Create the menu to be displayed
print('Please make a chose')
print("1 - For SandBox Virgil press")
print('2 - For SandBox Meraki')
print('3 - For LafageProduction')

user_input = int(input('Please select an enviroment: '))

# Determine the users input was and set variables
if user_input == 1:# Sandbox A
    api_key = 'ijkl'
    organization_id = '996719'
    print(api_key)
    

elif user_input == 2: # Sandbox B
    api_key = 'efgh' 
    organization_id = '566327653141842188'
    print(api_key)
    

elif user_input == 3:
    api_key = 'abcd' # Sandbox C
    organization_id = '647392446434509389'
    print(api_key)
else:
    print('Sorry there was not match')


# Creates the dashboard variable    
dashboard = meraki.DashboardAPI(api_key,output_log=False, print_console=False)
When I run the 2 scripts I get the api_key & organization_id but when I try to use the dashboard varialbe it says it isn't defined.

it works if I put all the code in a single code
# script sets the correct environment variables
import meraki 

# Create the menu to be displayed
print('Please make a chose')
print("1 - For SandBox Virgil press")
print('2 - For SandBox Meraki')
print('3 - For LafageProduction')

user_input = int(input('Please select an enviroment: '))

# Determine the users input was and set variables
if user_input == 1:# Sandbox A
    api_key = 'ijkl'
    organization_id = '996719'
    print(api_key)
    

elif user_input == 2: # Sandbox B
    api_key = 'efgh' 
    organization_id = '566327653141842188'
    print(api_key)
    

elif user_input == 3:
    api_key = 'abcd' # Sandbox C
    organization_id = '647392446434509389'
    print(api_key)
else:
    print('Sorry there was not match')


# Creates the dashboard variable    
dashboard = meraki.DashboardAPI(api_key,output_log=False, print_console=False)

my_org =  dashboard.organizations.getOrganizations()

print(my_org)



RE: Passing Variables between files. - Larz60+ - Oct-16-2020

please repost using code tags (python icon in toolbar).
Your indentation was removed when you posted without tags


RE: Passing Variables between files. - metulburr - Oct-17-2020

post the error code in proper BBCode tags too.


RE: Passing Variables between files. - snippsat - Oct-17-2020

(Oct-16-2020, 09:00 PM)Larz60+ Wrote: please repost using code tags (python icon in toolbar).
Your indentation was removed when you posted without tags
Just some info,indentation will never be removed if user paste in with indentation in first place.
This is because i removed wysiwyg mode and any button to use it in editor.
Ask for repost can be okay,or can go in add code tag(now will see pasted in indentation) as i have done now.