Re: '_' and '__'

2018-05-27 Thread Karsten Hilbert
On Sun, May 27, 2018 at 10:36:30AM +1000, Ben Finney wrote:

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

_() is often bound to gettext.gettext() in the global
namespace, so we'd better avoid that or else ...

[ _(_) for _ in '123' ]

... will fail :-)

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


Re: Some Issues on Tagging Text

2018-05-27 Thread subhabangalore
On Sunday, May 27, 2018 at 2:41:43 AM UTC+5:30, Cameron Simpson wrote:
> On 26May2018 04:02, Subhabrata Banerjee  wrote:
> >On Saturday, May 26, 2018 at 3:54:37 AM UTC+5:30, Cameron Simpson wrote:
> >> It sounds like you want a more general purpose parser, and that depends 
> >> upon
> >> your purposes. If you're coding to learn the basics of breaking up text, 
> >> what
> >> you're doing is fine and I'd stick with it. But if you're just after the
> >> outcome (tags), you could use other libraries to break up the text.
> >>
> >> For example, the Natural Language ToolKit (NLTK) will do structured 
> >> parsing of
> >> text and return you a syntax tree, and it has many other facilities. Doco:
> >>
> >>   http://www.nltk.org/
> >>
> >> PyPI module:
> >>
> >>   https://pypi.org/project/nltk/
> >>
> >> which you can install with the command:
> >>
> >>   pip install --user nltk
> >>
> >> That would get you a tree structure of the corpus, which you could process 
> >> more
> >> meaningfully. For example, you could traverse the tree and tag higher level
> >> nodes as you came across them, possibly then _not_ traversing their inner
> >> nodes. The effect of that would be that if you hit the grammatic node:
> >>
> >>   government of Mexico
> >>
> >> you might tags that node with "ORGANISATION", and choose not to descend 
> >> inside
> >> it, thus avoiding tagging "government" and "of" and so forth because you 
> >> have a
> >> high level tags. Nodes not specially recognised you're keep descending 
> >> into,
> >> tagging smaller things.
> >>
> >> Cheers,
> >> Cameron Simpson
> >
> >Dear Sir,
> >
> >Thank you for your kind and valuable suggestions. Thank you for your kind 
> >time too.
> >I know NLTK and machine learning. I am of belief if I may use language 
> >properly we need machine learning-the least.
> 
> I have similar beliefs: not that machine learning is not useful, but that it 
> has a tendency to produce black boxes in terms of the results it produces 
> because its categorisation rules are not overt, rather they tend to be side 
> effects of weights in a graph.
> 
> So one might end up with a useful tool, but not understand how or why it 
> works.
> 
> >So, I am trying to design a tagger without the help of machine learning, by 
> >simple Python coding. I have thus removed standard Parts of Speech(PoS) or 
> >Named Entity (NE) tagging scheme.
> >I am trying to design a basic model if required may be implemented on any 
> >one of these problems.
> >Detecting longer phrase is slightly a problem now I am thinking to employ 
> >re.search(pattern,text). If this part is done I do not need machine 
> >learning. 
> >Maintaining so much data is a cumbersome issue in machine learning.
> 
> NLTK is not machine learning (I believe). It can parse the corpus for you, 
> emitting grammatical structures. So that would aid you in recognising words, 
> phrases, nouns, verbs and so forth. With that structure you can then make 
> better decisions about what to tag and how.
> 
> Using the re module is a very hazard prone way of parsing text. It can be 
> useful for finding fairly fixed text, particularly in machine generated text, 
> but it is terrible for prose.
> 
> Cheers,
> Cameron Simpson 

Dear Sir, 

Thank you for your kind time to discuss the matter. 
I am very clear in Statistics but as I am a Linguist too I feel the modern day
craziness on theories is going no where. Many theories but hardly anything of
practical value, bit like post Chomskyan Linguistics scenario. Theories of 
parsing
are equally bad. Only advantage of statistics is if it is not giving result you 
may 
abandon them quickly. 

I do not feel Parsing theories of Linguistics lead anywhere esp if data is 
really big. 

I am looking for patterns. Like if you say Organizations in documents are 
mostly all
capital lettered acronyms. So no need of taking ML solution for that rather a 
simple
code line of [word for word in words if word.isupper()] does the job. In the 
same way
there are many interesting patterns in language if you observe them. I made 
many, making
many more. All you need some good time to observe the data patiently. 

NLTK is a library mainly built for students practice but now everyone uses it. 
They have many corpora and tools (most of them are built with ML based 
approach),
but they have many more ML libraries which you may use on user defined data and 
standard.
NLTK integrates nicely with other Python based libraries like Scikit or Gensim 
or Java based 
ones like Stanford. The code lines are nicely documented if you feel you may 
read as proper
references are mostly given. 

I got good results in re earlier but I would surely check your point.

Thank you again for your kind time and a nice discussion.




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


Re: Some Issues on Tagging Text

2018-05-27 Thread Richard Damon
On 5/27/18 7:43 AM, subhabangal...@gmail.com wrote:
> On Sunday, May 27, 2018 at 2:41:43 AM UTC+5:30, Cameron Simpson wrote:
>> On 26May2018 04:02, Subhabrata Banerjee  wrote:
>>> On Saturday, May 26, 2018 at 3:54:37 AM UTC+5:30, Cameron Simpson wrote:
 It sounds like you want a more general purpose parser, and that depends 
 upon
 your purposes. If you're coding to learn the basics of breaking up text, 
 what
 you're doing is fine and I'd stick with it. But if you're just after the
 outcome (tags), you could use other libraries to break up the text.

 For example, the Natural Language ToolKit (NLTK) will do structured 
 parsing of
 text and return you a syntax tree, and it has many other facilities. Doco:

   http://www.nltk.org/

 PyPI module:

   https://pypi.org/project/nltk/

 which you can install with the command:

   pip install --user nltk

 That would get you a tree structure of the corpus, which you could process 
 more
 meaningfully. For example, you could traverse the tree and tag higher level
 nodes as you came across them, possibly then _not_ traversing their inner
 nodes. The effect of that would be that if you hit the grammatic node:

   government of Mexico

 you might tags that node with "ORGANISATION", and choose not to descend 
 inside
 it, thus avoiding tagging "government" and "of" and so forth because you 
 have a
 high level tags. Nodes not specially recognised you're keep descending 
 into,
 tagging smaller things.

 Cheers,
 Cameron Simpson
>>> Dear Sir,
>>>
>>> Thank you for your kind and valuable suggestions. Thank you for your kind 
>>> time too.
>>> I know NLTK and machine learning. I am of belief if I may use language 
>>> properly we need machine learning-the least.
>> I have similar beliefs: not that machine learning is not useful, but that it 
>> has a tendency to produce black boxes in terms of the results it produces 
>> because its categorisation rules are not overt, rather they tend to be side 
>> effects of weights in a graph.
>>
>> So one might end up with a useful tool, but not understand how or why it 
>> works.
>>
>>> So, I am trying to design a tagger without the help of machine learning, by 
>>> simple Python coding. I have thus removed standard Parts of Speech(PoS) or 
>>> Named Entity (NE) tagging scheme.
>>> I am trying to design a basic model if required may be implemented on any 
>>> one of these problems.
>>> Detecting longer phrase is slightly a problem now I am thinking to employ 
>>> re.search(pattern,text). If this part is done I do not need machine 
>>> learning. 
>>> Maintaining so much data is a cumbersome issue in machine learning.
>> NLTK is not machine learning (I believe). It can parse the corpus for you, 
>> emitting grammatical structures. So that would aid you in recognising words, 
>> phrases, nouns, verbs and so forth. With that structure you can then make 
>> better decisions about what to tag and how.
>>
>> Using the re module is a very hazard prone way of parsing text. It can be 
>> useful for finding fairly fixed text, particularly in machine generated 
>> text, 
>> but it is terrible for prose.
>>
>> Cheers,
>> Cameron Simpson 
> Dear Sir, 
>
> Thank you for your kind time to discuss the matter. 
> I am very clear in Statistics but as I am a Linguist too I feel the modern day
> craziness on theories is going no where. Many theories but hardly anything of
> practical value, bit like post Chomskyan Linguistics scenario. Theories of 
> parsing
> are equally bad. Only advantage of statistics is if it is not giving result 
> you may 
> abandon them quickly. 
>
> I do not feel Parsing theories of Linguistics lead anywhere esp if data is 
> really big. 
>
> I am looking for patterns. Like if you say Organizations in documents are 
> mostly all
> capital lettered acronyms. So no need of taking ML solution for that rather a 
> simple
> code line of [word for word in words if word.isupper()] does the job. In the 
> same way
> there are many interesting patterns in language if you observe them. I made 
> many, making
> many more. All you need some good time to observe the data patiently. 
>
> NLTK is a library mainly built for students practice but now everyone uses 
> it. 
> They have many corpora and tools (most of them are built with ML based 
> approach),
> but they have many more ML libraries which you may use on user defined data 
> and standard.
> NLTK integrates nicely with other Python based libraries like Scikit or 
> Gensim or Java based 
> ones like Stanford. The code lines are nicely documented if you feel you may 
> read as proper
> references are mostly given. 
>
> I got good results in re earlier but I would surely check your point.
>
> Thank you again for your kind time and a nice discussion.
>
I will point out that I still haven't heard a statement of what you
actually are t

Possible bug in ThreadPoolExecutor, or just misinterpretation

2018-05-27 Thread Santiago Basulto
Hey list! I might have encountered a "bug", or maybe it's just a "design
decision" :)

Here's some example code:
https://gist.github.com/santiagobasulto/3513a50ec0dc939e8f7bb2ecfa8d4ae2

The problem is `ThreadPoolExecutor.map()`. It's not returning tasks "as
completed" but sequentially.  I understand that might be the desired
behavior since the function is `map()` and you *might* be expecting the
results "in order".

So, the questions are: Is this expected behavior? Is there any chance to
add an `map_unordered` as multiprocessing has
?
Another option might be making `as_completed` work with map results too
(which was my original intention).

Thanks for your answers in advance!

-- 
Santiago Basulto.-
Up!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Raw string statement (proposal)

2018-05-27 Thread Dan Stromberg
On Thu, May 24, 2018 at 9:34 PM, Mikhail V  wrote:

> Hi.
> I've put some thoughts together, and
> need some feedback on this proposal.
> Main question is:  Is it convincing?
> Is there any flaw?
> My own opinion - there IS something to chase.
> Still the justification for such syntax is hard.
>
This is a strange syntax that is quite unnecessary; just use triple-quoted
strings.

Please, please, please don't add it.

I believe Python's core language should be kept small.  Big libraries are
fine - important even.  But the core language should be easy to learn but
powerful.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Possible bug in ThreadPoolExecutor, or just misinterpretation

2018-05-27 Thread INADA Naoki
On Mon, May 28, 2018 at 1:12 AM Santiago Basulto

wrote:

> Hey list! I might have encountered a "bug", or maybe it's just a "design
> decision" :)

> Here's some example code:
> https://gist.github.com/santiagobasulto/3513a50ec0dc939e8f7bb2ecfa8d4ae2

> The problem is `ThreadPoolExecutor.map()`. It's not returning tasks "as
> completed" but sequentially.  I understand that might be the desired
> behavior since the function is `map()` and you *might* be expecting the
> results "in order".

> So, the questions are: Is this expected behavior?

Yes, you can use `future.as_completed()` instead.

>   Is there any chance to
> add an `map_unordered` as multiprocessing has
> <
https://docs.python.org/3/library/multiprocessing.html#multiprocessing.pool.Pool.imap_unordered
> ?

I don't it's reasonable.
You can use multiprocessing.ThreadPool instead.

> Another option might be making `as_completed` work with map results too
> (which was my original intention).

I don't like this idea.

Regards,

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


Re: Re: The PIL show() method looks for the default viewer. How do I change this to a different viewer (of my choice)?

2018-05-27 Thread Paul St George

So, on Unix I would use

Image.show(title=None, nameofdisplayutilty), or Image.show(title=None, 
scriptname) #where script with name scriptname invokes the program


I will try this now! And thank you.


On 26/05/2018 19:30, Dennis Lee Bieber wrote:

On Sat, 26 May 2018 17:17:42 +0200, Paul St George 
declaimed the following:


And, out of curiosity, as I will probably use a different method - how
do I find out what commands can be used as parameters for show()? I read
the docs at
,
but I am none the wiser.


AS the examples ("On OS-of-choice...") illustrate... command is any
external executable program that can handle the temporary file, I presume
using the name of the temporary and not via redirection of stdin... If you
have a hex-editor, you could even supply that as "command". If you need to
provide more than the program name, you may have to instead create a
shell-script, set it executable, and pass the script name -- have the
script then invoke the program with the options and forwarding the
temporary file name to it.




--
Paul St George
http://www.paulstgeorge.com
http://www.devices-of-wonder.com

+44(0)7595 37 1302

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


Re: Re: Re: The PIL show() method looks for the default viewer. How do I change this to a different viewer (of my choice)?

2018-05-27 Thread Paul St George

This is very helpful indeed, thank you. Awe-inspiring.

It occurred to me that I could edit the PIL/ImageShow.py, replacing ‘xv’ 
(in five places) with the utility of my choice and using ‘executable’ as 
the command.


Or, is this just not done?

On 26/05/2018 19:11, Peter Otten wrote:

Paul St George wrote:


Thank you.
You are very right. The show() method is intended for debugging purposes
and is useful for that, but what method should I be using and is PIL the
best imaging library for my purposes? I do not want to manipulate
images, I only want to show images (full screen) on an external display.
I want to use Python to control the timing of the images.

And, out of curiosity, as I will probably use a different method - how
do I find out what commands can be used as parameters for show()? I read
the docs at
,
but I am none the wiser.

If you look into the source code

https://github.com/python-pillow/Pillow/blob/master/src/PIL/Image.py#L1967

after a few indirections

show --> _show --> _showxv --> ImageShow.show

you will end up in the file

https://github.com/python-pillow/Pillow/blob/master/src/PIL/ImageShow.py

which is short enough to read completely ;)

At first glance it looks like the command argument is silently discarded, so
here's plan B:

It turns out that you can register() Viewer instances, and the pre-
registered viewers for unixoids -- and thus probably the Pi are
DisplayViewer and XVViewer.

Using these as a template I came up with the following simple viewer that
shows an image with firefox:

#!/usr/bin/env python3
import os
import sys

from PIL import Image, ImageShow


class Firefox(ImageShow.UnixViewer):

 # store the image in a format understood by the browser
 format = "jpeg"

 def get_command_ex(self, file, **options):
 return ("firefox",) * 2

 def show_file(self, file, **options):
 quote = ImageShow.quote

 command, executable = self.get_command_ex(file, **options)

 # firefox returns immediately, so let's sleep a few seconds
 # to give it time to actually open the image file
 command = "(%s %s; sleep 10; rm -f %s)&" % (
 command, quote("file://" + file), quote(file)
 )
 os.system(command)
 return 1


# the -1 means our viewer will be inserted before the others
# and thus become the default
ImageShow.register(Firefox(), -1)


if __name__ == "__main__":
 try:
 file = sys.argv[1]
 except IndexError:
 print("Please provide an image file", file=sys.stderr)
 else:
 image = Image.open(file)
 image.show()


Here's another, even simpler one:

class Gwenview(ImageShow.UnixViewer):
 def get_command_ex(self, file, **options):
 return ("gwenview",) * 2





--
Paul St George
http://www.paulstgeorge.com
http://www.devices-of-wonder.com

+44(0)7595 37 1302

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


how to read a syntax diagram

2018-05-27 Thread Paul
hi,
   I'm using the Google Sheets API (the client library rather than the
RESTful interface) and I'm confused about the meaning of the syntax
diagrams.  This is from
https://developers.google.com/resources/api-libraries/documentation/sheets/v4/python/latest/sheets_v4.spreadsheets.values.html#update

efaults to ROWS.
  }

update(spreadsheetId=*, range=*, body=*, valueInputOption=None,
x__xgafv=None, responseValueRenderOption=None,
includeValuesInResponse=None, responseDateTimeRenderOption=None)

Sets values in a range of a spreadsheet.
The caller must specify the spreadsheet ID, range, and
a valueInputOption.

Args:
  spreadsheetId: string, The ID of the spreadsheet to update. (required)
  range: string, The A1 notation of the values to update. (required)
  body: object, The request body. (required)
The object takes the form of:

{ # Data within a range of the spreadsheet.
  "range": "A String", # The range the values cover, in A1 notation.
  # For output, this range indicates the entire requested range,
  # even though the values will exclude trailing rows and columns.
  # When appending values, this field represents the range to search for a
  # table, after which values will be appended.
  "values": [ # The data that was read or to be written.  This is an
array of arrays,
  # the outer array representing all the data and each inner array
  # representing a major dimension. Each item in the inner array
  # corresponds with one cell.
  #
  # For output, empty trailing rows and columns will not be included.
  #
  # For input, supported value types are: bool, string, and double.
  # Null values will be skipped.
  # To set a cell to an empty value, set the string value to an
empty string.
[
  "",
],
  ],
  "majorDimension": "A String", # The major dimension of the values.
  #
  # For output, if the spreadsheet data is: `A1=1,B1=2,A2=3,B2=4`,
  # then requesting `range=A1:B2,majorDimension=ROWS` will return
  # `[[1,2],[3,4]]`,
  # whereas requesting `range=A1:B2,majorDimension=COLUMNS` will return
  # `[[1,3],[2,4]]`.
  #
  # For input, with `range=A1:B2,majorDimension=ROWS` then `[[1,2],[3,4]]`
  # will set `A1=1,B1=2,A2=3,B2=4`. With
`range=A1:B2,majorDimension=COLUMNS`
  # then `[[1,2],[3,4]]` will set `A1=1,B1=3,A2=2,B2=4`.
  #
  # When writing, if this field is not set, it defaults to ROWS.
}

  valueInputOption: string, How the input data should be
interpreted// I CUT IT OFF, HERE


My specific questions are:
   1) is this standard (python?) syntax notation?  I haven't found a key to
this form of documentation.
   1)  What does  '=*' mean?
   2)  What does '=None' mean?[my guess is that this means "no default
value"].
   3)  Note that it says that range is required.  Through trial, I see that
*one* of the 'range' specifications is required.  I.E., I can specify
'range' outside body, or 'range' as part of body, or both, but I must have
'range' someplace.   This is a bit confusing to me ( as opposed to my usual
understanding of "required").  Also, what does range mean, in these two
different spots, and what does it mean if two different values of range are
specified?

thanks
  Paul Czyzewski
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to read a syntax diagram

2018-05-27 Thread Paul
oops, please ignore the bit before "update(spreadsheetId=*, range=*, ..."

On Sun, May 27, 2018 at 9:17 PM, Paul  wrote:

> hi,
>I'm using the Google Sheets API (the client library rather than the
> RESTful interface) and I'm confused about the meaning of the syntax
> diagrams.  This is from
> https://developers.google.com/resources/api-libraries/
> documentation/sheets/v4/python/latest/sheets_v4.spreadsheets.values.html#
> update
>
> efaults to ROWS.
>   }
>
> update(spreadsheetId=*, range=*, body=*, valueInputOption=None,
> x__xgafv=None, responseValueRenderOption=None,
> includeValuesInResponse=None, responseDateTimeRenderOption=None)
>
> Sets values in a range of a spreadsheet.
> The caller must specify the spreadsheet ID, range, and
> a valueInputOption.
>
> Args:
>   spreadsheetId: string, The ID of the spreadsheet to update. (required)
>   range: string, The A1 notation of the values to update. (required)
>   body: object, The request body. (required)
> The object takes the form of:
>
> { # Data within a range of the spreadsheet.
>   "range": "A String", # The range the values cover, in A1 notation.
>   # For output, this range indicates the entire requested range,
>   # even though the values will exclude trailing rows and columns.
>   # When appending values, this field represents the range to search for a
>   # table, after which values will be appended.
>   "values": [ # The data that was read or to be written.  This is an array of 
> arrays,
>   # the outer array representing all the data and each inner array
>   # representing a major dimension. Each item in the inner array
>   # corresponds with one cell.
>   #
>   # For output, empty trailing rows and columns will not be included.
>   #
>   # For input, supported value types are: bool, string, and double.
>   # Null values will be skipped.
>   # To set a cell to an empty value, set the string value to an empty 
> string.
> [
>   "",
> ],
>   ],
>   "majorDimension": "A String", # The major dimension of the values.
>   #
>   # For output, if the spreadsheet data is: `A1=1,B1=2,A2=3,B2=4`,
>   # then requesting `range=A1:B2,majorDimension=ROWS` will return
>   # `[[1,2],[3,4]]`,
>   # whereas requesting `range=A1:B2,majorDimension=COLUMNS` will return
>   # `[[1,3],[2,4]]`.
>   #
>   # For input, with `range=A1:B2,majorDimension=ROWS` then `[[1,2],[3,4]]`
>   # will set `A1=1,B1=2,A2=3,B2=4`. With 
> `range=A1:B2,majorDimension=COLUMNS`
>   # then `[[1,2],[3,4]]` will set `A1=1,B1=3,A2=2,B2=4`.
>   #
>   # When writing, if this field is not set, it defaults to ROWS.
> }
>
>   valueInputOption: string, How the input data should be interpreted// I 
> CUT IT OFF, HERE
>
>
> My specific questions are:
>1) is this standard (python?) syntax notation?  I haven't found a key
> to this form of documentation.
>1)  What does  '=*' mean?
>2)  What does '=None' mean?[my guess is that this means "no default
> value"].
>3)  Note that it says that range is required.  Through trial, I see
> that *one* of the 'range' specifications is required.  I.E., I can specify
> 'range' outside body, or 'range' as part of body, or both, but I must have
> 'range' someplace.   This is a bit confusing to me ( as opposed to my usual
> understanding of "required").  Also, what does range mean, in these two
> different spots, and what does it mean if two different values of range are
> specified?
>
> thanks
>   Paul Czyzewski
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The PIL show() method looks for the default viewer. How do I change this to a different viewer (of my choice)?

2018-05-27 Thread Cameron Simpson

On 27May2018 20:15, Paul St George  wrote:

This is very helpful indeed, thank you. Awe-inspiring.

It occurred to me that I could edit the PIL/ImageShow.py, replacing 
‘xv’ (in five places) with the utility of my choice and using 
‘executable’ as the command.


Or, is this just not done?


It becomes a maintenance problem.

Alternatively you could:

Just write your own show function which accepts an Image and displays it with 
your program of choice. You might need to write some equivalent code which 
saves the Image to a file first, and removes it afterwards.


You could copy the show() code into a function of your own (i.e. in your own 
codebase) modify that to suit, then monkeypatch the class:


 Image.show = your_personal_show_function

when your programme starts. That way the code changes are not in the PIL code.

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


Re: how to read a syntax diagram

2018-05-27 Thread Steven D'Aprano
On Sun, 27 May 2018 21:17:57 +, Paul wrote:

> hi,
>I'm using the Google Sheets API (the client library rather than the
> RESTful interface) and I'm confused about the meaning of the syntax
> diagrams.

*Diagrams*? As in, *pictures*?


> update(spreadsheetId=*, range=*, body=*, valueInputOption=None,
> x__xgafv=None, responseValueRenderOption=None,
> includeValuesInResponse=None, responseDateTimeRenderOption=None)
[...]

> My specific questions are:
>1) is this standard (python?) syntax notation?  I haven't found a key
>to this form of documentation.

No.

>1)  What does  '=*' mean?

No idea.

>2)  What does '=None' mean?[my guess is that this means "no
>default value"].

If they are using the same meaning as the standard convention in Python, 
it means the opposite: that None is the default.

If they mean something else, your guess is as good as mine.


>3)  Note that it says that range is required.  Through trial, I see
>that
> *one* of the 'range' specifications is required.  I.E., I can specify
> 'range' outside body, or 'range' as part of body, or both, but I must
> have 'range' someplace.   This is a bit confusing to me ( as opposed to
> my usual understanding of "required").  Also, what does range mean, in
> these two different spots, and what does it mean if two different values
> of range are specified?

No idea.


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

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


Re: how to read a syntax diagram

2018-05-27 Thread MRAB

On 2018-05-27 22:17, Paul wrote:

hi,
I'm using the Google Sheets API (the client library rather than the
RESTful interface) and I'm confused about the meaning of the syntax
diagrams.  This is from
https://developers.google.com/resources/api-libraries/documentation/sheets/v4/python/latest/sheets_v4.spreadsheets.values.html#update

efaults to ROWS.
   }

update(spreadsheetId=*, range=*, body=*, valueInputOption=None,
x__xgafv=None, responseValueRenderOption=None,
includeValuesInResponse=None, responseDateTimeRenderOption=None)

Sets values in a range of a spreadsheet.
The caller must specify the spreadsheet ID, range, and
a valueInputOption.

Args:
   spreadsheetId: string, The ID of the spreadsheet to update. (required)
   range: string, The A1 notation of the values to update. (required)
   body: object, The request body. (required)
 The object takes the form of:

{ # Data within a range of the spreadsheet.
   "range": "A String", # The range the values cover, in A1 notation.
   # For output, this range indicates the entire requested range,
   # even though the values will exclude trailing rows and columns.
   # When appending values, this field represents the range to search for a
   # table, after which values will be appended.



[snip]


My specific questions are:
1) is this standard (python?) syntax notation?  I haven't found a key to
this form of documentation.


Note quite.


1)  What does  '=*' mean?


In the descriptions that follow, those that have '=*' also have 
'(required)', so I think it means that the parameter is required. That's 
not standard Python notation, AFAIK.



2)  What does '=None' mean?[my guess is that this means "no default
value"].


In standard Python notation it means that the default is None, which 
usually means that there's some kind of default. For example, if the 
parameter is for defining a date format, None would mean to use a 
standard date format, such as ISO-whatever or the system-defined date 
format for the current locale.



3)  Note that it says that range is required.  Through trial, I see that
*one* of the 'range' specifications is required.  I.E., I can specify
'range' outside body, or 'range' as part of body, or both, but I must have
'range' someplace.   This is a bit confusing to me ( as opposed to my usual
understanding of "required").  Also, what does range mean, in these two
different spots, and what does it mean if two different values of range are
specified?

For range it mentions "A1 notation". In spreadsheet applications, 
columns are labelled by letter (A, B, C, etc.) and rows by number (1, 2, 
3, etc.), so the top-left cell is "A1". You specify a range by giving 
the labels of 2 opposite corners, e.g. "A1B3".

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


Re: List replication operator

2018-05-27 Thread Richard Damon
On 5/25/18 6:28 PM, Steven D'Aprano wrote:
> On Sat, 26 May 2018 02:58:06 +1000, Chris Angelico wrote:
>
>> Your mail/news client might choose to represent configure.ac as a link,
>> since ".ac" is a valid TLD.
> Isn't *everything* a valid TLD now?
>
> For the right price, at least.
>
Not quite, .invalid has been promised (I beleive) to NEVER be a valid TLD

Also, I think two letter TLDs are reserved for country codes, and not up
for sale (except by getting ISO to assign you a country code).

-- 
Richard Damon

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


Re: List replication operator

2018-05-27 Thread Chris Angelico
On Mon, May 28, 2018 at 1:46 PM, Richard Damon  wrote:
> On 5/25/18 6:28 PM, Steven D'Aprano wrote:
>> On Sat, 26 May 2018 02:58:06 +1000, Chris Angelico wrote:
>>
>>> Your mail/news client might choose to represent configure.ac as a link,
>>> since ".ac" is a valid TLD.
>> Isn't *everything* a valid TLD now?
>>
>> For the right price, at least.
>>
> Not quite, .invalid has been promised (I beleive) to NEVER be a valid TLD
>
> Also, I think two letter TLDs are reserved for country codes, and not up
> for sale (except by getting ISO to assign you a country code).
>

Cool, I'll just start my own country then.

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


Re: The PIL show() method looks for the default viewer. How do I change this to a different viewer (of my choice)?

2018-05-27 Thread Christian Gollwitzer

Am 27.05.18 um 23:58 schrieb Cameron Simpson:

On 27May2018 20:15, Paul St George  wrote:

This is very helpful indeed, thank you. Awe-inspiring.

It occurred to me that I could edit the PIL/ImageShow.py, replacing 
‘xv’ (in five places) with the utility of my choice and using 
‘executable’ as the command.


Or, is this just not done?


It becomes a maintenance problem.

Alternatively you could:

Just write your own show function which accepts an Image and displays it 
with your program of choice. You might need to write some equivalent 
code which saves the Image to a file first, and removes it afterwards.


You could copy the show() code into a function of your own (i.e. in your 
own codebase) modify that to suit, then monkeypatch the class:


  Image.show = your_personal_show_function

when your programme starts. That way the code changes are not in the PIL 
code.


I think this is a bug/misfeature in the PIL code. On all 3 major 
platforms there is a way to invoke the standard program for a given file 
or URL. On Windows, it is "cmd.exe /c start ...", on OSX it is "open 
" and on Linux it is "xdg-open ...". That way the file is opened by 
whatever the user has set in his desktop environment.


Technically, xdg-open needs not to be present on Linux, though it is 
usually installed.


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