Python Forum

Full Version: Modules
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi

I am fairly new to Python and modules in particualar

I have folder containing 2 files :
Configuration.py
HelixApi.py

COnfiguration,py :
# URL of the Helix ALM REST API
import requests

HELIX_ALM_REST_API_URL = 'https://localhost:8443/helix-alm/api/v0/'

# Helix ALM login username
USER_NAME = 'ApiUser'

# Helix ALM login password
PASSWORD = 'APIUser'


PROJECT_NAME = ""
HelixApi.py error
from HelixApi import Configuration
The error in HelixApi.py is ModuleNotFoundError: No module named 'Configuration'

I do not understand what is wrong, please can someone explain
Thanks
Has to call with name Configuration.
Example this will work.
from Configuration import USER_NAME, PASSWORD

>>> USER_NAME
'ApiUser'
>>> PASSWORD
'APIUser'
Be aware that when import(also using from Configuration) all of code in Configuration.py will be executed.

There also configparser that fit this task fine.
Example.

helix.ini:
Output:
[helix_access] USER_NAME = ApiUser PASSWORD = APIxxx [api_url] HELIX_ALM_REST_API_URL = https://localhost:8443/helix-alm/api/v0/
import configparser

config = configparser.ConfigParser()
config.read('helix.ini')
>>> user = config['helix_access']['USER_NAME']
>>> user
'ApiUser'
>>> 
>>> url = config['api_url'].get('HELIX_ALM_REST_API_URL', 'Not found in config')
>>> url
'https://localhost:8443/helix-alm/api/v0/'
>>> 
>>> url = config['api_url'].get('HELIX_ALM_REST_API_URL999', 'Not found in config')
>>> url
'Not found in config'