Is there a better way to retrieve variables from class method Currently my code works but I wanted to know if I'm going about this the right way. I want to be able to individually call variables from method 'data_by_name' in 'otherfile.py' . At the moment I import 'otherfile.py' and put the elements into a list within 'main.py' and use tuple unpacking to give each element a variable name.

Could I go about this a better way?

otherfile.py

import requests
import json

API_KEY = "XXX"
PROJECT_TOKEN = "XXX"
RUN_TOKEN = "XXX"

class Data:
    def __init__(self, api_key, project_token):
        self.api_key = api_key
        self.project_token = project_token
        self.params = {"api_key":api_key}
        self.get_data()

    def get_data(self):
        r = requests.get('https://www.parsehub.com/api/v2/projects/PROJECT_TOKEN/last_ready_run/data', params={"api_key": API_KEY})
        self.data = json.loads(r.text)


    def data_by_name(self,country):

        data = self.data['country']
        for content in data:
            if content['Cname'].lower() == country.lower():
                print(content)
                name = content['Cname']
                pop = content['population']
                popRank = content['popRank']
                growth = content['growthRate']
                per = content['worldPer']
                area = content['area']
                capital = content['capital']
                region = content['region']
                gpd = content['gpd']
        return(name,pop,popRank,growth,per,area,capital,region,gpd)

if __name__ == '__main__':
    data = Data(API_KEY,PROJECT_TOKEN)
    data.data_by_name('Russia')


main.py

from ParsehubCode import Data,API_KEY,PROJECT_TOKEN

country = Data(API_KEY,PROJECT_TOKEN)
test = country.data_by_name("china")
list1 = []
for element in test:
    list1.append(element)
for x in list1:
    A,B,C,D,E,F,G,H,I = list1
print(A,B,C)


country.json

{
 "country": [
  {
   "Cname": "China",
   "name": "China Population 2020 (Live)",
   "population": "1,438,719,354",
   "popRank": "1",
   "growthRate": "0.39%",
   "worldPer": "18.47%",
   "area": "9,706,961 km²",
   "capital": "Beijing",
   "region": "Asia",
   "gpd": "$10,746.78"
  }
{
Instead of

list1 = []
for element in test:
    list1.append(element)
for x in list1:
    A,B,C,D,E,F,G,H,I = list1


you could simply write 

A,B,C,D,E,F,G,H,I = test




Regardless, here's a slightly different approach.

Assuming that the input json structure is { 'country': [{ }, ..., { }] }, 
I'd slightly modify self.data:

 self.data = {country['Cname'].lower(): country
              for country in json.loads(r.text)['country']}


then access this dictionary whenever required. Possibly by overwriting __getitem__:

def __getitem__(self, key):
    return self.data[key.lower()]


Then you can access the inner dictionary using [ ]:

GlobalDataLoader(API_KEY,PROJECT_TOKEN)['china']
GlobalDataLoader(API_KEY,PROJECT_TOKEN)['china']['population']


Here I've renamed the Data class: I don't expect the constructor of a class named Data to access the internet, and the data seems to be global.
Still, I'd remove the self.get_data() call from __init__.

On the other hand, if you are not planning to reuse the (API_KEY, PROJECT_TOKEN) for a specific GlobalDataLoader instance, then I wouldn't store these in the instances. Instead do something like

data = GlobalDataLoader(project_secrets)


where

class GlobalDataLoader:    
    def __init__(self, project_secrets):
        self.load_data(project_secrets)

    def load_data(self, project_secrets):
        url = f"https://www.parsehub.com/api/v2/projects/{project_secrets['project_token']}/last_ready_run/data"
        r = requests.get(url, params={"api_key": project_secrets['api_key']})
        self.data = {country['Cname'].lower(): country
                     for country in json.loads(r.text)['country']}

    def __getitem__(self, key):
        return self.data[key.lower()]




That being said, don't hard-code secrets into the source code.

API_KEY = "XXX"
PROJECT_TOKEN = "XXX"
RUN_TOKEN = "XXX"


You don't want this as a habit when you start using version control systems. Store these in a separate file. If you have to store that in a VCS, then encrypt it (e.g. use gitcrypt). 

To reuse the idea of a wrapped dictionary, you could write a

class ProjectSecretsLoader:
    def __init__(self, config_file_path):
        self.load_config(config_file_path)

    def load_config(self, config_file_path):
        self.config_data = dict() # TODO

    def __getitem__(self, key):
        return self.config_data[key]


then do

config_file_path = "..."
project_secrets = ProjectSecretsLoader(config_file_path)
data = GlobalDataLoader(project_secrets)




Last, but not least requests.get might fail, json.loads might fail. The result of json.loads might not have the structure you expect, or might be missing the country you will eventually try to look up, etc. In these cases specific exceptions will be raised, which ideally should be handled, otherwise the program will crash.