0

I am trying to import functions from another file. From my understanding all I had to do was import and use .

I am not familiar enough with classes but was trying to mess around and make the function a class. That didn't work. I tried importing the function from the file as well. Everything worked fine in one file but it became too big and I wanted to organize my code into seperate files. Calling the tarotDict (which is just three long dictionarys) worked fine but as soon as I tried to call functions I was hit with AttributeErrors.

fortune.py

import tarotFunctions

if user_selection == "1":
    print("-------------------------")
    print("Please select how many cards you wish to draw.")
    print("1. Single card draw.")
    print("2. Three card draw (Past, Present, Future)")
    print("3. Card information")
    print("0. Main menu")
    user_tarot_selection = input("> ")
        if user_tarot_selection == "1":
            tarotFunctions.draw_one() #<----------------------- 
                                      #attribute error when calling

tarotFunctions.py

import random
import tarotdict

def draw_one():
    single_draw = random.randint(1,78) 
    single_up_or_down = random.randint(1,2) 
    print("-------------------------")
    print("You have drawn the " + tarotdict.tarot[single_draw] + " 
          card.")
    if single_up_or_down == 1: #determine if face up or down
        print("Your card is facing up and represents:")
        print(tarotdict.tarot_face_up[single_draw])
        print("-------------------------")
    else:
        print("Your card is facing down and represents:")
        print(tarotdict.tarot_face_down[single_draw])
        print("-------------------------")



Traceback (most recent call last):
File "fortune.py", line 35, in <module>
main_menu()
File "fortune.py", line 20, in main_menu
tarotFunctions.draw_one() 
AttributeError: module 'tarotFunctions' has no attribute 'draw_one'
Chlorr
  • 3
  • 2

1 Answers1

0

Looks like your draw_one has an error.
The following cannot be done this way:

print("You have drawn the " + tarotdict.tarot[single_draw] + " 
          card.")

It has to be either:

print("You have drawn the " + tarotdict.tarot[single_draw] + " card.")

or

print("You have drawn the " + tarotdict.tarot[single_draw] + " \
          card.")

or

print("You have drawn the " + tarotdict.tarot[single_draw] 
    + " card.")

You can't multi line quotes (i.e. a string) without \.