看板 Python 關於我們 聯絡資訊
以下是我照抄寫的部分python遊戲程式碼 import pygame from pygame.locals import pygame.init() width, height = 640, 480 screen=pygame.display.set_mode((width. height)) player = pygame.images.load("resources/images/dude.png") error:couldn't open resources/images/dude.png 就像大家看到的,無法打開 resources,想請問是為什麼呢?? 我有先下載相關檔案在 電腦文件夾裡了啊... 我的作業系統是ubuntu12.04,用python2.7寫,以上程式碼是參照Beginning Game programming for Teens with python抄的,網址是 http://www.raywenderlich.com/24252/beginning-game-programming-for-teens-with-python 拜託高手指點迷津一下,謝謝! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.169.205.162 ※ 文章網址: http://www.ptt.cc/bbs/Python/M.1398945422.A.569.html
funnypeter:use absolute path not relative path 05/01 20:27
funnypeter:that's a common error 05/01 20:28
funnypeter:try a absolute path such as ~/script/images/.png 05/01 20:32
funnypeter:mkdir such path first of cours 請問F大,你是說最下面那行 要打player = pygame.images.load("script/images/dude.png ")嗎??e. 05/01 20:3
Microscft:么壽 網頁拉到最下面很驚人 這是一個13歲男孩寫的 05/01 20:46
※ 編輯: purestone (118.169.205.162), 05/01/2014 22:48:51
Microscft:...... 你是不是英文不太好 05/02 00:30
Microscft:你先去google什麼叫絕對路徑什麼叫相對路徑 05/02 00:31
Microscft:然後再去yahoo辭典查such as是什麼意思 05/02 00:32
jokester:python開啟文件時會展開~嗎? 05/02 00:50
apua:通常不會; 一樓應該只是提醒 05/02 02:04
funnypeter:絕對路徑:最前面有/開始 05/02 04:55
funnypeter:相對路徑沒有, 通常找不到是路徑設定錯誤 05/02 04:56
funnypeter:改成絕對路徑就不會發生找不到路徑的情況 05/02 04:57
funnypeter:~的意思是你的家目錄, /home/username 05/02 04:58
funnypeter:~/script/images/.png 意思是/home/username/script/im 05/02 05:00
funnypeter:ages/.png 05/02 05:00
funnypeter:當然你要先mkdir建立該目錄 05/02 05:01
funnypeter:路徑改成 我上述說的絕對路徑看看 05/02 05:02
funnypeter:這是初學者常見的錯誤 05/02 05:03
funnypeter:dude.png當然要移動到該目錄內 05/02 05:05
funnypeter:username改成你的名字 05/02 05:06
funnypeter:我這裡舉的路徑只是例子,你也可以用~/images/.png 05/02 05:07
funnypeter:你試試看 cd~ 05/02 05:09
funnypeter:然後打pwd就知道了 05/02 05:10
funnypeter:自己寫程式不要都照抄,要自己改環境變數,這是很常見 05/02 05:11
funnypeter:的修改 05/02 05:11
purestone:謝謝! 05/02 06:43