Re: Signals and Threads in Python 3.5 or so

2016-10-10 Thread dieter
Dan Stromberg  writes:
> I have a program http://stromberg.dnsalias.org/~dstromberg/looper/
> that I use and maintain.
>
> It's like GNU parallel or similar - yet another "run n processes, m at
> a time" implementation.  Interestingly, I've only used/tested it on
> Linux, but it's under a Microsoft copyright because Microsoft acquired
> a Linux company I was working for.
>
> Anyway, it seems to work well, except one annoying bug.
>
> That bug is: if you control-C the top-level process, all the
> subprocesses are left running.
>
> I've been thinking about making it catch SIGINT, SIGTERM and SIGHUP,
> and having it SIGKILL its active subprocesses upon receiving one of
> these signals.
>
> However, it's multithreaded, and I've heard that in CPython, threads
> and signals don't mix well.

I would not state it this way.

Signals are delivered to processes (not process threads).
That leads to the question which thread (in a multi thread application)
will handle a signal when it arrives.
In Python, the design decision has been not to use the currently
running thread (which may not be a Python thread at all or
may have executed Python code but at the moment runs C code outside
of Python) but let the signal be handled deterministically by
the main thread (once it starts again to execute Python code).
This looks like a sane decision to me.


Your problem description indicates that the problem is not
with signal handling by threads but with signal delivery by
the operating system.

In Linux, SIGINT signals in response to a "CTRL-C" are delivered
to the process group of the "control terminal".
Thus, with appropriate Linux calls, you can control whether or not
such a SIGINT is delivered to a subprocess.

Other operating systems may not provide such a control or it may
need different (OS dependent) calls.

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


Re: Solid Approach For Creating A Desktop Application

2016-10-10 Thread Mark Summerfield
On Monday, October 10, 2016 at 5:53:37 AM UTC+1, Mahan Marwat wrote:
> I want to know what will be your approach creating a solid/reliable 
> application in Python?
> i.e
> 1. Which GUI framework will you use i.e PyQT or what? (will you make it work 
> removing the window default border)
> 2. What will you use for it's style/appearance i.e CSS or what?
> 3. Which tool will you use to make an executable of your application i.e 
> Py2exe or what?
> 4. Which tool will you use to make an installable of your application i.e 
> Nsis or what?
> My approach: Python --> PyGTK --> Cx_Freeze --> Nsis
> And last and important question, does your application will work smoothly and 
> will not crash?
> If I am missing something like testing your application etc... Please mention 
> those things too.
> I want to know a full method of creating a solid desktop application.

1. The choice of framework will depend on the target platform(s) and your 
personal preference. In my case I use Python 3.4 + PySide 1.2 (which uses Qt 
4.8).

2. For desktop applications it is better not to do any styling yourself but to 
respect the user's preferences. Qt will automatically do this and I guess other 
toolkits might do this too.

3./4. I use cx_Freeze to produce a .msi file for Windows but which tool you use 
will depend on your target platform(s). cx_Freeze puts a .exe inside the .msi, 
so it does everything needed.

For testing I use Python's own unittest framework.

I have found this toolchain to be very reliable.

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


Re: Python-based monads essay (Re: Assignment versus binding)

2016-10-10 Thread Paul Rubin
Gregory Ewing  writes:
> Oh, undoubtedly. I just don't think it helps understand how burritos
> are used in prog... er, that is, how monads... well, you know what I
> mean.

How about in math?

   https://www.cs.cmu.edu/~edmo/silliness/burrito_monads.pdf

;-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python-based monads essay (Re: Assignment versus binding)

2016-10-10 Thread Paul Rubin
Paul Rubin  writes:
>https://www.cs.cmu.edu/~edmo/silliness/burrito_monads.pdf

Whoops, url changed:

http://emorehouse.web.wesleyan.edu/silliness/burrito_monads.pdf
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to refactor nested for loop into smaller for loop assume each of them independent?

2016-10-10 Thread Ho Yeung Lee
I updated the code in msdn forum,

I calculated from the end of file 
Discover file 4550 takes a long time to run,

Assume it runs a whole day a file, 4550 days I guess need 12 years to finish 
full combination if only run at home.


Hope Python sympy can be faster than cmaple in Amazon instance
-- 
https://mail.python.org/mailman/listinfo/python-list


Is there a free graph library to show program flow by tranverse AST tree

2016-10-10 Thread Ho Yeung Lee
can this graph library handle recursive function call this symbol 
If it recursive call a function 3 times then in the inner loop call another 
function , can this graph library 
Show this relationship
I find video that viv can show this program flow.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: segfault using shutil.make_archive

2016-10-10 Thread Tim
On Friday, October 7, 2016 at 1:05:43 PM UTC-4, Michael Torrie wrote:
> On 10/06/2016 10:46 AM, Tim wrote:
> > I need to zip up a directory that's about 400mb.
> > I'm using shutil.make_archive and I'm getting this response:
> > 
> > Segmentation fault: 11 (core dumped)
> > 
> > The code is straightforward (and works on other, smaller dirs):
> > 
> > shutil.make_archive(os.path.join(zip_dir, zname), 'zip', tgt_dir)
> > 
> > I guess I could drop the convenience of make_archive and use zipfile but 
> > that seems to be exactly what make_archive does.
> > 
> > I'm on FreeBSD, python2.7.
> > 
> > Anyone seen this before?
> 
> Does normal the normal zip utility crash also when trying to zip up this
> large directory?  I'm not familiar with how shutils.make_archive works,
> but since it's part of shutils, I suspect it's calling the zip command
> as a subprocess, rather than using the Python zip module.  Given the
> size of your directory I doubt the zip module would work anyway.
> 
> If the zip command works, you could just execute it using popen from
> within Python.

I'm now using subprocess and the zip command from FreeBSD, and it's working. So 
far I can't reproduce a small example of the problem with make_archive.
--Tim
-- 
https://mail.python.org/mailman/listinfo/python-list


Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest possible.

2016-10-10 Thread Nune9
Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't 
sorted) has highest possible.

The first I'm sorry for my English language.

I have a list is

land = [10,20,30,40,110,50,18,32,5]

and I want to find each values of summation (don't sorted values in list) as It 
has highest possible

example.

I want to dividing N=3 part from list as above and divieded each part has 
highest values that as possible.
*** (don't sorted values in list)

first part has values is = 10, 20, 30, 40
summation = 10+20+30+40 = 100

second part has values is = 110
summation = 110

and third part has values is = 50, 18, 32, 5
summation = 105

that 100, 110 and 105 is highest values as possible in list by dividing N=3 
part.

and then If I want to divide N(1,2,3,...,N) part from any numeric list???

Thank you for python code

(:
-- 
https://mail.python.org/mailman/listinfo/python-list


PyQT - Signals and Slots?

2016-10-10 Thread Veek M
I'm reading Rapid GUI Programming - Mark Summerfield with Python and QT 
pg 131. Basically the mechanism is an event table which maps a 'signal' 
to a 'function/slot' -correct?

  self.connect(dial, SIGNAL("valueChanged(int)"), spinbox.setValue)

Here, dial.valueChanged -> spinbox.setValue

 s.connect(w, SIGNAL("signalSignature"), functionName)
 s.connect(w, SIGNAL("signalSignature"), instance.methodName)
 s.connect(w, SIGNAL("signalSignature"), instance, 
SLOT("slotSignature"))

Here, w.signalSignature -> functionName
-> instance.methodName
-> instance.slotSignature

If signalSignature is a C++ implemented thingy then we got to pass type 
info as part of the mapping so "signalSignature(int, float, const char 
*). PyQT signals are any type and any number of args..


If the Slot-function is implemented in C++ it's better to use the SLOT() 
mechanism:
 self.connect(dial, SIGNAL("valueChanged(int)"), spinbox, 
SLOT("setValue(int)"))
Here, we are mapping dial.valueChanged(int) --> spinbox.setValue(int)


The part i found tricky was this:

class ZeroSpinBox(QSpinBox):
zeros = 0
def __init__(self, parent=None):
super(ZeroSpinBox, self).__init__(parent)
self.connect(self, SIGNAL("valueChanged(int)"), self.checkzero)

def checkzero(self):
if self.value() == 0:
self.zeros += 1
self.emit(SIGNAL("atzero"), self.zeros)

ZeroSpinBox.valueChanged -> ZeroSpinBox.checkzero? Why is he mapping 
back to himself? Shouldn't it be widget-to-widget?

Then he raises a signal 'atzero' with one arg - the lack of a atzero() 
implies it's a 'short-circuit' signal so self.zeroes is a python data 
type. And in the book he says:

###
Here is how we connect to the signal in the form’s __init__() method:
zerospinbox = ZeroSpinBox()
...
self.connect(zerospinbox, SIGNAL("atzero"), self.announce)
Again, we must not use parentheses because it is a short-circuit signal. 
And
for completeness, here is the slot it connects to in the form:
def announce(self, zeros):
print "ZeroSpinBox has been at zero %d times" % zeros
###

Whaaa...t?? Could someone explain what exactly is his grand design 
besides being awfully circuitous? So he has some other Form thingy.. and 
in that he sets up another mapping from ZeroSpinBox.atzero --> 
ZeroSpinBox.announce  where's announce and atzero defined?





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


Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest as possible.

2016-10-10 Thread amornsak . nak
Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't 
sorted) has highest as possible.

The first I'm sorry for my English language.

I have a list is

land = [10,20,30,40,110,50,18,32,5]

and I want to find each values of summation (don't sorted values in list) as It 
has highest as possible

example.

I want to dividing N=3 part from list as above and divieded each part has 
highest values that as possible.
*** (don't sorted values in list)

first part has values is = 10, 20, 30, 40
summation = 10+20+30+40 = 100

second part has values is = 110
summation = 110

and third part has values is = 50, 18, 32, 5
summation = 105

that 100, 110 and 105 is highest values as possible in list by dividing N=3 
part.

and then If I want to divide N(1,2,3,...,N) part from any more numeric list???

Thank you for python code

(:
-- 
https://mail.python.org/mailman/listinfo/python-list


Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest as possible.

2016-10-10 Thread Nuen9
Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't 
sorted) has highest as possible.

The first I'm sorry for my English language.

I have a list is

land = [10,20,30,40,110,50,18,32,5]

and I want to find each values of summation (don't sorted values in list) as It 
has highest as possible

example.

I want to dividing N=3 part from list as above and divieded each part has 
highest values that as possible.
*** (don't sorted values in list)

first part has values is = 10, 20, 30, 40
summation = 10+20+30+40 = 100

second part has values is = 110
summation = 110

and third part has values is = 50, 18, 32, 5
summation = 105

that 100, 110 and 105 is highest values as possible in list by dividing N=3 
part.

and then If I want to divide N(1,2,3,...,N) part from any more numeric list???

Thank you for python code

(:
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Deviding N(1, 2, 3, .., N) part from numeric list as summation of each values(don't sorted) has highest possible.

2016-10-10 Thread Ben Bacarisse
Nune9  writes:

> I have a list is
>
> land = [10,20,30,40,110,50,18,32,5]
>
> and I want to find each values of summation (don't sorted values in
> list) as It has highest possible
>
> example.
>
> I want to dividing N=3 part from list as above and divieded each part
> has highest values that as possible.
> *** (don't sorted values in list)
>
> first part has values is = 10, 20, 30, 40
> summation = 10+20+30+40 = 100
>
> second part has values is = 110
> summation = 110
>
> and third part has values is = 50, 18, 32, 5
> summation = 105
>
> that 100, 110 and 105 is highest values as possible in list by
> dividing N=3 part.

So, given a sequence of numbers, you want to partition it into N
consecutive sub-sequences such that the sums of these sub sequences is,
somehow, maximal.  I say "somehow" because there are various possible
meanings for "highest" when applies to set of numbers.  Have I got that
part right?

It would help if you clarified a couple of things.  Are all numbers in
the sequence always positive, and what makes one set of numbers "higher"
than any other?  I imagine you want the most equal partition -- the one
that minimises the variance in the set of sums.

> and then If I want to divide N(1,2,3,...,N) part from any numeric
> list???

I don't understand this last bit at all.  The repeated use of N is not
helping me.

-- 
Ben.
-- 
https://mail.python.org/mailman/listinfo/python-list


How to process syntax errors

2016-10-10 Thread mr . puneet . goyal
Hi 

Is there any way to capture syntax errors and process them ? I want to write a 
function which calls every time whenever there is syntax error in the program.

For example, 

inside example.py 

I just mention below line 


Obj = myClass()
Obj xyz

Obj is instance of a class. But there is syntax error on xyz. So I want to grab 
that error and process.

Regards, Puneet 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Function to take the minimum of 3 numbers

2016-10-10 Thread Steve D'Aprano
On Mon, 10 Oct 2016 10:56 am, Ian Kelly wrote:

> On Oct 9, 2016 2:57 PM,  alleged:

> The Pythonic way
> 
> if b >= a <= c:
> ...

I doubt that would be considered Pythonic by many people. Chained
comparisons are Pythonic, but not legal but weird combinations like 
`a == b < c is not d >= e <= f`.


> Better:
> 
> if a <= b <= c:
> ...

That's more like it. Unfortunately it doesn't mean the same as Mark's
version:

b >= a <= c means b >= a and a <= c
which is True for a = 1, b = 3 and c = 2;


a <= b <= c means a <= b and b <= c
which is False for a = 1, b = 3 and c = 2.


> Using consistent operators is not required but is easier to read and less
> confusing.

Indeed.





-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Deviding N(1, 2, 3, .., N) part from numeric list as summation of each values(don't sorted) has highest as possible.

2016-10-10 Thread Steve D'Aprano
On Tue, 11 Oct 2016 12:38 am, amornsak@gmail.com wrote:

> I have a list is
> 
> land = [10,20,30,40,110,50,18,32,5]
> 
> and I want to find each values of summation (don't sorted values in list)
> as It has highest as possible
> 
> example.
> 
> I want to dividing N=3 part from list as above and divieded each part has
> highest values that as possible. *** (don't sorted values in list)
> 
> first part has values is = 10, 20, 30, 40
> summation = 10+20+30+40 = 100

Why do you add four numbers? Why not add all the numbers?

10+20+30+40+110+50+18+32+5 = 315

> second part has values is = 110
> summation = 110

Why do you only take one number?


> and third part has values is = 50, 18, 32, 5
> summation = 105

Why do you take four numbers?

 
> that 100, 110 and 105 is highest values as possible in list by dividing
> N=3 part.

I do not understand, what do you mean "dividing N=3 part"?

Could you do this?

[10,20,30,40,110,50,18,32,5]

split into three lists:

[10,20,30,40,110,50,18], [32], [5]

Or these three lists:

[10], [20,30,40,110,50,18], [32,5]

Or these three lists:

[10,20,30], [40,110,50], [18,32,5]

How do you split the list into three?






-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: PyQT - Signals and Slots?

2016-10-10 Thread Mark Summerfield

The ZeroSpinBox is a tiny example designed to show how the signal/slot
mechanism works. It is just a QSpinBox with the addition of remembering
how many times (all the) ZeroSpinBox(es) have had a 0 value.

Nowadays the connections would be made with a new improved syntax:

self.connect(self, SIGNAL("valueChanged(int)"), self.checkzero) # OLD
self.valueChanged.connect(self.checkzero) # NEW
# or
self.valueChanged[int].connect(self.checkzero) # NEW

Similarly the emit:
self.emit(SIGNAL("atzero"), self.zeros) # OLD
self.atzero.emit(self.zeros) # NEW

What's happening inside ZeroSpinBox? Whenever its value is set to 0 it
calls its own checkzero() method, and this in turn emits an atzero signal
with the number of zeros so far. Why does it do this? Just to show the
mechanism. It doesn't matter whether you connect a widget to itself
(unusual but done here), or to another widget (the norm).

See the book's website https://www.qtrac.eu/pyqtbook.html
for all the source code including some updated with the new syntax.
(But the book is old, so even the Python 3.1 examples aren't as Pythonic as 
they would be written in Python 3.4+.)
-- 
https://mail.python.org/mailman/listinfo/python-list


Newbie Need Help On Regex!

2016-10-10 Thread infosecflag
Hey guys!
 
I am new to learning regex in python and I'm wondering how do I use regex in 
python to store the integers(positive and negative) i want into a list!
 
For e.g.
 
This is the data in a list.
 
[u'\x1b[0m[\x1b[1m\x1b[0m\xbb\x1b[0m\x1b[36m]\x1b[0m (A=-5,B=5)', 
u'\x1b[0m[\x1b[1m\x1b[0m\xbb\x1b[0m\x1b[36m]\x1b[0m (A=5,Y=5)', 
u'\x1b[0m[\x1b[1m\x1b[10m\xbb\x1b[0m\x1b[36m]\x1b[0m : ']
 
How do I extract the values of A and B and store them in a variable I want 
using regex?
 
Thank you and appreciate it :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Newbie Need Help On Regex!

2016-10-10 Thread infosecflag
Hey guys!
 
I am new to learning regex in python and I'm wondering how do I use regex in 
python to store the integers(positive and negative) i want into a list!
 
For e.g.
 
This is the data in a list.
 
[u'\x1b[0m[\x1b[1m\x1b[0m\xbb\x1b[0m\x1b[36m]\x1b[0m (A=-5,B=5)', 
u'\x1b[0m[\x1b[1m\x1b[0m\xbb\x1b[0m\x1b[36m]\x1b[0m (A=5,Y=5)', 
u'\x1b[0m[\x1b[1m\x1b[10m\xbb\x1b[0m\x1b[36m]\x1b[0m : ']
 
How do I extract the values of A and B and store them in a variable I want 
using regex?
 
Thank you and appreciate it :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest as possible.

2016-10-10 Thread Nuen9
เมื่อ วันจันทร์ที่ 10 ตุลาคม ค.ศ. 2016 21 นาฬิกา 31 นาที 25 วินาที UTC+7, Steve 
D'Aprano เขียนว่า:
> On Tue, 11 Oct 2016 12:38 am, amornsak@gmail.com wrote:
> 
> > I have a list is
> > 
> > land = [10,20,30,40,110,50,18,32,5]
> > 
> > and I want to find each values of summation (don't sorted values in list)
> > as It has highest as possible
> > 
> > example.
> > 
> > I want to dividing N=3 part from list as above and divieded each part has
> > highest values that as possible. *** (don't sorted values in list)
> > 
> > first part has values is = 10, 20, 30, 40
> > summation = 10+20+30+40 = 100
> 
> Why do you add four numbers? Why not add all the numbers?
> 
> 10+20+30+40+110+50+18+32+5 = 315
> 
> > second part has values is = 110
> > summation = 110
> 
> Why do you only take one number?
> 
> 
> > and third part has values is = 50, 18, 32, 5
> > summation = 105
> 
> Why do you take four numbers?
> 
>  
> > that 100, 110 and 105 is highest values as possible in list by dividing
> > N=3 part.
> 
> I do not understand, what do you mean "dividing N=3 part"?
> 
> Could you do this?
> 
> [10,20,30,40,110,50,18,32,5]
> 
> split into three lists:
> 
> [10,20,30,40,110,50,18], [32], [5]
> 
> Or these three lists:
> 
> [10], [20,30,40,110,50,18], [32,5]
> 
> Or these three lists:
> 
> [10,20,30], [40,110,50], [18,32,5]
> 
> How do you split the list into three?
> 
> 
> 
> 
> 
> 
> -- 
> Steve
> “Cheer up,” they said, “things could be worse.” So I cheered up, and sure
> enough, things got worse.

I'm sorry for my English language. 

OK, I have list = [10,20,30,40,110,50,18,32,5] and want to find three values of 
summation from my list by split any way list but three values of summation has 
closely
example.
[10,20,30], [40,110,50], [18,32,5] = 60, 200, 55 -> it is not closely
*** 60 = 10+20+30, 200 = 40+110+50, 18+32+5 = 55
and [10], [20,30,40,110,50,18], [32,5]  = 10, 268, 37 -> and it is not closely
and [10,20,30,40],[110],[50,18,32,5] = 100,110,105 -> it's closely

The Really answers that I want is [10,20,30,40],[110],[50,18,32,5] = 
100,110,105 from list[10,20,30,40,110,50,18,32,5]

And I don't know what I have to explain for my questions in English because My 
English so bad T_T

Thank you for reading my text

(;
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to process syntax errors

2016-10-10 Thread Chris Angelico
On Tue, Oct 11, 2016 at 1:13 AM,   wrote:
> Is there any way to capture syntax errors and process them ? I want to write 
> a function which calls every time whenever there is syntax error in the 
> program.
>
> For example,
>
> inside example.py
>
> I just mention below line
>
>
> Obj = myClass()
> Obj xyz
>
> Obj is instance of a class. But there is syntax error on xyz. So I want to 
> grab that error and process.

Yes and no. Syntax errors are detected when the script is compiled, so
you can't do something like this:

try:
Obj xyz
except SyntaxError:
print("Try Obj.xyz instead!")

However, you can catch this at some form of outer level. If you're
using exec/eval to run the code, you can guard that:

code = """
obj = MyClass() # using PEP 8 names
obj xyz
"""
try:
exec(code)
except SyntaxError:
print("Blah blah blah")

Alternatively, you can put the code into a file and import it:

# otherfile.py
obj = MyClass()
obj xyz

# mainfile.py
try:
import otherfile
except SyntaxError:
do_stuff()

This is probably the easiest solution, if your code's already in a
separate file.

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


Re: How to process syntax errors

2016-10-10 Thread Pierre-Alain Dorange
Chris Angelico  wrote:

> Yes and no. Syntax errors are detected when the script is compiled, so
> you can't do something like this:

You're right, except that Python is never compiled, it was just checked
for syntax error before interpreting code.

> 
> However, you can catch this at some form of outer level. If you're
> using exec/eval to run the code, you can guard that:

Your solution are OK, but that's not very "pythonic".

Python was not design to be used in such a way (intercepting syntax
error). There was hack to made somthing like requested but that only a
hack and should not be used in real world.

-- 
Pierre-Alain Dorange   Moof 

Ce message est sous licence Creative Commons "by-nc-sa-2.0"

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


Re: Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest as possible.

2016-10-10 Thread K. Elo

Hi!

Could it be, "Nuen9", that you would like to find a split where the 
split sums are close to each other? In other words, you define the 
number of splits (in your example: 3) and the algortihm should test all 
possible combinations and select the split where the sum differences are 
smallest.


Best,
Kimmo

10.10.2016, 18:20, Nuen9 wrote:

เมื่อ วันจันทร์ที่ 10 ตุลาคม ค.ศ. 2016 21 นาฬิกา 31 นาที 25 วินาที UTC+7, Steve 
D'Aprano เขียนว่า:

On Tue, 11 Oct 2016 12:38 am, amornsak@gmail.com wrote:

I'm sorry for my English language.

OK, I have list = [10,20,30,40,110,50,18,32,5] and want to find three values of 
summation from my list by split any way list but three values of summation has 
closely
example.
[10,20,30], [40,110,50], [18,32,5] = 60, 200, 55 -> it is not closely
*** 60 = 10+20+30, 200 = 40+110+50, 18+32+5 = 55
and [10], [20,30,40,110,50,18], [32,5]  = 10, 268, 37 -> and it is not closely
and [10,20,30,40],[110],[50,18,32,5] = 100,110,105 -> it's closely

The Really answers that I want is [10,20,30,40],[110],[50,18,32,5] = 
100,110,105 from list[10,20,30,40,110,50,18,32,5]

And I don't know what I have to explain for my questions in English because My 
English so bad T_T

Thank you for reading my text

(;


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


Re: PyQT - Signals and Slots?

2016-10-10 Thread Veek M
Mark Summerfield wrote:

> 
> The ZeroSpinBox is a tiny example designed to show how the signal/slot
> mechanism works. It is just a QSpinBox with the addition of
> remembering how many times (all the) ZeroSpinBox(es) have had a 0
> value.
> 
> Nowadays the connections would be made with a new improved syntax:
> 
> self.connect(self, SIGNAL("valueChanged(int)"), self.checkzero) # OLD
> self.valueChanged.connect(self.checkzero) # NEW
> # or
> self.valueChanged[int].connect(self.checkzero) # NEW
> 
> Similarly the emit:
> self.emit(SIGNAL("atzero"), self.zeros) # OLD
> self.atzero.emit(self.zeros) # NEW
> 
> What's happening inside ZeroSpinBox? Whenever its value is set to 0 it
> calls its own checkzero() method, and this in turn emits an atzero
> signal with the number of zeros so far. Why does it do this? Just to
> show the mechanism. It doesn't matter whether you connect a widget to
> itself (unusual but done here), or to another widget (the norm).
> 
> See the book's website https://www.qtrac.eu/pyqtbook.html
> for all the source code including some updated with the new syntax.
> (But the book is old, so even the Python 3.1 examples aren't as
> Pythonic as they would be written in Python 3.4+.)

ah - okay, so i was on the right track - thanks :) cool that you hang 
out here :) 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to process syntax errors

2016-10-10 Thread Chris Angelico
On Tue, Oct 11, 2016 at 2:44 AM, Pierre-Alain Dorange
 wrote:
> Chris Angelico  wrote:
>
>> Yes and no. Syntax errors are detected when the script is compiled, so
>> you can't do something like this:
>
> You're right, except that Python is never compiled, it was just checked
> for syntax error before interpreting code.

https://docs.python.org/3/library/functions.html#compile

It's compiled.

>> However, you can catch this at some form of outer level. If you're
>> using exec/eval to run the code, you can guard that:
>
> Your solution are OK, but that's not very "pythonic".
>
> Python was not design to be used in such a way (intercepting syntax
> error). There was hack to made somthing like requested but that only a
> hack and should not be used in real world.

The error is raised as an exception, which means it is most definitely
meant to be able to be caught. If it were utterly and completely
fatal, it would simply be handled as "print message to standard error,
terminate process" as some forms of fatal error are. (But even in some
of those cases - SystemError and MemoryError - they can still be
raised as exceptions.)

There's nothing unpythonic about catching an exception if you know how
to handle it. My examples did have somewhat unpythonic behaviour
(catching an exception only to print a message and continue), but
that's because they're placeholders.

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


Re: Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest as possible.

2016-10-10 Thread Nuen9
เมื่อ วันจันทร์ที่ 10 ตุลาคม ค.ศ. 2016 22 นาฬิกา 46 นาที 33 วินาที UTC+7, K. 
Elo เขียนว่า:
> Hi!
> 
> Could it be, "Nuen9", that you would like to find a split where the 
> split sums are close to each other? In other words, you define the 
> number of splits (in your example: 3) and the algortihm should test all 
> possible combinations and select the split where the sum differences are 
> smallest.
> 
> Best,
> Kimmo
> 
> 10.10.2016, 18:20, Nuen9 wrote:
> > เมื่อ วันจันทร์ที่ 10 ตุลาคม ค.ศ. 2016 21 นาฬิกา 31 นาที 25 วินาที UTC+7, 
> > Steve D'Aprano เขียนว่า:
> >> On Tue, 11 Oct 2016 12:38 am, amornsak@gmail.com wrote:
> > I'm sorry for my English language.
> >
> > OK, I have list = [10,20,30,40,110,50,18,32,5] and want to find three 
> > values of summation from my list by split any way list but three values of 
> > summation has closely
> > example.
> > [10,20,30], [40,110,50], [18,32,5] = 60, 200, 55 -> it is not closely
> > *** 60 = 10+20+30, 200 = 40+110+50, 18+32+5 = 55
> > and [10], [20,30,40,110,50,18], [32,5]  = 10, 268, 37 -> and it is not 
> > closely
> > and [10,20,30,40],[110],[50,18,32,5] = 100,110,105 -> it's closely
> >
> > The Really answers that I want is [10,20,30,40],[110],[50,18,32,5] = 
> > 100,110,105 from list[10,20,30,40,110,50,18,32,5]
> >
> > And I don't know what I have to explain for my questions in English because 
> > My English so bad T_T
> >
> > Thank you for reading my text
> >
> > (;
> >

Yes it is, I want example python code for finding my answers but I don't code 
my answers. please help me.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyQT - Signals and Slots?

2016-10-10 Thread Michael Torrie
On 10/10/2016 07:32 AM, Veek M wrote:
> Whaaa...t?? Could someone explain what exactly is his grand design 
> besides being awfully circuitous? So he has some other Form thingy.. and 
> in that he sets up another mapping from ZeroSpinBox.atzero --> 
> ZeroSpinBox.announce  where's announce and atzero defined?

In your example code, "atzero" is implicitly defined as a signal in the
connect() call.  Under the hood in Qt, signals are all dispatched by
strings when you emit() the signal.  PyQt does allow you to define
signals in a more pythonic way using class variables:

class Foo(QWidget):
atzero = SIGNAL( signature )

The signature can be a list of python types, or strings describing the
C++ types.  This is where the C++ nature of Qt leaks into PyQt.  In C++
since the moc compiler takes C++ code and C++ type names and generates a
meta-class that defines signals in terms of strings (moc does basic
compile-time type checking), in Python we also have to provide
signatures in strings also if we need something more than core python
types (int, bool, etc).  This signature helps PyQt (well Qt really)
marshal the types properly when the signal's callback is called.

But yes the example is convoluted and circuitous.  I think it's just to
demonstrate how signals and slots work, though.  That's what the
comments make clear.  This isn't how you'd implement a real widget with
customized behavior.

In general I don't think widgets normally want to catch their own
signals.  There are other mechanisms for that.  Usually you subclass the
widget and then override the appropriate *Event() method. For example,
to do something special on value changes I believe you'd subclass
QSpinBox and override the changeEvent() method. Inside that you would
get your value, do your logic, and potentially emit a custom signal. And
of course calling the parent changeEvent() to propagate the event
through to the parent class.


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


Re: Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest as possible.

2016-10-10 Thread Nuen9
> Hi!
> 
> Could it be, "Nuen9", that you would like to find a split where the 
> split sums are close to each other? In other words, you define the 
> number of splits (in your example: 3) and the algortihm should test all 
> possible combinations and select the split where the sum differences are 
> smallest.
> 
> Best,
> Kimmo

Yes it is, I want example python code for finding my answers but I don't code 
my answers. please help me. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest as possible.

2016-10-10 Thread Emile van Sebille

On 10/10/2016 09:25 AM, Nuen9 wrote:

Hi!

Could it be, "Nuen9", that you would like to find a split where the
split sums are close to each other? In other words, you define the
number of splits (in your example: 3) and the algortihm should test all
possible combinations and select the split where the sum differences are
smallest.

Best,
Kimmo


Yes it is, I want example python code for finding my answers but I don't code 
my answers. please help me.



Here's one way:

n=3
land = [10,20,30,40,110,50,18,32,5]
lsum = sum(land)
lavg = lsum/n
close = lavg/n
idx = 0
lnsums = [0]*n
ln=0
while idx < len(land) and ln lavg-close:
ln+=1

print lnsums


--

Emile


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


Re: Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest as possible.

2016-10-10 Thread K. Elo

Hi!

Here one possible solution:

--- snip ---

land = [10,20,30,40,110,50,18,32,5]

landlength=len(land)
winnersplit=[]

for i in range(landlength-2):
for j in range(landlength-1-i):
splitsums=[sum(land[0:(i+1)]), sum(land[(i+1):(i+j+2)]), 
sum(land[(i+j+2):landlength])]


differences=abs(splitsums[1]-splitsums[0])+abs(splitsums[2]-splitsums[1])

if (len(winnersplit)==0 or 
differences<(abs(sum(winnersplit[1])-sum(winnersplit[0]))+abs(sum(winnersplit[2])-sum(winnersplit[1]:
winnersplit=[land[0:(i+1)], land[(i+1):(i+j+2)], 
land[(i+j+2):landlength]]

print(splitsums," <<< WE HAVE A NEW LEADER! >>>")
else:
print(splitsums, " <<< split differences too large :( >>>")

print("And the winner is ... ", winnersplit)

--- snip ---

HTH,
Kimmo

10.10.2016, 19:25, Nuen9 kirjoitti:

Hi!

Could it be, "Nuen9", that you would like to find a split where the
split sums are close to each other? In other words, you define the
number of splits (in your example: 3) and the algortihm should test all
possible combinations and select the split where the sum differences are
smallest.

Best,
Kimmo


Yes it is, I want example python code for finding my answers but I don't code 
my answers. please help me.


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


Re: How to process syntax errors

2016-10-10 Thread BartC

On 10/10/2016 16:44, Pierre-Alain Dorange wrote:

Chris Angelico  wrote:


Yes and no. Syntax errors are detected when the script is compiled, so
you can't do something like this:


You're right, except that Python is never compiled, it was just checked
for syntax error before interpreting code.


In the case of CPython, source code is compiled into byte-code before 
it's interpreted. Part of that process is detecting syntax errors.


AFAIK, this is usually done a module at a time (convert an entire module 
to byte-code, then start interpreting). It might be a little different 
with functions such as eval and exec.


--
Bartc
--
https://mail.python.org/mailman/listinfo/python-list


Re: Newbie Need Help On Regex!

2016-10-10 Thread breamoreboy
On Monday, October 10, 2016 at 3:58:56 PM UTC+1, infos...@gmail.com wrote:
> Hey guys!
>  
> I am new to learning regex in python and I'm wondering how do I use regex in 
> python to store the integers(positive and negative) i want into a list!
>  
> For e.g.
>  
> This is the data in a list.
>  
> [u'\x1b[0m[\x1b[1m\x1b[0m\xbb\x1b[0m\x1b[36m]\x1b[0m (A=-5,B=5)', 
> u'\x1b[0m[\x1b[1m\x1b[0m\xbb\x1b[0m\x1b[36m]\x1b[0m (A=5,Y=5)', 
> u'\x1b[0m[\x1b[1m\x1b[10m\xbb\x1b[0m\x1b[36m]\x1b[0m : ']
>  
> How do I extract the values of A and B and store them in a variable I want 
> using regex?
>  
> Thank you and appreciate it :)

What makes you think you need a regex?  Why don't you write some code and when 
you have problems, post it here.  Then we'll give you some answers.

Kindest regards.

Mark Lawrence.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to process syntax errors

2016-10-10 Thread breamoreboy
On Monday, October 10, 2016 at 3:15:40 PM UTC+1, mr.pune...@gmail.com wrote:
> Hi 
> 
> Is there any way to capture syntax errors and process them ? I want to write 
> a function which calls every time whenever there is syntax error in the 
> program.
> 
> For example, 
> 
> inside example.py 
> 
> I just mention below line 
> 
> 
> Obj = myClass()
> Obj xyz
> 
> Obj is instance of a class. But there is syntax error on xyz. So I want to 
> grab that error and process.
> 
> Regards, Puneet

Simple, catch it in your IDE, no need to try and get clever.

Kindest regards.

Mark Lawrence.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest as possible.

2016-10-10 Thread breamoreboy
On Monday, October 10, 2016 at 5:25:46 PM UTC+1, Nuen9 wrote:
> > Hi!
> > 
> > Could it be, "Nuen9", that you would like to find a split where the 
> > split sums are close to each other? In other words, you define the 
> > number of splits (in your example: 3) and the algortihm should test all 
> > possible combinations and select the split where the sum differences are 
> > smallest.
> > 
> > Best,
> > Kimmo
> 
> Yes it is, I want example python code for finding my answers but I don't code 
> my answers. please help me.

Awfully sorry but we don't write your code for you.  I suggest that you read 
any Python tutorial and try running code at an interactive prompt, then when 
you run into problems ask a specific question about a specific problem.

Kindest regards.

Mark Lawrence.
-- 
https://mail.python.org/mailman/listinfo/python-list


Free Python e-books from O'Reilly

2016-10-10 Thread Martin Schöön
http://www.oreilly.com/programming/free/

Any of these good enough to bother getting? Yes, I know, they
are for no pay but if not worth reading still a waste of time
and memory space.

/Martin
-- 
https://mail.python.org/mailman/listinfo/python-list


Raster top and lowe x,y how ca i get

2016-10-10 Thread Xristos Xristoou
How can i get left lower X,Y left top X,Y right lower X,Y and right Top X,Y  
from a raster image like dem(digital elevation model).
I am nembie sorry if i have stupid quest
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Free Python e-books from O'Reilly

2016-10-10 Thread Uri Even-Chen
I think it's good that so many free books are about Python, more than any
other specific programming language. But I haven't read any of them yet.


*Uri Even-Chen*
[image: photo] Phone: +972-54-3995700
Email: u...@speedy.net
Website: http://www.speedysoftware.com/uri/en/
  
    

On Tue, Oct 11, 2016 at 12:03 AM, Martin Schöön 
wrote:

> http://www.oreilly.com/programming/free/
>
> Any of these good enough to bother getting? Yes, I know, they
> are for no pay but if not worth reading still a waste of time
> and memory space.
>
> /Martin
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


[RELEASE] Python 3.6.0b2 is now available

2016-10-10 Thread Ned Deily
On behalf of the Python development community and the Python 3.6 release
team, I'm happy to announce the availability of Python 3.6.0b2. 3.6.0b2
is the second of four planned beta releases of Python 3.6, the next major
release of Python, and marks the end of the feature development phase
for 3.6.

Among the new major new features in Python 3.6 are:

* PEP 468 - Preserving the order of **kwargs in a function
* PEP 487 - Simpler customization of class creation
* PEP 495 - Local Time Disambiguation
* PEP 498 - Literal String Formatting
* PEP 506 - Adding A Secrets Module To The Standard Library
* PEP 509 - Add a private version to dict
* PEP 515 - Underscores in Numeric Literals
* PEP 519 - Adding a file system path protocol
* PEP 520 - Preserving Class Attribute Definition Order
* PEP 523 - Adding a frame evaluation API to CPython
* PEP 524 - Make os.urandom() blocking on Linux (during system startup)
* PEP 525 - Asynchronous Generators (provisional)
* PEP 526 - Syntax for Variable Annotations (provisional)
* PEP 528 - Change Windows console encoding to UTF-8 (provisional)
* PEP 529 - Change Windows filesystem encoding to UTF-8 (provisional)
* PEP 530 - Asynchronous Comprehensions

Please see "What’s New In Python 3.6" for more information:

https://docs.python.org/3.6/whatsnew/3.6.html

You can find Python 3.6.0b2 here:

https://www.python.org/downloads/release/python-360b2/

Beta releases are intended to give the wider community the opportunity
to test new features and bug fixes and to prepare their projects to
support the new feature release. We strongly encourage maintainers of
third-party Python projects to test with 3.6 during the beta phase and
report issues found to bugs.python.org as soon as possible. While the
release is feature complete entering the beta phase, it is possible that
features may be modified or, in rare cases, deleted up until the start
of the release candidate phase (2016-12-05). Our goal is have no changes
after rc1. To achieve that, it will be extremely important to get as
much exposure for 3.6 as possible during the beta phase. Please keep in
mind that this is a preview release and its use is not recommended for
production environments

The next planned release of Python 3.6 will be 3.6.0b3, currently
scheduled for 2016-10-31. More information about the release schedule
can be found here:

https://www.python.org/dev/peps/pep-0494/

--
  Ned Deily
  n...@python.org -- []

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


Re: Free Python e-books from O'Reilly

2016-10-10 Thread John Gordon
In  Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?= 
 writes:

> http://www.oreilly.com/programming/free/

> Any of these good enough to bother getting? Yes, I know, they
> are for no pay but if not worth reading still a waste of time
> and memory space.

I downloaded several of them and noticed that they were all fairly short,
none more than 80 pages or so.  I suspect these books are somewhat lighter
fare than the typical O'Reilly tome.

Not necessarily a bad thing, but worth mentioning.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: How to process syntax errors

2016-10-10 Thread Terry Reedy

On 10/10/2016 11:24 AM, Chris Angelico wrote:

On Tue, Oct 11, 2016 at 1:13 AM,   wrote:

Is there any way to capture syntax errors and process them ? I want to write a 
function which calls every time whenever there is syntax error in the program.



However, you can catch this at some form of outer level. If you're
using exec/eval to run the code, you can guard that:

code = """
obj = MyClass() # using PEP 8 names
obj xyz
"""
try:
exec(code)
except SyntaxError:
print("Blah blah blah")


Far from being 'un-pythonic' (Puneet's response), this is essentially 
what the interpreter does, either without or with a separate explicit 
compile step.  IDLE splits the exec into two pieces in two processes. 
Except for the two process part, this either uses or copies 
code.InteractiveInterpreter in the stdlib.  The fact that the latter 
separates compile and exec is what allows IDLE to subclass it and run 
the code object elsewhere, by over-riding the runcode method.


# in IDLE process:

code = 

try:
code_ob = compile(code, )
except (SyntaxError, ) as e:
  # replace ^ with red background highlight
else:


# in user process

exec(code, fake_main)
# stdout, stderr connect to IDLE process



--
Terry Jan Reedy

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