Imports not working?

I am not entirely sure what is happening here but I had it working for a moment before all I did was actually use the imports
The rest of the pictures are in the comments

What might be the issue here?


Circular imports is when the imports, which tries to import… In an infinite loop.

1 Like

So how might I get some variable from to is a helper file. treats it as a servant, mostly.
therefore, should be independent.

the answer is, getting a variable from to is not recommended, since is a helper and should not depend on its master.

but, I’ll provide an example, of how could import a function from and use it.

def add(*numbers):
    return sum(numbers)

from addition import add
sum = add(1,2,3)
assert sum == 6

Okay, well for the most part that is what I had before though I am attempting to add a memory function to it, is there a better way to do that or would i just have to combine the files?

What is a memory function?

so I am coding a calculator and want to add some way of keeping a number from a previous task
so taking the sum of some numbers and in a different function use that sum without having to type it, like you can on some actual calculators

Interesting. Looks like you’ll need a way to store temporary storage.

I recommend environment variables.

import os
def add(*numbers,previous=False):
    ans = os.getenv("ans")
    ans = ans if ans and previous else 0
    result = sum(numbers) + ans
    return result

import os
from addition import add

result1 = add(1,2,3)
assert result1 == 6

result2 = add(1,2,previous=True)
assert result2 == 6 + 1 + 2

result3 = add(4,5,6)
assert result3 == 15

Did you make the memory function you wanted?

just has to step away for a moment I will try it and get back to you

I was unable to get this to work, but I have decided to just combine the files and just make a local variable. Thank you for your help

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.