Мне только что удалось создать coreCal c () Класс в Python. Все работает отлично. Теперь я хочу вызвать этот алгоритм из coreCal c () из другого файла python, без необходимости запускать весь исходный файл Class, я полагаю, потому что в настоящее время мой Class зависит от всего кода выше.
Может кто-нибудь подсказать, как решить этот вопрос?
**My code**:
#references
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import pandas as pd
import csv
import time
import requests
#using creds to create a client to interact with the Google Drive API
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name('/Users/Miauw/Miauw/github/Miauw/Token/token.json', scope)
client = gspread.authorize(creds)
# Find a workbook by name and open the first sheet
sheet = client.open("IFTTT_Webhooks_Events").sheet1
#get data directly from google sheet.
data = sheet.get_all_values()
headers = data.pop(0)
# capture data into dataframe
df = pd.DataFrame(data, columns=headers)
df_array = [ (df["Statement 3"].iloc[-1]),
(df["Statement 2"].iloc[-1]),
(df["Statement 3"].iloc[-1]),
(df["Statement 3"].iloc[-1])
]
#function for calculating user lonelienss based on UCLA Lonliness scoring (theory)
class coreCalc:
def __init__(self):
#assign loneliness-scores to the various user-responses
for i in range(len(df_array)):
if df_array[i] == 'Often':
df_array[i] = 3
elif df_array[i] == 'Sometimes':
df_array[i] = 2
elif df_array[i] == 'Rarely':
df_array[i] = 1
elif df_array[i] == 'Never':
df_array[i] = 0
#obtain sum of values for final scoring
print(sum(map(int,df_array)))
#coreCalc()