Re: Connection refused when tryign to run bottle/flask web framweworks

2018-08-21 Thread Michael Torrie
On 08/20/2018 06:07 AM, Νίκος wrote:
> Iam trying to access the bottle web framework running on my VPS as
> 
> http://superhost.gr:8080/hello
> 
> i get connection refused

> The weird thing is that in my vps command line my hello app is in state of 
> listening
> 
> [root@superhost public_html]# python3 app.py 
> Bottle v0.12.13 server starting up (using WSGIRefServer())...
> Listening on http://localhost:8080/
> Hit Ctrl-C to quit.
> 
> So, i wonder why the socket with port 8080 aint being displayed.

Why do you wonder?  You're using the wrong url.  The message that's
displayed when you start your mini app says it's listening on localhost,
which is 127.0.0.1.  Yet you are trying to access the url
http://superhost.gr:8080/hello, which is a completely different IP
address.

For security reasons while you're debugging and developing, most web
frameworks bind to localhost, not your public address. So you need to
access it via localhost:

http://localhost:8080/hello

If you notice, this is the exact url that your program told you it was
listening on.

It is possible to configure flask to listen on "*.*.*.*" which means
listen on all interfaces, localhost as well as the outside address.  But
this is not recommended. Instead you would publish it to the outside
world through another web server like Apache.

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


Re: Connection refused when tryign to run bottle/flask web framweworks

2018-08-21 Thread Νίκος
Τη Δευτέρα, 20 Αυγούστου 2018 - 7:18:16 μ.μ. UTC+3, ο χρήστης Chris Warrick 
έγραψε:
> On Mon, 20 Aug 2018 at 18:15, Νίκος  wrote:
> >
> > Τη Δευτέρα, 20 Αυγούστου 2018 - 9:49:00 π.μ. UTC+3, ο χρήστης Miki Tebeka 
> > έγραψε:
> > > If you're trying to access the machine from another machine, you need to 
> > > change the host to '0.0.0.0'. 'localhost' is the internal interface.
> > >
> > > On Sunday, August 19, 2018 at 10:36:25 PM UTC+3, Νίκος wrote:
> > > > Hello,
> > > >
> > > > i just installed bottle and flask web frameworks in my CentOS 
> > > > environment but i canno get it working even with the simpleste xample. 
> > > > The coonection is refused always.
> > > >
> > > > from bottle import route, run, template
> > > >
> > > > @route('/hello/')
> > > > def index(name):
> > > > return template('Hello {{name}}!', name=name)
> > > >
> > > > run(host='localhost', port=8080)
> > > >
> > > >
> > > > Any ideas as to why i cannot access it?
> > > > I dont have sme firewall blocking the ports 8080 or 5000.
> > > >
> > > > Thank you.
> >
> > 0.0.0.0 is used when you want your app to lsiten to all available 
> > interfaces. Even with that still i cannot access the hello app.
> 
> You should avoid exposing the built-in web server to the Internet.

> Either way, are you sure you don’t have any firewall set up on the
> server?

Yes, as far as i know i dont have any firewal installed, i use 
webmin/virtulamin and i have uninstalled firewalld.
How can i check if some other firewall like iptables or somethign else is 
blocking the connection?



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


Re: Connection refused when tryign to run bottle/flask web framweworks

2018-08-21 Thread Νίκος
Τη Τρίτη, 21 Αυγούστου 2018 - 4:39:50 μ.μ. UTC+3, ο χρήστης Michael Torrie 
έγραψε:
> On 08/20/2018 06:07 AM, Νίκος wrote:
> > Iam trying to access the bottle web framework running on my VPS as
> > 
> > http://superhost.gr:8080/hello
> > 
> > i get connection refused
> 
> > The weird thing is that in my vps command line my hello app is in state of 
> > listening
> > 
> > [root@superhost public_html]# python3 app.py 
> > Bottle v0.12.13 server starting up (using WSGIRefServer())...
> > Listening on http://localhost:8080/
> > Hit Ctrl-C to quit.
> > 
> > So, i wonder why the socket with port 8080 aint being displayed.
> 
> Why do you wonder?  You're using the wrong url.  The message that's
> displayed when you start your mini app says it's listening on localhost,
> which is 127.0.0.1.  Yet you are trying to access the url
> http://superhost.gr:8080/hello, which is a completely different IP
> address.
> 
> For security reasons while you're debugging and developing, most web
> frameworks bind to localhost, not your public address. So you need to
> access it via localhost:
> 
> http://localhost:8080/hello
> 
> If you notice, this is the exact url that your program told you it was
> listening on.
> 
> It is possible to configure flask to listen on "*.*.*.*" which means
> listen on all interfaces, localhost as well as the outside address.  But
> this is not recommended. Instead you would publish it to the outside
> world through another web server like Apache.

But my mini app runds on my remote VPS and iam trying to access it from my 
windows 10 machine.


Also '0.0.0.0' which listen to all network interfaces on the VPS still isn't 
allowing the mini app to be access from the outside world.

Should i try superhost.gr/ip address in order to access it?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pylint false positives

2018-08-21 Thread Steven D'Aprano
On Tue, 21 Aug 2018 00:36:56 +, Dan Sommers wrote:
[...]

 (Not that I do this using "inner classes", but I do often want to use
 a class as a container for functions, without caring about "self" or
 wrapping everything in staticmethod.)
>>>
>>> Isn't that what modules are for?  (I suspect that I'm missing
>>> something, because I also suspect that you knew/know that.)
>> 
>> What's the syntax for creating an inner module...?
> 
> Why does it have to be an inner anything?  An ordinary, top-level,
> "outer" module is a perfectly good "container for functions, without
> caring about "self.""

And what if you want to subdivide those functions (or other objects) into 
categories that are finer than the module, without introducing a package 
structure?

We can design the structure of our program into *outward* hierarchies, by 
adding packages with subpackages and sub-subpackages:

import spam.eggs.cheese.tomato.aardvark

So using the file system and packages, we can logically nest modules 
inside modules inside modules 'til the cows come home. But that's a 
fairly heavyweight solution, in the sense that it requires separate 
directory for each level of the hierarchy.

Sometimes a package is too much. I want a single module file, but still 
want to pull out a collection of related functions and other objects and 
put them in their own namespace, but without creating a new module.

The Zen says:

Namespaces are one honking great idea -- let's do more of those!

but Python's namespaces are relatively impoverished. We have packages, 
modules, classes and instances, and that's it.

Classes and instances come with inheritance, self etc which is great if 
you want a class, but if you just want a simple module-like namespace 
without the extra file, classes are a pretty poor alternative. But 
they're all we've got.


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

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


ignoring some default fields from SimpleJsonFormatter

2018-08-21 Thread shradhattx
I am using for my logger

handler.setFormatter(SimpleJsonFormatter(json.dumps))

It had some default fields - timestamp, function, line_number, module, level

and flexibility to provide extra fields in json log with use of 

   logger.info("my test message", extra={"anotherfield1": "test"})

I am using decorator functions so some of the default fields provided ex- 
function, line_number, module are not useful as it gives information on 
decorator module, line_number. 
I like to remove some fields from being logged while retaining others, keeping 
also the use of "extra"

This is what I tried -
 logging.Formatter('{"timestamp": "%(asctime)s.%(msecs)06d", 
"level":"%(levelname)s"}',
'%Y-%m-%dT%H:%M:%S')

The problem is that it doesn't print the fields given in 'extra'


How do I accomplish this?
-- 
https://mail.python.org/mailman/listinfo/python-list


Project Structure for Backend ETL Project

2018-08-21 Thread Jeff M
Is this a good example to follow for a project that does mostly python to 
interact with external data sources including files, transformation, and import 
into Postgres?

https://github.com/bast/somepackage

I have a SWE background but not with python, and I want to make sure my team is 
following good practices.  I am aware of pep8 but does that have project 
structure examples also?
-- 
https://mail.python.org/mailman/listinfo/python-list


Is pypi the best place to find external python packages?

2018-08-21 Thread Jeff M
are there other places also?  On pypi I did not see anywhere the status of 
defects or downloads, if it's actively supported.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is pypi the best place to find external python packages?

2018-08-21 Thread Jeff M
On Tuesday, August 21, 2018 at 9:48:50 AM UTC-6, Jeff M wrote:
> are there other places also?  On pypi I did not see anywhere the status of 
> defects or downloads, if it's actively supported.

nevermind, i see the info i was looking for on the left side.
-- 
https://mail.python.org/mailman/listinfo/python-list


Saving application configuration to the ini file respecting order of sections/options and providing mechanism for (nested) complex objects

2018-08-21 Thread zljubisic



Hi,

I am looking for a way to save ini file with application section/option 
combination. Something like the following:

[Default]
ROOT_DIR= /home/...
RUN = True
COUNTER = 5
LAST_VALUE = 5.6
TEST_FILES_LIST=['a.txt', 'b.txt', 'c.txt']
TEST_FILES_DICT={'CASE1' : ['a.txt', 'b.txt'], 'CASE2': ['c.txt']}

[Dates]
CREATE_DATE="2018-01-01"

[DateTimes]
LAST_MODIFIED_DATE="2018-01-01 14:23:45"


For that purpose I decided to use json as a quite readable fomat that can be 
edited with external text editor.
So I have created dict with all options hoping that I will be able to save it 
with json.dumps and read it with json.loads, but I have run to several problems:

1. saving json will result in unordered ini file. It could be solved by using 
OrderedDict that will than with json.dumps be saved to file in the same order 
as options are added to the ordered dict.

2. there is a problem with datatime values because json format serialize 
everything to string. I have found the solution on page 
https://gist.github.com/abhinav-upadhyay/5300137, but I dislike the idea that 
datetime is represented as unordered dict. When you have to change datetime 
manually in the ini file by using text editor, you first have to sort 
year,month,day... in order to be sure that you are setting correct date. 

3. reading with json.loads will get unordered dict again, so new save will be 
unordered.


Maybe json/(un)OrderedDict is not a proper tool for what I am trying to do. 
How you are saving your (nested) configuration to the ini file?

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


Re: ignoring some default fields from SimpleJsonFormatter

2018-08-21 Thread Peter Otten
shradha...@gmail.com wrote:

> I am using for my logger
> 
> handler.setFormatter(SimpleJsonFormatter(json.dumps))

Where does SimpleJsonFormatter come from?

If it uses the json.dumps argument to serialize a dict you may pass a 
modified version instead:

# untested
KEYS_TO_IGNORE = {"fields", "you", "do", "not", "want"}

def my_pruning_dumps(d):
for k in KEYS_TO_IGNORE:
try:
del d[k]
except KeyError:
pass
return json.dumps(d)

handler.setFormatter(SimpleJsonFormatter(my_pruning_dumps))

> It had some default fields - timestamp, function, line_number, module,
> level
> 
> and flexibility to provide extra fields in json log with use of
> 
>logger.info("my test message", extra={"anotherfield1": "test"})
> 
> I am using decorator functions so some of the default fields provided ex-
> function, line_number, module are not useful as it gives information on
> decorator module, line_number. I like to remove some fields from being
> logged while retaining others, keeping also the use of "extra"
> 
> This is what I tried -
>  logging.Formatter('{"timestamp": "%(asctime)s.%(msecs)06d",
>  "level":"%(levelname)s"}',
> '%Y-%m-%dT%H:%M:%S')
> 
> The problem is that it doesn't print the fields given in 'extra'
> 
> 
> How do I accomplish this?


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


RE: ignoring some default fields from SimpleJsonFormatter

2018-08-21 Thread David Raymond
https://docs.python.org/3.7/library/logging.html#logging.Logger.debug
https://docs.python.org/3.7/library/logging.html#logging.Formatter.format


Basically your Formatter string doesn't include %(anotherfield1)s in it 
anywhere, so that gets ignored. To have a variable number of those in there 
you'd have to make a custom Formatter class where .format(record) looks for any 
"left over" keys in the given LogRecord's args, and adds them to the returned 
message as appropriate.

(Also note that you want 03d for msecs, not 06d)


import logging
import sys
fmt = '{"timestamp": "%(asctime)s.%(msecs)03d", "level":"%(levelname)s"' \
  ', "anottherfield1":"%(anotherfield1)s"}'
datefmt = "%Y-%m-%dT%H:%M:%S"
logging.basicConfig(stream = sys.stdout,
level = logging.DEBUG,
format = fmt,
datefmt = datefmt)
logging.info("my test message", extra = {"anotherfield1": "test"})


{"timestamp": "2018-08-21T12:20:35.475", "level":"INFO", 
"anottherfield1":"test"}




-Original Message-
From: Python-list 
[mailto:python-list-bounces+david.raymond=tomtom@python.org] On Behalf Of 
shradha...@gmail.com
Sent: Tuesday, August 21, 2018 11:37 AM
To: python-list@python.org
Subject: ignoring some default fields from SimpleJsonFormatter

I am using for my logger

handler.setFormatter(SimpleJsonFormatter(json.dumps))

It had some default fields - timestamp, function, line_number, module, level

and flexibility to provide extra fields in json log with use of 

   logger.info("my test message", extra={"anotherfield1": "test"})

I am using decorator functions so some of the default fields provided ex- 
function, line_number, module are not useful as it gives information on 
decorator module, line_number. 
I like to remove some fields from being logged while retaining others, keeping 
also the use of "extra"

This is what I tried -
 logging.Formatter('{"timestamp": "%(asctime)s.%(msecs)06d", 
"level":"%(levelname)s"}',
'%Y-%m-%dT%H:%M:%S')

The problem is that it doesn't print the fields given in 'extra'


How do I accomplish this?
-- 
https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pylint false positives

2018-08-21 Thread Marko Rauhamaa
Gregory Ewing :

> Marko Rauhamaa wrote:
>> Lexically, there is special access:
>>
>>class C:
>>def __init__(self, some, arg):
>>c = self
>>class D:
>>def method(self):
>>access(c)
>>access(some)
>>access(arg)
>
> [...]
>
> you can do that without creating a new class every time you want an
> instance. You just have to be *slightly* more explicit about the link
> between the inner and outer instances.

By "*slightly* more explicit," do you mean more syntactic clutter?

Because of course you replace inner classes and closures with top-level
classes and methods of top-level classes.

And of course, I would prefer not to create a class for a singleton
object:

class C:
def __init__(self, some, arg):
c = self
self.d = object:
def method(self):
access(c)
access(some)
access(arg)

Unfortunately, there is no such syntax in Python.


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


Re: Saving application configuration to the ini file respecting order of sections/options and providing mechanism for (nested) complex objects

2018-08-21 Thread Peter Otten
zljubi...@gmail.com wrote:

> 1. saving json will result in unordered ini file. It could be solved by
> using OrderedDict that will than with json.dumps be saved to file in the
> same order as options are added to the ordered dict.

dict-s are guaranteed to keep insertion order in Python 3.7, see

https://docs.python.org/dev/whatsnew/3.7.html#summary-release-highlights

> 2. there is a problem with datatime values because json format serialize
> everything to string. I have found the solution on page
> https://gist.github.com/abhinav-upadhyay/5300137, but I dislike the idea
> that datetime is represented as unordered dict. When you have to change
> datetime manually in the ini file by using text editor, you first have to
> sort year,month,day... in order to be sure that you are setting correct
> date.

You're free to pick whatever serialisation you like:

$ cat datetimedecoder_isoformat.py
from datetime import datetime
import json
import re


def dict_to_object(d):
if d.get("__type__") != "datetime":
return d
return datetime(*map(int, re.split("[-T:.]", d["isovalue"])))


def default(obj):
if isinstance(obj, datetime):
return {
'__type__': 'datetime',
'isovalue': obj.isoformat()
}
raise TypeError


original = {'name': 'foo', 'type': 'bar', 'date': datetime.now()}
print("original:", original)

serialized = json.dumps(original, default=default, indent=4)
print("serialized:", serialized)

reloaded = json.loads(serialized, object_hook=dict_to_object)
print("reloaded obj:", reloaded)

assert original == reloaded

$ python3 datetimedecoder_isoformat.py 
original: {'date': datetime.datetime(2018, 8, 21, 19, 25, 16, 852379), 
'type': 'bar', 'name': 'foo'}
serialized: {
"date": {
"__type__": "datetime",
"isovalue": "2018-08-21T19:25:16.852379"
},
"type": "bar",
"name": "foo"
}
reloaded obj: {'date': datetime.datetime(2018, 8, 21, 19, 25, 16, 852379), 
'type': 'bar', 'name': 'foo'}


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


Re: Pylint false positives

2018-08-21 Thread Chris Angelico
On Wed, Aug 22, 2018 at 2:38 AM, Marko Rauhamaa  wrote:
> Gregory Ewing :
>
>> Marko Rauhamaa wrote:
>>> Lexically, there is special access:
>>>
>>>class C:
>>>def __init__(self, some, arg):
>>>c = self
>>>class D:
>>>def method(self):
>>>access(c)
>>>access(some)
>>>access(arg)
>>
>> [...]
>>
>> you can do that without creating a new class every time you want an
>> instance. You just have to be *slightly* more explicit about the link
>> between the inner and outer instances.
>
> By "*slightly* more explicit," do you mean more syntactic clutter?
>

No, he actually means "explicit" in the normal English sense. You're
trying to use it in the python-ideas sense of "code that I like", and
since you don't like it, you want to call it "implicit" instead, but
it obviously isn't that, so you call it "syntactic clutter".

But this is actually a case of explicit vs implicit.

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


Bottle framework references

2018-08-21 Thread tommy yama
What’s up?

I am building up the microsite based on Bottle framework now. 
Any references/books? I am unfamiliar with this framework yet. 

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


Re: Project Structure for Backend ETL Project

2018-08-21 Thread Terry Reedy

On 8/21/2018 11:46 AM, Jeff M wrote:

Is this a good example to follow for a project that does mostly python to 
interact with external data sources including files, transformation, and import 
into Postgres?

https://github.com/bast/somepackage


AFAIK, the recommendations in the README are a plausible beginning. 
Some of them obviously depend on programming philosophy and tyle. 
Depending on your background (other languages), you might prefer 
unittest to pytest.  You might prefer another code checker to pycodestyle.



I have a SWE background but not with python, and I want to make sure my team is 
following good practices.


I think the most important 'good practice' is rigorous testing, with  at 
least the basics repeated with every commit.


  I am aware of pep8 but does that have project structure examples also?

If you intend to use github, I would look at a few other packages on github.


--
Terry Jan Reedy

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


Re: Is pypi the best place to find external python packages?

2018-08-21 Thread Terry Reedy

On 8/21/2018 11:48 AM, Jeff M wrote:

are there other places also?  On pypi I did not see anywhere the status of 
defects or downloads, if it's actively supported.


There is another good place for packages that need Windows binaries.

For this and previous post, most information from you can allow better 
answers for you.


--
Terry Jan Reedy

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


Re: Bottle framework references

2018-08-21 Thread Jason Friedman
>
> I am building up the microsite based on Bottle framework now.
> Any references/books? I am unfamiliar with this framework yet.
>
> I have used it with success.  The online documentation was sufficient for
my needs, at least.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Connection refused when tryign to run bottle/flask web framweworks

2018-08-21 Thread Joel Goldstick
On Tue, Aug 21, 2018 at 12:06 PM Dennis Lee Bieber
 wrote:
>
> On Mon, 20 Aug 2018 05:07:59 -0700 (PDT), ?
>  declaimed the following:
>
> >?? ???, 20 ? 2018 - 7:59:06 ?.?. UTC+3, ? ??? dieter ??:
> >> ?  writes:
>
> >> >
> >> > run(host='localhost', port=8080)
> >>
> >> Likely, the code above is supposed to start the server component.
> >> Ensure, that the start is successful (I typically use "lsof -i"
> >> to find out whether a server is listening on the expected port).
> >
> >Iam trying to access the bottle web framework running on my VPS as
> >
> >http://superhost.gr:8080/hello
> >
> >i get connection refused
>
> Note that the coded snippet says LOCALHOST... It is NOT listening for
> connections coming from anything except 127.0.0.1!
>
> >
> >[root@superhost public_html]# python3 app.py
> >Bottle v0.12.13 server starting up (using WSGIRefServer())...
> >Listening on http://localhost:8080/
> >Hit Ctrl-C to quit.
> >
> >So, i wonder why the socket with port 8080 aint being displayed.
>
> Same... it is configured to only listen to connections from the same
> (virtual?) machine on which it is running.
>
> C:\Users\Wulfraed>nslookup superhost.gr
> Server:  dsldevice6.attlocal.net
> Address:  2600:1700:e630:890::1
>
> Non-authoritative answer:
> Name:superhost.gr
> Address:  176.223.129.220
>
>
> C:\Users\Wulfraed>
>
>
> Obviously "superhost.gr" @ 176.223.129.220 is NOT the same as
> "localhost" at 127.0.0.1
>
>
>
> --
> Wulfraed Dennis Lee Bieber AF6VN
> wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/
>
> --
> https://mail.python.org/mailman/listinfo/python-list
although i don't offer advice too often here, as i am kind of
retired., this is extremely reminiscent of a whole lot of server issue
posts from I believe this same OP some years ago.  It will soon become
a rabbit hole.  take care to get involved.  I believe then he was
nikos cranus or something that translated into metal head in english.


-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Partitioning a list

2018-08-21 Thread Poul Riis
I would like to list all possible ways to put N students in groups of k 
students (suppose that k divides N) with the restriction that no two students 
should ever meet each other in more than one group. 
I think this is a classical problem and I think there must be a python solution 
out there but I cannot find it. For instance, numpy's array_split only lists 
one (trivial) split.
I would be happy if someone could refer me to a general python algorithm 
solving the problem.

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


Re: Connection refused when tryign to run bottle/flask web framweworks

2018-08-21 Thread Chris Angelico
On Wed, Aug 22, 2018 at 7:09 AM, Joel Goldstick
 wrote:
> although i don't offer advice too often here, as i am kind of
> retired., this is extremely reminiscent of a whole lot of server issue
> posts from I believe this same OP some years ago.  It will soon become
> a rabbit hole.  take care to get involved.  I believe then he was
> nikos cranus or something that translated into metal head in english.

Correct. He's still selling his "superhost" service, and still
depending on unpaid assistance from python-list (and, I am told, other
places) instead of learning about devops or paying someone for
services.

Help vampire.

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


Re: Partitioning a list

2018-08-21 Thread Steven D'Aprano
On Tue, 21 Aug 2018 14:36:30 -0700, Poul Riis wrote:

> I would like to list all possible ways to put N students in groups of k
> students (suppose that k divides N) with the restriction that no two
> students should ever meet each other in more than one group. I think
> this is a classical problem 

If its a classical problem, there should be many solutions written for 
other languages. Take one of them and port it to Python. (We can help 
with the Python part if needed.)

I've never come across it before. I think the restriction makes it a HARD 
problem to solve efficiently, but I've spent literally less than two 
minutes thinking about it so I could be wrong.

With no additional restriction it sounds like a classical permutations or 
combinations problem. Check out the combinatoric iterators functions in 
the itertools module:

https://docs.python.org/3/library/itertools.html




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

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


Re: Pylint false positives

2018-08-21 Thread Steven D'Aprano
On Wed, 22 Aug 2018 03:58:29 +1000, Chris Angelico wrote:

> On Wed, Aug 22, 2018 at 2:38 AM, Marko Rauhamaa 
> wrote:
>> Gregory Ewing :
>>
>>> Marko Rauhamaa wrote:
 Lexically, there is special access:

class C:
def __init__(self, some, arg):
c = self
class D:
def method(self):
access(c)
access(some)
access(arg)
>>>
>>> [...]
>>>
>>> you can do that without creating a new class every time you want an
>>> instance. You just have to be *slightly* more explicit about the link
>>> between the inner and outer instances.
>>
>> By "*slightly* more explicit," do you mean more syntactic clutter?
>>
>>
> No, he actually means "explicit" in the normal English sense. You're
> trying to use it in the python-ideas sense of "code that I like", and
> since you don't like it, you want to call it "implicit" instead, but it
> obviously isn't that, so you call it "syntactic clutter".

That's an incredible insight into Marko's internal mental state you have 
there. And you get that all from the words "syntactic clutter"? I thought 
he just meant that it was cluttered code. How naive was that?

*wink*



> But this is actually a case of explicit vs implicit.

To be honest, I don't even understand Greg's comment. With no inner 
class, what is this "inner instance" he refers to here?

"you can do that without creating a new class every time you 
want an instance. You just have to be *slightly* more explicit
about the link between the inner and outer instances."


Marko wants to use closures. So how do you close over per-instance 
variables if you create the closures before the instances are created?

If we only needed *one* function, there would be no problem:

class Outer:
def __init__(self, some, arg):
c = self
def closure():
access(c)
access(some)
access(arg)
# then do something useful with closure


But as soon as you have a lot of them, its natural to want to wrap them 
up in a namespace, and the only solution we have for that is to use a 
class.

Its a truism that anything you can do with a closure, you can do with a 
class (or vise versa) so I dare say there are alternative designs which 
avoids closures altogether but we don't know the full requirements here 
and its hard to judge from the outside on why Marko picked the design he 
has and whether its a good idea. It could be a case of "ooh, closures are 
a shiny new hammer, this problem must be a nail!" but let's give him the 
benefit of the doubt and assume he has good reasons, not just reasons.



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

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


Re: Pylint false positives

2018-08-21 Thread Chris Angelico
On Wed, Aug 22, 2018 at 10:39 AM, Steven D'Aprano
 wrote:
> On Wed, 22 Aug 2018 03:58:29 +1000, Chris Angelico wrote:
>
>> On Wed, Aug 22, 2018 at 2:38 AM, Marko Rauhamaa 
>> wrote:
>>> Gregory Ewing :
>>>
 Marko Rauhamaa wrote:
> Lexically, there is special access:
>
>class C:
>def __init__(self, some, arg):
>c = self
>class D:
>def method(self):
>access(c)
>access(some)
>access(arg)

 [...]

 you can do that without creating a new class every time you want an
 instance. You just have to be *slightly* more explicit about the link
 between the inner and outer instances.
>>>
>>> By "*slightly* more explicit," do you mean more syntactic clutter?
>>>
>>>
>> No, he actually means "explicit" in the normal English sense. You're
>> trying to use it in the python-ideas sense of "code that I like", and
>> since you don't like it, you want to call it "implicit" instead, but it
>> obviously isn't that, so you call it "syntactic clutter".
>
> That's an incredible insight into Marko's internal mental state you have
> there. And you get that all from the words "syntactic clutter"? I thought
> he just meant that it was cluttered code. How naive was that?
>
> *wink*
>

Hah. I was just picking up on a few specific parts of the conversation:

1) It's possible to create a class with a number of methods, then
instantiate that class, and have all of its methods be closures.
Lexical containment grants implicit access to the variable "c".

2) It's also possible to create the class at a broader scope, then
instantiate that class, passing it a reference to whatever is in "c".

3) Passing an explicit reference is, if I'm understanding Marko's
scoffing correctly, "syntactic clutter".

4) Clutter is, by implication, unnecessary. In simple assignment "x =
1", we don't consider the equals sign to be "clutter".

My point is that passing the reference truly is "explicit" and relying
on lexical containment truly is "implicit", unlike the usual uses of
those words.

Maybe I misjudged Marko's internal mental state. All I have is his
outputs, so it's like trying to deduce Mersenne's internal state from
its outputs - not fundamentally impossible, but not particularly easy
either. But if I have, he is, as always, most welcome to correct me.

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


[ANN] A magazine for Data Science Enthusiasts

2018-08-21 Thread Karthikeyan A K via Python-list
Hello All,
I have started a magazine for Data Science enthusiasts which brings you every 
week the latest happenings in the world of Data Science. You can get the first 
issue here https://datasciencenews.herokuapp.com/2018/08/19/issue-1.html

- Karthikeyan A K
-- 
https://mail.python.org/mailman/listinfo/python-list