0
def main():
with Path(filepath).open("rb") as fp:
    image_binary = fp.read()
    response = requests.post(
        PINATA_BASE_URL + endpoint,
        files={"file": (filename, image_binary)},
        headers=headers,
    )
    ipfs_hash = response.json()["IpfsHash"]
    print(response.json())
    image_uri = "{}{}".format(first_part_image_uri, ipfs_hash)
    print(image_uri)

    # Aufruf Funktion create_image_uri_meta_file
    simple_collectible = SimpleCollectible[len(SimpleCollectible) - 1]
    token_id = simple_collectible.tokenCounter()
    create_image_uri_meta_file(response, token_id)
return image_uri

I want to transfer the variable image_uri into another Python script. The best attempt so far I have succeeded with:

from scripts.upload_to_pinata import main
image_uri = main()
image_uri_from_upload = image_uri

However, the problem arises here that I take over all commands and other variables from main. I would like to take over however ONLY the one variable. Does anyone have a solution, idea or suggestion how I can transfer only the one variable between the Python scripts? Here is a part of the script in which the variable should be inserted.

from scripts.upload_to_pinata import main

image_uri = main()
image_uri_from_upload = image_uri

image_uri_from_upload = ""

def main():

Thanks in advance for the support.

maxver
  • 1
  • 2
  • the important part is `image_uri = "{}{}".format(first_part_image_uri, ipfs_hash)`... so to get an `image_uri` you need the values of those two variables. `first_part_image_uri` seems like it must come from some code you didn't put in the question, and `ipfs_hash` is derived from the api response. Hard to tell what you really want – Anentropic Jun 07 '22 at 16:24
  • yes the `first_part_image_uri` is an URL link. I want to value (string in form of an URL-Link) of `image_uri` in antother script. But i only want to export this variable and not the functions or other values of the main-function. Did you need more code to give a better answer? – maxver Jun 07 '22 at 18:27
  • it sounds like you need to take just the parts necessary to generate an image_uri from `main` and move them into a new function, say `get_image_uri`, and then you call that function in `main` and also import just the new function in your other script and call it there too – Anentropic Jun 07 '22 at 18:30
  • i generate the `image_uri` in the function main. i only want to call this `image_uri` in another function which is in another script. The `image_uri` is an URL Link which i want to use in another script and therefore i need to export this `image_uri` – maxver Jun 07 '22 at 18:49
  • well, good luck – Anentropic Jun 07 '22 at 19:34
  • @Anentropic you have no idea to solve this problem? – maxver Jun 08 '22 at 12:59
  • I suggested a way but you are fixated on things that don't make sense, not a criticism, it is just due to lack of understanding. You need to start from basics, learn how functions and variables work – Anentropic Jun 08 '22 at 13:04

0 Answers0