Re: [Tutor] Before I start

2007-01-10 Thread Tor Hildrum
On 1/9/07, Hemantharaju Subbanna [EMAIL PROTECTED] wrote:
 Hi,
 Before I jump into the investigation, I wanted to ask
 experts and get help/direction.

 I am looking to develop a simple web application.
 What would be my best approach? What package/s is good
 to explore?

 Need HTML GUI for Client (Qt plug-in may be ok).
 Server application with database

Have a look at Turbogears or Django.

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


Re: [Tutor] Noobie projects

2006-12-15 Thread Tor Hildrum
On 12/15/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 Is there a set of more basic projects for flexing one's novice Python skills?

They key to finding a project is to find something you will enjoy doing.

I used statistics to get to know Python.
The code parsed some text, added some numbers, calculated various
things. Very basic stuff, but it was a nice way to dip into Python while
doing something I had to do.

Other projects I did afterwards mostly consisted of fiddling around
with text. Parsing, building new strings and outputting in a special format.

Not sure if this helps, but that's how I started with Python :)

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


Re: [Tutor] User identification and running in the background.

2006-12-13 Thread Tor Hildrum
On 12/12/06, Tim Golden [EMAIL PROTECTED] wrote:

 But this is all quite Win32-specific (as well as
 being hand-wavingly unspecific). I don't know
 how you'd go about it on *nix but I bet it's nothing
 like the same.

The same general principle applies. You need to get a
UID or similar from a specific user, or you have to
check all connected TTYs and just pick a random user
out of the users logged in. Most systems today are
multi-user so the notion of 'the user logged in' doesn't
make sense system-wide.

I think the best way to solve this is to use a client-server
approach. Have a deamon/service run in the background,
and then have a client started at login that pings the server
and notifies it of your presence.

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


Re: [Tutor] help

2006-12-11 Thread Tor Hildrum
On 12/9/06, Kamran Haider [EMAIL PROTECTED] wrote:

 Hi

 I have got some python related queries. I am working on an MRes project
 which involves a bit of programing in python. Actually, I am using a
 python program developed by someone, which gives pairwise genetic
 distances between a set of sequences (I don't know how...) and outputs a
 simple text file of the following format...

 s1,s2,s3,s4,s5
 4,7,2,3
 8,6,4
 3,6
 7
 where s1, s2, s3...represent sequences and the  second line describes
 the pairwise distance between s1 and all other sequences,thid line is
 for the distance between s2 and other sequences.
 and so on.
 1. I want to read this line into a data structure(most probably by making a
 list of lists like [[s1,s2,4],[s1,s2,7],[s1,s3,2] and so on) which gives
 each pair and the corresponding pairwise distances. Of course, I would do
 this by writing a function that reads this file into a data structure which
 gives the all the pairs of sequences and theircorresponding distance values,
 but I am not sure how to do this.

This is a weighted graph.
see http://en.wikipedia.org/wiki/Glossary_of_graph_theory

Here is a nice text written for Python:
http://www.python.org/doc/essays/graphs.html

Should go a long way to solve your second problem as well.

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


Re: [Tutor] Getting the directory the program is in

2006-12-11 Thread Tor Hildrum
On 12/11/06, Toon Pieton [EMAIL PROTECTED] wrote:
 Hey friedly users!

 I was wondering: how can I get the directory the program is in? For example
 C:\Python Programs\Calculator\.

 os.path.split.__doc__
'Split a pathname.  Returns tuple (head, tail) where tail is\n
everything after the final slash.  Either part may be empty.'

The full pathname is in sys.argv[0]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Getting the directory the program is in

2006-12-11 Thread Tor Hildrum
On 12/11/06, Jordan Greenberg [EMAIL PROTECTED] wrote:
 Tor Hildrum wrote:
  The full pathname is in sys.argv[0]
 At least on my system, it only includes the filename if executed from
 the current directory.

Hm, yeah, I thought the full path was standard behavior but I see it's not.

I need to go change some code :)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Of integers, relations and trees

2006-12-08 Thread Tor Hildrum
I have this problem which I thought would be trivial, but I can't
seem to figure out a decent way to do it.

Say I have the following file:
10
-100
-101
-103
-108
--1080
---1080.10
---1080.11
12
-120
-125
20
30
-300
--3010
---3010.3

These numbers represents a tree-like structure.

In lack of a better explanation, here is how it works:
A level in the tree follows the following:
x * 10^level

x * 10^1 belongs to level 1 in the three
x * 10^2 belongs to level 2 in the three.
etc.

So, the top-nodes in the three are 10, 12, 20 and 30.
The childs of 10 is 100, 101, 103 and 108.
The child of 108 is 1080.
The child of 1080 is 1080.10 and 1080.11 and these are the leaves.

I decided to make this pretty straightforward so I wrote a Node class
and a Tree class.
A Node has a key which is an integer, as well as some additional
information that isn't relevant to the structure. It also has a link
to it's sibling, which is the next node on the same level. And a link
to it's first child.

So for 10, it looks like this.:
10 - 20  (siblings of 10)
 | (child)
100 - 101 - 103 - 108 (siblings of 100)

Inserting a sibling is done like this:
-
def addSibling(self, newNode):
tmp = self.node # current node
last = self.node # previous node

# find the node that is the direct sibling to the new node
while( tmp != None  tmp['key']  newNode['key']):
  last = tmp
  tmp = tmp['sibling']

# insert the new node after the node with a lower key
last['sibling'] = newNode

# If there is a node with a higher key, add it as a sibling to the new node
if( tmp != None ):
  newNode['sibling'] = tmp
-

This code does not handle a special case where the newNode has the
smallest key among the siblings and should be placed first and thus be
the direct child of the parent level. But, that doesn't really matter.

How do I know if I have a sibling or a child?
Simple, I just check the length:
-
if( len(str(node1[key])) == len(str(node2[key])) ):
-

If the length, amount of integers, is the same, they are siblings.

My problem is this:
Say I have created a new node with the key 2080.

I start of with my root node which has a key of 0. 2080 is not
a sibling of 0, so I call a recursive function named addChild().
addChild checks the child of 0, which is 10 and determines that
2080 is not a sibling of 10. But, it's not a child either.

Here comes my query:
How do I determine that 2080 is not a child of 10. Or how do i determine
that 536798 is not a child of 536780? And how do I determine that it is a child?

I'll try to explain again:
5.36798 * 10^5 is at level 5 in the tree.
It's direct children looks like this:
5.36798x * 10^6.
5.36797x * 10^6 is NOT a child, it is a child of 5.36797 * 10^5.
Does this make sense to anyone? :)

Also, consider the following:
5.36798xxx * 10^8

While this is not a direct child of 5.36798 * 10^5, it is a child of a
child and belongs in that subtree.

I can't seem to rack my brains around a solution for this. Maybe it's
my tree-structure that is making this more complex than it should be?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Best Known Method for Filtering redundant list items.

2006-12-01 Thread Tor Hildrum
On 11/30/06, John Fouhy [EMAIL PROTECTED] wrote:

 For the same reason that dictionaries don't preserve order.
 Basically, sets are (I think) implemented using a hash table.  You can
 read about hash tables on wikipedia (or many other places), but one of
 the components of a hash table is a function mapping keys to integers
 in a particular range.

Why not just call a sigar for a sigar.

A set is a set, it may be implemented using a hash or it may be
implemed using some other datastructure. It could be implemented using
lists which preserves order, all though that doesn't make much sense.
How it is implemented does not really matter here.

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

If you want a collection of ordered objects, you don't want a set. Not
even if the current implementation of sets in Python did preserve
order. Doing so could not be considered as anything else than a ugly
hack or exploitation of the current implementation. And would be
likely to break in the future.

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