msg139810 - (view) |
Author: Juan Gonzalez (juan.gonzalez) |
Date: 2011-07-04 21:48 |
Something really weird going on in python find() string function. When I call .find() and python returns -1 it crashes when compared against 0 using the ">" operator. The statement in which crash condition occurs is the following: if url.find(str) > 0: print "RSS Item:", url break; However, if I change the statement to be "<" instead it does not crash. The error that the python compiler reports is: AttributeError: 'int' object has no attribute 'find' My version of python is: tony@ubuntu:~/auto/sel/scripts$ python -V Python 2.7.1+ |
|
|
msg139823 - (view) |
Author: Jesús Cea Avión (jcea) *  |
Date: 2011-07-05 02:20 |
Python 2.7.2 (default, Jun 16 2011, 01:46:46) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> "hola".find("q") > 0 False >>> "hola".find("q") < 0 True I don't see the problem. Please, send a complete testcase. |
|
|
msg139824 - (view) |
Author: Jesús Cea Avión (jcea) *  |
Date: 2011-07-05 02:21 |
Note, anyway, that your python is not a real release. where is it coming from?. |
|
|
msg139830 - (view) |
Author: Georg Brandl (georg.brandl) *  |
Date: 2011-07-05 06:37 |
I suspect this is a problem where "url" is reassigned to an integer somewhere in code that isn't shown to us. Please post the whole function and the whole traceback if you still think this is a valid bug. |
|
|
msg139887 - (view) |
Author: Juan Gonzalez (juan.gonzalez) |
Date: 2011-07-05 16:03 |
Today I tried to use parse() instead of find() and I found out the following response: tony@ubuntu:~/auto/sel/scripts$ python wtfibmdom Traceback (most recent call last): File "wtfibmdom", line 22, in if url.parse(str) > 0: AttributeError: 'str' object has no attribute 'parse' tony@ubuntu:~/auto/sel/scripts$ python wtfibmdom Title: j3-dcsled-prd-validation passed Fri, 01 Jul 2011 14:03:59 -0500 Description: Build passed Traceback (most recent call last): File "wtfibmdom", line 22, in if url.find(str) > 0: AttributeError: 'int' object has no attribute 'find' I think this behavior is inconsistent since the compiler is treating the url variable as int and string at the same time. |
|
|
msg139888 - (view) |
Author: Juan Gonzalez (juan.gonzalez) |
Date: 2011-07-05 16:06 |
Hi Georg, This is the python code listing: from RSS import ns, CollectionChannel, TrackingChannel #Create a tracking channel, which is a data structure that #Indexes RSS data by item URL tc = TrackingChannel() str = 'j3-nspire-prd-validation' index = 0 #Returns the RSSParser instance used, which can usually be ignored #tc.parse("http://www.python.org/channews.rdf") tc.parse("http://pdt-california.eps.ti.com:8080/dashboard/rss.xml") RSS10_TITLE = (ns.rss10, 'title') RSS10_DESC = (ns.rss10, 'description') #You can also use tc.keys() items = tc.listItems() for item in items: #Each item is a (url, order_index) tuple url = item[index] #print "RSS Item:", #str.find(str, beg=0 end=len(string)) if url.find(str) > 0: print "RSS Item:", url break; #Get all the data for the item as a Python dictionary index = index + 1 item_data = tc.getItem(item) print "Title:", item_data.get(RSS10_TITLE, "(none)") print "Description:", item_data.get(RSS10_DESC, "(none)") |
|
|
msg139890 - (view) |
Author: Brian Curtin (brian.curtin) *  |
Date: 2011-07-05 16:08 |
Can you post some example code or a test case? |
|
|
msg139893 - (view) |
Author: Jesús Cea Avión (jcea) *  |
Date: 2011-07-05 16:16 |
Put the failing code inside a "try", and wrote in the "except": "print repr(url)". I am pretty sure your "url" can be, actually, a number. Or print "url" just before the 'faulty' line. I guess you will be surprised. |
|
|
msg139896 - (view) |
Author: Juan Gonzalez (juan.gonzalez) |
Date: 2011-07-05 16:24 |
I print 1 before the faulty line and like Jesús says I'm surprised I get a 1 Description: Build passed 1 Traceback (most recent call last): File "wtfibmdom", line 23, in if url.find(str) > 0: AttributeError: 'int' object has no attribute 'find' |
|
|