pythonshell显示了一个包含内容的文件,但它们可以';不能在磁盘上加载

pythonshell显示了一个包含内容的文件,但它们可以';不能在磁盘上加载,python,io,scripting,ipython,Python,Io,Scripting,Ipython,我正在尝试使用脚本写入文件。我有: In [15]: f = file('/home/me/scripts/python/notrecent.txt', 'w') In [16]: f Out[16]: <open file '/home/me/scripts/python/notrecent.txt', mode 'w' at 0x7f8677440030> In [17]: notrecentstring Out[17]: 'Username, "Full name", "C

我正在尝试使用脚本写入文件。我有:

In [15]: f = file('/home/me/scripts/python/notrecent.txt', 'w')

In [16]: f
Out[16]: <open file '/home/me/scripts/python/notrecent.txt', mode 'w' at 0x7f8677440030>

In [17]: notrecentstring
Out[17]: 'Username, "Full name", "Clinics they still work at", "Last logon"\n"jdo", "John Do", "Dallas", "08/19/2013"\n"
...yadayada'
In [18]: f.flush()

In [19]: f.write(notrecentstring)

In [20]: f
Out[20]: <open file '/home/me/scripts/python/notrecent.txt', mode 'w' at 0x7f8677440030>

In [22]: f.close()

In [23]: f = file('/home/me/scripts/python/notrecent.txt', 'r')

In [24]: content = f.read()

In [25]: content
Out[25]: 'Username, "Full name", "Clinics they still work at", "Last logon"\n"jdo", "John Do", "Dallas", "08/19/2013"\n"
...yadayada'
In [26]: f.close()
[15]中的
:f=file('/home/me/scripts/python/notrecent.txt',w')
In[16]:f
出[16]:
在[17]中:notrecentstring
Out[17]:“用户名”、“全名”、“他们仍在工作的诊所”、“上次登录”\n“jdo”、“John Do”、“达拉斯”、“2013年8月19日”\n
…yadayada'
[18]:f.flush()
In[19]:f.write(notrecentstring)
In[20]:f
出[20]:
在[22]中:f.close()
在[23]中:f=file('/home/me/scripts/python/notrecent.txt',r')
在[24]中:content=f.read()
在[25]中:内容
Out[25]:“用户名”、“全名”、“他们仍在工作的诊所”、“上次登录”\n“jdo”、“John Do”、“达拉斯”、“2013年8月19日”\n
…yadayada'
在[26]:f.close()中
然而,当我从它的位置加载文件时,它是完全空白的。什么可能导致这种令人困惑的行为?多谢各位


科迪

你能说得更具体些吗?“当我从它的位置加载文件”与在python shell中加载文件是什么意思?如果在shell中键入cat/home/cchilders/scripts/python/notrecent.txt,会发生什么情况。另外,在您的示例中,前面的路径是
'/home/me/scripts/python/notrecent.txt'
,后面的路径是
'/home/cchilders/scripts/python/notrecent.txt'
。它是哪一个?我的意思是,如果我单击gedit并获得文件(GUI打开),它将加载为空。如果我是猫,我什么也得不到。应该工作的空格(f.flush()、f.write()、f.close()。我怀疑问题出在别处。检查你的文件名,它不会抛出一个错误,如果你弄错了,它实际上只会创建一个新的.txt文件名不正确。你可能是在写这封信。当我指的是scripts/python/emailcleanup(为我的老板)时,我设法在scripts/python中创建了一个同名文件。对不起,伙计们,谢谢