Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Modules
#1
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
Reply
#2
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'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Modules issue, pip3 download modules only to pyhton3.5.2 not the latest 3.6.1 bmohanraj91 6 8,468 May-25-2017, 08:15 AM
Last Post: wavic

Forum Jump:

User Panel Messages

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