[Tutor] extracting lines between patterns.

2012-05-14 Thread Bala subramanian
Friends,
Could someone please give some hint on how to extract lines between two
patterns in a file. I use the re module to compile my patterns but not able
to figure out how i can use these patterns to extract the lines lying in
between.

Thanks,
Bala
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] extracting lines between patterns.

2012-05-14 Thread Russel Winder
On Mon, 2012-05-14 at 09:31 +0200, Bala subramanian wrote:
> Friends,
> Could someone please give some hint on how to extract lines between two
> patterns in a file. I use the re module to compile my patterns but not able
> to figure out how i can use these patterns to extract the lines lying in
> between.

Without the source code you already have, it is difficult to provide any
constructive suggestions.

-- 
Russel.
=
Dr Russel Winder  t: +44 20 7585 2200   voip: sip:russel.win...@ekiga.net
41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder


signature.asc
Description: This is a digitally signed message part
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] extracting lines between patterns.

2012-05-14 Thread delegbede
Give an example. 

Let's see what you've tried and then it becomes clear what help is needed. 

Regards. 
Sent from my BlackBerry wireless device from MTN

-Original Message-
From: Bala subramanian 
Sender: tutor-bounces+delegbede=dudupay@python.org
Date: Mon, 14 May 2012 09:31:41 
To: 
Subject: [Tutor] extracting lines between patterns.

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


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


Re: [Tutor] (no subject)

2012-05-14 Thread Keitaro Kaoru
sorry if i keep missing this up.

hey. Austin here for some reason this command. all it does it produces the
error message at the bottom.. itll say my name and the persons name im
trying to send the message to but thats it. heres the command.


# Imports

from tools import Html, Error, Text, shared_db, log
import urllib.request as urlreq
import urllib.parse as urlpar
import xml.dom.minidom as xdm
import random
import time
import json
import re
import ch

mgr.addCommand("tell", 1, "send a person a message to the rooms he is in",
tell, unlisted = True)

def tell(mgr, croom, user, msg, args):
        name = args.lower().split(" ")[0]
        if not name.isalnum(): return Html("Non-alphanumeric name, seriously?")
        data = shared_db.get("seen:" + name)
        if data == None:
                return Html("I have no records about this user.")
        data = json.loads(data)
        for room in mgr.rooms:
                if data[1] == "join":
                        mgr.sendObject(target,
Html("%s,%s  wants to tell
you%s ", name.title, user.name.title$
        else:
                        return Error("%s  I couldn't find %s
anywhere", user.name.title(), name.title())

i built it off these 2 commands

def broadcast(mgr, croom, user, msg, args):
        for room in mgr.rooms:
                mgr.sendObject(room, Html("Broadcast by%s:%s",
user.name, args))

def seen(mgr, room, user, msg, args):
name = args.lower().split(" ")[0]
if not name.isalnum(): return Html("Non-alphanumeric name, seriously?")
data = shared_db.get("seen:" + name)
if data == None:
        return Html("I have no records about this user.")
data = json.loads(data)
ifdata[1] == "join":
        return Html("Last seen%s  join%s,%s
ago.", name, data[0], tdelta(data[2]))
elif data[1] == "leave":
        return Html("Last seen%s  leave%s,%s
ago.", name, data[0], tdelta(data[2]))
elif data[1] == "message":
        return Html("Last seen%s  message in%s,%s
 ago: \"%s\"", name, data[0], tdelta(data[2]), data[3])
        return Html("I have no records about this user.")

as you can see i only use some of the command. it doesnt produce an error
message tho.. just repeats "return Error("%s  I couldn't find %s
anywhere", user.name.title(), name.title())"



On Sat, May 12, 2012 at 10:28 PM, bob gailer  wrote:
>
> On 5/12/2012 6:34 PM, Keitaro Kaoru wrote:
>
> hey i keep having a problem with adding commands.. i get this error message
>
> Traceback (most recent call last):
>   File "bot.py", line 23, in 
>     import modules.core, modules.ai, modules.dict, modules.fun, modules.kc, 
> modules.games, modules.lulz2, modules.modding, modules.meta, modules.mpd, 
> modules.post, modules.poll, modules.util, modules.yt
>   File "/home/digest/digest/modules/core.py", line 170
>     def pm(mgr, room, user, msg, args):
>       ^
> SyntaxError: invalid syntax
>
> Thanks for posting the traceback. All we need is to see more of the program 
> (especially the lines before the one you posted. It is always a good idea to 
> post more of the code regardless of the problem.
>
> --
> Bob Gailer
> 919-636-4239
> Chapel Hill NC




--
~Keitaro Kaoru-Sama~
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2012-05-14 Thread Keitaro Kaoru
and i also realized my real name isnt on google i am austin but im
guessing u see keitaro kaoru or whatever yeha this is a very old email
account and i cant change the name i use.. lol i made my signature
austin tho maybe thatll help

On Mon, May 14, 2012 at 5:58 AM, Keitaro Kaoru  wrote:
> sorry if i keep missing this up.
>
> hey. Austin here for some reason this command. all it does it produces the
> error message at the bottom.. itll say my name and the persons name im
> trying to send the message to but thats it. heres the command.
>
> 
> # Imports
> 
> from tools import Html, Error, Text, shared_db, log
> import urllib.request as urlreq
> import urllib.parse as urlpar
> import xml.dom.minidom as xdm
> import random
> import time
> import json
> import re
> import ch
>
> mgr.addCommand("tell", 1, "send a person a message to the rooms he is in",
> tell, unlisted = True)
>
> def tell(mgr, croom, user, msg, args):
>         name = args.lower().split(" ")[0]
>         if not name.isalnum(): return Html("Non-alphanumeric name, 
> seriously?")
>         data = shared_db.get("seen:" + name)
>         if data == None:
>                 return Html("I have no records about this user.")
>         data = json.loads(data)
>         for room in mgr.rooms:
>                 if data[1] == "join":
>                         mgr.sendObject(target,
> Html("%s,%s  wants to tell
> you%s ", name.title, user.name.title$
>         else:
>                         return Error("%s  I couldn't find %s
> anywhere", user.name.title(), name.title())
>
> i built it off these 2 commands
>
> def broadcast(mgr, croom, user, msg, args):
>         for room in mgr.rooms:
>                 mgr.sendObject(room, Html("Broadcast by%s:%s",
> user.name, args))
>
> def seen(mgr, room, user, msg, args):
> name = args.lower().split(" ")[0]
> if not name.isalnum(): return Html("Non-alphanumeric name, seriously?")
> data = shared_db.get("seen:" + name)
> if data == None:
>         return Html("I have no records about this user.")
> data = json.loads(data)
> ifdata[1] == "join":
>         return Html("Last seen%s  join%s,%s
> ago.", name, data[0], tdelta(data[2]))
> elif data[1] == "leave":
>         return Html("Last seen%s  leave%s,%s
> ago.", name, data[0], tdelta(data[2]))
> elif data[1] == "message":
>         return Html("Last seen%s  message in%s,%s
>  ago: \"%s\"", name, data[0], tdelta(data[2]), data[3])
>         return Html("I have no records about this user.")
>
> as you can see i only use some of the command. it doesnt produce an error
> message tho.. just repeats "return Error("%s  I couldn't find %s
> anywhere", user.name.title(), name.title())"
>
>
>
> On Sat, May 12, 2012 at 10:28 PM, bob gailer  wrote:
>>
>> On 5/12/2012 6:34 PM, Keitaro Kaoru wrote:
>>
>> hey i keep having a problem with adding commands.. i get this error message
>>
>> Traceback (most recent call last):
>>   File "bot.py", line 23, in 
>>     import modules.core, modules.ai, modules.dict, modules.fun, modules.kc, 
>> modules.games, modules.lulz2, modules.modding, modules.meta, modules.mpd, 
>> modules.post, modules.poll, modules.util, modules.yt
>>   File "/home/digest/digest/modules/core.py", line 170
>>     def pm(mgr, room, user, msg, args):
>>       ^
>> SyntaxError: invalid syntax
>>
>> Thanks for posting the traceback. All we need is to see more of the program 
>> (especially the lines before the one you posted. It is always a good idea to 
>> post more of the code regardless of the problem.
>>
>> --
>> Bob Gailer
>> 919-636-4239
>> Chapel Hill NC
>
>
>
>
> --
> ~Keitaro Kaoru-Sama~



-- 
~Keitaro Kaoru-Sama~
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] hello~

2012-05-14 Thread Keitaro Kaoru
i resent it but if that doesnt work. cause i sent it to myself also
looks fine on my gmail.. but heres a link to pastebin

http://pastebin.com/Jp7VJKGB
 maybe thatll help?
On Mon, May 14, 2012 at 1:43 AM, Russel Winder  wrote:
> On Mon, 2012-05-14 at 00:19 +0100, Mark Lawrence wrote:
> [...]
>> Sorry but it's unreadable to me.  Have you sent this in HTML when you
>> should have sent in plain text?
>
> I think it is just line wrapping, email still is supposed to have no
> lines greater that 78 characters (RFC 2822) and some email clients
> enforce this on sending by amending what the author thought they sent.
>
> --
> Russel.
> =
> Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.win...@ekiga.net
> 41 Buckmaster Road    m: +44 7770 465 077   xmpp: rus...@winder.org.uk
> London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



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


Re: [Tutor] extracting lines between patterns.

2012-05-14 Thread Bala subramanian
The code is given below. Here i try to extract lines that are between the
two patterns atomtype and mol.type

#!/usr/bin/env python
import re
mypat=re.compile(r'^[ atomtypes ]$[ moleculetype ]',re.MULTILINE)
data=open('test.dat').read()
extr=re.findall(mypat,data)
print extr

The data file is something like the following,
[ defaults ]
; nbfunccomb-rule   gen-pairs   fudgeLJ fudgeQQ
1   2   no  0.5 0.8333

[ atomtypes ]
;name   bond_type mass charge   ptype
 N3   N3  0.0  0.0A
 HH   0.0  0.0  A
 CT   CT  0.0  0.0   A
 HP   HP  0.0  0.0   A
 O2   O2  0.0  0.0   A

[ moleculetype ]
;namenrexcl
 tripe3


On Mon, May 14, 2012 at 9:53 AM, Russel Winder  wrote:

> On Mon, 2012-05-14 at 09:31 +0200, Bala subramanian wrote:
> > Friends,
> > Could someone please give some hint on how to extract lines between two
> > patterns in a file. I use the re module to compile my patterns but not
> able
> > to figure out how i can use these patterns to extract the lines lying in
> > between.
>
> Without the source code you already have, it is difficult to provide any
> constructive suggestions.
>
> --
> Russel.
>
> =
> Dr Russel Winder  t: +44 20 7585 2200   voip:
> sip:russel.win...@ekiga.net
> 41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@winder.org.uk
> London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
>



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


Re: [Tutor] (no subject)

2012-05-14 Thread Dave Angel
On 05/14/2012 05:58 AM, Keitaro Kaoru wrote:
> sorry if i keep missing this up.
>
> hey. Austin here for some reason this command. all it does it produces the
> error message at the bottom.. itll say my name and the persons name im
> trying to send the message to but thats it. heres the command.
I spent some time trying to re-indent this code, and eventually got it
to make sense.  However then I got at least two syntax errors, noted inline.
 
> 
> # Imports
> 
> from tools import Html, Error, Text, shared_db, log
> import urllib.request as urlreq
> import urllib.parse as urlpar
> import xml.dom.minidom as xdm
> import random
> import time
> import json
> import re
> import ch
>
> mgr.addCommand("tell", 1, "send a person a message to the rooms he is in",
> tell, unlisted = True)
>
> def tell(mgr, croom, user, msg, args):
> name = args.lower().split(" ")[0]
> if not name.isalnum(): return Html("Non-alphanumeric name, 
> seriously?")
> data = shared_db.get("seen:" + name)
> if data == None:
> return Html("I have no records about this user.")
> data = json.loads(data)
> for room in mgr.rooms:
> if data[1] == "join":
> mgr.sendObject(target,
> Html("%s,%s  wants to tell
> you%s ", name.title, user.name.title$
That $ at the end is a syntax error.  At a minimum there should be two
right parentheses there, but i can't tell if other stuff got lost there.

> else:
> return Error("%s  I couldn't find %s
> anywhere", user.name.title(), name.title())
>
> i built it off these 2 commands
>
> def broadcast(mgr, croom, user, msg, args):
> for room in mgr.rooms:
> mgr.sendObject(room, Html("Broadcast by%s:%s",
> user.name, args))
>
> def seen(mgr, room, user, msg, args):
> name = args.lower().split(" ")[0]
> if not name.isalnum(): return Html("Non-alphanumeric name, seriously?")
> data = shared_db.get("seen:" + name)
> if data == None:
> return Html("I have no records about this user.")
> data = json.loads(data)
> ifdata[1] == "join":
Need a space after the 'if'


> return Html("Last seen%s  join%s,%s
> ago.", name, data[0], tdelta(data[2]))
> elif data[1] == "leave":
> return Html("Last seen%s  leave%s,%s
> ago.", name, data[0], tdelta(data[2]))
> elif data[1] == "message":
> return Html("Last seen%s  message in%s,%s
>  ago: \"%s\"", name, data[0], tdelta(data[2]), data[3])
> return Html("I have no records about this user.")
>
> as you can see i only use some of the command. it doesnt produce an error
> message tho.. just repeats "return Error("%s  I couldn't find %s
> anywhere", user.name.title(), name.title())"
>
>

At this point, I got import errors on four of the nine import
statements.  And then the following:

Traceback (most recent call last):
  File "keitaro.py", line 15, in 
mgr.addCommand("tell", 1, "send a person a message to the rooms he
is in",
NameError: name 'mgr' is not defined

This is with python 2.7 on Linux



-- 

DaveA

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


Re: [Tutor] List Indexing Issue

2012-05-14 Thread Bala subramanian
Hi,
I would suggest you to use the biopython package. It has a PDB parser with
which you can extract any specific information like atom name, residue,
chain etc as you wish.
Bala

On Wed, May 9, 2012 at 3:19 AM, Jerry Hill  wrote:

> On Tue, May 8, 2012 at 4:00 PM, Spyros Charonis 
> wrote:
> > Hello python community,
> >
> > I'm having a small issue with list indexing. I am extracting certain
> > information from a PDB (protein information) file and need certain
> fields of
> > the file to be copied into a list. The entries look like this:
> >
> > ATOM   1512  N   VAL A 222   8.544  -7.133  25.697  1.00 48.89
> > N
> > ATOM   1513  CA  VAL A 222   8.251  -6.190  24.619  1.00 48.64
> > C
> > ATOM   1514  C   VAL A 222   9.528  -5.762  23.898  1.00 48.32
> > C
> >
> > I am using the following syntax to parse these lines into a list:
> ...
> > charged_res_coord.append(atom_coord[i].split()[1:9])
>
> You're using split, assuming that there will be blank spaces between
> your fields.  That's not true, though.  PDB is a fixed length record
> format, according to the documentation I found here:
> http://www.wwpdb.org/docs.html
>
> If you just have a couple of items to pull out, you can just slice the
> string at the appropriate places.  Based on those docs, you could pull
> the x, y, and z coordinates out like this:
>
>
> x_coord = atom_line[30:38]
> y_coord = atom_line[38:46]
> z_coord = atom_line[46:54]
>
> If you need to pull more of the data out, or you may want to reuse
> this code in the future, it might be worth actually parsing the record
> into all its parts.  For a fixed length record, I usually do something
> like this:
>
> pdbdata = """
> ATOM   1512  N   VAL A 222   8.544  -7.133  25.697  1.00 48.89
>   N
> ATOM   1513  CA  VAL A 222   8.251  -6.190  24.619  1.00 48.64
>   C
> ATOM   1514  C   VAL A 222   9.528  -5.762  23.898  1.00 48.32
>   C
> ATOM   1617  N   GLU A1005  11.906  -2.722   7.994  1.00 44.02
>   N
> """.splitlines()
>
> atom_field_spec = [
>slice(0,6),
>slice(6,11),
>slice(12,16),
>slice(16,18),
>slice(17,20),
>slice(21,22),
>slice(22,26),
>slice(26,27),
>slice(30,38),
>slice(38,46),
>slice(46,54),
>slice(54,60),
>slice(60,66),
>slice(76,78),
>slice(78,80),
>]
>
> for line in pdbdata:
>if line.startswith('ATOM'):
>data = [line[field_spec] for field_spec in atom_field_spec]
>print(data)
>
>
> You can build all kind of fancy data structures on top of that if you
> want to.  You could use that extracted data to build a namedtuple for
> convenient access to the data by names instead of indexes into a list,
> or to create instances of a custom class with whatever functionality
> you need.
>
> --
> Jerry
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



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


Re: [Tutor] extracting lines between patterns.

2012-05-14 Thread Russel Winder
On Mon, 2012-05-14 at 12:23 +0200, Bala subramanian wrote:
[...]
> mypat=re.compile(r'^[ atomtypes ]$[ moleculetype ]',re.MULTILINE)
[...]

mypat=re.compile(r'^\[ atomtypes \]$(.*)^\[ moleculetype \]$',re.MULTILINE | 
re.DOTALL)

-- 
Russel.
=
Dr Russel Winder  t: +44 20 7585 2200   voip: sip:russel.win...@ekiga.net
41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder


signature.asc
Description: This is a digitally signed message part
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] syntax error

2012-05-14 Thread bob gailer

I have changed the subject to "syntax error".

Please always post a meaningful subject.

On 5/14/2012 5:58 AM, Keitaro Kaoru wrote:

sorry if i keep missing this up.

hey. Austin here for some reason this command. all it does it produces the
error message at the bottom..

The code you sent has numerous errors.

How did you miss all the other errors?

Are you using an IDE to edit the code? An IDE will help you locate the 
errors.


I corrected the errors (so the program compiles) and put a copy in 
http://pastebin.com/zWcD7gnT.


I have no idea if all the indentation is correct, as I can only guess, 
and don't want to spend time doing better guessing.


Please sign up with pastebin and post your code there. That will 
guarantee we can copy it as you wrote it.


Also please refer to your program as a program or script. It is not a 
command.


--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] syntax error

2012-05-14 Thread bob gailer

On 5/14/2012 6:14 AM, Keitaro Kaoru wrote:

hello~ is NOT a good subject


i resent it but if that doesnt work. cause i sent it to myself also
looks fine on my gmail.. but heres a link to pastebin

http://pastebin.com/Jp7VJKGB


There are still numerous errors that prevent the program from compiling.

PLEASE ONLY PASTEBIN code that we can run!
Line 26 ends with ; should be ))
Line 28 is split
Line 31 - is that a comment if so put # in front of it.
Line 38-51 must be indented
Line 44   ifdata[1] == "join":
Line 51 will never be executed.


--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] extracting lines between patterns.

2012-05-14 Thread Alan Gauld

On 14/05/12 08:31, Bala subramanian wrote:

Friends,
Could someone please give some hint on how to extract lines between two
patterns in a file. I use the re module to compile my patterns but not
able to figure out how i can use these patterns to extract the lines
lying in between.


Without much detail here goes the generic pattern in pseudo code:

active_flag = False
for line in file:
   if not active_flag:
  if start_pattern in line:
  active_flag = True
   else:
  if end_pattern in line:
  active_flag = False   # or break if only one group possible
  else: #process line

You can tweak the logic to make it more efficient but at the cost of 
readability.


Hopefully that gives you a starting point.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


[Tutor] Multiple DBs per application?

2012-05-14 Thread leam hall
All,

Just a general question. If you have an application with different
data types where it might be better to use one database over another,
are there issues with having multiple databases used by the
application?

Thanks!

Leam

-- 
Mind on a Mission 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pip errors for numpy, scipy matplotlib

2012-05-14 Thread Bjorn Madsen
Hi Jerry,
Sorry the missing details - but well spotted: I do use ubuntu and it was
with the 12.04 upgrade that I experienced the issue.
Your advice was spot on - sudo apt-get install python-numpy solved the job,
and when I ran pip afterwards I received the message that "requirements are
already satisfied".

Thank you again - I will keep it in mind that
"apt-get install python-some_packages" may be the right way about it on
ubuntu.


Bjorn

On 11 May 2012 19:52, Jerry Hill  wrote:

> On Fri, May 11, 2012 at 2:42 PM, Bjorn Madsen
>  wrote:
> > Hi,
> > when attempting to use pip to install numpy, scipy matplotlib I get a
> mile
> > of errors. There is simply too much information printed - so it must be a
> > systematic error (http://paste.ubuntu.com/982180/). What am I
> missing/doing
> > wrong?
>
> The error messages sound like you're missing a bunch of the thing
> required to build the packages you're trying to compile.  It looks
> like libraries called Atlas and Blas, plus a fortran compiler, from
> the errors you posted.
>
> Are you using ubuntu?  You didn't say, but I see you're using a ubuntu
> pastebin.  Are you wedded to compiling and installing with pip?  It's
> a whole lot easier to just use the packaging system included with
> ubuntu when you can.  In this case you should be able to do `sudo
> apt-get install python-numpy` to install numpy.
>
> If you do want to compile and build via pip, I would start by doing
> `sudo apt-get build-dep python-numpy` to get all the required
> prerequisites installed, then retry installing via pip.
>
> --
> Jerry
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Bjorn Madsen
*
*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Multiple DBs per application?

2012-05-14 Thread Alan Gauld

On 14/05/12 20:33, leam hall wrote:

Just a general question. If you have an application with different
data types where it might be better to use one database over another,
are there issues with having multiple databases used by the
application?



No, you can usuially have multiple databases open at once.
You can have multiple instances of the same database or
different database types.

However the data types are rarely ta reason to use different databases. 
More typically would be different performance requirements or security 
issues. For example it's common to hold some data in an LDAP structure 
for speed of access (at the expense of flexibility) and the rest of the 
data in an RDBMS such as MySql. But using say MySQL and Oracle together 
would normally only be done because they were pre-existing datastores 
from another project.



--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] Multiple DBs per application?

2012-05-14 Thread Leam Hall

On 05/14/2012 06:44 PM, Alan Gauld wrote:

On 14/05/12 20:33, leam hall wrote:

Just a general question. If you have an application with different
data types where it might be better to use one database over another,
are there issues with having multiple databases used by the
application?



No, you can usuially have multiple databases open at once.
You can have multiple instances of the same database or
different database types.

However the data types are rarely ta reason to use different databases.
More typically would be different performance requirements or security
issues. For example it's common to hold some data in an LDAP structure
for speed of access (at the expense of flexibility) and the rest of the
data in an RDBMS such as MySql. But using say MySQL and Oracle together
would normally only be done because they were pre-existing datastores
from another project.


Thanks! I was more thinking of something like a CMS where user login 
information and admin functions might be in a SQLite database and then 
some larger backend big data stuff in MongoDB or similar. Just wasn't 
sure if there was a basic flaw to the idea that I wasn't aware of.


Leam

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


Re: [Tutor] Multiple DBs per application?

2012-05-14 Thread bob gailer

On 5/14/2012 3:33 PM, leam hall wrote:

All,

Just a general question. If you have an application with different
data types where it might be better to use one database over another,
are there issues with having multiple databases used by the
application?

BY "database" do you mean
a table (as in dBase)
a collection of tables (as an Access file)
a database management system (MySQL)?

--
Bob Gailer
919-636-4239
Chapel Hill NC

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


[Tutor] table to dictionary and then analysis

2012-05-14 Thread questions anon
I am completely new to dictionaries and I am not even sure if this is what
I need to use.
I have a text file that I would like to run summary stats on particular
months, years and climate indices (in this case the climate indices are
rainfall and fire area, so not actualy climate indices at all).

A text file is attached but a small sample of the file:
  rainfallfirearea
1972 Jan12.70831990
1972 Feb14.170071420
1972 Mar14.56593020
1972 Apr1.5085173020
1972 May2.7800098890
1972 Jun1.6096192870
1972 Jul0.13815018128
1972 Aug0.21434614832
1972 Sep1.32210222834747.8
1972 Oct0.0926631373655.9
1972 Nov1.85227663585.1
1972 Dec2.01120600242959.6
1973 Jan5.55704346153.5
1973 Feb12.60326356116.2
1973 Mar11.08849105223.6
1973 Apr5.8649254492.4
..

I have used an example from a book (a primer on scientific programming with
python) and it seems to be working (see below) but I am not sure if I have
my keys etc. are set up correctly to then begin anlaysis, and even how to
use the dictionaries in my analysis. For example how can I print out the
year with calculated the mean 'firearea' of June-July-August for that year
along with the maximum 'rainfall' for June-July-august of the same year?
Any feedback will be greatly appreaciated!

infile=open('d:/yearmonthrainfire.txt','r')
lines=infile.readlines()
infile.close()
data={} #data[index][year]=indexvalue
first_line=lines[0]
climateindexname=first_line.split()
for index in climateindexname:
data[index]={}
YEAR={}
MONTH={}

for line in lines[2:]:
words=line.split()
year=words[0] #years
YEAR[year]={}
month=words[1] #months
MONTH[month]={}
values=words[2:] #values of climateindices
for index, v in zip(climateindexname, values):
if v !=' ':
data[index][year]=float(v)

print "years=", YEAR
print "months=", MONTH
print "data=", data
meanrainfirearea
1972 Jan12.7083199  0
1972 Feb14.17007142 0
1972 Mar14.5659302  0
1972 Apr1.508517302 0
1972 May2.780009889 0
1972 Jun1.609619287 0
1972 Jul0.138150181 28
1972 Aug0.214346148 32
1972 Sep1.322102228 34747.8
1972 Oct0.092663137 3655.9
1972 Nov1.852276635 85.1
1972 Dec2.011206002 42959.6
1973 Jan5.55704346  153.5
1973 Feb12.60326356 116.2
1973 Mar11.08849105 223.6
1973 Apr5.864925449 2.4
1973 May2.352622232 0
1973 Jun1.600553474 0
1973 Jul0.776217634 0.4
1973 Aug0.369365192 0
1973 Sep2.2226749   13523.2
1973 Oct1.122739926 229.3
1973 Nov7.904255106 144
1973 Dec13.31568494 1558.5
1974 Jan24.85492667 1170.8
1974 Feb16.21160985 11.1
1974 Mar15.68630322 64.5
1974 Apr1.761830238 0
1974 May3.245113376 0
1974 Jun0.413113179 0
1974 Jul0.056925965 0
1974 Aug1.056679232 0
1974 Sep0.506806924 0.2
1974 Oct0.571465459 0
1974 Nov1.747845479 2939.4
1974 Dec5.423673558 2212.4
1975 Jan8.246915224 34838.4
1975 Feb10.09194262 14467.3
1975 Mar8.228448671 2673.5
1975 Apr4.033215013 608.4
1975 May1.953680674 28.2
1975 Jun1.343020358 0
1975 Jul1.038350229 48
1975 Aug1.217719419 0
1975 Sep2.873960222 2.4
1975 Oct3.647092246 2.1
1975 Nov1.789754789 41135
1975 Dec12.7257926  1837.2
1976 Jan8.670511763 12972.1
1976 Feb12.82303773 556.9
1976 Mar8.693052739 646.6
1976 Apr4.824761671 2441.1
1976 May1.185164667 174.3
1976 Jun0.807438979 0
1976 Jul0.772650504 0
1976 Aug0.339851675 0.8
1976 Sep0.172502614 18.5
1976 Oct0.942766622 18
1976 Nov2.882269122 115558.6
1976 Dec8.023477936 2566.7
1977 Jan6.995102092 2771.8
1977 Feb18.99860777 21637.1
1977 Mar10.80012409 145.1
1977 Apr7.522531332 792.3
1977 May3.779496681 171.6
1977 Jun0.653845173 0
1977 Jul0.577692075 0
1977 Aug0.46951093  903.4
1977 Sep0.690806944 164
1977 Oct0.355984233 38512.8
1977 Nov2.256052975 1946.3
1977 Dec4.696920357 3620.8
1978 Jan7.361228919 38343.3
1978 Feb6.082772277 7332.2
1978 Mar2.345215476 298.3
1978 Apr4.67913104  117.7
1978 May2.831787858 5
1978 Jun0.371906624 0
1978 Jul0.815953022 0
1978 Aug1.214826869 0
1978 Sep0.822085

Re: [Tutor] table to dictionary and then analysis

2012-05-14 Thread bob gailer

On 5/14/2012 10:16 PM, questions anon wrote:
I am completely new to dictionaries and I am not even sure if this is 
what I need to use.
I have a text file that I would like to run summary stats on 
particular months, years and climate indices (in this case the climate 
indices are rainfall and fire area, so not actualy climate indices at 
all).
I would set up a SQLite database with a table of 4 numeric columns: 
year, month, rainfall, firearea
Use SQL to select the desired date range and do the max and avg 
calculations:
select year, avg(firearea), max(rainfall) from table where year = 1973 
and month between 6 and 8)


you can use dictionaries but that will be harder. Here a start 
(untested). Assumes data are correct.


months = 
dict(Jan=1,Feb=2,Mar=4,Apr=4,May=5,Jun=6,Jul=7,Aug=8,Sep=9.Oct=10,Nov=11,Dec=12)

for line in open('d:/yearmonthrainfire.txt','r'):
line = line.split()
year = int(line[0])
month = months[line[1]]
rainfall = float(line[2]
firearea = float(line[3]
sql = "insert into table (year, month, rainfall, firearea) 
values(%i,%i,%f,%f)" % (year, month, rainfall, firearea)

# I don't have handy how one runs the sql


A text file is attached but a small sample of the file:
  rainfallfirearea
1972 Jan12.70831990
1972 Feb14.170071420
1972 Mar14.56593020
1972 Apr1.5085173020
1972 May2.7800098890
1972 Jun1.6096192870
1972 Jul0.13815018128
1972 Aug0.21434614832
1972 Sep1.32210222834747.8
1972 Oct0.0926631373655.9
1972 Nov1.85227663585.1
1972 Dec2.01120600242959.6
1973 Jan5.55704346153.5
1973 Feb12.60326356116.2
1973 Mar11.08849105223.6
1973 Apr5.8649254492.4
..

I have used an example from a book (a primer on scientific programming 
with python) and it seems to be working (see below) but I am not sure 
if I have my keys etc. are set up correctly to then begin anlaysis, 
and even how to use the dictionaries in my analysis
. For example how can I print out the year with calculated the mean 
'firearea' of June-July-August for that year along with the maximum 
'rainfall' for June-July-august of the same year?

Any feedback will be greatly appreaciated!

infile=open('d:/yearmonthrainfire.txt','r')
lines=infile.readlines()
infile.close()
data={} #data[index][year]=indexvalue
first_line=lines[0]
climateindexname=first_line.split()
for index in climateindexname:
data[index]={}
YEAR={}
MONTH={}

for line in lines[2:]:
words=line.split()
year=words[0] #years
YEAR[year]={}
month=words[1] #months
MONTH[month]={}
values=words[2:] #values of climateindices
for index, v in zip(climateindexname, values):
if v !=' ':
data[index][year]=float(v)

print "years=", YEAR
print "months=", MONTH
print "data=", data

We usually reserve all caps names for constants.
You have way too many dictionaries.
Your program seems very complex for a very simple task.
I will not attempt to figure out what it does.





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



--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] Multiple DBs per application?

2012-05-14 Thread bob gailer

On 5/14/2012 7:55 PM, Leam Hall wrote:

On 05/14/2012 06:44 PM, Alan Gauld wrote:

On 14/05/12 20:33, leam hall wrote:

Just a general question. If you have an application with different
data types where it might be better to use one database over another,
are there issues with having multiple databases used by the
application?



No, you can usuially have multiple databases open at once.
You can have multiple instances of the same database or
different database types.

However the data types are rarely ta reason to use different databases.
More typically would be different performance requirements or security
issues. For example it's common to hold some data in an LDAP structure
for speed of access (at the expense of flexibility) and the rest of the
data in an RDBMS such as MySql. But using say MySQL and Oracle together
would normally only be done because they were pre-existing datastores
from another project.


Thanks! I was more thinking of something like a CMS where user login 
information and admin functions might be in a SQLite database and then 
some larger backend big data stuff in MongoDB or similar. Just wasn't 
sure if there was a basic flaw to the idea that I wasn't aware of.

Seems like a good idea. Right tool for right purpose.


--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] table to dictionary and then analysis

2012-05-14 Thread questions anon
Thanks Bob,
sql does appear to be very simple although I cannot get the queries to
work. Can you suggest a site that has examples for what I am trying to do.
I have done some googling but it has not been successful so far.



On Tue, May 15, 2012 at 1:38 PM, bob gailer  wrote:

>  On 5/14/2012 10:16 PM, questions anon wrote:
>
> I am completely new to dictionaries and I am not even sure if this is what
> I need to use.
> I have a text file that I would like to run summary stats on particular
> months, years and climate indices (in this case the climate indices are
> rainfall and fire area, so not actualy climate indices at all).
>
> I would set up a SQLite database with a table of 4 numeric columns: year,
> month, rainfall, firearea
> Use SQL to select the desired date range and do the max and avg
> calculations:
> select year, avg(firearea), max(rainfall) from table where year = 1973 and
> month between 6 and 8)
>
> you can use dictionaries but that will be harder. Here a start (untested).
> Assumes data are correct.
>
> months =
> dict(Jan=1,Feb=2,Mar=4,Apr=4,May=5,Jun=6,Jul=7,Aug=8,Sep=9.Oct=10,Nov=11,Dec=12)
> for line in open('d:/yearmonthrainfire.txt','r'):
> line = line.split()
> year = int(line[0])
> month = months[line[1]]
> rainfall = float(line[2]
> firearea = float(line[3]
> sql = "insert into table (year, month, rainfall, firearea)
> values(%i,%i,%f,%f)" % (year, month, rainfall, firearea)
> # I don't have handy how one runs the sql
>
>
> A text file is attached but a small sample of the file:
>   rainfallfirearea
> 1972 Jan12.70831990
> 1972 Feb14.170071420
> 1972 Mar14.56593020
> 1972 Apr1.5085173020
> 1972 May2.7800098890
> 1972 Jun1.6096192870
> 1972 Jul0.13815018128
> 1972 Aug0.21434614832
> 1972 Sep1.32210222834747.8
> 1972 Oct0.0926631373655.9
> 1972 Nov1.85227663585.1
> 1972 Dec2.01120600242959.6
> 1973 Jan5.55704346153.5
> 1973 Feb12.60326356116.2
> 1973 Mar11.08849105223.6
> 1973 Apr5.8649254492.4
> ..
>
> I have used an example from a book (a primer on scientific programming
> with python) and it seems to be working (see below) but I am not sure if I
> have my keys etc. are set up correctly to then begin anlaysis, and even how
> to use the dictionaries in my analysis
>
> . For example how can I print out the year with calculated the mean
> 'firearea' of June-July-August for that year along with the maximum
> 'rainfall' for June-July-august of the same year?
> Any feedback will be greatly appreaciated!
>
> infile=open('d:/yearmonthrainfire.txt','r')
> lines=infile.readlines()
> infile.close()
> data={} #data[index][year]=indexvalue
> first_line=lines[0]
> climateindexname=first_line.split()
> for index in climateindexname:
> data[index]={}
> YEAR={}
> MONTH={}
>
> for line in lines[2:]:
> words=line.split()
> year=words[0] #years
> YEAR[year]={}
> month=words[1] #months
> MONTH[month]={}
> values=words[2:] #values of climateindices
> for index, v in zip(climateindexname, values):
> if v !=' ':
> data[index][year]=float(v)
>
> print "years=", YEAR
> print "months=", MONTH
> print "data=", data
>
> We usually reserve all caps names for constants.
> You have way too many dictionaries.
> Your program seems very complex for a very simple task.
> I will not attempt to figure out what it does.
>
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription 
> options:http://mail.python.org/mailman/listinfo/tutor
>
>
>
> --
> Bob Gailer919-636-4239
> Chapel Hill NC
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor