Re: Can't see numpy etc after upgrading Python on Ubuntu

2016-12-20 Thread Vincent Vande Vyvre

Le 20/12/16 à 08:45, Chris Angelico a écrit :

On Tue, Dec 20, 2016 at 5:19 PM,   wrote:

Thanks Chris for replying, but it didn't work. The upgrade happened, but still 
python can't see numpy! So it seems to be a path problem. The numpy (and scipy 
and matplotlib) files are there, so surely in principle it's a simple matter of 
pointing my python path at them?

Any ideas how?

You just installed pip into your /usr/bin/python, not
/usr/local/bin/python. You'll need to get pip in that Python and use
that. I'm not sure the best way to install pip into a 2.7 - someone
else on this list can advise.

ChrisA


It seems you have shadowed your default python2 with the new one. A very 
bad idea.


You can have two python2 but you can't replace the default version.

The default is in /usr/lib and the new is in /usr/locale/lib

The third party libs are into the default version. For this reason 
there's probably some applications that are broken. (apport, bzr, 
synaptic?, ...)


The link /usr/bin/python *MUST* point to the 2.7.3 version, if not, 
restore it.


One solution for use the new version is to create the necessary symbolic 
links into /usr/locale/lib/python2.7/dist-packages which point to 
/usr/lib/python2.7/dist-packages numpy, scipy and others.


In fact, this is the same think when you create a virtual environment, 
the libs are not copied but linked.



VVV

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


Re: Can't see numpy etc after upgrading Python on Ubuntu

2016-12-20 Thread Chris Angelico
On Tue, Dec 20, 2016 at 7:36 PM, Vincent Vande Vyvre
 wrote:
> It seems you have shadowed your default python2 with the new one. A very bad
> idea.

Only because /usr/local/bin is ahead of /usr/bin in PATH.

> The link /usr/bin/python *MUST* point to the 2.7.3 version, if not, restore
> it.

It does. When he installs pip via apt, it manages his original 2.7.3.
Anything that explicitly shebangs to /usr/bin/python will be
unaffected by this.

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


Re: Can't see numpy etc after upgrading Python on Ubuntu

2016-12-20 Thread Vincent Vande Vyvre

Le 20/12/16 à 10:13, Chris Angelico a écrit :

On Tue, Dec 20, 2016 at 7:36 PM, Vincent Vande Vyvre
 wrote:

It seems you have shadowed your default python2 with the new one. A very bad
idea.

Only because /usr/local/bin is ahead of /usr/bin in PATH.

That's the problem.



The link /usr/bin/python *MUST* point to the 2.7.3 version, if not, restore
it.

It does. When he installs pip via apt, it manages his original 2.7.3.
Anything that explicitly shebangs to /usr/bin/python will be
unaffected by this.

ChrisA


Not sure, when the OP enter python into a terminal he have:

peter@sirboris:~$ python
Python 2.7.12 (default, Dec 11 2016, 22:16:38)

So, python point now to the new one. No? VVV

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


Re: Can't see numpy etc after upgrading Python on Ubuntu

2016-12-20 Thread Chris Angelico
On Tue, Dec 20, 2016 at 8:28 PM, Vincent Vande Vyvre
 wrote:
>>> The link /usr/bin/python *MUST* point to the 2.7.3 version, if not,
>>> restore
>>> it.
>>
>> It does. When he installs pip via apt, it manages his original 2.7.3.
>> Anything that explicitly shebangs to /usr/bin/python will be
>> unaffected by this.
>>
>> ChrisA
>
>
> Not sure, when the OP enter python into a terminal he have:
>
> peter@sirboris:~$ python
> Python 2.7.12 (default, Dec 11 2016, 22:16:38)
>
> So, python point now to the new one. No? VVV

So when you type 'python' at the command line, it searches $PATH. But
you don't need to worry about system scripts; they'll use an explicit
"#!/usr/bin/python", which means they'll keep running 2.7.3.

(Unless, of course, the goal of upgrading was actually to change the
system Python, in which case you want to do things _very_
differently.)

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


Re: python list index - an easy question

2016-12-20 Thread BartC

On 20/12/2016 00:49, Steve D'Aprano wrote:

On Mon, 19 Dec 2016 03:21 am, BartC wrote:


On 18/12/2016 10:59, Paul Götze wrote:

Hi John,

there is a nice short article by E. W. Dijkstra about why it makes sense
to start numbering at zero (and exclude the upper given bound) while
slicing a list. Might give a bit of additional understanding.

http://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF



If you can understand threads, OOP design patterns, binary search or C
pointers, counting indexes 0, 1, 2, 3, ... should hold no fears for you.


Who's talking about me? In the area of scripting languages that could be 
used by people with a wide range of expertise, I would have expected 
1-based to be more common.



In Python you can also have a third operand for a range, A:B:C, which
can mean that B is not necessarily one past the last in the range, and
that the A <= i < B condition in that paper is no longer quite true.


You cannot use a simple comparison like A <= i < B to represent a range with
a step-size not equal to 1. How would you specify the sequence:

2, 4, 6, 8, 10, 12, 14

as a single expression with ONLY an upper and lower bound?



2 <= i <= 14

clearly doesn't work, and nor does any alternative.


I didn't mean that the expression specifies the range, but that an value 
in the range satisfies the expression.



In fact, A:B:-1 corresponds to A >= i > B, which I think is the same as
condition (b) in the paper (but backwards), rather (a) which is favoured.


I have no way of knowing what it corresponds to in your head, but in Python,
a slice A:B:-1 corresponds to the elements at indices:


I got the idea for a minute that, since A:B:C specifies a set of 
indices, and that range(A,B,C) specifies the same set of values, that 
they are interchangeable. But of course you can't use x[range(A,B,C)] 
and you can't do 'for i in A:B:C'. [In my, ahem, own language, you can 
just that...]



A, A-1, A-2, A-3, ..., B+1

*in that order*.

py> '0123456789'[7:2:-1]
'76543'


When A is 7, B is 2 and C is -1, then

for i in range(-1000,1000):
if A >=i > B:
print (i)

displays only the numbers 3,4,5,6,7; the same elements you get, and they 
satisfy A >= i > B as I said.



Another little anomaly in Python is that when negative indices are used,
it suddenly switches to 1-based indexing! Or least, when -index is
considered:



That's silly. You can get whichever correspondence you like by choosing
values which do or don't match the indices used by Python:

x = [-3, -2, -1, 0]
print x[-1]  # Notice the lack of correspondence

x = [0, 1, 2, 3]
print x[1]  # Notice the correspondence here

x = [6, 7, 8, 9]
print x[1]  # Notice the lack of correspondence here



What's your point?


That point is that indices go 0,1,2,3,... when indexed from the start, 
and -1,-2,-3,... when indexed from the end.


That means that the THIRD item from the start has index [2], but the 
THIRD item from the end has index [-3].


(So if you reversed a list x, and wanted the same x[i] element you had 
before it was reversed, it now has to be x[-(i+1)]. 1-based, the 
elements would be x[i] and x[-i], a little more symmetric. But with 
N-based, you wouldn't be able to index from the end at all.)



+---+---+---+---+---+---+
| P | y | t | h | o | n |
+---+---+---+---+---+---+
^...^
cut hereand here


That's the fence/fencepost thing I mentioned elsewhere. It comes up also 
in graphics: if these boxes represent pixels rather than elements, and a 
function draws a line from pixel 1 to pixel 4 or fills then in, then 
should pixel 4 be filled in or not?


But if you think of these values as continuous measures from the left 
edge, rather than as discrete units, and denote them as 1.0 to 4.0, then 
it becomes more obvious. The 3 pixels between 1.0 and 4.0 are filled in.


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


windows utf8 & lxml

2016-12-20 Thread Sayth Renshaw
Hi 

I have been trying to get a script to work on windows that works on mint. The 
key blocker has been utf8 errors, most of which I have solved.

Now however the last error I am trying to overcome, the solution appears to be 
to use the .decode('windows-1252') to correct an ascii error.

I am using lxml to read my content and decode is not supported are there any 
known ways to read with lxml and fix unicode faults?

The key part of my script is 

for content in roots:
utf8_parser = etree.XMLParser(encoding='utf-8')
fix_ascii = utf8_parser.decode('windows-1252')
mytree = etree.fromstring(
content.read().encode('utf-8'), parser=fix_ascii)

Without the added .decode my code looks like

for content in roots:
utf8_parser = etree.XMLParser(encoding='utf-8')
mytree = etree.fromstring(
content.read().encode('utf-8'), parser=utf8_parser)

However doing it in such a fashion returns this error:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid 
start byte
Which I found this SO for http://stackoverflow.com/a/29217546/461887 but cannot 
seem to implement with lxml.

Ideas?

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


Re: Can't see numpy etc after upgrading Python on Ubuntu

2016-12-20 Thread ozpeterballard
OK thanks both of you. I didn't realise there was a distinction between system 
python and other (user/personal) python. Yes, python2.7.3 is still there in 
/usr/bin/python .

/usr/bin/python appears to be getting numpy and scipy from 
/usr/lib/python2.7/dist-packages . So I added that to PYTHONPATH and reran 
python (i.e. /usr/local/bin/python, which is 2.7.12). 

But now when I "import numpy" I get an error message which ends in:
 File "/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 5, in 

import multiarray
ImportError: /usr/lib/python2.7/dist-packages/numpy/core/multiarray.so: 
undefined symbol: PyUnicodeUCS4_AsUnicodeEscapeString

So for now I give up.

But the good news is that I have learned that my "old" python (2.7.3) is still 
on my machine. So for now I am renaming /usr/local/bin/python to 
/usr/local/bin/python2.7.12 , and going back to using python 2.7.3. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Geting error using python 3.5 : a_token = r.json() mention below

2016-12-20 Thread Akbar Shaikh
import io
import csv
import glob
import os.path
import requests
import subprocess
import urllib.request
import json
import time
import xlwt
import xlrd
import datetime
from datetime import date, timedelta

def main():
""" Run the whole toolchain for all accounts. """
_clean()

payload = {'client_id':'' ,
'client_secret':'',
'grant_type':'client_credentials'}
headers1 = {
'Content-Type':'application/json'
}

r = requests.post('https://auth.smaato.com/v2/auth/token/ 
HTTP/1.1',params=payload,auth=('username', 'password'),headers = headers1,)

a_token = r.json()

ACCESSTOKEN = a_token['access_token']
print ('Bearer ' + ACCESSTOKEN)

content2 = {
'client_id':'' ,
'client_secret':'',
'grant_type':'client_credentials',
'Authorization': 'Bearer' + ACCESSTOKEN,
'POST':'https://api.smaato.com/v1/reporting/ HTTP/1.1',
'Content-Type':'application/json',
'Host': 'api.smaato.com',
'criteria':{"dimension":"ApplicationId","child":"null"},
'kpi': {"clicks : true"},

'period':{"period_type":"fixed","start_date":"2016-12-7","end_date":"2016-12-7"}
}

headers2 = {
'client_id':'' ,
'client_secret':'',
'grant_type':'client_credentials',
'Authorization': 'Bearer' + ACCESSTOKEN,
'Username':'Username',
'Password':'Password',
'Content-Type': 'application/json',
'Host': 'api.smaato.com',
}
s = 
requests.post('https://api.smaato.com/v1/reporting/',params=content2,auth=('username',
 'password'), headers = headers2)
print(s.content)
  
def _clean():
""" Cleans old data files.
"""
for f in glob.glob('./Numbers *.csv'):
os.remove(f)

if '__main__' == __name__:
main()
-
Error:  Traceback (most recent call last):
  File "C:\Users\\Desktop\Smaato Akbar.py", line 66, in 
main()
  File "C:\Users\\Desktop\Smaato Akbar.py", line 28, in main
a_token = r.json()
  File 
"C:\Users\xxx\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\models.py",
 line 850, in json
return complexjson.loads(self.text, **kwargs)
  File 
"C:\Users\\AppData\Local\Programs\Python\Python35-32\lib\site-packages\simplejson\__init__.py",
 line 516, in loads
return _default_decoder.decode(s)
  File 
"C:\Users\\AppData\Local\Programs\Python\Python35-32\lib\site-packages\simplejson\decoder.py",
 line 374, in decode
obj, end = self.raw_decode(s)
  File 
"C:\Users\\AppData\Local\Programs\Python\Python35-32\lib\site-packages\simplejson\decoder.py",
 line 404, in raw_decode
return self.scan_once(s, idx=_w(s, idx).end())
simplejson.scanner.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Geting error using python 3.5 : a_token = r.json() mention below

2016-12-20 Thread Ned Batchelder
On Tuesday, December 20, 2016 at 7:28:47 AM UTC-5, Akbar Shaikh wrote:
> import io
> import csv
> import glob
> import os.path
> import requests
> import subprocess
> import urllib.request
> import json
> import time
> import xlwt
> import xlrd
> import datetime
> from datetime import date, timedelta
> 
> def main():
> """ Run the whole toolchain for all accounts. """
> _clean()
> 
> payload = {'client_id':'' ,
> 'client_secret':'',
> 'grant_type':'client_credentials'}
> headers1 = {
> 'Content-Type':'application/json'
> }
> 
> r = requests.post('https://auth.smaato.com/v2/auth/token/ 
> HTTP/1.1',params=payload,auth=('username', 'password'),headers = headers1,)
> 
> a_token = r.json()
> 
> ACCESSTOKEN = a_token['access_token']
> print ('Bearer ' + ACCESSTOKEN)
> 
> content2 = {
> 'client_id':'' ,
> 'client_secret':'',
> 'grant_type':'client_credentials',
> 'Authorization': 'Bearer' + ACCESSTOKEN,
> 'POST':'https://api.smaato.com/v1/reporting/ HTTP/1.1',
> 'Content-Type':'application/json',
> 'Host': 'api.smaato.com',
> 'criteria':{"dimension":"ApplicationId","child":"null"},
> 'kpi': {"clicks : true"},
> 
> 'period':{"period_type":"fixed","start_date":"2016-12-7","end_date":"2016-12-7"}
> }
> 
> headers2 = {
> 'client_id':'' ,
> 'client_secret':'',
> 'grant_type':'client_credentials',
> 'Authorization': 'Bearer' + ACCESSTOKEN,
> 'Username':'Username',
> 'Password':'Password',
> 'Content-Type': 'application/json',
> 'Host': 'api.smaato.com',
> }
> s = 
> requests.post('https://api.smaato.com/v1/reporting/',params=content2,auth=('username',
>  'password'), headers = headers2)
> print(s.content)
>   
> def _clean():
> """ Cleans old data files.
> """
> for f in glob.glob('./Numbers *.csv'):
> os.remove(f)
> 
> if '__main__' == __name__:
> main()
> -
> Error:  Traceback (most recent call last):
>   File "C:\Users\\Desktop\Smaato Akbar.py", line 66, in 
> main()
>   File "C:\Users\\Desktop\Smaato Akbar.py", line 28, in main
> a_token = r.json()
>   File 
> "C:\Users\xxx\AppData\Local\Programs\Python\Python35-32\lib\site-packages\requests\models.py",
>  line 850, in json
> return complexjson.loads(self.text, **kwargs)
>   File 
> "C:\Users\\AppData\Local\Programs\Python\Python35-32\lib\site-packages\simplejson\__init__.py",
>  line 516, in loads
> return _default_decoder.decode(s)
>   File 
> "C:\Users\\AppData\Local\Programs\Python\Python35-32\lib\site-packages\simplejson\decoder.py",
>  line 374, in decode
> obj, end = self.raw_decode(s)
>   File 
> "C:\Users\\AppData\Local\Programs\Python\Python35-32\lib\site-packages\simplejson\decoder.py",
>  line 404, in raw_decode
> return self.scan_once(s, idx=_w(s, idx).end())
> simplejson.scanner.JSONDecodeError: Expecting value: line 1 column 1 (char 0)


That error means you are trying to decode an empty string. Most likely,
your request failed, and there's a status code that will give you a clue
as to why it failed.  You should check the success of the request before
trying to use the results.

>From the docs 
>(http://docs.python-requests.org/en/master/user/quickstart/#json-response-content):

> To check that a request is successful, use r.raise_for_status() or check
> r.status_code is what you expect.

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


ImportError: The ``fake-factory`` package is now called ``Faker``.

2016-12-20 Thread Uri Even-Chen
Hi, we get this error with Python 3.4 and 3.5:
https://travis-ci.org/urievenchen/speedy-net/jobs/185497863


--

ImportError: Failed to import test module:
speedy.net.accounts.tests.test_factories

Traceback (most recent call last):

  File "/opt/python/3.5.2/lib/python3.5/unittest/loader.py", line 428,
in _find_test_path

module = self._get_module_from_name(name)

  File "/opt/python/3.5.2/lib/python3.5/unittest/loader.py", line 369,
in _get_module_from_name

__import__(name)

  File 
"/home/travis/build/urievenchen/speedy-net/speedy/net/accounts/tests/test_factories.py",
line 4, in 

import factory

  File 
"/home/travis/virtualenv/python3.5.2/lib/python3.5/site-packages/factory/__init__.py",
line 46, in 

from .faker import Faker

  File 
"/home/travis/virtualenv/python3.5.2/lib/python3.5/site-packages/factory/faker.py",
line 41, in 

import faker

  File 
"/home/travis/virtualenv/python3.5.2/lib/python3.5/site-packages/faker/__init__.py",
line 7, in 

raise ImportError(error)

ImportError: The ``fake-factory`` package is now called ``Faker``.

Please update your requirements.


What is the problem? We didn't update our requirements recently.

Thanks,
Uri.

*Uri Even-Chen*
[image: photo] Phone: +972-54-3995700
Email: [email protected]
Website: http://www.speedysoftware.com/uri/en/
  
    

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


Re: ImportError: The ``fake-factory`` package is now called ``Faker``.

2016-12-20 Thread William Mayor
I came across this error this morning.

In my case I was running a script that did this: “pip install fake-factory”

The install worked properly but then I couldn’t import the library (with the 
same error message as you).

I had to update the pip install command to say “pip install Faker” and then 
everything worked as before.

The authors appear to have forced a name change: 
https://github.com/joke2k/faker/blob/fake-factory/faker/__init__.py 


I’ve just checked and if you pin your requirements (e.g. pip install 
fake-factory==0.7.4) then it still works.


> On 20 Dec 2016, at 16:57, Uri Even-Chen  wrote:
> 
> Hi, we get this error with Python 3.4 and 3.5:
> https://travis-ci.org/urievenchen/speedy-net/jobs/185497863
> 
> 
> --
> 
> ImportError: Failed to import test module:
> speedy.net.accounts.tests.test_factories
> 
> Traceback (most recent call last):
> 
>  File "/opt/python/3.5.2/lib/python3.5/unittest/loader.py", line 428,
> in _find_test_path
> 
>module = self._get_module_from_name(name)
> 
>  File "/opt/python/3.5.2/lib/python3.5/unittest/loader.py", line 369,
> in _get_module_from_name
> 
>__import__(name)
> 
>  File 
> "/home/travis/build/urievenchen/speedy-net/speedy/net/accounts/tests/test_factories.py",
> line 4, in 
> 
>import factory
> 
>  File 
> "/home/travis/virtualenv/python3.5.2/lib/python3.5/site-packages/factory/__init__.py",
> line 46, in 
> 
>from .faker import Faker
> 
>  File 
> "/home/travis/virtualenv/python3.5.2/lib/python3.5/site-packages/factory/faker.py",
> line 41, in 
> 
>import faker
> 
>  File 
> "/home/travis/virtualenv/python3.5.2/lib/python3.5/site-packages/faker/__init__.py",
> line 7, in 
> 
>raise ImportError(error)
> 
> ImportError: The ``fake-factory`` package is now called ``Faker``.
> 
> Please update your requirements.
> 
> 
> What is the problem? We didn't update our requirements recently.
> 
> Thanks,
> Uri.
> 
> *Uri Even-Chen*
> [image: photo] Phone: +972-54-3995700
> Email: [email protected]
> Website: http://www.speedysoftware.com/uri/en/
>   
>    
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


windows utf8 & lxml

2016-12-20 Thread Sayth Renshaw
Possibly i will have to use a different method from lxml like this. 
http://stackoverflow.com/a/29057244/461887

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


Metaclasses - magic functions

2016-12-20 Thread Mr. Wrobel

Hi,

Quick question, can anybody tell me when to use __init__ instead of 
__new__ in meta programming?


I see that __new__ can be used mostly when I want to manipulate with 
class variables that are stored into dictionary.


But when to use __init__? Any example?

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


topology rules in python

2016-12-20 Thread Xristos Xristoou
I have a PostGIS database with shapefiles lines, polygons and points and I want 
to create a topology rules with python.
Any idea how to do that ?some packages ?

I like some easy way to do that because I am newbie but its OK.

Some topology rules when I want.
shapefile must not have gaps
shapefile must not have overlaps
shapefile must not overlap with shapefile2
invalid geometries
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Metaclasses - magic functions

2016-12-20 Thread Ian Kelly
On Tue, Dec 20, 2016 at 2:04 PM, Mr. Wrobel  wrote:
> Hi,
>
> Quick question, can anybody tell me when to use __init__ instead of __new__
> in meta programming?
>
> I see that __new__ can be used mostly when I want to manipulate with class
> variables that are stored into dictionary.
>
> But when to use __init__? Any example?

__new__ is useful because of its power. You can use it to do things
like alter the name of the class or its base classes, or modify class
attributes before the class is created. The latter is interesting
mostly because it allows you to set the __slots__ or do something
interesting with the __prepare__ hook (although the only interesting
thing I've ever seen done with __prepare__ is to use an OrderedDict to
preserve the the definition order of the class attributes; now that
Python 3.6 does this by default it's probably obsolete).

__init__ is simpler than __new__. If you don't need to do any of the
fancy stuff above, you should probably use __init__ instead.

I can't think of any reason why one would ever want to use both on a metaclass.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Metaclasses - magic functions

2016-12-20 Thread Ben Finney
"Mr. Wrobel"  writes:

> Quick question, can anybody tell me when to use __init__ instead of
> __new__ in meta programming?

Use ‘__new__’ to do the work of *creating* one instance from nothing;
allocating the storage, determining the type, etc. — anything that will
be *the same* for every instance. ‘__new__’ is the constructor.

Use ‘__init__’ to do the work of *configuring* one instance, after it
already exists. Any attributes that are special to an instance should be
manipulated in the ‘__init__’ method. ‘__init__’ is the initialiser.

Because Python has a powerful type system built in, you generally have
little or nothing to do in ‘__new__’, and more work in ‘__init__’ for
each instance.


That's a general answer because you haven't said what your goal is. What
is it you want to do with types?

-- 
 \  “Fur coats made for the ladies from their own skin.” —furrier, |
  `\Sweden |
_o__)  |
Ben Finney

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


Re: Metaclasses - magic functions

2016-12-20 Thread Ethan Furman

On 12/20/2016 03:26 PM, Ian Kelly wrote:


... The latter is interesting mostly because it allows you to set the
__slots__ or do something interesting with the __prepare__ hook
(although the only interesting thing I've ever seen done with
__prepare__ is to use an OrderedDict to preserve the the definition
order of the class attributes; now that Python 3.6 does this by default
 it's probably obsolete).


__prepare__ is not obsolete.  Enum uses it to set a custom dictionary which 
tracks the new members, etc.

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


Re: Metaclasses - magic functions

2016-12-20 Thread Ethan Furman

On 12/20/2016 03:39 PM, Ben Finney wrote:

"Mr. Wrobel" writes:



Quick question, can anybody tell me when to use __init__ instead of
__new__ in meta programming?


Use ‘__new__’ to do the work of *creating* one instance from nothing;
allocating the storage, determining the type, etc. — anything that will
be *the same* for every instance. ‘__new__’ is the constructor.

Use ‘__init__’ to do the work of *configuring* one instance, after it
already exists. Any attributes that are special to an instance should be
manipulated in the ‘__init__’ method. ‘__init__’ is the initialiser.


That sounds like general object creation/class advice, which as a general
guideline is okay, but don't feel like it's the most important thing.

I only use `__new__` when the object being created is (or is based on)
an immutable type; otherwise I use `__init__`.  Likewise, if I'm using
`__new__` then I do all my configuration in `__new__` unless I have a
really good reason not to (such as making it easier for subclasses to
modify/skip `__init__`).

As far as metaclasses go... the only time I recall writing an `__init__`
for a metaclass was to strip off the extra arguments so `type.__init__`
wouldn't fail.

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


Pyvenv puts both Python 2 and Python 3 in the same environment. Shocked!

2016-12-20 Thread Malik Rumi
I just created a new venv using pyvenv from a 2.7 install. Now I am shocked to 
see that I can get both 2.7 and 3.4 in this same venv:

(memory) malikarumi@Tetuoan2:~/Projects/cannon/New2.7Projects/memory$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
(memory) malikarumi@Tetuoan2:~/Projects/cannon/New2.7Projects/memory$ python3
Python 3.4.2 (default, Apr 17 2015, 18:47:05) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.

I did not even know this was possible. Doesn’t that defeat the purpose? More to 
the point, how do I make sure I am using the right one? If I want the 
interpreter, that’s easy. But what happens when I want to install and use a 
program like Django? How do I control which interpreter Django uses? I’ve been 
through the official docs a couple of times today, but detailed explanations of 
pyvenv, let alone this dual version feature, have not been found. If you can 
point me to a good one, please do. Meanwhile...

I hoped maybe using different versions of pip would solve the problem, but pip2 
list and pip3 list are identical – hence, the very problem I thought venv’s 
were supposed to avoid. 

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


Re: Pyvenv puts both Python 2 and Python 3 in the same environment. Shocked!

2016-12-20 Thread Steven D'Aprano
On Wednesday 21 December 2016 13:37, Malik Rumi wrote:

> I just created a new venv using pyvenv from a 2.7 install. Now I am shocked
> to see that I can get both 2.7 and 3.4 in this same venv:

I'm not an expert on pyvenv, but my guess is this:

Would you expect a command like "ls" or "grep" to continue to work from inside 
a venv? I expect you would say Yes.

How about "perl"?

If your venv has shadowed python, using the venv instead of the system python, 
there's no reason to expect that python3 will be any different than the same 
command outside of the venv. It will just run the same executable found in the 
PATH as normal, just like (say) "perl" or "grep".

> I did not even know this was possible. Doesn’t that defeat the purpose? More
> to the point, how do I make sure I am using the right one? 

Run this command from the shell prompt:

which python

and that should tell you which executable you are getting.

(I think that should work inside a venv.)


> If I want the
> interpreter, that’s easy. But what happens when I want to install and use a
> program like Django? How do I control which interpreter Django uses? I’ve
> been through the official docs a couple of times today, but detailed
> explanations of pyvenv, let alone this dual version feature, have not been
> found. If you can point me to a good one, please do. Meanwhile...

How do you control which interpreter Django uses outside of a venv?




-- 
Steven
"Ever since I learned about confirmation bias, I've been seeing 
it everywhere." - Jon Ronson

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


Re: Pyvenv puts both Python 2 and Python 3 in the same environment. Shocked!

2016-12-20 Thread Cameron Simpson

On 20Dec2016 18:37, Malik Rumi  wrote:

I just created a new venv using pyvenv from a 2.7 install. Now I am shocked to 
see that I can get both 2.7 and 3.4 in this same venv:

(memory) malikarumi@Tetuoan2:~/Projects/cannon/New2.7Projects/memory$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.

exit()

(memory) malikarumi@Tetuoan2:~/Projects/cannon/New2.7Projects/memory$ python3
Python 3.4.2 (default, Apr 17 2015, 18:47:05)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.

I did not even know this was possible. Doesn’t that defeat the purpose? More 
to the point, how do I make sure I am using the right one? If I want the 
interpreter, that’s easy. But what happens when I want to install and use a 
program like Django? How do I control which interpreter Django uses? I’ve been 
through the official docs a couple of times today, but detailed explanations 
of pyvenv, let alone this dual version feature, have not been found. If you 
can point me to a good one, please do. Meanwhile...


I suspect you're confused. What do:

 which python

and

 which python3

say? Creating a virtual env does not do anything in particular to your 
environment. It provides a distinct environment to work in, but you do need to 
take a specific action to use it.


I'd inspect sys.path in each of your pythons:

 >>> import sys
 >>> sys.path

Watch on my own Mac:

 % /opt/local/bin/python3
 Python 3.5.2 (default, Oct 11 2016, 15:01:29)
 [GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import sys
 >>> sys.path
 ['', '/Users/cameron/lib/python', '/Users/cameron/rc/python', 
 '/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python35.zip', 
 '/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5', 
 '/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plat-darwin', 
 '/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/lib-dynload', 
 '/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages']


versus this:

 % ~/var/venv/3/bin/python3
 Python 3.5.2 (default, Oct 11 2016, 15:01:29)
 [GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import sys
 >>> sys.path
 ['', '/Users/cameron/lib/python', '/Users/cameron/rc/python', 
 '/Users/cameron/var/venv/3/lib/python35.zip', 
 '/Users/cameron/var/venv/3/lib/python3.5', 
 '/Users/cameron/var/venv/3/lib/python3.5/plat-darwin', 
 '/Users/cameron/var/venv/3/lib/python3.5/lib-dynload', 
 '/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5', 
 '/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plat-darwin', 
 '/Users/cameron/var/venv/3/lib/python3.5/site-packages', 
 '/Users/cameron/var/venv/3/lib/python3.5/site-packages/llfuse-1.1.1-py3.5-macosx-10.11-x86_64.egg', 
 '/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages']


so you can see that the "native" python3 has one sys.path, and the one from my 
local python 3 virtualenv has a different one.


Check which pythons you're actually invoking, and what their respective 
sys.path values are.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: topology rules in python

2016-12-20 Thread Bernd Nawothnig
On 2016-12-20, Xristos Xristoou wrote:
> I have a PostGIS database with shapefiles lines, polygons and points
> and I want to create a topology rules with python. Any idea how to do
> that ?some packages ?

http://www.gdal.org/

or:

pip install gdal




Bernd

-- 
no time toulouse
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pyvenv puts both Python 2 and Python 3 in the same environment. Shocked!

2016-12-20 Thread Paul Rudin
Malik Rumi  writes:

> I just created a new venv using pyvenv from a 2.7 install. Now I am shocked to
> see that I can get both 2.7 and 3.4 in this same venv:
>
> (memory) malikarumi@Tetuoan2:~/Projects/cannon/New2.7Projects/memory$ python
> Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
> [GCC 5.4.0 20160609] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
 exit()
> (memory) malikarumi@Tetuoan2:~/Projects/cannon/New2.7Projects/memory$ python3
> Python 3.4.2 (default, Apr 17 2015, 18:47:05) 
> [GCC 4.8.2] on linux
> Type "help", "copyright", "credits" or "license" for more information.

A venv doesn't remove everything from your path. Presumably python3 is
some system installed python. What does "which python3" say?

If you just invoke "python" then you'll get the venv one.


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