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

2018-06-03 Thread Jach Fong

Forgive my ignorance of "*any" notation. I don't have real experience of
using it in my codes so far, and didn't know those parameters were
packed as a tuple:-(


Steven D'Aprano 於 2018/6/3 下午 01:08 寫道:

On Sun, 03 Jun 2018 04:59:34 +, Steven D'Aprano wrote:


On Sun, 03 Jun 2018 10:55:04 +0800, Jach Fong wrote:


The attached is a script which can run under Python 3.4/Windows Vista
correctly. 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?


90% of the script you attached is irrelevant to your question. None of
the tkinter or threading code is important. The only important parts
are:

def threaded(action, args, context, onExit, onProgress):
 def progress(*any):
 threadQueue.put((onProgress, any + context))

Here we can tell that ``any`` is a tuple.


Oops, I misread your question. You thought any was an int. But the *
(star) notation in function parameters makes the parameter collect any
unnamed arguments into a single tuple.

def test(first, *args):
 print(args)

test(1, 2, 3, "hello", 99)
=> prints the tuple (2, 3, "hello", 99)





---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


ipython does not work with latest version of prompt-toolkit

2018-06-03 Thread Cecil Westerhof
When executing:
pip3 list --no-cache-dir --outdated

I got:
prompt-toolkit 1.0.152.0.1wheel
PyGObject  3.28.23.28.3   sdist
youtube-dl 2018.5.30 2018.6.2 wheel

So I executed:
pip3 install --upgrade prompt-toolkit PyGObject youtube-dl

This gave:
Successfully installed PyGObject-3.28.3 prompt-toolkit-2.0.1 
youtube-dl-2018.6.2
ipython 6.4.0 has requirement prompt-toolkit<2.0.0,>=1.0.15, but you'll 
have prompt-toolkit 2.0.1 which is incompatible.

And when I now execute ipython3, I get:
Traceback (most recent call last):
  File "/usr/local/bin/ipython3", line 7, in 
from IPython import start_ipython
  File "/usr/local/lib/python3.5/dist-packages/IPython/__init__.py", line 
55, in 
from .terminal.embed import embed
  File "/usr/local/lib/python3.5/dist-packages/IPython/terminal/embed.py", 
line 16, in 
from IPython.terminal.interactiveshell import TerminalInteractiveShell
  File 
"/usr/local/lib/python3.5/dist-packages/IPython/terminal/interactiveshell.py", 
line 22, in 
from prompt_toolkit.shortcuts import create_prompt_application, 
create_eventloop, create_prompt_layout, create_output
ImportError: cannot import name 'create_prompt_application'

When I now execute:
pip3 list --no-cache-dir --outdated

I do not get output. So pip3 thinks everything is OK.

How do I fix this? Or is the expected that ipython3 will be updated
shortly?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ipython does not work with latest version of prompt-toolkit

2018-06-03 Thread Chris Warrick
On Sun, 3 Jun 2018 at 10:32, Cecil Westerhof  wrote:
>
> When executing:
> pip3 list --no-cache-dir --outdated
>
> I got:
> prompt-toolkit 1.0.152.0.1wheel
> PyGObject  3.28.23.28.3   sdist
> youtube-dl 2018.5.30 2018.6.2 wheel
>
> So I executed:
> pip3 install --upgrade prompt-toolkit PyGObject youtube-dl
>
> This gave:
> Successfully installed PyGObject-3.28.3 prompt-toolkit-2.0.1 
> youtube-dl-2018.6.2
> ipython 6.4.0 has requirement prompt-toolkit<2.0.0,>=1.0.15, but you'll 
> have prompt-toolkit 2.0.1 which is incompatible.
>
> And when I now execute ipython3, I get:
> Traceback (most recent call last):
>   File "/usr/local/bin/ipython3", line 7, in 
> from IPython import start_ipython
>   File "/usr/local/lib/python3.5/dist-packages/IPython/__init__.py", line 
> 55, in 
> from .terminal.embed import embed
>   File 
> "/usr/local/lib/python3.5/dist-packages/IPython/terminal/embed.py", line 16, 
> in 
> from IPython.terminal.interactiveshell import TerminalInteractiveShell
>   File 
> "/usr/local/lib/python3.5/dist-packages/IPython/terminal/interactiveshell.py",
>  line 22, in 
> from prompt_toolkit.shortcuts import create_prompt_application, 
> create_eventloop, create_prompt_layout, create_output
> ImportError: cannot import name 'create_prompt_application'
>
> When I now execute:
> pip3 list --no-cache-dir --outdated
>
> I do not get output. So pip3 thinks everything is OK.
>
> How do I fix this? Or is the expected that ipython3 will be updated
> shortly?

Start by reading the warning from pip:

> ipython 6.4.0 has requirement prompt-toolkit<2.0.0,>=1.0.15, but you'll 
> have prompt-toolkit 2.0.1 which is incompatible.

To fix this, downgrade prompt-toolkit. `pip list --outdated` (not)
having output isn’t a “good” or “bad” thing. prompt-toolkit v2 has
changed its API from v1, and ipython doesn’t support the new one yet.

Don’t randomly upgrade pip packages without knowing what the upgrade
entails, especially if the version changed from 1.x to 2.x (x.y →
x+1.y) — that usually means an API change and possible
incompatibilities in dependent packages. Upgrading a tool like
youtube-dl should be fine, and so should be a x.y.z → x.y.z+1 upgrade,
but it’s still best to know what you’re doing.

-- 
Chris Warrick 
PGP: 5EAAEA16
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ipython does not work with latest version of prompt-toolkit

2018-06-03 Thread Cecil Westerhof
Chris Warrick  writes:

> On Sun, 3 Jun 2018 at 10:32, Cecil Westerhof  wrote:
>>
>> When executing:
>> pip3 list --no-cache-dir --outdated
>>
>> I got:
>> prompt-toolkit 1.0.152.0.1wheel
>> PyGObject  3.28.23.28.3   sdist
>> youtube-dl 2018.5.30 2018.6.2 wheel
>>
>> So I executed:
>> pip3 install --upgrade prompt-toolkit PyGObject youtube-dl
>>
>> This gave:
>> Successfully installed PyGObject-3.28.3 prompt-toolkit-2.0.1 
>> youtube-dl-2018.6.2
>> ipython 6.4.0 has requirement prompt-toolkit<2.0.0,>=1.0.15, but you'll 
>> have prompt-toolkit 2.0.1 which is incompatible.
>>
>> And when I now execute ipython3, I get:
>> Traceback (most recent call last):
>>   File "/usr/local/bin/ipython3", line 7, in 
>> from IPython import start_ipython
>>   File "/usr/local/lib/python3.5/dist-packages/IPython/__init__.py", 
>> line 55, in 
>> from .terminal.embed import embed
>>   File 
>> "/usr/local/lib/python3.5/dist-packages/IPython/terminal/embed.py", line 16, 
>> in 
>> from IPython.terminal.interactiveshell import 
>> TerminalInteractiveShell
>>   File 
>> "/usr/local/lib/python3.5/dist-packages/IPython/terminal/interactiveshell.py",
>>  line 22, in 
>> from prompt_toolkit.shortcuts import create_prompt_application, 
>> create_eventloop, create_prompt_layout, create_output
>> ImportError: cannot import name 'create_prompt_application'
>>
>> When I now execute:
>> pip3 list --no-cache-dir --outdated
>>
>> I do not get output. So pip3 thinks everything is OK.
>>
>> How do I fix this? Or is the expected that ipython3 will be updated
>> shortly?
>
> Start by reading the warning from pip:
>
>> ipython 6.4.0 has requirement prompt-toolkit<2.0.0,>=1.0.15, but
>> you'll have prompt-toolkit 2.0.1 which is incompatible.
>
> To fix this, downgrade prompt-toolkit. `pip list --outdated` (not)
> having output isn’t a “good” or “bad” thing. prompt-toolkit v2 has
> changed its API from v1, and ipython doesn’t support the new one yet.

I did not find a command to get all the existing versions. I solved it
with uninstalling and then installing with:
pip3 install 'prompt-toolkit>=1.0.15,<2.0.0'

Is there a way to find the versions? It would be handy to install the
1.0.16 version if it comes out.


> Don’t randomly upgrade pip packages without knowing what the upgrade
> entails, especially if the version changed from 1.x to 2.x (x.y →
> x+1.y) — that usually means an API change and possible
> incompatibilities in dependent packages. Upgrading a tool like
> youtube-dl should be fine, and so should be a x.y.z → x.y.z+1 upgrade,
> but it’s still best to know what you’re doing.

Always checking would be a lot of work: I get several times a week
several packages to update. If I would check them all I need a few
hours more a week. I am used to systems that do not update when there
is a conflict. But sadly pip does not work that way. :'-(

But I could do the 'automatic' update only when x does not change. Or
for specific packages like youtube-dl.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Problem with pickle in zodb

2018-06-03 Thread Etienne Robillard

Hi,

Any ideas why this is happening ?

erob@marina:/home/www/open-neurosecurity.org/trunk$ schevo editor 
zodb://127.0.0.1:4545

07:32:16 environ  No en_CA translation found for domain kiwi
07:32:16 environ  No en_CA translation found for domain gazpacho
libschevo 4.0.1 :: Database Navigator ()
()
> /home/erob/src/libschevo/lib/schevo/gtk2/window.py(295)database_open()
-> self._db = schevo.database.open(db_alias)
(Pdb) n
zodb://127.0.0.1:4545
127.0.0.1:4545
Found epoll library, good!
/home/erob/src/libschevo/lib/schevo/backends/zodb.py:7: RuntimeWarning: 
Patching more than once will result in the union of all True parameters 
being patched

  patch_all(thread=True)
07:32:23 ZEO.asyncio.marshal  can't decode message: 
'\x80\x03(K\x01K\x00U\x06.replyU\x08\x03\xc7\xf6]\xe0\xd...'

07:32:23 ZEO.asyncio.base data_received 4 0 True
Traceback (most recent call last):
  File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/base.py", line 128, 
in data_received

    self.message_received(collected)
  File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/client.py", line 206, 
in message_received

    msgid, async, name, args = self.decode(data)
  File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/marshal.py", line 91, 
in pickle_decode

    return unpickler.load() # msgid, flags, name, args
ValueError: unsupported pickle protocol: 3
07:32:52 ZEO.asyncio.client   Registration or cache validation failed, 
Closed

Traceback (most recent call last):
  File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/client.py", line 188, 
in finish_connect

    *credentials)
ClientDisconnected: Closed
ClientDisconnected: ClientDi...ection',)


Thank you in advance,

Etienne


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


Re: How to move the scrollbar to inside the text widget

2018-06-03 Thread Cousin Stanley
[email protected] wrote:

> I am a Newbie
> 
> I have this code
> 
> from tkinter import *
> 
> root = Tk()
> root.geometry("1200x1000+30+30")
> # width x height + x_offset + y_offset:
> T = Text(root, height=10, width=100)
> T.place(x=20, y=30)
> for i in range(40):
>T.insert(END, "This is line %d\n" % i)
> 
> # create a vertical scrollbar to the right of the listbox
> yscroll = Scrollbar(command=T.yview, orient=VERTICAL)
> T.configure(yscrollcommand=yscroll.set)
> yscroll.pack(side="right", fill="y", expand=False)
> 
> root.mainloop()
> 
> 
> The srollbar is on the window frame, is there a way I can move it to inside 
> and right edge of
> text area?
> 
> Thanks


You might try the tkinter  ScrolledText  widget 


from tkinter import *

from tkinter import scrolledtext as ST


root = Tk()

root.geometry( "1200x1000+30+30" )  # width x height + x_offset + y_offset


T = ST.ScrolledText( root, height=40, width=100, font=( 'Fixed' , 14 ) )


T.place( x = 20 , y = 30 )

for i in range( 101 ) :

   T.insert( END , "  This is line %03d\n" % i )


.
include the rest of your orignal code 
.


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

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


add me

2018-06-03 Thread gamesland5108
i am saran. i want to learn python programming.
-- 
https://mail.python.org/mailman/listinfo/python-list


Attachments (was: How can an int be '+' with a tuple?)

2018-06-03 Thread Peter J. Holzer
On 2018-06-03 13:57:26 +1000, Ben Finney wrote:
> (For good reasons, attachments are dropped when messages are distributed
> on the forum.)

By "the forum" you mean Gmane? (I got the attachment over the mailing
list)

hp

-- 
   _  | Peter J. Holzer| we build much bigger, better disasters now
|_|_) || because we have much more sophisticated
| |   | [email protected] | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson 


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


tkinter (ttk) combobox dropdown text is white on white

2018-06-03 Thread Jim Lee

Given the following snippet (Python 3.6.5, Tk 8.6.8):

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
cb = ttk.Combobox(root)
cb.grid(row=0, column=0, sticky='NSEW')
cb['values'] = ['one', 'two', 'three', 'four']
root.mainloop()

The text of the values in the combobox dropdown list is white on 
white.   The *selected* item in the list is white on light grey, but all 
the unselected items are invisible (white on white).  I have played with 
themes and styles, and can alter the foreground and background colors of 
the combobox itself, but I cannot figure out how to alter the appearance 
of entries in the dropdown list. Any pointers?



Thanks,

-Jim Lee


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


Re: tkinter (ttk) combobox dropdown text is white on white

2018-06-03 Thread Christian Gollwitzer

Am 03.06.18 um 21:54 schrieb Jim Lee:> import tkinter as tk

from tkinter import ttk

root = tk.Tk()
cb = ttk.Combobox(root)
cb.grid(row=0, column=0, sticky='NSEW')
cb['values'] = ['one', 'two', 'three', 'four']
root.mainloop()

The text of the values in the combobox dropdown list is white on 
white.   The *selected* item in the list is white on light grey, but all 
the unselected items are invisible (white on white). 


Which platform are you on, i.e. which operating system? I guess it is 
Linux. In that case the default colors are read by Tk from the X11 
options database, which is some cruft from the past to set options for 
X11 applications. Try to run


xrdb -query

That should give you a list of default values, and maybe you can see 
something. The dropdown list is actually a popdown menu, so look for 
Menu colors. For instance, if you use a dark theme in your desktop 
environment, it could be that the foreground is correctly set to white, 
but the background is hardcoded white for some reason e.g.



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


Re: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to

2018-06-03 Thread bellcanadardp
On Tuesday, 22 May 2018 17:23:55 UTC-4, Peter J. Holzer  wrote:
> On 2018-05-20 15:43:54 +0200, Karsten Hilbert wrote:
> > On Sun, May 20, 2018 at 04:59:12AM -0700, [email protected] wrote:
> > 
> > > On Saturday, 19 May 2018 19:48:20 UTC-4, Skip Montanaro  wrote:
> > > > As Chris indicated, you'll have to figure out the correct encoding. You
> > > > might want to check out the chardet module (available on PyPI, I 
> > > > believe)
> > > > and see if it can come up with a better guess. I imagine there are other
> > > > encoding guessers out there. That's just one I'm familiar with.
> > > 
> > > thank you for the reply, but how exactly am i supposed to find oout what 
> > > is the correct encodeing??
> > 
> > One CAN NOT.
> > 
> > The best you can do is to go ask the canonical source of the
> > file what encoding the file is _supposed_ to be in.
> 
> I disagree on both counts.
> 
> 1) For any given file it is almost always possible to find the correct
>encoding (or *a* correct encoding, as there may be more than one).
> 
>This may require domain-specific knowledge (e.g. it may be necessary
>to recognize the human language and know at least some distinctive
>words, or to know some special symbols likely to be used in a data
>file), and it almost always takes a bit of detective work and trial
>and error. But I don't think I ever encountered a file where I
>couldn't figure out the encoding.
> 
>(If you have several files in the same encoding, it may not be
>possible to figure out the encoding from a subset of them. For
>example, the files may all be in ISO-8859-2, but the subset you have
>contains only characters <= 0x7F. But if you have several files, they
>may not all be the same encoding, either).
> 
> 2) The canonical source of the file may not know. This is quite frequent
>when the source is some non-technical person. Then you get answers
>like "it's ASCII" (although the file contains umlauts, which aren't
>in ASCII) or "it's ANSI" (which isn't an encoding, although Windows
>pretends it is). Or they may not be aware that the file is converted
>somewhere in the pipeline, to that the file they generated isn't
>actually the file you received. So ask (or check the docs), but
>verify!
> 
> hp
> 
> -- 
>_  | Peter J. Holzer| we build much bigger, better disasters now
> |_|_) || because we have much more sophisticated
> | |   | [email protected] | management tools.
> __/   | http://www.hjp.at/ | -- Ross Anderson 

hello peter ...how exactly would i solve this issue .i have a script that 
works in python 2 but not pytho3..i did 2 to 3.py ...but i still get the 
errro...character undefieed..unicode decode error cant decode byte 1x09 in line 
7414 from cp 1252..like would you have a sraright solution answer??..i cant get 
a straight answer..it was ported from ansi to python...so its utf-8 as far asi 
can see
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to

2018-06-03 Thread Steven D'Aprano
On Sun, 03 Jun 2018 16:36:12 -0700, bellcanadardp wrote:

> hello peter ...how exactly would i solve this issue .i have a script
> that works in python 2 but not pytho3..i did 2 to 3.py ...but i still
> get the errro...character undefieed..unicode decode error cant decode
> byte 1x09 in line 7414 from cp 1252..like would you have a sraright
> solution answer??..i cant get a straight answer..it was ported from ansi
> to python...so its utf-8 as far asi can see

You won't get a straight answer because you won't tell us *precisely* 
what is happening.

Don't retype a summary of what you think the error is. "character 
undefieed" is not a thing, and there is no such thing as "byte 1x09".

You need to COPY AND PASTE the EXACT error that you get. Not just the 
last line, the error message, but the FULL TRACEBACK starting from the 
line "Traceback" and going to the end.

Until you do that, we cannot give you a straight answer.

You also need to COPY AND PASTE the EXACT line of code that gives the 
error, plus enough code so that it works. For a file read error, that 
probably means code that opens the file, and then tries to read from it.

Until you do that, we cannot give you a straight answer.

You need to tell us what version of Python you are using, and the 
operating system.

You should read this:

http://sscce.org/

Even though it is written for Java programmers, it applies to Python to.

If you think that your file is UTF-8, why are you using CP-1252 to read 
the file?

https://en.wikipedia.org/wiki/Windows-1252

https://en.wikipedia.org/wiki/UTF-8



I recommend you start with reading this if you haven't already:

https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-
software-developer-absolutely-positively-must-know-about-unicode-and-
character-sets-no-excuses/

Sorry for the huge URL, try this if your mail client breaks it:

https://tinyurl.com/h8yg9d7


Until you read that, you will probably remain confused about text  
encodings and Unicode and will probably not understand the straight 
answer we give you.

Also read: https://nedbatchelder.com/text/unipain.html



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

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


What is the "Unpacking Arguments List" rule?

2018-06-03 Thread Jach Fong

I had read "More on Defining Functions" sections of "The Python
Tutorial" carefully yesterday. One thing in the example code(Re: How can
an int be '+' with a tuple?) puzzles me again. It's the line 19:

def progress(*any):
threadQueue.put((onProgress, any + context))
action(progress=progress, *args)  # line 19, it calls threadaction 
function


def threadaction(id, reps, progress):


""" below was quoted from the document
4.7.2. Keyword Arguments
...
def parrot(voltage, state='a stiff', action='voom', type='Norwegian Blue'):
...

but all the following calls would be invalid:
...
parrot(voltage=5.0, 'dead')  # non-keyword argument after a keyword argument
...

4.7.3. Arbitrary Argument Lists
...
def write_multiple_items(file, separator, *args):
...
Normally, these variadic arguments will be last in the list of formal
parameters, because they scoop up all remaining input arguments that are
passed to the function.
...

4.7.4. Unpacking Argument Lists
The reverse situation occurs when the arguments are already in a list or
tuple but need to be unpacked for a function call requiring separate
positional arguments.
...
>>> args = [3, 6]
>>> list(range(*args))
"""

I can't understand why line 19 works? Didn't it violate the rule of
"# non-keyword argument after a keyword argument"? and why a more
reasonable look syntax gets an error?

action(*args, progress)
 ^
SyntaxError: only named arguments may follow *expression  File 
"test.py", line 19


The only reason I can guess is that it checks with the rule in 4.7.3 
which is really unrelated. The "*any" notation used in different places

with different meaning, such as defining arbitrary argument, unpacking
argument or even in an assignment(a,*b=any). Maybe it will be better to
stop this syntax checking and lets both statements below valid:-)

action(progress=progress, *args)
action(*args, progress)


Best Regards,
Jach Fong


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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