Re: How can I make this piece of code even faster?

2013-07-21 Thread Peter Otten
pablobarhamal...@gmail.com wrote:

> Ok, I'm working on a predator/prey simulation, which evolve using genetic
> algorithms. At the moment, they use a quite simple feed-forward neural
> network, which can change size over time. Each brain "tick" is performed
> by the following function (inside the Brain class):
> 
> def tick(self):
> input_num = self.input_num
> hidden_num = self.hidden_num
> output_num = self.output_num
>  
> hidden = [0]*hidden_num
> output = [0]*output_num
> 
> inputs = self.input
> h_weight = self.h_weight
> o_weight = self.o_weight
> 
> e = math.e
> 
> count = -1
> for x in range(hidden_num):
> temp = 0
> for y in range(input_num):
> count += 1
> temp += inputs[y] * h_weight[count]
> hidden[x] = 1/(1+e**(-temp))
> 
> count = -1
> for x in range(output_num):
> temp = 0
> for y in range(hidden_num):
> count += 1
> temp += hidden[y] * o_weight[count]
> output[x] = 1/(1+e**(-temp))
>  
> self.output = output
> 
> The function is actually quite fast (~0.040 seconds per 200 calls, using
> 10 input, 20 hidden and 3 output neurons), and used to be much slower
> untill I fiddled about with it a bit to make it faster. However, it is
> still somewhat slow for what I need it.
>  
> My question to you is if you an see any obvious (or not so obvious) way of
> making this faster. I've heard about numpy and have been reading about it,
> but I really can't see how it could be implemented here.
> 
> Cheers!

Assuming every list is replaced with a numpy.array,

h_weight.shape == (hidden_num, input_num)
o_weight.shape == (output_num, hidden_num)

and as untested as it gets:

def tick(self):
temp = numpy.dot(self.inputs, self.h_weight)
hidden = 1/(1+numpy.exp(-temp))  

temp = numpy.dot(hidden, self.o_weight)
self.output = 1/(1+numpy.exp(-temp))  

My prediction: this is probably wrong, but if you can fix the code it will 
be stinkin' fast ;)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make this piece of code even faster?

2013-07-21 Thread Serhiy Storchaka

20.07.13 23:22, pablobarhamal...@gmail.com написав(ла):

 e = math.e

 count = -1
 for x in range(hidden_num):
 temp = 0
 for y in range(input_num):
 count += 1
 temp += inputs[y] * h_weight[count]
 hidden[x] = 1/(1+e**(-temp))

[...]

My question to you is if you an see any obvious (or not so obvious) way of 
making this faster.


1. Use math.exp() instead of math.e**.

2. I'm not sure that it will be faster, but try to use sum().

  temp = sum(inputs[y] * h_weight[count + y] for y in range(input_num))
  count += input_num

or

  temp = sum(map(operator.mul, inputs, h_weight[count:count+input_num]))
  count += input_num


--
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make this piece of code even faster?

2013-07-21 Thread Paul Rudin
Steven D'Aprano  writes:

> On Sat, 20 Jul 2013 13:22:03 -0700, pablobarhamalzas asked:
>
> "How can I make this piece of code even faster?"
>
> - Use a faster computer.
> - Put in more memory.
> - If using Unix or Linux, decrease the "nice" priority of the process.
>
> I mention these because sometimes people forget that if you have a choice 
> between "spend 10 hours at $70 per hour to optimize code", and "spend 
> $200 to put more memory in", putting more memory in may be more cost 
> effective.
>

Sure - but it's helpful if programmers understand a little bit about the
computational complexity of algorithms. If it's just a question of
making each basic step of your algorithm a bit faster, then it may well
be better to spend money on better hardware than on squeezing more out
of your code. OTOH if you've got an n^2 implementation and there's
actually an n.log n solution available then you should probably re-code.

Of course if what you've got is actually adequate for your use-case then
it maybe that you don't actually need to do anything at all...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make this piece of code even faster?

2013-07-21 Thread Christian Gollwitzer

How about using numpy?

Am 20.07.13 22:22, schrieb pablobarhamal...@gmail.com:

Ok, I'm working on a predator/prey simulation, which evolve using genetic algorithms. At 
the moment, they use a quite simple feed-forward neural network, which can change size 
over time. Each brain "tick" is performed by the following function (inside the 
Brain class):




 count = -1
 for x in range(hidden_num):
 temp = 0
 for y in range(input_num):
 count += 1
 temp += inputs[y] * h_weight[count]
 hidden[x] = 1/(1+e**(-temp))


I don't really understand this loop, but it looks to me like a 
matrix-vector multiplication of the matrix of weights (indexed with a 
single continous index) with the inputs.


Given that you reshape the weights() array correctly into a 
hidden_num-by-input_num array, this would result in


import numpy as np
hidden = 1.0/(1.0 + np.exp(-np.dot(h_weights, inputs)))

The matrix-vector product is then executed by a compiled loop. You can 
reshape your existing lists into that form by


inputs = np.array(inputs)
h_weight = np.reshape(h_weight, (hidden_num, input_num))

... but of course you should use this only to check whether you get the 
correct result. You don't want to do that in the loop, instead, store 
the weights always in matrix form.


Christian
--
http://mail.python.org/mailman/listinfo/python-list


Re: Find and Replace Simplification

2013-07-21 Thread Serhiy Storchaka

20.07.13 20:03, Joshua Landau написав(ла):

Still, it seems to me that it should be optimizable for sensible
builtin types such that .translate is significantly faster, as there's
no theoretical extra work that .translate *has* to do that .replace
does not, and .replace also has to rebuild the string a lot of times.


You should analyze overall mapping and reorder items in right order (if 
it possible), i.e. '&' should be replaced before '<' in html.escape. 
This extra work is too large for most real input.



--
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make this piece of code even faster?

2013-07-21 Thread Chris Angelico
On Sun, Jul 21, 2013 at 5:11 PM, Paul Rudin  wrote:
> Steven D'Aprano  writes:
>
>> On Sat, 20 Jul 2013 13:22:03 -0700, pablobarhamalzas asked:
>>
>> "How can I make this piece of code even faster?"
>>
>> - Use a faster computer.
>> - Put in more memory.
>> - If using Unix or Linux, decrease the "nice" priority of the process.
>>
>> I mention these because sometimes people forget that if you have a choice
>> between "spend 10 hours at $70 per hour to optimize code", and "spend
>> $200 to put more memory in", putting more memory in may be more cost
>> effective.
>>
>
> Sure - but it's helpful if programmers understand a little bit about the
> computational complexity of algorithms. If it's just a question of
> making each basic step of your algorithm a bit faster, then it may well
> be better to spend money on better hardware than on squeezing more out
> of your code. OTOH if you've got an n^2 implementation and there's
> actually an n.log n solution available then you should probably re-code.

I haven't analyzed every suggestion in this thread in detail, but I
don't think any of them affects the algorithmic complexity of the
code. They're all incremental changes.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make this piece of code even faster?

2013-07-21 Thread pablobarhamalzas
Thank's for all the replies! I've tried some of the imporovements you suggested 
(using math.exp() and sum() or math.fsum()). 
None of that made the code faster, because they are functions you are calling 
lots of times, and function calling is quite time expensive (same as x**(1/2) 
is faster than math.sqrt(x)).

I'm going to try to convert tu numpy now (I have no idea how to do it at the 
moment), thank's again to everyone.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make this piece of code even faster?

2013-07-21 Thread Steven D'Aprano
On Sun, 21 Jul 2013 03:19:24 -0700, pablobarhamalzas wrote:

> Thank's for all the replies! I've tried some of the imporovements you
> suggested (using math.exp() and sum() or math.fsum()). None of that made
> the code faster, because they are functions you are calling lots of
> times, and function calling is quite time expensive (same as x**(1/2) is
> faster than math.sqrt(x)).

You are *badly* mistaken. Not only is sqrt more accurate, but it is also 
much faster.


[steve@ando ~]$ python3.3 -m timeit -s "x = 2.357e7" "x**0.5"
100 loops, best of 3: 0.319 usec per loop
[steve@ando ~]$ python3.3 -m timeit -s "x = 2.357e7" -s "from math import 
sqrt" "sqrt(x)"
1000 loops, best of 3: 0.172 usec per loop


How exactly are you timing the code?



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make this piece of code even faster?

2013-07-21 Thread Chris Angelico
On Sun, Jul 21, 2013 at 8:31 PM, Steven D'Aprano
 wrote:
> On Sun, 21 Jul 2013 03:19:24 -0700, pablobarhamalzas wrote:
>
>> Thank's for all the replies! I've tried some of the imporovements you
>> suggested (using math.exp() and sum() or math.fsum()). None of that made
>> the code faster, because they are functions you are calling lots of
>> times, and function calling is quite time expensive (same as x**(1/2) is
>> faster than math.sqrt(x)).
>
> You are *badly* mistaken. Not only is sqrt more accurate, but it is also
> much faster.
>
>
> [steve@ando ~]$ python3.3 -m timeit -s "x = 2.357e7" "x**0.5"
> 100 loops, best of 3: 0.319 usec per loop
> [steve@ando ~]$ python3.3 -m timeit -s "x = 2.357e7" -s "from math import
> sqrt" "sqrt(x)"
> 1000 loops, best of 3: 0.172 usec per loop

Don't forget the cost of attribute lookup, which adds 50% to the
sqrt() figure. Still faster than exponentiation. (Figures from Python
3.4 alpha, but unlikely to be materially different.)

rosuav@sikorsky:~$ python3 -m timeit -s "x = 2.357e7" "x**0.5"
100 loops, best of 3: 0.239 usec per loop
rosuav@sikorsky:~$ python3 -m timeit -s "x = 2.357e7" -s "from math
import sqrt" "sqrt(x)"
1000 loops, best of 3: 0.102 usec per loop
rosuav@sikorsky:~$ python3 -m timeit -s "x = 2.357e7" -s "import math"
"math.sqrt(x)"
1000 loops, best of 3: 0.155 usec per loop

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make this piece of code even faster?

2013-07-21 Thread pablobarhamalzas
El domingo, 21 de julio de 2013 12:31:42 UTC+2, Steven D'Aprano  escribió:
> On Sun, 21 Jul 2013 03:19:24 -0700, pablobarhamalzas wrote:
> 
> 
> 
> > Thank's for all the replies! I've tried some of the imporovements you
> 
> > suggested (using math.exp() and sum() or math.fsum()). None of that made
> 
> > the code faster, because they are functions you are calling lots of
> 
> > times, and function calling is quite time expensive (same as x**(1/2) is
> 
> > faster than math.sqrt(x)).
> 
> 
> 
> You are *badly* mistaken. Not only is sqrt more accurate, but it is also 
> 
> much faster.
> 
> 
> 
> 
> 
> [steve@ando ~]$ python3.3 -m timeit -s "x = 2.357e7" "x**0.5"
> 
> 100 loops, best of 3: 0.319 usec per loop
> 
> [steve@ando ~]$ python3.3 -m timeit -s "x = 2.357e7" -s "from math import 
> 
> sqrt" "sqrt(x)"
> 
> 1000 loops, best of 3: 0.172 usec per loop
> 
> 
> 
> 
> 
> How exactly are you timing the code?

I'm timing the whole program with cProfile. Removing math.sqrt() from a 
function and using **(1/2) instead cut the execution time for a significant 
amount (~0.035 to ~0.020). I can't see another explanation for the speed 
increase...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner - GUI devlopment in Tkinter - Any IDE with drag and drop feature like Visual Studio?

2013-07-21 Thread Dave Cook
On 2013-07-20, Aseem Bansal  wrote:

> Do I need to use QtCreator with PySide if I want drag-and-drop
> feature for GUI development? 

No, you just need the layout part of QtCreator, called QtDesigner, and
any decent Python editor or IDE (e.g. Idle):

http://wiki.python.org/moin/IntegratedDevelopmentEnvironments

There's another Qt IDE that uses QtDesigner called Monkey Studio
(seems to be PyQt only).

Designers can be really nice for learning the toolkit widgets and
layout, but I'd like to get away from them in my own projects,
actually, and move to something like enaml:

http://docs.enthought.com/enaml/

> Do I need to install Qt? If yes, which version - 4.8 or 5.1? 

PySide does not support 5.x yet, according to their website.  I
installed the PySide windows download, and it seems to work without
needing any Qt packages.

> Can I use cxfreeze to make exe files from the GUI developed? 

Probably.  We use py2exe for our wxPython/numpy application. 
Depending on the complexity and number of external modules used by
your application, bundling tools like this can require some google-fu
and trial and error to get working.  

http://qt-project.org/wiki/Packaging_PySide_applications_on_Windows

Dave Cook
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner - GUI devlopment in Tkinter - Any IDE with drag and drop feature like Visual Studio?

2013-07-21 Thread Chris “Kwpolska” Warrick
On Sun, Jul 21, 2013 at 1:14 PM, Dave Cook  wrote:
> On 2013-07-20, Aseem Bansal  wrote:
>
>> Do I need to use QtCreator with PySide if I want drag-and-drop
>> feature for GUI development?
>
> No, you just need the layout part of QtCreator, called QtDesigner, and
> any decent Python editor or IDE (e.g. Idle):

…and one more thing: pyside-uic, for transforming the .ui files into
(ugly) .py files.  It seems to be in /PythonXY/Scripts according to
Stack Overflow if you have PySide installed.
--
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Find and Replace Simplification

2013-07-21 Thread Joshua Landau
On 21 July 2013 08:44, Serhiy Storchaka  wrote:
> 20.07.13 20:03, Joshua Landau написав(ла):
>
>> Still, it seems to me that it should be optimizable for sensible
>> builtin types such that .translate is significantly faster, as there's
>> no theoretical extra work that .translate *has* to do that .replace
>> does not, and .replace also has to rebuild the string a lot of times.
>
> You should analyze overall mapping and reorder items in right order (if it
> possible), i.e. '&' should be replaced before '<' in html.escape. This extra
> work is too large for most real input.

I don't understand. What items are you reordering?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make this piece of code even faster?

2013-07-21 Thread Joshua Landau
On 20 July 2013 21:22,   wrote:
> Ok, I'm working on a predator/prey simulation, which evolve using genetic 
> algorithms. At the moment, they use a quite simple feed-forward neural 
> network, which can change size over time. Each brain "tick" is performed by 
> the following function (inside the Brain class):
>

>
> The function is actually quite fast (~0.040 seconds per 200 calls, using 10 
> input, 20 hidden and 3 output neurons), and used to be much slower untill I 
> fiddled about with it a bit to make it faster. However, it is still somewhat 
> slow for what I need it.
>
> My question to you is if you an see any obvious (or not so obvious) way of 
> making this faster. I've heard about numpy and have been reading about it, 
> but I really can't see how it could be implemented here.

Currently we're just guessing; if you gave us an appropriate stand-in
for "self" (so that we can call the function) we could be helpful much
more easily.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Find and Replace Simplification

2013-07-21 Thread Serhiy Storchaka

21.07.13 14:29, Joshua Landau написав(ла):

On 21 July 2013 08:44, Serhiy Storchaka  wrote:

20.07.13 20:03, Joshua Landau написав(ла):


Still, it seems to me that it should be optimizable for sensible
builtin types such that .translate is significantly faster, as there's
no theoretical extra work that .translate *has* to do that .replace
does not, and .replace also has to rebuild the string a lot of times.


You should analyze overall mapping and reorder items in right order (if it
possible), i.e. '&' should be replaced before '<' in html.escape. This extra
work is too large for most real input.


I don't understand. What items are you reordering?


mapping.items(). We can implement s.translate({ord('<'): '<', 
ord('&'): '&'}) as s.replace('&', '&').replace('<', '<'), but 
not as s.replace('<', '<').replace('&', '&').



--
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make this piece of code even faster?

2013-07-21 Thread Stefan Behnel
pablobarhamal...@gmail.com, 21.07.2013 12:48:
> El domingo, 21 de julio de 2013 12:31:42 UTC+2, Steven D'Aprano  escribió:
>> [steve@ando ~]$ python3.3 -m timeit -s "x = 2.357e7" "x**0.5"
>> 100 loops, best of 3: 0.319 usec per loop
>> [steve@ando ~]$ python3.3 -m timeit -s "x = 2.357e7" -s "from math import 
>> sqrt" "sqrt(x)"
>> 1000 loops, best of 3: 0.172 usec per loop
>>
>> How exactly are you timing the code?
> 
> I'm timing the whole program with cProfile. Removing math.sqrt() from a 
> function and using **(1/2) instead cut the execution time for a significant 
> amount (~0.035 to ~0.020).

With or without the profiler running? Note that profiling will slow down
your code (especially function calls), often significantly and sometimes
even in such an unbalanced way that it visibly changes its execution
profile. Always make sure you validate your code changes with benchmarks,
outside of the profiler.

Stefan


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Find and Replace Simplification

2013-07-21 Thread Joshua Landau
On 21 July 2013 13:28, Serhiy Storchaka  wrote:
> 21.07.13 14:29, Joshua Landau написав(ла):
>
>> On 21 July 2013 08:44, Serhiy Storchaka  wrote:
>>>
>>> 20.07.13 20:03, Joshua Landau написав(ла):
>>>
 Still, it seems to me that it should be optimizable for sensible
 builtin types such that .translate is significantly faster, as there's
 no theoretical extra work that .translate *has* to do that .replace
 does not, and .replace also has to rebuild the string a lot of times.
>>>
>>>
>>> You should analyze overall mapping and reorder items in right order (if
>>> it
>>> possible), i.e. '&' should be replaced before '<' in html.escape. This
>>> extra
>>> work is too large for most real input.
>>
>>
>> I don't understand. What items are you reordering?
>
>
> mapping.items(). We can implement s.translate({ord('<'): '<', ord('&'):
> '&'}) as s.replace('&', '&').replace('<', '<'), but not as
> s.replace('<', '<').replace('&', '&').

I see -- that won't always be the case though, as there can be "loops"
aka "ab" -> "ba".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Play Ogg Files

2013-07-21 Thread Stefan Behnel
Devyn Collier Johnson, 20.07.2013 14:25:
> On 07/20/2013 12:21 AM, Stefan Behnel wrote:
>> Devyn Collier Johnson, 20.07.2013 03:06:
>>> I am making a chatbot that I host on Launchpad.net/neobot. I am currently
>>> converting the engine from BASH code to Python3. I need to convert this for
>>> cross-platform compatibility. I do not need to use Mplayer; I just show the
>>> below code to give others a better idea what I am doing. I would prefer to
>>> be Python3 independent; I do not want to use the system shell. I am fine
>>> with using Python3 modules like Pygame (if there is a py3 module). As long
>>> as the code is fast, efficient, and simple without depending on the system
>>> shell or external apps, that would be nice. I also need the code to execute
>>> while the rest of the script continues running.
>>>
>>>  jobs = multiprocessing.Process(SEND = subprocess.getoutput('mplayer
>>> -nogui -nolirc -noar -quiet ./conf/boot.ogg')) #Boot sound#
>> Well, since you mentioned it already, have you actually looked at pygame?
>> It should be able to do what you want. There's also pyaudio, which is more
>> specialised to, well, audio. A web search for python and ogg might provide
>> more.
>
> Thanks Stefan! I have not heard of Pyaudio; I will look into that. As for
> Pygame, I have not been able to find any good documentation for playing
> audio files.

A quick duckduckgo search gave me this, at least:

http://www.pygame.org/docs/ref/mixer.html


> Plus, I recently learned that Pygame is not Python3 compatible.

Looks like it's your lucky day:

http://www.pygame.org/wiki/FrequentlyAskedQuestions#Does%20Pygame%20work%20with%20Python%203?

Stefan


-- 
http://mail.python.org/mailman/listinfo/python-list


Simple Python script as SMTP server for outgoing e-mails?

2013-07-21 Thread Gilles
Hello

Every once in a while, my ISP's SMTP server refuses to send
perfectly legit e-mails because it considers them as SPAM.

So I'd like to install a dead-simple SMTP server on my XP computer
just to act as SMTP backup server.
All I'd need is to change the SMTP address in my e-mail client, and
off they go. No need for anything else like user authentication or
SPAM control.

Is there a no-brainer, ready-to-use solution in Python that I could
use for this?

Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-21 Thread Chris Angelico
On Mon, Jul 22, 2013 at 12:42 AM, Gilles  wrote:
> Hello
>
> Every once in a while, my ISP's SMTP server refuses to send
> perfectly legit e-mails because it considers them as SPAM.
>
> So I'd like to install a dead-simple SMTP server on my XP computer
> just to act as SMTP backup server.
> All I'd need is to change the SMTP address in my e-mail client, and
> off they go. No need for anything else like user authentication or
> SPAM control.
>
> Is there a no-brainer, ready-to-use solution in Python that I could
> use for this?

Rather than write something from scratch, I'd look at deploying
something out-of-the-box - Postfix, for instance - which you will be
able to configure much faster than writing your own. And then you
could have it either send via your ISP or send directly to the
receiving MTA, without much extra effort.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make this piece of code even faster?

2013-07-21 Thread Michael Torrie
On 07/21/2013 04:19 AM, pablobarhamal...@gmail.com wrote:
> Thank's for all the replies! I've tried some of the imporovements you 
> suggested (using math.exp() and sum() or math.fsum()). 
> None of that made the code faster, because they are functions you are calling 
> lots of times, and function calling is quite time expensive (same as x**(1/2) 
> is faster than math.sqrt(x)).
> 
> I'm going to try to convert tu numpy now (I have no idea how to do it at the 
> moment), thank's again to everyone.

Perhaps you'd have better results if you'd post a runnable piece of
code.  Otherwise we're just guessing since no one has the ability to
actually run your code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-21 Thread Gilles
On Mon, 22 Jul 2013 00:48:29 +1000, Chris Angelico 
wrote:
>Rather than write something from scratch, I'd look at deploying
>something out-of-the-box - Postfix, for instance - which you will be
>able to configure much faster than writing your own. And then you
>could have it either send via your ISP or send directly to the
>receiving MTA, without much extra effort.

Thank you but precisely, I was looking for a "ready-to-use solution in
Python" so that I wouldn't have to write it myself.

Also, I don't need a full-fledged SMTP server, just a tiny script that
will let me send the occasional e-mails from my e-mail client that my
ISP wrongly considers as SPAM.

So, does someone know of a good, SMTP server just to send e-mails?

Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-21 Thread Michael Torrie
On 07/21/2013 10:19 AM, Gilles wrote:
> So, does someone know of a good, SMTP server just to send e-mails?

What you're looking for is not an SMTP server but a Mail Transfer Agent,
called an MTA.

Pretty much all distros ship with an MTA by default, even if the SMTP
server part of it isn't installed or running. And often the MTA is, for
compatibility reasons, /usr/sbin/sendmail.

http://stackoverflow.com/questions/73781/sending-mail-via-sendmail-from-python

I'm sure there are MTA's implemented in python. Now that you know what
they are called (not SMTP servers!) you can search for them.

Dennis is correct, though, that most ISPs do block outbound port 25
connections for security and spam reasons, and require you to use their
SMTP server, which precludes the use of the local MTA.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-21 Thread Gilles
On Sun, 21 Jul 2013 11:46:52 -0600, Michael Torrie 
wrote:
>What you're looking for is not an SMTP server but a Mail Transfer Agent,
>called an MTA.
>
>Pretty much all distros ship with an MTA by default, even if the SMTP
>server part of it isn't installed or running. And often the MTA is, for
>compatibility reasons, /usr/sbin/sendmail.
>
>http://stackoverflow.com/questions/73781/sending-mail-via-sendmail-from-python
>
>I'm sure there are MTA's implemented in python. Now that you know what
>they are called (not SMTP servers!) you can search for them.
>
>Dennis is correct, though, that most ISPs do block outbound port 25
>connections for security and spam reasons, and require you to use their
>SMTP server, which precludes the use of the local MTA.

Thanks for the infos. Ideally, I was looking for a simple Windows app
as MTA, but a Python script is OK.

I'm not sure my ISP blocks outbound port 25 connections. I'll
experiment with a small Linux box.

I wist they would use a smarter SPAM filter that wouldn't flag
perfectly legit-looking outgoing e-mails.
-- 
http://mail.python.org/mailman/listinfo/python-list


Homework help requested, thanks to everyone.

2013-07-21 Thread John Ladasky
Thanks to everyone for their wealth of suggestions.  I already had my students 
playing with turtle.  And I had asked them to alphabetize a string (without 
having previously revealed the sorted() function).

So far, I have taken up the suggestion of the number-guessing game.  One of my 
students has a working version.  The logic is a bit clumsy, but it's a fine 
first attempt.

I will also take up the Twenty Questions idea.  My son and I played that game a 
lot over the years, to pass the time on long car rides.  And it would be a 
great way to introduce the binary tree data structure.

Another project I thought of was a Pig Latin translator.  (But do kids today 
even know what Pig Latin is?  Am I showing my age?)

Concerning more advanced, real-time, game-oriented graphics, I am trying to 
figure out how to build PyGame on top of Python3.x.  Supposedly it is possible. 
 I just haven't figured out how.  It's 2013: I refuse to complicate my 
students' programming education with Python 2.x.

I used wxPython happily for years, and I think that its graphical capabilities 
would probably be up to the task of a simple 2D game.  Unfortunately, it has 
the same problem as PyGame, at least for now.  The Py3-compatible version of 
wxPython, to be known as Phoenix, is still under development.

I'll keep Unity, Panda3D, and Blender in mind for later.  Again, one of my main 
concerns will be Python 3.x compatibility.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-21 Thread Ivan Shmakov
> Gilles   writes:
> On Sun, 21 Jul 2013 11:46:52 -0600, Michael Torrie wrote:

[Cross-posting to news:comp.mail.misc.]

 >> What you're looking for is not an SMTP server but a Mail Transfer
 >> Agent, called an MTA.

[...]

 >> Dennis is correct, though, that most ISPs do block outbound port 25
 >> connections for security and spam reasons, and require you to use
 >> their SMTP server, which precludes the use of the local MTA.

 > I'm not sure my ISP blocks outbound port 25 connections.  I'll
 > experiment with a small Linux box.

There's yet another issue: certain email "operators" may block
/inbound/ port 25 connections from ISP "customer" networks.

 > I wist they would use a smarter SPAM filter that wouldn't flag
 > perfectly legit-looking outgoing e-mails.

FWIW, it may also be possible to use an email service (such as
Google Mail) provided by a third-party.

-- 
FSF associate member #7257
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-21 Thread Grant Edwards
On 2013-07-21, Gilles  wrote:

> Every once in a while, my ISP's SMTP server refuses to send
> perfectly legit e-mails because it considers them as SPAM.
>
> So I'd like to install a dead-simple SMTP server on my XP computer
> just to act as SMTP backup server. All I'd need is to change the SMTP
> address in my e-mail client, and off they go. No need for anything
> else like user authentication or SPAM control.

Unless you've got a static IP address, a domain name, and a valid MX
record that will match up when they do a reverse DNS lookup, it's
pretty unlikely that you're going to have much luck running an SMTP
server.  Most other SMTP servers are probably going to ignore or
reject your attempts to transfer mail from your own SMTP server.

> Is there a no-brainer, ready-to-use solution in Python that I could
> use for this?

I'd recommend postfix or exim if I was going to try to do it, but I
think they're Unix-only.

-- 
Grant

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner - GUI devlopment in Tkinter - Any IDE with drag and drop feature like Visual Studio?

2013-07-21 Thread Dave Cook
On 2013-07-21, Chris “Kwpolska” Warrick  wrote:

> …and one more thing: pyside-uic, for transforming the .ui files into
> (ugly) .py files.  It seems to be in /PythonXY/Scripts according to
> Stack Overflow if you have PySide installed.

Also, it looks like it's possible to directly load the .ui files:

http://srinikom.github.io/pyside-docs/PySide/QtUiTools/QUiLoader.html

Dave Cook
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Homework help requested, thanks to everyone.

2013-07-21 Thread Chris Angelico
On Mon, Jul 22, 2013 at 6:49 AM, John Ladasky
 wrote:
> Another project I thought of was a Pig Latin translator.  (But do kids today 
> even know what Pig Latin is?  Am I showing my age?)


Even if they don't, they'll grok it no problem. It's simple enough.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-21 Thread Michael Torrie
On 07/21/2013 02:34 PM, Gilles wrote:
> Thanks for the infos. Ideally, I was looking for a simple Windows app
> as MTA, but a Python script is OK.

The Sendmail MTA has been ported to many platforms including windows.
But...

> I'm not sure my ISP blocks outbound port 25 connections. I'll
> experiment with a small Linux box.

Having spent a long time managing e-mail servers, everything Ivan said
in his reply is true as well.  I had forgotten a lot of that since I
haven't been running my own mail server (MTA or server part) in a while.
 I've sold my soul to Google for e-mail now with Google Apps for my
domain.

> I wist they would use a smarter SPAM filter that wouldn't flag
> perfectly legit-looking outgoing e-mails.

But then how would it know that legit-looking e-mails aren't in fact
SPAM?  E-mail is starting to be an almost intractable problem.  No
wonder the younger generations are just abandoning it entirely in favor
of centralized, cathedral-style messaging systems such as facebook.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Homework help requested, thanks to everyone.

2013-07-21 Thread Roy Smith
In article ,
 Chris Angelico  wrote:

> On Mon, Jul 22, 2013 at 6:49 AM, John Ladasky
>  wrote:
> > Another project I thought of was a Pig Latin translator.  (But do kids 
> > today even know what Pig Latin is?  Am I showing my age?)
> 
> 
> Even if they don't, they'll grok it no problem. It's simple enough.
> 
> ChrisA

Igpay ythonpay!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner - GUI devlopment in Tkinter - Any IDE with drag and drop feature like Visual Studio?

2013-07-21 Thread fronagzen
On Saturday, July 20, 2013 3:59:00 PM UTC+8, Aseem Bansal wrote:
> After considering all the options suggested here I decided to use 
> PySide/QtCreator as was suggested by Dave Cook. I created a simple GUI with 
> QtCreator and found a way to convert .ui files to .py files. So far so good.
> 
> But now I am having some confusion about the correct tools to use for PySide 
> and I am stuck due to that. I explored the PySide wiki and discussed the 
> confusion on Qt-forums but that didn't help much. The url of that discussion 
> is given below(without backslashes to avoid it being shortened). Just using 
> this on google you can easily find the discussion.
> 
> qt-project.org  forums   viewthread  30114
> 
> Do I need to use QtCreator with PySide if I want drag-and-drop feature for 
> GUI development? Do I need to install Qt? If yes, which version - 4.8 or 5.1? 
> 
> Can I use cxfreeze to make exe files from the GUI developed? I used it for 
> pure Python files and it worked. The size of the file was big but it worked 
> with me having to install Python on another computer. I tried to use cxfreeze 
> on the GUI Python script that I was finally able to make. Some exe was made 
> but no GUI started when I ran the exe. Is that a problem with cxfreeze or me 
> having wrong tools installed?
> 
> Any help is appreciated.

It is possible to freeze PyQt programs, yes; I've succeeded before. However, 
cxFreeze will grab the entire PyQt library, which is past a hundred megabytes 
in size, so you're going to end up with an enormous file.

Do you have a setup.py appropriately configured for this? You should probably 
do, it's rather likely that the autodetect isn't correctly identifying 
dependencies. cxFreeze actually lists missing modules near the beginning of its 
run, try and take a look at that. Unfortunately, not every single missing 
module is actually missing or critical, and I can't really help you identify 
which one. For example, for my script, I have:

Missing Modules:
? BeautifulSoup imported from lxml.html.souparser
? UserDict imported from lxml.html
? __main__imported from bdb
? _gestalt imported from platform
? _posixsubprocess imported from subprocess
? etree imported from lxml.ptclasslookup
? html5lib imported from lxml.html.html5parser
? htmlentitydefs imported from lxml.html.soupparser
? sets oimported from lxml.ElementInclude
? Ssouppraser imported from lxml.html.ElementSoup
? urllib.urlencode imported from lxml.html
? urllib.urlopen imported from lxml.html
? urllib2 imported from lxml.ElementInclude
? urlparse imported from lxml.ElementInclude
? win32api imported from platform
? win32con imported from platform

But the only thing I actually need to explicitly include in my setup.py is os, 
lxml and gzip. Go figure.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Homework help requested, thanks to everyone.

2013-07-21 Thread Joseph Clark
John, have you taken a look at pyglet?  It's an alternative to pygame and I 
found it pretty slick once I got the hang of it.  There is a development 
version that's compatible with python 3 and I've never had a bug with it.  It 
wraps OpenGL itself so there are no additional dependencies.



// joseph w. clark , phd , visiting research associate
\\ university of nebraska at omaha - college of IS&T
 
> Date: Sun, 21 Jul 2013 13:49:40 -0700
> Subject: Homework help requested, thanks to everyone.
> From: john_lada...@sbcglobal.net
> To: python-list@python.org
> 
> Thanks to everyone for their wealth of suggestions.  I already had my 
> students playing with turtle.  And I had asked them to alphabetize a string 
> (without having previously revealed the sorted() function).
> 
> So far, I have taken up the suggestion of the number-guessing game.  One of 
> my students has a working version.  The logic is a bit clumsy, but it's a 
> fine first attempt.
> 
> I will also take up the Twenty Questions idea.  My son and I played that game 
> a lot over the years, to pass the time on long car rides.  And it would be a 
> great way to introduce the binary tree data structure.
> 
> Another project I thought of was a Pig Latin translator.  (But do kids today 
> even know what Pig Latin is?  Am I showing my age?)
> 
> Concerning more advanced, real-time, game-oriented graphics, I am trying to 
> figure out how to build PyGame on top of Python3.x.  Supposedly it is 
> possible.  I just haven't figured out how.  It's 2013: I refuse to complicate 
> my students' programming education with Python 2.x.
> 
> I used wxPython happily for years, and I think that its graphical 
> capabilities would probably be up to the task of a simple 2D game.  
> Unfortunately, it has the same problem as PyGame, at least for now.  The 
> Py3-compatible version of wxPython, to be known as Phoenix, is still under 
> development.
> 
> I'll keep Unity, Panda3D, and Blender in mind for later.  Again, one of my 
> main concerns will be Python 3.x compatibility.
> -- 
> http://mail.python.org/mailman/listinfo/python-list
  -- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner - GUI devlopment in Tkinter - Any IDE with drag and drop feature like Visual Studio?

2013-07-21 Thread Michael Torrie
On 07/21/2013 05:20 AM, Chris “Kwpolska” Warrick wrote:
> On Sun, Jul 21, 2013 at 1:14 PM, Dave Cook  wrote:
>> On 2013-07-20, Aseem Bansal  wrote:
>>
>>> Do I need to use QtCreator with PySide if I want drag-and-drop
>>> feature for GUI development?
>>
>> No, you just need the layout part of QtCreator, called QtDesigner, and
>> any decent Python editor or IDE (e.g. Idle):
> 
> …and one more thing: pyside-uic, for transforming the .ui files into
> (ugly) .py files.  It seems to be in /PythonXY/Scripts according to
> Stack Overflow if you have PySide installed.

I don't think you want to be converting ui files into python classes.
Just use the PySide Qt api for loading them at runtime.
-- 
http://mail.python.org/mailman/listinfo/python-list