在Xcode中找不到Python的输出文件

时间:2012-08-11 23:15:48

标签: python xcode pyobjc

我刚开始学习Python一周前。感谢所有提出问题并回答问题的人,我取得了相当大的进步。我昨晚遇到了一个问题,经过大量的搜索和思考 - 我仍然无法弄明白。

我尝试在xcode中创建一个Python项目,但是我找不到输出文件。我从“选择模板菜单”中选择“Cocoa-Python Application”开始了项目:“在main.py文件中,我有以下代码:

import objc
import Foundation
import AppKit
from PyObjCTools import AppHelper

file = open('test.txt', 'w')

print >> file, 'Test of the emergency broadcast system.'
print 'This is merely a test...'

file.close()

控制台显示“这只是一个测试...”语句,但我无法在任何地方找到输出文件'test.txt'。我搜索过计算机,但无处可寻。我确定这是愚蠢的,但我错过了什么?

1 个答案:

答案 0 :(得分:0)

将其打印到您的控制台,您将看到文件名:

print file

http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files


如果只是显示相对路径,请像这样打印cwd:

from os import getcwd
print 'Current directory:', getcwd()

http://docs.python.org/library/os#os.getcwd