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


Groups > comp.lang.python > #39239

Re: IOerror : need urgent help

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!feeder3.eweka.nl!81.171.88.16.MISMATCH!eweka.nl!hq-usenetpeers.eweka.nl!xlned.com!feeder3.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'error:': 0.05; 'escape': 0.07; 'subject:help': 0.07; '"w")': 0.09; 'backslash': 0.09; 'ioerror:': 0.09; 'literal': 0.09; 'rows': 0.09; 'tab': 0.09; 'stored': 0.10; "'/'": 0.16; "(it's": 0.16; '(windows': 0.16; 'backslashes': 0.16; 'csv': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'initially,': 0.16; 'literal,': 0.16; 'literals': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'recognise': 0.16; 'sequence,': 0.16; 'traceback.': 0.16; 'writer': 0.16; 'string': 0.17; 'wrote:': 0.17; 'skip:g 40': 0.17; 'subject:need': 0.17; 'equivalent': 0.20; 'skip:" 40': 0.20; 'import': 0.21; 'occurs': 0.22; "skip:' 40": 0.22; 'allows': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; '(most': 0.27; 'raw': 0.27; 'merge': 0.27; 'character.': 0.29; 'character': 0.29; 'starts': 0.29; 'folder': 0.30; 'mode': 0.30; 'subject: : ': 0.30; 'file': 0.32; 'received:84': 0.32; 'says': 0.33; 'traceback': 0.33; 'to:addr :python-list': 0.33; 'equal': 0.33; "can't": 0.34; 'path': 0.35; 'sequence': 0.35; 'but': 0.36; 'should': 0.36; 'why': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'skip:" 10': 0.40; 'received:192.168': 0.40; "you'll": 0.62; 'here': 0.65; 'header:Reply-To:1': 0.68; 'programme': 0.69; 'reply-to:no real name:2**0': 0.72; 'reply-to:addr:python.org': 0.84; 'treats': 0.84; 'subject:urgent': 0.91
X-CM-Score 0.00
X-CNFS-Analysis v=2.0 cv=HO4d4PRv c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=Tv4_tr9OjFAA:10 a=HlIS5AWzDbMA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=3rq6i3jQHLoA:10 a=RDpiW2QZg4ijr4DAd-sA:9 a=wPNLvfGTeEIA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117
X-AUTH mrabarnett:2500
Date Tue, 19 Feb 2013 15:54:39 +0000
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130107 Thunderbird/17.0.2
MIME-Version 1.0
To python-list@python.org
Subject Re: IOerror : need urgent help
References <CAFqGZREMOm4YSntzwie8o=RmusdV8KzrggY0wK8w4vCXWuwmBw@mail.gmail.com>
In-Reply-To <CAFqGZREMOm4YSntzwie8o=RmusdV8KzrggY0wK8w4vCXWuwmBw@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To python-list@python.org
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2037.1361289281.2939.python-list@python.org> (permalink)
Lines 47
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1361289281 news.xs4all.nl 6909 [2001:888:2000:d::a6]:46773
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:39239

Show key headers only | View raw


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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: IOerror : need urgent help MRAB <python@mrabarnett.plus.com> - 2013-02-19 15:54 +0000

csiph-web