简体   繁体   English

打开功能不返回文件描述符

[英]open function not returning file descriptor

Python open function does not return file descriptor. Python open函数不返回文件描述符。 Why could this be? 为什么会这样呢? I am using python 3.3. 我正在使用python 3.3。

test_file_open.py test_file_open.py

#!/usr/bin/env python

import sys
if __name__ == '__main__':
    html = ""
    hmtl_fd = open("ns_temp.html",'r')
    for line in html_fd:
        html += line

Output: 输出:

Traceback (most recent call last):
  File "./test_file_open.py", line 7, in <module>
    for line in html_fd:
NameError: name 'html_fd' is not defined

Permissions: 权限:

-rwxr-xr-x 1 michael michael 160 Mar 16 23:03 test_file_open.py

There is a typo in a variable name, see hmtl_fd and html_fd . 变量名中有一个错字,请参阅hmtl_fdhtml_fd

Replace: 更换:

hmtl_fd = open("ns_temp.html",'r')

with: 与:

html_fd = open("ns_temp.html",'r')

hmtl_fd :用hmtl_fd代替html_fd

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM