Python:根据另一个变量改变时间? [英] Python: change time depending on another variable?

查看:136
本文介绍了Python:根据另一个变量改变时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制定财务预算,有些人可能不熟悉。 

我创建了这个脚本来调用文件参数中的参数:

Net = $ 10'000'000
从文件中提取(salary1 = 19000,salary2 = 15000) ,salary3 = 19000有时会改变)
parametersAndValues = {}
parameterFile = open('Parameter')
try:
for parameterFile中的行:
parametersAndValues [line。 split()[0]] = int(round(float(line.split()[1])))
finally:
parameterFile.close()

i1 = parametersAndValues.get('$ salary1')
i2 = parametersAndValues.get('$ salary2')
i3 = parametersAndValues.get('$ salary3')
for parametersAndValues中的参数:
(参数+'='+ str(parametersAndValues.get(参数)))
time1 = 0.1 *(净/工资1)
时间2在TSTEP中的工资2 =时间1 +时间1 *(工资1 /( salary1 + salary2))
time3 of salary3 = time2 + time1


我想更新`TSTEP`下的时间步长取决于sal ary付款。
查看可以支付多少个月工资。

如果我们划分净额10'000'000 / on salary1 19'000 = 526天=这将是17个月的31天(17 * 31)

输出应该是`17 * 31`,它将被粘贴在`TSTEP`下的第一个工资和`27 * 31`将被粘贴在`TSTEP`下的工资2.

问题是,我需要根据工资在每个TSTEP中更改3 * 31,我不知道如何做到这一点。

以下是从`parameter`文件更新的示例`Schedule`文件:


SCHEDULE


## - First Cycle
/
WCLSIN
Class1 LIQ OPEN RESV 1 * $ salary1 1 * 3500 /
/
/
TSTEP
3 * 31

/

TUNING
/
/
2 * 100 /
## - Second周期
WCLSIN
Class1 LIQ OPEN RESV 1 * $ salary2 3500 /
/
TSTEP
3 * 31
/
TUNING
/
/
2 * 100 /

应更改为:


SCHEDULE


## - 第一周期
/
WCLSIN
Class1 LIQ OPEN RESV 1 * $ salary1 1 * 3500 /
/
/
TSTEP
17 * 31

/

TUNING
/
/
2 * 100 /
## - 第二周期
WCLSIN
Class1 LIQ OPEN RESV 1 * $ salary2 3500 /
/
TSTEP
27 * 31
/
TUNING
/
/
2 * 100 /

再次,如果你知道如何做到这一点,我会非常感激。
最好的问候





我尝试过:



打开('schedule.txt')为f:#Mode'r'是默认值,无需指定。 
for current_line in f.read()。split('\ n'):
if previous_line =='TSTEP':
new_lines.append(str(time1))
else:
new_lines.append(current_line)
previous_line = current_line

new_text ='\ n'.join(new_lines)
open('schedule.txt ','w')。write(new_text)





问题是有两个TSTEP表示不同的工资,我不知道如何做第二个工资??

解决方案

10'000'000
从文件中提取(salary1 = 19000,salary2 = 15000,salary3 = 19000有时会改变)
parametersAndValues = {}
parameterFile = open('Parameter')
try:
for parameterFile中的行:
parametersAndValues [line.split()[0] ] = int(round(float(line.split()[1])))
finally:
parameterFile.close()

i1 = parametersAndValues.get('

salary1')
i2 = parametersAndValues.get('


salary2')
i3 = parametersAndValues.get('

I am working on a financial budget and may not be familiar to some of you. 

I created this script to call parameters from a file parameter:

    Net=$10'000'000
    Extract from file (salary1 =19000, salary2= 15000, salary3 = 19000 sometimes change) 
    parametersAndValues = {}
    parameterFile = open('Parameter') 
    try:
    	for line in parameterFile:
    		parametersAndValues[line.split()[0]] = int(round(float(line.split()[1])))
    finally:
    	parameterFile.close()
    
    i1 = parametersAndValues.get('$salary1')
    i2 = parametersAndValues.get('$salary2')
    i3 = parametersAndValues.get('$salary3')
    for parameter in parametersAndValues:
    	( parameter + ' = ' + str(parametersAndValues.get(parameter)))
    time1=0.1*(net/salary1) 
    time2 in TSTEP of salary2=time1+time1*(salary1/(salary1+salary2))
    time3 of salary3 = time2+time1


I want to update the timesteps under `TSTEP` depending on the salary payment. 
To see how many months that salary can be paid.

If we divided Net 10'000'000/on salary1 19'000=526 Days = which will be 17 months of 31 Days (17*31)

The output should be `17*31` which will be pasted under `TSTEP` for the first salary and `27*31` which will be pasted under `TSTEP` for salary 2.

The question is, I need to change `3*31` in each TSTEP depending on the salary, and I have no idea of how to do that.

The following is a sample `Schedule` file to be updated from `parameter` file:


    SCHEDULE
    
    
    ##-- First Cycle
    /   
    WCLSIN
    Class1  LIQ  OPEN  RESV  1*  $salary1  1*  3500 /
    /
    /
    TSTEP 
      3*31
  
      /
       
    TUNING
     /
     /
     2*  100 /
    ##-- Second Cycle
    WCLSIN
    Class1  LIQ  OPEN  RESV  1*  $salary2  3500 /
    /
    TSTEP 
      3*31
    /
    TUNING
     /
     /
     2*  100 /

It should be changed to:


    SCHEDULE
    
    
    ##-- First Cycle
    /   
    WCLSIN
    Class1  LIQ  OPEN  RESV  1*  $salary1  1*  3500 /
    /
    /
    TSTEP 
      17*31
    
      /
    
    TUNING
     /
     /
     2*  100 /
    ##-- Second Cycle
    WCLSIN
    Class1  LIQ  OPEN  RESV  1*  $salary2  3500 /
    /
    TSTEP 
      27*31
    /
    TUNING
     /
     /
     2*  100 /

Again, please if you have any idea of how to do that I would really appreciate it. 
Best Regards



What I have tried:

with open('schedule.txt') as f:  # Mode 'r' is default, no need to specify.
    for current_line in f.read().split('\n'):
        if previous_line == 'TSTEP':
            new_lines.append(str(time1))
        else:
            new_lines.append(current_line)
        previous_line = current_line

new_text = '\n'.join(new_lines)
open('schedule.txt', 'w').write(new_text)



The problem is there are two TSTEPs represent different salaries, and I dont know how to do the second salary ??

解决方案

10'000'000 Extract from file (salary1 =19000, salary2= 15000, salary3 = 19000 sometimes change) parametersAndValues = {} parameterFile = open('Parameter') try: for line in parameterFile: parametersAndValues[line.split()[0]] = int(round(float(line.split()[1]))) finally: parameterFile.close() i1 = parametersAndValues.get('


salary1') i2 = parametersAndValues.get('


salary2') i3 = parametersAndValues.get('


这篇关于Python:根据另一个变量改变时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆