Answers for "python import config file"

6

python config file

''' config.cfg
[whatever]
key=qwerertyertywert2345
secret=sadfgwertgrtujdfgh
'''

from configparser import ConfigParser

config = ConfigParser()
config.read('config.cfg')

my_key = config['whatever']['key']
my_secret = config['whatever']['secret']
Posted by: Guest on January-06-2021
0

how to use config file to remove redundant variables in code

from ConfigParser import SafeConfigParser

parser = SafeConfigParser()
parser.read('simple.ini')

print parser.get('bug_tracker', 'url')
Posted by: Guest on December-10-2020
0

cant import config python 3

/anaconda2/lib/python2.7/site-packages/boto3/session.py in <module>()
     16 
     17 import botocore.session
---> 18 from botocore.client import Config
     19 from botocore.exceptions import DataNotFoundError, UnknownServiceError
     20 

ImportError: cannot import name Config
Posted by: Guest on November-12-2020
0

python config file json datatypes

import pandas as pd
import json
import numpy as np

# Create a file (csv) for test purposes 
data = '''
3,10,3.5,abc
3,010,3,bcd'''
file = io.StringIO(data)

# Create a file (json) for test purposes
json_data = '''
{
   "header":[
       ["field1","int16"],
       ["field2","float32"],
       ["field3","float64"],
       ["field4","str"]]
}'''

# Load json to dictionary
json_d = json.loads(json_data)

# Fetch field names and dtypes
names = [i[0] for i in json_d['header']]
dtype = dict(json_d['header'])

# Now use pandas to read the whole thing to a dataframe
df = pd.read_csv(file,header=None,names=names,dtype=dtype)

# Output as dict (this can be passed to a json file with json.dump())
df.to_dict('r')
Posted by: Guest on December-26-2020

Python Answers by Framework

Browse Popular Code Answers by Language