Re: [Tutor] Unpack requires a string argument of length 8

2011-05-03 Thread Jim Richardson
On Mon, May 2, 2011 at 1:17 PM, Marc Tompkins  wrote:
> On Mon, May 2, 2011 at 12:36 PM, Susana Iraiis Delgado Rodriguez
>  wrote:
>>
>> I'm working on getting information that comes from a dbf file (database),
>> this dbf file is related to another file in the system, a shapefile. My code
>> is trying to get all the dbf name records, but when the systen gets an empty
>> file, my code fails:
>> Traceback (most recent call last):
>>   File "", line 1, in 
>>   File "get_dbf.py", line 32, in 
>>     dbf = Dbf(d,new=False, readOnly=True)
>>   File "C:\Python26\lib\site-packages\dbf.py", line 135, in __init_
>>     self.header = self.HeaderClass.fromStream(self.stream)
>>   File "C:\Python26\lib\site-packages\header.py", line 109, in from
>>     (_cnt, _hdrLen, _recLen) = struct.unpack("> struct.error: unpack requires a string argument of length 8
>> >>>
>> How can I fix it?
>
> You said that this happens when you're trying to process an empty file.  If
> that's the case, then I would certainly expect this: "_data[4:12]"  not to
> return a string of length 8!
>
> So you have two options:
> - "Get permission"
>>
>> if (some check to make sure the file isn't empty):
>>     dbf = Dbf(d,new=False, readOnly=True)
>
> or
> - "Ask forgiveness".
>>
>> try:
>>     dbf = Dbf(d,new=False, readOnly=True)
>> except:
>>     (cleanup code to handle aborted file opening)
>>
>
> Which is correct?  That depends on your own preference, and also on how
> often the error occurs.  If you rarely run across empty files, then "ask
> forgiveness" makes more sense, since otherwise you waste time checking for
> an error that hardly ever happens; on the other hand, if you run into lots
> of empty files, then it makes sense to check first, each time.


Also, the first option does leave the possibility of a race condition,
however slim that might be.

Personally, I'd use the try/except pair, and optimize later if it
turned out to be an issue.

-- 
http://neon-buddha.net
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Medical Decision-Making Question

2011-06-13 Thread Jim Richardson
On Mon, Jun 13, 2011 at 7:22 AM, Fred G  wrote:
> Hello--
> I'm a pre-med student interested in decision-making as applied to medical
> decisions.  I am trying to build a medical decision-making algorithm and am
> pretty stuck on a few things.
> I've built a file that contains a list of many diseases and their associated
> symptoms.  For example, here are the column headers and two sample rows (the
> "|" = "or"):
> Disease                Symptoms
> Cold
> sore_throat|runny_nose|congestion|cough|aches|slight_fever
> Flu
> sore_throat|fever|headache|muscle_aches|soreness|congestion|cough|returning_fever
> My questions are the following:
> a)  How's the best way to make it so I can have a user type in a list of
> symptoms and then have the computer tell the user the possible diseases that
> share those symptoms? In other words, on a high-level I have a pretty good
> idea of what I want my algorithm to do-- but I need help implementing the
> basic version first.  I'd like to do the following:
Please enter a list of symptoms
[user_input]
Possible diseases include: x, y, z
> b)Once I get that working, could anyone point me to good code already
> written in Python such that I could have a model (for syntax and overall
> structure) for figuring out how to make the computer evaluate more factors
> such as: patient age, patient history, and even downloading archival data
> for patients in the same demographic group?
> Thanks!
>
>



One problem with writing the symptoms is misspelling and word choice,
is mild fever the same as slight fever? etc.

Another way to do that is to present a list, when the user selects one
item in that list, (say, fever, mild) the list is restructured to
exclude symptoms that would clash with that, like all the other
fevers.  After a while of clicking on list items, the evaluator can
make a best match against diseases.  Downside is a fair amount of
processing.

You could also group symptoms and have severity as a seperate, so you
select fever, then mild,high, whatever.

Evaluating it is going to be fun, it's a lot more than binary matches.



-- 
http://neon-buddha.net
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Medical Decision-Making Question

2011-06-13 Thread Jim Richardson
On Mon, Jun 13, 2011 at 3:35 PM, Fred G  wrote:
> Thanks guys for all the feedback.
> re Jim's comments: I completely agree that the difference b/t "slight" fever
> and "returning" fever, etc will pose some problems.  My hunch is that
> initially I'll just do something like make "fever" be the only one for now
> w/ the obvious caveat that a few more diseases would not be eliminated than
> actually should be.  Building on this, another challenging problem will be
> how to code the fact that when a symptom occurs early it usually means
> something else than if it returns later in the course of an illness.  I'm
> not 100% sure how I'll handle this, but I think the first priority is
> getting access to a dataset and getting the bot up and running before I
> focus on this.
> re Steve's comments: hmm, sounds like I really should take an AI class.
>  This problem is just really exciting and driving me, and I'm glad you
> pointed out that this will probably take a lot more time than I had
> predicted.  I'm pretty motivated personally to solve it.  I had a few more
> questions about your code:
> a) Why did you choose not to use a dictionary to store the diseases (keys)
> and their possible values (symptoms)?  That seemed the most intuitive to me,
> like, what I want to do is have it such that we enter in a few symptoms and
> then all the keys without those symptoms are automatically eliminated.  I've
> been off and on teaching myself python for the last 6 months and have
> experience in Java.  I mean, I think I want a structure like this:


If you are going to use dicts, I'd suggest you flip it around, have
the symptom be the key, and the list of diseases related to a given
symptom, be the value.

But that sounds more like a map:reduce problem or an sql query problem
than a dict one.   I haven't used it in over 20 years, and I was no
expert then, but this sounds like a prolog problem :) To maintain the
pythonical nature of the list, https://bitbucket.org/cfbolz/pyrolog/
is something I found. Looks interesting.




> 1) Main class
> -this class calls the diagnose_disease class based on the set of entered
> symptoms and demographic information (ie age, location, season (winter,
> spring, fall, etc), patient history)
> 2) Diagnose_disease class
> -this is the heart of the project.  Based on the entered symptoms, it keeps
> narrowing down the list of possible diseases.  Ideally it would ask
> follow-up questions of the user to even further narrow down the list of
> possible diseases, but that's going to have to wait until I get the rest
> working.
> 3) Dictionary Class
> -this class contains a *dictionary??* of all possible diseases and their
> associated symptoms.  Assuming in a standardized form for now (such that
> "slight_fever" and "returning_fever" are simply coded as "fever" for now,
> etc).
> does this seem like the best way to go about it?
> re: James.  I completely agree that my first step should be getting access
> to a dataset.  I need to know the format, etc of it before I really can
> progress on this.
>
>



-- 
http://neon-buddha.net
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor