Python bug report

2017-12-22 Thread Ranya
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.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with assignment. Python error or mine?

2017-12-22 Thread Tim Williams
On Thursday, December 21, 2017 at 12:18:11 PM UTC-5, MarkA wrote:
> On Thu, 21 Dec 2017 07:05:33 -0800, rafaeltfreire wrote:
> From docs.python.org:
> 
> 8.10. copy — Shallow and deep copy operations
> 
> Source code: Lib/copy.py
> 
> Assignment statements in Python do not copy objects, they create bindings 
> between a target and an object. For collections that are mutable or 
> contain mutable items, a copy is sometimes needed so one can change one 
> copy without changing the other. This module provides generic shallow and 
> deep copy operations (explained below)...
> 
> 
> > Dear community, I am having the following problem when I am assigning
> > the elements of a vector below a certain number to zero or any other
> > value.
> > I am creating a new variable but Python edits the root variable. Why?
> > 
> > import numpy as np
> > 
> > X=np.arange(1, 1, 1) #root variable x1=X x1[x1<1]=0
> > 
> > print(X)
> > Out[1]: array([ 0.,  0.,  0., ...,  0.,  0.,  0.])
> > 
> > Why? It is supposed to be the original value Thank you for your
> > time Rafael
> 
> 
> 
> -- 
> MarkA
> 
> We hang petty theives, and appoint the great theives to public office
>   -- Aesop

Shouldn't the OP just create a list for what he want's to do?

X = list(np.arange(1, 1, 1)) #root variable x1=X x1[x1<1]=0

Then I think his other statements would do what he expects, no?
-- 
https://mail.python.org/mailman/listinfo/python-list


Using the variable type annotation syntax as a placeholder in a nonlocal scope?

2017-12-22 Thread Kirill Balunov
Any suggestions? Thank you.

With kind regards, -gdg

On Dec 20, 2017 22:43, "Kirill Balunov"  wrote:

> I've asked the same question on StackOverflow, but it seems to me that it
> is opinion based and will be ignored. So I ask for advice here:
>
> Since PEP 526 -- Syntax for Variable Annotations
>   was approved, in Python 3.6+
> it is possible to provide type hint information in the form *x: int*,
> also the PEP says "However, annotating a local variable will cause the
> interpreter to always make it local to the scope and leaves the variable
> uninitialized". Therefore in Python 3.6+ it is syntactically legal to
> write:
>
> def outer():
> x: int
> def inner():
> nonlocal x
> x = 10
> inner()
> print(x)
>
> while the above snippet is semantically more equivalent to:
>
> def outer():
> #x
> def inner():
> nonlocal x
> x = 10
> inner()
> print(x)
>
> Which is obviously a *SyntaxError: no binding for nonlocal 'x' found`*,
> sorry for the pun. Also there is nothing said about this style in PEP 8 and
> Python 3.6 docs. So should I consider this as a bug, or an implementation
> detail (side effect), or a wart, or a feature?
>
> To clarify the purpose of the question - we can not come to a consensus
> and I would like to hear your opinion and possible pitfalls, if any, if we
> choose to use this form in our codebase.
>
> With kind regards, -gdg
>
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with assignment. Python error or mine?

2017-12-22 Thread Tim Williams
On Friday, December 22, 2017 at 8:41:29 AM UTC-5, Tim Williams wrote:
> On Thursday, December 21, 2017 at 12:18:11 PM UTC-5, MarkA wrote:
> > On Thu, 21 Dec 2017 07:05:33 -0800, rafaeltfreire wrote:
> > From docs.python.org:
> > 
> > 8.10. copy — Shallow and deep copy operations
> > 
> > Source code: Lib/copy.py
> > 
> > Assignment statements in Python do not copy objects, they create bindings 
> > between a target and an object. For collections that are mutable or 
> > contain mutable items, a copy is sometimes needed so one can change one 
> > copy without changing the other. This module provides generic shallow and 
> > deep copy operations (explained below)...
> > 
> > 
> > > Dear community, I am having the following problem when I am assigning
> > > the elements of a vector below a certain number to zero or any other
> > > value.
> > > I am creating a new variable but Python edits the root variable. Why?
> > > 
> > > import numpy as np
> > > 
> > > X=np.arange(1, 1, 1) #root variable x1=X x1[x1<1]=0
> > > 
> > > print(X)
> > > Out[1]: array([ 0.,  0.,  0., ...,  0.,  0.,  0.])
> > > 
> > > Why? It is supposed to be the original value Thank you for your
> > > time Rafael
> > 
> > 
> > 
> > -- 
> > MarkA
> > 
> > We hang petty theives, and appoint the great theives to public office
> >   -- Aesop
> 
> Shouldn't the OP just create a list for what he want's to do?
> 
> X = list(np.arange(1, 1, 1)) #root variable x1=X x1[x1<1]=0
> 
> Then I think his other statements would do what he expects, no?

Disregard what I just posted. I didn't think this through enough. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using the variable type annotation syntax as a placeholder in a nonlocal scope?

2017-12-22 Thread Terry Reedy

On 12/22/2017 8:53 AM, Kirill Balunov wrote:

On Dec 20, 2017 22:43, "Kirill Balunov"  wrote:



Since PEP 526 -- Syntax for Variable Annotations
  was approved, in Python 3.6+
it is possible to provide type hint information in the form *x: int*,
also the PEP says "However, annotating a local variable will cause the
interpreter to always make it local to the scope and leaves the variable
uninitialized".


It is unitialized only if you do not initialize it.


Therefore in Python 3.6+ it is syntactically legal to
write:

def outer():
 x: int
 def inner():
 nonlocal x
 x = 10
 inner()
 print(x)


Why would you write the above instead of

>>> def f():
x:int = 10
print(x)

>>> f()
10


while the above snippet is semantically more equivalent to:


More equivalent than what?


def outer():
 #x
 def inner():
 nonlocal x
 x = 10
 inner()
 print(x)

Which is obviously a *SyntaxError: no binding for nonlocal 'x' found`*,
sorry for the pun. Also there is nothing said about this style in PEP 8 and
Python 3.6 docs. So should I consider this as a bug, or an implementation
detail (side effect), or a wart, or a feature?


I don't understand the question.  Maybe people on SO did not either.

--
Terry Jan Reedy

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


Re: Why "flat is better than nested"?

2017-12-22 Thread andrewpate08
On Monday, October 25, 2010 at 11:07:42 AM UTC+1, kj wrote:
> In "The Zen of Python", one of the "maxims" is "flat is better than
> nested"?  Why?  Can anyone give me a concrete example that illustrates
> this point?
> 
> TIA!
> 
> ~kj
> 
> PS: My question should not be construed as a defense for "nested".
> I have no particular preference for either flat or nested; it all
> depends on the situation; I would have asked the same question if
> the maxim had been "nested is better than flat".

I think there is a point where flat stops working. One of the products I work 
on has a 40-50 field datastructure - it is hard to work with and find the 
appropriate fields in. So I would say structured is better than flat but simple 
is better than to structured.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why "flat is better than nested"?

2017-12-22 Thread Steve D'Aprano
On Sat, 23 Dec 2017 01:48 am, [email protected] wrote:

> On Monday, October 25, 2010 at 11:07:42 AM UTC+1, kj wrote:
>> In "The Zen of Python", one of the "maxims" is "flat is better than
>> nested"?  Why?  Can anyone give me a concrete example that illustrates
>> this point?
>> 
>> TIA!
>> 
>> ~kj
>> 
>> PS: My question should not be construed as a defense for "nested".
>> I have no particular preference for either flat or nested; it all
>> depends on the situation; I would have asked the same question if
>> the maxim had been "nested is better than flat".
> 
> I think there is a point where flat stops working. One of the products I
> work on has a 40-50 field datastructure - it is hard to work with and find
> the appropriate fields in. So I would say structured is better than flat but
> simple is better than to structured.


Do you realise you are responding to a message more than seven years old?

In any case, structured is not the opposite of flat. Nested is the opposite to
flat, and unstructured is the opposite of structured. The two concepts are
independent of each other: any data structure can be:

- flat and structured;
- flat and unstructured;
- nested and structured;
- nested and unstructured.

Data can even be semi-structured; for example, mp3 files have some structured
metadata (title, artist, track number, comment, etc), while data in the
comment field itself is unstructured (free-form) text.


Here is an example of iterating over a flat collection of numbers:

values = [1, 2, 3, 4, 5, 6, 7, 8]
for num in values:
print(num)


Here is the same, as a nested collection of numbers:

values = [1, [2, [3, [4, [5, [6, [7, [8, []
while values:
num, values = values
print(num)


In Python, the first is much more efficient than the second. It is also easier
to write, easier to read, and less likely for the programmer to mess up.

A list or a dict is flat; a binary tree is nested.

Structured and unstructured data can have two related but separate meanings.
One is to distinguish between data with or without a pre-defined
organization:

- structured data: XML, JSON, YAML, databases, etc;

- unstructured data: books, the body of emails, arbitrary web pages, etc.

Dealing with unstructured data in this sense often means coming up with some
sort of heuristic or "best guess" for picking out the useful information
(say, based on regexes) then writing a scraper to pull part the data source
looking for what you want.


The meaning you seem to be using seems to be:

- structured data has named fields (e.g. C struct, Pascal record, 
  object with named attributes, Python named tuple, CSV file with 
  descriptive column headers);

- unstructured data does not name the fields (e.g. a plain tuple,
  CSV file without column headers) and you have to infer the 
  meaning of each field from out-of-band knowledge (say, you read
  the documentation to find out that "column 7" is the score).


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


plot map wit box axes

2017-12-22 Thread jorge . conrado


Hi,

I use the PYTHON and IDL. In IDL I can plot a grid map like a this 
figure (mapa.png). Please, I would like know how can I plot my figure 
using PYTHON with the box around the figure. Like this that I plot using 
the IDL.


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


Re: co-ordianate transformation with astropy

2017-12-22 Thread mm0fmf

On 22/12/2017 21:36, 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?



How would you do it by hand?

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


Re: Python bug report

2017-12-22 Thread Peter Pearson
On Thu, 21 Dec 2017 23:54:17 +0100, 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.

What is clr?  Whatever it is, it doesn't have the AddReference
attribute that you seem to be expecting.

-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Where is ^ (symmetric_difference) documented in help()?

2017-12-22 Thread Peng Yu
Hi, I see the following two lines are the same. But I'd like to find
where ^ is documented via the help() function (I am not looking for
the document in html)? Does anybody know? Thanks.

s.symmetric_difference(t)
s ^ t

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


Re: Where is ^ (symmetric_difference) documented in help()?

2017-12-22 Thread Dan Sommers
On Fri, 22 Dec 2017 21:35:53 -0600, Peng Yu wrote:

> Hi, I see the following two lines are the same. But I'd like to find
> where ^ is documented via the help() function (I am not looking for
> the document in html)? Does anybody know? Thanks.
> 
> s.symmetric_difference(t)
> s ^ t

It's sort of documented in help(set):

 |  __xor__(self, value, /)
 |  Return self^value.

HTH,
Dan

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


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

2017-12-22 Thread Peng Yu
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.

$ cat  ./main.py
#!/usr/bin/env python
# vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8:

d = dict()

d['l1'] = set(locals().keys())
d['g1'] = set(globals().keys())

x = 10
def f():
  pass

d['l2'] = set(locals().keys())
d['g2'] = set(globals().keys())

print d['l2'] - d['l1']
print d['g2'] - d['g1']

import os.path
d['l3'] = set(locals().keys())
d['g3'] = set(globals().keys())

print d['l3'] - d['l2']
print d['g3'] - d['g2']

from os import path
d['l4'] = set(locals().keys())
d['g4'] = set(globals().keys())

print d['l4'] - d['l3']
print d['g4'] - d['g3']

$  ./main.py
set(['x', 'f'])
set(['x', 'f'])
set(['os'])
set(['os'])
set(['path'])
set(['path'])


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


Re: Where is ^ (symmetric_difference) documented in help()?

2017-12-22 Thread Peng Yu
Where is it documented that __xor__ and ^ is the same as
symmetric_difference? Thanks.

BTW, I am using to Python 2, your help message is different from mine.
Do you use Python 3?

On Fri, Dec 22, 2017 at 9:41 PM, Dan Sommers  wrote:
> On Fri, 22 Dec 2017 21:35:53 -0600, Peng Yu wrote:
>
>> Hi, I see the following two lines are the same. But I'd like to find
>> where ^ is documented via the help() function (I am not looking for
>> the document in html)? Does anybody know? Thanks.
>>
>> s.symmetric_difference(t)
>> s ^ t
>
> It's sort of documented in help(set):
>
>  |  __xor__(self, value, /)
>  |  Return self^value.
>
> HTH,
> Dan
>
> --
> https://mail.python.org/mailman/listinfo/python-list



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


Re: Where is ^ (symmetric_difference) documented in help()?

2017-12-22 Thread Steve D'Aprano
On Sat, 23 Dec 2017 02:35 pm, Peng Yu wrote:

> Hi, I see the following two lines are the same. But I'd like to find
> where ^ is documented via the help() function (I am not looking for
> the document in html)? Does anybody know? Thanks.
> 
> s.symmetric_difference(t)
> s ^ t


You can call:

help("^")

(notice you need to quote the operator) but it only talks about the bitwise
operators.


I've just raised bug report for this: 

https://bugs.python.org/issue32412




-- 
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: Where is ^ (symmetric_difference) documented in help()?

2017-12-22 Thread Steve D'Aprano
On Sat, 23 Dec 2017 03:50 pm, Peng Yu wrote:

> Where is it documented that __xor__ and ^ is the same as
> symmetric_difference? Thanks.

You read 

https://docs.python.org/2/library/stdtypes.html#set

to learn that ^ is the same as symmetric difference, and then read:

https://docs.python.org/2/reference/datamodel.html#emulating-numeric-types

to learn that you must override __xor__ to override the ^ operator.

It isn't really clear from the documentation that the set operator ^ is
implemented by __xor__ (and also __rxor__). Perhaps you can suggest a
documentation patch?



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


What is the meaning of @@?

2017-12-22 Thread Peng Yu
Hi, I only can find the doc for @. What does @@ mean in python?

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


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

2017-12-22 Thread Steve D'Aprano
On Sat, 23 Dec 2017 03:01 pm, 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.

There are three places you can call locals() and globals():

(1) Inside a function:

def function():
x = 1
L = locals()
G = globals()
print "id(L)=%d  id(G)=%d" % (id(L), id(G))


(2) Inside a class definition:

class Class(object):
x = 1
L = locals()
G = globals()
print "id(L)=%d  id(G)=%d" % (id(L), id(G))

(3) At the top level of a module (outside of any function or class):

# module
x = 1
L = locals()
G = globals()
print "id(L)=%d  id(G)=%d" % (id(L), id(G))



If you try this, you will find that in #3, the dicts L and G have the same ID
number. This means that at the module level, locals() and globals() are the
same dict. This is (barely!) documented here:

https://docs.python.org/2/reference/executionmodel.html#binding-of-names

where it tells us that "The variables of the module code block are local and
global" but not documented here:

https://docs.python.org/2/library/functions.html#locals

I've raised an issue for that too: https://bugs.python.org/issue32413


Also note that for technical reasons, assigning to locals() inside a function
is not guaranteed to always work. The locals() dict returned is *sometimes* a
copy of the actual local variables, and so assigning to it does not assign to
the actual local variable. This is a tricky area of Python, where different
versions and different implementations (such as CPython, IronPython, Jython,
PyPy) may behave differently.


By the way, using globals() and locals() is considered an "advanced" feature.
If you want to set a variable, use ordinary assignment:

# set a local
x = 1

# to set a global from inside a function or class, declare it global
global x
x = 1

rather than trying to play around with globals() and locals(). 



-- 
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: What is the meaning of @@?

2017-12-22 Thread Steve D'Aprano
On Sat, 23 Dec 2017 04:38 pm, Peng Yu wrote:

> Hi, I only can find the doc for @. What does @@ mean in python?

I don't think that @@ means anything yet.

There was a proposal to use @@ for matrix exponentiation in Numpy, as @ is
used for matrix multiplication, but that was left on hold to see whether it
is really needed or not.

Where did you find @@ in Python?


(By the way, @ for matrix multiplication only works in Python 3.5 or better.)

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



-- 
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: What is the meaning of @@?

2017-12-22 Thread Ian Kelly
@@ is a syntax error. Where did you encounter this?

On Fri, Dec 22, 2017 at 10:38 PM, Peng Yu  wrote:
> Hi, I only can find the doc for @. What does @@ mean in python?
>
> --
> Regards,
> Peng
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list