简体   繁体   English

Python 3.2.2 open('C:\\ file.txt')不起作用

[英]Python 3.2.2 open('C:\file.txt') doesn't work


Admittedly, I am a novice; 不可否认,我是新手; however, (I think) I did what the tutorial said (for the version I installed) and I can't get Python to read a file. 但是,(我认为)我做了教程所说的(对于我安装的版本),我无法让Python读取文件。 Others have had problems with long file names or paths, but I kept mine short and sweet... so I thought. 其他人有长文件名或路径的问题,但我保持简短和甜蜜...所以我想。
The file itself contains one word on a single line. 文件本身在一行中包含一个单词。
The print('string') works, len('string') works... print('string')有效,len('string')有效......

Here's what I got, in IDLE and CMD, even before using the import statements included below: 这是我在IDLE和CMD中得到的,甚至在使用下面的import语句之前:

Python 3.2.2 (default, Sep 4 2011, 09:07:29) [MSC v.1500 64 bit (AMD64)] on win32 win32上的Python 3.2.2(默认,2011年9月4日,09:07:29)[MSC v.1500 64位(AMD64)]

Type "copyright", "credits" or "license()" for more information. 输入“copyright”,“credits”或“license()”以获取更多信息。

import os, csv, urllib import os,csv,urllib

f0txt = () f0txt =()

f0txt = open("C:\\try\\in0.txt") f0txt = open(“C:\\ try \\ in0.txt”)

Traceback (most recent call last): Traceback(最近一次调用最后一次):

File " <pyshell#4 >", line 1, in 文件“ <pyshell#4 >”,第1行,in

f0txt = open("C:\\try\\in0.txt") f0txt = open(“C:\\ try \\ in0.txt”)

IOError: [Errno 22] Invalid argument: 'C:\\try\\in0.txt' IOError:[Errno 22]参数无效:'C:\\ try \\ in0.txt'

\\ is an escape character. \\是一个逃脱角色。 Try open(r"C:\\try\\in0.txt") or open("C:\\\\try\\\\in0.txt") . 尝试open(r"C:\\try\\in0.txt")open("C:\\\\try\\\\in0.txt")

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

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