Re: Python bug report

2017-12-23 Thread breamoreboy
On Friday, December 22, 2017 at 1:28:17 PM UTC, Ranya wrote:
> Hi,
> Am trying to use clr.AddReference and clr.AddReferenceToFile, but
> python(2.7) keeps making this error:
> 
> Traceback (most recent call last):
>   File "", line 1, in 
> clr.AddReference("UnityEngine")AttributeError: 'module' object has
> no attribute 'AddReference'
> 
> How can I fix this?
> Thanks in advance.

Are you actually using the IronPython clr module, have you downloaded by 
mistake the module of the same name from pypi, or do you have a module of the 
same name on your path?

--
Kindest regards.

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


Re: co-ordianate transformation with astropy

2017-12-23 Thread breamoreboy
On Friday, December 22, 2017 at 9:36:29 PM UTC, hemanta phurailatpam wrote:
> I want to do co-ordinate transformation from earth-frame to equatorial frame. 
> By entering date and time, I want to get RA(right ascension) and 
> Dec(declination) wrt to equatorial frame. How do I do it?

It looks as if you need astropy, specifically 
http://docs.astropy.org/en/stable/coordinates/transforming.html

--
Kindest regards.

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


co-ordianate transformation with astropy

2017-12-23 Thread hemanta phurailatpam
I want to do co-ordinate transformation from earth-frame to equatorial frame. 
By entering date and time, I want to get RA(right ascension) and 
Dec(declination) wrt to equatorial frame. How do I do it?
-- 
https://mail.python.org/mailman/listinfo/python-list


A convenient and powerful API for interacting with external commands

2017-12-23 Thread Thiago Padilha
Hello fellow Python users

I've always used Python as shell scripting language to automate tasks in various
projects, especially when doing complex work where Bash gets messy.

While Python is a much more powerful language than Bash, I've always
found the builtin subprocess.Popen APIs a bit inconvenient to invoke external
commands, especially for creating pipelines and doing redirection. Surely one
can use shell=True and Popen will invoke the shell, but this is not without
drawbacks since one has to deal with shell-specific syntax particularities,
such as argument quoting.

To make shell scripting in Python more convenient, I've created a new module:
https://github.com/tarruda/python-ush. The README and tests contains more
detailed examples but here's an idea of how it looks like:

  import ush
  sh = ush.Shell()

  ls, sort = sh('ls', 'sort')

  # by default, wait for command to exit and return status code for each in
  # pipeline. stdin, stdout and stderr are inherited.
  ls_exit_code, sort_exit_code = (ls | sort)()

  # iterate output, line by line
  for f in ls | sort:
print(f)

  # collect all output into a string
  str(ls('-la') | sort('--reverse'))

  # redirect stdout

  ls | sort | 'output.txt'

  # append output to a file

  (ls | sort | '+output.txt')()

  # redirect stdin

  ('input.txt' | sort)()

  # filename expansion

  ls('*.py', glob=True)

The module is compatible with python 2 and 3, and should work on any Unix or
Windows. Also, since it is implemented in a single file (~650 LOC) without
dependencies, it should be easy to download and incorporate in a
another project.

Any feedback is appreciated
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why are both locals() and globals() set?

2017-12-23 Thread MRAB

On 2017-12-23 04:01, Peng Yu wrote:

Hi, The following example shows that both locals() and globals() are
updated when x and f are defined. Shouldn't they be considered and
global variable and functions only? Why does it make sense to set
locals() as well? Thanks.

It's "local" in the sense that it's in the current scope, so in a 
function it's local to that function, and in the main code of a module 
it's local to that module as well as being "global".


[snip]
--
https://mail.python.org/mailman/listinfo/python-list


acircle.getCenter() to (x,y) coordinates in Python

2017-12-23 Thread G Yu
My program has two circles: one stationary circle, drawn at a random location; 
and one moving circle, consistently drawn in the same place in the graphics 
window.

The moving circle moves towards the stationary one.  However, when the moving 
circle hits the stationary one (when the x-coordinates of the circles' centers 
are equal), I want the moving circle to stop moving and then disappear.

I tried the command acircle.getCenter() to determine when the centers are 
equal, but it doesn't work; I suspect because the centers are never truly 
equal, and only come within something like .01 pixels of each other.  So to 
account for the approximation, I used the math function "isclose":

move_moving_circle = True

while move_moving_circle:
moving_circle.move(P_to_R/P_to_E, E_to_R/P_to_E)
time.sleep(0.01)

if isclose(moving_circle.getCenter(), stationary_circle.getCenter(), 
rel_tol=1e-4, abs_tol=0.0):
move_moving_circle= False

else:
move_moving_circle = True


But this doesn't work.  Apparently isclose can't be applied to points - only 
floating-point decimals.


So now, I want to convert the output of "acircle.getCenter()" to Cartesian 
(x,y) coordinates for both circles.  Then I can use the two circle centers' 
x-coordinates in the if statement.

Currently, acircle.getCenter() outputs this:




I don't understand/can't use the format that the locations are printed in.

How do I convert the above format to "usable" Cartesian coordinates?  Or is 
there a simpler way to solve this problem?

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


Re: acircle.getCenter() to (x,y) coordinates in Python

2017-12-23 Thread MRAB

On 2017-12-23 19:44, G Yu wrote:

My program has two circles: one stationary circle, drawn at a random location; 
and one moving circle, consistently drawn in the same place in the graphics 
window.

The moving circle moves towards the stationary one.  However, when the moving 
circle hits the stationary one (when the x-coordinates of the circles' centers 
are equal), I want the moving circle to stop moving and then disappear.

I tried the command acircle.getCenter() to determine when the centers are equal, but it 
doesn't work; I suspect because the centers are never truly equal, and only come within 
something like .01 pixels of each other.  So to account for the approximation, I used 
the math function "isclose":

move_moving_circle = True

 while move_moving_circle:
 moving_circle.move(P_to_R/P_to_E, E_to_R/P_to_E)
 time.sleep(0.01)

 if isclose(moving_circle.getCenter(), stationary_circle.getCenter(), 
rel_tol=1e-4, abs_tol=0.0):
 move_moving_circle= False

 else:
 move_moving_circle = True


But this doesn't work.  Apparently isclose can't be applied to points - only 
floating-point decimals.


So now, I want to convert the output of "acircle.getCenter()" to Cartesian 
(x,y) coordinates for both circles.  Then I can use the two circle centers' x-coordinates 
in the if statement.

Currently, acircle.getCenter() outputs this:




I don't understand/can't use the format that the locations are printed in.

How do I convert the above format to "usable" Cartesian coordinates?  Or is 
there a simpler way to solve this problem?

You didn't say what graphics library you're using, but from a quick 
search on the internet I think the answer is to use the .getX and .getY 
methods of the Point object.
You could calculate the distance between the 2 points, which is sqrt((x1 
- x2) ** 2 + (y1 - y2) ** 2). You can speed it up a little by omitting 
the sqrt and just remember that you're working with the square of the 
distance.


Another point: why do they need to be so close to each other? 
Personally, I'd just say they collide when round(distance) < 1 or 
round(distance ** 2) < 1.

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


Re: acircle.getCenter() to (x,y) coordinates in Python

2017-12-23 Thread G Yu
I did try that.  The problem is that I already declared a point 
moving_object_center = (-555,-555), because that's the point I used as the 
center to draw the moving_object circle itself.  So the 
moving_object_center.getX() will return -555 no matter what I do.

That's why I need to calculate the center using some attribute of the circle, 
not the center point - because the circle moves, but the point that I declared 
as the initial center point will never change.

I'm not totally sure what you mean by "graphics library", but these are all the 
import statements I'm using at the beginning.

from graphics import *
import datetime
import random
from math import *
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: acircle.getCenter() to (x,y) coordinates in Python

2017-12-23 Thread MRAB

On 2017-12-23 21:30, G Yu wrote:

I did try that.  The problem is that I already declared a point 
moving_object_center = (-555,-555), because that's the point I used as the 
center to draw the moving_object circle itself.  So the 
moving_object_center.getX() will return -555 no matter what I do.


But your code has:

moving_circle.move(P_to_R/P_to_E, E_to_R/P_to_E)

so won't that move the circle and change what:

moving_circle.getCenter()

returns?


That's why I need to calculate the center using some attribute of the circle, 
not the center point - because the circle moves, but the point that I declared 
as the initial center point will never change.

The initial point won't change, but that's just where the circle was 
originally.


Are you sure that it doesn't change? Have you printed out 
moving_circle.getCenter().getX() and moving_circle.getCenter().getY() 
and seen that they aren't changing?



I'm not totally sure what you mean by "graphics library", but these are all the 
import statements I'm using at the beginning.

from graphics import *
import datetime
import random
from math import *

As far as I know, "graphics" isn't part of the standard CPython 
distribution from www.python.org. At least, I have CPython 3.6 for 
Windows, and "graphics" doesn't appear to be present.

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


Writing a chess-playing AI like Alphago in Python

2017-12-23 Thread Cai Gengyang
How many lines of code in Python would it take to create a Go-playing AI like 
AlphaGo ? Estimates ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: acircle.getCenter() to (x,y) coordinates in Python

2017-12-23 Thread G Yu
> But your code has:
> 
>  moving_circle.move(P_to_R/P_to_E, E_to_R/P_to_E)
> 
> so won't that move the circle and change what:
> 
>  moving_circle.getCenter()
> 
> returns?

Yes, moving the circle changes the value of moving_circle.getCenter(). The 
problem is interpreting the output. The command gives , and I don't know how to determine the x-coordinate of the 
center from that output. This is my problem. I can't translate the .getCenter() 
output to Cartesian coordinates.



> The initial point won't change, but that's just where the circle was 
> originally.

> Are you sure that it doesn't change? Have you printed out 
> moving_circle.getCenter().getX() and moving_circle.getCenter().getY() 
> and seen that they aren't changing?

Distinguish between the circle's center and the initial center point I 
declared. My program can output the former, but it's in a format that I don't 
understand: .

As for the initial center point (I'll call it moving_circle_*initial*_center 
instead), it won't change at all throughout the program execution.

I need to know the x- and y-coordinates of moving_circle.getCenter() at any 
point in time. I can't use the center of the circle *before* it started moving, 
because that value is static (in other words, 
moving_circle_initial_center.getX() and moving_circle_initial_center.getY() 
never change).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: acircle.getCenter() to (x,y) coordinates in Python

2017-12-23 Thread Gregory Ewing

G Yu wrote:

The command gives , and I don't know how to determine the x-coordinate of
the center from that output.


Try this in an interactive session:

   p = circle.getCenter()
   help(p)

This should give you a page of text showing all the attributes
and methods your point object has. Somewhere in there will almost
certainly be something that tells you the coordinates.

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


Re: acircle.getCenter() to (x,y) coordinates in Python

2017-12-23 Thread Irv Kalb

> On Dec 23, 2017, at 11:44 AM, G Yu  wrote:
> 
> My program has two circles: one stationary circle, drawn at a random 
> location; and one moving circle, consistently drawn in the same place in the 
> graphics window.
> 
> 
> 
> Currently, acircle.getCenter() outputs this:
> 
> 
> 
> 
> I don't understand/can't use the format that the locations are printed in.
> 
> How do I convert the above format to "usable" Cartesian coordinates?  Or is 
> there a simpler way to solve this problem?
> 
> Thanks!
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

I found this document that looks like it described the "graphics" module that 
you are using (it does describe the getCenter call that you showed):

  http://mcsp.wartburg.edu/zelle/python/graphics/graphics.pdf 


If this is the module, then Points are objects, and what you are seeing is the 
memory address of those points.  Section 3.1 of the document describes how you 
can call the getX() and getY() methods on any point to get the x and y values:
getX() Returns the x coordinate of a point. Example: xValue = aPoint.getX()

getY() Returns the y coordinate of a point. Example: yValue = aPoint.getY() 

Therefore, it sounds like you need to take the Point object that you have, and 
call the getX method and alto the getY method to get the coordinates you want.

Hope that helps,

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


Re: Writing a chess-playing AI like Alphago in Python

2017-12-23 Thread Steve D'Aprano
On Sun, 24 Dec 2017 12:20 pm, Cai Gengyang wrote:

> How many lines of code in Python would it take to create a Go-playing AI
> like AlphaGo ? Estimates ?

Somewhere between 1 and 1 billion.

How about you start by telling us:

- do you mean AlphaGo or AlphaGo Zero?

- how many lines of code AlphaGo [Zero] has;

- in what language or languages;

- is Python allowed to call out to libraries written in other 
  languages, e.g. machine learning and neural net libraries,
  or databases, or does it have to implement *everything*
  from scratch?


The Michi Go engine uses about 550 lines of Python:

https://github.com/pasky/michi

but I don't believe it does any machine learning.


See also:

https://github.com/rossumai/nochi

https://medium.com/rossum/building-our-own-version-of-alphago-zero-b918642bd2b5



-- 
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