作者purestone (天空之子)
看板Python
标题[问题] 无法开启
时间Thu May 1 19:56:57 2014
以下是我照抄写的部分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://webptt.com/cn.aspx?n=bbs/Python/M.1398945422.A.569.html
1F:→ funnypeter:use absolute path not relative path 05/01 20:27
2F:→ funnypeter:that's a common error 05/01 20:28
3F:推 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
4F:推 Microscft:么寿 网页拉到最下面很惊人 这是一个13岁男孩写的 05/01 20:46
※ 编辑: purestone (118.169.205.162), 05/01/2014 22:48:51
5F:→ Microscft:...... 你是不是英文不太好 05/02 00:30
6F:→ Microscft:你先去google什麽叫绝对路径什麽叫相对路径 05/02 00:31
7F:→ Microscft:然後再去yahoo辞典查such as是什麽意思 05/02 00:32
8F:推 jokester:python开启文件时会展开~吗? 05/02 00:50
9F:→ apua:通常不会; 一楼应该只是提醒 05/02 02:04
10F:推 funnypeter:绝对路径:最前面有/开始 05/02 04:55
11F:→ funnypeter:相对路径没有, 通常找不到是路径设定错误 05/02 04:56
12F:→ funnypeter:改成绝对路径就不会发生找不到路径的情况 05/02 04:57
13F:→ funnypeter:~的意思是你的家目录, /home/username 05/02 04:58
14F:推 funnypeter:~/script/images/.png 意思是/home/username/script/im 05/02 05:00
15F:→ funnypeter:ages/.png 05/02 05:00
16F:→ funnypeter:当然你要先mkdir建立该目录 05/02 05:01
17F:→ funnypeter:路径改成 我上述说的绝对路径看看 05/02 05:02
18F:→ funnypeter:这是初学者常见的错误 05/02 05:03
19F:推 funnypeter:dude.png当然要移动到该目录内 05/02 05:05
20F:→ funnypeter:username改成你的名字 05/02 05:06
21F:→ funnypeter:我这里举的路径只是例子,你也可以用~/images/.png 05/02 05:07
22F:推 funnypeter:你试试看 cd~ 05/02 05:09
23F:→ funnypeter:然後打pwd就知道了 05/02 05:10
24F:→ funnypeter:自己写程式不要都照抄,要自己改环境变数,这是很常见 05/02 05:11
25F:→ funnypeter:的修改 05/02 05:11
26F:→ purestone:谢谢! 05/02 06:43