简体   繁体   中英

How to make a config.ini for python project?

I have create a python project that update the data excel for my work, the problem is i need to create a config file so that others people can use my python project without changing the code.

My code:

import pandas as pd
import datetime
timestr = datetime.date.today().strftime('%d%m%Y')

Buyerpath = 'https://asd.cvs'
Sellerpath = 'https://dsa.csv'
Onlinepath = 'https://sda.csv'

Totalpath = pd.DataFrame({'BuyValue': Buyerpath.Buytotal,
                          'SellerValue': Sellerpath.Sellertotal,
                          'OnlineValue':Onlinepath.onlinetotal})

Totalpath.to_excel(index=False, excel_writer=r'C:\Users\Mike\Desktop\Result\ResultTotal'+timestr+'.xlsx')

I need the config file to allow others people use my python code and save the excel update in the output folder. 在此处输入图像描述

I think what you're asking is: how do I hide strings/variables that are specific to my local machine? correct?

The easiest way to do this is with another python file

my-project
├── __init__.py
├── main.py
└── secrets.py

put your the strings into you're secrets file, then import the values into your main.py file

from .secrets import secret_val

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM