Re: [Tutor] iterating over a sequence question..

2007-06-18 Thread Simon Hooper
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,

print [(l[i%len(l)],t[i%len(t)]) for i in range(max(len(l), len(t)))]

Regards

Simon.

-- 
Simon Hooper
PARTEX MARKING SYSTEMS UK LTD
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python and XSI

2007-06-18 Thread Vishal Jain

Hello Guys!!
I have just started learning Python couple days back, actually, I am a
fresher to programming. I am trying to get Python registered with XSI but
everything described in docs failed. I have Python 2.5.1 and Pywin32 build
210 installed. I tried to register Python manually also by running the file
C:\Python25\Lib\site-packages\win32comext\axscript\client\pyscript.py but
still no luck. Is anybody else also facing the same situation? I am not very
sure how many people here uses Python for XSI but still hoping to get some
light on my problem.

Thanks a lot

--
Vishal
(TheBigV)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help converting base32 to base16

2007-06-18 Thread cms cms

Hello all,

Newbie here trying to find a module that I can use to convert a number of
strings (sha1 values) from base32 to base16 (hex), and vice versa. I've
searched this list for similar questions, the Global Module Index, the
Vaults of Parnassus, as well as the obvious (Google); however , I cannot
seem to find anything on point. While I'm sure the solution will be obvious,
it currently escapes me.

TIA for any comments or suggestions.


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


Re: [Tutor] Finding all locations of a sequence

2007-06-18 Thread Danny Yoo


> 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.

Hi Lauren,

I am positive that this problem has been tackled before.  Have you talked 
to any of your fellow bioinformaticists?  It might not be effective to ask 
on Python-tutor because, for typical problems, regexes are sufficient. 
For your particular scenario, regexes may not be, so you may want to ask 
specialists like those on the Biopython mailing lists:

 http://biopython.org/wiki/Mailing_lists

It may seem like a simple extension of regular expression search, but as 
you may have noticed, feeding 4100 regex searches across that RNA sequence 
is going to take some time.  And trying to feed all of those subsequences 
as a single regular expression (using ORs) is probably not going to work 
too well either: the engine has limitations on how large the pattern can 
be before it starts behaving very badly.


To scale to this problem, we need to do something different.  What you're 
probably looking for is more typically known as the keyword matching 
problem, and there are algorithms specifically used for keyword matching. 
For example, take a look at Nicholas Lehuen's Pytst package, which 
implements ternary search trees:

 http://nicolas.lehuen.com/index.php/category/Pytst

I've also written a different package that uses the "Aho-Corasick" 
automata matcher, but to tell the truth I've let the code stale a bit, and 
can't support it (too busy with other work).  But if you're interested in 
tinkering with it, it's here: 
http://hkn.eecs.berkeley.edu/~dyoo/python/ahocorasick/.


If you're going to do more string-matching stuff, I'd recommend a look 
into "Algorithms on Strings, Trees, and Sequences".

 http://www.cambridge.org/uk/catalogue/catalogue.asp?isbn=0521585198

It's one of the better books on bioinformatics string algorithms, and it 
specifically covers this class of sequence-searching problems.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python and XSI

2007-06-18 Thread Alan Gauld
"Vishal Jain" <[EMAIL PROTECTED]> wrote

> I am trying to get Python registered with XSI but
> everything described in docs failed.

OK, I'm assuming that XSI is the 3D Graphics software from Avid?

Can you tell us which docs and what exactly 'failed' means?
What did you do and what actually happened?
Any error messages?

> C:\Python25\Lib\site-packages\win32comext\axscript\client\pyscript.py

ISTR that as being the script for registering Python as an
Active Scripting language for WSH and the IE ActiveX engine.

I assume from that, that XSI uses active scripting?

What did you expect to happen after running it?
And what did happen?

> still no luck. Is anybody else also facing the same situation? I am 
> not very
> sure how many people here uses Python for XSI but still hoping to 
> get some

I had to do a Google search...
You might have more luck on the main comp.lang.python list or
maybe even in the pyGame list. This group is for beginners to Python
and XSI looks a tad advanced for most beginners, going by the couple
of pages I browsed. OTOH there is usually somebody here with an
interest in most things...

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


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


Re: [Tutor] Help converting base32 to base16

2007-06-18 Thread Kent Johnson
cms cms wrote:
> Hello all,
> 
> Newbie here trying to find a module that I can use to convert a number of
> strings (sha1 values) from base32 to base16 (hex), and vice versa. I've
> searched this list for similar questions, the Global Module Index, the
> Vaults of Parnassus, as well as the obvious (Google); however , I cannot
> seem to find anything on point. While I'm sure the solution will be obvious,
> it currently escapes me.

The int() function takes a second argument of the base, so it can 
convert from base 16 or base 32 to integers. The hex() function converts 
from integer to base 16 but there is no equivalent built-in for base 32.

This cookbook recipe will convert in both directions:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/111286

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


[Tutor] [Fwd: Re: Help converting base32 to base16]

2007-06-18 Thread Kent Johnson
Forwarding to the list...

 Original Message 
Subject: Re: [Tutor] Help converting base32 to base16
Date: Mon, 18 Jun 2007 12:12:46 -0500
From: lucio arteaga <[EMAIL PROTECTED]>
To: Kent Johnson <[EMAIL PROTECTED]>
References: <[EMAIL PROTECTED]> 
<[EMAIL PROTECTED]>

You are the second person that in less than a moth  has had a similar.
Please  Read in page  241 of my book Algorithms and their Computer 
Solutions
written by Lucio Arteaga ,and published by  Charles E. Merrill in 1972.

- Original Message -
From: "Kent Johnson" <[EMAIL PROTECTED]>
To: "cms cms" <[EMAIL PROTECTED]>
Cc: 
Sent: Monday, June 18, 2007 11:30 AM
Subject: Re: [Tutor] Help converting base32 to base16


> cms cms wrote:
>> Hello all,
>>
>> Newbie here trying to find a module that I can use to convert a number of
>> strings (sha1 values) from base32 to base16 (hex), and vice versa. I've
>> searched this list for similar questions, the Global Module Index, the
>> Vaults of Parnassus, as well as the obvious (Google); however , I cannot
>> seem to find anything on point. While I'm sure the solution will be 
>> obvious,
>> it currently escapes me.
>
> The int() function takes a second argument of the base, so it can
> convert from base 16 or base 32 to integers. The hex() function converts
> from integer to base 16 but there is no equivalent built-in for base 32.
>
> This cookbook recipe will convert in both directions:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/111286
>
> 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] Help converting base32 to base16

2007-06-18 Thread Alan Gauld
"cms cms" <[EMAIL PROTECTED]> wrote

> Newbie here trying to find a module that I can use to convert a 
> number of
> strings (sha1 values) from base32 to base16 (hex), and vice versa.

I'm intrigued. What does a base 32 number look like?
For example what is 29 in base 32?
Or 1022 for that matter?

I undeetsanmd the principle but I'm wondering what characters
are used above the F of hex.

Also who uses base 32 and for what purpose?

Alan G. 


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


Re: [Tutor] Help converting base32 to base16

2007-06-18 Thread Jason Massey

Nice entry at wikipedia:

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

I like the naming of Base32: *duotrigesimal

*Gotta try to work that into a conversation somehow.*
*
On 6/18/07, Alan Gauld <[EMAIL PROTECTED]> wrote:


"cms cms" <[EMAIL PROTECTED]> wrote

> Newbie here trying to find a module that I can use to convert a
> number of
> strings (sha1 values) from base32 to base16 (hex), and vice versa.

I'm intrigued. What does a base 32 number look like?
For example what is 29 in base 32?
Or 1022 for that matter?

I undeetsanmd the principle but I'm wondering what characters
are used above the F of hex.

Also who uses base 32 and for what purpose?

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] iterating over a sequence question..

2007-06-18 Thread Luke Paireepinart

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
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help converting base32 to base16

2007-06-18 Thread Alan Gauld

"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.

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


Re: [Tutor] Finding all locations of a sequence (fwd)

2007-06-18 Thread Danny Yoo
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 hours.  His question is below.  Thanks!


-- Forwarded message --
Date: Mon, 18 Jun 2007 16:41:39 -0400
From: Lauren <[EMAIL PROTECTED]>
To: Danny Yoo <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Finding all locations of a sequence

Ok, these may be useful. I do have a potentially embarrassing problem,
however I will preface this with I'm practically computer illiterate. Ok
after I download the one you wrote (which I think I understand better than
the one listed previous...famous last words, I'm sure), but when I ask to
import the ahocorasick module, it says it can't find it :( Is it possible to
get step by step instructions on how to open the module? Do I need something
other than the latest download for it?
Again, I'm not good at this programming thing, so I'm sure I'm missing
something obvious

Thank you for your help,

Lauren

On 18/06/07, Danny Yoo <[EMAIL PROTECTED]> wrote:
>
>
>
>> 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.
>
> Hi Lauren,
>
> I am positive that this problem has been tackled before.  Have you talked
> to any of your fellow bioinformaticists?  It might not be effective to ask
> on Python-tutor because, for typical problems, regexes are sufficient.
> For your particular scenario, regexes may not be, so you may want to ask
> specialists like those on the Biopython mailing lists:
>
>  http://biopython.org/wiki/Mailing_lists
>
> It may seem like a simple extension of regular expression search, but as
> you may have noticed, feeding 4100 regex searches across that RNA sequence
> is going to take some time.  And trying to feed all of those subsequences
> as a single regular expression (using ORs) is probably not going to work
> too well either: the engine has limitations on how large the pattern can
> be before it starts behaving very badly.
>
>
> To scale to this problem, we need to do something different.  What you're
> probably looking for is more typically known as the keyword matching
> problem, and there are algorithms specifically used for keyword matching.
> For example, take a look at Nicholas Lehuen's Pytst package, which
> implements ternary search trees:
>
>  http://nicolas.lehuen.com/index.php/category/Pytst
>
> I've also written a different package that uses the "Aho-Corasick"
> automata matcher, but to tell the truth I've let the code stale a bit, and
> can't support it (too busy with other work).  But if you're interested in
> tinkering with it, it's here:
> http://hkn.eecs.berkeley.edu/~dyoo/python/ahocorasick/
> .
>
>
> If you're going to do more string-matching stuff, I'd recommend a look
> into "Algorithms on Strings, Trees, and Sequences".
>
>  http://www.cambridge.org/uk/catalogue/catalogue.asp?isbn=0521585198
>
> It's one of the better books on bioinformatics string algorithms, and it
> specifically covers this class of sequence-searching problems.
>



-- 
Lauren

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


Re: [Tutor] sockets

2007-06-18 Thread Linus Nordström
gusse i use this thread as my own little help thread.. :)

im having problem whit recv. It will not break the loop if ther are
nothing more to recive. It dose recv all tit should, but then it go
another round in the loop and get stuck on recv, as far as print
debugging has showed,  Dont realy know waht ells information i could
write sown to make my problem anny clrearer, so ask if anythin is
unclear :)

And on another note, is there a way to use the self. less, it might be
just me but it looks rather ugly :)

def recive(self):
 all_data = []
 while 1:
 self.buf = self.s.recv(4096)
 if not self.buf: break
 all_data.append(self.buf)
 return all_data


On 6/18/07, Linus Nordström <[EMAIL PROTECTED]> wrote:
> Hello
> I'm trying to rewrite a chat-program i did in school this spring in
> python, the school program was in java. All this to leran python.
>
> Anyway. I m trying to send a message using udp to a server that
> conntains the message 3 0 0 0, it has to be in network byte order and
> unsigned. I have tried to send it like a string "3000" but get an
> error message from the server saying that it did recive 4 bytes, but
> that it was an unknown message
>
> So what i am wondering is if there are anny special byte arrays, or
> some thing i should use. or if there are anny other way than to send
> the message than a string.
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sockets

2007-06-18 Thread Alan Gauld
"Linus Nordström" <[EMAIL PROTECTED]> wrote

> im having problem whit recv. It will not break the loop if ther are
> nothing more to recive.

Take a look at the client side of the address book
example in my network profgramming topic. It shows
an example of breaking out of a recv loop.

Another option is to use the select module services

> And on another note, is there a way to use the self. less,
> it might be just me but it looks rather ugly :)

No, it's good practice, it distinguishes between class level
variables and local variables. The use of self/this etc is usually
required in industrial coding standards for C++ and Java
(eg Dept of defense/Government etc) for the same reason,
even though those languages don't require it. As in many
things python is simply enforcing what is already considered
good practice elsewhere.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


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


Re: [Tutor] Finding all locations of a sequence (fwd)

2007-06-18 Thread Alan Gauld

> From: Lauren <[EMAIL PROTECTED]>
> To: Danny Yoo <[EMAIL PROTECTED]>
> Subject: Re: [Tutor] Finding all locations of a sequence
>
> after I download the one you wrote (which I think I understand 
> better than
> the one listed previous...famous last words, I'm sure), but when I 
> ask to
> import the ahocorasick module, it says it can't find it :(

You will need to ocate and download the module too.
Either store it along with your program or in the site-packages
folder in your python installation.

> get step by step instructions on how to open the module?

You just import it.
You can read more about that in my modules and functions topic
if that helps.

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld



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


Re: [Tutor] cannot pickle instancemethod objects

2007-06-18 Thread hok kakada
នៅថ្ងៃ ពុធ 13 មិថុនា 2007 19:09, Kent Johnson បាន​សរសេរ​ថា ៖
> hok kakada wrote:
> >> What kind of object is matcher? Does it have any attributes that are
> >> functions? (Not methods you defined for the class, but functions or
> >> methods that you assign to attributes of self.)
> >
> > Actually, I use the translate-toolkit from
> > http://translate.sourceforge.net/snapshots/translate-toolkit-1.0.1rc1/
> > in translate/search/match.py:
> > if comparer is None:
> > comparer = lshtein.LevenshteinComparer(max_length)
> >
>  > self.comparer = comparer
> >
> > I just found the problem that it is because of the LevenshteinComparer.
> > Once I assign self.comparer = None, the I can dump the matcher
> > successfully. However, I still don't understand what could be wrong with
> > LevenshteinComparer.
>
> I think the problem is this code in LevenshteinComparer.__init__():
>
>  if Levenshtein:
>  self.distance = self.native_distance
>  else:
>  self.distance = self.python_distance
>
> which assigns an instance method to an instance attribute; this is the
> instancemethod that can't be pickled.
Ok...but how can we deal with it?

Kind Regards,
da
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor