我在python中编写安装脚本的脚本.
如何在python中从ftp下载文件?
操作系统 - Windows XP - 如果有所作为.
python脚本有什么问题?
码:
import os
import shutil
import getpass
os.mkdir("C:\\dtmp")
shutil.copy("C:\\path\\to\\bb-freeze-script.py","C:\\dtmp")
os.chdir("C:\\dtmp")
shutil.copy("C:\\path\\to\\main.py","C:\\dtmp")
os.system("python bb-freeze-script.py main.py")
os.mkdir("C:\\Program Files\\Directories v0.6")
os.chdir("C:\\")
shutil.rmtree("C:\\dtmp")
print getpass.getuser()
Run Code Online (Sandbox Code Playgroud)
错误:
Traceback (most recent call last):
File "bb-freeze-script.py", line 8, in <module>
load_entry_point('bbfreeze==0.97.3', 'console_scripts', 'bb-freeze')()
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\__init__.py", line 24, in main
f.addScript(x)
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\freezer.py", line 410, in addScript
s = self.mf.run_script(path)
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\modulegraph\modulegraph.py", line 241, in run_script
co = compile(file(pathname, READ_MODE).read()+'\n', pathname, 'exec')
File "C:\dtmp\main.py", line 14
^
IndentationError: expected an indented block
Run Code Online (Sandbox Code Playgroud)
操作系统 - Windows XP
在python中使用此代码时:
f = open('ping.log', 'r+')
f.write("["+time.ctime()+"]"+"Status")
f.close()
Run Code Online (Sandbox Code Playgroud)
我的文件总是被覆盖.并且只有一行,如下所示:
[2011年9月2日星期五16:30:56]状态
为什么会被覆盖?
我在创造一个游戏.当我正在阅读LinkedHashMap时,它给了我一个NPE.
我这样填写LinkedHashMap hm:
for (String s : line.split("")) {
if (s.contains("*")) {
hm.put(new Coordinates(xa-32, ya), "gray");
} else if (s.contains("#")) {
hm.put(new Coordinates(xa-32, ya), "black");
}
// other code...
}
Run Code Online (Sandbox Code Playgroud)
后来我尝试从这样的HashMap中获取颜色,并得到一个NPE:
if ((keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_A)
&& isPainted && hm.get(new Coordinates(x - 32, y)).equalsIgnoreCase("gray")) {
x -= 32;
}
Run Code Online (Sandbox Code Playgroud)
完整代码:
python ×5
file ×2
file-io ×2
windows-xp ×2
delete-file ×1
directory ×1
ftp ×1
indentation ×1
install ×1
java ×1
linux ×1
sh ×1
windows ×1