Re: Can signal.alarm be safely cleared in python?

2016-11-18 Thread dieter
Pedro Franco de Carvalho  writes:

> Assume a python program sets a handler function for the
> `signal.SIGALRM` signal, and then schedules an alarm in T seconds with
> `signal.alarm(T)`.
>
> Assume the program later cancels any scheduled alarm with `signal.alarm(0)`.

I do not think so. You might have a "race condition".

I think of the following (hypothetical) situation: the alarm
arrives while "signal.alarm(0)" processing has started but not yet finished.
In this case, the alarm arrival will schedule the alarm handler
activation - but, as "signal.alarm" is "C" implemented, the handler
will not be activated immediately (but delayed until the next
execution of Python code).

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


Re: how to simulate the situation in DNA evolution for finding the minimum population needed and minimum samples selected to mating in order to no extinction in any one of original species and new spe

2016-11-18 Thread meInvent bbird
i noticed the faces of human repeated or similar, 
and would like to prove whether evolution a several generations will 
return to the original intelligence of ancester

On Friday, November 18, 2016 at 1:55:31 PM UTC+8, meInvent bbird wrote:
> how to simulate the situation in DNA evolution for finding the minimum 
> population needed and minimum samples selected to mating in order to no 
> extinction in any one of original species and new species
> 
> assume mating are randomly selected to become a couple,
> how to keep species good which means no extinction in original species
> 
> i use i+j to get new species, 
> but i do not know whether there is limit in evolution, i assume
> limit is 7, then extra evolution will go back to past species and 
> cycle again
> 
> import matplotlib.pyplot as plt
> import random
> dict = {}
> dist = {}
> maxnum = 5
> allowedmax = 7
> for i in range(1,allowedmax+1):
> dist[str(i)] = 0
> 
> rr = range (1,maxnum)
> for i in range (1,maxnum):
> for j in range (1,maxnum):
> if i < j:
> print("(" +str(i) + "," + str(j) + ")");
> dict[str(i) + str(j)] = 1;
> dist[str(i+j)] = dist[str(i+j)] + 1
> if i+j > max(rr or [0]):
>  rr = rr + [i+j];
> 
> original = rr;
> for numberofevolutions in range(1,10):
> rr2 = []
> samples = random.sample(original, len(original)-2)
> print("total rr")
> print(str(rr))
> print("samples")
> print(str(samples))
> for i in samples:
> for j in samples:
> if i < j:
> print("(" +str(i) + "," + str(j) + ")");
> if i+j > allowedmax:
> dict[str(i) + str(j)] = (i+j) % allowedmax;
> dist[str((i+j) % allowedmax)] = dist[str((i+j) % 
> allowedmax)] + 1
> if ((i+j) % allowedmax) > max(rr2 or [0]):
> rr2 = rr2 + [((i+j) % allowedmax)];
> else:
> dict[str(i) + str(j)] = i+j;
> dist[str(i+j)] = dist[str(i+j)] + 1
> if i+j > max(rr2 or [0]):
> rr2 = rr2 + [i+j];
> temp = rr
> rr = rr2
> rr2 = temp
> 
> plt.bar(range(len(dist)), dist.values(), align='center')
> plt.xticks(range(len(dist)), dist.keys())
> plt.show()

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


Re: Can signal.alarm be safely cleared in python?

2016-11-18 Thread Chris Angelico
On Fri, Nov 18, 2016 at 7:51 PM, dieter  wrote:
> Pedro Franco de Carvalho  writes:
>
>> Assume a python program sets a handler function for the
>> `signal.SIGALRM` signal, and then schedules an alarm in T seconds with
>> `signal.alarm(T)`.
>>
>> Assume the program later cancels any scheduled alarm with `signal.alarm(0)`.
>
> I do not think so. You might have a "race condition".
>
> I think of the following (hypothetical) situation: the alarm
> arrives while "signal.alarm(0)" processing has started but not yet finished.
> In this case, the alarm arrival will schedule the alarm handler
> activation - but, as "signal.alarm" is "C" implemented, the handler
> will not be activated immediately (but delayed until the next
> execution of Python code).

That situation would be safe if the cancelling of the timer is in a
sense of "okay, don't bother" rather than "this must now not happen".
For example, you could set a timeout on some operation (say, a
subprocess execution) by setting an alarm. When the process
terminates, you cancel the alarm. If, just after you cancel the alarm,
the signal comes through, that's fine - the handler will already need
to cope with the process having just finished.

So I would say that it's safe IFF you accept this restriction.

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


IDLEX association

2016-11-18 Thread Luis Marzulli
Hi

When I double click a .py file, a windows appears and immediately disappears.
How can I associate the .py file extension to the IDLEX EDITOR?

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


Style().configure don't works for all widgets

2016-11-18 Thread Luis Marzulli
Hi
Why 

ttk.Style().configure(".", font=('Courier New', 30, "bold"))

works for Button and Label widgets (and maybe others) and don't works for Entry 
widget?

Example in Python 3:
from tkinter import *
from tkinter import ttk
from tkinter import font

root = Tk()
ttk.Style().configure(".", font=('Courier New', 30, "bold"))

ttk.Entry(root).grid() # don't works
ttk.Label(root, text="my text").grid() # works OK
ttk.Button(root, text="some text").grid() # works OK

root.mainloop()

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


Encountering fatal error x80070643 while installing Python

2016-11-18 Thread Irene Venditti
Hi everybody,

 

I've got a problem with the installation of Python. I am a translator and
currently I'm translating a book on programming Minecraft with Python, from
English to Dutch. 

 

My computer is a Windows 10 computer, 64-bits  (Toshiba Qosmio all in one).

I already had a 2.7 version of Python installed to C:\Program Files
(x86)\Python and stupidly forgot to uninstall this version when I downloaded
and installed version 3.5.1 (required for the book translation).

This didn't seem to be a problem, since version 3.5.1 installed to my
C:\Users\username\appdata\local\... directory. But when I tried to install
Python 3.5.2 and uninstalled both previous versions, the problems began.

Now I cannot install any version of Python anymore, not 3.5.0 or any later
versions. At the end of the procedure I get a fatal error message, with code
0x80070643, saying an error was encountered and the installation couldn't be
completed.

 

What do I do now? I desperately need my Python program for my book
translation.

 

Thanks, Irene

 

Kind regards,

Irene Venditti

i-write translations and texts

 

  [email protected]

  www.i-write.biz

0031 (0)6 220 760 73

 



 

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


need help to get my python image to move around using tkinter

2016-11-18 Thread twgrops--- via Python-list
Hi I am new here and to python,

I am currently studying towards my degree in computer science and have to build 
a program but I have hit a brick wall. I am trying to make an image move around 
the canvas. I can make a rectangle move using the following:

#test rectangle
id1=canvas.create_rectangle(3,7,3+10,7+10)

# Generate x and y coordinates for 500 timesteps
for t in range(1, 500):

x1,y1,x2,y2=canvas.coords(id1)

# If a boundary has been crossed, reverse the direction
if x1 >= x_max:
 vx = -10.0
if y1 <= y_min:
 vy = 5.0
if y2 >= y_max:
 vy = -5.0
if x1 <= x_min:
 vx = 10.0

# Reposition the robot
canvas.coords(id1,x1+vx,y1+vy,x2+vx,y2+vy)
canvas.update()

# Pause for 0.1 seconds, then delete the image
time.sleep(0.1)

However i would like my image/sprite to move around:

objecttank=canvas.create_image(950,650,image=gif6, anchor= NW)

from what i gather it is because an image only has two axis, x and y but the 
rectangle seems to have 4 values, my error code keeps saying expecting 4 but 
got 2. 

Can anyone help me in the right direction, many thanks tom.
-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: eGenix PyRun - One file Python Runtime 2.2.2

2016-11-18 Thread eGenix Team: M.-A. Lemburg


ANNOUNCING

eGenix PyRun - One file Python Runtime

Version 2.2.2


   An easy-to-use single file relocatable Python run-time -
  available for Linux, Mac OS X and Unix platforms,
  with support for Python 2.6, 2.7, 3.4 and
* now for Python 3.5 *


This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-PyRun-2.2.2-GA.html



INTRODUCTION

eGenix PyRun is our open source, one file, no installation version of
Python, making the distribution of a Python interpreter to run based
scripts and applications to Unix based systems as simple as copying a
single file.

eGenix PyRun's executable only needs 11MB for Python 2 and 13MB for
Python 3, but still supports most Python application and scripts - and
it can be compressed to just 3-4MB using upx, if needed.

Compared to a regular Python installation of typically 100MB on disk,
eGenix PyRun is ideal for applications and scripts that need to be
distributed to several target machines, client installations or
customers.

It makes "installing" Python on a Unix based system as simple as
copying a single file.

eGenix has been using eGenix PyRun internally in the mxODBC Connect
Server product since 2008 with great success and decided to make it
available as a stand-alone open-source product.

We provide both the source archive to build your own eGenix PyRun, as
well as pre-compiled binaries for Linux, FreeBSD and Mac OS X, as 32-
and 64-bit versions. The binaries can be downloaded manually, or you
can let our automatic install script install-pyrun take care of the
installation: ./install-pyrun dir and you're done.

Please see the product page for more details:

http://www.egenix.com/products/python/PyRun/



NEWS

This minor level release of eGenix PyRun comes with the following
enhancements:

Enhancements / Changes
--

 * Upgraded PyRun to Python 2.7.12, Python 3.4.5 and Python 3.5.2.

 * Fixed rpath setting to properly include the $ORIGIN marker. Without
   this, the rpath setting doesn't work.

 * Added missing lzma module to default PyRun 3.x installation. Please
   note that this adds an additional dependency on libzma.so.5 for
   PyRun for Python 3.4 and 3.5.

install-pyrun Quick Install Enhancements
-

eGenix PyRun includes a shell script called install-pyrun, which
greatly simplifies installation of PyRun. It works much like the
virtualenv shell script used for creating new virtual environments
(except that there's nothing virtual about PyRun environments).

https://downloads.egenix.com/python/install-pyrun

With the script, an eGenix PyRun installation is as simple as running:

./install-pyrun targetdir

This will automatically detect the platform, download and install the
right pyrun version into targetdir.

We have updated this script since the last release:

 * Updated install-pyrun to default to eGenix PyRun 2.2.2 and its
   feature set.

For a complete list of changes, please see the eGenix PyRun Changelog:

http://www.egenix.com/products/python/PyRun/changelog.html



LICENSE

eGenix PyRun is distributed under the eGenix.com Public License 1.1.0
which is an Open Source license similar to the Python license. You can
use eGenix PyRun in both commercial and non-commercial settings
without fee or charge.

Please see our license page for more details:

http://www.egenix.com/products/python/PyRun/license.html

The package comes with full source code.



DOWNLOADS

The download archives and instructions for installing eGenix PyRun can
be found at:

http://www.egenix.com/products/python/PyRun/

As always, we are providing pre-built binaries for all common
platforms: Windows 32/64-bit, Linux 32/64-bit, FreeBSD 32/64-bit, Mac
OS X 32/64-bit. Source code archives are available for installation on
other platforms, such as Solaris, AIX, HP-UX, etc.

___

SUPPORT

Commercial support for this product is available from eGenix.com.
Please see

http://www.egenix.com/services/support/

for details about our support offerings.



MORE INFORMATION

For more information about eGenix PyRun, licensing and download
instructions, please visit our web-site:

http://www.egenix.com/products/python/PyRun/


About eGenix (http://www.egenix.com/):

eGenix is a Python software project, consulting and product
company delivering expert services and

Re: ANN: eGenix PyRun - One file Python Runtime 2.2.2

2016-11-18 Thread Grant Edwards
On 2016-11-18, eGenix Team: M.-A. Lemburg  wrote:

> eGenix PyRun is our open source, one file, no installation version of
> Python, making the distribution of a Python interpreter to run based
> scripts and applications

What's a "based" script?

-- 
Grant Edwards   grant.b.edwardsYow! Those people look
  at   exactly like Donnie and
  gmail.comMarie Osmond!!

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


Re: Style().configure don't works for all widgets

2016-11-18 Thread Peter Otten
Luis Marzulli wrote:

> ttk.Style().configure(".", font=('Courier New', 30, "bold"))
> 
> works for Button and Label widgets (and maybe others) and don't works for
> Entry widget?
> 
> Example in Python 3:
> from tkinter import *
> from tkinter import ttk
> from tkinter import font
> 
> root = Tk()
> ttk.Style().configure(".", font=('Courier New', 30, "bold"))
> 
> ttk.Entry(root).grid() # don't works
> ttk.Label(root, text="my text").grid() # works OK
> ttk.Button(root, text="some text").grid() # works OK
> 
> root.mainloop()

I can confirm this, but I have no idea why this is so.
As a workaround you can set the font directly:

FONT = ("Courier New", 30, "bold")
ttk.Style().configure(".", font=FONT)
...
ttk.Entry(root, font=FONT)

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


Re: Encountering fatal error x80070643 while installing Python

2016-11-18 Thread MRAB

On 2016-11-18 11:40, Irene Venditti wrote:

Hi everybody,

I've got a problem with the installation of Python. I am a translator and
currently I'm translating a book on programming Minecraft with Python, from
English to Dutch.

My computer is a Windows 10 computer, 64-bits  (Toshiba Qosmio all in one).

I already had a 2.7 version of Python installed to C:\Program Files
(x86)\Python and stupidly forgot to uninstall this version when I downloaded
and installed version 3.5.1 (required for the book translation).

This didn't seem to be a problem, since version 3.5.1 installed to my
C:\Users\username\appdata\local\... directory. But when I tried to install
Python 3.5.2 and uninstalled both previous versions, the problems began.

Now I cannot install any version of Python anymore, not 3.5.0 or any later
versions. At the end of the procedure I get a fatal error message, with code
0x80070643, saying an error was encountered and the installation couldn't be
completed.

What do I do now? I desperately need my Python program for my book
translation.

Have you tried manually deleting those folders? You could just rename 
them instead and delay deleting them until the problem is fixed.


It's recommended to give the Python folder a name that reflects its 
version, e.g. Python35. If you want both the 64-bit and 32-bit versions, 
then Python35-32 and Python35 (or Python35-64).


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


Parsing a single-level JSON file

2016-11-18 Thread mike . reider
hi all, 

Im reading in a JSON file that looks like this


[  
   {  
  "name":"myField1",
  "searchable":true,
  "navigable":true,
  "custom":true,
  "clauseNames":[  
 "cf[10190]",
 "Log Details"
  ],
  "orderable":true,
  "id":"customfield_10190",
  "schema":{  
 "customId":10190,
 "type":"string",
 "custom":"com.atlassian.jira.plugin.system.customfieldtypes:textarea"
  }
   },
   {  
  "name":"myField2",
  "searchable":true,
  "navigable":true,
  "custom":true,
  "clauseNames":[  
 "cf[10072]",
 "Sellside Onboarding Checklist"
  ],
  "orderable":true,
  "id":"customfield_10072",
  "schema":{  
 "items":"option",
 "customId":10072,
 "type":"array",
 
"custom":"com.atlassian.jira.plugin.system.customfieldtypes:multicheckboxes"
  }
   }]


Lets say I want to get the ID # of MyField1, how can I parse this with json 
lib? Theyre all on the same level, not sure how to target it to go to MyField1 
and get "id" value. 

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


Re: Parsing a single-level JSON file

2016-11-18 Thread John Gordon
In  
[email protected] writes:

> Im reading in a JSON file that looks like this
> ... snip ...
> Lets say I want to get the ID # of MyField1, how can I parse this with
> json lib? Theyre all on the same level, not sure how to target it to go
> to MyField1 and get "id" value. 

That data looks like a list of dictionaries:

import json

with open("json.dat", "r") as fp:
data = json.load(fp)
for item in data:
if item['name'] == 'myField2':
print item['id']

-- 
John Gordon   A is for Amy, who fell down the stairs
[email protected]  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Parsing a single-level JSON file

2016-11-18 Thread John Gordon
In  John Gordon  writes:

> In  
> [email protected] writes:

> with open("json.dat", "r") as fp:
> data = json.load(fp)
> for item in data:
> if item['name'] == 'myField2':

Oops, that should be 'myField1' of course.

-- 
John Gordon   A is for Amy, who fell down the stairs
[email protected]  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Parsing a single-level JSON file

2016-11-18 Thread MRAB

On 2016-11-18 18:23, [email protected] wrote:

hi all,

Im reading in a JSON file that looks like this


[
   {
  "name":"myField1",
  "searchable":true,
  "navigable":true,
  "custom":true,
  "clauseNames":[
 "cf[10190]",
 "Log Details"
  ],
  "orderable":true,
  "id":"customfield_10190",
  "schema":{
 "customId":10190,
 "type":"string",
 "custom":"com.atlassian.jira.plugin.system.customfieldtypes:textarea"
  }
   },
   {
  "name":"myField2",
  "searchable":true,
  "navigable":true,
  "custom":true,
  "clauseNames":[
 "cf[10072]",
 "Sellside Onboarding Checklist"
  ],
  "orderable":true,
  "id":"customfield_10072",
  "schema":{
 "items":"option",
 "customId":10072,
 "type":"array",
 
"custom":"com.atlassian.jira.plugin.system.customfieldtypes:multicheckboxes"
  }
   }]


Lets say I want to get the ID # of MyField1, how can I parse this with json lib? Theyre 
all on the same level, not sure how to target it to go to MyField1 and get "id" 
value.

Thanks


Parsing it is easy:

with open(json_path) as json_file:
data_list = json.load(json_file)


If it's a one-off lookup, just do a linear search:

for entry in data_list:
if entry['name'] == 'myField1':
print('ID is {}'.format(entry['id']))
break
else:
print('Not found!')


If you're going to do multiple lookups, turn it into a dict, using the 
'name' field as the key:


data_dict = {entry['name']: entry for entry in data_list}
if 'myField1' in data_dict:
print('ID is {}'.format(data_dict['myField1']['id']))
else:
print('Not found!')

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


Re: Parsing a single-level JSON file

2016-11-18 Thread Peter Otten
[email protected] wrote:

> hi all,
> 
> Im reading in a JSON file that looks like this
> 
> 
> [  
>{  
>   "name":"myField1",
>   "searchable":true,
>   "navigable":true,
>   "custom":true,
>   "clauseNames":[
>  "cf[10190]",
>  "Log Details"
>   ],
>   "orderable":true,
>   "id":"customfield_10190",
>   "schema":{
>  "customId":10190,
>  "type":"string",
>  
"custom":"com.atlassian.jira.plugin.system.customfieldtypes:textarea"
>   }
>},
>{  
>   "name":"myField2",
>   "searchable":true,
>   "navigable":true,
>   "custom":true,
>   "clauseNames":[
>  "cf[10072]",
>  "Sellside Onboarding Checklist"
>   ],
>   "orderable":true,
>   "id":"customfield_10072",
>   "schema":{
>  "items":"option",
>  "customId":10072,
>  "type":"array",
>  
"custom":"com.atlassian.jira.plugin.system.customfieldtypes:multicheckboxes"
>   }
>}]
> 
> 
> Lets say I want to get the ID # of MyField1, how can I parse this with
> json lib? Theyre all on the same level, not sure how to target it to go to
> MyField1 and get "id" value.

>>> import json
>>> data = json.loads(s)
>>> [wanted] = [d["id"] for d in data if d["name"] == "myField1"]
>>> wanted
'customfield_10190'

If you need to do this often for the same data you can speed up the process 
with a lookup table:

>>> lookup = {d["name"]: d["id"] for d in data}
>>> lookup["myField1"]
'customfield_10190'
>>> lookup["myField2"]
'customfield_10072'

I'm assuming that the names are unique.

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


Re: need help to get my python image to move around using tkinter

2016-11-18 Thread Peter Otten
twgrops--- via Python-list wrote:

> Hi I am new here and to python,
> 
> I am currently studying towards my degree in computer science and have to
> build a program but I have hit a brick wall. I am trying to make an image
> move around the canvas. I can make a rectangle move using the following:
> 
> #test rectangle
> id1=canvas.create_rectangle(3,7,3+10,7+10)
> 
> # Generate x and y coordinates for 500 timesteps
> for t in range(1, 500):
> 
> x1,y1,x2,y2=canvas.coords(id1)
> 
> # If a boundary has been crossed, reverse the direction
> if x1 >= x_max:
>  vx = -10.0
> if y1 <= y_min:
>  vy = 5.0
> if y2 >= y_max:
>  vy = -5.0
> if x1 <= x_min:
>  vx = 10.0
> 
> # Reposition the robot
> canvas.coords(id1,x1+vx,y1+vy,x2+vx,y2+vy)
> canvas.update()
> 
> # Pause for 0.1 seconds, then delete the image
> time.sleep(0.1)

You should never use sleep() in conjunction with tkinter. Instead make a 
little function that schedules itself for invocation after a few 
milliseconds:

def move():
   ... # move sprits
   root.after(100, move) # have tkinter call move() 
 # again after 100 milliseconds

That way the event loop is undisturbed and the application can respond to 
user input.

> However i would like my image/sprite to move around:
> 
> objecttank=canvas.create_image(950,650,image=gif6, anchor= NW)
> 
> from what i gather it is because an image only has two axis, x and y but
> the rectangle seems to have 4 values, my error code keeps saying expecting
> 4 but got 2.

Always provide the exact code causing the error, and the traceback it 
generated. Use copy and paste instead of paraphrasing.
 
> Can anyone help me in the right direction, many thanks tom.

I think I have done this before, but cannot find it atm, so instead of a 
link here's a new demo:

try:
import tkinter as tk
except ImportError:
import Tkinter as tk

import random

WIDTH = 1024
HEIGHT = 768


def random_speed():
return random.choice([-1, 1]) * random.randrange(5, 15)


def random_image(canvas, image):
"""Place `image` on `canvas` with random pos and speed.
"""
return Image(
canvas,
image,
random.randrange(WIDTH-image.width()),
random.randrange(HEIGHT-image.height()),
random_speed(),
random_speed(),
)


class Image(object):
def __init__(self, canvas, image, x, y, vx, vy):
self.canvas = canvas
self.image = image
self.x = x
self.y = y
self.vx = vx
self.vy = vy
self.w = image.width()
self.h = image.height()
self.id = canvas.create_image(x, y, image=image, anchor=tk.NW)

@property
def right(self):
return self.x + self.w

@property
def bottom(self):
return self.y + self.h

def move(self):
self.x += self.vx
self.y += self.vy
self.canvas.move(self.id, self.vx, self.vy)
if self.bottom > HEIGHT or self.y < 0:
self.vy = - self.vy
if self.right > WIDTH or self.x < 0:
self.vx = - self.vx


def move():
for image in images:
image.move()
root.after(50, move)


if __name__ == "__main__":
root = tk.Tk()
ball = tk.PhotoImage(file="ball.gif")
canvas = tk.Canvas(root, width=WIDTH, height=HEIGHT)
canvas.pack()
images = [random_image(canvas, ball) for _ in range(10)]
move()
root.mainloop()


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


Re: Parsing a single-level JSON file

2016-11-18 Thread mike . reider
On Friday, November 18, 2016 at 1:23:18 PM UTC-5, [email protected] wrote:
> hi all, 
> 
> Im reading in a JSON file that looks like this
> 
> 
> [  
>{  
>   "name":"myField1",
>   "searchable":true,
>   "navigable":true,
>   "custom":true,
>   "clauseNames":[  
>  "cf[10190]",
>  "Log Details"
>   ],
>   "orderable":true,
>   "id":"customfield_10190",
>   "schema":{  
>  "customId":10190,
>  "type":"string",
>  "custom":"com.atlassian.jira.plugin.system.customfieldtypes:textarea"
>   }
>},
>{  
>   "name":"myField2",
>   "searchable":true,
>   "navigable":true,
>   "custom":true,
>   "clauseNames":[  
>  "cf[10072]",
>  "Sellside Onboarding Checklist"
>   ],
>   "orderable":true,
>   "id":"customfield_10072",
>   "schema":{  
>  "items":"option",
>  "customId":10072,
>  "type":"array",
>  
> "custom":"com.atlassian.jira.plugin.system.customfieldtypes:multicheckboxes"
>   }
>}]
> 
> 
> Lets say I want to get the ID # of MyField1, how can I parse this with json 
> lib? Theyre all on the same level, not sure how to target it to go to 
> MyField1 and get "id" value. 
> 
> Thanks



thanks everyone for the feedback, i got it to work like this using multi-dim 
dictionary

# get JSON to parse
url = "https://"+jira_server+"/rest/api/2/field";
req = requests.get(url,auth=(jira_user,jira_pw), verify=False)
jsonfile = req.json()

# save as key,val pair file
cf = {}
for item in jsonfile:
name = item.get("name")
fid =  item.get("id")
cf[name] = { 'id' : fid }
 
with open(base_dir+'/fields.json','w') as f:
json.dump(cf,f)

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


Re: Parsing a single-level JSON file

2016-11-18 Thread mike . reider


the end result file looks like this

cat fields.json

{"myField1": {"id": "customfield_10600"}, "myField2": {"id": 
"customfield_11334"}, "myField3": {"id": "customfield_993434"}, etc etc
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need help to get my python image to move around using tkinter

2016-11-18 Thread Thomas Grops via Python-list
thankyou so much, that is the exact help I required to put me in the right 
direction :D
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Encountering fatal error x80070643 while installing Python

2016-11-18 Thread eryk sun
On Fri, Nov 18, 2016 at 5:55 PM, MRAB  wrote:
> On 2016-11-18 11:40, Irene Venditti wrote:
>>
>> This didn't seem to be a problem, since version 3.5.1 installed to my
>> C:\Users\username\appdata\local\... directory. But when I tried to install
>> Python 3.5.2 and uninstalled both previous versions, the problems began.
>>
>> Now I cannot install any version of Python anymore, not 3.5.0 or any later
>> versions. At the end of the procedure I get a fatal error message, with
>> code 0x80070643, saying an error was encountered and the installation
>> couldn't be completed.
>
> Have you tried manually deleting those folders? You could just rename them
> instead and delay deleting them until the problem is fixed.
>
> It's recommended to give the Python folder a name that reflects its version,
> e.g. Python35. If you want both the 64-bit and 32-bit versions, then
> Python35-32 and Python35 (or Python35-64).

It looks like the OP is using the default per-user target directory,
"%LocalAppData%\Programs\Python\Python35[-32]". It's possible
something was left there by the old 3.5.1 installation, such as
pip/setuptools in site-packages, which is causing the 3.5.2
installation to fail. I would first try the "repair" option using the
3.5.1 installer, if that's an available option. Then upgrade to 3.5.2.
You shouldn't need to remove 3.5.1 to install 3.5.2. It's an in-place
upgrade.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: IDLEX association

2016-11-18 Thread eryk sun
On Fri, Nov 18, 2016 at 7:09 PM, Dennis Lee Bieber
 wrote:
> On Fri, 18 Nov 2016 04:46:46 -0800 (PST), Luis Marzulli
>  declaimed the following:
>
>>When I double click a .py file, a windows appears and immediately disappears.
>>How can I associate the .py file extension to the IDLEX EDITOR?
>
> You really don't want to do that (I'm not familiar with "IDLEX", but
> Python's IDLE is itself a Python script, so if Python scripts were
> associated with the editor script, you'd get a recursion of the editor
> trying to open itself in the editor).

No, the file association would run IDLE[X] via pyw.exe or pythonw.exe.

If Python is installed for all users and you have the default
associations selected as you user choice in the shell (i.e.
Python.File and Python.NoConFile), then you can easily modify the .py
and .pyw file association using an elevated command prompt.
(Ironically it's harder to modify this for a per-user installation,
since cmd's assoc and ftype commands use only the system registry
hive.) For example:

Show the current association:

C:\>assoc .py
.py=Python.File

C:\>ftype Python.File
Python.File="C:\Windows\py.exe" "%1" %*

(Note that assoc shows the system association, but your user choice in
the shell may be different. This choice is buried in the registry
under 
HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.py\UserChoice.)

Modify the "Python.File" ProgId to run IDLE 3.5 (running IDLEX is
probably similar, but I don't use it):

C:\>ftype Python.File="C:\Windows\pyw.exe" -3.5 -m idlelib "%1" %*
Python.File="C:\Windows\pyw.exe" -3.5 -m idlelib "%1" %*

You can easily restore the association back to the default:

C:\>ftype Python.File="C:\Windows\py.exe" "%1" %*
Python.File="C:\Windows\py.exe" "%1" %*

and run a test script:

C:\>type test.py
#!/usr/bin/python3
import sys
print(sys.executable)

C:\>test.py
C:\Program Files\Python36\python.exe

Personally I don't use an editor as the default action for .py files.
Instead I add a right-click "edit" action. For the command line, I
have an edit script that invokes this action on a file.
-- 
https://mail.python.org/mailman/listinfo/python-list


How to append a modified list into a list?

2016-11-18 Thread jfong
I have a working list 'tbl' and recording list 'm'. I want to append 'tbl' into 
'm' each time when the 'tbl' was modified. I will record the change by append 
it through the function 'apl'.

For example:

>>>tbl=[0,0]
>>>m=[]

>>>tbl[0]=1
>>>apl(tbl)
>>>m
[[1,0]]

>>>tbl[1]=2
>>>apl(tbl)
>>>m
[[1,0], [1,2]]

How to define this function properly?

Obviously the most intuitive way doesn't work.
def apl0(tbl):
m.append(tbl)

and introducing a local variable will not help either.
def apl1(tbl):
w=tbl
m.append(w)

I figure out a workable way, but looks ugly.
def apl2(tbl):
w=[]
w[:]=tbl
m.append(w)

I know those binding tricks between names and objects. Just wondering if there 
is an elegant way of doing this:-)

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


how to multiply two matrices with different size?

2016-11-18 Thread limetree377
Hi :)
I'm trying to multiply two matrices that has different size.

-code-

import numpy as np

a = np.random.randn(4, 3)
b = np.random.randn(4, 1)

print a
print b

-code-

How should I multiply a and b so that the multipled matrix's size is 4*3?

I want to multiply matrix 'b' to each row of matrix 'a'.
So that if matrix a is
[[1, 2, 3],
  [2, 3, 4]]
and b is
[[2],
[3]]
a*b is
[[2, 4, 6],
  [4, 6 ,8]]

Plz help me!

if possible, plz use numpy
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to multiply two matrices with different size?

2016-11-18 Thread Ian Kelly
On Fri, Nov 18, 2016 at 6:51 PM,   wrote:
> Hi :)
> I'm trying to multiply two matrices that has different size.
>
> -code-
>
> import numpy as np
>
> a = np.random.randn(4, 3)
> b = np.random.randn(4, 1)
>
> print a
> print b
>
> -code-
>
> How should I multiply a and b so that the multipled matrix's size is 4*3?
>
> I want to multiply matrix 'b' to each row of matrix 'a'.
> So that if matrix a is
> [[1, 2, 3],
>   [2, 3, 4]]
> and b is
> [[2],
> [3]]
> a*b is
> [[2, 4, 6],
>   [4, 6 ,8]]
>
> Plz help me!
>
> if possible, plz use numpy

You don't need to do anything special.

>>> import numpy as np
>>> a = np.array([[1,2,3],[2,3,4]])
>>> b = np.array([[2], [3]])
>>> a
array([[1, 2, 3],
   [2, 3, 4]])
>>> b
array([[2],
   [3]])
>>> a * b
array([[ 2,  4,  6],
   [ 6,  9, 12]])

(I'm assuming this is actually the output you want. The output you
posted is jut a * 2.)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to append a modified list into a list?

2016-11-18 Thread Ian Kelly
On Nov 18, 2016 6:47 PM,  wrote:

I have a working list 'tbl' and recording list 'm'. I want to append 'tbl'
into 'm' each time when the 'tbl' was modified. I will record the change by
append it through the function 'apl'.

For example:

>>>tbl=[0,0]
>>>m=[]

>>>tbl[0]=1
>>>apl(tbl)
>>>m
[[1,0]]

>>>tbl[1]=2
>>>apl(tbl)
>>>m
[[1,0], [1,2]]

How to define this function properly?

Obviously the most intuitive way doesn't work.
def apl0(tbl):
m.append(tbl)

and introducing a local variable will not help either.
def apl1(tbl):
w=tbl
m.append(w)

I figure out a workable way, but looks ugly.
def apl2(tbl):
w=[]
w[:]=tbl
m.append(w)

I know those binding tricks between names and objects. Just wondering if
there is an elegant way of doing this:-)


The important thing is to copy the list, not rebind it.

def apl(tbl):
m.append(tbl[:])

Or:

def apl(tbl):
m.append(list(tbl))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to append a modified list into a list?

2016-11-18 Thread Steve D'Aprano
On Sat, 19 Nov 2016 12:44 pm, [email protected] wrote:

> I have a working list 'tbl' and recording list 'm'. I want to append 'tbl'
> into 'm' each time when the 'tbl' was modified. I will record the change
> by append it through the function 'apl'.
[...]
> Obviously the most intuitive way doesn't work.
> def apl0(tbl):
> m.append(tbl)

That works perfectly -- it just doesn't do what you want.

It sounds like what you want is to append a COPY of the list rather than the
list itself. I'm not sure why, making copies of things in Python is usually
rare, but perhaps I don't understand what you are doing with this "working
list" and "recording list".

The simplest way to do this is:


m.append(tbl[:])  # use slicing to make a copy


In newer versions of Python, you can do this:


m.append(tbl.copy())


But that won't work in Python 2.7. Or you can do this:



from copy import copy
m.append(copy(tbl))



But the most Pythonic way (the most standard way) is to use a slice to copy
the list: m.append(tbl[:])

 
> and introducing a local variable will not help either.
> def apl1(tbl):
> w=tbl
> m.append(w)

Of course not. Assignment does not make a copy.





-- 
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: help on "from deen import *" vs. "import deen"

2016-11-18 Thread Steve D'Aprano
On Sat, 19 Nov 2016 05:50 am, Dennis Lee Bieber wrote:

> Python's name binding is very easy to state in English: Assignment in
> Python attaches the name (on the left hand side of the statement) to the
> object (that is the result of the right hand side).

What do you mean "attach"? What's a name? What's an object?


What happens if you do this?

spam = eggs = cheese = obj

Is that different from:

spam = obj
eggs = obj
cheese = obj


or from this?

spam = obj
eggs = spam
cheese = eggs


As an expert Python program with more than a decade's experience, you
probably think these questions are so basic that they are obvious. But to a
beginner, they aren't even close to obvious.


https://www.edutopia.org/blog/the-curse-of-knowledge-chris-reddy

https://signalvnoise.com/posts/213-the-curse-of-knowledge


> In contrast, assignment in C, FORTRAN, BASIC, COBOL can be stated as:
> Assignment in  copies the contents (value) of the memory
> location identified by the right hand side to the memory location
> identified by the left hand side.

Well that doesn't help...

foo = 999 + 1;

What memory location is identified by the right hand side?



> The Python actually comes out cleaner -- no need to explain memory
> locations, contents/values, and copying.

No, but you do have to explain "bind", "name" and "value".


> If you need a visual, in Python, fully qualified names are labels with
> a string; the other end of the string is taped to an object.

Analogies are great, but you also have to explain the limits of the analogy.
And analogies can mislead too.


What's the first end attached to? What precisely is a name?


Since we can do this:

# name with string attached to object
fred---999


and we can do this:

# two names with two strings both attached to the same object
fred--999
   |
george-+


can we do any of these? If we can't, why not?


# object with string not attached to any name
  ---999


# name with string not attached to any object
fred---


# name with string attached to another name, attached to object
fred-george--999


# object with string attached to name
fred--999---george


# two names, attached to each other, with no object
fred+
|
george--+


# name with two pieces of string attached to two objects
fred-999
   |
   +-888


# name with string attached to another string?
fred-+
 |
george---+--999



# two objects tied together
   999-888


# name with no string
fred


# object with no string
  999


# string tied in a loop (with or without a name)

fred+---+
|   |
+---+

+---+
|   |
+---+



These aren't silly questions. Some of them are meaningful, some of them
aren't. They're questions suggested by the "label with string tied to an
object" model of name binding. As experts, we're so used to the limits of
the model that we don't stop to think about all the ways that it can
mislead. But a beginner doesn't know the limits of the model, and doesn't
know how to apply the model to their code.




-- 
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: How to append a modified list into a list?

2016-11-18 Thread jfong
Oh, I don't know slice well enough:-(

So, slice tbl[:] will create a new object (a copy of tbl) which can be passed 
as a function argument
m.append(tbl[:])

or bind to a new name
w=tbl[:]

or re-bind to itself
w[:]=tbl

Thanks you, Ian and Steve.

Steve D'Aprano at 2016/11/19 11:01:26AM wrote:
> In newer versions of Python, you can do this:
> m.append(tbl.copy())

I like it:-)

--Jach

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


Re: help on "from deen import *" vs. "import deen"

2016-11-18 Thread Chris Angelico
On Sat, Nov 19, 2016 at 3:34 PM, Steve D'Aprano
 wrote:
> What happens if you do this?
>
> spam = eggs = cheese = obj
>
> Is that different from:
>
> spam = obj
> eggs = obj
> cheese = obj
>
>
> or from this?
>
> spam = obj
> eggs = spam
> cheese = eggs
> ...
> These aren't silly questions.

Indeed, they are not silly. It surprised me (as a C programmer) that
the assignments happen left-to-right, rather than right-to-left (in C,
cheese would be set first, then eggs, then spam). These are questions
filled with subtleties.

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