[Tutor] Can a method be added to dictionary?

2009-11-19 Thread lauren
Hey Gang,

Can a function/method be added to a dictionary like so:

myDictionary = {string:processString(parameter),
string2:processString2(parameter),
string3:processString3(parameter)
   }

I am basically interested in doing this with a Combobx Event.
When the user selects an option in my dropdown box (event.GetString())
that matches the string in my dictionary...say string2 then the method:
processString2(parameter) is executed.

Currently when I get the value of: myDictionary[string2] it is None.

Thanks for your help!
Lauren


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


Re: [Tutor] Can a method be added to dictionary?

2009-11-19 Thread lauren
John,

Thank you so much for your help! -- Problem SOLVED!!! -- Your explanation
and example was extremely helpful. I am very grateful.

Lauren :-)


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


Re: [Tutor] Distributing MySQL with my application

2009-03-23 Thread Lauren Snyder

Alan and André, 

Thank you very much for your assistance. My script takes a long log file,
parses it, puts the data to a database. The application has a GUI interface
and uses the data in the database to make and display various calculations
and graphs. Users will have their own log files...but to use my tool, I need
to either ensure they have a db server (like noted below) to create my db
on...or to somehow provide a db for them to use with my tool. 

1. how do I create a database that is not in users localhost? Currently I
just use MySQL's create [database] command after I connect using
MySQLdb.connect Alan mentioned something about 

Do you not use an environment variable or config file to allow the user to
select where the database server runs?

-- This sounds like it might be an excellent solution, but I'm not sure how
to do it.

2. I also like the idea of writing a script to check to see if MySQL is
installed. However, I need pointers on writing this script and also the
script to auto install MySQL on another user's computer. 

Thank you again for your help and brilliant ideas!
Lauren




-Original Message-
From: andré palma [mailto:andre...@gmail.com] 
Sent: Sunday, March 22, 2009 7:29 AM
To: Lauren Snyder
Subject: Re: [Tutor] Distributing MySQL with my application

Hi! It depends for what do you want for your aplication. How about you 
create a database anywhere else(not in users localhost) for each user 
who uses your software? This way you just wouldn't have this problem. 
But if you really need the database on localhost my suggestion is:
- make a script that check if the user already have MySQL installed, 
this way you just need to create an new database on localhost server for 
your software.
if there is no MySQL :
- make a script to install MySQL locally




Lauren Snyder wrote:

 Hello!

 I have written an application in python that uses a MySQL database. I 
 want to distribute this application to many users so I created an 
 executable using GUI2exe. My executable works marvelously. However, 
 when attempting to run the app on a computer that doesn’t have the 
 MySQL server running, I obviously get the error: Can’t connect MySQL 
 server on localhost.

 So I have some questions around this problem:

1. Is it possible to bundle the database into my application?
2. Do I have to write a script that installs the database server
   locally?
3. Do I have to make “Users must have MySQL server running” as a
   pre-requisite for using my software?
4. Did I miss an option in GUI2exe that allows me to set up my exe
   to use MySQL?

 Thank you,

 Lauren

 

 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor
   

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Distributing MySQL with my application

2009-03-21 Thread Lauren Snyder
Hello!

 

I have written an application in python that uses a MySQL database. I want
to distribute this application to many users so I created an executable
using GUI2exe. My executable works marvelously. However, when attempting to
run the app on a computer that doesn't have the MySQL server running, I
obviously get the error: Can't connect MySQL server on localhost.  

 

So I have some questions around this problem:

 

1.  Is it possible to bundle the database into my application?
2.  Do I have to write a script that installs the database server
locally?
3.  Do I have to make Users must have MySQL server running as a
pre-requisite for using my software?
4.  Did I miss an option in GUI2exe that allows me to set up my exe to
use MySQL?

 

Thank you,

Lauren

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to reference a wx.grid.Grid outside the method inwhich it was created?

2008-08-11 Thread lauren
I have created a wx.grid.Grid attached to a panel which is attached to a
frame within one method (Method #1). Inside this method I also created a
combobox.

When an item is selected in the combobox another method is called (i.e.
When the event is called the method is run…)
Inside this method I want to fill the grid created in Method #1 with data
generated/calculated from within Method #2 based on which item was
selected from the combobox.

How do I reference the grid from method #1 when I am in method #2?

Currently I am receving this error message:
NameError: global name 'myGrid' is not defined.

It's an error against this statement in method #2:
myGrid.SetCellValue(i, 0, myValue)


Thanks!
Lauren


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to reference a wx.grid.Grid outside the method inwhich it was created?

2008-08-11 Thread lauren
It worked like a charm!
Thank you so much!!

Lauren



 If method1 and method2 are both methods of the same class, just save
 myGrid as an attribute of the class rather than having it as a local
 variable in method1. I.e.

 def method1(self):
   self.myGrid = ...

 def method2(self):
   self.myGrid.SetCellValue(...)

 Kent



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to reference a wx.grid.Grid outside the methodinwhich it was created?

2008-08-11 Thread Lauren Snyder
Will do!

Thanks again,
Lauren :-)

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Alan Gauld
Sent: Monday, August 11, 2008 4:27 PM
To: tutor@python.org
Subject: Re: [Tutor] How to reference a wx.grid.Grid outside the
methodinwhich it was created?


[EMAIL PROTECTED] wrote 

Currently I am receving this error message:
NameError: global name 'myGrid' is not defined.

It's an error against this statement in method #2:
myGrid.SetCellValue(i, 0, myValue)

As a general rule when posting to the list include the full 
error trace not just a summary. The tracelback often has 
useful info.

In this case it wasn't needed however. :-)

Alan G.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tree Ctrl Data Structure - Help, please!

2008-07-16 Thread lauren


Hi!

Thanks for much for your reply! I'm sorry my posting was so
confusing...It's partially because my understanding is so hazy right now.
I'm trying to piece together what I should do next...

Based on your example...
My understanding is that if I desire the following tree control structure
in my GUI:

  australia
  europe
   -  spain
   -  germany
   -  belgium
  north america
   -  united states
   -   -  california
   -   -  oregon
   -   -  arizona
   -  canada
  asia

That my nested list will look something like this(NOTE) I believe that
I will need to include the parent root node IN the list like this (not
outside of it before the children):

geo=[
australia,
[europe,
[spain,
 germany,
 belgium,]],
[north america,
[united states,[
california,
 oregon,
 arizona],
canada]],
asia]


Currently the format of my data are lists from queries such as:

Select Distinct(Continent) from world_globe;  -- Query returns a list --
[australia, europe, north america, asia]
Select Distinct(Country) from world_globe
where continent = europe;  -- Query returns a list --
[spain, germany, belgium]
Select Distinct(State) from world_globe
where country = united states;  -- Query returns a list --
[california, oregon, arizona]
ETC

So my lists are these:
continent = [australia, europe, america, asia]
country = [[spain, germany, belgium], [united states, canada]]
state = [california, oregon, arizona]

So ... what I have:
The data is already split out into nodes. Clearly my tree will be 3 deep.
Continent
- Country
- State

What I don't have - aka my questions??:
I think I need a list of nested lists...and they need to be in the proper,
logical order. I can't simply iterate on continent inserting the lists
from Country because they don't associate themselves with the correct
objects. It would become for example:

tree_list = [australia, [spain, germany, belgium], europe,
[united states, canada], america, asia

...logically representing this (which is wrong):

australia
- spain
- germany
- belgium
europe
- united states
- canada
america
asia

Also, I believe that the parent of the children needs to INSIDE a list
with it's children. For example this:

geo = [australia, [europe,[spain, germany, belgium]]] --
Correct (I believe)

NOT THIS...

geo = [australia, europe, [spain, germany, belgium]] --
Incorrect (I believe)

***

I need assistance getting from here:

continent = [australia, europe, america, asia]
country = [[spain, germany, belgium], [united states, canada]]
state = [california, oregon, arizona]

To here:

geo=[
australia,
[europe,
[spain,
 germany,
 belgium,]],
[north america,
[united states,[
california,
 oregon,
 arizona],
canada]],
asia]


Thanks Again!
Lauren


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tree Ctrl Data Structure - Help, please!

2008-07-16 Thread lauren
John--

Thanks again - I so appreciate your direction!

Okay so i have a list of lists just as you describe below...I hate to make
myself look really stupid...but I don't see how this converts to a tree
structure...I was looking at this earlier and I guess what's confusing me
are the duplicates...do I need to convert the list below into a data
structure of tuples? Can this be plugged straight into a tree control?

Now my question is:

How do I get from here:
 [('north america', 'United States', 'California'),
 ('north america', 'United States, 'Texas'),
 ('north america', 'United States, 'Washington'),
 ('north america', 'Canada', 'Ontario'),
 ('Asia', 'Japan', None),

To Here:
geo=[(north america, [
(united states,[
(california, []),
(oregon, []),
 (arizona, [])]),
(canada, [
(Ontario, [])])]),
 (asia, [
(japan, [])])

Lauren


 From looking at your other email, my guess is that you want to start
 with SQL looking something like this:

 select continent, country, state from world_globe

 with the intention of getting back data that looks like:

 [('America', 'United States', 'California'),
 ('America', 'United States, 'Texas'),
 ('America', 'United States, 'Washington'),
 ('America', 'Canada', 'Ontario'),
 ('Asia', 'Japan', None),
 # etc
 ]

 It would be fairly straightforward to take data looking something like
 that and produce a tree.

 --
 John.



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Tree Ctrl Data Structure - Help, please!

2008-07-15 Thread Lauren Snyder
Hello!

 

ACK!!! I am attempting to AUTO populate a tree control

 

Right now I am just focusing on dynamically creating the data structure
(a list of lists) that will later be used to populate the tree control. 

This is where I am stuck! 

 

Based on some research I've done,  I think I want my data structure to
be a series of lists within lists:

 

[ node1, node1a, node1b, [node1c, node2, node2a, node2b,],
[node1d, [node2c, node3, node3a], node2d], node1e]]

 

-

The list above represents this tree structure:

 

Node1

 

Node1a

 

Node1b

 

Node1c

Node2

Node2a

Node2b

 

Node1d

Node2c

Node3

Node3a

Node2d

 

Node1e

 

-

All of my data will be variable and I collect all the node information
via SQL queries. 

But now I have a series of lists:

 

[node1, node1a, node1b, node1c, node1d, node1e]

[node2, node2a, node2b, node2c, node2d]

[node3, node3a]

 

If I execute my sql queries in a series of nested  'FOR' statements I
get the hierarchy for each node traversal (as shown below) - but not in
tree format. For example 1c has many branches - so it is returned 3
times. 

 

Node1

Node1a

Node1b

 

Node1c

Node2

 

Node1c

Node2a

 

Node1c

Node2b

 

Node1d

Node2c

Node3

 

Node1d

Node2c

Node3a

 

Node1d

Node2d

 


**

 

So - my questions:

 

Is there an existing method/class/library that already exists in python
to help me create the data structure I need for my tree structure?

If not, can someone give me some pointers on how to think about this
clearly??  I'm obviously missing some steps!! :-(

 

As an aside, I'm using wxpython for my GUI

Thanks!

Lauren

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Finding all locations of a sequence

2007-06-27 Thread Lauren

Firstly, I'd like to thank everyone for their help. I ended up throwing
something together using dictionaries (because I understood those best out
of what I had), that was a lot faster than my initial attempt, but have run
into a different problem, that I was hoping for help with. So, what I have
is all the subsequences that I was looking for in separate entries in the
dictionary, and where each of them is found as the value. If a subsequence
binds to more than one other item, I want to have the locations of the items
all together.
The closest I've been able to manage to get to what I want is this:

dict_of_bond_location = {}
dict1 = {'AAA':['UUU'], 'AAU':['UUG', 'UUA'], 'AAC':['UUG'], 'AAG':['UUC',
'UUU'], 'CCC':['GGG']}
dict2 = {'AAA':[1], 'AAU':[2], 'AAC':[3], 'AAG':[0, 4], 'GGG':[10]}
dict3 = {'UUU':[3, 5], 'UUG':[0], 'UUA':[1], 'UUC':[2], 'GGG':[14]}


for key in dict2:
   if key in dict1:
   matching_subseq = dict1.get(key)
   for item in matching_subseq:
   if item in dict3:
   location = dict3.get(item)
   dict_of_bond_location.setdefault(key, []).append(location)
print dict_of_bond_location

which gives this:
{'AAU': [[0], [1]], 'AAG': [[2], [3, 5]], 'AAA': [[3, 5]], 'AAC': [[0]]}

but what I want is
'AAU':[0, 1], 'AAG':[2, 3, 5], 'AAA':[3. 5], 'AAC':[0]

the setdefault(key, []).append(location) thing sort of does what I want, but
I don't want the result to be a list of lists...just one big list. The
production of a new dictionary is not necessary, but it made sense to me a
few hours ago. Anyway, is there a fast and dirty way to add lists together,
if the lists are not named (I think that's essentially what I want?)

Thanks again,

Lauren



On 19/06/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:


Send Tutor mailing list submissions to
tutor@python.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
[EMAIL PROTECTED]

You can reach the person managing the list at
[EMAIL PROTECTED]

When replying, please edit your Subject line so it is more specific
than Re: Contents of Tutor digest...


Today's Topics:

   1. Re: iterating over a sequence question.. (Luke Paireepinart)
   2. Re: Help converting base32 to base16 (Alan Gauld)
   3. Re: Finding all locations of a sequence (fwd) (Danny Yoo)
   4. Re: sockets ( Linus Nordstr?m )
   5. Re: sockets (Alan Gauld)
   6. Re: Finding all locations of a sequence (fwd) (Alan Gauld)
   7. Re: cannot pickle instancemethod objects (hok kakada)
   8. Re: Python and XSI (Vishal Jain)


--

Message: 1
Date: Mon, 18 Jun 2007 13:37:21 -0500
From: Luke Paireepinart [EMAIL PROTECTED]
Subject: Re: [Tutor] iterating over a sequence question..
To: Simon Hooper [EMAIL PROTECTED], tutor@python.org
Message-ID:
[EMAIL PROTECTED]
Content-Type: text/plain; charset=iso-8859-1

On 6/18/07, Simon Hooper [EMAIL PROTECTED] wrote:

 Hi Luke,

 * On 17/06/07, Luke Paireepinart wrote:
  a more expanded version that accounts for either list being the longer
  one, or both being the same length, would be:
 
if len(t)  len(l): x = len(t)
  else: x = len(l)
print [(l[i%len(l)],t[i%len(t)]) for i in range(x)]
  [(1, 'r'), (2, 'g'), (3, 'b'), (4, 'r'), (5, 'g')]

 Being the duffer that I am, I'm very pleased with myself that I came up
 with a similar solution (albeit as a function rather than a list
 comprehension) :)

 You do not need the if statement either,


Yeah, I never knew about the max() function!
I noticed someone else used it in one of their solutions.
I'm pretty sure I've seen it a lot before, just didn't remember it.
-Luke
-- next part --
An HTML attachment was scrubbed...
URL:
http://mail.python.org/pipermail/tutor/attachments/20070618/1cf0ac67/attachment-0001.html

--

Message: 2
Date: Mon, 18 Jun 2007 21:12:02 +0100
From: Alan Gauld [EMAIL PROTECTED]
Subject: Re: [Tutor] Help converting base32 to base16
To: tutor@python.org
Message-ID: [EMAIL PROTECTED]
Content-Type: text/plain; format=flowed; charset=iso-8859-1;
reply-type=original


Jason Massey [EMAIL PROTECTED] wrote

  Nice entry at wikipedia:

 http://en.wikipedia.org/wiki/Base_32


Thanks for the link, I should have thought of oooking there!
I've heardof Base64 for encoding email but never come
across Base32 - any of the versions!

Alan G.



--

Message: 3
Date: Mon, 18 Jun 2007 16:54:53 -0400 (EDT)
From: Danny Yoo [EMAIL PROTECTED]
Subject: Re: [Tutor] Finding all locations of a sequence (fwd)
To: tutor@python.org
Message-ID: [EMAIL PROTECTED]
Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed

Hi everyone,

Can someone help Lauren?  I apologize for this, but I am very time
constrained at this moment, and won't be able to reply back for at least a
few

[Tutor] Finding all locations of a sequence

2007-06-14 Thread Lauren
Ok, please bear with me, I'm very new to programming and python. And
my question is rather...convoluted.

I have a bunch of sequences (about 4100 or so), and want to know where
they are in a very, very large string of letters. But wait, there's
more. Some of these sequences match to more than 'word' (for
example...to be consistent with later, chicken could match to poultry
or chicken).

example of what I want to do (on a much smaller scale):

Say I have chicken and I want to know where it occurs in a string of
words, but I want it to match to both chicken and poultry and have the
output of:

chicken  (locations of chicken and poultry in the string)

or something like that.

The string I'm dealing with is really large, so whatever will get
through it the fastest is ideal for me.

I hope this all makes sense...

If it's possible to have pseudocode that would be helpful.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Finding all locations of a sequence

2007-06-14 Thread Lauren
Ok, what I have is a RNA sequence (about 5 million nucleotides
[characters] long) and have (4100) subsequences (from another
sequence) and the sub-sequences are 6 characters long, that I want to
find in it.
The problem is the exceptional bond of U:G, which results in U bonding
to A (as per normal) and G (the abnormal bond) and G to bond with C
(as per normal) and U. Normally I'd go to search software already
available, however what I need done isn't covered b y anything out
there so far. That and I believe that they do not deal with the
exceptional bond. In any event, I want to know where the subsequences
can bind in the larger RNA sequence (ie, the location of binding in
the larger sequence) so I'm not (just) for where they would bind
normally, but also where the abnormal bonds would figure in.
Unfortunately my first attempt at this was unbearably slow, so I'm
hoping there is a faster way.

So an example with this would be:

Subseq  AU can bind to UA (which is normal) and UG (not so
normal) and I want to know where UA, and UG are in the large
RNA sequence, and the locations to show up as one...thing.

I don't know if that is more helpful or not than the chicken example...

Thanks again for the help


On 14/06/07, Teresa Stanton [EMAIL PROTECTED] wrote:
 OK, I'm going to take a shot at this.  If what I'm understanding is correct,
 a dictionary might help.  But that would depend on the format of the
 original sequence.  If you have a list:

 Lst1 = ['cow', 'pig', 'chicken', 'poultry', 'beef', 'pork']

 Then you could:

 Lst1.index('chicken')

 And get 2, because the list starts with 0,  not 1, as the first index.

 Or this:

  for i in Lst1:
 if i == 'chicken':
 print Lst1.index(i)
 if i == 'poultry':
 print Lst1.index(i)


 2
 3

 Now, Kent or Alan and perhaps others will have a much more sophisticated way
 of doing this same problem.  I'm still not exactly sure what it is you are
 looking for, because there isn't enough information for me to really get a
 grasp on your problem. My response is a simple list structure that has
 simple operations.

 Hope it helps :)

 T

 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
 Of Lauren
 Sent: Thursday, June 14, 2007 11:35 AM
 To: tutor@python.org
 Subject: [Tutor] Finding all locations of a sequence

 Ok, please bear with me, I'm very new to programming and python. And
 my question is rather...convoluted.

 I have a bunch of sequences (about 4100 or so), and want to know where
 they are in a very, very large string of letters. But wait, there's
 more. Some of these sequences match to more than 'word' (for
 example...to be consistent with later, chicken could match to poultry
 or chicken).

 example of what I want to do (on a much smaller scale):

 Say I have chicken and I want to know where it occurs in a string of
 words, but I want it to match to both chicken and poultry and have the
 output of:

 chicken  (locations of chicken and poultry in the string)

 or something like that.

 The string I'm dealing with is really large, so whatever will get
 through it the fastest is ideal for me.

 I hope this all makes sense...

 If it's possible to have pseudocode that would be helpful.
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor






-- 
Lauren

[EMAIL PROTECTED]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor