The Lookup, Hlookup, and Vlookup functions in Excel are pretty bad. I found that they die with #VALUE, or #N/A if they don’t find the value you’re looking up, and today I found that my lookup function was only looking for the first word in my lookup value!
So here is a better lookup function to use in Excel when you want it to return a specified default value if your value is not found:
Read the rest of this entry »
Posted by Greg Pinero (Primary Searcher) as win32, Excel at 4:20 PM MST
2 Comments »
Why do this?
I made a small Python-based website that outputs results based on user supplied data from a form. The form is submitted using POST but I wanted to let people bookmark or link to their results which requires creating a link which includes all of the data that generated their page.
Here’s how I did it:
Instead of converting the whole site to use GET, I wrote this conversion function that works with Python’s cgi module:
This is the function:
#do these imports somewhere in your module of course.
import cgi
import urllib
def convertpost_to_get(baseurl,postdata):
"""Convert POST data into get data and return the Get url.
This is useful for creating a "link to this page" or "bookmark this page"
type of link for your post results.
"""
if not postdata.keys():
return baseurl
query_items=[(key,postdata.getfirst(key)) for key in postdata.keys()]
baseurl+='?'+urllib.urlencode(query_items,0)
return baseurl
This is how you would use it:
import cgi
form = cgi.FieldStorage()
url_linkback=convertpost_to_get(
baseurl=r"http://www.yourURL.com/index.py",postdata=form)
print '<a href="%s">Link to this page!</a>' % url_linkback
This all works by taking advantage of the fact that Python’s cgi module doesn’t make a distinction between data passed via GET or via POST (At least for this purpose). So that means when you script gets this link you made, it will behave the same way it does for post data. Well at least it does for me. If you have more complex POST data then your results may vary and you could have to do some tweaking. Definitely let me know what you did and I’ll update this post.
Disclaimer:
I’m fairly new to Python CGI programming, hence I have no idea what I’m doing, but this does work for me. Caveat emptor
Update:
I modified this to encode the url parameters with urllib.urlencode. It will now work even if you have amperstands and such in your data.
Tags: Python CGI, GET, POST, HTTP GET, HTTP POST
Posted by Greg Pinero (Primary Searcher) as Python at 8:30 PM MST
Comments Off
Update:
Here’s a better way provided by Florent Guillaume:
def sign(number):return cmp(number,0)
Here is my original method:
def sign(number):
"""Will return 1 for positive,
-1 for negative, and 0 for 0"""
try:return number/abs(number)
except ZeroDivisionError:return 0
It’s just a function I’ve been thinking would be included somewhere in Python but haven’t been able to find. It’s simple but _I_ searched for it so enjoy!
Terms I searched for:
- python get sign of a number
-
python “get sign”
Posted by Greg Pinero (Primary Searcher) as Python at 1:54 PM MST
2 Comments »
Wikipedia tells us:
These birds feed mainly on plant material. When feeding in water, they submerge their heads and necks to reach aquatic plants, sometimes tipping forward like a dabbling duck. Flocks of these birds often feed on leftover cultivated grains in fields, especially during migration or in winter. They also eat some insects, molluscs and crustaceans.
Why I was curious:
I always see 30-50 of these birds in a field on my way to work every day and they seem to just be pecking in the grass. I can’t fathom what there is for them to eat there. I’d say insects but they appear to be continually eating and there can’t be that many insects. So my best guess so far is that they’re just eating grass. Perhaps I’ll never know.
Tags: canada goose, geese, eating grass
Posted by Greg Pinero (Primary Searcher) as Other, Idle Curiosities at 10:54 AM MST
12 Comments »
I had this problem today and I fixed it my simply changing the position of that blinking cursor to be over some text.
It looks like if your insert point is over a graphic or other non-text element then page setup becomes grayed out for who knows why.
I found this answer here.
If that doesn’t solve your problem I also read about people having corrupted normal.dot files so you could try these instructions.
My search terms were:
- word page setup grayed out
- word + “page setup” + (”grayed out” OR “greyed out”) #google and google groups
Posted by Greg Pinero (Primary Searcher) as win32, Other at 3:29 PM MST
2 Comments »