[Tutor] Fwd: arrangement of datafile

Keith Winston keithwins at gmail.com
Sun Jan 5 21:23:21 CET 2014


I should have included an example. If you can, and if it doesn't make your
file too long, and if I'm right that this is easy to do in the output
module of wherever this is coming from, add some white space so you can
read/debug easier, though it's not at all necessary (strings have to be
quoted also: see below):

[2, ALA, {C: 178.255, CA: 53.263, CB: 18.411,,,,,,,,,,}]

This is ready to be accessed: If I do this at the command prompt:

shift = [2, "ALA", {"C": 178.255, "CA": 53.263, "CB": 18.411}]

Then:

shift[0] returns 2
shift[2]['CA'] returns 53.263

And if you had a bunch of these in a list shift_list[] (like your original
data set), you could do things like

for i in shift_list:
    for atom in shift_list[i][2]:
        return shift_list[i][2][atom]

I didn't check this code, it's pretty much guaranteed to be wrong but I
think it might point in the right direction.

I think I made this a little more complicated than it needs to be, but I
have to run right now. Maybe this is helpful. Good luck!

Actually, I think shift needs to be a class... but that's just my nascent
OOP comment.

Keith




On Sun, Jan 5, 2014 at 3:01 PM, Keith Winston <keithwins at gmail.com> wrote:

> Hi Amrita, I'm just a beginner but I notice that, after the first two
> entries on each line (i.e. 10,ALA), the rest might fit nicely into a dict,
> like this {H: 8.388, HB1: 1.389, ...}. That would give you a lot of
> flexibility in getting at the values later. It would be easy enough to
> replace the "=" with ':", and add some curly braces. In fact, if you
> enclosed each line in square braces, changed =/: and added the curly braces
> on the dict, then each line would already be a list containing a
> dictionary, and you'd be ready to do some rearranging very easily.
>
> Whether you do that in Python or when you are building your file in
> whatever system it's coming from is your call. If you left off the outer
> braces, each line is a tuple containing a dict, which works too.
>
> Sorry if all I've done is state the obvious here. I warned you I'm a
> beginner.
>
>


-- 
Keith
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140105/23e76cd4/attachment.html>


More information about the Tutor mailing list