我不知道如何將我的簡單功能添加到我的主程序文件。爲什麼不 ?從模塊訪問功能
當我這樣做:
import print_text
echothis("this is text")
exit()
無法理解爲什麼人們認爲這是這樣一個壞的問題。
這並不工作之一:如果鍵入以下任何答案
print_text.echothis("this is text")
同樣的事情發生。 包括:
from print_text import echothis
我剛剛得到這個錯誤:
from: can't read /var/mail/print_text
./blah3.py: line 3: syntax error near unexpected token `"this is text"'
./blah3.py: line 3: `print_text.echothis("this is text")'
或沒有在/ var /郵件線變體...
*此文件被命名爲print_text.py *
#!/usr/bin/env python
import time
import random
import string
import threading
import sys
def echothis(txt):
woo=txt
stdout.write(woo)
其實你應該得到一個錯誤,說'echothis'是不確定的。你的導入應該是'from print_text import echothis' –
你用什麼材料來學習python?這聽起來像你應該得到更好的學習材料。 – Marcin
我看不到線程對象正在創建的位置。也許你缺少的是實例化'print_text'類併爲該對象調用'start'方法。 – jcollado