Re: Copying a compiled Python from one system to another

2016-10-01 Thread Paul Rubin
Steve D'Aprano  writes:
> Yes, this. You need gcc 4.8 or better to build CPython 3.6, and the most
> recent any of my systems support is 4.4.

Building gcc takes a while but it's reasonably simple.  Just start it
going and read a book for a while.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue28183] Clean up and speed up dict iteration

2016-10-01 Thread INADA Naoki

INADA Naoki added the comment:

dict_iter8.patch is based on dict_iter3.patch.  Added some comments and fixing 
indents.
No change about _PyDict_Next API.

--
Added file: http://bugs.python.org/file44921/dict_iter8.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21124] _struct module compilation error under Cygwin 1.7.17 on Python 3.4

2016-10-01 Thread Zachary Ware

Zachary Ware added the comment:

For future reference, having a patch attached to the issue does not mean the 
issue is fixed, and it should not be closed.

--
nosy: +zach.ware
stage:  -> resolved
type:  -> compile error
versions: +Python 3.7 -Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: inplace text filter - without writing file

2016-10-01 Thread Sayth Renshaw
On Sunday, 2 October 2016 16:19:14 UTC+11, Sayth Renshaw  wrote:
> On Sunday, 2 October 2016 12:14:43 UTC+11, MRAB  wrote:
> > On 2016-10-02 01:21, Sayth Renshaw wrote:
> > > Hi
> > >
> > > I have a fileobject which was fine however now I want to delete a line 
> > > from the file object before yielding.
> > >
> > > def return_files(file_list):
> > > for filename in sorted(file_list):
> > 
> > When joining paths together, it's better to use 'os.path.join'.
> > 
> > > with open(dir_path + filename) as fd:
> > >  for fileItem in fd:
> > >  yield fileItem
> > >
> > > Ned gave an answer over here http://stackoverflow.com/a/6985814/461887
> > >
> > > for i, line in enumerate(input_file):
> > > if i == 0 or not line.startswith('#'):
> > > output.write(line)
> > >
> > > which I would change because it is the first line and I want to rid 

[issue21124] _struct module compilation error under Cygwin 1.7.17 on Python 3.4

2016-10-01 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 3bde312ae936 by Zachary Ware in branch 'default':
Issue #21124: Fix building _struct on Cygwin.
https://hg.python.org/cpython/rev/3bde312ae936

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: inplace text filter - without writing file

2016-10-01 Thread Sayth Renshaw
On Sunday, 2 October 2016 12:14:43 UTC+11, MRAB  wrote:
> On 2016-10-02 01:21, Sayth Renshaw wrote:
> > Hi
> >
> > I have a fileobject which was fine however now I want to delete a line from 
> > the file object before yielding.
> >
> > def return_files(file_list):
> > for filename in sorted(file_list):
> 
> When joining paths together, it's better to use 'os.path.join'.
> 
> > with open(dir_path + filename) as fd:
> >  for fileItem in fd:
> >  yield fileItem
> >
> > Ned gave an answer over here http://stackoverflow.com/a/6985814/461887
> >
> > for i, line in enumerate(input_file):
> > if i == 0 or not line.startswith('#'):
> > output.write(line)
> >
> > which I would change because it is the first line and I want to rid 

[issue28328] statistics.geometric_mean has no tests. Defer to 3.7?

2016-10-01 Thread Steven D'Aprano

Steven D'Aprano added the comment:

> The newly-added statistics.geometric_mean function appears to have no 
> tests at all

That's weird and unfortunate. I certainly wrote tests, and I have a 
backup of them. I have no idea what happened.

Attached is a patch that adds the tests, but obviously I haven't been 
able to run this until I resolve my gcc issues and can build 3.6 again. 
(I did run this some weeks ago, and they passed *then*, but I cannot be 
sure they still pass now.) If somebody would like to test this for me, 
it would be appreciated.

--
keywords: +patch
Added file: http://bugs.python.org/file44920/geometric_mean_tests.patch

___
Python tracker 

___diff --git a/Lib/test/test_statistics.py b/Lib/test/test_statistics.py
--- a/Lib/test/test_statistics.py
+++ b/Lib/test/test_statistics.py
@@ -1694,6 +1694,124 @@
 self.assertEqual(statistics.mean([tiny]*n), tiny)
 
 
+class TestGeometricMean(NumericTestCase, AverageMixin, UnivariateTypeMixin):
+def setUp(self):
+self.func = statistics.geometric_mean
+
+def prepare_data(self):
+# Override mixin method.
+values = super().prepare_data()
+values.remove(0)
+return values
+
+def prepare_types_for_conservation_test(self):
+# Override mixin method.
+return (float, Decimal)
+
+def prepare_values_for_repeated_single_test(self):
+# Override mixin method.
+return (3.5, 17, 2.5e9, Decimal('4.9712'), Decimal('9236.40781'))
+
+def test_repeated_fractions(self):
+# This test has been split out from the test_repeated_single_value 
mixin.
+for x in (Fraction(61, 67), Fraction(935, 821)):
+expected = float(x)
+for n in (2, 14, 93):
+with self.subTest(x=x, n=n):
+self.assertEqual(self.func([x]*n), expected)
+
+def test_repeated_huge_single_value(self):
+# Test geometric mean with a single really big float repeated many 
times.
+x = 2.5e15
+for count in (2, 3, 10):
+self.assertEqual(self.func([x]*count), x)
+count = 20
+self.assertApproxEqual(self.func([x]*count), x, rel=1e-15)
+
+def test_zero(self):
+# Test that geometric mean returns zero if zero is an element.
+values = [1, 2, 3, 0, 5]
+self.assertEqual(self.func(values), 0.0)
+
+def test_negative_error(self):
+# Test that geometric mean raises when given a negative value.
+exc = statistics.StatisticsError
+for values in ([-1], [1, -2, 3]):
+with self.subTest(values=values):
+self.assertRaises(exc, self.func, values)
+
+def test_ints(self):
+# Test geometric mean with ints.
+data = [12, 21, 294]
+random.shuffle(data)
+self.assertEqual(self.func(data), 42.0)
+data = [90, 135, 270, 320]
+random.shuffle(data)
+self.assertEqual(self.func(data), 180.0)
+
+def test_floats_exact(self):
+# Test geometric mean with some carefully chosen floats.
+data = [1.0, 2.0, 6.125, 12.25]
+random.shuffle(data)
+self.assertEqual(self.func(data), 3.5)
+
+def test_singleton_lists(self):
+# Test that geometric mean([x]) returns x.
+for i in range(100):
+x = random.uniform(0.0, 1.0)
+self.assertEqual(self.func([x]), x)
+
+def test_decimals_exact(self):
+# Test geometric mean with some carefully chosen Decimals.
+D = Decimal
+data = [D("0.972"), D("8.748"), D("23.328")]
+random.shuffle(data)
+self.assertEqual(self.func(data), D("5.832"))
+
+def test_fractions(self):
+# Test geometric mean with Fractions.
+F = Fraction
+data = [F(1, 2), F(2, 3), F(3, 4), F(4, 5), F(5, 6), F(6, 7), F(7, 8)]
+random.shuffle(data)
+expected = 1/(8**(1/7))
+self.assertApproxEqual(self.func(data), expected, rel=1e-13)
+
+def test_inf(self):
+# Test geometric mean with infinity.
+INF = float('inf')
+values = [2.0, INF, 1.0]
+self.assertEqual(self.func(values), INF)
+
+def test_nan(self):
+# Test geometric mean with NANs.
+values = [2.0, float('nan'), 1.0]
+self.assertTrue(math.isnan(self.func(values)))
+
+def test_multiply_data_points(self):
+# Test multiplying every data point by a constant.
+c = 111
+data = [3.4, 4.5, 4.9, 6.7, 6.8, 7.2, 8.0, 8.1, 9.4]
+expected = self.func(data)*c
+result = self.func([x*c for x in data])
+self.assertApproxEqual(self.func(data), expected, rel=1e-13)
+
+def test_doubled_data(self):
+# Test doubling data from [a,b...z] to [a,a,b,b...z,z].
+data = [random.uniform(1, 500) for _ in range(1000)]
+

Re: unintuitive for-loop behavior

2016-10-01 Thread Chris Angelico
On Sun, Oct 2, 2016 at 3:19 PM, Steve D'Aprano
 wrote:
> In IronPython, you could have the following occur in a function locals, just
> as it could happen CPython for globals:
>
> - delete the name binding "x"
> - which triggers a dictionary resize
> - bind a value to x again
> - because the dictionary is resized, the new "slot" for x is in a
>   completely different position of the dictionary to the old one
>
> There is no user-visible difference between these two situations. Your code
> works the same way whether it is executed inside a function or at the
> global top level, whether functions use the CPython local variable
> optimization or not.

Hmm, interesting. I don't have IronPython here, but maybe you can tell
me what this does:

print(str)
str = "demo"
print(str)
del str
print(str)

and the same inside a function. In CPython, the presence of 'str =
"demo"' makes str function-local, ergo UnboundLocalError on the first
reference; but globals quietly shadow built-ins, so this will print
the class, demo, and the class again. If IronPython locals behave the
way CPython globals behave, that would most definitely be a
user-visible change to shadowing semantics.

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


Re: Copying a compiled Python from one system to another

2016-10-01 Thread Chris Angelico
On Sun, Oct 2, 2016 at 3:25 PM, Steve D'Aprano
 wrote:
> On Sun, 2 Oct 2016 01:58 pm, Chris Angelico wrote:
>
>> Hmm, I've possibly missed something here, which may indicate a
>> problem. Why can't your existing machines build? Is it because they
>> have too-old versions of tools, and if so, which?
>
> Yes, this. You need gcc 4.8 or better to build CPython 3.6, and the most
> recent any of my systems support is 4.4.

In itself not a problem, but you might find that libc is an
incompatibly different version, which would be a pain.

But, give it a try. Worst case, it fails with a linker error straight
away. (And you MAY be able to just copy in some libraries from the
other system.)

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


[issue28325] Remove MacOS 9-specific module macurl2path.py

2016-10-01 Thread Chi Hsuan Yen

Chi Hsuan Yen added the comment:

Thanks for landing all the changes :) It's definitely surprising to see those 
old CPython codes.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: unintuitive for-loop behavior

2016-10-01 Thread Steve D'Aprano
On Sun, 2 Oct 2016 11:44 am, Gregory Ewing wrote:

> Steve D'Aprano wrote:
>> When you say:
>> 
>> x = 0
>> x = 1
>> 
>> inside a function, and the interpreter does the name binding twice,
>> there's no way of telling whether it writes to the same cell each time or
>> not.
> 
> Yes, there is:
> 
> ...  x = 0
> ...  f1 = lambda: x
> ...  x = 1
> ...  f2 = lambda: x
> ...  print(f1(), f2())
> ...
>  >>> f()
> 1 1
> 
> This indicates that both assignments updated the same slot.
> Otherwise the result would have been "0 1".


No it doesn't mean that at all. The result you see is compatible with *both*
the "update existing slot" behaviour and "create a new slot" behavior. The
*easiest* way to prove that is to categorically delete the existing "slot"
and re-create it:

x = 0
f1 = lambda: x
del x
assert 'x' not in locals()
x = 1
f2 = lambda: x
print(f1(), f2())


which will still print exactly the same results. 

Objection: I predict that you're going to object that despite the `del x`
and the assertion, *if* this code is run inside a function, the "x slot"
actually does still exist. It's not "really" deleted, the interpreter just
makes sure that the high-level behaviour is the same as if it actually were
deleted.

Well yes, but that's exactly what I'm saying: that's not an objection, it
supports my argument! The way CPython handles local variables is an
implementation detail. The high-level semantics is *identical* between
CPython functions, where local variables live in a static array of "slots"
and re-binding always updates an existing slot, and IronPython, where they
don't. The only way you can tell them apart is by studying the
implementation.

In IronPython, you could have the following occur in a function locals, just
as it could happen CPython for globals:

- delete the name binding "x"
- which triggers a dictionary resize
- bind a value to x again
- because the dictionary is resized, the new "slot" for x is in a 
  completely different position of the dictionary to the old one

There is no user-visible difference between these two situations. Your code
works the same way whether it is executed inside a function or at the
global top level, whether functions use the CPython local variable
optimization or not.


> It's not currently possible to observe the other behaviour in
> Python, because the only way to create new bindings for local
> names is to enter a function.

Not at all. Delete a name, and the binding for that name is gone. Now assign
to that name again, and a new binding must be created, by definition, since
a moment ago it no longer existed.

x = 1
del x
assert 'x' not in locals()
x = 2


> The change to for-loop semantics 
> I'm talking about would introduce another way.

I have lost track of how this is supposed to change for-loop semantics.

I'm especially confused because you seem to be arguing that by using an
implementation which CPython already uses, for-loops would behave
differently. So either I'm not reading you right or you're not explaining
yourself well.



>> Certainly when you call a function, the local bindings need to be
>> created. Obviously they didn't exist prior to calling the function! I
>> didn't think that was the difference you were referring to, and I fail to
>> see how it could be relevant to the question of for-loop behaviour.
> 
> My proposed change is (mostly) equivalent to turning the
> loop body into a thunk and passing the loop variable in as
> a parameter.

A thunk is not really well-defined in Python, because it doesn't exist, and
therefore we don't know what properties it will have. But generally when
people talk about thunks, they mean something like a light-weight anonymous
function without any parameters:

https://en.wikipedia.org/wiki/Thunk


You say "passing the loop variable in as a parameter" -- this doesn't make
sense. Variables are not values in Python. You cannot pass in a
*variable* -- you can pass in a name (the string 'x') or the *value* bound
to the name, but there's no existing facility in Python to pass in a
variable. If there was, you could do the classic "pass by reference" test:

Write a *procedure* which takes as argument two variables 
and swaps their contents

but there's no facility to do something like that in Python. So its hard to
talk about your hypothetical change except in hand-wavy terms:

"Something magically and undefined happens, which somehow gives the result I
want."



> This is the way for-loops or their equivalent are actually
> implemented in Scheme, Ruby, Smalltalk and many other similar
> languages, which is why they don't have the same "gotcha".

Instead, they presumably have some other gotcha -- "why don't for loops work
the same as unrolled loops?", perhaps.

In Python, the most obvious gotcha would be that if for-loops introduced
their own scope, you would have to declare any other variables in the outer
scope nonlocal. So this would work fine as top-level code:

x = 1
for i in range(10):

Re: Copying a compiled Python from one system to another

2016-10-01 Thread Steve D'Aprano
On Sun, 2 Oct 2016 01:58 pm, Chris Angelico wrote:

> Hmm, I've possibly missed something here, which may indicate a
> problem. Why can't your existing machines build? Is it because they
> have too-old versions of tools, and if so, which?

Yes, this. You need gcc 4.8 or better to build CPython 3.6, and the most
recent any of my systems support is 4.4.




-- 
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: Copying a compiled Python from one system to another

2016-10-01 Thread Steve D'Aprano
On Sun, 2 Oct 2016 12:30 am, Zachary Ware wrote:

> On Oct 1, 2016 06:25, "Steve D'Aprano"  wrote:
>>
>> Long story short: I have no working systems capable of compiling the
> latest
>> Python 3.6, and no time to upgrade my usual machines to something which
>> will work.
> 
> Since you're working on a pure-Python module (statistics), I'd recommend
> updating to the latest changeset that will build, and work from there. I
> don't know of any changes that would make it impossible for you to update
> to the last working changeset, build, update to 3.6 tip, and develop and
> test your statistics changes without rebuilding.

That actually sounds like it might be workable.

Thanks for the suggestion. Now I just need to work out the latest changeset
that works...





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


[issue28326] multiprocessing.Process depends on sys.stdout being open

2016-10-01 Thread Tiago Antao

Tiago Antao added the comment:

I made a small patch for this. This is the first time I submit one, so please 
be careful with this...

--
keywords: +patch
nosy: +tiagoantao
Added file: http://bugs.python.org/file44919/mp.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: unintuitive for-loop behavior

2016-10-01 Thread Steve D'Aprano
On Sun, 2 Oct 2016 12:28 am, Jussi Piitulainen wrote:

> I'm not sure any more to what message this should be a followup, but
> here is a demonstration of two different semantics of the for-loop
> variable scope/update, this time with nested loops using the same loop
> variable name. The first function, tabulate, uses Python semantics ("t"
> for true, if you like); the second, fabulate, is a translation ("f" for
> false, if you like) that uses the magical semantics where the loop
> variable is not only local to the loop but also a different variable on
> each iteration. 

I'm sorry, I don't understand what you mean by "Python semantics" versus "a
translation". A translation of what? In what way is it "magical semantics"?
I see nothing magical in your code: it is Python code.

Of course, it is complex, complicated, convoluted, obfuscated, hard to
understand, non-idiomatic Python code, but there's nothing magical in it
(unless you count nonlocal as magic). And it does nothing that can't be
done more simply: just change the tabulate inner loop variable to a
different name.


def fabulate2(m, n):
# The simple, Pythonic, non-complicated way.
for i in range(m):
print(i, end = ': ')
c = 0
for j in range(n):
print(j, end = ', ' if j + 1 < n else ' : ')
c += 1
print(i, c)


Your version of tabulate and fabulate:
py> tabulate(3, 4)
0: 0, 1, 2, 3 : 3 4
1: 0, 1, 2, 3 : 3 4
2: 0, 1, 2, 3 : 3 4

py> fabulate(3, 4)
0: 0, 1, 2, 3 : 0 4
1: 0, 1, 2, 3 : 1 4
2: 0, 1, 2, 3 : 2 4

My simple version of fabulate:

py> fabulate2(3, 4)
0: 0, 1, 2, 3 : 0 4
1: 0, 1, 2, 3 : 1 4
2: 0, 1, 2, 3 : 2 4


> The latter property makes no difference in this 
> demonstration, but the former does; there's also a spurious counter that
> is not local to the nested loops, just to be sure that it works as
> expected (it does).
> 
> A summary of sorts: it's possible to demonstrate the scope difference in
> Python code, with no box in sight; boxes are irrelevant; the relevant
> issue is what function and when the loop variable is associated with,
> explicitly or implicitly.

I don't know what "scope difference" you think you are demonstrating.
tabulate() has a single scope, fabulate() has multiple scopes because it
has inner functions that take i as argument, making them local to the inner
functions. Um, yeah, of course they are different. They're different
because you've written them differently. What's your point?

As far as I can see, all you have demonstrated is that it is possible to
write obfuscated code in Python. But we already knew that.




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


[issue28322] chain.__setstate__ Type Confusion

2016-10-01 Thread Raymond Hettinger

Raymond Hettinger added the comment:

The patch looks reasonable.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28334] netrc does not work if $HOME is not set

2016-10-01 Thread Berker Peksag

Berker Peksag added the comment:

Thanks for the patch, Dimitri. I think this is a reasonable improvement. 
However, since we are changing the behavior of the netrc() class, I'm not sure 
this can be considered as a bug fix.

In any case, 3.3 and 3.4 are in security-fix-only mode so I'm going to remove 
them from the versions field.

We need two things from you to move this forward:

1. A test. It should go in Lib/test/test_netrc.py. You can use

   env = support.EnvironmentVarGuard()
   env.unset('HOME')

   to test the new behavior.

2. A CLA form. You can sign it online at 
https://www.python.org/psf/contrib/contrib-form/

--
nosy: +berker.peksag
stage:  -> patch review
versions:  -Python 3.3, Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: announcing fython

2016-10-01 Thread Raoul Fleckman
On 2016-10-02, nicolasessisbre...@gmail.com :
> **How does this compare to Python+Numpy? 
> **How much faster is Fython, and what are the restrictions on the
> **Python code? 
>
> Python+Numpy allows easy processing of vector, but there is a limit to
> how much user-defined logic can be used with Numpy.  For example,
> operating on three different arrays to do something like
>
>   if x[i]  > 0 :
>   temp = get_value( y[i] )
>
>   if temp > 0:
>   z[i] = another_operation( z[i] )
>
> may require three different Numpy calls.
> With Fython, the if statements and the loop around them is directly
>  compiled to machine code.

> Fython speed is the same as Fortran speed.
>
> In some applications, I get a speed-up of 100 compared to Cython, and
>  a speed-up of 10 compared to C.
>
> I'm not a Cython nor a C expert, and I know that with some good
> compiler flags, one may make the performance of these two languages
> similar two Fortran.  The advantage of Fython is that everything is
> tune out-of-box because of its connection to Fortran.
>
> There is no restriction on the Python code.
> Once a Fython program is avalaible, Python can throw any scalar or
>  Numpy array at it.
>
> **whether Fython is pass by reference (Fortran) or value 
> **and then there's the 'little' matter of one-based (Fortran) or
> **zero-based (python) arrays? 
>
> Fython is passed by reference, so that any modification made to a
>  variable in Fython is propagated back to Python.
>
> Fython follows Fortran syntax and is one-based by default.

> This doesn't give any interop problem with Python, because what
>  matters is to know the pointer to the first element of an array, and
>  Fython knows it.
>
> For the programmer convenience, like Fortran, Fython allows the choice
>  between one-based and zero-based indexing at array declaration.

Thank you!  it sounds very interesting indeed, particularly for those of
us with a substantial Fortran code base which needs to be updated.
Please keep us posted on your progress!

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


Re: inplace text filter - without writing file

2016-10-01 Thread Sayth Renshaw
Thank you
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue28222] test_distutils fails

2016-10-01 Thread Berker Peksag

Berker Peksag added the comment:

I can reproduce it with the following dependencies:

$ pip list
docutils (0.12)
pip (8.1.2)
setuptools (27.1.2)

The test was added in issue 23063. Since the purpose of the test was testing a 
bug in _check_rst_data(), skipping it if pygments is not available wouldn't be 
an ideal solution.

We probably need to do something like:

if pygments is not None:
self.assertEqual(len(msgs), 0)
else:
self.assertEqual(len(msgs), 1)
self.assertEqual(
str(msgs[0][1]),
'Cannot analyze code. Pygments package not found.'
)

--
nosy: +berker.peksag
versions: +Python 3.5, Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: announcing fython

2016-10-01 Thread Michael Torrie
On 10/01/2016 09:06 PM, Chris Angelico wrote:
> On Sun, Oct 2, 2016 at 1:58 PM,   wrote:
>> Fython speed is the same as Fortran speed.
>>
>> There is no restriction on the Python code.
>> Once a Fython program is avalaible, Python can throw any scalar or Numpy 
>> array at it.
>>
>> For the programmer convenience, like Fortran, Fython allows the choice 
>> between
>> one-based and zero-based indexing at array declaration.
> 
> This is where I'm a little confused. Is Fython a full-featured Python
> implementation that compiles to Fortran, or a thin wrapper around
> Fortran that uses Python syntax, or something in between?

>From the web page, it's appears to be just Fortran with a Python-ish
syntax, but with a special Python module ("import fython") to more
easily allow the use of Fortran or Fython constructs (compiled fortran
code) from within actual Python.  Seems to allow the blending of
Fortran, Python, and Numpy.  Sounds pretty useful.  A transpiler and
also a Python bridge.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue9850] obsolete macpath module dangerously broken and should be removed

2016-10-01 Thread Mariatta Wijaya

Changes by Mariatta Wijaya :


--
nosy: +Mariatta

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: announcing fython

2016-10-01 Thread Chris Angelico
On Sun, Oct 2, 2016 at 1:58 PM,   wrote:
> Fython speed is the same as Fortran speed.
>
> There is no restriction on the Python code.
> Once a Fython program is avalaible, Python can throw any scalar or Numpy 
> array at it.
>
> For the programmer convenience, like Fortran, Fython allows the choice between
> one-based and zero-based indexing at array declaration.

This is where I'm a little confused. Is Fython a full-featured Python
implementation that compiles to Fortran, or a thin wrapper around
Fortran that uses Python syntax, or something in between?

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


Re: Copying a compiled Python from one system to another

2016-10-01 Thread Chris Angelico
On Sun, Oct 2, 2016 at 1:51 PM, Steve D'Aprano
 wrote:
> On Sun, 2 Oct 2016 09:31 am, Paul Rubin wrote:
>
>> Steve D'Aprano  writes:
>>> However I do have access to another machine (actually a VM) which can
>>> compile Python 3.6. It's not practical for me to use it as a my main
>>> development machine, but as a temporary measure, I thought I could
>>> compile 3.6 on this VM, then copy the python binary to my usual
>>> desktop machine.
>>
>> How about installing the same OS on the VM that you're running on the
>> development machine?
>
> Because then I won't be able to build Python on the VM either, which
> completely misses the point. I already have three machines that cannot
> build Python. I don't need a fourth. I need one which *can* build Python.

Hmm, I've possibly missed something here, which may indicate a
problem. Why can't your existing machines build? Is it because they
have too-old versions of tools, and if so, which?

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


Re: announcing fython

2016-10-01 Thread nicolasessisbreton
**How does this compare to Python+Numpy? 
**How much faster is Fython, and what are the restrictions on the Python code? 

Python+Numpy allows easy processing of vector, but there is a limit to how much
user-defined logic can be used with Numpy.
For example, operating on three different arrays to do something like

if x[i]  > 0 :
temp = get_value( y[i] )

if temp > 0:
z[i] = another_operation( z[i] )

may require three different Numpy calls.
With Fython, the if statements and the loop around them is directly compiled to 
machine code.

Fython speed is the same as Fortran speed.
In some applications, I get a speed-up of 100 compared to Cython, and a 
speed-up of 10 compared to C.
I'm not a Cython nor a C expert, and I know that with some good compiler flags, 
one may make the performance of these two languages similar two Fortran.
The advantage of Fython is that everything is tune out-of-box because of its 
connection to Fortran.

There is no restriction on the Python code.
Once a Fython program is avalaible, Python can throw any scalar or Numpy array 
at it.

**whether Fython is pass by reference (Fortran) or value 
**and then there's the 'little' matter of one-based (Fortran) or zero-based 
(python) arrays? 

Fython is passed by reference, so that any modification made to a variable in 
Fython is propagated back to Python.

Fython follows Fortran syntax and is one-based by default.
This doesn't give any interop problem with Python, because what matters is to 
know the pointer to the first element of an array, and Fython knows it.

For the programmer convenience, like Fortran, Fython allows the choice between 
one-based and zero-based indexing at array declaration.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: announcing fython

2016-10-01 Thread Steve D'Aprano
On Sun, 2 Oct 2016 11:18 am, Raoul Fleckman wrote:

> Interested to hear the answers to those questions, and whether Fython is
> pass by reference (Fortran) or value (python, unless passing a list, for
> example); 

That's not how Python works. Ints and lists are passed exactly the same way,
neither by value nor by reference.

http://import-that.dreamwidth.org/1130.html



-- 
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: Copying a compiled Python from one system to another

2016-10-01 Thread Steve D'Aprano
On Sun, 2 Oct 2016 09:31 am, Paul Rubin wrote:

> Steve D'Aprano  writes:
>> However I do have access to another machine (actually a VM) which can
>> compile Python 3.6. It's not practical for me to use it as a my main
>> development machine, but as a temporary measure, I thought I could
>> compile 3.6 on this VM, then copy the python binary to my usual
>> desktop machine.
> 
> How about installing the same OS on the VM that you're running on the
> development machine?

Because then I won't be able to build Python on the VM either, which
completely misses the point. I already have three machines that cannot
build Python. I don't need a fourth. I need one which *can* build Python.



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


[issue9850] obsolete macpath module dangerously broken and should be removed

2016-10-01 Thread Berker Peksag

Changes by Berker Peksag :


--
keywords: +easy -needs review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28222] test_distutils fails

2016-10-01 Thread Mariatta Wijaya

Mariatta Wijaya added the comment:

Hmm.. the test works for me on master branch

$ ./python.exe -m test test_distutils
Run tests sequentially
0:00:00 [1/1] test_distutils
1 test OK.

Total duration: 4 sec
Tests result: SUCCESS

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Reading the Windows Location API

2016-10-01 Thread Glenn Linderman
I found some GeoLocation stuff on PyPi, but it seems to be focused on 
turning an IP address into a (rough) location rather than reading a GPS. 
Seems like if a GPS is attached, reading it would be the best way to 
obtain a more accurate location, falling back to approximations if there 
is no GPS.


But I'm not sure where to start with reading the Windows Location API.  
Anyone have some clues or sample code?

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


[issue9850] obsolete macpath module dangerously broken and should be removed

2016-10-01 Thread Ned Deily

Ned Deily added the comment:

It's a bit late in the 3.6 cycle to be removing macpath, but it's not too late 
to mark it in 3.6 as deprecated and to be removed in 3.7.  If someone wants to 
write two patches, one for 3.6 to add a deprecation warning to the code and to 
the docs, the other for 3.7 to actually remove all traces of macpath, that 
would be great!

--
assignee: ronaldoussoren -> 
type: enhancement -> 
versions: +Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28325] Remove MacOS 9-specific module macurl2path.py

2016-10-01 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 07c593845994 by Ned Deily in branch 'default':
Issue #28325: Remove vestigal MacOS 9 macurl2path module and its tests.
https://hg.python.org/cpython/rev/07c593845994

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28325] Remove MacOS 9-specific module macurl2path.py

2016-10-01 Thread Ned Deily

Ned Deily added the comment:

Thanks for the suggestion; I didn't even know that was still around.  Because 
it is a bit late in the game for 3.6 and to be extra cautious, I decided to 
remove it starting with 3.7.

--
resolution:  -> fixed
stage:  -> resolved
status: open -> closed
type: enhancement -> 
versions:  -Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28324] Clean up MacOS 9-specific description in the docstring of os.py

2016-10-01 Thread Ned Deily

Ned Deily added the comment:

Thanks for this patch, too!

--
keywords: +gsoc -patch
resolution:  -> fixed
stage:  -> resolved
status: open -> closed
type: enhancement -> 

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28323] Remove MacOS 9-specific codes from exit() and quit()

2016-10-01 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 2d8d9abb3bf8 by Ned Deily in branch '3.6':
Issue #28323: Remove vestigal MacOS 9 checks from exit() and quit().
https://hg.python.org/cpython/rev/2d8d9abb3bf8

New changeset 2c7034d59c7b by Ned Deily in branch 'default':
Issue #28323: Merge from 3.6
https://hg.python.org/cpython/rev/2c7034d59c7b

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28323] Remove MacOS 9-specific codes from exit() and quit()

2016-10-01 Thread Ned Deily

Ned Deily added the comment:

Thanks for the patch!

--
resolution:  -> fixed
stage:  -> resolved
status: open -> closed
type: enhancement -> 

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28324] Clean up MacOS 9-specific description in the docstring of os.py

2016-10-01 Thread Roundup Robot

Roundup Robot added the comment:

New changeset dbdcedf3583e by Ned Deily in branch '3.6':
Issue #28324: Remove vestigal MacOS 9 references in os.py docstring.
https://hg.python.org/cpython/rev/dbdcedf3583e

New changeset d55fd379b994 by Ned Deily in branch 'default':
Issue #28324: Merge from 3.6
https://hg.python.org/cpython/rev/d55fd379b994

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Byte code descriptions somewhere?

2016-10-01 Thread breamoreboy
On Saturday, October 1, 2016 at 11:57:17 PM UTC+1, Cem Karan wrote:
> Hi all, I've all of a sudden gotten interested in the CPython interpreter, 
> and started trying to understand how it ingests and runs byte code.  I found 
> Include/opcode.h in the python sources, and I found some basic documentation 
> on how to add in new opcodes online, but I haven't found the equivalent of an 
> assembly manual like you might for x86, etc.  Is there something similar to a 
> manual dedicated to python byte code?  Also, is there a manual for how the 
> interpreter expects the stack, etc. to be setup so that all interactions go 
> as expected (garbage collections works, exceptions work, etc.)?  Basically, I 
> want a manual similar to what Intel or AMD might put out for their chips so 
> that all executables behave nicely with one another.
> 
> Thanks,
> Cem Karan

Further to Ben Finney's answer this 
https://docs.python.org/devguide/compiler.html should help.

Kindest regards.

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


Merecurial and Python-2.7.x, Python-3.Y

2016-10-01 Thread Michael Felt
Finally, I got to where I understood what needed to be done to get both 
Mercurial built - and the the new SSL requirements met.


So, running:

# hg clone https://hg.python.org/cpython

works. What is the next step to getting Python-2.7 AND Python-3.7 so I 
can submit patches against both versions and/or other versions?


Is it going to be a command like in the developer guide (that references 
Python3.5)?


Does this create a new directory, or just undo a lot of things that was 
just cloned - or was 3.5 the development branch when the guide was last 
updated?


Will I need to clone (as above) several times - one for each version I 
want to test against - and then run a second command -- OR --


is there an hg clone command to get a specific version (If that is in 
the guide - my apologies, as I missed it.


Thanks for hints and patience!

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


Thonny 2.0 released (Python IDE for beginners)

2016-10-01 Thread Aivar Annamaa
 

Hi! 

Thonny is Python IDE for learning and teaching programming. It is
developed in University of Tartu, Estonia. 

It has an easy to use debugger which shows clearly how Python executes
your programs. Unlike most debuggers, it can even show the steps of
evaluating an expression, visually explain references, function calls,
exceptions etc. 

For more info and downloads see http://thonny.cs.ut.ee/ [1] 

best regards, 

Aivar Annamaa
University of Tartu
Institute of Computer Science 

 

http://thonny.cs.ut.ee;>Thonny 2.0 - Python IDE for
beginners (01-Oct-16) 
 

Links:
--
[1] http://thonny.cs.ut.ee/
-- 
https://mail.python.org/mailman/listinfo/python-list


Need help for the print() function with a better order

2016-10-01 Thread 380162267qq
I am trying to print a simple decision tree for my homework.
The answer must keep in this format:

Top 7,4,0.95
career gain = 100
1.Management 2, 3, 0.9709505944546686
2.Service 5, 1, 0.6500224216483541
location gain = 100
1.Oregon 4, 1, 0.7219280948873623
2.California 3, 3, 1.0
edu_level gain = 100
1.High School 5, 1, 0.6500224216483541
2.College 2, 3, 0.9709505944546686
years_exp gain = 100
1.Less than 3 3, 1, 0.8112781244591328
2.3 to 10 2, 1, 0.9182958340544896
3.More than 10 2, 2, 1.0

Here is my code:
features={'edu_level':['High School','College'],'career':
['Management','Service'],'years_exp':['Less than 3','3 to 10','More than 
10'],'location':['Oregon','California']}

print('Top 7,4,0.95')
for key in features:
print('{} gain = {}'.format(key,100))
attributes_list=features[key]
kargs={}
for i in range(len(attributes_list)):
kargs[key]=attributes_list[i]
low=table.count('Low',**kargs)
high=table.count('High',**kargs)
print('\t{}.{} {}, {}, 
{}'.format(i+1,attributes_list[i],low,high,entropy(low,high)))





I set all the gain as 100 now.But actually the gain must calculate with the 
data below.
For example, the career gain need the data of 'Management' and 'Service'.
I don't know how to do.
or Anyone can provide me a better logic?



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


Re: inplace text filter - without writing file

2016-10-01 Thread MRAB

On 2016-10-02 01:21, Sayth Renshaw wrote:

Hi

I have a fileobject which was fine however now I want to delete a line from the 
file object before yielding.

def return_files(file_list):
for filename in sorted(file_list):


When joining paths together, it's better to use 'os.path.join'.


with open(dir_path + filename) as fd:
 for fileItem in fd:
 yield fileItem

Ned gave an answer over here http://stackoverflow.com/a/6985814/461887

for i, line in enumerate(input_file):
if i == 0 or not line.startswith('#'):
output.write(line)

which I would change because it is the first line and I want to rid 

Re: Lawrence D'Oliveiro

2016-10-01 Thread Gregory Ewing

On Fri, 30 Sep 2016 23:29:41 -0700, Paul Rubin 
declaimed the following:


That's the weird Italian spam that the newsgroup has been getting for a
while.  I've been wondering for a while if anyone knows what the story
is, i.e. why it's on comp.lang.python but not on other newsgroups that
I've noticed.


The Spanish Inquisition is trying to get the Pope
impeached, or something?

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


Re: generator no iter - how do I call it from another function

2016-10-01 Thread Gregory Ewing

Sayth Renshaw wrote:

def dataAttr(roots):
"""Get the root object and iter items."""
with open("output/first2.csv", 'w', newline='') as csvf:
race_writer = csv.writer(csvf, delimiter=',')
for meet in roots.iter("meeting"):


The value of roots you're passing in here is a generator
object that yields root instances, not a root instance itself.
So it looks like you need another level of iteration:

   for root in roots:
  for meet in root.iter("meeting"):
 ...

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


[issue28328] statistics.geometric_mean has no tests. Defer to 3.7?

2016-10-01 Thread Ned Deily

Ned Deily added the comment:

I was hoping that the open issues could be resolved in time for b2 but that 
seems unlikely at this point.  So I have to agree that this feature should be 
deferred to 3.7.  Steven, can you make the necessary reverts on the 3.6 branch?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28088] Document Transport.set_protocol and get_protocol

2016-10-01 Thread Mariatta Wijaya

New submission from Mariatta Wijaya:

Added the documentation for set_protocol and get_protocol.

--
keywords: +patch
Added file: http://bugs.python.org/file44918/issue28088.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: unintuitive for-loop behavior

2016-10-01 Thread Gregory Ewing

Steve D'Aprano wrote:

When you say:

x = 0
x = 1

inside a function, and the interpreter does the name binding twice, there's
no way of telling whether it writes to the same cell each time or not.


Yes, there is:

...  x = 0
...  f1 = lambda: x
...  x = 1
...  f2 = lambda: x
...  print(f1(), f2())
...
>>> f()
1 1

This indicates that both assignments updated the same slot.
Otherwise the result would have been "0 1".

It's not currently possible to observe the other behaviour in
Python, because the only way to create new bindings for local
names is to enter a function. The change to for-loop semantics
I'm talking about would introduce another way.


Certainly when you call a function, the local bindings need to be created.
Obviously they didn't exist prior to calling the function! I didn't think
that was the difference you were referring to, and I fail to see how it
could be relevant to the question of for-loop behaviour.


My proposed change is (mostly) equivalent to turning the
loop body into a thunk and passing the loop variable in as
a parameter.

This is the way for-loops or their equivalent are actually
implemented in Scheme, Ruby, Smalltalk and many other similar
languages, which is why they don't have the same "gotcha".
(Incidentally, this is why some people describe Python's
behaviour here as "broken". They ask -- it works perfectly
well in these other languages, why is Python different?)

The trick with cells is a way to get the same effect in
CPython, without the overhead of an actual function call
on each iteration (and avoiding some of the other problems
that using a thunk would entail).

The cell trick isn't strictly necessary, though -- other
Python implementations could use a thunk if they had to.

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


Re: ConfigParser: use newline in INI file

2016-10-01 Thread Ned Batchelder
On Saturday, October 1, 2016 at 6:25:16 PM UTC-4, Thorsten Kampe wrote:
> * Ben Finney (Sun, 02 Oct 2016 07:12:46 +1100)
> > 
> > Thorsten Kampe  writes:
> > 
> > > ConfigParser escapes `\n` in ini values as `\\n`.
> 
> Indenting solves the problem. I'd rather keep it one line per value 
> but it solves the problem.

If you want to have \n mean a newline in your config file, you can 
do the conversion after you read the value:

>>> "a\\nb".decode("string-escape")
'a\nb'

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


Re: announcing fython

2016-10-01 Thread Chris Angelico
On Sun, Oct 2, 2016 at 11:18 AM, Raoul Fleckman
 wrote:
> Interested to hear the answers to those questions, and whether Fython is
> pass by reference (Fortran) or value (python, unless passing a list, for
> example); and then there's the 'little' matter of one-based (Fortran) or
> zero-based (python) arrays?

Python doesn't have two different pass-by-X conventions. Please read
and comprehend:

http://nedbatchelder.com/text/names1.html

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


Re: Byte code descriptions somewhere?

2016-10-01 Thread Ned Batchelder
On Saturday, October 1, 2016 at 7:48:09 PM UTC-4, Cem Karan wrote:
> Cool, thank you!  Quick experimentation suggests that I don't need to worry 
> about marking anything for garbage collection, correct?  The next question 
> is, how do I create a stream of byte codes that can be interpreted by CPython 
> directly?  I don't mean 'use the compile module', I mean writing my own byte 
> array with bytes that CPython can directly interpret.

In Python 2, you use new.code: 
https://docs.python.org/2/library/new.html#new.code  It takes a bytestring of 
byte codes as one of its
twelve (!) arguments.

Something that might help (indirectly) with understanding bytecode:
byterun (https://github.com/nedbat/byterun) is a pure-Python implementation
of a Python bytecode VM.

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


inplace text filter - without writing file

2016-10-01 Thread Sayth Renshaw
Hi

I have a fileobject which was fine however now I want to delete a line from the 
file object before yielding.

def return_files(file_list):
for filename in sorted(file_list):
with open(dir_path + filename) as fd:
 for fileItem in fd:
 yield fileItem

Ned gave an answer over here http://stackoverflow.com/a/6985814/461887

for i, line in enumerate(input_file):
if i == 0 or not line.startswith('#'):
output.write(line)

which I would change because it is the first line and I want to rid 

Re: announcing fython

2016-10-01 Thread Raoul Fleckman
On 2016-10-01, Chris Angelico  wrote:
> On Sat, Oct 1, 2016 at 11:41 PM,   wrote:
>> Fython permits to write numerical code with the same syntax then Python.
>> Under the hood, the code is transpiled to Fortran and run at top speed.
>
> How does this compare to Python+Numpy? How much faster is Fython, and
> what are the restrictions on the Python code?
>
> ChrisA

Interested to hear the answers to those questions, and whether Fython is
pass by reference (Fortran) or value (python, unless passing a list, for
example); and then there's the 'little' matter of one-based (Fortran) or
zero-based (python) arrays?

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


[issue28281] Remove year limits from calendar

2016-10-01 Thread Mark Gollahon

Mark Gollahon added the comment:

First time patch for CPython.  I followed instructions given by belopolsky and 
added tests.  Please critique.

--
keywords: +patch
nosy: +golly
Added file: http://bugs.python.org/file44917/calendar-no-year-limits.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Converting PyMember_Get usage to PyMember_GetOne - no docs?

2016-10-01 Thread Skip Montanaro
I'm trying to convert the python-sybase module C code from oldish Python 2
usage to work in Python 3. The code currently calls PyMember_Get(), which
is obsolete. In later versions of Python 2, PyMember_GetOne became the
official way to do things, the the former function was still available. In
Python 3, PyMember_Get() is gone.

This is all well and good, but I can't find documentation for either
function, or seemingly examples of code which converted from one to the
other. Any pointers?

Thx,

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


[issue28294] HTTPServer server.py assumes sys.stderr != None

2016-10-01 Thread R. David Murray

R. David Murray added the comment:

OK, lets close this won't fix, then.  Especially since aiohttp does use logging 
already

Sorry, Mariatta.  Thanks for the patch, but we aren't going to use it.

--
resolution:  -> wont fix
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Byte code descriptions somewhere?

2016-10-01 Thread Chris Angelico
On Sun, Oct 2, 2016 at 10:47 AM, Cem Karan  wrote:
> Cool, thank you!  Quick experimentation suggests that I don't need to worry 
> about marking anything for garbage collection, correct?  The next question 
> is, how do I create a stream of byte codes that can be interpreted by CPython 
> directly?  I don't mean 'use the compile module', I mean writing my own byte 
> array with bytes that CPython can directly interpret.
>

"Marking for garbage collection" in CPython is done by refcounts; the
bytecode is at a higher level than that.

>>> dis.dis("x = y*2")
  1   0 LOAD_NAME0 (y)
  3 LOAD_CONST   0 (2)
  6 BINARY_MULTIPLY
  7 STORE_NAME   1 (x)
 10 LOAD_CONST   1 (None)
 13 RETURN_VALUE

A LOAD operation will increase the refcount (a ref is on the stack),
BINARY_MULTIPLY dereferences the multiplicands and adds a ref to the
product, STORE will deref whatever previously was stored, etc.

To execute your own code, look at types.FunctionType and
types.CodeType, particularly the latter's 'codestring' argument
(stored as the co_code attribute). Be careful: you can easily crash
CPython if you mess this stuff up :)

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


Re: Byte code descriptions somewhere?

2016-10-01 Thread Paul Rubin
Cem Karan  writes:
> how do I create a stream of byte codes that can be interpreted by
> CPython directly?

Basically, study the already existing code and do something similar.
The CPython bytecode isn't standardized like JVM bytecode.  It's
designed for the interpreter's convenience, not officially documented,
and (somewhat) subject to change between versions.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Byte code descriptions somewhere?

2016-10-01 Thread Cem Karan
Cool, thank you!  Quick experimentation suggests that I don't need to worry 
about marking anything for garbage collection, correct?  The next question is, 
how do I create a stream of byte codes that can be interpreted by CPython 
directly?  I don't mean 'use the compile module', I mean writing my own byte 
array with bytes that CPython can directly interpret.

Thanks,
Cem Karan


On Oct 1, 2016, at 7:02 PM, Ben Finney  wrote:

> Cem Karan  writes:
> 
>> Hi all, I've all of a sudden gotten interested in the CPython
>> interpreter, and started trying to understand how it ingests and runs
>> byte code.
> 
> That sounds like fun!
> 
>> Is there something similar to a manual dedicated to python byte code?
> 
> The Python documentation for the ‘dis’ module shows not only how to use
> that module for dis-assembly of Python byte code, but also a reference
> for the byte code.
> 
>32.12. dis — Disassembler for Python bytecode
> 
>
> 
> -- 
> \ “Skepticism is the highest duty and blind faith the one |
>  `\   unpardonable sin.” —Thomas Henry Huxley, _Essays on |
> _o__)   Controversial Questions_, 1889 |
> Ben Finney
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: Byte code descriptions somewhere?

2016-10-01 Thread Ben Finney
Cem Karan  writes:

> Hi all, I've all of a sudden gotten interested in the CPython
> interpreter, and started trying to understand how it ingests and runs
> byte code.

That sounds like fun!

> Is there something similar to a manual dedicated to python byte code?

The Python documentation for the ‘dis’ module shows not only how to use
that module for dis-assembly of Python byte code, but also a reference
for the byte code.

32.12. dis — Disassembler for Python bytecode



-- 
 \ “Skepticism is the highest duty and blind faith the one |
  `\   unpardonable sin.” —Thomas Henry Huxley, _Essays on |
_o__)   Controversial Questions_, 1889 |
Ben Finney

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


Byte code descriptions somewhere?

2016-10-01 Thread Cem Karan
Hi all, I've all of a sudden gotten interested in the CPython interpreter, and 
started trying to understand how it ingests and runs byte code.  I found 
Include/opcode.h in the python sources, and I found some basic documentation on 
how to add in new opcodes online, but I haven't found the equivalent of an 
assembly manual like you might for x86, etc.  Is there something similar to a 
manual dedicated to python byte code?  Also, is there a manual for how the 
interpreter expects the stack, etc. to be setup so that all interactions go as 
expected (garbage collections works, exceptions work, etc.)?  Basically, I want 
a manual similar to what Intel or AMD might put out for their chips so that all 
executables behave nicely with one another.

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


[issue28326] multiprocessing.Process depends on sys.stdout being open

2016-10-01 Thread James Lu

Changes by James Lu :


--
nosy: +James Lu

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Copying a compiled Python from one system to another

2016-10-01 Thread Paul Rubin
Steve D'Aprano  writes:
> However I do have access to another machine (actually a VM) which can
> compile Python 3.6. It's not practical for me to use it as a my main
> development machine, but as a temporary measure, I thought I could
> compile 3.6 on this VM, then copy the python binary to my usual
> desktop machine.

How about installing the same OS on the VM that you're running on the
development machine?  

You can get powerful hourly VM's (x86) and dedicated servers (x86 and
ARM) really cheap at Scaleway.com.  I've used them for a while and they
work well.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: RASTER analysis(slope)

2016-10-01 Thread Sayth Renshaw
On Sunday, 2 October 2016 04:52:13 UTC+11, Xristos Xristoou  wrote:
> hello team
> 
> i want to calculate slope and aspect from some RASTER 
> IMAGE(.grid,tiff,geotiff)
> who is the better method to can i do this ?
> with numpy and scipy or with some package?
> 
> 
> thnx you team

I don't know much about the topic however pyDem seems like the appropriate 
library to use.

https://pypi.python.org/pypi/pyDEM/0.1.1

Here is a standford article on it
https://pangea.stanford.edu/~samuelj/musings/dems-in-python-pt-3-slope-and-hillshades-.html

and a pdf from scipy conference.

https://conference.scipy.org/proceedings/scipy2015/pdfs/mattheus_ueckermann.pdf

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


Re: ConfigParser: use newline in INI file

2016-10-01 Thread Thorsten Kampe
* Ben Finney (Sun, 02 Oct 2016 07:12:46 +1100)
> 
> Thorsten Kampe  writes:
> 
> > ConfigParser escapes `\n` in ini values as `\\n`.

Indenting solves the problem. I'd rather keep it one line per value 
but it solves the problem.

Thorsten

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


Re: Copying a compiled Python from one system to another

2016-10-01 Thread Chris Angelico
On Sat, Oct 1, 2016 at 11:03 PM, Steve D'Aprano
 wrote:
>> Are both Linuxes of broadly similar vintage?
>
> That depends on what you mean by "broadly similar". As far as I am
> concerned, a five year difference is not very much, and is broadly
> similar -- it's not like I'm using Linux from 1991. But the whole point is
> that I need something with gcc 4.8 (maybe 4.7 will do, not sure) but
> certainly not 4.4 which is the most recent I can get on my current systems.

It's a rubbery term, but basically take the year of release of the
distro versions you're using, push 'em forward if they're
bleeding-edge distros or back if they're uber-stable, and try to guess
the age of the libraries they're running. Or check by looking at some
nice over-arching version number like Linux kernel; if they use
similar versions of Linux and libc, they probably have roughly similar
versions of a lot of other libraries, too.

The more similar the library versions, the less issues you'll have.

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


Re: announcing fython

2016-10-01 Thread Chris Angelico
On Sat, Oct 1, 2016 at 11:41 PM,   wrote:
> Fython permits to write numerical code with the same syntax then Python.
> Under the hood, the code is transpiled to Fortran and run at top speed.

How does this compare to Python+Numpy? How much faster is Fython, and
what are the restrictions on the Python code?

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


Re: ConfigParser: use newline in INI file

2016-10-01 Thread Thorsten Kampe
* Terry Reedy (Sat, 1 Oct 2016 15:44:39 -0400)
> 
> On 10/1/2016 10:56 AM, Thorsten Kampe wrote:
> 
> > ConfigParser escapes `\n` in ini values as `\\n`. Is there a way to
> > signal to ConfigParser that there is a line break?
> 
> Without an example or two, I don't really understand the question enough 
> to answer.

>>> !cat INI.ini
[Asciidoc]
_test_stdout = \nHello, World!\n

>>> import configparser

>>> config = configparser.ConfigParser()

>>> config.read('INI.ini')
['INI.ini']

>>> config['Asciidoc']['_test_stdout']
'\\nHello, World!\\n'

...as you can see, ConfigParser escaped the backslash by doubling it. 
Which is fine in most cases - except when I want to have something 
indicating an newline.

Thorsten

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


[issue28088] Document Transport.set_protocol and get_protocol

2016-10-01 Thread Mariatta Wijaya

Changes by Mariatta Wijaya :


--
nosy: +Mariatta

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28089] Document TCP_NODELAY by default

2016-10-01 Thread Mariatta Wijaya

Changes by Mariatta Wijaya :


--
nosy: +Mariatta

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13756] Python3.2.2 make fail on cygwin

2016-10-01 Thread Zachary Ware

Zachary Ware added the comment:

Fixed on 3.7, we can evaluate backporting later.  With this committed, a build 
on Cygwin can succeed if you configure with --without-threads.

Thanks for the patch!

--
nosy: +zach.ware
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13756] Python3.2.2 make fail on cygwin

2016-10-01 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 5b4c21436036 by Zachary Ware in branch 'default':
Issue #13756: Fix building extensions modules on Cygwin
https://hg.python.org/cpython/rev/5b4c21436036

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28335] Exception reporting in `logging.config`

2016-10-01 Thread Mariatta Wijaya

Changes by Mariatta Wijaya :


--
nosy: +Mariatta

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: unintuitive for-loop behavior

2016-10-01 Thread Terry Reedy

On 10/1/2016 8:24 AM, Rustom Mody wrote:


Yeah by comprehension-variable I mean the one that sits left of the
‘in’ inside the conprehension.


In other words, a 'loop variable within a comprehension'.  Keep in mind 
that there may be multiple targets for the implicit (hidden) assignment, 
so there may be multiple loop (comprehension) variables even without 
nested loops.


--
Terry Jan Reedy


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


Re: ConfigParser: use newline in INI file

2016-10-01 Thread Ben Finney
Thorsten Kampe  writes:

> ConfigParser escapes `\n` in ini values as `\\n`.

How do you demonstrate that?

Here is an example text of a config file::

>>> import io
>>> import textwrap

>>> config_text = textwrap.dedent(r"""
... [foo]
... wibble = Lorem\nipsum.
... """)
>>> print(config_text)

[foo]
wibble = Lorem\nipsum.

So that text has the characters “\n” in it. (Note that I had to use the
‘r’ prefix on the string literal, in order to turn off the special
meaning of “\” and get that character literally.)

When I use a ConfigParser it reads “\n” and reproduces exactly those
characters::

>>> import configparser

>>> config_file = io.StringIO(config_text)
>>> config = configparser.ConfigParser()
>>> config.read_file(config_file)
>>> print(config['foo']['wibble'])
Lorem\nipsum.

So you see that the “\n” characters are preserved exactly by the
ConfigParser.

> Is there a way to signal to ConfigParser that there is a line break?

Yes, you use a line break. See the ‘configparser’ module documentation:

Values can also span multiple lines, as long as they are indented
deeper than the first line of the value. Depending on the parser’s
mode, blank lines may be treated as parts of multiline values or
ignored.




Thus::

>>> config_text = textwrap.dedent(r"""
... [foo]
... wibble = Lorem
... ipsum.
... """)
>>> print(config_text)

[foo]
wibble = Lorem
ipsum.

>>> config_file = io.StringIO(config_text)
>>> config = configparser.ConfigParser()
>>> config.read_file(config_file)
>>> print(config['foo']['wibble'])
Lorem
ipsum.

-- 
 \  “Only the shallow know themselves.” —Oscar Wilde, _Phrases and |
  `\  Philosophies for the Use of the Young_, 1894 |
_o__)  |
Ben Finney

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


Re: rocket simulation game with just using tkinter

2016-10-01 Thread Irmen de Jong
On 1-10-2016 15:44, Christian Gollwitzer wrote:
> Am 01.10.16 um 00:59 schrieb Irmen de Jong:
>> Hi,
>>
>> I've made a very simple rocket simulation game, inspired by the recent 
>> success of SpaceX
> 
>> You can get the code here if you want to give it a try:
>> https://github.com/irmen/rocketsimulator
> 
> Nice! I'll have to rebind the keys before I can successfully play this, 
> though. My []
> "keys" are in fact combinations of Alt+5 and Alt+6 on a German Macbook 
> keyboard (on a
> German PC, it is AltGr+8, AltGr+9). Why not using the arrow keys? These 
> should be pretty
> universal

Oh, I'm sorry about that, my little knowledge of non-US keyboard layouts shows.
Arrow keys could be an option.   For my education what are the 2 keys to the 
right of
the P then on your keyboard?

Rebinding the keys should be easy though just change them in the keypress and 
keyrelease
methods.

Irmen

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


[issue28336] Slicing (operation) is not symmetrical with respect to suffixes and prefixes

2016-10-01 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

The default value of the lower bound index is 0, but the default value of the 
upper bound index is the length of the sequence. s[:a] is the same as s[0:a], 
but s[a:] is the same as s[a:len(s)].

If make s[a:0] meaning the same as s[a:len(s)], i.e. return a subsequence from 
index a to the end, while s[0:a] means the same as s[:a], i.e. returns a 
subsequence from the begin to index a, what should mean s[0:0]? There is a 
contradiction.

This change would break existing code.

--
nosy: +serhiy.storchaka
resolution:  -> rejected
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: ConfigParser: use newline in INI file

2016-10-01 Thread Terry Reedy

On 10/1/2016 10:56 AM, Thorsten Kampe wrote:


ConfigParser escapes `\n` in ini values as `\\n`. Is there a way to
signal to ConfigParser that there is a line break?


Without an example or two, I don't really understand the question enough 
to answer.


--
Terry Jan Reedy

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


[issue28332] silent truncations in socket.htons and socket.ntohs

2016-10-01 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Looks reasonable. ntohl() and htonl() already raise an exception if the 
argument exceeds 32 bit. Added comments on Rietveld.

--
nosy: +serhiy.storchaka
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28336] Slicing (operation) is not symmetrical with respect to suffixes and prefixes

2016-10-01 Thread Juan Carlos Pujol Mainegra

New submission from Juan Carlos Pujol Mainegra:

Let s be a string or other array-like object, a, b > 0 integers, s[0:b] returns 
a b-long prefix to s, the same as s[:b], but s[-a:0] returns empty (for len(s) 
> 0 and a > 1), while it should return the same as s[-a:], an a-long suffix (a 
> 0).

A syntax asymmetry like this shall not be imposed to those using non-literal 
slicing indexes, as it would be necessarily to introduce a control condition to 
test whether the upper bound index is a non-negative quantity, assuming the 
lower bound index is negative. Furthermore, it breaks the whole negative 
slicing idea, being that (I consider) index i always be treated as i mod 
len(s), so that constructions like s[-a:b] (for a, b > 0 or a, b < 0) could 
return s[-a:] + s[:b].

--
components: Interpreter Core
messages: 277829
nosy: jksware
priority: normal
severity: normal
status: open
title: Slicing (operation) is not symmetrical with respect to suffixes and 
prefixes
type: enhancement
versions: Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28273] Make os.waitpid() option parameter optional.

2016-10-01 Thread Jaysinh shukla

Changes by Jaysinh shukla :


Added file: 
http://bugs.python.org/file44916/os_waitpid_updated_codebase_2_jaysinh.diff

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28273] Make os.waitpid() option parameter optional.

2016-10-01 Thread Jaysinh shukla

Changes by Jaysinh shukla :


Removed file: 
http://bugs.python.org/file44915/os_waitpid_updated_codebase_jaysinh.diff

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28335] Exception reporting in `logging.config`

2016-10-01 Thread Ram Rachum

Ram Rachum added the comment:

I now see similar raises that could use a `from` in other places in this  
module, so I'd suggest going over the module and putting `from`s all over the 
place.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28273] Make os.waitpid() option parameter optional.

2016-10-01 Thread Jaysinh shukla

Jaysinh shukla added the comment:

Removing the `options` default argument from all the call to os.waitpid.

Note: This patch is based on [this 
patch](http://bugs.python.org/file44822/os_waitpid-optional_options.diff) 
submitted by StyXman.

--
nosy: +jaysinh.shukla
Added file: 
http://bugs.python.org/file44915/os_waitpid_updated_codebase_jaysinh.diff

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28335] Exception reporting in `logging.config`

2016-10-01 Thread Ram Rachum

New submission from Ram Rachum:

In `logging.config.DictConfigurator.configure`, there are exceptions that are 
caught and then replaced with `ValueError` exceptions. I think you should use 
the `raise x from y` syntax so that the original tracebacks will be preserved. 
(I'm debugging such an exception now and it's quite frustrating that I'm not 
seeing the full traceback of the original exception.)

--
components: Library (Lib)
messages: 277826
nosy: cool-RR, vinay.sajip
priority: normal
severity: normal
status: open
title: Exception reporting in `logging.config`
type: enhancement
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22392] Clarify documentation of __getinitargs__

2016-10-01 Thread Mariatta Wijaya

Changes by Mariatta Wijaya :


--
nosy: +Mariatta

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: unintuitive for-loop behavior

2016-10-01 Thread Steve D'Aprano
On Sun, 2 Oct 2016 03:57 am, Rustom Mody wrote:

> Hoo boy1
> Thats some tour de force and makes my head spin

I certainly agree with the second part of your sentence.


> Point can be made more simply with map
> ie if we *define*
> [exp for cv in l]
> as
> map(lambda cv: exp, l)
> 
> the problem vanishes

> 
> Demo:
> 
> First a helper function for demoing:
> 
> def pam(fl,x):
> return map(lambda f: f(x), fl)
> # pam is the complement to map; map runs one fnc on a list of args
> # pam runs a list of funcs on one arg
> 
> Trying to make a list of functions that add one, two and three to their
> arguments
> 
> fl = [lambda x: x + cv for cv in [1,2,3]]
> 
> Broken because of python's wrong LC semantics:
 pam(fl, 3)
> [6, 6, 6]

Its not *broken*, its doing *exactly what you told it to do*. You said,
define a function that takes a single argument x, and return x + cv. Then
you delayed evaluating it until cv = 3, and passed the argument 3, so of
course it returns 6. That's exactly what you told it to calculate.

You seem to have the concept that lambda should be magical, and just
miraculously know how far back in time to look for the value of cv. And
then when it doesn't, you're angry that Python is "broken". But why should
it be magical? cv is just an ordinary variable, and like all variables,
looking it up returns the value it has at the time you do the look-up, not
some time in the past. Let's unroll the loop:

fl = []
cv = 1
def f(x): return x + cv
fl.append(f)
cv = 2
def f(x): return x + cv
fl.append(f)
cv = 3
def f(x): return x + cv
fl.append(f)

pam(fl, 3)

Are you still surprised that it returns [6, 6, 6]?




> Transform the LC into a map with the rule above:
> fl_good = map((lambda cv :lambda x: x+cv), [1,2,3])


This is equivalent to something completely different, using a closure over
cv, so of course it works:

def factory(cv):
def inner(x):
return x + cv
return inner

fl_good = []
fl_good.append(factory(1))
fl_good.append(factory(2))
fl_good.append(factory(3))


Each time you call factory(), you get a new scope, with its own independent
variable cv. The inner function captures that environment (a closure),
which includes that local variable cv. Each invocation of factory leads to
an inner function that sees a different local variable which is independent
of the others but happens to have the same name. Instead of three functions
all looking up a single cv variable, you have three functions looking up
three different cv variables.

This is essentially why closures exist.


> Which is not very far from the standard workaround for this gotcha:
 fl_workaround = [lambda x, cv=cv: x+cv for cv in [1,2,3]]
 pam(fl_workaround, 3)
> [4, 5, 6]
 
> 
> Maybe we could say the workaround is the map definition uncurried
> And then re-comprehension-ified

If your students think in terms of map, then fine, but I think it would
confuse more people than it would help. Your mileage may vary.

There are certainly a number of ways to get the desired behaviour. If you
prefer to work with map, go right ahead.




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


[issue26617] Assertion failed in gc with __del__ and weakref

2016-10-01 Thread Guido van Rossum

Guido van Rossum added the comment:

Ben Bangert reported to me that this crash caused instabilities in an app using 
asyncio (https://github.com/home-assistant/home-assistant/issues/3453). This 
hack made his crashes go away:
https://github.com/home-assistant/home-assistant/commit/922dbba8814b81b69471dc4f1bf5c5a3b2bfe4ed

What are the chances of getting the crash fixed in 3.5.3 and 3.6b2?

--
nosy: +gvanrossum

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



RASTER analysis(slope)

2016-10-01 Thread Xristos Xristoou
hello team

i want to calculate slope and aspect from some RASTER IMAGE(.grid,tiff,geotiff)
who is the better method to can i do this ?
with numpy and scipy or with some package?


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


[issue28326] multiprocessing.Process depends on sys.stdout being open

2016-10-01 Thread Ned Deily

Changes by Ned Deily :


--
nosy: +davin

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28331] "CPython implementation detail:" is removed when contents is translated

2016-10-01 Thread Ned Deily

Changes by Ned Deily :


--
nosy: +georg.brandl

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: unintuitive for-loop behavior

2016-10-01 Thread Rustom Mody
On Saturday, October 1, 2016 at 7:02:58 PM UTC+5:30, Jussi Piitulainen wrote:
> Rustom Mody writes:
> 
> > And then define comprehensions not as now done in terms of for loops
> > that mutatingly extend the list being built up but as recursive
> > functions that get (re)called for every new value of the comprehension
> > variable passed and therefore fresh-bound as parameter
> 
> You'd get the magical semantics for comprehensions from the current
> definition of comprehension semantics in terms of the loop, if the loop
> semantics was magical. Let me demonstrate. (The b-word is unfortunately
> not available, so I substitute "magical" instead.)
> 
> # delayd = [ lambda : c for c in "abracadabra" ]
> # is roughly/almost equal to the following.
> 
> delayd = []
> for c in "abracadabra":
> delayd.append(lambda : c)
> 
> print('Python:', ''.join(f() for f in delayd))
> 
> # But that for-loop could have been roughly equal to the following,
> # giving both the comprehension and the underlying for-loop a
> # semantics that some people say they would prefer.
> 
> delayd = [] # reset the list, not part of the loop
> 
> g1 = iter("abracadabra")
> try:
> while True:
> def g2(c):
> delayd.append(lambda : c)
> g2(next(g1))
> except StopIteration:
> pass
> 
> print('Magick:', ''.join(f() for f in delayd))
> 
> # Output from the above:
> # Python: aaa
> # Magick: abracadabra

Hoo boy1
Thats some tour de force and makes my head spin

Point can be made more simply with map
ie if we *define*
[exp for cv in l]
as
map(lambda cv: exp, l)

the problem vanishes

Demo:

First a helper function for demoing:

def pam(fl,x):
return map(lambda f: f(x), fl)
# pam is the complement to map; map runs one fnc on a list of args
# pam runs a list of funcs on one arg

Trying to make a list of functions that add one, two and three to their 
arguments

fl = [lambda x: x + cv for cv in [1,2,3]]

Broken because of python's wrong LC semantics:
>>> pam(fl, 3)
[6, 6, 6]

Transform the LC into a map with the rule above:
fl_good = map((lambda cv :lambda x: x+cv), [1,2,3])

Works!
>>> pam(fl_good, 3)
[4, 5, 6]
>>> 

Which is not very far from the standard workaround for this gotcha:
>>> fl_workaround = [lambda x, cv=cv: x+cv for cv in [1,2,3]]
>>> pam(fl_workaround, 3)
[4, 5, 6]
>>> 

Maybe we could say the workaround is the map definition uncurried
And then re-comprehension-ified
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue28326] multiprocessing.Process depends on sys.stdout being open

2016-10-01 Thread Mariatta Wijaya

Changes by Mariatta Wijaya :


--
nosy: +Mariatta

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28294] HTTPServer server.py assumes sys.stderr != None

2016-10-01 Thread Guido van Rossum

Guido van Rossum added the comment:

A problem with switching to logging is the API design.

There are three functions, log_request(), log_error() and
log_message(). The former two call the latter. The API explicitly
encourages overriding log_message() to customize logging. But it has
no way to know whether it's called from log_error(), log_request(), or
directly.

So how is it to choose logging levels? I imagine log_request() should
log at the INFO level, log_error() at the ERROR level, and let's say
that direct calls to log_message() should also log at the INFO level
(from looking at the few calls). So how should log_error() distinguish
itself to log_message() without breaking apps that override the
latter?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28334] netrc does not work if $HOME is not set

2016-10-01 Thread Dimitri Merejkowsky

New submission from Dimitri Merejkowsky:

If $HOME is not set, netrc will raise an exception.

Attached patch fixes the problem by using `os.path.expanduser` instead

--
components: Library (Lib)
files: netrc-use-expanduser.patch
keywords: patch
messages: 277824
nosy: Dimitri Merejkowsky
priority: normal
severity: normal
status: open
title: netrc does not work if $HOME is not set
type: behavior
versions: Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 3.6, Python 3.7
Added file: http://bugs.python.org/file44914/netrc-use-expanduser.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28294] HTTPServer server.py assumes sys.stderr != None

2016-10-01 Thread Jaap van der Velde

Jaap van der Velde added the comment:

Closing and not fixing is fair enough - I did not realize that this would be an 
issue that occurs in many places in stdlib.

I realize this is not a help forum, so I will ask elsewhere to see if there's 
some way to redirect all of sys.stderr in scenarios like these (running a 
service), because tracking down an issue like this takes a lot of time and 
finding the issue buried in a standard library caught me off guard.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28333] input() with Unicode prompt produces mojibake on Windows

2016-10-01 Thread Adam Bartoš

New submission from Adam Bartoš:

In my setting (Python 3.6b1 on Windows), trying to prompt a non-ASCII character 
via input() results in mojibake. This is related to the recent fix of #1602 and 
so is Windows-specific.

>>> input("α")
╬▒

The result corresponds to print("α".encode("utf-8").decode("cp852")). That 
cp852 the default terminal encoding in my locale.

--
components: Unicode, Windows
messages: 277821
nosy: Drekin, ezio.melotti, haypo, paul.moore, steve.dower, tim.golden, 
zach.ware
priority: normal
severity: normal
status: open
title: input() with Unicode prompt produces mojibake on Windows
type: behavior
versions: Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28332] silent truncations in socket.htons and socket.ntohs

2016-10-01 Thread Oren Milman

Changes by Oren Milman :


--
keywords: +patch
Added file: http://bugs.python.org/file44913/issue28332_ver1.diff

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28332] silent truncations in socket.htons and socket.ntohs

2016-10-01 Thread Oren Milman

Changes by Oren Milman :


Added file: http://bugs.python.org/file44912/patchedCPythonTestOutput_ver1.txt

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28332] silent truncations in socket.htons and socket.ntohs

2016-10-01 Thread Oren Milman

New submission from Oren Milman:

 current state 
Due to the implementation of socket_htons (in Modules/socketmodule.c), in case 
the received integer does not fit in 16-bit unsigned integer, but does fit in a 
positive C int, it is silently truncated to 16-bit unsigned integer (before 
converting to network byte order):
>>> import socket
>>> hex(socket.htons(0x1234))
'0x3412'
>>> hex(socket.htons(0x81234))
'0x3412'
>>> hex(socket.htons(0x881234))
'0x3412'
>>> hex(socket.htons(0x8881234))
'0x3412'
>>> hex(socket.htons(0x1234))
Traceback (most recent call last):
  File "", line 1, in 
OverflowError: Python int too large to convert to C long
>>>

Likewise, socket.ntohs has the same silent truncation feature, due to the 
implementation of socket_ntohs.

ISTM this silent truncation feature has the potential to conceal nasty bugs, 
and I guess it is rarely used in purpose.

With regard to relevant changes made in the past:
* The silent truncation was there since the two functions were first added, 
in changeset 3673 (https://hg.python.org/cpython/rev/f6ace61c3dfe).
* A check whether the received integer is negative was added (to each of 
the two functions) in changeset 40632 
(https://hg.python.org/cpython/rev/6efe3a4b10ac), as part of #1635058.
Note the lack of discussion in #1635058 and #1619659 about backward 
compatibility. It might suggest that Guido didn't hesitate to make the change, 
even though at the time, the four conversion functions (socket.htons, 
socket.ntohs, socket.htonl and socket.ntohl) were already in the wild for 10 
years.


 proposed changes 
1. In Modules/socketmodule.c, raise a DeprecationWarning before silently 
truncating the received integer. In Python 3.8, replace the DeprecationWarning 
with an OverflowError.

2. In Lib/test/test_socket.py, add tests to verify a DeprecationWarning is 
raised as expected.

3. In Doc/library/socket.rst, add a description of the silent truncation 
feature, and declare it is deprecated.


 diff 
The proposed patches diff file is attached.

(I wasn't sure you would approve deprecating a feature that was in the wild for 
so long, but I implemented it anyway, as it was quite simple.)


 tests 
I ran 'python_d.exe -m test -j3' (on my 64-bit Windows 10) with and without the 
patches, and got quite the same output. (That also means my new tests in 
test_socket passed.)
The outputs of both runs are attached.

--
components: Library (Lib)
files: CPythonTestOutput.txt
messages: 277820
nosy: Oren Milman
priority: normal
severity: normal
status: open
title: silent truncations in socket.htons and socket.ntohs
type: behavior
versions: Python 3.7
Added file: http://bugs.python.org/file44911/CPythonTestOutput.txt

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



ConfigParser: use newline in INI file

2016-10-01 Thread Thorsten Kampe
Hi,

ConfigParser escapes `\n` in ini values as `\\n`. Is there a way to 
signal to ConfigParser that there is a line break?

Thorsten


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


  1   2   >