Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #39241

Re: IOerror : need urgent help

References <CAFqGZREMOm4YSntzwie8o=RmusdV8KzrggY0wK8w4vCXWuwmBw@mail.gmail.com> <5123A03F.1000705@mrabarnett.plus.com>
Date 2013-02-19 16:58 +0100
Subject Re: IOerror : need urgent help
From inshu chauhan <insideshoes@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2039.1361289519.2939.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Tue, Feb 19, 2013 at 4:54 PM, MRAB <python@mrabarnett.plus.com> wrote:

> 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"
>
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>

Thanks I understood the problem now and my programme is working !!

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: IOerror : need urgent help inshu chauhan <insideshoes@gmail.com> - 2013-02-19 16:58 +0100

csiph-web