0
I have a script in Python divided into functions and need to access a function variable in another example function:
import glob, os, time, datetime, sys, platform
from datetime import datetime
from datetime import timedelta
os.chdir = 'C:\Zabbix\Temp'
#Pegar SO e retorna os valores de acordo com a plataforma: 0 - Linux; 1 - Windows; 2 - ERROR
def getOperationSystem():
OpSys = platform.system()
print(OpSys)
if OpSys == 'Windows':
return(getParameters('C:\\Zabbix\\Parameters.txt'))
elif OpSys == 'Linux':
return('#')
else:
print('Sistema Operacional desconhecido')
return(2)
StopIteration()
#Pegar os parametros no arquivo Parameters
def getParameters(dirBkp):
with open(dirBkp, "r") as arq:
for linha in arq:
global values
values = linha.split(';')
return getTasks(values[2])
#Valida se o processo do backup está em execução: 0 - Sim; 1 - Não
def getTasks(name):
read_process = os.popen('tasklist /v').read().strip().split('\n')
for i in range(len(read_process)):
process = read_process[i]
if name in read_process[i]:
return 0
StopIteration
getTimeArq(values)
#Valor tempo do ultimo arquivo
def getTimeArq(values):
bkp_name = values[2]
print("Nome do Bkp:\t\t\t", bkp_name)
bkp_name = bkp_name+"*.log"
print(bkp_name)
log = glob.glob(bkp_name)
log.sort(key=os.path.getctime, reverse=True)
print (log[0])
In the case, the getParameters
, has a variable that should be used in 3 or more functions of 20 (which is in the script)
It loads several values where each function pulls a value, while trying to use it in the getTimeArq
he returned this to me:
By the message, you tried to call the function
getTimeArq
without specifying the parameters. To call a function, you need to place the parentheses and, in this case, the value ofvalues
. Something likex = getTimeArq(meus_values)
.– Woss
Even using the method you recommended, now he gives me the None return... as if it were empty =/
– user68537
You could post the 'error' or output completely ?
– Otávio Reis Perkles
Of course, to make it easier I’ll give an Edit posted all the code and the print of the output OK?
– user68537
I have another script that works (because it was designed to receive the parameters coming from the command line and it is lake that can no longer occur so I put all the parameters inside a txt that the value variable is receiving and printing the values as needed but when passing to the Variable LOG it is void
– user68537
Cara I solved hsuahsuhauhsauhsaus Vlw by helping I who did shit and had not seen I will edit with the answer
– user68537
In that case, answer your own post with your answer. In the most elaborate way possible. So whoever finds the question somehow might have an idea of what you did to solve
– Otávio Reis Perkles
Dear Wallace, use the answer field to add the answer. Take the tour to understand how the site works https://answall.com/tour
– Guilherme Nascimento