[issue26362] Approved API for creating a temporary file path

2021-03-12 Thread Ben Finney


Ben Finney  added the comment:

> tempfile.mktemp() still exists and works without raising a deprecation 
> warning. Of course it's still marked as deprecated in the docs.

Right. So, the issue is not resolved: Functionality to create a temporary file 
path is maintained in the standard library (good) but the public API for it is 
unsupported.

> Does anyone still want this tempfile.makepath() function?

That's a proposed name. But yes, a supported function in the `tempfile` 
standard library module, which does what's described in this issue.

> Or can this issue be closed?

The issue remains unresolved. Unless you can point us to something new which 
resolves this?

So no, while unresolved, this bug report should not be closed.

--

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



Re: How Do You Replace Variables With Their Values?

2019-07-11 Thread Ben Finney
Aldwin Pollefeyt  writes:

> dinner = {'Starters':['Fried Calamari', 'Potted crab'],'Main
> Course':['Fish', 'Meat'], 'Desert':['Cake', 'Banana Split']}
>
> # Don't ask where I got the dinner from
>
> for meal in dinner.keys():
> exec(meal.replace(' ','_') + ' = list(dinner[meal])')
>
> print(Starters)
> print(Main_Course)
> print(Desert)

Why do you think this is needed? Why (there may be some reason! but you
have not told us what that is) can your program not just::

print(dinner['Starters'])
print(dinner['Main Course'])
print(dinner['Desert'])

> OUTPUT:
> ['Fried Calamari', 'Potted crab']
> ['Fish', 'Meat']
> ['Cake', 'Banana Split']

The above code produces this output, without any need for binding new
names. So what is it you are actually trying to achieve, and why do you
think the new bindings are necessary?

-- 
 \“The number of UNIX installations has grown to 10, with more |
  `\ expected.” —Unix Programmer's Manual, 2nd Ed., 1972-06-12 |
_o__)          |
Ben Finney

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


Re: How Do You Replace Variables With Their Values?

2019-07-10 Thread Ben Finney
Terry Reedy  writes:

> On 7/10/2019 6:37 PM, CrazyVideoGamez wrote:
>
> > and I'm just changing it with the code above (you can find that by
> > printing it out). How can I make separate lists called 'Starters',
> > 'Main Course', and 'Desert'?
>
> starters = dinner['Starters']
> main_course = dinner['Main Course']
> desert = dinner['Desert']

The question comes, though, why you (CrazyVideoGamez) are doing this.

You have the lists immediately accesible as dictionary elements, by
name.

Why do you need to also have them bound to separate names; what problem
are you trying to solve that you think this will help?

-- 
 \   “If [a technology company] has confidence in their future |
  `\  ability to innovate, the importance they place on protecting |
_o__) their past innovations really should decline.” —Gary Barnett |
Ben Finney

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


Re: Instance vs Class variable oddity

2019-05-15 Thread Ben Finney
Irv Kalb  writes:

> I just saw some code that confused me.  The confusion has to do with
> class variables and instance variables.

(Perhaps unrelated, but here's another confusion you may be suffering
from: There's no such thing as a “class variable” or “instance
variable”. In Python, a “variable” is always a *binding* between a name
and and object. The “variable” has no concept of different types.)

> When I instantiate two objects (t1 and t2), the __init__ method calls
> the show method, which prints a value of self.x.

That's right. The ‘__init__’ method initialises an already-created
instance, and so has the same access any other instance method has.

> I'm not understanding why this is legal.  I would expect that I would
> get an error message saying that self.x does not exist, since no
> instance variable named self.x has been defined.

Note that you're not calling the initialiser (‘__init__’) directly.

Also note that the initialiser receives, as its first argument, the
already-existing instance. So something has already created that
instance before calling the initialiser.

The initialiser ‘__init__’ is called from the constructor (‘__new__’),
and this happens only *after the instance is created*. For details see
https://docs.python.org/3/reference/datamodel.html#object.__new__>
the documentation for the constructor method, ‘__new__’.

> My guess is that there is some scoping rule that says that if there is
> no instance variable by a given name, then see if there is one in the
> class.

Yes, though that is an entirely separate issue from when the initialiser
gets called.

You are correct that the scope resolution includes:

* Does the attribute exist on this instance?
* Does the attribute exist on this instance's class?

and it continues with the class's superclass(es), and so on until it
finds an attribute with that name.

> If the self.x on the right hand side refers to the class variable

For the purpose of resolving the value of the right hand side, yes.

> and creates an instance variable called self.x on the left hand side

Yes.

(The correct terms are “class attribute” and “instance attribute”.)

> then how does the second call work using the value of the instance
> variable on the right hand side?

I'm not sure I understand the confusion; once the instance has an
attribute of that name, the same logic you outlined above applies when
attempting to resolve that attribute. When ‘self.x’ exists on the
instance, that's what will be used when resolving ‘self.x’.

I hope that helps.

-- 
 \“To me, boxing is like a ballet, except there's no music, no |
  `\   choreography, and the dancers hit each other.” —Jack Handey |
_o__)          |
Ben Finney

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


Re: convert .py to Android ?

2019-05-14 Thread Ben Finney
"Steve"  writes:

> I have a working .py program

(Do you mean a Python program? Or something different?)

> that I want to get into my Android Moto G phone.

To my knowledge, an Android app must be implemented, at some level, in
Java and specifically linked to Android Java libraries. That's a hard
limitation of the Android platform.

That implies that any Python program will need to be written at least
with partial awareness that it is not going to run in a native Python
VM, but instead get compiled to somehow run in a Java Android environment.

> A bit more than a year ago, I went through the Kivy set up and
> actually had the Good Morning World program in my phone but at that
> time I did not seem to be able to do it again.

Yes, Kivy is one way to have a Python program that gets converted to an
Android native app.

> Is there an easier way to achieve my task?

Easier than Kivy? Probably not.

You might want to investigate the BeeWare suite as an alternative
https://pybee.org/>. Bonus: a single Python program can be compiled
to an app for multiple different platforms.

-- 
 \  “Compulsory unification of opinion achieves only the unanimity |
  `\of the graveyard.” —Justice Roberts in 319 U.S. 624 (1943) |
_o__)          |
Ben Finney

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


[issue23297] Clarify error when ‘tokenize.detect_encoding’ receives text

2019-04-28 Thread Ben Finney

Ben Finney  added the comment:

On 28-Apr-2019, Berker Peksag wrote:

> The original problem has already been solved by making
> tokenize.generate_tokens() public in issue 12486.

I don't understand how that would affect the resolution of this issue.

Isn't the correct resolution here going to entail correct
implementation in ‘file.readline’?

--

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



Re: formatted docstrings

2019-04-03 Thread Ben Finney
Cameron Simpson  writes:

> To answer my own question ...
>
> On 04Apr2019 14:05, Cameron Simpson  wrote:
> > Is it unreasonable to promote bare format strings as candidates for
> > the docstring?
>
> Sigh. Because such a string _should_ be evaluated in the runtime scope
> context of the _called_ function, and it hasn't been called.

Another reason why docstrings should only be literals: a common use case
is to evaluate the docstrings and put them into static reference
documentation.

If there's something about the API that will be different depending on
where the API is running, but the API documentation just shows me some
condition from when the documentation was built, that's a nasty surprise
waiting to happen.

Instead, the docstring should just explicitly describe the domain of
possible values (or whatever it is that's going to change depending on
the environment).

-- 
 \  “Courage is not the absence of fear, but the decision that |
  `\ something else is more important than fear.” —Ambrose Redmoon |
_o__)          |
Ben Finney

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


Re: Syntax for one-line "nonymous" functions in "declaration style"

2019-03-27 Thread Ben Finney
Alexey Muranov  writes:

> It would be however more convenient to be able to write instead just
>
>f(x) = x*x

That's not an anonymous function then, is it? You want to assign a name
to that function, and (to be useful in development tools, such as a
stack trace) the function needs to know its own name.

The way to do that is, as you point out, the ‘def’ statement:

def f(x):
return (x * x)

What does that prevent you from doing? It will need to be pretty
significant improvement to be considered as a change to language syntax.

> Have this idea been discussed before?

Too many times to count :-)

-- 
 \   “Theology is the effort to explain the unknowable in terms of |
  `\ the not worth knowing.” —Henry L. Mencken |
_o__)      |
Ben Finney

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


Re: configparser - which one?

2019-03-27 Thread Ben Finney
DL Neil  writes:

> After striking this problem, I was encouraged to take a look at JSON,
> and thence YAML. Once there, as they say, didn't look back!
> - multi-dimensional possibilities, cf .ini
> - similarity/correspondence with Python data structures
> - convenient PSL
> - easily adopted by (power-)users, cf Python code

Those are all true.

Drawbacks for YAML as a configuration format:

* Not implemented in Python standard library.

* Not a single, unambiguous standard which all implementations support
  (this may be one reason for no Python standard library implementation).

Despite those, yes I would very much prefer to use YAML as a
configuration format. (ConfigParser INI format is acceptable. JSON is
definitely not, because it has no simple way to put comments in the
file.)

-- 
 \  “In the long run, the utility of all non-Free software |
  `\  approaches zero. All non-Free software is a dead end.” —Mark |
_o__)    Pilgrim, 2006 |
Ben Finney

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


Re: Your IDE's?

2019-03-27 Thread Ben Finney
Mr Zaug  writes:

> On Monday, March 25, 2019 at 5:38:41 PM UTC-4, John Doe wrote:
> > What is your favorite Python IDE?
>
> "Your IDE's?" is not a question

It is a topic for discussion though. Hence, appropriate for the Subject
field. Especially because he then wrote a full sentence question in the
message body.

> nor is any word in English made plural with an apostrophe  s.

Bob the Angry Flower agrees http://www.angryflower.com/247.html>.

-- 
 \  “The history of Western science confirms the aphorism that the |
  `\ great menace to progress is not ignorance but the illusion of |
_o__)knowledge.” —Daniel J. Boorstin, historian, 1914–2004 |
Ben Finney

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


Re: Your IDE's?

2019-03-25 Thread Ben Finney
John Doe  writes:

> What is your favorite Python IDE?

The same as my favourite JavaScript IDE, Haskell IDE, and any other
language I need:

Emacs and a shell multiplexer (today, that's GNU Screen, but others
swear that I should try TMux).

An IDE, like all of the tools that we rely on for getting our work done,
should be free software and owned by its community to ensure it's always
meeting its community's needs.

An IDE in particular should handle my programming tasks well regardless
of whether it was designed with that programming language in mind. So a
mature, flexible, extensible, language-agnostic IDE is a must.

Of those available, I know of Vim and GNU Emacs to be the strongest
contenders.

Maybe the Atom editor will get there some day, though for now I hear
many complaints that with many plug-ins active it's just too slow when
doing the kind of complex tasks we expect of a programmer's editor like
Vim or GNU Emacs.

-- 
 \“The reason we come up with new versions is not to fix bugs. |
  `\ It's absolutely not.” —Bill Gates, 1995-10-23 |
_o__)  |
Ben Finney

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


Re: Reasoning of calling a method on class object instead of class instance object

2019-03-18 Thread Ben Finney
Arup Rakshit  writes:

Michael Torrie  writes:

> On 03/18/2019 05:55 PM, Ben Finney wrote:
> >> If I call `_c_to_f`, `_f_to_c` methods on `self` instead of
> >> `RefrigeratedShippingContainer` class object, still it works.
> > 
> > That's right, and is indeed the point of making a static method on a
> > class. 
>
> I'm confused. […] he never said anything about static methods unless
> I'm really missing something.

You included it, quoted above (but stripped out the attribution; please
don't do that). The only methods discussed in Arup Rakshit's message are
‘_c_to_f’ and ‘_f_to_c’, both static methods on the class.

-- 
 \ “A child of five could understand this. Fetch me a child of |
  `\  five.” —Groucho Marx |
_o__)      |
Ben Finney

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


Re: Reasoning of calling a method on class object instead of class instance object

2019-03-18 Thread Ben Finney
Arup Rakshit  writes:

> class RefrigeratedShippingContainer(ShippingContainer):
> # ...
>
> @staticmethod
> def _c_to_f(celsius):
> return celsius * 9/5 + 32
>
> @staticmethod
> def _f_to_c(fahrenheit):
> return (fahrenheit - 32) * 5/9

Both those functions are decorated with ‘staticmethod’. That means
https://docs.python.org/3/library/functions.html#staticmethod>
that the function will, unlike typical methods, not automatically
receive any implicit first argument. That's why the function signature
has no ‘self’ or ‘klass’ or the like.

> If I call `_c_to_f`, `_f_to_c` methods on `self` instead of
> `RefrigeratedShippingContainer` class object, still it works.

That's right, and is indeed the point of making a static method on a
class. From the above documentation link:

[A staticmethod-decorated function] can be called either on the
class (such as `C.f()`) or on an instance (such as `C().f()`). The
instance is ignored except for its class.

> So what is the reason behind of this calling on the class object,
> instead class instance object?

Whichever makes the most sense in the code where that function is
called.

The purpose of a static method is to imply that, though the function
*could* be entirely separate from any class, it is conceptually part of
a spacific class's behaviour.

In the specific example you show, I expect the code maintenance was
deemed to be easier when the RefrigeratedShippingContainer encapsulates
the conversions of temperature units.

-- 
 \ “When we pray to God we must be seeking nothing — nothing.” |
  `\—Francis of Assisi |
_o__)          |
Ben Finney

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


Re: Not a python question, just programming logic trap?

2019-03-13 Thread Ben Finney
jonas.thornv...@gmail.com writes:

> Anyone who is good at see logic traps in programming?
> comp.lang.javascript is defunct so i try here.

Please don't; this forum should primarily be used for discussing Python.

I appreciate that you have tried another forum for JavaScript, but
that's unrelated to whether this is an approriate forum for the
question. It isn't.

You could try https://stackoverflow.com/tags/javascript> but really
it's not good to be using this Python discussion forum for that purpose.

-- 
 \ “I went to a museum where all the artwork was done by children. |
  `\   They had all the paintings up on refrigerators.” —Steven Wright |
_o__)          |
Ben Finney

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


Re: Totally Legit Signing Key?

2019-03-04 Thread Ben Finney
Peter Otten <__pete...@web.de> writes:

> $ gpg --import pubkeys.txt 
> […]
> gpg: Schlüssel 487034E5: "Steve Dower (Python Release Signing) 
> " 8 neue Signaturen
> gpg: Schlüssel 10250568: Öffentlicher Schlüssel "Łukasz Langa (GPG langa.pl) 
> " importiert
> gpg: Schlüssel 487034E5: Öffentlicher Schlüssel "Totally Legit Signing Key 
> " importiert
> gpg: Schlüssel F73C700D: Öffentlicher Schlüssel "Totally Legit Signing Key 
> " importiert
> gpg: Schlüssel 6F5E1540: Öffentlicher Schlüssel "Totally Legit Signing Key 
> " importiert
> gpg: Schlüssel AA65421D: Öffentlicher Schlüssel "Totally Legit Signing Key 
> " importiert
> gpg: Schlüssel E6DF025C: Öffentlicher Schlüssel "Totally Legit Signing Key 
> " importiert
> gpg: Schlüssel EA5BBD71: Öffentlicher Schlüssel "Totally Legit Signing Key 
> " importiert
> [...]
>
> Now "totally legit" does sound like anything but "totally legit".

Another clue is in the email address for that key: the ‘example.org’
domain is guaranteed to never resolve to any machine on the internet.

There's nothing stopping anyone putting a fake email address, and any
description they like, into a GnuPG userid. This was an inexpensive way
to discover that :-)

> Is there a problem with my machine, or python.org, or is this all
> "totally legit"?

Your computer, and your GnuPG program, are working as intended. Those
specific signatures are made with a key that is bogus (and has been
constructed to look as fake as it in fact is), and so you can ignore
them.

> Advice or pointers welcome.

Cryptographic signatures should be trusted no more than you trust the
provenance of the key that made the signature.

-- 
 \“Human reason is snatching everything to itself, leaving |
  `\   nothing for faith.” —Bernard of Clairvaux, 1090–1153 CE |
_o__)  |
Ben Finney

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


Re: Two Tier Cloud Network

2019-02-25 Thread Ben Finney
asimejaz...@gmail.com writes:

> I am a beginner in Python, I need your help in Python coding.

Welcome! You are in the right place to discuss Python.

> I want to create a two-tier cloud network which consists of the
> cloudlets and DataCenters, cloudlets and DataCenters have virtual
> machines which are attached to each other. Thanks in advance

That sounds like an interesting problem. It's very large and vaguely
described though.

I assume you are smart enough to not ask for strangers to write a big
program to your specifications just because you ask, right?

What is the Python code you have already written? What do you expect
your code to do, and what does it do instead? What is the exact error
output?

-- 
 \  “… a Microsoft Certified System Engineer is to information |
  `\ technology as a McDonalds Certified Food Specialist is to the |
_o__)   culinary arts.” —Michael Bacarella |
Ben Finney

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


Re: Feature suggestions: "Using declarations" i.e. context managers ("with" blocks) tied to scope/lifetime of the variable rather than to nesting

2019-02-19 Thread Ben Finney
"mnl.p...@gmail.com"  writes:

> with xx.open() as logfile:
>  do this
>  do that
>  logfile.write()
>  do this
>  do that
>  logfile.write()

That's a good sign you have identified a discrete collection of
statements that should be in a function. The function accepts
‘logfile’ as a (probably named) parameter, so that it is explit the
opening and closing of that file is someone else's responsibility This,
as you say, simplifies the code in those statements.

Bonus: you can name the function to summarise its entire purpose::

with foo.open() as logfile:
frobnicate_the_whelk(logfile=logfile)

-- 
 \  “I don't want to live peacefully with difficult realities, and |
  `\ I see no virtue in savoring excuses for avoiding a search for |
_o__)real answers.” —Paul Z. Myers, 2009-09-12 |
Ben Finney

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


Re: Multiprocessing performance question

2019-02-18 Thread Ben Finney
I don't have anything to add regarding your experiments with
multiprocessing, but:

Israel Brewster  writes:

> Which creates and populates an 800x1000 “grid” (represented as a flat
> list at this point) of “boxes”, where a box is a
> shapely.geometry.box(). This takes about 10 seconds to run.

This seems like the kind of task NumPy http://www.numpy.org/> is
designed to address: Generating and manipulating large-to-huge arrays of
numbers, especially numbers that are representable directly in the
machine's basic number types (such as moderate-scale integers).

Have you tried using that library and timing the result?

-- 
 \ “You don't need a book of any description to help you have some |
  `\kind of moral awareness.” —Dr. Francesca Stavrakoloulou, bible |
_o__)  scholar, 2011-05-08 |
Ben Finney

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


Re: What's the address for?

2019-02-18 Thread Ben Finney
"Avi Gross"  writes:

> I hear that [the ‘id(foo)’ return value] is implementation dependent.
> But are there any requirements on the implementation that allow it to
> have meaning?

The requirements are that `id(foo)` should satisfy the documented API
for that function https://docs.python.org/3/library/functions.html#id>:

 Return the “identity” of an object. This is an integer which is
 guaranteed to be unique and constant for this object during its
 lifetime. Two objects with non-overlapping lifetimes may have the
 same `id()` value.

> I mean is the ID guaranteed to be unique and not reused within a
> session?

No. The identity of an object is guaranteed to be unique only during the
lifetime of that object. This implies that *outside* the lifetime of
that object (before it exists; after it is destroyed) the same value
is allowed to be the identity of some other object.

> If two things concurrently show the same ID, are they the same in some
> way?

Yes, querying the identity of two references concurrently will return
the same identity value only if those two references refer to the same
object.

That is the essential meaning of an object identity: you can compare it
with some other identity value and see whether that came from the same
object.

Other than object identity, there is pretty much no guarantee (and hence
almost no purpose for the value you get from ‘id(foo)’). That is useful
enough, of course.

> On the implementation I am using, the ID changes if I do this:

You are creating new objects and binding the name ‘a’ to different
objects in succession. Those different objects will each have different
identities.

> It looks like the ID of "a" can change depending on its contents.

That's because a name is not a container, it is a reference. Names don't
know *anything* about the object; they have no type, no identity,
nothing except the ability to refer to some object at a particular point
in time.

> So I decided to do what maybe should be done first. Find some
> documentation!

Yes (especially the documentation of the function you're using, ‘id’).

Also helpful: Learn the actual behaviour of references in Python. They
do not behave like “variables” in some other languages (I avoid talking
about Python “variables” at all, for this reason). References are not
containers, and thinking of them that way will frequently lead you to
the wrong conclusion.

https://nedbatchelder.com/text/names1.html>

-- 
 \   “Theology is the effort to explain the unknowable in terms of |
  `\ the not worth knowing.” —Henry L. Mencken |
_o__)          |
Ben Finney

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


Re: The NaNny State

2019-02-18 Thread Ben Finney
"Avi Gross"  writes:

> It is about the recent discussion about the concept and word "nan" as used
> in python and elsewhere. As noted, the correct spelling in python is all
> lower case as in "nan" with a minor exception that creating a nan using
> float(string) allows any combination of cases such as string="nAN".

Who says that the “correct spelling in python is all lower case "nan"”?

The text representation of a Python ‘float’ NaN object is 'nan'. That is
what the object emits as its text representation; it is not the same
thing as "the correct spelling".

As you note, the ‘float’ type accepts several spellings as input to
create a NaN object, all of them correct spelling.

Similarly, I can spell the number one thousand ‘1000.0’, ‘1.0e+3’
‘1.000e+3’, ‘1000.0’, and so on. Those are all correct (and, as it
happens, they all result in equal ‘float’ values).

The resulting object will, when I interrogate it, represent itself *by
default* as ‘1000.0’; Python is not showing *the* correct spelling, just
one possible correct spelling.

-- 
 \ “I wrote a song, but I can't read music so I don't know what it |
  `\is. Every once in a while I'll be listening to the radio and I |
_o__)    say, ‘I think I might have written that.’” —Steven Wright |
Ben Finney

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


Re: Problem : Generator

2019-02-14 Thread Ben Finney
Prahallad Achar  writes:

> How to implement reverse generator

Welcome to the Python forum!

That sounds like an interesting problem. Can you describe it more
precisely? What should a “reverse generator” actually do (and not do)?

Ideally, give an example:

* Some code you would maybe expect to create a "reverse generator", that
  you have already tried but doesn't work.

* Exactly what you *expect* the resulting object to do; what is its
  expected behaviour? What is its expected output?

-- 
 \  “Software patents provide one more means of controlling access |
  `\  to information. They are the tool of choice for the internet |
_o__) highwayman.” —Anthony Taylor |
Ben Finney

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


Re: Can't run setup.py offline due to setup_requires - setup.py calls home

2019-02-11 Thread Ben Finney
Chris Narkiewicz via Python-list  writes:

> debian/rules calls this pip to install all requirements from local
> package collection:
>
> pip3 install --log=... --no-cache --no-index --find-links=pypi
> --no-binary=":all:" -r requirements.txt

As you have observed, this fails because Setuptools does not correctly
handle the ‘setup_requires’ option
https://github.com/pypa/setuptools/issues/457>.

> Directory pypi contains ALL dependencies required for build.

All of the build dependencies, *including* the ones specified in
‘setup_requires’?

> This works ok when build server has connection to network, but fails for
> offline builds. I pinpointed the problem to package Automat, that
> specifies some dependencies via setup_requires=[...]:
>
> setup(
> ...,
> setup_requires=[
> 'setuptools-scm',
> 'm2r',
> ],
> ...
> )

To avoid the Setuptools bug, the PyPA recommends dropping the
‘setup_requires’ option and instead specifying build dependencies in a
PEP 518 formatted metadata file
https://github.com/pypa/setuptools/issues/293>.

You could create such a specification (by adding a metadata file),
ensure those dependencies are also present locally, and meanwhile
present the maintainers of this project with your merge request to add
that metadata file.

-- 
 \   “What do religious fundamentalists and big media corporations |
  `\   have in common? They believe that they own culture, they are so |
_o__)     self-righteous about it …” —Nina Paley, 2011 |
Ben Finney

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


Re: Loop with else clause

2019-02-05 Thread Ben Finney
DL Neil  writes:

> Possible solution:
> To make anything more than the trivial case readable, I think I'd put
> the list processing into one function, and the exception into another
> (except that this case is so trivial), ie
>
>   if list:
>   process_list() #the heading and for-loop, as above
>   else:
>   print( "Sorry...

(As an aside: It's best to avoid choosing names like ‘list’ that clobber
built-in names; your code examples are harder to read that way. I'll
assume a different name, ‘ipsums’.)

One aspect of that example I would prefer to avoid: It scatters the
handling of the list to different locations in the code. It's not
obvious from the purpose of ‘process_list’ whether that function should
be handling an empty list; this could lead to double-handling in
different locations.

An alternative to consider::

if ipsums:
for item in ipsums:
process_item(item)
else:
print("Sorry...")

An advantage of this is that the handling of the list is all in the same
place, where changing that logic later will be easier. The
‘process_item’ then just assumes some other code has decided which items
to handle; it becomes correspondingly simpler.

-- 
 \   “Two possibilities exist: Either we are alone in the Universe |
  `\   or we are not. Both are equally terrifying.” —Arthur C. Clarke, |
_o__)         1999 |
Ben Finney

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


Re: When to Use Django & Flask frame work

2018-12-12 Thread Ben Finney
VENKEY ROKZS  writes:

> Hi Viewers,

Welcome to the Python discussion forum.

>  I am new to java I want to about when to Use Django & Flask..

Typically we use those frameworks more with Python, not Java :-)

> I have started working on it.Anybody can you suggest the difference...

The biggest difference I would point out: Flask is small, Django is big.

More accurately: Both are full web development frameworks, but Flask is
focussed more to allow you to assemble many of the pieces yourself,
which Django makes many of the decisions for you by default.

Even more accurately: Both Flask and Django are reasonably small and
fast, and both allow you to customise the pieces quite well. The
difference I alluded to is rather one of emphasis: Flask expects that
you will want to quite soon replace many of the standard pieces, while
Django expects that you can go the whole application lifecycle without
needing to change any of the default pieces.

I hope that helps! If you have the time, feel free to evaluate each of
them and choose whichever one suits your need. If you don't have time, I
would recommend starting with Django because you will be able to get a
long way without needing to diverge from the default.

-- 
 \  “If I ever get real rich, I hope I'm not real mean to poor |
  `\  people, like I am now.” —Jack Handey |
_o__)          |
Ben Finney

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


Re: Help - Python REST API

2018-12-12 Thread Ben Finney
Afriyie Abraham Kwabena  writes:

> Am trying to create a basic authorization server using client
> credentials flow and client so that the client can send it credentials
> using REST methods (POST) to the authorization server.

At minimum, this implies that you are implementing a web server (either
from scratch, or by plugging your code into some existing web server) to
listen for and respond to the HTTP requests.

Have you already chosen which web server will be receiving requests?

> Can anyone help me or give guidelines how I can achieve this using
> python?

There are existing frameworks (Flask, Django) that make it relatively
straightforward to implement a REST API — that is, relative to writing
it from scratch!

Even using such a framework, you would still be accepting the burden of
implementing and deploying a full web service.

-- 
 \ “Computers are useless. They can only give you answers.” —Pablo |
  `\   Picasso |
_o__)          |
Ben Finney

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


Re: setup.py and licensing questions

2018-12-12 Thread Ben Finney
songbird  writes:

>   can i put multiple License lines in setup.py 
> classifiers like: ?
>
>   "License :: OSI Approved :: ???",
>   "License :: OSI Approved :: ???",

Yes.

The semantics of that are not formalised, to my knowledge. You would be
signaling that the specified licenses are involved somehow, but not how
they combine for this specific work.

For this reason (and others) you should always put an explicit,
unambiguous *grant of license* in the work, preferably in the README
document or somewhere prominent like that.

The grant of license is a statement, preferably brief, that says exactly
what the work is, who holds copyright, who receives a grant of license,
and what that grants the recipient to do, under what explicit conditions.

For example:

Copyright © 2018 Ben Finney 
Purple Drachma is free software: you are free to copy, modify,
and/or distribute this work under the conditions of the GNU Affero
General Public License, version 3 or later as published by the Free
Software Foundation. See the file LICENSE.AGPL-3.0 for details.

-- 
 \ “You don't need a book of any description to help you have some |
  `\kind of moral awareness.” —Dr. Francesca Stavrakoloulou, bible |
_o__)          scholar, 2011-05-08 |
Ben Finney

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


[issue33130] functools.reduce signature uses `iterable`, documentation should use the same term

2018-11-30 Thread Ben Finney


Ben Finney  added the comment:

Hah, sorry to use a local-filesystem URL. (Hooray for locally-installed 
developer documentation!)

The same section is online at 
https://docs.python.org/3/library/functools.html#functools.reduce .

--

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



[issue33130] functools.reduce signature uses `iterable`, documentation should use the same term

2018-11-30 Thread Ben Finney


Ben Finney  added the comment:

The library documentation (e.g. 
file:///usr/share/doc/python3/html/library/functools.html#functools.reduce ) 
also has this dissonance:

>  functools.reduce(`function`, `iterable` [, `initializer` ])
>
>Apply function of two arguments cumulatively to the items of `sequence`, 
> from left to right, so as to reduce the sequence to a single value.

--
nosy: +bignose
title: functools.reduce signature/docstring discordance -> functools.reduce 
signature uses `iterable`, documentation should use the same term

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



Re: question on the 'calendar' function

2018-11-20 Thread Ben Finney
o1bigtenor  writes:

> On Tue, Nov 20, 2018 at 12:09 PM Ben Finney  
> wrote:
> > o1bigtenor  writes:
> > > It could be useful to see the longer time spans as weeks rather
> > > than as days but seeing the larger time frames only as months
> > > would enable the planning that I need to do.
> >
> > Does ‘calendar.monthcalendar’ come close to what you need
> > https://docs.python.org/3/library/calendar.html#calendar.monthcalendar>?
>
> No - - - the limit is still one year (of 12 months) and my minimum
> would be 18 months and preferably quite a bit more.

That doesn't match what I understand from the module documentation.

Can you show a (small, self-contained) example that demonstrates the
“limit is still one year” when you try to use ‘calendar.monthcalendar’
for the purpose you described above?

-- 
 \ “I have yet to see any problem, however complicated, which, |
  `\  when you looked at it in the right way, did not become still |
_o__)        more complicated.” —Paul Anderson |
Ben Finney

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


Re: question on the 'calendar' function

2018-11-20 Thread Ben Finney
o1bigtenor  writes:

> I am in the process of learning my first computer programming language
> (unless g-code counts and then it is my second - - - grin). It
> definitely is a big world out there.

Welcome, and congratulations on starting with Python!

> The calendar function has a lot of versatility and shows care in its
> development.

I assume we are here talking about the standard library ‘calendar’
module https://docs.python.org/3/library/calendar.html>, and the
function is ‘calendar.calendar’ to generate a whole year calendar
https://docs.python.org/3/library/calendar.html#calendar.calendar>.

> For planning I need to be able to easily look backward 6 months and
> forward at least 12 and better 18 months and would prefer perhaps even
> a total of 36 (and even 60 might be useful) months of calendar
> available. It could be useful to see the longer time spans as weeks
> rather than as days but seeing the larger time frames only as months
> would enable the planning that I need to do.

Have you looked through the rest of the documentation of that module?
Does ‘calendar.monthcalendar’ come close to what you need
https://docs.python.org/3/library/calendar.html#calendar.monthcalendar>?

> Do I need to (somehow and I have no idea how) extend the calendar
> function?

It's quite feasible you may get to that point, at which time you will
want to learn about composing functions by calling other functions;
eventually you will learn a different technique, of creating a class by
inheriting from an existing class.

But all that may be in the future! Try just using the existing functions
from that library module and see how far that gets you.

Good hunting.

-- 
 \ “I have the simplest tastes. I am always satisfied with the |
  `\best.” —Oscar Wilde, quoted in _Chicago Brothers of the Book_, |
_o__)         1917 |
Ben Finney

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


Re: PEP 394

2018-10-19 Thread Ben Finney
Anders Wegge Keller  writes:

> Short and simple: Do you expect PEP 394 to change status

The status of PEP 394 today is “Active”. What change of status would you
expect in this Informational PEP?

> or recommendation when official support for Python2 ends in 13½ months
> time, or at least some time thereafter?

The criterion will not, IIUC, be the end of official PSF support for
Python 2.

Rather, the criteria will include (at least) an insignificant number of
remaining Python 2 installations in the wild.

How that will be measured, I don't know, but *actual usage* of Python 2
is much more the measurement to be made, before deprecating backward
compatibility in the command name.

-- 
 \ “My house is on the median strip of a highway. You don't really |
  `\notice, except I have to leave the driveway doing 60 MPH.” |
_o__)   —Steven Wright |
Ben Finney

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


Re: ESR "Waning of Python" post

2018-10-11 Thread Ben Finney
Chris Angelico  writes:

> In actual fact, it's not a problem per-se. It's a design choice, and
> every alternative choice tried so far has even worse problems. THAT is
> why we still have it.

That reads to me like a rejection of the point made in the blog post:
that the GIL prevents Python from taking proper advantage of multi-core
machines.

In other words: Yes, it's a design decision, but that design decision
causes the problems described.

Is it your position that the described behaviour is not a problem? Do
you hold that position because you think multi-core machines are not a
sector that Python needs to be good at? Or that the described behaviour
doesn't occur? Or something else?

-- 
 \  “A hundred times every day I remind myself that […] I must |
  `\   exert myself in order to give in the same measure as I have |
_o__)received and am still receiving” —Albert Einstein |
Ben Finney

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


Re: Python indentation (3 spaces)

2018-10-08 Thread Ben Finney
Terry Reedy  writes:

> You assumption that a tab means '4 spaces' is wrong.  A tab means
> 'jump to the next tab stop'.  On 10 char/inch US typewriters, tab
> stops were initially set to every 5 spaces or 1/2 inch.  In terminals
> and code editors, virtual tab stops were often set to every 8 spaces,
> and python still interprets tabs that way.
>
> This means that editing Python code in an editor that *displays* tabs
> (as opposed to converting them to spaces) with other than
> every-8-space tab stops is arguably a bad idea if the file has or
> might have non-tab space indents.

The distinctions Terry is drawing attention to are important. Often the
confusion in these discussions comes from people conflating the three
separate issues that jwz described in this classic essay
https://www.jwz.org/doc/tabs-vs-spaces.html>.

-- 
 \  “I find the whole business of religion profoundly interesting. |
  `\ But it does mystify me that otherwise intelligent people take |
_o__)    it seriously.” —Douglas Adams |
Ben Finney

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


Python indentation (correct behaviour) (was: Python indentation (3 spaces))

2018-10-08 Thread Ben Finney
Cameron Simpson  writes:

> What I do wish was that I had a vim mode that highlighted an indent
> column so I can line up indented code with its controlling top line.

For Vim: https://github.com/nathanaelkane/vim-indent-guides>.
For Emacs: https://github.com/antonj/Highlight-Indentation-for-Emacs>

The latter is used by default in Elpy, an excellent Python development
suite https://elpy.readthedocs.io/>.

-- 
 \   “When a well-packaged web of lies has been sold to the masses |
  `\over generations, the truth will seem utterly preposterous and |
_o__)its speaker a raving lunatic.” —Dresden James |
Ben Finney

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


Re: This thread is closed [an actual new thread]

2018-10-02 Thread Ben Finney
Ethan Furman  writes:

> On 10/01/2018 04:26 PM, Ben Finney wrote:
> > If there is some specific formal meaning to the above statement, I
> > don't know where it's documented. If it's not a specific formal
> > statement, that is itself troubling, because it's not clear what
> > would constitute a violation nor what the consequences are.
>
> Consider it now documented, at least on Python List. I imagine Python
> Ideas may also implement this framework (assuming we stay on Mail Man
> and don't migrate to some web-based forum).

Thank you.

I don't want to imply an obligation for others, but I suggest it will be
(beyond the short term) less painful for future thread-closing actions
if that is documented in an official document at a known web page URL.
So every time a moderator closes a thread, the message announcing that
action can simply say "see  for what this means".

-- 
 \   “Drop your trousers here for best results.” —dry cleaner, |
  `\   Bangkok |
_o__)          |
Ben Finney

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


This thread is closed (was: [OT] master/slave debate in Python)

2018-10-01 Thread Ben Finney
Ethan Furman  writes:

> This thread is closed.

Coming from a moderator of this forum, I don't know how that statement
is to be interpreted.

Is that a statement that it is *impossible* (mechanically) to post
replies in this thread? Across the different technologies that propogate
this forum?

If not impossible, is that a statement that it is *strictly prohibited*,
by a forum moderator, to post replies in this thread?

If prohibited, what are we to expect are the consequences of breaching
that prohibition, knowingly or unknowingly?

How is any of the above affected by posting in the same thread but on a
different metter, as I have done?

How is any of the above affected by changing the Subject field, as I
have done?

If there is some specific formal meaning to the above statement, I don't
know where it's documented. If it's not a specific formal statement,
that is itself troubling, because it's not clear what would constitute a
violation nor what the consequences are.

Ethan, I thank you for doing the fraught work of a moderator of this
forum. Hopefully we can get clarity on this and future thread-closing
actions, separate from the thread which prompted this instance.

-- 
 \ “Truth would quickly cease to become stranger than fiction, |
  `\ once we got as used to it.” —Henry L. Mencken |
_o__)  |
Ben Finney

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


Re: What's an elegant way to test for list index existing?

2018-09-29 Thread Ben Finney
Ben Finney  writes:

> You can use a comprehension, iterating over the full range of index you
> want::
>
> words = shlex.split(line)
> padding_length = 5
> words_padded = [
> (words[index] if index < len(words))
> for index in range(padding_length)]

That omits the important case you were concerned with: when `index <
len(words)` is false. In other words, that example fails to actually pad
the resulting list.

Try this instead::

words = shlex.split(line)
padding_length = 5
padding_value = None
words_padded = [
(words[index] if index < len(words) else padding_value)
for index in range(padding_length)]

-- 
 \   “When a well-packaged web of lies has been sold to the masses |
  `\over generations, the truth will seem utterly preposterous and |
_o__)its speaker a raving lunatic.” —Dresden James |
Ben Finney

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


Re: What's an elegant way to test for list index existing?

2018-09-28 Thread Ben Finney
Chris Green  writes:

> I have a list created by:-
>
> fld = shlex.split(ln)
>
> It may contain 3, 4 or 5 entries according to data read into ln.

Because of what an index means for the 'list' type, that's equivalent to
saying "the result of `len(fld)` may be 3, 4, or 5".

> What's the neatest way of setting the fourth and fifth entries to an
> empty string if they don't (yet) exist?

You have the right idea: testing the length of the object is a correct
and expressive way to ask "is there an item at this index in the list".

> Using 'if len(fld) < 4:' feels clumsy somehow.

One reason I finx that clumsy is that you're testing against a
hard-coded value; and you'd have to write a loop to get the value each
time.

You can use a comprehension, iterating over the full range of index you
want::

words = shlex.split(line)
padding_length = 5
words_padded = [
(words[index] if index < len(words))
for index in range(padding_length)]

That accomplishes the construction of the padded list in a single
expression, hopefully expressive, and definitely making use of whatever
optimisations the in-built comprehension mechanics provide.

-- 
 \   “Pray, v. To ask that the laws of the universe be annulled in |
  `\ behalf of a single petitioner confessedly unworthy.” —Ambrose |
_o__)       Bierce, _The Devil's Dictionary_, 1906 |
Ben Finney

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


Re: Which class method is being called when we declare below expression?

2018-09-28 Thread Ben Finney
Ben Finney  writes:

> Ajay Patel  writes:
>
> > L = [1,2,3]
>
> That's not an expression; it is an assignment statement.
>
> The right-hand side is an expression. […] in this case, [the object] a new
> instance of 'list' […] is the result of evaluating the right-hand side
> of the expression.

I goofed there. That should end with "[…] evaluating the expression on
the right-hand side".

> The statement then assigns the reference 'L' to that object.

-- 
 \   “We have clumsy, sputtering, inefficient brains…. It is a |
  `\ *struggle* to be rational and objective, and failures are not |
_o__) evidence for an alternative reality.” —Paul Z. Myers, 2010-10-14 |
Ben Finney

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


Re: Which class method is being called when we declare below expression?

2018-09-28 Thread Ben Finney
Ajay Patel  writes:

> L = [1,2,3]

That's not an expression; it is an assignment statement.

The right-hand side is an expression. It will (at the top level) create
a list.

To create a new instance of the 'list' type, Python will call the type's
'__new__' method. This is termed the constructor for that type.

The constructor returns a new instance of the type; in this case, it
returns a new instance of 'list'. That object is the result of
evaluating the right-hand side of the expression.

The statement then assigns the reference 'L' to that object.

> And
> L =[]

All the above description also applies to that assignment statement.

-- 
 \“If you go parachuting, and your parachute doesn't open, and |
  `\you friends are all watching you fall, I think a funny gag |
_o__) would be to pretend you were swimming.” —Jack Handey |
Ben Finney

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


Re: Enum with nested classes or with types as members

2018-09-12 Thread Ben Finney
Ethan Furman  writes:

> I'm asking because in doing some work on Enum it became apparent to me
> that having nested classes was not a smooth, satisfying experience,
> and I'm considering treating them the same way as methods (they will
> no longer be converted into members).

For reference (and to hopefully better inform this discussion) the topic,
of Enum subclasses with nested class attributes, was raised recently
https://mail.python.org/pipermail/python-list/2018-June/735128.html>
by Ethan, and several conflicting positions were aired back then.

> So if you use that functionality, tell me now!  :)

Thanks for keeping this going, I hope a consensus can emerge.

-- 
 \   “If we listen only to those who are like us, we will squander |
  `\   the great opportunity before us: To live together peacefully in |
_o__)a world of unresolved differences.” —David Weinberger |
Ben Finney

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


Re: How to pass Python command line options (vs arguments) when running script directly vs via Python interpreter?

2018-08-15 Thread Ben Finney
David Raymond  writes:

> So what are you saying is an option vs an argument? Because I see no
> distinction whatsoever.

The command-line conventions do recognise the distinction.

* A command-line argument specifies input to the program.

  For example, the destination file for a ‘cp’ command is specified as
  the final argument to that command.

* A command-line option specifies a modifier to the program's behaviour.

  For example, the ‘--force’ option for a ‘cp’ command modifies the
  behaviour to remove the destination file if it already exists.

> When you run something you give it a bunch of strings.

Sure, command-line arguments and options are specified as strings. That
doesn't erase the distinction; it just means there is a category they
both belong to.

> That's it.

You can claim to not see the distinction, but that's athwart existing
convention, and you'll need to accept that there *is* such a distinction
in the specification of a great many programs.

> There is nothing magical about putting a dash in front of a letter,

Convention is not magical, true. Specifying options with a leading
hyphen is arbitrary.

That doesn't make it meaningless; the convention exists and is very
normal.

https://en.wikipedia.org/wiki/Command-line_interface#Arguments>

-- 
 \  “In the long run, the utility of all non-Free software |
  `\  approaches zero. All non-Free software is a dead end.” —Mark |
_o__)    Pilgrim, 2006 |
Ben Finney

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


Good reason not to obfuscate URLs (was: Fishing from PyPI ?)

2018-08-07 Thread Ben Finney
Vincent Vande Vyvre  writes:

>To verify, visit your Account Settings
><https://pypi.us18.list-manage.com/track/click?u=[… personally-identifying 
> information …]>
>page.
>
> -
>
> The Account Settings
> <https://pypi.us18.list-manage.com/track/click?u=[… personally-identifying 
> information …]>
> is :
> https://pypi.us18.list-manage.com/track/click?u=[… personally-identifying 
> information …]
>
> Phishing ? yes, no ?

It's impossible to tell, from those links alone. The links are
obfuscated deliberately.

What we can say for certain, is that following those links allows
parties unknown, to track the fact you've followed that link, before you
ever get to PyPI.

You are right to be concerned.

This is one good reason why I argue that link obfuscation like this is
bad practice: we can't tell what domain they will redirect to, so
there's no way to know before visiting the link whether it will go to a
‘python.org’ URL.

Instead, sending people links that you want them to follow should be
direct links. That way we can see where it is the person wants us to
visit.

As a bonus, we avoid more layers of surveillance that these
man-inthe-middle providers like ‘list-manage.com’ try to gather about
our online behaviour.

-- 
 \  “Programs must be written for people to read, and only |
  `\incidentally for machines to execute.” —Abelson & Sussman, |
_o__)          _Structure and Interpretation of Computer Programs_ |
Ben Finney

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


Re: How to start gnuradio

2018-08-01 Thread Ben Finney
bengt.to...@gmail.com writes:

> My gnuradio program does not start in my Mint 17.3 installation.

Summary: I believe this is a bug in the package on Mint. (The bug may be
inherited from elsewhere, too: maybe in the Debian package, maybe in the
PyPI package. That would need more diagnosis to determine.)

> When I invoke the command "gnuradio-companion" I get the following message:
>
> -
> Cannot import gnuradio.

That looks like a bug, indeed.

Because you later reported that installing another Python package brings
correct behaviour, this strongly indicates that the gnuradio package
does not correctly declare its dependencies.

In other words: The 'gnuradio-companion' program does not work without
an additional package installed, so that is a dependency which must be
declared for the 'gnuradio' package.

> Grateful for hints on how to find out the reason and to solve the
> problem.

I think you have enough information to write a bug report to the Mint
bug tracking system for this.

-- 
 \  “The good thing about science is that it's true whether or not |
  `\  you believe in it.” —Neil deGrasse Tyson, 2011-02-04 |
_o__)          |
Ben Finney

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


Re: Why did logging not undergo PEP8 API change?

2018-07-30 Thread Ben Finney
Skip Montanaro  writes:

> There was some discussion of the idea (before the thread predictably
> wandered off into the weeds). I've not found anything else obviously
> related to the topic. Perhaps it was nothing more than that the
> threading module had a PEP-8 champion while logging didn't?

Sometimes, even with a champion for improving the API through renames,
it doesn't happen. There is still the BDFL (or whatever comes to replace
that role) to reckon with
https://mail.python.org/pipermail/python-dev/2008-July/081263.html>.

In that case, it was the inertia of the existing body of code using the
API names which gave justification to reject renames. I would expect
that was significant also in the decision not to change the ‘logging’
API names.

-- 
 \ “[F]reedom of speech does not entail freedom to have your ideas |
  `\accepted by governments and incorporated into law and policy.” |
_o__)   —Russell Blackford, 2010-03-06 |
Ben Finney

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


Re: Anyone using cloud based monitoring/logging services with Python logging module?

2018-07-26 Thread Ben Finney
Malcolm Greene  writes:

> Looking for feedback on anyone who's using a cloud based
> monitoring/logging service with Python's standard lib logging module,

The free-software Sentry https://sentry.io/> is full-featured,
implemented in PYthon, and available to set up on your own hosting or
pay someone else to host it.

This means you can choose Sentry as your logging service, and that
leaves you free to choose (and change your mind later) how Sentry itself
gets hosted. You're not tied to some vendor's hosted instance.

It integrates very well with logging frameworks of many languages,
including Python's ‘logging’ module.

-- 
 \ “When I turned two I was really anxious, because I'd doubled my |
  `\   age in a year. I thought, if this keeps up, by the time I'm six |
_o__)  I'll be ninety.” —Steven Wright |
Ben Finney

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


Re: coding style - where to declare variables

2018-07-23 Thread Ben Finney
Gregory Ewing  writes:

> Marko is asking us to stop using the word "binding" to refer to
> assignment because of the potential confusion with this other meaning.

That's about as reasonable as my request that we stop using the term
“variable” for what is, in Python, an un-typed reference to an object.

I expect both of these requests to meet with little satisfaction.

-- 
 \ “We are all agreed that your theory is crazy. The question that |
  `\  divides us is whether it is crazy enough to have a chance of |
_o__)being correct.” —Niels Bohr (to Wolfgang Pauli), 1958 |
Ben Finney

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


Re: For next loops

2018-07-23 Thread Ben Finney
no@none.invalid writes:

> never mind.

Congratulations for working out the error. And thank you for returning
to show the corrected code :-)

-- 
 \   “If you don't know what your program is supposed to do, you'd |
  `\ better not start writing it.” —Edsger W. Dijkstra |
_o__)  |
Ben Finney

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


Re: functions vs methods

2018-07-22 Thread Ben Finney
INADA Naoki  writes:

> Please don't refer the FAQ entry.
> See this: https://bugs.python.org/issue27671

Interesting. Thanks for raising that bug report.

I offer my text as a starting point for a better explanation:

Because ‘len’ works with *any* sequence, not only lists. To
implement it as a method of each sequence type, it would have to be
implemented on each type separately, which is a design that is
needlessly more complex.

This is common in Python: it uses so-called “duck typing”
https://docs.python.org/3/glossary.html#term-duck-typing>,
where the way an object behaves is more important than its type.
Because “what is the length of this object” is a question valid for
a broad variety of types, the design decision was made to allow it
to accept any type for which that query makes sense.

Feel free to use that (or something derived from it) to improve the
documentation as you suggest.

-- 
 \   “Come on, if your religion is so vulnerable that a little bit |
  `\   of disrespect is going to bring it down, it's not worth |
_o__)   believing in, frankly.” —Terry Gilliam, 2005-01-18 |
Ben Finney

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


Re: functions vs methods

2018-07-22 Thread Ben Finney
Sharan Basappa  writes:

> Is there a difference between functions and methods in Python.

Python's documentation includes a useful Glossary. See the terms
https://docs.python.org/3/glossary.html#term-method>
https://docs.python.org/3/glossary.html#term-function>.

Every method is a function; but there are functions that are not
methods.

What distinguishes a method is that it is associated with a specific
class. A method is always a method *of* some class or object.

> For example, this is the text from tutorialpoint on Python:
> Python includes the following list functions - cmp, len etc.

The functions ‘cmp’, ‘len’, are not associated with any particular
class. They can be called without being bound to any object.

> Python includes following list methods - append, count

That means the functions it is referring to are each methods of ‘list’.
Any instance of ‘list’ has methods ‘append’ and ‘count’, bound to that
instance.

> In the first case, len is a function that python provides to which
> list can be passed and in the second case, append is a method within
> list class?

Yes, that's correct.

> If my interpretation is correct, why not make len also as a part of
> list class itself?

Because ‘len’ works with *any* sequence, not only lists. To implement it
as a method of each sequence type, it would have to be implemented on
each type separately, which is a design that is needlessly more complex.

This is common in Python: it uses so-called “duck typing”, where the way
an object behaves is more important than its type. Because “what is the
length of this object” is a question valid for a broad variety of types,
the design decision was made to allow it to accept any type for which
that query makes sense.

https://docs.python.org/3/glossary.html#term-duck-typing>

Your particular question is itself a FAQ
https://docs.python.org/3/faq/design.html#why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list>.

-- 
 \   “All progress has resulted from people who took unpopular |
  `\  positions.” —Adlai Stevenson |
_o__)          |
Ben Finney

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


Re: Looking for a recent quote about dynamic typing, possibly on this list

2018-07-06 Thread Ben Finney
Steven D'Aprano  writes:

> Somebody gave a quote about dynamic typing, along the lines of
>
> "Just because a language allows a lot of dynamic features, doesn't mean 
> people's code uses a lot of dynamism."

You did refer us to http://lambda-the-ultimate.org/node/1519> on
this forum. That contains a quote attributed to John Aycock with the
meaning you paraphrase above.

-- 
 \“… it's best to confuse only one issue at a time.” —Brian W. |
  `\Kernighan and Dennis M. Ritchie, _The C programming language_, |
_o__)         1988 |
Ben Finney

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


Re: Using Python with a website

2018-07-04 Thread Ben Finney
Adrian Taylor  writes:

> I have just discovered Python […]

Welcome. The Python community has a starter page for beginners at
https://wiki.python.org/moin/BeginnersGuide>.

> However my next big step is to be able to use this python feature
> within a website.

Good. Be aware, though, that running a program on the public internet is
a very complicated thing. Partly this is because your program needs to
be on a web site, which itself needs to play nicely with the rest of the
internet.

And, an even more important part, is that the internet is a very wild
place with a continual noise of malicious parties trying to compromise
any site. So you need to do a lot of things just to defend against that.

All of which is to say: There is a huge increase in complexity from “my
simple program which accepts input and produces output”, to a website
that will do the same thing.

See the community guides on web frameworks, which let you wrap your
feature in a whole lot of code that will take care of the “be a website”
job https://wiki.python.org/moin/WebFrameworks/>.

For general purpose use, I recommend Django which has excellent help
https://www.djangoproject.com/>.

-- 
 \  “If sharing a thing in no way diminishes it, it is not rightly |
  `\  owned if it is not shared.” —Augustine of Hippo (354–430 CE) |
_o__)          |
Ben Finney

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


Re: PEP 526 - var annotations and the spirit of python

2018-07-03 Thread Ben Finney
Jim Lee  writes:

> I claimed that Steven was using three different numbers to refer to
> the time it takes to master a subject:
>
> 10,000 hours
> an indefinite number
> 2 years

Yes. He did so in the context of showing that *there is no precise
number* that universally applies for the amount of effort required.

Add as many numbers as you like, provided they're all in the same broad
range. That is the point, and showing there are multiple numbers in play
is *supporting* Steven's point.

I still don't know what point you had, but I'm not really interested any
more.

-- 
 \“This sentence contradicts itself — no actually it doesn't.” |
  `\   —Douglas Hofstadter |
_o__)          |
Ben Finney

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


Re: PEP 526 - var annotations and the spirit of python

2018-07-03 Thread Ben Finney
Abdur-Rahmaan Janhangeer  writes:

> apart from programming, other questions go like this :
>
> […]
> *cut at this point*

Ooh, I like that last step! How do we make that happen on demand?

-- 
 \   “Everything you read in newspapers is absolutely true, except |
  `\for that rare story of which you happen to have first-hand |
_o__) knowledge.” —Erwin Knoll |
Ben Finney

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


Re: Getting posts to sort chronologically in tree view

2018-07-03 Thread Ben Finney
T Berger  writes:

> On Tuesday, July 3, 2018 at 4:00:03 PM UTC-4, Ben Finney wrote:
> > Given that history [of ignoring user requests for improvement], you
> > might want to avoid Google Groups for interacting with forums, and
> > choose software that works better with discussion forums. I am told
> > Mozilla Thunderbird is a good choice, but there are likely others.
>
> I don't think I want to try a mail list.

Good news: you're already participating in one. That was easy! :-)

This is because the forum you're participating is distributed in many
media, *including* a mailing list. You may send some or all of your
messages using a different interface, but you're still participating in
the same forum as the rest of us and so you're participating on (among
other things) a mailing list.

> I had subscribed to the python-list a few weeks ago and then been
> forced to unsubscribe because of the flood of irrelevant posts.

Yes, this forum can sometimes host a high volume of discussion. You will
want to learn the “filter” feature (it may have a different name) of
whatever interface you use.

> Ben, I tried responding to your email from gmail. I hit the reply
> button, and got the below message. Do you know why?

I haven't got any insight to that error, no.

If you have an easy way to get official support for Google Groups, ask
there.

If you don't have an easy way to get support for the software, I'd say
that is a good hint to avoid using that software entirely.

-- 
 \“Members of the general public commonly find copyright rules |
  `\implausible, and simply disbelieve them.” —Jessica Litman, |
_o__)          _Digital Copyright_ |
Ben Finney

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


Re: PEP 526 - var annotations and the spirit of python

2018-07-03 Thread Ben Finney
Jim Lee  writes:

> On 07/03/18 19:58, Ben Finney via Python-list wrote:
> > Jim Lee  writes:
> >
> >> If you were to say John had 2 apples, Jane had 4 apples, and Joe had
> >> an indefinite number of apples, how many numbers are we talking about?
> > Three numbers. And “indefinite” is not one of those numbers. So, no,
> > that doesn't support “"indefinite" is a number”.
> >
> Exactly.  And you've just confirmed my original argument.  Thanks!

Still no, because you're the only one who claimed "indefinite" is a number.

-- 
 \  “If you saw two guys named Hambone and Flippy, which one would |
  `\   you think liked dolphins the most? I'd say Flippy, wouldn't |
_o__) you? You'd be wrong, though. It's Hambone.” —Jack Handey |
Ben Finney

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


Re: PEP 526 - var annotations and the spirit of python

2018-07-03 Thread Ben Finney via Python-list
Jim Lee  writes:

> If you were to say John had 2 apples, Jane had 4 apples, and Joe had
> an indefinite number of apples, how many numbers are we talking about?

Three numbers. And “indefinite” is not one of those numbers. So, no,
that doesn't support “"indefinite" is a number”.

-- 
 \“That's the essence of science: Ask an impertinent question, |
  `\and you're on the way to the pertinent answer.” —Jacob |
_o__) Bronowski, _The Ascent of Man_, 1973 |
Ben Finney

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


Re: Getting posts to sort chronologically in tree view

2018-07-03 Thread Ben Finney
T Berger  writes:

> I'm posting directly to the forum (computer.lang.python, at this web
> address:
> https://groups.google.com/forum/#!topic/comp.lang.python/vWCvLYjOWUQ)

Thanks for being specific. So, from that description, you are using the
Google Groups web interface to read and send messages in this forum.

That is not “posting directly to the forum”, because this forum doesn't
have a single canonical direct location. (And if it did, that location
would certainly not be Google Groups.)

> And I have to apologize. The threads in my previous conversation,
> ERRNO 48: Address already in use, are so extensive and hierarchical,
> that they appear to be out of order. They're not.

Right. I gather, from many complaints by Google Groups users over many
years, that it is a terrible interface for interacting with any forum.

The lack of proper threading support is just one of many well-known bugs
that Google show no sign of correcting. They show every sign, in fact,
of having no interest in listening to the requests from users of that
software.

Given that history, you might want to avoid Google Groups for
interacting with forums, and choose software that works better with
discussion forums. I am told Mozilla Thunderbird is a good choice, but
there are likely others.

-- 
 \  “Earth gets its price for what Earth gives us.” —James Russell |
  `\Lowell |
_o__)          |
Ben Finney

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


Re: Getting posts to sort chronologically in tree view

2018-07-02 Thread Ben Finney
T Berger  writes:

> Here is another question. I replied to this email in my inbox. But
> it's not showing here.

Please understand that the “here” you mention is subjective, for your
particular view of this forum.

This forum is distributed over many servers, and the participants here
use various different software – even different network protocols – to
interact. Your view, your “here” is *not* universal for the participants
in this forum.

So, if you want help with some specific software, you should ask the
people who support *that software*. This forum is unlikely to be the
best place to get that help.

-- 
 \  “I tell you the truth: this generation will certainly not pass |
  `\   away until all these things [the end of the world] have |
_o__)  happened.” —Jesus, c. 30 CE, as quoted in Matthew 24:34 |
Ben Finney

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


Re: Getting posts to sort chronologically in tree view

2018-07-02 Thread Ben Finney
T Berger  writes:

> Is there any way to set posts to appear chronologically in tree view?

Yes, depending on what software you use to interact with this forum. See
the documentation for that software.

In the case of Gnus, that ordering is the default when viewing the group
summary.

-- 
 \  “The entertainment industry calls DRM "security" software, |
  `\ because it makes them secure from their customers.” —Cory |
_o__) Doctorow, 2014-02-05 |
Ben Finney

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


Re: Should nested classes in an Enum be Enum members?

2018-06-28 Thread Ben Finney
Ethan Furman  writes:

> On 06/28/2018 05:58 PM, Ben Finney wrote:
>
> > So I remain dumbfounded as to why anyone would want a class to *both* be
> > an enumerated type, *and* have callable attributes in its API.
>
> Perhaps I am using Enum incorrectly, but here is my FederalHoliday
> Enum. […]

Thanks for the example. Yes, my personal impression is that class
is not a good use of enum.Enum (nor enum.AutoEnum).

To inherit from enum.Enum (or enum.AutoEnum) signals, to my mind, that
the class is not really intended as a typical Python class, but instead
is intended to be that special beast known as an “enumerated type” which
has little behaviour other than being a namespace for constant values.

Adding all that other stuff just makes it quite unclear what the class
means any more.

-- 
 \ “Pinky, are you pondering what I'm pondering?” “I think so, |
  `\ Brain, but me and Pippi Longstocking — I mean, what would the |
_o__)  children look like?” —_Pinky and The Brain_ |
Ben Finney

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


Re: Should nested classes in an Enum be Enum members?

2018-06-28 Thread Ben Finney
Ian Kelly  writes:

> On Thu, Jun 28, 2018 at 4:38 AM Ben Finney  wrote:
> >
> > Ethan Furman  writes:
> >
> > Specifically, I can't make sense of why someone would want to have a
> > class that is simultaneously behaving as an enumerated type, *and*
> > has an API of custom callable attributes.
>
> You don't see value in enum members having properties?

Is a Python property a callable attribute?

>>> class Lorem:
... @property
... def spam(self):
... print(self)
... 
>>> foo = Lorem()
>>> foo.spam()
<__main__.Lorem object at 0x7ff5078bc710>
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'NoneType' object is not callable

It seems that no, a property is not a callable attribute.

So I remain dumbfounded as to why anyone would want a class to *both* be
an enumerated type, *and* have callable attributes in its API.

-- 
 \  “It's dangerous to be right when the government is wrong.” |
  `\   —Francois Marie Arouet Voltaire |
_o__)  |
Ben Finney

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


Re: Should nested classes in an Enum be Enum members?

2018-06-28 Thread Ben Finney
Ethan Furman  writes:

> Consider the following Enum definition:
>
>   class Color(Enum):
>   RED = 1
>   GREEN = 2
>   BLUE = 3
>   @property
>   def lower(self):
>   return self.name.lower()
>   def spam(self):
>   return "I like %s eggs and spam!" % self.lower
>   class SomeClass:
>   pass

That dumbfounds my intuitions.

Specifically, I can't make sense of why someone would want to have a
class that is simultaneously behaving as an enumerated type, *and* has
an API of custom callable attributes.

> Question:
>
>   Should `SomeClass` be an enum member?  When would it be useful to
>   have an embedded class in an Enum be an enum member?

I can't think of a satisfactory answer to the question “Why is SomeClass
defined inside that enumerated type at all?”

> So I'm asking the community:  What real-world examples can you offer
> for either behavior?

That set is empty.

I'd be going straight to the author of that code; or, if that weren't an
option, re-factoring that code at the next opportunity.

-- 
 \ “Our urge to trust our senses overpowers what our measuring |
  `\ devices tell us about the actual nature of reality.” —Ann |
_o__)       Druyan, _Cosmos_, 2014 |
Ben Finney

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


Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-26 Thread Ben Finney
From: Ben Finney 

Paul Moore  writes:

> On 24 June 2018 at 06:03, Steven D'Aprano
>  wrote:
> > Given this function:
> >
> > def test():
> > a = 1
> > b = 2
> > result = [value for key, value in locals().items()]
> > return result
> >
> > what would you expect the result of calling test() to be? [Γ |]

> I'm aware of the background for this question. Is there any equivalent
> question that doesn't use locals()? The reason I ask is that I see
> locals() as "digging into implementation stuff" and sort of expect it
> to act oddly in situations like this...

My understanding of Steven's question is to give an unambiguous way to:

* Express the question Γ úwhich name bindings do you expect to exist in
  this local function scope, by the time of the Γ  returnΓ ╓ statement?Γ ╪.

* Avoid prejudicing the reader to expect any particular binding to be
  active.

One way to do the first, at the cost of losing the second, might be this::

def test():
a = 1
b = 2
[value for key, value in dict().items()]
print(a)
print(b)
print(key)
print(value)

and then ask Γ úWhich of those statements do you expect to fail with
NameError?Γ ╪.

But I may have misunderstood some nuance of what is being asked, which is to be
 expected because Steven was deliberately trying to avoid having the reader
second-guess what the purpose of the code is.

--
 \ Γ úI wish there was a knob on the TV to turn up the intelligence. |
  `\  There's a knob called Γ  brightnessΓ ╓ but it doesn't work.Γ ╪ |
_o__) Γ ÷Eugene P. Gallagher |
Ben Finney

--- BBBS/Li6 v4.10 Toy-3
 * Origin: Prism bbs (1:261/38)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Anyone here on Python-Dev mailing list?

2018-06-26 Thread Ben Finney
From: Ben Finney 

Steven D'Aprano  writes:

> Anyone on the Python-Dev mailing list, are you getting private emails
> containing nothing but stream of consciousness word-salad from
> somebody (some bot?) calling himself "Chanel Marvin" with a gmail
> address?

I am on that forum (via Gmane), and am not receiving anything like that.

--
 \ Γ úToday, I was Γ ÷ no, that wasn't me.Γ ╪ Γ ÷Steven Wright
|
  `\   |
_o__)          |
Ben Finney

--- BBBS/Li6 v4.10 Toy-3
 * Origin: Prism bbs (1:261/38)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Package directory question

2018-06-26 Thread Ben Finney
From: Ben Finney 

Robert Latest via Python-list  writes:

> Because the main.py script needs to import the tables.py module from
> backend, I put this at the top if main.py:
>
>sys.path.append('../..')
>import jobwatch.backend.tables as tables
>
> My question is: Is this the way it should be done? It looks fishy. The
> only alternative I could come up with is to put a symlink to tables.py
> into the frontend directory, which also seems fishy.

Your fish-sense is working correctly. Both of those are hard-coding the path,
when the Python import mechanism is designed so you don't do that.

Instead, to run the package, first install the package.

To install the package, use the Pip tool. This comes standard when you install
Python 3.

By installing your code, you make it available to be discovered by Python's
normal import mechanism.

So, choose how you want to install the package:

* To install for normal use, Γ  python3 -m pip install Γ |Γ ╓.

* To install for use only by the current user, add the Γ  --userΓ ╓ option.

* To install for use while also developing, add the Γ  --editableΓ ╓ option.

See the Γ  python3 -m pip --helpΓ ╓ document for details about what all that
does.

--
 \Γ úTelling pious lies to trusting children is a form of abuse, |
  `\plain and simple.Γ ╪ Γ ÷Daniel Dennett, 2010-01-12 |
_o__)          |
Ben Finney

--- BBBS/Li6 v4.10 Toy-3
 * Origin: Prism bbs (1:261/38)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: translating foreign data

2018-06-25 Thread Ben Finney
From: Ben Finney 

Richard Damon  writes:

> On 6/23/18 11:27 AM, Steven D'Aprano wrote:
> >> On 6/23/18 9:05 AM, Marko Rauhamaa wrote:
> >>> Richard Damon wrote:
> >>> > Data presented to the user should normally use his locale
> >>> > (unless he has specified something different).
> >>>
> >>> Ok. Here's a value for you:
> >>>
> >>> 100ΓΘ¼
> >>>
> > [Γ |]
> > The data you were given was 100 Euros. If your system is incapable
> > of reading that as 100 Euros, and errors out, then at least to know
> > that it is brain-damaged and useless.
> >
> > But if instead it silently changes the data to $100 (US dollars?
> > Australian dollars? Zimbabwe dollars? the gods only know what a
> > system that broken might do...) then it is not only broken but
> > *dangerously* broken.
> >
> [Γ |]
>
> The number CAN'T say 100 Euros (can you give me what bit pattern you
> would use for such a number).

That is (I believe) the point being made: The data is *not* a number. It is a
value that must encapsulate more than only the number 100, but also and
simultaneously the curency Γ úEuroΓ ╪.

> The currency is encoded in the locale used for the conversion, so if it
> is using en-US, the currency value would ALWAYS be US$ (which the
> general locale format is just $). As such 100ΓΘ¼ is an invalid input to a
> system getting a Locale based input for a currency if the locale is not
> one from a country that uses the euro.

The value is 100 Euro, a quantity of a particular currency and not something
trivially converted to US$ (for many reasons, including the obvious one that we
 don't know the exact exchange rate to use, and it will be different at a
different time).

You appear to be arguing that this value must either be arbitrarily converted
to the user's local currency, something we agree is impossible to do given the
data, or the value is simply invalid.

So the rule you assert Γ ⌠ Γ úData presented to the user should normally use
his localeΓ ╪ Γ ⌠ fails to usefuly handle the very normal case of data that
represents a quantity of some foreign currency. Any system following your
asserted rule will give either the wrong answer, or an error. We had better
hope the rule you assert is not in effect.

--
 \ Γ úDRM doesn't inconvenience [lawbreakers] Γ ÷ indeed, over time it |
  `\ trains law-abiding users to become [lawbreakers] out of sheer |
_o__)frustration.Γ ╪ Γ ÷Charles Stross, 2010-05-09 |
Ben Finney

--- BBBS/Li6 v4.10 Toy-3
 * Origin: Prism bbs (1:261/38)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-24 Thread Ben Finney
Paul Moore  writes:

> On 24 June 2018 at 06:03, Steven D'Aprano
>  wrote:
> > Given this function:
> >
> > def test():
> > a = 1
> > b = 2
> > result = [value for key, value in locals().items()]
> > return result
> >
> > what would you expect the result of calling test() to be? […]

> I'm aware of the background for this question. Is there any equivalent
> question that doesn't use locals()? The reason I ask is that I see
> locals() as "digging into implementation stuff" and sort of expect it
> to act oddly in situations like this...

My understanding of Steven's question is to give an unambiguous way to:

* Express the question “which name bindings do you expect to exist in
  this local function scope, by the time of the ‘return’ statement?”.

* Avoid prejudicing the reader to expect any particular binding to be
  active.

One way to do the first, at the cost of losing the second, might be
this::

def test():
a = 1
b = 2
[value for key, value in dict().items()]
print(a)
print(b)
print(key)
print(value)

and then ask “Which of those statements do you expect to fail with
NameError?”.

But I may have misunderstood some nuance of what is being asked, which
is to be expected because Steven was deliberately trying to avoid having
the reader second-guess what the purpose of the code is.

-- 
 \ “I wish there was a knob on the TV to turn up the intelligence. |
  `\  There's a knob called ‘brightness’ but it doesn't work.” |
_o__) —Eugene P. Gallagher |
Ben Finney

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


Re: Anyone here on Python-Dev mailing list?

2018-06-24 Thread Ben Finney
Steven D'Aprano  writes:

> Anyone on the Python-Dev mailing list, are you getting private emails
> containing nothing but stream of consciousness word-salad from
> somebody (some bot?) calling himself "Chanel Marvin" with a gmail
> address?

I am on that forum (via Gmane), and am not receiving anything like that.

-- 
 \ “Today, I was — no, that wasn't me.” —Steven Wright |
  `\   |
_o__)          |
Ben Finney

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


Re: Package directory question

2018-06-24 Thread Ben Finney
Robert Latest via Python-list  writes:

> Because the main.py script needs to import the tables.py module from
> backend, I put this at the top if main.py:
>
>sys.path.append('../..')
>import jobwatch.backend.tables as tables
>
> My question is: Is this the way it should be done? It looks fishy. The
> only alternative I could come up with is to put a symlink to tables.py
> into the frontend directory, which also seems fishy.

Your fish-sense is working correctly. Both of those are hard-coding the
path, when the Python import mechanism is designed so you don't do that.

Instead, to run the package, first install the package.

To install the package, use the Pip tool. This comes standard when you
install Python 3.

By installing your code, you make it available to be discovered by
Python's normal import mechanism.

So, choose how you want to install the package:

* To install for normal use, ‘python3 -m pip install …’.

* To install for use only by the current user, add the ‘--user’ option.

* To install for use while also developing, add the ‘--editable’ option.

See the ‘python3 -m pip --help’ document for details about what all that
does.

-- 
 \“Telling pious lies to trusting children is a form of abuse, |
  `\plain and simple.” —Daniel Dennett, 2010-01-12 |
_o__)          |
Ben Finney

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


Re: translating foreign data

2018-06-23 Thread Ben Finney
Richard Damon  writes:

> On 6/23/18 11:27 AM, Steven D'Aprano wrote:
> >> On 6/23/18 9:05 AM, Marko Rauhamaa wrote:
> >>> Richard Damon wrote:
> >>> > Data presented to the user should normally use his locale
> >>> > (unless he has specified something different).
> >>>
> >>> Ok. Here's a value for you:
> >>>
> >>> 100€
> >>>
> > […]
> > The data you were given was 100 Euros. If your system is incapable
> > of reading that as 100 Euros, and errors out, then at least to know
> > that it is brain-damaged and useless.
> >
> > But if instead it silently changes the data to $100 (US dollars?
> > Australian dollars? Zimbabwe dollars? the gods only know what a
> > system that broken might do...) then it is not only broken but
> > *dangerously* broken.
> >
> […]
>
> The number CAN'T say 100 Euros (can you give me what bit pattern you
> would use for such a number).

That is (I believe) the point being made: The data is *not* a number. It
is a value that must encapsulate more than only the number 100, but also
and simultaneously the curency “Euro”.

> The currency is encoded in the locale used for the conversion, so if it
> is using en-US, the currency value would ALWAYS be US$ (which the
> general locale format is just $). As such 100€ is an invalid input to a
> system getting a Locale based input for a currency if the locale is not
> one from a country that uses the euro.

The value is 100 Euro, a quantity of a particular currency and not
something trivially converted to US$ (for many reasons, including the
obvious one that we don't know the exact exchange rate to use, and it
will be different at a different time).

You appear to be arguing that this value must either be arbitrarily
converted to the user's local currency, something we agree is impossible
to do given the data, or the value is simply invalid.

So the rule you assert – “Data presented to the user should normally use
his locale” – fails to usefuly handle the very normal case of data that
represents a quantity of some foreign currency. Any system following
your asserted rule will give either the wrong answer, or an error. We
had better hope the rule you assert is not in effect.

-- 
 \ “DRM doesn't inconvenience [lawbreakers] — indeed, over time it |
  `\ trains law-abiding users to become [lawbreakers] out of sheer |
_o__)frustration.” —Charles Stross, 2010-05-09 |
Ben Finney

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


Re: Is it possible to call a class but without a new instance created?

2018-06-18 Thread Ben Finney
Jach Fong  writes:

> Although it passed the first examination, I have no idea if it can
> work correctly in the real application:-)

Neither do I. What is the real-world problem you are trying to solve?
Why do you think this (and not some more idiomatic Python feature) is
needed for solving that problem?

-- 
 \ “The Vatican is not a state.… a state must have territory. This |
  `\ is a palace with gardens, about as big as an average golf |
_o__) course.” —Geoffrey Robertson, 2010-09-18 |
Ben Finney

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


Re: Is it possible to call a class but without a new instance created?

2018-06-18 Thread Ben Finney
Jach Fong  writes:

> I also make a test of my own and it fails too.
>
> >>> class A:
> ... objs = []
> ... def __init__(self, exists=False):
> ... if exists:  self = self.objs[0]

The function parameters (bound here to the names ‘self’, ‘exists’) are
in the local function scope. After the function ends, the scope of those
names ends; those name bindings no longer affect anything. So, changing
what ‘self’ refers to has no effect on the A instance that exists.

In other words: Creating the instance is the responsibility of the
constructor method (a class method named ‘__new__’), and that instance
is what gets passed to the instance initialiser (an instance method
named ‘__init__’).

The initialiser has no control over what instance gets passed in, and no
control over that same instance being returned from the constructor.

> What I expect is that id(a0) and id(a1) has the same value. They
> should points to the same object.

You can't get that effect from within the instance initialiser. What you
need to do is change the class constructor (named ‘__new__’), and that's
a more advanced topic I leave you to research on your own.

-- 
 \  “Now Maggie, I’ll be watching you too, in case God is busy |
  `\   creating tornadoes or not existing.” —Homer, _The Simpsons_ |
_o__)          |
Ben Finney

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


Re: Metasyntactic thingies

2018-06-17 Thread Ben Finney
Steven D'Aprano  writes:

> But what placeholder names do you use for functions, methods or other
> actions? As in, placeholder verbs rather than nouns?

I find Lewis Carroll's canon to be a rich source of pronounceable
nonsense words. The poem Jabberwocky is particularly valuable
https://en.wikipedia.org/wiki/Jabberwocky#Lexicon>.

The trouble with doesn't-mean-anything words is that they quickly
*acquire* meaning. Many of the words that were unknown before
Jabberwocky have since entered the English language as accepted standard
words.

This is going on all the time. The term “widget” was once a deliberately
abstract unit of manufacture, a metasyntactic word for discussion of
economics deliberately chosen because it had no concrete meaning. It has
since gained concrete meaning, and would be too confusing to use it
today without disambiguating https://en.wikipedia.org/wiki/Widget>.

Another good example is the word “goon”. In the early 20th century, the
word was not widespread enough to have a fixed, determined meaning
https://en.wiktionary.org/wiki/goon>, and the Popeye cartoon used
it as a name for a strange grotesque giant in 1933. That word, perhaps
more than the character, inspired the title of The Goon Show in the
1950s https://en.wikipedia.org/wiki/The_Goon_Show>. Simultaneously,
the word was *also* used to mean a hired thug.

Words were so freely appropriated and gleefully mangled to surreal
effect in The Goon Show that it, too, is a rich source of such
semi-comprehensible words, good for use as metasyntactic tokens.

So all told, English is particularly prone to have seeming nonsense
words enter common use and people *apply* one or more meanings; the
metasyntactic usage is thus undermined. So it goes.

> Aside from such boring ones as "do_work" and similar, the only
> placeholder verb I can think of is frobnicate.
>
> Does anyone else have any?

I tend to riff on Latinate word constructions in the same vein as
“frobnicate”. I also try to channel The Goon Show when I need a
metasyntactic word. Some recent ones include “spunge”, “nardle”, “crun”,
etc.

-- 
 \ “Pinky, are you pondering what I'm pondering?” “I think so, |
  `\   Brain, but where are we going to find a duck and a hose at this |
_o__)    hour?” —_Pinky and The Brain_ |
Ben Finney

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


Re: syntax difference

2018-06-17 Thread Ben Finney
Chris Angelico  writes:

> Also: I would call that a "note", not a "warning". Please stop
> spreading the FUD that there's somehow something "wrong" with using
> what is a well-known convention for a format mini-language.

If I say there's something “wrong” with it (is that different from
saying there's something wrong with it? I am not sure the function of
the quotes you use there), I'm not aware. I haven't stated the
printf-style formatting is especially prone to official deprecation.

As for a clear *preference*, as presented in the Python documentation,
for ‘str.format’ rather than printf-style, I'll continue to spread that
implication which seems a pretty uncontroversial reading of the Python
documentation.

-- 
 \“Beware of bugs in the above code; I have only proved it |
  `\ correct, not tried it.” —Donald Knuth, 1977-03-29 |
_o__)          |
Ben Finney

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


Re: syntax difference

2018-06-17 Thread Ben Finney
Chris Angelico  writes:

> On Sun, Jun 17, 2018 at 3:30 PM, Ben Finney  
> wrote:
> > (or, if you want to continue with the older less-flexible style,

(I gave an unhelpful URL for that documentation. Try this instead
https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting>.)

> For the record, there's nothing at all wrong with printf-style
> formatting; its flexibility and brevity make it extremely useful in
> many situations.

That isn't the impression I get from the above documentation. It starts
with a clearly worded warning:

Note

The formatting operations described here exhibit a variety of quirks
that lead to a number of common errors (such as failing to display
tuples and dictionaries correctly). Using the newer formatted string
literals or the str.format() interface helps avoid these errors.
These alternatives also provide more powerful, flexible and
extensible approaches to formatting text.

That states a clear opinion that ‘str.format’ is preferred.

-- 
 \ “True greatness is measured by how much freedom you give to |
  `\  others, not by how much you can coerce others to do what you |
_o__)   want.” —Larry Wall |
Ben Finney

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


Re: syntax difference

2018-06-16 Thread Ben Finney
Sharan Basappa  writes:

> I think I am now confused with format options in Python.

You should refer to the documentation for string formatting
https://docs.python.org/3/library/stdtypes.html#str.format>
https://docs.python.org/3/library/string.html#formatstrings>

(or, if you want to continue with the older less-flexible style,
)

> I tried an example as below and both print proper value:
>
> age = 35
>
> print "age is %s" % age

The ‘s’ format specifier says “Ask the object for its text
representation, and put that text here”.

Every object has a text representation, so ‘s’ works with any object.

> print "age is %d" % age

The ‘d’ format specifier says “Format the integer as a decimal text
representation, and put that text here”.

Only objects that are integers (or that implement the format-as-decimal
API) will work with ‘d’.

> I other languages I know the format specifier should be same as the
> variable type. For example, in the above case, it has to be %d and not
> %s

Because you are explicitly specifying which formatting to use, there's
no ambiguity. With an object that is an integer, either of the above
makes sense in different use cases.

-- 
 \“A right is not what someone gives you; it's what no one can |
  `\ take from you.” —Ramsey Clark |
_o__)      |
Ben Finney

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


Re: Server warning

2018-06-15 Thread Ben Finney
Tamara Berger  writes:

> Is this a serious issue, or can I ignore it? I was just following
> instructions in a manual I consider trustworthy.

(A word of advice: You have recently been asking here for many different
topics – Flask, Google Mail, etc. – that are not the focus of this
forum. That's not a problem for us, but you would be better to seek
specific help for those topics at their specific support forums.

This is not any kind of support forum, it is a discussion forum for the
Python community. You're part of that now, so welcome! But this is not a
forum for getting support when you're needing help.)


The message from Flask is, I believe, both serious *and* you may be able
to ignore it.

If you are not intending to make the server available on the internet,
you are free to ignore it for that case.

You should never expose the development server onto the live internet.
Use a proper WSGI server (its own topic, with more involved steps)
instead.

The development server is much easier to start (which is why it's there,
and why it is recommended when learning), but much less secure (which is
why, before deploying your application, you need to configure a
properly secure WSGI server).

-- 
 \ “[F]reedom of speech does not entail freedom to have your ideas |
  `\accepted by governments and incorporated into law and policy.” |
_o__)   —Russell Blackford, 2010-03-06 |
Ben Finney

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


Re: How to apply filters to posts

2018-06-14 Thread Ben Finney
Dennis Lee Bieber  writes:

> On Fri, 15 Jun 2018 05:39:08 +1000, Ben Finney 
> declaimed the following:
>
> >Don't choose the daily digest, because it makes a special “digest”
> >message for you each day. That message is disconnected from any other
> >message, and so you will not be able to reply correctly to any
>
>   Unless one has a client that can do digest bursting -- if the digest
> provides all the proper headers for each message in it, the burst messages
> should link properly.

At which point, there seems little point in subscribing to the digest:
just get all the actual messages delivered, and use the more powerful
filtering built into the mail client.

-- 
 \  “[Entrenched media corporations will] maintain the status quo, |
  `\   or die trying. Either is better than actually WORKING for a |
_o__)  living.” —ringsnake.livejournal.com, 2007-11-12 |
Ben Finney

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


[issue14102] argparse: add ability to create a man page

2018-06-14 Thread Ben Finney

Ben Finney  added the comment:

On Thu, 2018-06-14 23:46 +, Aaron Meurer  wrote:

> Couldn't such a tool exist outside the standard library.

I've tried writing such a tool. It would ideally re-use as much as feasible of 
the functionality that assembles the usage message. But that is hampered by the 
fact the usage message generation is not easily accessible from outside.

I am hoping that, in order to re-use that functionality, a common set of “take 
the argument collection as input, generate a document structure” functionality 
can be factored out for other use — initially, for generating a manual page.

So this bug report asks for that work to be done in the ‘argparse’ library.

> Installing the manpage is a separate concern.

Yes, I agree. That is not part of this bug report.

--

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



[issue14102] argparse: add ability to create a man page

2018-06-14 Thread Ben Finney

Ben Finney  added the comment:

On Thu, 2018-06-14 20:02 +, Pablo Galindo Salgado  
wrote:
> The (possible) confusion is the existence of a manpage only available 
> though argparse (`./python foo.py --manpage`)

This report isn't asking for that. (I see only one person proposing such an 
interface, and even that person said it's not a good idea.) So please don't 
conflate that with the original bug report.

> I am  not sure how many people do something like `./python poc_2.py > output 
> && man ./output` to **read** the manpage.

Right, I am not asking for anything like that; I'm not asking that ‘argparse’ 
grow a way to read a manual page,. I am asking only for a standard way to 
programmatically generate that manual page from the information ‘argparse’ 
already knows.

> >This is asking that the ‘argparse’ library should have an API to
> >create a manual page, for use in the build system.
> 
> At this point argparse is user facing in the sense that once configured, 
> it provides functionality for the user of the command line application. 
> My opinion is that it will be weird to have it provide also APIs for 
> creating man pages (which is a developer utility).

Creating an argument parser itself is already a developer activity, and we 
don't see that as weird that ‘argparse’ allows for that.

I'm arguing that the library already knows how to turn the argument collection 
into a user-facing document (the usage message), and a manual page is a 
different way of rendering that same internal data. So that's why ‘argparse’ is 
a consistent place to have that functionality.

> My humble opinion is 
> that it if argparse starts to provide APIs for usage at install time is 
> not "doing one thing and doing it well".

That API already exists: the specific ‘ArgumentParser’ is available to be 
imported for a program which defines one. So, the library already provides APIs 
for usage at install time (or any other run-time).

I am asking to make that API more useful for the distribution of programs.

--

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



Re: mutable sequences

2018-06-14 Thread Ben Finney
Larry Martell  writes:

> A string and a list go into a bar. The string asks for a cup of
> coffee. The bartender says "We don't have coffee." The string asks for
> a cup of coffee. The bartender says "I told you we don't have coffee."
> The string asks for a cup of coffee. The bartender says to the list
> "What is wrong with him? Is he deaf?" The list replies, "No, he's
> immutable."

There need to be more bartender scenarios in programming tutorials.

-- 
 \   “The internet's completely over.… Anyway, all these computers |
  `\and digital gadgets are no good. They just fill your head with |
_o__) numbers and that can't be good for you.” —Prince, 2010-07-05 |
Ben Finney

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


Re: How to apply filters to posts

2018-06-14 Thread Ben Finney
T Berger  writes:

> Thanks, Rhodri. One more question. What is a daily digest? I'm
> wondering whether to choose that option.

Don't choose the daily digest, because it makes a special “digest”
message for you each day. That message is disconnected from any other
message, and so you will not be able to reply correctly to any
discussion. It's not appropriate for anyone who wants to also
participate in discussions.

-- 
 \   “I have said to you to speak the truth is a painful thing. To |
  `\  be forced to tell lies is much worse.” —Oscar Wilde, _De |
_o__) Profundis_, 1897 |
Ben Finney

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


[issue14102] argparse: add ability to create a man page

2018-06-14 Thread Ben Finney

Ben Finney  added the comment:

On 14-Jun-2018, Pablo Galindo Salgado wrote:

> I think this should be something that is not included in argparse
> itself. I can imagine a scenario in which the manpage is accessible
> through `./python foo.py --manpage` but the manpage is not installed
> systemwide.

This bug report is not asking that ‘argparse’ install a manual page,
and it is not asking for any new command-line option in programs. So I
don't know the relevance of that point.

> This will be very confusing for users.

What would cause that confusion? This is not something that would
change how ‘argparse’ parses its arguments, so I don't know what
you're referring to.

> Generating a man page in a build script sounds like something that
> should be on its own or as a help function of the build system.

This is asking that the ‘argparse’ library should have an API to
create a manual page, for use in the build system.

The reason to have it in the ‘argparse’ library is that the library
already knows how to build a single document (the ‘--help’ output)
from the collection of arguments, so this would be just another
rendering of that information. It makes sense to have it in the
‘argparse’ library as an API for other tools to use.

--

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



Re: mutable sequences

2018-06-13 Thread Ben Finney
Sharan Basappa  writes:

> For example, Python lists are mutable.

Yes, that's correct.

> BTW, is the below explanation correct (it is taken from a book I am
> reading)
>
> Python lists are mutable sequences. They are very similar to tuples,
> but they don't have the restrictions due to immutability.
>
> It says lists are mutable and then says they are immutable???

The passage is correct, but is ambiguously phrased.

You appear to be parsing it as:

Python lists are mutable sequences. They are very similar to tuples,
but {{they don't have the restrictions} due to immutability}.

which would imply that Python lists are both mutable and are immutable.

Instead, I think the intended parsing is:

Python lists are mutable sequences. They are very similar to tuples,
but {they don't have {the restrictions due to immutability}}.

implying that Python lists are mutable; and then contrasting lists
against Python tuples which have “the restrictions due to immutability”.

Does that help?

You might send the publisher a request to clarify the text in a future
edition.

-- 
 \   “To have the choice between proprietary software packages, is |
  `\  being able to choose your master. Freedom means not having a |
_o__)master.” —Richard M. Stallman, 2007-05-16 |
Ben Finney

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


Re: Why exception from os.path.exists()?

2018-06-07 Thread Ben Finney
Richard Damon  writes:

> This does bring up an interesting point. Since the Unix file system
> really has file names that are collection of bytes instead of really
> being strings, and the Python API to it want to treat them as strings,
> then we have an issue that we are going to be stuck with problems with
> filenames.

I agree with the general statement “we are going to be stuck with
problems with filenames”; the world of filesystems is messy, which will
always cause problems.

With that said, I don't agree that “the Python API wants to treat
[file paths] as strings”. The ‘os’ module explicitly promises to treat
bytes as bytes, and text as text, in filesystem paths:

Note: All of these functions accept either only bytes or only string
objects as their parameters. The result is an object of the same
type, if a path or file name is returned.

https://docs.python.org/3/library/os.path.html>

There is a *preference* for text, it's true. The opening paragraph
includes this:

Applications are encouraged to represent file names as (Unicode)
character strings.

That is immediately followed by more specific advice that says when to
use bytes:

Unfortunately, some file names may not be representable as strings
on Unix, so applications that need to support arbitrary file names
on Unix should use bytes objects to represent path names. Vice
versa, using bytes objects cannot represent all file names on
Windows (in the standard mbcs encoding), hence Windows applications
should use string objects to access all files.

(That needs IMO a correction, because as already explored in this
thread, it's not Unix or Windows that makes the distinction there. It's
the specific *filesystem type* which records either bytes or text, and
that is true no matter what operating system happens to be reading the
filesystem.)

> Ultimately we have a fundamental limitation with trying to abstract out
> the format of filenames in the API, and we need a back door to allow us
> to define what encoding to use for filenames (and be able to detect that
> it doesn't work for a given file, and change it on the fly to try
> again), or we need an alternate API that lets us pass raw bytes as file
> names and the program needs to know how to handle the raw filename for
> that particular file system.

Yes, I agree that there is an unresolved problem to explicitly declare
the encoding for filesystem paths on ext4 and other filesystems where
byte strings are used for filesystem paths.

-- 
 \   “Give a man a fish, and you'll feed him for a day; give him a |
  `\religion, and he'll starve to death while praying for a fish.” |
_o__)       —Anonymous |
Ben Finney

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


Re: Valid encodings for a Python source file

2018-06-07 Thread Ben Finney via Python-list
Daniel Glus  writes:

> I'm trying to figure out the entire list of possible encodings for a Python
> source file - that is, encodings that can go in a PEP 263
> <https://www.python.org/dev/peps/pep-0263/> encoding specification, like #
> -*- encoding: foo -*-.

What if the answer is not an emunerated set of encodings? That is, I am
pretty sure the set isn't specified, to allow the encoding to be
negotiated. Whatever the interpreter recognises as an encoding can be
the encoding of the source.

So, I guess that leads to the question: Why do you need it to be an
exhaustive set (rather than deliberately unspecified)? What are you
hoping to do with that information?

-- 
 \   “Good design adds value faster than it adds cost.” —Thomas C. |
  `\  Gale |
_o__)          |
Ben Finney

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


Re: Attachments

2018-06-05 Thread Ben Finney
"Peter J. Holzer"  writes:

> Then the statement
>
> | (For good reasons, attachments are dropped when messages are
> | distributed on the forum.)
>
> was demonstrable false (at least overly general) as the attachment in
> Jach's message wasn't dropped.

Try this more precise statement, then:

Many attachments are dropped when distributed on this forum, to the
extent that one should expect attachments will tend not survive
distribution on this forum.

> (I remember that I have seen some messages in the past where an
> attachment was obviously missing. Maybe specific content types are
> stripped, but not attachments in general)

Yes. There may be exceptions, but “don't expect that readers of this
forum can see your attachments” is a good rule to operate by.

-- 
 \  “Writing a book is like washing an elephant: there no good |
  `\place to begin or end, and it's hard to keep track of what |
_o__)  you've already covered.” —anonymous |
Ben Finney

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


Re: Attachments

2018-06-04 Thread Ben Finney
"Peter J. Holzer"  writes:

> So we have determined that "the forum" is not the mailing list and not
> the newsgroup (Jach's message appeared on both with the attachment).

By “the forum” I don't mean any specific server to the exclusion of
others. I mean the aggregate forum in which we are having this
discussion: comp.lang.python and python-list are a single discussion
forum, distributed across many servers.

-- 
 \“If you go parachuting, and your parachute doesn't open, and |
  `\you friends are all watching you fall, I think a funny gag |
_o__) would be to pretend you were swimming.” —Jack Handey |
Ben Finney

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


Re: How can an int be '+' with a tuple?

2018-06-02 Thread Ben Finney
Jach Fong  writes:

> The attached is a script

Thanks for making an example script. Instead of attaching it, please
post it along with your message so that everyone can read it. You can
make scripts suitable for posting in your message, by keeping them short
and simple http://sscce.org/>.

(For good reasons, attachments are dropped when messages are distributed
on the forum.)

> One thing make me puzzled is that the "any + context" at line
> 18. The "any" was passed as an integer from line 43 and the "context"
> was defined as a tuple at line 35. This concatenation works! how?

If the values are actually as you say, then Python should raise a
TypeError. For example::

>>> 1 + ("foo", "bar")
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unsupported operand type(s) for +: 'int' and 'tuple'

What makes me suspect that's different from your code, is that you say
“defined as a tuple”. Names in Python have no defined type; only an
object has a type, and operations (like ‘+’ only take effect on the
object, not the name.

-- 
 \ “I went to the cinema, it said ‘Adults: $5.00, Children $2.50’. |
  `\  So I said ‘Give me two boys and a girl.’” —Steven Wright |
_o__)  |
Ben Finney

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


Re: '_' and '__'

2018-05-26 Thread Ben Finney
Mike McClain <mike.junk...@att.net> writes:

> Steven D'Aprano and Ben Finney used these '_' and '__'.
> Steve said, "[[] for _ in range(5)]".
> Ben said, "[ [] for __ in range(5) ]".
>
> These aren't listed separately in the index

That's right, the names ‘_’ and ‘__’ have no special meaning in
Python-the-language so they don't appear in the index.

Steven and I both used those respective names to communicate “never
going to use this value but the syntax requires a name here”.

> where might I find written discussion of these?

I find Nick Coghlan's answer on StackOverflow
<URL:https://stackoverflow.com/questions/5893163/what-is-the-purpose-of-the-single-underscore-variable-in-python/5893946#5893946>
to be especially helpful.

Nick also explains that, because the name ‘_’ has too many conventional
meanings already, the name ‘__’ is better for “don't need this value but
I am required to specify a name”.

-- 
 \ “The double standard that exempts religious activities from |
  `\   almost all standards of accountability should be dismantled |
_o__)   once and for all.” —Daniel Dennett, 2010-01-12 |
Ben Finney

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


Re: Some Issues on Tagging Text

2018-05-25 Thread Ben Finney
Cameron Simpson <c...@cskk.id.au> writes:

> On 25May2018 04:23, Subhabrata Banerjee <subhabangal...@gmail.com> wrote:
> >On Friday, May 25, 2018 at 3:59:57 AM UTC+5:30, Cameron Simpson wrote:
> >> If you want to solve this problem with a programme you must first
> >> clearly define what makes an unwanted tag "unwanted". [...]
> >
> >By unwanted I did not mean anything so intricate.
> >Unwanted meant things I did not want.
>
> That much was clear, but you need to specify in your own mind
> _precisely_ what makes some things unwanted and others wanted. Without
> concrete criteria you can't write code to implement those criteria.

Importantly, “define” means more than just coming up with examples.

To determine with precision; to mark out with distinctness; to
ascertain or exhibit clearly.

<URL:https://en.wiktionary.org/wiki/define>

Before you can write code that will *reliably* select those parts you
want and exclude those parts you don't want, you need to precisely
define what should be matched such that it also excludes what should not
be matched.

Come up with statements about what you want, and ask “if *any* text
matches this, does that necessarily mean it is wanted?”

Then do exactly the same in reverse: “if *any* text fails to match this,
does that necessarily mean it is unwanted?”

Keep refining your statement until it is precise enough that you can say
“yes” to both those questions.

Then, you have a statement that is precise enough to write tests for,
and therefore to write in code.

-- 
 \   “I have always wished for my computer to be as easy to use as |
  `\   my telephone; my wish has come true because I can no longer |
_o__)  figure out how to use my telephone.” —Bjarne Stroustrup |
Ben Finney

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


Re: List replication operator

2018-05-24 Thread Ben Finney
Paul <tallp...@gmail.com> writes:

> How would one make a multi-dimensional list now, with truly-separate sub
> lists?  Is there just no way to do it with the replication operator? IE,
> would I just have to do
>   X = [[], [], [], [], []]

The expressions in a comprehension are evaluated each time through. So
this is another way to get that result:

foo = [ [] for __ in range(5) ]

-- 
 \ “We now have access to so much information that we can find |
  `\  support for any prejudice or opinion.” —David Suzuki, 2008-06-27 |
_o__)          |
Ben Finney

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


Re: how to handle captcha through machanize module or any module

2018-05-23 Thread Ben Finney
Jai <jaiprakashsingh...@gmail.com> writes:

> please do replay how to handle captcha through machanize module 

Step 1: ‘import mechanize’.

Step 2: be an actual human, and interact manually with the CAPTCHA.

If you are attempting to fool a CAPTCHA with an automated tool, you are
entering an arms race against those who design the CAPTCHA to *prevent*
exactly what you're doing.

Any technique someone can describe to fool the CAPTCHA, will most likely
already be considered as part of the design of the more effective
CAPTCHAs, and so the technique will still not actually work reliably.

So, there is no general answer, other than to stop thinking that's a
race that you can win.

-- 
 \ “DRM doesn't inconvenience [lawbreakers] — indeed, over time it |
  `\ trains law-abiding users to become [lawbreakers] out of sheer |
_o__)frustration.” —Charles Stross, 2010-05-09 |
Ben Finney

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


Re: "Data blocks" syntax specification draft

2018-05-21 Thread Ben Finney
Ned Batchelder <n...@nedbatchelder.com> writes:

> You've proposed it and asked for feedback, but you seem to be
> completely ignoring the feedback people are giving you.

Another problem with the proposal: The motivation to introduce such a
large change is not compelling. What is the problem this proposal aims
to solve? Why solve it with such a large amount of fundamental change,
when (as discussed in this thread) there are apparently many existing
solutions that work well?

If there's a problem that existing solutions are not addressing well,
the proposal needs to do the work of explicitly stating the problem and
its constraints, demonstrating an understanding of those existing
solutions and how they are inadequate to the explicitly described
problem.

-- 
 \ “If you can do no good, at least do no harm.” —_Slapstick_, |
  `\ Kurt Vonnegut |
_o__)      |
Ben Finney

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


Re: what does := means simply?

2018-05-17 Thread Ben Finney
Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> writes:

> If you want to *really* see code that is hard to port, you should try
> porting an Inform 7 program to another language. Any other language.

Does porting Inform 7 code to Inform 6 count? They are very different
languages :-)

-- 
 \  “Puritanism: The haunting fear that someone, somewhere, may be |
  `\ happy.” —Henry L. Mencken |
_o__)      |
Ben Finney

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


Re: object types, mutable or not?

2018-05-16 Thread Ben Finney
Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> writes:

> On Wed, 16 May 2018 11:30:26 +1000, Ben Finney wrote:
>
> > An object is not a value; an object *has* a value. The object
> > retains its identity even when its value changes.
>
> Here you have hit on the crux of the matter. Why cannot both
> statements be true?

The above assertion was in the context of saying what is pedagogically
useful.

If we have someone with the patience of a philosophy academic, one can
of course choose to explore the definitions of all terms. Then, by
choosing the definitions appropriately, we can make those statements
both true.

For teaching Python, we should not assume that kind of limitless
patience for ruthlessly abandoning prior meanings of terms before using
them.

For the purpose of teaching Python, I maintain that teaching “every
value is an object” will lead the learner to infer “an object is
whatever the value is”. That's a false inference, and we should avoid it
by not stating such an equivalence in the first place.

So, no, I think the more useful – and less problematic – framing is that
every object *has* a value, and mutable objects may change to a
different value while remaining the same object.

-- 
 \  “He who allows oppression, shares the crime.” —Erasmus Darwin, |
  `\ grandfather of Charles Darwin |
_o__)          |
Ben Finney

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


Re: object types, mutable or not?

2018-05-15 Thread Ben Finney
Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> writes:

> On Tue, 15 May 2018 07:29:39 -0700, Mike McClain wrote:
>
> > I had gotten the impression that everything in OOP is an object but
> > you're all saying that variables are not objects.
>
> Perhaps it is better to say every VALUE in Python is an object.

IMO that is better than using the term “variable”, which carries baggage
from other languages when people try learning Python.

But not good enough. It was you, Steven (I think?) who taught me that
using the term “value” interchangeably with “object” is problematic.

That's because, in Python an object can remain the same object, while
its value changes.

>>> foo = [1, 2, 3]# A new list now exists.
>>> foo.append(4)  # It's the same object, but now its value is 
different.

Therefore, an object is not its value (otherwise, when the value
changes, we necessarily have a different object. That's false, and so
the equivalence is also false.)

An object is not a value; an object *has* a value. The object retains
its identity even when its value changes.

> Variables *hold* values, or if you prefer, names refer to values. But
> since they aren't themselves values, names/variables aren't objects.

I really want that sentence to be useful for this pedagogical purpose.
My earlier message in this thread went to some length to do something
similar.

But because we only invite later confusion when the “a value is an
object” false equivalence needs un-learning, I can't let it pass.

-- 
 \“The idea that He would take his attention away from the |
  `\   universe in order to give me a bicycle with three speeds is |
_o__)  just so unlikely that I can't go along with it.” —Quentin Crisp |
Ben Finney

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


Re: What's the rationale for b"..." in this example?

2018-05-15 Thread Ben Finney
Skip Montanaro <skip.montan...@gmail.com> writes:

> Consider this:
>
> >>> bytes("abc", encoding="utf-8")
> b'abc'
>
> Looks reasonable. Then consider this:
>
> >>> str(bytes("abc", encoding="utf-8"))
> "b'abc'"
>
> Why is the b'...' bit still there?

Because the bytes object is asked for a text representation of itself,
and the text value ‘b'abc'’ is what it returned.

> I suppose it's because I didn't tell it explicitly how to decode the
> bytes object, as when I do, I get the expected result:
>
> >>> str(bytes("abc", encoding="utf-8"), encoding="utf-8")
> 'abc'

Yes.

> Coming from a still largely Python 2 perspective, did all attempts to
> apply default encodings disappear in Python 3?

To the extent I understand that question, the answer is no.

Rather, the ‘bytes’ and ‘str’ types are now entirely incompatible, and
implicit conversions are never done between them. Any conversions
between them must be explicit.

-- 
 \“There are always those who think they know what is your |
  `\  responsibility better than you do.” —Ralph Waldo Emerson |
_o__)  |
Ben Finney

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


Re: object types, mutable or not?

2018-05-15 Thread Ben Finney
Mike McClain <mike.junk...@att.net> writes:

> Many thanks to those teachers who responded.

Thank you for asking the question in a way that allows the discussion
:-)

> I think I got it.
> The variable is not the object just as the name is not the thing.

Yes. The term “variable” is so overloaded, for people new to Python,
that I prefer to avoid it altogether. I discuss Python's assignment
behaviour in terms of binding and references.

> I had gotten the impression that everything in OOP is an object

That is definitely not true. There are many languages that support OOP
where *not* everything is an object.

See 
<URL:https://en.wikipedia.org/wiki/Object-oriented_programming#OOP_languages.

> but you're all saying that variables are not objects.

Yes. In the “everything is an object” adage, it's important to realise
what ontology is being used — what “things” exist.

It would be more accurate to say “every value is an object”, but that
gets into how “value” has technical meanings and is IMO less helpful
than “everything is an object”.

A different formulation to make it more accurate would be “everything
that can be addressed by an expression is an object”. Not as catchy, and
I don't expect to see it used as often :-)

The point being, there are many things *we* can talk about which don't
“exist” as things in the context of that adage. Numbers, file handles,
data structures all are “things” and therefore are objects in Python.

Variables, sequence indexes, memory locations, names, statements are
concepts with meaning when *talking about* Python, but are not “things”
that have a value in a Python expression. Because they are not “things”
in Python, those are not objects in Python.

The adage is intended (IIUC) to contrast with languages other than
Python that *do* support OOP, but where *not* everything is an object.
Examples include Java, PHP, Pascal.

> Does a variable have a type?

No, because in Python, “variable” refers to the *binding* between a
reference and an object. In that binding, only the object has a type,
and its type is totally unaffected by whatever references are bound to
that object.

> If so what is the type of a variable and how is that demonstrated
> if 'type()' reports what the variable points to?

This is an illustration of why I don't find “variable” a helpful term
for discussing Python behaviour.

Instead, an expression like ‘type(foo)’ is better understood as getting
the type of object that the name ‘foo’ references.

It doesn't make sense to ask “what is the type of foo” if you're
thinking of ‘foo’ the name. The type is not a property of the name and
not a property of the name–object binding (the “variable”). The type is
a property of the object.

-- 
 \ “It is the fundamental duty of the citizen to resist and to |
  `\  restrain the violence of the state.” —Noam Chomsky, 1971 |
_o__)          |
Ben Finney

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


  1   2   3   4   5   6   7   8   9   10   >