Cleaning up conditionals

Deborah Swanson python at deborahswanson.net
Mon Jan 2 17:52:00 EST 2017


Dennis Lee Bieber wrote on January 02, 2017 8:30 AM
> 
> On Sun, 1 Jan 2017 18:30:03 -0800, "Deborah Swanson" 
> <python at deborahswanson.net> declaimed the following:
> 

<snip>
> 	Out of curiosity -- don't those listings have street 
> addresses? There must be lots of "2 br" units in the city.
> 

<snip>

> 	Part of the hassle in your schema is that you are 
> treating the type of unit (2 br) AND the city (as shown in 
> your sample; I'd hope a full address is available) as a 
> single data field. Similarly, you have some obscure code 
> attached to the state.

haha - what schema?

But seriously, I've loosely had one in mind all along, and there are
currently 14 columns for each listing. I've just only mentioned the
fields involved in the conditional problem I was having. One of those
fields (br) is for bedrooms, and another couple I'll add later will be
for address, phone, and local features, which may be pulled from my
locations dictionary. The Descriptions I made up for my example are very
simple short ones. Real webpage titles from Craigslist are frequently
very long, complex and full of typos. I go fishing in them for most of
the data, but I don't plan on making any effort to clean them up.

I think it was you who asked another question that I didn't answer at
the time, of why I used those weird 2-letter codes for the field names.
It's rather stupidly simple. Since the "database" will be in flux for
some time, with columns being moved around, added and deleted, I came up
with this little scheme that executes right after the csv has been
opened and read into ls[], to avoid having to change any of the
subscripts in my code whenever the columns changed:

flds = len(ls[0])
cl, ur, d1, de, lo, st, mi, ki, re, da, br, no, yn, ma, ar =
range(0,flds)

ls[0] is the title row, so the range is automatically sized to the
number of columns in the current csv. If I open a csv with more columns
than last time, I hit an IndexError right off, which is a handy reminder
if I've forgotten to update the field codes. I'd welcome anyone's
improvement on this scheme, if it accomplishes the same result.

Also, 'kind' is for the kind of property. I want a house, but I'd
consider a cottage, trailer or manufactured home if it's nice and has a
garage or a carport. And I want 2 bedrooms (one for my office), but I'm
keeping track of 1 brs & even nice studio cabins, just in case I really
need to get out of here and into something I can afford quickly. I've
also tried to screen the plexes (duplex, triplex, six-plex and what
all), apartments, condos and other undesirable "kinds" out of my
searches, but they still slip into the results anyway. Craigslist's
search function leaves much to be desired. So 'kind' also serves as a
place to snag them for later deletion. And it's a red flag when one
listing for a property comes up with 'kind' = 'house' and another comes
up 'duplex'. For some reason people like to pretend their duplexes are
houses, and sometimes they change their titles from duplex to house
after they've had to relist it a couple of times. Or they don't say what
kind of property it is, and I have to pull up the ad and look at it.

Details, details, details. ;)
D.



More information about the Python-list mailing list