[Tutor] Speech recognition, and synthesis

2010-04-11 Thread Ray Parrish

Hello,

Are there any Python libraries that deal with speech recognition, and 
speech synthesis?


If so, where are they available, and are there any open source versions?

Thanks for any help you can be.

Later, Ray Parrish

--
Linux dpkg Software Report script set..
http://www.rayslinks.com/LinuxdpkgSoftwareReport.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com


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


[Tutor] Declaring methods in modules.

2010-04-11 Thread Ray Parrish

Hello,

I am working on some stuff, and I would like to be able to write a 
module which can be imported, and after it's been imported I would like 
to be able to access it's functions as methods.


In other words, if I do the import of module ISPdetector, I want to then 
be able to make calls like the following -


   ipAddress = "123.123.123.123"
   emails = ipAddress.GetEmailAddresses()

where GetEmailAddresses() is defined in module ISPdetector. Do I just 
wite that function in ISPdetector.py as a normally deffed function, or 
does it have to be part of a class within the module?


Thanks for any help you can be.

Later, Ray Parrish

--
Linux dpkg Software Report script set..
http://www.rayslinks.com/LinuxdpkgSoftwareReport.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com


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


Re: [Tutor] Declaring methods in modules.

2010-04-11 Thread Patrick Sabin

   ipAddress = "123.123.123.123"
   emails = ipAddress.GetEmailAddresses()


Not exactly sure, what you want, but maybe something like this?

class mystr(str):
def GetEmailAddresses(self):
return [str(self)]

ipAddress = mystr("123.123.123.123")
emails = ipAddress.GetEmailAddresses()

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


Re: [Tutor] Declaring methods in modules.

2010-04-11 Thread Alan Gauld


"Ray Parrish"  wrote

I am working on some stuff, and I would like to be able to write a module 
which can be imported, and after it's been imported I would like to be 
able to access it's functions as methods.


OK, Kind of...

In other words, if I do the import of module ISPdetector, I want to then 
be able to make calls like the following -


   ipAddress = "123.123.123.123"
   emails = ipAddress.GetEmailAddresses()


This won;t work since ipAddress is a string and you can't add methods to a 
builtin type.


But you could define a new special type of string class - an IPstring say - 
and

add methods to that. Put that definition in a module and you code becomes:

import ispdetector

ipAddress = ispdetector.IPstring("123.123.123.123")# use module to 
access the class
emails = ipAddress.getEmailAddresses() # use the locally created 
instance to access methods


where GetEmailAddresses() is defined in module ISPdetector. Do I just 
wite that function in ISPdetector.py as a normally deffed function, or 
does it have to be part of a class within the module?


If you want to use it as a method it needs to be in a class. You could just 
write
it as a function that hass a string parameter in which case your code looks 
like:


import ispdetector

ipAddress = "123.123.123.123"
emails = ispdetector.getEmailAddresses(ipAddress) # use the module 
and pass the strintg


Whether you need a class or not depends on what the restof your code is 
doing
and how data is being handled/stored etc. But we don;t have enough 
information
to be sure. My guess is that a class will be handy because you will likely 
need
several such methods all acting on common data - which is the definition of 
a class!


HTH,

--
Alan Gauld
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] Speech recognition, and synthesis

2010-04-11 Thread Alan Gauld


"Ray Parrish"  wrote

Are there any Python libraries that deal with speech recognition, and 
speech synthesis?


Yes.

If so, where are they available, 


Google "python speech recognition synthesis"

There are several. I can't recommend any because I've 
never used them.



and are there any open source versions?


Yes.

HTH,

--
Alan Gauld
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] Declaring methods in modules.

2010-04-11 Thread Steven D'Aprano
On Sun, 11 Apr 2010 10:30:54 pm Ray Parrish wrote:
> Hello,
>
> I am working on some stuff, and I would like to be able to write a
> module which can be imported, and after it's been imported I would
> like to be able to access it's functions as methods.
>
> In other words, if I do the import of module ISPdetector, I want to
> then be able to make calls like the following -
>
> ipAddress = "123.123.123.123"
> emails = ipAddress.GetEmailAddresses()

Can't be done -- in Python, built-in types like strings can't have new 
methods added to them, and thank goodness for that! The ability to 
monkey-patch builtins is more dangerous than useful. 

But you can subclass builtins, as Alan suggested:

# module ISPdetector
class MyString(string):
def GetEmailAddresses(self):
pass

# another module
import ISPdetector
ipAddress = ISPdetector.MyString("123.123.123.123")
emails = ipAddress.GetEmailAddresses()


But that is a strange API design. IP addresses aren't strings, they're 
integers, and although they are commonly written in quad-dotted form as 
a string, you don't want to treat them as strings. For example, 
something like ipAddress.replace('2', 'P') makes no sense.

Also, making GetEmailAddresses a method of an IP address implies that 
address *have* email addresses, which is nonsense. People have email 
addresses. Computer accounts have email addresses. Particular email 
*messages* come from an IP address, but IP addresses don't have email 
addresses. A better name would be ipaddress.find_email_from().

So I would suggest the best API is either to create an IP address class 
(or better still, don't re-invent the wheel, use one of the fine 
existing IP address modules already written), or write functions in the 
module and just call them:

import ISPdetector
ipAddress = "123.123.123.123"
emails = find_email_from(ipAddress)

Remember, in Python methods are just syntactic sugar for function calls. 
obj.method(arg) is just another way of spelling method(obj, arg).



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


Re: [Tutor] Declaring methods in modules.

2010-04-11 Thread Chris Fuller

This actually isn't so hard with classes (not instances of the class).  Just 
use setattr().  The first parameter of the function will be the instance, 
called "self" by convention.  This should work with both old and new style 
There's stuff in the new module for adding stuff to instances, but I haven't 
played around with it recently.  A little fiddling around in the interactive 
interpreter should clear up anything you're uncertain about, though.

Cheers


On Sunday 11 April 2010, Ray Parrish wrote:
> Hello,
> 
> I am working on some stuff, and I would like to be able to write a
> module which can be imported, and after it's been imported I would like
> to be able to access it's functions as methods.
> 
> In other words, if I do the import of module ISPdetector, I want to then
> be able to make calls like the following -
> 
> ipAddress = "123.123.123.123"
> emails = ipAddress.GetEmailAddresses()
> 
> where GetEmailAddresses() is defined in module ISPdetector. Do I just
> wite that function in ISPdetector.py as a normally deffed function, or
> does it have to be part of a class within the module?
> 
> Thanks for any help you can be.
> 
> Later, Ray Parrish
> 

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


Re: [Tutor] Declaring methods in modules.

2010-04-11 Thread Chris Fuller

Sorry, should have included a concrete example.  Although, as the others have 
said, I'm not sure how it helps with what you (seem) to want to do.

0 % cat bar.py
def the_answer(self):
   return 42
0 % cat foo.py
import bar

class A:
   pass


setattr(A, '__call__', bar.the_answer)

a=A()
print a()

class B(object):
   pass


setattr(B, '__call__', bar.the_answer)

b=B()
print b()

0 % python foo.py 
42
42


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


[Tutor] Sequences of letter

2010-04-11 Thread Juan Jose Del Toro
Dear List;

I have embarked myself into learning Python, I have no programming
background other than some Shell scripts and modifying some programs in
Basic and PHP, but now I want to be able to program.

I have been reading Alan Gauld's Tutor which has been very useful and I've
also been watching Bucky Roberts (thenewboston) videos on youtube (I get
lost there quite often but have also been helpful).

So I started with an exercise to do sequences of letters, I wan to write a
program that could print out the suquence of letters from "aaa" all the way
to "zzz"  like this:
aaa
aab
aac
...
zzx
zzy
zzz

So far this is what I have:
letras =
["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","x","y","z"]
letra1 = 0
letra2 = 0
letra3 = 0
for i in letras:
for j in letras:
for k in letras:
print letras[letra1]+letras[letra2]+letras[letra3]
letra3=letra3+1
letra2=letra2+1
letra1=letra1+1

It goes all the way to aaz and then it gives me this error
Traceback (most recent call last):
 File "/home/administrador/programacion/python/letras2.py", line 8, in

print letras[letra1]+letras[letra2]+letras[letra3]
IndexError: list index out of range
Script terminated.

Am I even in the right path?
I guess I should look over creating a function or something like that
because when I run it I can't even use my computer no memory left

-- 
¡Saludos! / Greetings!
Juan José Del Toro M.
jdeltoro1...@gmail.com
Guadalajara, Jalisco MEXICO
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sequences of letter

2010-04-11 Thread Mark Tolonen


"Juan Jose Del Toro"  wrote in message 
news:s2i9b44710e1004112212zdf0b052fxe647ba6bb9671...@mail.gmail.com...

Dear List;

I have embarked myself into learning Python, I have no programming
background other than some Shell scripts and modifying some programs in
Basic and PHP, but now I want to be able to program.

I have been reading Alan Gauld's Tutor which has been very useful and I've
also been watching Bucky Roberts (thenewboston) videos on youtube (I get
lost there quite often but have also been helpful).

So I started with an exercise to do sequences of letters, I wan to write a
program that could print out the suquence of letters from "aaa" all the way
to "zzz"  like this:
aaa
aab
aac
...
zzx
zzy
zzz

So far this is what I have:
letras =
["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","x","y","z"]
letra1 = 0
letra2 = 0
letra3 = 0
for i in letras:
   for j in letras:
   for k in letras:
   print letras[letra1]+letras[letra2]+letras[letra3]
   letra3=letra3+1
   letra2=letra2+1
letra1=letra1+1

It goes all the way to aaz and then it gives me this error
Traceback (most recent call last):
File "/home/administrador/programacion/python/letras2.py", line 8, in

print letras[letra1]+letras[letra2]+letras[letra3]
IndexError: list index out of range
Script terminated.

Am I even in the right path?
I guess I should look over creating a function or something like that
because when I run it I can't even use my computer no memory left

--
¡Saludos! / Greetings!
Juan José Del Toro M.
jdeltoro1...@gmail.com
Guadalajara, Jalisco MEXICO







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



It's easier than you think.  Here's a hint:


for i in 'abcd':

...  print i
...
a
b
c
d

What are the values of i,j,k in your loop?

-Mark


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


Re: [Tutor] Sequences of letter

2010-04-11 Thread Patrick Sabin

So far this is what I have:
letras = 
["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","x","y","z"]

letra1 = 0
letra2 = 0
letra3 = 0
for i in letras:
for j in letras:
for k in letras:
print letras[letra1]+letras[letra2]+letras[letra3]
letra3=letra3+1
letra2=letra2+1
letra1=letra1+1


It goes all the way to aaz and then it gives me this error
Traceback (most recent call last):
 File "/home/administrador/programacion/python/letras2.py", line 8, in 


print letras[letra1]+letras[letra2]+letras[letra3]
IndexError: list index out of range


You should consider resetting the letra-variables before each loop (not 
before every loop).


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