Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #39239 > unrolled thread
| Started by | MRAB <python@mrabarnett.plus.com> |
|---|---|
| First post | 2013-02-19 15:54 +0000 |
| Last post | 2013-02-19 15:54 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: IOerror : need urgent help MRAB <python@mrabarnett.plus.com> - 2013-02-19 15:54 +0000
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2013-02-19 15:54 +0000 |
| Subject | Re: IOerror : need urgent help |
| Message-ID | <mailman.2037.1361289281.2939.python-list@python.org> |
On 2013-02-19 15:27, inshu chauhan wrote:
> Here is my attempt to merge 10 files stored in a folder into a single file :
>
> import csv
>
> with open("C:\Users\inshu.chauhan\Desktop\test.arff", "w") as w:
> writer = csv.writer(w)
> for f in glob.glob("C:\Users\inshu.chauhan\Desktop\For
> Model_600\*.arff"):
> rows = open(f, "r").readlines()
> writer.writerows(rows)
>
>
> Error:
>
> Traceback (most recent call last):
> File "C:\Users\inshu.chauhan\Desktop\Mergefiles.py", line 3, in <module>
> with open("C:\Users\inshu.chauhan\Desktop\test.arff", "w") as w:
> IOError: [Errno 22] invalid mode ('w') or filename:
> 'C:\\Users\\inshu.chauhan\\Desktop\test.arff'
>
> Why my programme is not working ?? :(
>
Look at the traceback. It says that the path is:
'C:\\Users\\inshu.chauhan\\Desktop\test.arff'
All but one of the backslashes are doubled.
That's because the backslash character \ starts an escape sequence, but
if it can't recognise the escape sequence, it treats the backslash as a
literal character.
In that string literal, '\t' is an escape sequence representing a tab
character (it's equal to chr(9)), but '\U', '\i' and '\D' are not
escape sequences, so they are equivalent to '\\U, '\\i' and '\\D'
respectively.
What you should do is use raw string literals for paths:
r"C:\Users\inshu.chauhan\Desktop\test.arff"
or use '/' instead (Windows allows it as an alternative, unless it
occurs initially, which you'll rarely want to do in practice):
"C:/Users/inshu.chauhan/Desktop/test.arff"
Back to top | Article view | comp.lang.python
csiph-web