Class - error return

2016-09-06 Thread Smith

Hi,
you can help me ?
I can not understand where is the error in this script.
Use Python3.


In [71]: class Day(object):
...: def __init__(self,visits,contacts):
...: self.visits = visits
...: self.contacts = contacts
...: def __add__(self,other):
...: total_visits = self.visits + other.visits
...: total_contacts = self.contacts + other.contacts
...: return Day(total_visits,total_contacts)
...: def __radd__(self,other):
...: if other == 0:
...: return self
...: else:
...: return self.__add__(other)
...: def __str__(self):
...: return "Visitor: %i, Contacts: %i % 
(self.visits,self.contacts)"

...:
...:



In [72]: day1 = Day(8,9)

In [73]: day2 = Day(7,7)

In [74]: print(day1)
Visitor: %i, Contacts: %i % (self.visits,self.contacts)

In [75]: print(day2)
Visitor: %i, Contacts: %i % (self.visits,self.contacts)
--
https://mail.python.org/mailman/listinfo/python-list


Re: Class - error return

2016-09-06 Thread Peter Otten
Smith wrote:

> you can help me ?

Yes ;) But you might consider posting on python-tutor instead of python-
list.

> I can not understand where is the error in this script.

It's always a good idea to state both what you expect and what you get 
instead explicitly, in plain english.

> In [72]: day1 = Day(8,9)

> In [74]: print(day1)
> Visitor: %i, Contacts: %i % (self.visits,self.contacts)

That might pass as the "what you get" part; I suppose you expect it to print

Visitor: 8, Contacts: 9

If so look at

>  ...: def __str__(self):
>  ...: return "Visitor: %i, Contacts: %i %
> (self.visits,self.contacts)"

once more. Where are the quotes? Where should the be?



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


Re: Extend unicodedata with a name/pattern/regex search for character entity references?

2016-09-06 Thread Veek 'this_is_not_my_name' M
Rustom Mody wrote:

> On Saturday, September 3, 2016 at 5:25:48 PM UTC+5:30, Veek. M wrote:
>> https://mail.python.org/pipermail//python-ideas/2014-October/029630.htm
>> 
>> Wanted to know if the above link idea, had been implemented and if
>> there's a module that accepts a pattern like 'cap' and give you all
>> the instances of unicode 'CAP' characters.
>>  ⋂ \bigcap
>>  ⊓ \sqcap
>>  ∩ \cap
>>  ♑ \capricornus
>>  ⪸ \succapprox
>>  ⪷ \precapprox
>> 
>> (above's from tex)
>> 
>> I found two useful modules in this regard: unicode_tex, unicodedata
>> but unicodedata is a builtin which does not do globs, regexs - so
>> it's kind of limiting in nature.
>> 
>> Would be nice if you could search html/xml character entity
>> references as well.
> 
> [Not exactly an answer]
> 
> I use a number of things for such
> 1. Google
> 2. Xah Lee’s excellent pages which often fit my brain better than
> wikipedia:
>http://xahlee.info/comp/unicode_index.html
> 3. emacs’ function ucs-insert recently renamed to insert-char
>ie [In emacs] Type Alt-x insert-char
>After that some kind of TAB-globbing (case-insensitive) works
>I wont try with Cap (because the number of *CAPITAL* is in
>thousands!) eg alphaTAB gives nothing. However *alphaTAB gives a
>bunch. Narrow to "greek alpha"TAB and you get a bunch
> 
> 
> The fact that we should have a series of levels for char-input from
> most general and unergonomic (google) to most specific and ergonomic
> (special purpose keyboard) Ive tried to talk of as 7 levels near end
> of http://blog.languager.org/2015/01/unicode-and-universe.html


got dengu - i'm dead
-- 
https://mail.python.org/mailman/listinfo/python-list


Suggestions to improve a code

2016-09-06 Thread GP
I have a list:
shelves2 =[{'Part No': '1', 'Length': 610.0,  'Width': 50.0},
   {'Part No': '2', 'Length': 2319.0, 'Width': 465.0 },
   {'Part No': '3', 'Length': 5.0,'Width': 465.0}]

The length of shelf is calculated as follows:
 1. Calculate the maximum length of all items in the shelf.
 2. Calculate width of shelf = 610 (in this case).
 3. Length of shelf : maxlength of all items + length ( if it less than width 
of shelf) or width of other items such that length of shelf  is less than 
maximum allowed length.

In the above case the length is 2319+50+5 = 2374. I have the following code 
which generates it correctly but would like to know if there is a better way to 
write it. I would like to know some smarter way to write the code ( especially 
if the "for", "if" statements can be avoided).
  list_1=[]
  list_2=[]
  WidthOfShelf = max([x['Width'] for x in shelves2])
  MaxLengthOfItem =  max([x['Length'] for x in shelves2])
  f_LMax=lambda seq, m: [ii for ii in range(0, len(seq)) if seq[ii] ['Length'] 
>= m][0]
  MaxLengthOfItem_Index =f_LMax(shelves2,MaxLengthOfItem)
  current= MaxLengthOfItem

  list_1=[shelves2[MaxLengthOfItem_Index]]
  list_2 = [MaxLengthOfItem]
  del shelves2[MaxLengthOfItem_Index]
  for i in range(0,len(shelves2)):
   if shelves2[i]['Length'] <= Width:
   if (current + shelves2[i]['Length']) or (current + shelves2  
[i]['Width'])<= 2438.5 :
   q_2= min(shelves2[i]['Length'],  shelves2[i]['Width'])
   q=shelves2[i]
   list_1.append(q)
   list_2.append(q_2)
   current += (shelves2[i]['Length'] or shelves2[i]  ['Width'])
   length = sum(list_2)
  print("LENGTH:",length)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3 curiosity.

2016-09-06 Thread Wildman via Python-list
On Tue, 06 Sep 2016 02:51:39 -0700, wxjmfauth wrote:

> It's curious to see all these apps, that were
> more of less working correctly up to Python 3.2
> (included) and are now no more working at all.
> 
> Probably something wrong somewhere...

http://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html

-- 
 GNU/Linux user #557453
The cow died so I don't need your bull!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3 curiosity.

2016-09-06 Thread Chris Angelico
On Wed, Sep 7, 2016 at 2:13 AM, Wildman via Python-list
 wrote:
> On Tue, 06 Sep 2016 02:51:39 -0700, wxjmfauth wrote:
>
>> It's curious to see all these apps, that were
>> more of less working correctly up to Python 3.2
>> (included) and are now no more working at all.
>>
>> Probably something wrong somewhere...
>
> http://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html

That's jmf, and he never actually posts proof, but keeps on asserting
that Unicode handling in Python 3.3+ is "broken". Actually, it's not.
The worst criticism you can level at it is that it may be slower in
certain microbenchmarks... but only if you're comparing against a
*narrow build* of Python 3.2, which is *buggy*. In other words, Python
eliminated an endemic bug, and actually improved performance overall,
but worsened it on a very VERY few cases.

Most of us have either killfiled him, or are reading this via the
mailing list, which doesn't carry his traffic. I suggest you do the
same. He's a crank.

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


Re: Python 3 curiosity.

2016-09-06 Thread Wildman via Python-list
On Wed, 07 Sep 2016 02:27:40 +1000, Chris Angelico wrote:

> On Wed, Sep 7, 2016 at 2:13 AM, Wildman via Python-list
>  wrote:
>> On Tue, 06 Sep 2016 02:51:39 -0700, wxjmfauth wrote:
>>
>>> It's curious to see all these apps, that were
>>> more of less working correctly up to Python 3.2
>>> (included) and are now no more working at all.
>>>
>>> Probably something wrong somewhere...
>>
>> http://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html
> 
> That's jmf, and he never actually posts proof, but keeps on asserting
> that Unicode handling in Python 3.3+ is "broken". Actually, it's not.
> The worst criticism you can level at it is that it may be slower in
> certain microbenchmarks... but only if you're comparing against a
> *narrow build* of Python 3.2, which is *buggy*. In other words, Python
> eliminated an endemic bug, and actually improved performance overall,
> but worsened it on a very VERY few cases.
> 
> Most of us have either killfiled him, or are reading this via the
> mailing list, which doesn't carry his traffic. I suggest you do the
> same. He's a crank.
> 
> ChrisA

Thanks for the heads-up.

-- 
 GNU/Linux user #557453
"Be at war with your vices, at peace with your neighbors,
and let every new year find you a better man."
  -Benjamin Franklin
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Class - error return

2016-09-06 Thread Smith

On 06/09/2016 11:23, Peter Otten wrote:

If so look at


>  ...: def __str__(self):
>  ...: return "Visitor: %i, Contacts: %i %
> (self.visits,self.contacts)"

once more. Where are the quotes? Where should the be?




I solved the problem.
thank you Peter
--
https://mail.python.org/mailman/listinfo/python-list


Re: Extend unicodedata with a name/pattern/regex search for character entity references?

2016-09-06 Thread jladasky
On Saturday, September 3, 2016 at 7:49:14 PM UTC-7, Steve D'Aprano wrote:
> On Sun, 4 Sep 2016 12:19 pm, Chris Angelico wrote:

> > Killfile him and move on...
> 
> But but but... I couldn't do that.
> 
> https://www.xkcd.com/386/

I strongly suspected it would be that particular XKCD.  :^)
-- 
https://mail.python.org/mailman/listinfo/python-list


Python 3.5.0 python --version command reports 2.5.4

2016-09-06 Thread Yang, Gang CTR (US)
Hi,



I just installed Python 3.5.0 (since 3.5.2 would not installed on Windows 2008 
R2) and tried the python --version command. Surprisingly, the command reported 
2.5.4. What's going on?



Gang Yang

Shonborn-Becker Systems Inc. (SBSI)
Contractor Engineering Supporting SEC
Office: 732-982-8561, x427

Cell: 732-788-7501
Email: [email protected]
-- 
https://mail.python.org/mailman/listinfo/python-list


Multiprocessing interactive processes with connections

2016-09-06 Thread Charles Hixson
I want to process a bunch of processes that all talk to each other.  
I've figured out how to do this using queues with the main process as 
the mail handler, but I'd rather have them talk directly.  If I use 
connections, then I can pass the pipes to the processes, but there 
doesn't seem to be anything analogous to queue, so it looks like I need 
to divide each process into two threads, one of which does nothing but 
mail handling.


Is this correct?


FWIW, a small, unoptimized, test of the working "mailhandler" approach is:

## Multiprocessing:  main thread as post office.
#  This is a bit clumsy, but it works.

from  multiprocessing import Process, Queue
from  queue import   Empty

def f(i, lim, q_rcv, q_snd):
   for j in range(lim):
  if i != j:
 q_snd.put([i, "message from process {0} to proess 
{1}".format(i, j), j])

  if not q_rcv.empty():
 val   =  q_rcv.get()
 print (val)
   q_snd.put([i, "done"])
   while (not q_recv.empty()):
  val   =  q_rcv.get()
  print (val, " :: ", i)
  if val == "done": return


if __name__ == '__main__':
   ps =  []
   qs =  []
   q_recv   =  Queue()
   for i in range(3):
  q  =  Queue()
  qs.append (q)
  ps.append (Process(target=f, args=(i, 3, q, q_recv)) )
   for p in ps:
  p.start()
   dones =  0
   try:
  v = q_recv.get(True, 1)
  while (v):
 print ("v = ", v)
 if v[1] == "done":
dones =  dones + 1
 else:
if len(v) == 3:
   assert v[2] < len(qs), "unexpected value"
   qs[v[2]].put(v[1])
else:
   print ("error:  ", v, " was an unexpected value.")
 v = q_recv.get(True, 1)
   except   Empty:
  print ("1: Timeout of maine receive queue")
   for q in qs:
  q.put("done")
   try:
  v = q_recv.get(True, 1)
  while (v):
 print ("2: v = ", v)
 if v[1] == "done":
dones =  dones + 1
 else:
if len(v) == 3:
   assert v[3] < len(qs), "2: unexpected value"
   qs[v[3]].put(v[2])
else:
   print ("2: error:  ", v, " was an unexpected value.")
 v = q_recv.get(True, 1)
   except   Empty:
  print ("2: Timeout of maine receive queue")
   for i in range(len(qs)):
  qs[i].close();
  qs[i] =  None

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


Re: Python 3.5.0 python --version command reports 2.5.4

2016-09-06 Thread breamoreboy
On Tuesday, September 6, 2016 at 10:06:34 PM UTC+1, Yang, Gang CTR (US) wrote:
> Hi,
> 
> I just installed Python 3.5.0 (since 3.5.2 would not installed on Windows 
> 2008 R2) and tried the python --version command. Surprisingly, the command 
> reported 2.5.4. What's going on?
>  
> Gang Yang
>

You'll need to change your environment settings.  All the details are here 
https://docs.python.org/3/using/windows.html

Kindest regards.

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


Re: Extend unicodedata with a name/pattern/regex search for character

2016-09-06 Thread jladasky
On Saturday, September 3, 2016 at 7:49:14 PM UTC-7, Steve D'Aprano wrote:
> On Sun, 4 Sep 2016 12:19 pm, Chris Angelico wrote:

> > Killfile him and move on...
>
> But but but... I couldn't do that.
>
> https://www.xkcd.com/386/

I strongly suspected it would be that particular XKCD.  :^)

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


Re: Class - error return

2016-09-06 Thread nospam . Smith
On 06/09/2016 11:23, Peter Otten wrote:
> If so look at
>
>> >  ...: def __str__(self):
>> >  ...: return "Visitor: %i, Contacts: %i %
>> > (self.visits,self.contacts)"
> once more. Where are the quotes? Where should the be?
>
>
>
I solved the problem.
thank you Peter

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


Python 3.5.0 python --version command reports 2.5.4

2016-09-06 Thread Yang, Gang CTR (US)
Hi,



I just installed Python 3.5.0 (since 3.5.2 would not installed on Windows 2008
R2) and tried the python --version command. Surprisingly, the command reported
2.5.4. What's going on?



Gang Yang

Shonborn-Becker Systems Inc. (SBSI) Contractor Engineering Supporting SEC
Office: 732-982-8561, x427

Cell: 732-788-7501 Email:
[email protected]

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


Multiprocessing interactive processes with connections

2016-09-06 Thread nospam . Charles Hixson
I want to process a bunch of processes that all talk to each other. I've
figured out how to do this using queues with the main process as the mail
handler, but I'd rather have them talk directly.  If I use connections, then I
can pass the pipes to the processes, but there doesn't seem to be anything
analogous to queue, so it looks like I need to divide each process into two
threads, one of which does nothing but mail handling.

Is this correct?


FWIW, a small, unoptimized, test of the working "mailhandler" approach is:

## Multiprocessing:  main thread as post office.
#  This is a bit clumsy, but it works.

from  multiprocessing import Process, Queue from  queue import   Empty

def f(i, lim, q_rcv, q_snd):
for j in range(lim):
   if i != j:
  q_snd.put([i, "message from process {0} to proess
{1}".format(i, j), j])
   if not q_rcv.empty():
  val   =  q_rcv.get()
  print (val)
q_snd.put([i, "done"])
while (not q_recv.empty()):
   val   =  q_rcv.get()
   print (val, " :: ", i)
   if val == "done": return


if __name__ == '__main__':
ps =  []
qs =  []
q_recv   =  Queue()
for i in range(3):
   q  =  Queue()
   qs.append (q)
   ps.append (Process(target=f, args=(i, 3, q, q_recv)) )
for p in ps:
   p.start()
dones =  0
try:
   v = q_recv.get(True, 1)
   while (v):
  print ("v = ", v)
  if v[1] == "done":
 dones =  dones + 1
  else:
 if len(v) == 3:
assert v[2] < len(qs), "unexpected value"
qs[v[2]].put(v[1])
 else:
print ("error:  ", v, " was an unexpected value.")
  v = q_recv.get(True, 1)
except   Empty:
   print ("1: Timeout of maine receive queue")
for q in qs:
   q.put("done")
try:
   v = q_recv.get(True, 1)
   while (v):
  print ("2: v = ", v)
  if v[1] == "done":
 dones =  dones + 1
  else:
 if len(v) == 3:
assert v[3] < len(qs), "2: unexpected value"
qs[v[3]].put(v[2])
 else:
print ("2: error:  ", v, " was an unexpected value.")
  v = q_recv.get(True, 1)
except   Empty:
   print ("2: Timeout of maine receive queue")
for i in range(len(qs)):
   qs[i].close();
   qs[i] =  None

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


Re: Class - error return

2016-09-06 Thread Smith
From: Smith 

On 06/09/2016 11:23, Peter Otten wrote:
> If so look at
>
>> >  ...: def __str__(self):
>> >  ...: return "Visitor: %i, Contacts: %i %
>> > (self.visits,self.contacts)"
> once more. Where are the quotes? Where should the be?
>
>
>
I solved the problem.
thank you Peter

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


Python 3.5.0 python --version command reports 2.5.4

2016-09-06 Thread US
From: "Yang, Gang CTR (US)" 

Hi,



I just installed Python 3.5.0 (since 3.5.2 would not installed on Windows 2008
R2) and tried the python --version command. Surprisingly, the command reported
2.5.4. What's going on?



Gang Yang

Shonborn-Becker Systems Inc. (SBSI) Contractor Engineering Supporting SEC
Office: 732-982-8561, x427

Cell: 732-788-7501 Email:
[email protected]

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


Re: Extend unicodedata with a name/pattern/regex search for character

2016-09-06 Thread jladasky
From: [email protected]

On Saturday, September 3, 2016 at 7:49:14 PM UTC-7, Steve D'Aprano wrote:
> On Sun, 4 Sep 2016 12:19 pm, Chris Angelico wrote:

> > Killfile him and move on...
>
> But but but... I couldn't do that.
>
> https://www.xkcd.com/386/

I strongly suspected it would be that particular XKCD.  :^)

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


Multiprocessing interactive processes with connections

2016-09-06 Thread Charles_Hixson
From: Charles Hixson 

I want to process a bunch of processes that all talk to each other. I've
figured out how to do this using queues with the main process as the mail
handler, but I'd rather have them talk directly.  If I use connections, then I
can pass the pipes to the processes, but there doesn't seem to be anything
analogous to queue, so it looks like I need to divide each process into two
threads, one of which does nothing but mail handling.

Is this correct?


FWIW, a small, unoptimized, test of the working "mailhandler" approach is:

## Multiprocessing:  main thread as post office.
#  This is a bit clumsy, but it works.

from  multiprocessing import Process, Queue from  queue import   Empty

def f(i, lim, q_rcv, q_snd):
for j in range(lim):
   if i != j:
  q_snd.put([i, "message from process {0} to proess
{1}".format(i, j), j])
   if not q_rcv.empty():
  val   =  q_rcv.get()
  print (val)
q_snd.put([i, "done"])
while (not q_recv.empty()):
   val   =  q_rcv.get()
   print (val, " :: ", i)
   if val == "done": return


if __name__ == '__main__':
ps =  []
qs =  []
q_recv   =  Queue()
for i in range(3):
   q  =  Queue()
   qs.append (q)
   ps.append (Process(target=f, args=(i, 3, q, q_recv)) )
for p in ps:
   p.start()
dones =  0
try:
   v = q_recv.get(True, 1)
   while (v):
  print ("v = ", v)
  if v[1] == "done":
 dones =  dones + 1
  else:
 if len(v) == 3:
assert v[2] < len(qs), "unexpected value"
qs[v[2]].put(v[1])
 else:
print ("error:  ", v, " was an unexpected value.")
  v = q_recv.get(True, 1)
except   Empty:
   print ("1: Timeout of maine receive queue")
for q in qs:
   q.put("done")
try:
   v = q_recv.get(True, 1)
   while (v):
  print ("2: v = ", v)
  if v[1] == "done":
 dones =  dones + 1
  else:
 if len(v) == 3:
assert v[3] < len(qs), "2: unexpected value"
qs[v[3]].put(v[2])
 else:
print ("2: error:  ", v, " was an unexpected value.")
  v = q_recv.get(True, 1)
except   Empty:
   print ("2: Timeout of maine receive queue")
for i in range(len(qs)):
   qs[i].close();
   qs[i] =  None

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


Re: Python 3.5.0 python --version command reports 2.5.4

2016-09-06 Thread Terry Reedy

On 9/6/2016 4:59 PM, [email protected] wrote:


I just installed Python 3.5.0 (since 3.5.2 would not installed on Windows 2008
R2) and tried the python --version command. Surprisingly, the command reported
2.5.4. What's going on?


Most likely you have 2.5.4 installed and are running it.

--
Terry Jan Reedy

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