def save_config(self): # configs.process = int(self.process_edit.text()) configs.path = self.path_edit.text() configs.Scalerfile_path = self.scaler_path_edit.text() configs.TDDIfile_path = self.tddi_path_edit.text() configs.UserDatafile_path = self.userdata_path_edit.text() with open("Config/configs.py", "w", encoding="utf-8") as f: f.write(f"# -*- coding: utf-8 -*-\n") # f.write(f"process = {configs.process}\n") f.write(f"path = \"{configs.path}\"\n") f.write(f"Scalerfile_path = \"{configs.Scalerfile_path}\"\n") f.write(f"TDDIfile_path = \"{configs.TDDIfile_path}\"\n") f.write(f"UserDatafile_path = \"{configs.UserDatafile_path}\"\n") time.sleep(0.5)这个怎么改为写入硬盘中
时间: 2024-01-30 10:03:49 浏览: 21
你可以将文件路径改为硬盘中的路径,例如:
```
with open("/mnt/data/Config/configs.py", "w", encoding="utf-8") as f:
```
这样就会将文件写入到硬盘的指定路径中。请根据你的实际情况修改路径。
相关问题
def __init__(self, glueContext: GlueContext, config: argparse.Namespace): """ init function. :param glueContext: the glueContext. the spark session can get from glueContext. :param config: Obtained by parsing from the Glue Job Input parameter list. """ self.config = config self.logger = logging.getLogger(self.config.table_full_name) self.logger.info(f'job init with params: {vars(self.config)}') self.glueContext = glueContext self.spark = glueContext.spark_session self.table_schema = Custom_Schema(self.spark).get_schema(self.config.source_file_schema) self.source_df_count = 0 self.destination_df_count = 0 self.load_date = datetime.now() self.logger.info(f'job load date: {self.load_date}') self.database_name, self.table_name = self.config.table_full_name.split('.') self.set_spark_configs()
这是一个Python类的初始化函数,它接受两个参数:glueContext和config。其中,glueContext是Glue的上下文,可以从中获取Spark会话,而config则是从Glue作业的输入参数列表中解析得到的命名空间。在初始化函数中,将这两个参数分别赋值给实例变量self.glueContext和self.config,并且设置了一些其他的实例变量,比如self.logger、self.spark、self.table_schema等。最后,调用了self.set_spark_configs()方法。可以看到,这个类是用来处理一些数据加载和转换的任务的,具体实现需要看其他方法的实现。
def _reset(self): self.epoch = 0 self.best_val_acc = 0 self.best_params = {} self.loss_history = [] self.train_acc_history = [] self.val_acc_history = [] self.optim_configs = {} for p in self.model.params: d = {k: v for k, v in self.optim_config.items()} self.optim_configs[p] = d
这是Solver类中的一个私有函数_reset(),用于初始化一些训练变量。这个函数会将epoch(训练轮数)、best_val_acc(最佳验证集准确率)、best_params(最佳模型参数)、loss_history(训练集损失值历史记录)、train_acc_history(训练集准确率历史记录)和val_acc_history(验证集准确率历史记录)等变量初始化。同时,它还会为每个模型参数p初始化一个优化器配置项optim_configs[p],并将其设置为self.optim_config字典中的配置项。这样,每个参数都会有自己的优化器配置项。