arleigh418 / python-and-Taiwan-stock-market

Python 金融市場賺大錢聖經:寫出你的專屬指標
54 stars 17 forks source link

請問關於自動寄信 #31

Open erichuang888 opened 2 years ago

erichuang888 commented 2 years ago

您好想請問一下 在3-64當中 import sys sys.path.append('D:\Trading Strategy_EX\Chapter3') 上面這段的用意為何?

另外我嘗試複製一個類似程式,在同一個資料夾下執行範例程式時 出現以下錯誤訊息

File "/Users/mac/Documents/python-and-Taiwan-stock-market-main/Trading Strategy_EX/Chapter3/smtp(def).py", line 16, in from AES_Encrytion.encrype_process import *

ModuleNotFoundError: No module named 'AES_Encrytion'

之後改為直接執行範例程式smtp.py 就出現下面錯誤訊息 File "/Users/mac/Documents/python-and-Taiwan-stock-market-main/Trading Strategy_EX/Chapter3/smtp.py", line 8, in from AES_Encryption.encrype_process import *

File "/Users/mac/Documents/python-and-Taiwan-stock-market-main/Trading Strategy_EX/Chapter3/AES_Encryption/encrype_process.py", line 2, in from AES_Encryption.en_decrype import *

File "/Users/mac/Documents/python-and-Taiwan-stock-market-main/Trading Strategy_EX/Chapter3/AES_Encryption/en_decrype.py", line 1, in from Crypto.Cipher import AES

ModuleNotFoundError: No module named 'Crypto'

請問是哪裡有問題呢?

arleigh418 commented 2 years ago

Hi 您好, 關於您第一個問題 import sys sys.path.append('D:\Trading Strategy_EX\Chapter3') 舉例來說,我有兩只程式,位址分別是: D:\Trading Strategy_EX\test.py D:\Trading Strategy_EX\Chapter3\tool.py 您應該可以感受到上面兩個程式的階層不同,當我想要在test.py中直接引用tool.py,import tool時,程式就會告訴你找不到程式,不過透過sys的方式,我們將那個路徑告訴程式,他就能找到那個路徑底下的所有py檔,就能引用。 這是一個做法,其實您也可以按照您的階層去import您寫的py檔。(e.g. import Chapter3.tool)

您的第二個問題應只是沒有安裝套件 ModuleNotFoundError: No module named 'Crypto'

嘗試在您的環境中安裝套件即可。 pip install pycryptodome==3.9.7

erichuang888 commented 1 year ago

又順利解決了 謝謝詳細的解說 能狗透過這樣發問解決書中的疑惑 真的大大解決市面上程式書籍遇到難題的困境

arleigh418 commented 1 year ago

您客氣了,祝學習順利哦~