新人求教,关于Python用open()找不到文件的问题。。

Samerol_Jomior 2013-08-08 05:18:38
小弟这几天自己在看python。。今天看到open()这个,倒腾好久都没搞好。。希望前辈们指教一下。。我已经创建好test.txt的文件了。。为什么找不到呢。。
>>> the_file = open('test.txt')
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
the_file = open('test.txt')
FileNotFoundError: [Errno 2] No such file or directory: 'test.txt'
>>> the_file = open('D:\\Program Files\\Python\\test.txt')
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
the_file = open('D:\\Program Files\\Python\\test.txt')
FileNotFoundError: [Errno 2] No such file or directory: 'D:\\Program Files\\Python\\test.txt'
>>>
...全文
3736 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Samerol_Jomior 2013-08-08
  • 打赏
  • 举报
回复
引用 2 楼 crifan 的回复:
我这里是可以的。然后也故意弄个错的给你看了:
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> the_file = open("D:\\Program Files\\Python\\test.txt");
>>> print the_file
<open file 'D:\Program Files\Python\test.txt', mode 'r' at 0x0000000002FAA270>
>>> notExist_file = open("D:\\Program Files\\Python\\notFound.txt");

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    notExist_file = open("D:\\Program Files\\Python\\notFound.txt");
IOError: [Errno 2] No such file or directory: 'D:\\Program Files\\Python\\notFound.txt'
>>> 
所以: 1.猜测你的python是不是安装的有问题。 重新安装一下试试。 2.你的python是什么版本的???
我的是3.3的那个,我也觉得我的这个有问题,有时候在按backspace键的时候会出现小方块。。但是换了输入法又好了。。我好几次卸载安装,都是这种情况。。
crifan 2013-08-08
  • 打赏
  • 举报
回复
我这里是可以的。然后也故意弄个错的给你看了:
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> the_file = open("D:\\Program Files\\Python\\test.txt");
>>> print the_file
<open file 'D:\Program Files\Python\test.txt', mode 'r' at 0x0000000002FAA270>
>>> notExist_file = open("D:\\Program Files\\Python\\notFound.txt");

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    notExist_file = open("D:\\Program Files\\Python\\notFound.txt");
IOError: [Errno 2] No such file or directory: 'D:\\Program Files\\Python\\notFound.txt'
>>> 
所以: 1.猜测你的python是不是安装的有问题。 重新安装一下试试。 2.你的python是什么版本的???
叶恭介叶恭介 2013-08-08
  • 打赏
  • 举报
回复
the_file = open('D:\\Program Files\\Python\\test.txt')..好像不用\\,直接\
内容概要:本文系统研究了构网型变流器的正负序阻抗解耦特性及其在弱电网环境下的稳定性表现,重点依托Matlab/Simulink仿真平台,构建了详细的阻抗数学模型,设计了解耦控制策略,并采用小信号扫频法进行频域辨识与稳定性验证。研究深入探讨了构网型变流器与传统跟网型逆变器在正负序阻抗特性上的本质差异,结合虚拟同步发电机(VSG)等先进控制技术,分析其在抑制宽频带振荡、削弱锁相环动态耦合等方面的优越性。文中不仅提供了完整的仿真模型与MATLAB代码实现,还整合了光伏、风电、储能、微电网等多类新能源系统的阻抗建模与稳定性分析资源,形成了一套面向新型电力系统稳定性的综合性技术资料体系,具有较强的科研复现与工程参考价值。; 适合人群:面向具备电力电子、电力系统自动化、新能源并网等专业背景的研究生、高校教师及工程技术人员,特别适用于从事阻抗建模、小干扰稳定性分析、宽频振荡机理研究以及撰写高水平学术论文的科研工作者。; 使用场景及目标:①掌握构网型变流器正负序阻抗建模与扫频辨识的仿真方法;②深入理解VSG等构网型控制在弱电网中提升稳定性的内在机理;③复现顶刊论文中的阻抗分析流程与稳定性判据应用;④利用提供的成熟模型与代码加速科研进程,支撑课题研究与学术成果产出。; 阅读建议:建议结合文中提供的Simulink模型与MATLAB代码,按照“理论建模—仿真搭建—扫频激励—频响提取—Nyquist判据分析”的完整流程进行实践操作,重点关注扫频信号的注入方式、频率范围设置及阻抗曲线的物理意义解读,并参考博士论文复现案例深化对复杂动态耦合问题的理解。

37,738

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧