⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 config.py

📁 PyChem是用Python语言编写的多元变量分析软件。它包括一个前端图形界面用于管理和保存试验数据
💻 PY
字号:
"""config.py adapted from GaussSum, gausssum.sf.net"""

import ConfigParser,os,sys

import pychem

whereami = pychem.__path__[0]



class Preferences(object):



    def __init__(self):

        """Initialise the preferences."""



        if sys.platform == "win32":

            location = os.getenv("APPDATA")

        else: # i.e. for Linux

            location = os.getenv("HOME")

        self.filename = os.path.join(location,".pychem")

        if not os.path.isfile(self.filename):

            self.setdefaults()



        self.read()

            

    def __getitem__(self,key):

        return self.settings[key]



    def __setitem__(self,key,value):

        self.settings[key] = value



    def setdefaults(self):

        """Set the defaults."""

        self.settings = {

                          'main.wdir':os.path.join(whereami,"examples")

                        }

        self.write()

    

    def read(self):

        """Read the preferences from an .ini file.

        

        Taken from the Python Cookbook 1st ed. (O'Reilly):

        Uses the Python module ConfigParser for the complicated stuff.

        """

        cp = ConfigParser.ConfigParser()

        cp.read(self.filename)

        config = {}

        

        for sec in cp.sections():

            name = sec.lower()

            for opt in cp.options(sec):

                fullname = ".".join([name,opt.lower()])

                config[fullname] = cp.get(sec,opt).strip()

                

        self.settings = config

                

    def write(self):

        """Write the preferences to an .ini file."""

        cp = ConfigParser.ConfigParser()



        for key,value in self.settings.items():

            sec = key.split('.')[0]

            opt = key.split('.')[1]

            if not cp.has_section(sec):

                cp.add_section(sec)

            cp.set(sec,opt,str(value))



        out = open(self.filename,"w")

        cp.write(out)

        out.close()



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -