Re: Emulating Final classes in Python

2017-01-16 Thread Steven D'Aprano
On Tuesday 17 January 2017 18:05, Steven D'Aprano wrote: > I wish to emulate a "final" class using Python, similar to bool: [...] > Any hints? I may have a solution: here's a singleton (so more like None than bools) where instantiating the class returns the singleton, and subclassing the class f

Re: Emulating Final classes in Python

2017-01-16 Thread Ethan Furman
On 01/16/2017 11:05 PM, Steven D'Aprano wrote: I wish to emulate a "final" class using Python, similar to bool: py> class MyBool(bool): ... pass ... Traceback (most recent call last): File "", line 1, in TypeError: type 'bool' is not an acceptable base type It doesn't have to be absolu

Emulating Final classes in Python

2017-01-16 Thread Steven D'Aprano
I wish to emulate a "final" class using Python, similar to bool: py> class MyBool(bool): ... pass ... Traceback (most recent call last): File "", line 1, in TypeError: type 'bool' is not an acceptable base type It doesn't have to be absolutely bulletproof, but anyone wanting to subclass

Re: Error handling in context managers

2017-01-16 Thread Gregory Ewing
Terry Reedy wrote: Traceback (most recent call last): File "", line 1, in with None: pass AttributeError: __enter__ Like he said, you get an AttributeError! -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: Error handling in context managers

2017-01-16 Thread Gregory Ewing
Israel Brewster wrote: The problem is that, from time to time, I can't get a connection, the result being that cursor is None, That's your problem right there -- you want a better-behaved version of psql_cursor(). def get_psql_cursor(): c = psql_cursor() if c is None: raise CantGet

Re: tokenize.untokenize adding line continuation characters

2017-01-16 Thread Steven D'Aprano
On Tuesday 17 January 2017 09:42, Rotwang wrote: > Here's something odd I've found with the tokenize module: [...] > Copypasted from iPython: It's not impossible that iPython is doing something funny with the tokenize module. Before reporting it as a bug, I recommend that you confirm that it al

tokenize.untokenize adding line continuation characters

2017-01-16 Thread Rotwang
Here's something odd I've found with the tokenize module: tokenizing 'if x:\n y' and then untokenizing the result adds '\\\n' to the end. Attempting to tokenize the result again fails because of the backslash continuation with nothing other than a newline after it. On the other hand, if the o

Re: Error handling in context managers

2017-01-16 Thread Terry Reedy
On 1/16/2017 1:06 PM, Israel Brewster wrote: I generally use context managers for my SQL database connections, so I can just write code like: with psql_cursor() as cursor: And the context manager takes care of making a connection (or getting a connection from a pool, more likely), and cl

Re: Sockets: IPPROTO_IP not supported

2017-01-16 Thread Peter Pearson
On Mon, 16 Jan 2017 10:17:06 +, Joseph L. Casale wrote: >> Trying to sniff Ethernet packets, I do this: >> >>s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP) >> >> but it results in this: >> >> $ sudo python3 sniff_survey.py >> Traceback (most recent call last)

Re: Error handling in context managers

2017-01-16 Thread Marko Rauhamaa
Steve D'Aprano : > or you can let the context manager do what it does, and write your own code > to do what you do: > > try: > with ...: >... > except: > ... Even better: try: a = open(...) except ...: ... with a: ... You want to catch exceptions

Re: Error handling in context managers

2017-01-16 Thread Steve D'Aprano
On Tue, 17 Jan 2017 05:06 am, Israel Brewster wrote: > I generally use context managers for my SQL database connections, so I can > just write code like: > > with psql_cursor() as cursor: > > > And the context manager takes care of making a connection (or getting a > connection from a pool,

Re: Error handling in context managers

2017-01-16 Thread Peter Otten
Israel Brewster wrote: > I generally use context managers for my SQL database connections, so I can > just write code like: > > with psql_cursor() as cursor: > > > And the context manager takes care of making a connection (or getting a > connection from a pool, more likely), and cleaning up

Re: Error handling in context managers

2017-01-16 Thread Chris Angelico
On Tue, Jan 17, 2017 at 5:06 AM, Israel Brewster wrote: > I generally use context managers for my SQL database connections, so I can > just write code like: > > with psql_cursor() as cursor: > > > And the context manager takes care of making a connection (or getting a > connection from a po

Error handling in context managers

2017-01-16 Thread Israel Brewster
I generally use context managers for my SQL database connections, so I can just write code like: with psql_cursor() as cursor: And the context manager takes care of making a connection (or getting a connection from a pool, more likely), and cleaning up after the fact (such as putting the

Re: Running Virtualenv with a custom distlib?

2017-01-16 Thread Paul Moore
On Friday, 13 January 2017 09:27:59 UTC, haraldn...@gmail.com wrote: > I want to do some development on `distlib`, and in the process run the code > via `virtualenv` which has distlib as a dependency. > > That is, not run the process inside a virtualenv, but run virtualenv's code > using a cust

Re: A detailed description on virtualenv's packaging dependecies? (pip, easy_install, wheel, setuptools, distlib, etc.)

2017-01-16 Thread Paul Moore
On Friday, 13 January 2017 09:27:21 UTC, haraldn...@gmail.com wrote: > I was working on a bugfix for Virtualenv, regarding very long shebang lines > that are breaking things. In the process, I realized that if I want really > fix to my particular issue it likely needs to be done on the lower lev

ANN: Python Meeting Düsseldorf - 18.01.2017

2017-01-16 Thread eGenix Team: M.-A. Lemburg
[This announcement is in German since it targets a local user group meeting in Düsseldorf, Germany] ANKÜNDIGUNG Python Meeting Düsseldorf http://pyddf.de/ Ein Tref

RE: Sockets: IPPROTO_IP not supported

2017-01-16 Thread Joseph L. Casale
> Trying to sniff Ethernet packets, I do this: > >s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP) > > but it results in this: > > $ sudo python3 sniff_survey.py > Traceback (most recent call last): > File "sniff_survey.py", line 118, in > s = socket

Re: Python Error

2017-01-16 Thread Terry Reedy
On 1/16/2017 12:32 AM, Girish Khasnis wrote: Hi, I am unable to install Python on my system. After installing Python I get the below error when I try to open Python. [image: Inline image 1] Copy and paste the error message. This is text only list. -- Terry Jan Reedy -- https://mail.pytho

Re: Python Web Scrapping : Within href readonly those value that have href in it

2017-01-16 Thread Jesse Alama
To complement what Peter wrote: I'd approach this problem using XPath. XPath is a query language for XML/HTML documents; it's a great tool to have in your web scraping toolbox (among other tasks). With Python's excellent lxml library you can do some XPath processing. Here's how I might tackle this

Python Error

2017-01-16 Thread Girish Khasnis
Hi, I am unable to install Python on my system. After installing Python I get the below error when I try to open Python. [image: Inline image 1] Regards Girish -- https://mail.python.org/mailman/listinfo/python-list

Re: matrix from matrix

2017-01-16 Thread Adnan Sheikh
My apologies for not providing enough information. I'll share my code attempt shortly. Cheers for your help :) Shei -- https://mail.python.org/mailman/listinfo/python-list