Я пытаюсь импортировать функции из другого файла. Из моего понимания все, что мне нужно было сделать, это импортировать и использовать.
Я недостаточно знаком с классами, но пытался возиться и делать функцию классом. Это не сработало. Я также попытался импортировать функцию из файла. В одном файле все работало нормально, но оно стало слишком большим, и я хотел организовать свой код в отдельные файлы. Вызов tarotDict (который представляет собой всего три длинных словаря) работал нормально, но как только я попытался вызвать функции, я столкнулся с 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'