Re: [Tutor] printing the random seed?

2006-02-01 Thread Danny Yoo


On Thu, 2 Feb 2006, kevin parks wrote:

> Danny (hope you are good!) & co,
>
> I see that biz about random.seed()... but in the absence of setting that
> ... does it just grab a value from the system clock?

Yes.  Here's what the documentation says officially:

"""current system time is also used to initialize the generator when the
module is first imported"""


> Is there a way to just let it generate it's usual, known seed... but
> then observe what that is in case you get an especially good run of
> data?

We can call seed() explicitely using system time then when we start using
the random module, and if the results are interesting, we report that
initial seed value too.  That way, by knowing the initial conditions, we
can reproduce the results.

##
>>> import time
>>> import random
>>>
>>> t = time.time()
>>>
>>> random.seed(t)
>>> random.random()
0.39026231885512619
>>> random.random()
0.72296902513427053
>>> random.random()
0.48408173490166762
>>>
>>> t
1138866167.719857
>>>
>>> random.seed(t)
>>> random.random()
0.39026231885512619
>>> random.random()
0.72296902513427053
>>> random.random()
0.48408173490166762
##

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


Re: [Tutor] need to get unique elements out of a 2.5Gb file

2006-02-01 Thread Danny Yoo


On Wed, 1 Feb 2006, Srinivas Iyyer wrote:

> I have a file which is 2.5 Gb.,
>
[data cut]
>
> There are many duplicate lines.  I wanted to get rid of the duplicates.


Hi Srinivas,

When we deal with such large files, we do have to be careful and aware of
issues like the concept of memory.


> I chose to parse to get uniqe element.
>
> f1 = open('mfile','r')
> da = f1.read().split('\n')
   ^

This line is particularly problematic.  Your file is 2.5GB, so you must
have at least have that much memory.  That's already a problem for most
typical desktops.  But you also need to store roughly 2.5GB as you're
building the list of line elements from the whole string we've read from
f1.read().

And that just means you've just broken the limits of most 32-bit machines
that can't address more than 2**32 MB of memory at once!

##
>>> 2**32
4294967296L
>>> 2 * (2.5 * 10**9)  ## Rough estimate of memory necessary to do
   ## what your program needs at that point
50.0
##

That's the hard limit you're facing here.


You must read the file progressively: trying to process it all at once is
not going to scale at all.

Simpler is something like this:

##
uniqueElements = Set()
for line in open('mfile'):
   uniqueElements.add(line.rstrip())
##

which tries to accumulate only unique elements, reading the file line by
line.

However, this approach too has limits.  If the number of unique elements
exceeds the amount of system memory, this too won't work.  (An approach
that does work involves using a mergesort along with auxiliary scratch
files.)



If you really need to get this job done fast, have you considered just
using the Unix 'sort' utility?

It has a uniqueness flag that you can enable, and it's always a good
approach to use tools that already exist rather than write your own.

That is, your problem may be solved by the simple shell command:

sort -u [somefile]
(Alternatively:   sort [somefile] | uniq)

So I guess my question is: why did you first approached this "unique line"
problem with Python?

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


Re: [Tutor] printing the random seed?

2006-02-01 Thread kevin parks
Danny (hope you are good!) & co,

I see that biz about random.seed()... but in the absence of setting 
that ... does it
just grab a value from the system clock?

Is there a way to just let it generate it's usual, known seed... but 
then observe
what that is in case you get an especially good run of data?

like i clearly can't just go:

zeed = random.seed()
print "zeed = ", zeed

hmm...

cheers,

-[kp]--

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


Re: [Tutor] printing the random seed?

2006-02-01 Thread Danny Yoo


> I am having some fun with python and making multiple runs on an
> algorhythm and sometimes getting some fun stuff that i would like to be
> able to reproduce, but there are some random elements in it. I wonder is
> there a way to see the random seed, and make note of it so that you
> could then set the seed for a subsequent run to get the same (initially)
> random results?

Hi Kevin,

Sure; take a look at the seed() function in the random module.

http://www.python.org/doc/lib/module-random.html#l2h-1298

Just set it to some consistant value at the very beginning of your
program, and you should then see duplicate results between program runs.

You could also probably do something with random.getstate() and
random.setstate(), but it's probably a bit simpler just to inject a known
seed value into the pseudorandom generator.


>   (Hi Danny, if you are still here!)

*wave wave*


Good luck!

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


[Tutor] need to get unique elements out of a 2.5Gb file

2006-02-01 Thread Srinivas Iyyer
Hi Group,

I have a file which is 2.5 Gb.,
 
TRIM54  NM_187841.1 GO:0004984
TRIM54  NM_187841.1 GO:0001584
TRIM54  NM_187841.1 GO:0003674
TRIM54  NM_187841.1 GO:0004985
TRIM54  NM_187841.1 GO:0001584
TRIM54  NM_187841.1 GO:0001653
TRIM54  NM_187841.1 GO:0004984

There are many duplicate lines.  I wanted to get rid
of the duplicates.

I chose to parse to get uniqe element.

f1 = open('mfile','r')
da = f1.read().split('\n')
dat = da[:-1]
f2 = open('res','w')
dset = Set(dat)
for i in dset:
f2.write(i)
f2.write('\n')
f2.close()

Problem: Python says it cannot hande such a large
file. 
Any ideas please help me.

cheers
srini

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] printing the random seed?

2006-02-01 Thread kevin parks
hi.

I am having some fun with python and making multiple runs on an 
algorhythm and sometimes getting some fun stuff that i would like to be 
able to reproduce, but there are some random elements in it. I wonder 
is there a way to see the random seed, and make note of it so that you 
could then set the seed for a subsequent run to get the same 
(initially) random results?

cheers,

kevin

  (Hi Danny, if you are still here!)

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


Re: [Tutor] mapping problem

2006-02-01 Thread Kent Johnson
Srinivas Iyyer wrote:
> Dear group, 
>   I have a problem in finding a method to solve a
> problem where I want to walk through a lineage of
> terms and find group them from right to left. 
> 
> A snippet of the problem is here. The terms in file as
> tab delim manner. 
> 
> a b   c   d   car
> a b   c   f   truck
> a b   c   d   van
> a b   c   d   SUV
> a b   c   f   18-wheeler
> a b   j   k   boat
> a b   j   a   submarine
> a b   d   a   B-747
> a b   j   c   cargo-ship
> a b   j   p   passenger-cruise ship
> a b   a   a   bicycle
> a b   a   b   motorcycle
> 
> 
> Now my question is to enrich members that have
> identical lineage with different leaf.
> 'i.e': a b c d - van suv . I have two terms in this
> path and I am not happy with two. I wish to have more.
> 
> Then: a b c - car, van, truck, SUV and 18-wheeler
> (automobiles that travel on road). I am happy with
> this grouping and I enriched more items if I walk on
> lienage : (a-b-c)

I'm not sure I understand what you want to do, but I think a tree where 
each internal node is a dict and each leaf node is a list will do what 
you want. You would end up with something like
tree['a']['b']['c']['d'] = ['car', 'van', 'suv']

To find the value for a b c you would traverse the tree to that point, 
then accumulate all the leaf nodes underneath.

OK I guess I feel like writing code, here is a simple implementation. It 
requires that all the leaves be at the same depth. It's not particularly 
clever but it works and shows what can be done just by hooking together 
basic data structures.

raw_data = '''a   b   c   d   car
a   b   c   f   truck
a   b   c   d   van
a   b   c   d   SUV
a   b   c   f   18-wheeler
a   b   j   k   boat
a   b   j   a   submarine
a   b   d   a   B-747
a   b   j   c   cargo-ship
a   b   j   p   passenger-cruise ship
a   b   a   a   bicycle
a   b   a   b   motorcycle'''.splitlines()

tree = {}

# This builds the tree of nested dictionaries with lists as the leaves
for line in raw_data:
 data = line.split(None, 5)
 keys = data[:4]
 value = data[4]

 # This loop makes the dict nodes
 subtree = tree
 for key in keys[:-1]:
 subtree = subtree.setdefault(key, {})

 # The last key points to a list, not a dict
 lastkey = keys[-1]
 subtree.setdefault(lastkey, []).append(value)


def iter_leaves(subtree):
 ''' Recursive generator that yields all the leaf nodes of subtree '''
 if isinstance(subtree, list):
 # A leaf node
 yield subtree
 return

 for item in subtree.itervalues():
 for leaf in iter_leaves(item):
 yield leaf

def get_leaves(*keys):
 ''' Return a list of all the leaves in the subtree pointed to by 
*keys '''
 subitem = tree
 for key in keys:
 subitem = subitem[key]

 leaves = []
 for leaf in iter_leaves(subitem):
 leaves.extend(leaf)

 return leaves

print get_leaves('a', 'b', 'c', 'd')
print get_leaves('a', 'b', 'c')

## prints

['car', 'van', 'SUV']
['car', 'van', 'SUV', 'truck', '18-wheeler']

Kent

> 
> 
> Thus, I want to try to enrich for all 21 K lines of
> lineages.
> 
> My question:
> 
> Is there a way to automate this problem.
> 
> My idea of doing this:
> 
> Since this is a tab delim file. I want to read a line
> with say 5 columns (5 tabs).  Search for items with
> same column item 4 (because leaf items could be
> unique). If I find a hit, then check if columns 3 and
> 2 are identical if so create a list. 
> 
> Although this problem is more recursive and time and
> resource consuming, I cannot think of an easy
> solution. 
> 
> Would you please suggest a nice and simple method to
> solve this problem. 
> 
> For people who are into bioinformatics (I know Danny
> Yoo is a bioinformatician) the question is about GO
> terms.  I parsed OBO file and laid out the term
> lineages that constitute the OBO-DAG structure. I want
> to enrich the terms to do an enrichment analysis for a
> set of terms that I am interested in.
> 
> Thank you in advance.
> 
> cheers
> Srini
> 
> 
> 
> 
> __
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> ___
> 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] Exit a child thread using threading.Thread() object

2006-02-01 Thread Bernard Lebel
Thanks a lot Kent.

The exit call would be made from the same thread whose fate is to terminate.

Bernard


On 1/31/06, Kent Johnson <[EMAIL PROTECTED]> wrote:
> Bernard Lebel wrote:
> > A quick question.
> >
> > I have started a child thread using the threading.Thread class. Is
> > there any way to cleanly exit the child thread?
> >
> > What I mean by "cleanly" is for example if you use the
> > thread.start_new() function to create a child thread, the function
> > running in the child thread can call thread.exit() to terminate the
> > thread.
> >
> > I could not find anything comparable in the Thread object's documentation.
>
> Both thread.start_new() and threading.Thread wrap a callable object in a
> new thread. For start_new(), the callable is a parameter passed to the
> function. For threading.Thread, the callable can be passed as an
> initialization parameter or by overriding Thread.run().
>
> In any case, the thread runs until the wrapped method terminates, either
> by a normal function return or by raising an uncaught exception. The
> usual way to exit a thread is for the wrapped callable to return (just a
> normal function return).
>
> thread.exit() just raises SystemExit which terminates the callable with
> an uncaught exception. You could probably do the same in a Thread by
> raising SystemExit explicitly or calling sys.exit() (which raises
> SystemExit for you). But just returning normally from the callable is
> the usual way to exit a thread from within the thread.
>
> If you want to stop a thread from another thread it is harder. The
> cleanest way to do it is to set a flag that the running thread will
> check. There are several recipes in the online cookbook that show how to
> do this.
>
> Kent
>
> ___
> 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] mapping problem

2006-02-01 Thread Danny Yoo


> A snippet of the problem is here. The terms in file as
> tab delim manner.

[data cut]

> Now my question is to enrich members that have identical lineage with
> different leaf. 'i.e': a b c d - van suv.


Hi Srinivas,

You're starting to use the vocabulary of tree data structures here.  Let's
clarify what you mean by:

> I have two terms in this path and I am not happy with two. I wish to
> have more.

I think you mean "I have two descendent leaves at this point ...", in
which case your next statement:


> Then: a b c - car, van, truck, SUV and 18-wheeler (automobiles that
> travel on road). I am happy with this grouping and I enriched more items
> if I walk on lienage : (a-b-c)

sounds like traversing up from your current node up to the parent node. In
your example, this expands the descendent leaves to include those other
elements.



> Is there a way to automate this problem.

I would strongly recommend not thinking about this as a text file problem,
but as a data structure problem.  Trying to do this by messing with lines
and tabs seems to me like asking to turn a simple problem into a difficult
one.  The fact that the data that you have is in a text file should be
treated as an accident more than anything: nothing binds you to try to
solve your problem by slogging through with the original data
representation.

The problem becomes much clearer if you're dealing with trees:

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

in which case you can use the vocabulary of tree traversal to make the
problem very simple.  I might be misundestanding what you're sying but it
sounds like you're just asking for parent node traversal, which is a
fundamental operation on trees.

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


Re: [Tutor] mapping problem

2006-02-01 Thread Hugo González Monteverde
What about choosing a native Python data structure for this?

A list of attributes comes to mind, as presence of one can be easily 
tested with

if x in attributes:
 do_something

Here's a test:

 >>> elements= {}
 >>> elements['boat'] = ['a', 'b', 'j', 'k']
 >>> 'a' in elements['boat']
True
 >>>

Then it is just a matter of getting the fiels into the structure, and 
then recursing through  the elements, like this.


elements = {}

for line in table_fileo:
 fields = line.split()

 #get rid of linefeed
 fields[-1] = fields[-1][:-1]

 elements[fields[-1]] = fields[:-1]

Then you get a dictionary with the last name in the table as key and a 
list of the other attributes as value.

Then, if you want to look for an attribute, just do:
for element in elements.items():
 if 'j' in element[1]:
 print element[0]

What do you think?

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


Re: [Tutor] Todays Learning Python Question From a Newbie ;)

2006-02-01 Thread Bob Gailer
Jon Moore wrote:
> Hi,
>
> Ok its the last exercise in the chapter of the python book (Python for 
> the absolute beginner) I am working my way through.
>
> I have been learning about functions using a tic-tac-toe game as an 
> example and I understand it fairly clearly, however the author says 
> the following:
>
> Write a new computer_move() function for the tic-tac-toe game to plug 
> the hole in the computers stratergy. See if you can create an opponent 
> that is unbeatable!
>
> My main problem is that I can not see how the computers stratergy can 
> be improved as at best I can only manage a tie with the computer!
See http://ostermiller.org/tictactoeexpert.html.
The "bottom line" is "If you know what you are doing, you can't lose at 
Tic-Tac-Toe. If your opponent knows what they are doing, you can't win 
at Tic-Tac-Toe. The game is a zero sum game. If both players are playing 
with an optimal strategy, every game will end in a tie."
[snip]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] mapping problem

2006-02-01 Thread Srinivas Iyyer
Dear group, 
  I have a problem in finding a method to solve a
problem where I want to walk through a lineage of
terms and find group them from right to left. 

A snippet of the problem is here. The terms in file as
tab delim manner. 

a   b   c   d   car
a   b   c   f   truck
a   b   c   d   van
a   b   c   d   SUV
a   b   c   f   18-wheeler
a   b   j   k   boat
a   b   j   a   submarine
a   b   d   a   B-747
a   b   j   c   cargo-ship
a   b   j   p   passenger-cruise ship
a   b   a   a   bicycle
a   b   a   b   motorcycle


Now my question is to enrich members that have
identical lineage with different leaf.
'i.e': a b c d - van suv . I have two terms in this
path and I am not happy with two. I wish to have more.

Then: a b c - car, van, truck, SUV and 18-wheeler
(automobiles that travel on road). I am happy with
this grouping and I enriched more items if I walk on
lienage : (a-b-c)


Thus, I want to try to enrich for all 21 K lines of
lineages.

My question:

Is there a way to automate this problem.

My idea of doing this:

Since this is a tab delim file. I want to read a line
with say 5 columns (5 tabs).  Search for items with
same column item 4 (because leaf items could be
unique). If I find a hit, then check if columns 3 and
2 are identical if so create a list. 

Although this problem is more recursive and time and
resource consuming, I cannot think of an easy
solution. 

Would you please suggest a nice and simple method to
solve this problem. 

For people who are into bioinformatics (I know Danny
Yoo is a bioinformatician) the question is about GO
terms.  I parsed OBO file and laid out the term
lineages that constitute the OBO-DAG structure. I want
to enrich the terms to do an enrichment analysis for a
set of terms that I am interested in.

Thank you in advance.

cheers
Srini




__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question re. Functions

2006-02-01 Thread Jon Moore
Thats fine, but what differance does it make?I can see no way that it improves the code.I assume later on when the function is called, it should look as follows:move = ask_number("Where will you move? (0-8): ", 0, NUM_SQUARES, 1)
JonOn 01/02/06, Ed Singleton <[EMAIL PROTECTED]> wrote:
On 31/01/06, Jon Moore <[EMAIL PROTECTED]> wrote:> Improve the function ask_number() so that the function can be called with a> step value. Make the default value of step 1.
>> The function looks like this:>> def ask_number(question, low, high):> """Ask for a number within the range"""> response = None> while response not in range(low, high):
> response =  int(raw_input(question))> return responseTo be honest, this made sense to me.  I assumed the author wants youto be able to do the following:ask_number("Give me an even number between 1 and 10", 1, 10, 2)
The solution would be:def ask_number(question, low, high, step=1):"""Ask for a number within the range"""response = Nonewhile response not in range(low, high, step):
response =  int(raw_input(question))return responseBut I definitely agree that he said it very, very badly.Ed___Tutor maillist  -  
Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor-- Best Regards
Jon Moore
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question re. Functions

2006-02-01 Thread Ed Singleton
On 31/01/06, Jon Moore <[EMAIL PROTECTED]> wrote:
> Improve the function ask_number() so that the function can be called with a
> step value. Make the default value of step 1.
>
> The function looks like this:
>
> def ask_number(question, low, high):
> """Ask for a number within the range"""
> response = None
> while response not in range(low, high):
> response =  int(raw_input(question))
> return response

To be honest, this made sense to me.  I assumed the author wants you
to be able to do the following:

ask_number("Give me an even number between 1 and 10", 1, 10, 2)

The solution would be:

def ask_number(question, low, high, step=1):
"""Ask for a number within the range"""
response = None
while response not in range(low, high, step):
response =  int(raw_input(question))
return response

But I definitely agree that he said it very, very badly.

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


Re: [Tutor] smtplib with yahoo smtp server

2006-02-01 Thread Python
On Wed, 2006-02-01 at 18:51 +0530, Intercodes wrote:
> Received: by wproxy.gmail.com with SMTP id i23so141320wra for
> ; Wed, 01 Feb 2006 05:21:36 -0800 (PST)
> Received: by 10.65.228.15 with SMTP id f15mr63752qbr; Wed, 01 Feb 2006
> 05:21:36 -0800 (PST)
> Received: by 10.65.100.11 with HTTP; Wed, 1 Feb 2006 05:21:36 -0800
> (PST)
> Message-ID:
> <[EMAIL PROTECTED]>

Intercodes, you are using a web interface to send your email.  Can you
get a "normal" (Evolution, Thunderbird, pine, etc.) email client to work
on your system.  If those do not work, your Python program probably
won't work either.

The errors you're getting appear to come from system config issues
rather than programming errors.

-- 
Lloyd Kvam
Venix Corp

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


Re: [Tutor] smtplib with yahoo smtp server

2006-02-01 Thread Intercodes
Ewald,>Here, I think is a strange problem. You can not resolve your own hostname.
>Is there no entry in /etc/hosts for linux with the IP-Address of your server?>If not, try to insert such an entry. 
Thanks for all your suggestions. I inserted my IP address for 'linux' into /etc/hosts. Now smtplib.SMTP() works. But the authentication fails. I tried all combinations of user/pass , but no joy.I tried using gmail (
smtp.gmail.com), but it too shows some TLS error or something.I ve searched google , but every script that is available for smtplib uses either sendmail or use their own/isp smtp server. None for connecting to yahoo/gmail/hotmail or other servers using authentication.
But anyway, ill try hotmail next. (If I can't get this smtp to work, I have to manually send mails to users :p, disastrous. ) Thanks for your time.-- Intercodes

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


Re: [Tutor] Re : Project Work

2006-02-01 Thread Kent Johnson
Chandrashekar Jayaraman wrote:
> I m doing a project using Python and Bluetooth . I tried running the 
> sample programs given with the pybluez-0.5 distro with python 2.4 . The 
> socket program s just dont seem to run . However the inquiry.py program 
> run s perfectly.
> ne solutions ?

"just dont seem to run" is pretty vague. Exactly what did you try? 
Exactly what happened? If there is an error message or stack trace, copy 
/ paste it into your email and show us.

Kent

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


[Tutor] Re : Project Work

2006-02-01 Thread Chandrashekar Jayaraman
I m doing a project using Python and Bluetooth . I tried running the
sample programs given with the pybluez-0.5 distro with python 2.4 . The
socket program s just dont seem to run . However the inquiry.py program
run s perfectly. 
ne solutions ?

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


[Tutor] Todays Learning Python Question From a Newbie ;)

2006-02-01 Thread Jon Moore
Hi,Ok its the last exercise in the chapter of the python book (Python for the absolute beginner) I am working my way through.I have been learning about functions using a tic-tac-toe game as an example and I understand it fairly clearly, however the author says the following:
Write a new computer_move() function for the tic-tac-toe game to plug the hole in the computers stratergy. See if you can create an opponent that is unbeatable!
My main problem is that I can not see how the computers stratergy can be improved as at best I can only manage a tie with the computer! If I could see past this, I could hopefully work out the code.
Copy of the function:def computer_move(board, computer, human):    """Make computer move."""
    # make a copy to work with since function will be changing list
    board = board[:]    # the best positions to have, in order    BEST_MOVES = (4, 0, 2, 6, 8, 1, 3, 5, 7)
    print "I shall take square number",
        # if computer can win, take that move    for move in legal_moves(board):
    board[move] = computer    if winner(board) == computer:
    print move    return move
    # done checking this move, undo it    board[move] = EMPTY
        # if human can win, block that move
    for move in legal_moves(board):    board[move] = human    if winner(board) == human:
    print move    return move
    # done checkin this move, undo it    board[move] = EMPTY
    # since no one can win on next move, pick best open square    for move in BEST_MOVES:
    if move in legal_moves(board):    print move
    return move-- Best Regards
Jon Moore
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] smtplib with yahoo smtp server

2006-02-01 Thread Ewald Ertl
Hi!

Intercodes wrote:
> 
> My nssswitch.conf
> --
> passwd: compat
> group:  compat
> 
> hosts:  files dns
> networks:   files dns
> 
> services:   files
> protocols:  files
> rpc:files
> ethers: files
> netmasks:   files
> netgroup:   files
> publickey:  files
> 
> bootparams: files
> automount:  files nis
> aliases:files
> 
>  
> -
> 

The system looks first in the /etc/hosts-File and when there is no match found, 
the
configured DNS would be requested.

> 
> >This should resolve your own local hostname!
> >The socket.gethostbyname () is a call into a shared object of
> Python and this >would use ( So think I ) the standard-Libraries for
> resolution.
> 
> 
> You totally lost me here :)
> -
> 
> 
> >Is "linux" a valid hostname?
> >Does "ping linux" succeed.
> 
> 
> I suppose not.
> 
> linux:/srv/ # ping linux
> ping: unknown host linux
> --

Here, I think is a strange problem. You can not resolve your own hostname.
Is there no entry in /etc/hosts for linux with the IP-Address of your server?
If not, try to insert such an entry.

HTH Ewald

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


Re: [Tutor] smtplib with yahoo smtp server

2006-02-01 Thread Intercodes
Ewald, 
> -- ex= smtplib.SMTP('smtp.mail.yahoo.com ')> Traceback (most recent call last):>   File "", line 1, in ?>   File "/usr/lib/python2.4/smtplib.py", line 241, in __init__> (code, msg) = self.connect
(host, port)>   File "/usr/lib/python2.4/smtplib.py", line 289, in connect> for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):> socket.gaierror: (-2, 'Name or service not known')
>> I am sorry , that's a mistake on my part. This output corresponds to a  typo input data. The error you saw previously was the original one (the one with error on line 255...). I corrected the typo while posting it ( ..I thought the error was same)
 -->the call should be 
socket.getaddrinfo( "smtp.mail.yahoo.com", 25, 0, >socket.SOCK_STREAM ); >>>socket.getaddrinfo('
smtp.mail.yahoo.com',25,0,socket.SOCK_STREAM)[(2, 1, 6, '', ('216.136.173.18', 25))]--
How do you resolve your hostnames ( /etc/nsswitch.conf gives the order of hostname resolution )
My nssswitch.conf --passwd: compatgroup:  compathosts:  files dnsnetworks:   files dnsservices:   filesprotocols:  files
rpc:    filesethers: filesnetmasks:   filesnetgroup:   filespublickey:  filesbootparams: filesautomount:  files nisaliases:    files -
>This should resolve your own local hostname!>The socket.gethostbyname
() is a call into a shared object of Python and this >would use ( So think I ) the standard-Libraries for resolution.You totally lost me here :) -
>Is "linux" a valid hostname?>Does "ping linux" succeed.
I suppose not.linux:/srv/ # ping linuxping: unknown host linux--
-- Intercodes
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] smtplib with yahoo smtp server

2006-02-01 Thread Ewald Ertl
Hi!



Intercodes wrote:
> Ewald,
> 
>  First off, thanks for stopping by.
> 
> >The connection via the smtplib.SMTP() could be established.
> 
> 
>  I dont think so. I think it fails before the login().
> 
> --
 ex= smtplib.SMTP('smtp.mail.yahoo.com ')
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "/usr/lib/python2.4/smtplib.py", line 241, in __init__
> (code, msg) = self.connect(host, port)
>   File "/usr/lib/python2.4/smtplib.py", line 289, in connect
> for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
> socket.gaierror: (-2, 'Name or service not known')
> 
> 

Here you get a different Traceback than in the original post.

After digging in smtplib.py here ( Python 2.3.3 )

the call should be socket.getaddrinfo( "smtp.mail.yahoo.com", 25, 0, 
socket.SOCK_STREAM );

which succeeds here at my installation.

How do you resolve your hostnames ( /etc/nsswitch.conf gives the order of 
hostname resolution )



>  >>> socket.gethostname()
> 'linux'
> -
> 
 socket.gethostbyname(socket.gethostname())
> Traceback (most recent call last):
>   File "", line 1, in ?
> socket.gaierror: (-2, 'Name or service not known')

> -- 

This should resolve your own local hostname!
The socket.gethostbyname() is a call into a shared object of Python and this 
would use
( So think I ) the standard-Libraries for resolution.

Is "linux" a valid hostname?
Does "ping linux" succeed.

I still think, that this a name resolution error on your host.

HTH Ewald

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


Re: [Tutor] smtplib with yahoo smtp server

2006-02-01 Thread Intercodes
Ewald, First off, thanks for stopping by. >The connection via the 
smtplib.SMTP() could be established.  I dont think so. I think it fails before the login().-->>> ex=
smtplib.SMTP('smtp.mail.yahoo.com')Traceback (most recent call last):  File "", line 1, in ?  File "/usr/lib/python2.4/smtplib.py", line 241, in __init__
    (code, msg) = self.connect(host, port)  File "/usr/lib/python2.4/smtplib.py", line 289, in connect    for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):socket.gaierror: (-2, 'Name or service not known')
 >>> socket.gethostname()'linux'->>> 
socket.gethostbyname(socket.gethostname())Traceback (most recent call last):  File "", line 1, in ?socket.gaierror: (-2, 'Name or service not known')
>>>-- linux:/srv/www/htdocs/konnect # nslookup smtp.mail.yahoo.com
Server: 203.145.184.13Address:    203.145.184.13#53Non-authoritative answer:smtp.mail.yahoo.com canonical name = 
smtp.plus.mail.yahoo.com.smtp.plus.mail.yahoo.com    canonical name = smtp.plus.mail.yahoo4.akadns.net
.Name:   smtp.plus.mail.yahoo4.akadns.netAddress: 216.136.173.18 -
Thank you,--Intercodes
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] smtplib with yahoo smtp server

2006-02-01 Thread Ewald Ertl
Hi!

I made a copy of the source you posted.
I just got a problem as expected when doing the session.login()
because the access-data is invalid.
The connection via the smtplib.SMTP() could be established.

Perhaps there is something wrong with your namelookup.

Can you try a call in the interactive environment for
socket.gethostname()
or
socket.gethostbyname( socket.gethostname() )

Can you resolve the hostname "smtp.mail.yahoo.com" on a commandline?
e.g. nslookup smtp.mail.yahoo.com ?

Hope this can help you

Ewald


Intercodes wrote:
> 
> Hello everyone,
> 
> I am working with a registration system for my website in mod_python. I
> needed to send mail to registered users for confirmation. Since I can't
> use my ISP's smtp server, I used yahoo's smtp server and my yahoo
> username and password  to connect and send mail using this script (see
> below). But I get the following error.
> 
> "Traceback (most recent call last):
>   File "mail.py", line 12, in ?
> session = smtplib.SMTP(smtpserver)
>   File "/usr/lib/python2.4/smtplib.py", line 255, in __init__
> addr = socket.gethostbyname(socket.gethostname())
> socket.gaierror: (-2, 'Name or service not known')
> "
> 
> I got this script from some website I can't remember and just changed
> some values to get it to work. Is is possible to send mail like this? Is
> there any other easy way to do this?
> 
> Thanks for your time.
> ---
> 
> import smtplib
> 
> smtpserver = 'smtp.mail.yahoo.com '
> AUTHREQUIRED = 1 
> smtpuser = 
> '[EMAIL PROTECTED]' //
> smtppass = '[snip]'  
> 
> RECIPIENTS = ['[EMAIL PROTECTED]']
> SENDER = '[EMAIL PROTECTED]'
> mssg = "mod python"
> 
> session = smtplib.SMTP(smtpserver)
> *if* AUTHREQUIRED:
> session.login(smtpuser, smtppass)
> smtpresult = session.sendmail(SENDER, RECIPIENTS, mssg)**
> 
> 
> -- 
> Intercodes
> 
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


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