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


Groups > comp.lang.python > #34537

Re: TypeError: 'in <string>' requires string as left operand, not Element

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!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; 'root': 0.04; 'builtin': 0.07; 'lines.': 0.07; 'root,': 0.07; 'try:': 0.07; 'type,': 0.07; 'python': 0.09; 'block.': 0.09; 'files:': 0.09; 'subject: <': 0.09; 'subject:string': 0.09; 'typeerror:': 0.09; 'subject:not': 0.11; 'value.': 0.15; "'r')": 0.16; 'dirs,': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'printout': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'statements,': 0.16; 'stuff.': 0.16; 'subject: \n ': 0.16; 'variable.': 0.16; "where's": 0.16; '{0}': 0.16; 'string': 0.17; 'wrote:': 0.17; 'element': 0.17; 'define': 0.20; 'file:': 0.22; 'parse': 0.22; "i'd": 0.22; 'cheers,': 0.23; 'idea': 0.24; 'header :In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'looks': 0.26; 'skip:" 20': 0.26; '(most': 0.27; 'guess': 0.27; 'tree': 0.27; "doesn't": 0.28; 'run': 0.28; 'received:192.168.1.3': 0.29; 'types.': 0.29; 'probably': 0.29; "i'm": 0.29; 'error': 0.30; 'asking': 0.32; 'file': 0.32; 'received:84': 0.32; 'print': 0.32; 'getting': 0.33; 'instead,': 0.33; 'traceback': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'along': 0.35; 'pm,': 0.35; 'except': 0.36; 'but': 0.36; 'skip:{ 10': 0.36; 'xml': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'skip:o 20': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'your': 0.60; 'subject:, ': 0.61; 'strange': 0.62; 'different': 0.63; 'show': 0.63; 'header:Reply- To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'reply- to:addr:python.org': 0.84; 'upset': 0.84; 'victor': 0.84; 'angel': 0.93
X-CM-Score 0.00
X-CNFS-Analysis v=2.0 cv=O5K7TWBW c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=O2Kvzccb_dQA:10 a=bZJ_09fqvKUA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=UEXIiadrj88A:10 a=yajjupMj0H4M1tSaSXUA:9 a=wPNLvfGTeEIA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117
X-AUTH mrabarnett:2500
Date Mon, 10 Dec 2012 02:42:50 +0000
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/17.0 Thunderbird/17.0
MIME-Version 1.0
To python-list@python.org
Subject Re: TypeError: 'in <string>' requires string as left operand, not Element
References <8c78344a-8019-450a-bfdf-13508bf75292@googlegroups.com> <50C538A2.20301@davea.name>
In-Reply-To <50C538A2.20301@davea.name>
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.669.1355107363.29569.python-list@python.org> (permalink)
Lines 49
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1355107363 news.xs4all.nl 6873 [2001:888:2000:d::a6]:37268
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:34537

Show key headers only | View raw


On 2012-12-10 01:19, Dave Angel wrote:
> On 12/09/2012 07:52 PM, Victor Hooi wrote:
>> Hi,
>>
>> I'm getting a strange error when I try to run the following:
>>
>>     for root, dirs, files in os.walk('./'):
>>         for file in files:
>>             if file.startswith('ml') and file.endswith('.xml') and 'entity' not in file:
>>                 print(root)
>>                 print(file)
>>                 with open(os.path.join(root, file), 'r') as f:
>>                     print(f.name)
>>                     try:
>>                         tree = etree.parse(f)
>>                         root = tree.getroot()
>>                         print(f.name)
>>                         print(root.tag)
>>                     except xml.parsers.expat.ExpatError as e:
>>                         print('Unable to parse file {0} - {1}'.format(f.name, e.message))
>>
>
> Where's the printout of the root and file variables?  You're asking
> os.path.join to work on them, and it's clearly upset about their types.
> I see print statements, so you clearly were thinking along these lines.
> But you don't show them.  BTW, I'd be using  print(repr(root)) and
> print(repr(file)) instead, so you get a better idea of their type and value.
>
> My guess for the problem is that you're trashing 'root' with the
> contents of your try block.  Try using a different name for the xml stuff.
>
>> The error is:
>>
>> Traceback (most recent call last):
>>   File "foo.py", line 275, in <module>
>>     marketlink_configfiles()
>>   File "foo.py", line 83, in bar
>>     with open(os.path.join(root, file), 'r') as f:
>>   File "C:\Python27\lib\ntpath.py", line 97, in join
>>     if path[-1] in "/\\":
>> TypeError: 'in <string>' requires string as left operand, not Element
>>
>> Cheers,
>> Victor
>
> Incidentally, 'file' is a builtin type, so it's probably not a good idea
> to hide it by using it as your own local variable.
>
It looks like Python 3 to me, which doesn't define 'file'.

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


Thread

TypeError: 'in <string>' requires string as left operand, not Element Victor Hooi <victorhooi@gmail.com> - 2012-12-09 16:52 -0800
  Re: TypeError: 'in <string>' requires string as left operand, not Element Roy Smith <roy@panix.com> - 2012-12-09 20:08 -0500
  Re: TypeError: 'in <string>' requires string as left operand, not Element Victor Hooi <victorhooi@gmail.com> - 2012-12-09 17:09 -0800
  Re: TypeError: 'in <string>' requires string as left operand, not Element Dave Angel <d@davea.name> - 2012-12-09 20:19 -0500
  Re: TypeError: 'in <string>' requires string as left operand, not Element MRAB <python@mrabarnett.plus.com> - 2012-12-10 02:42 +0000

csiph-web