I am using feedparser to parse RSS feed from spotcrime
However, I am getting "no attribute" error whenever I'm trying to loop through the entries to get the 'geo_long' and 'geo_lat' attribute.
If I don't loop than it works fine:
f = feedparser.parse(link)
entries = f.entries
print entries[0].geo_long
But when I do it in a loop like this, it starts giving me error
for e in entries:
print e.geo_long
And this error is only for geo_long/geo_lat/where attribute on my feed. Other attributes work just fine when accessed in a loop. Can someone please let me know the problem? Thanks
I found a way to go around this by using e.get('geo_long') instead and it worked. Still don't know why the other way does not work though
Related
I'm very new to robot framework. This question is about creating a list variable using Xpath.
I'm trying to write a FOR LOOP in robot in order to print all items that appear on a search result page. Here is what I've done so far:
I tried to declare a list variable using Xpath:
#{product} //div[contains(#class,'ProductCard__TitleMaxLines')]
This Xpath has the number of repetitions the same as the number of items on the page, e.g. 20, so I assume that this list will contain 20 members. --> Is this how it works?
I created a For loop:
${index} Set variable 1
For ${product} in #{related_product}
Exit for loop if ${index} > 20
Log to console ${product}
${index} Evaluate ${index}+1
End
For this, I assume that it will take the first product found on the Xpath to be index=1, and the next index=2, and so on.
That's all I've done so far. Please advise if this works correctly or if there is another way that is better and more typical.
I think your question is, you have similar kind of xpath around 20 times in the webpage. If my understanding is correct, you should use the Get Webelements keyword from Selenium Library.
#{product} Get Webelements //div[contains(#class,'ProductCard__TitleMaxLines')]
The above line will create the list of webelements which having the same xpath
I have a little problem getting the result i wanted from the data that i have.
I tried index match match and vlook up match but it doesnt give me the result that i wanted.
Please see the sample data that I have. DATA 1
I wanted to get the # of hours based from this table TABLE
Can someone help me get the correct syntax for this please?
Tried several things to go around the with formulas but ended up either just 1 result for the whole column or an error. Thanks
up for this.
I created a scikit learn model endpoint inside AWS Sagemaker. I want to make predictions on my test set using this endpoint. My endpoint creation code looks like
predictor = sklearn.deploy(1, 'ml.m4.xlarge')
from sagemaker.predictor import csv_serializer
predictor.content_type = 'text/csv'
predictor.serializer = csv_serializer
predictor.deserializer = None
When I pass my test data point as a list predictor.predict(l) where l is the list, it throws an error
ValueError: Expected 2D array, got 1D array instead:
When I pass it as a numpy array of 2 dimensions(I checked dimensions using .ndim), it still throws the same error. When I tried to pass the data as a string separated by commas without any spaces, it still throws the same error.
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
This line gets displayed every time the Valueerror is thrown but even after reshaping, the same error persists.
So I have tried the formats '2,3,4,5', ['2,3,4,5'], array[[2,3,4,5]],[2,3,4,5] but none of these work.
Can someone please convey what the right format is for the input to the predictor function of sci-kit learn?
Are you still having problems with your input dimensions? Users are able to implement their own input_fn in order to help with debugging as well. I suggest you try printing the deserialized input when it is passed to the inference call to see where you might be having trouble with the dimension size.
Relatively new to crystal and I've hit a bit of a snag with a formula.
I'm trying to create a formula that will report out when an RMA was received and how many. If none of the items have been received, I want it to show a message stating such, but if items from the RMA have been received I want it to return the receipt number.
Since a picture is worth a thousands words...
Current report view
I tried using an if then but I don't think you can combine strings with BAQReportResult values.
if {BAQReportResult.RMARcpt.OurReceivedQty}>0 then {BAQReportResult.RMARcpt.RMAReceipt}
After that I tried a variety of else statements but stuck here I am...
Any help is greatly appreciated!
I think you must declare a string type and then assign the value in else part.
Create a Formula and place in the Report, what has to be written in formula will be like:
stringvar text:="";
if {BAQReportResult.RMARcpt.OurReceivedQty}>0 then
text="{BAQReportResult.RMARcpt.RMAReceipt}"
else
text="There are ..."
I'm just starting to explore Xlrd, and to be honest am pretty new to programming altogether, and have been working through some of their simple examples, and can't get this simple code to work:
import xlrd
book=open_workbook('C:\\Users\\M\\Documents\\trial.xlsx')
sheet=book.sheet_by_index(1)
cell=sheet.cell(0,0)
print cell
I get an error: list index out of range (referring to the 2nd to last bit of code)
I cut and pasted most of the code from the pdf...any help?
You say:
I get an error: list index out of range (referring to the 2nd to last
bit of code)
I doubt it. How many sheets are there in the file? I suspect that there is only one sheet. Indexing in Python starts from 0, not 1. Please edit your question to show the full traceback and the full error message. I suspect that it will show that the IndexError occurs in the 3rd-last line:
sheet=book.sheet_by_index(1)
I would play around with it in the console.
Execute each statement one at a time and then view the result of each. The sheet indexes count from 0, so if you only have one worksheet then you're asking for the second one, and that will give you a list index out of range error.
Another thing that you might be missing is that not all cells exist if they don't have data in them. Some do, but some don't. Basically, the cells that exist from xlrd's standpoint are the ones in the matrix nrows x ncols.
Another thing is that if you actually want the values out of the cells, use the cell_value method. That will return you either a string or a float.
Side note, you could write your path like so: 'C:/Users/M/Documents/trial.xlsx'. Python will handle the / vs \ on the backend perfectly and you won't have to screw around with escape characters.