Search code examples
pythonpackageshared-librariesfilenames

Having short python file log file names with complete parameters details in the name


I am generating log files in python. I have around 20 parameters, which I am reading from config.cnf file. Based on the value of these parameters, I name the log file. I want to use abbreviations to make the file name short. The present name of file and directories generated form my code are very long.

This is an example of a file name "cifar10_symm_ter_1bits_128_256_512_f1024_2_det_fil_ssl_1e-06_chan_ssl_1e-06_fco_ssl_1e-06_fci_ssl_1e-06_prthr1e-06_bc_init_cgs_c_50_4_cgs_f_50_16.txt". Here I have inserted different parameter names such as "symm_ter" and following the parameter I have added details of the parameter as "1bits". If their are some recommended naming techniques etc. and not exactly a library that should also be helpful.

I want to shorten file and folder names and at the same time have details about the parameters in the file name. If there is some python library which can help me abbreviate names for the parameters to be used in file name that will solve my task. Also, if that library can help display details about the abbreviated parameters that will help. I have looked into argparse library but that is for command line parameters. In my code I am reading from, config.cnf, configuration file. I have read python module naming convention; however I am concerned about brevity of the names here.


Solution

  • You can shorten by encoding your options through your own dictionary ( for example if some options are only 128,256,512 you can decide it will be A B or C) but you will lose readability.
    In fact, I think you are on a wrong way. The name is not the place to store your 20 parameters. What happens if 21 or if a very long option ? You are already in trouble.
    If i have to do, i will use a general name for the log file (ex: Mylog+datetime) and either put the 20 parameters as my first log line, either adding a secondary file with same root (ex: mylog+datetime+. desc) to store and retreive these values.
    Hth
    It seems you want to design a cms (content management system) using file name as descriptor. This is (a little) meaningful if you need to move these folders as individuals.
    If your store will stay same place, using a sqlite db to link a folder name with its parameters will be much more powerful and quite simple in python.