我在导入函数时遇到了一些问题。这是代码!
!/usr/bin/env python
import pyglet
class main():
def mainfunc(self):
# sets up user input and converts it into a string
userinput = str(input("Please enter the full path of your file: "))
path = userinput
return userinput
music = pyglet.media.load(userinput)
exitinput = str(input("Do you want to exit? Please press q to quit!"))
music.play()
pyglet.app.run()
if exitinput == "q":
quit()
else:
pass
main()
from main import mainfunc
class PlayLists:
def playlists(self):
playinput = str(input("Please enter a key if you want to save a playlist"))
user = main()
user.main(userinput)
此外,我在尝试按“ q”按钮退出程序时遇到问题。顺便说一句,main.py的第一行需要一个英镑符号。 谢谢!
答案 0 :(得分:1)
您正在尝试从类中导入方法
from main import main
main.mainfunc() #to access your method from the class
user = main() #to create an instance of the imported class
user.mainfunc(userinput) # to get the method going