Re: Tkinter List of Canvases

2020-11-10 Thread ChalaoAdda
On Tue, 10 Nov 2020 17:21:04 +, MRAB wrote: > On 2020-11-10 10:01, ChalaoAdda wrote: >> Hello, >> >> I have a list of canvas of images. I would like to display all the >> images. But it displays the last image. Here is my code. >> >> from tkinter import * >> from PIL import Image, ImageTk >>

Re: Problem with rearanging list with paired letters next to each others

2020-11-10 Thread MRAB
On 2020-11-11 01:26, Bischoop wrote: Can anybody help?Here's the code that gives me a hedeache for second day https://bpa.st/XLOA If I have letter_list = ["a","a",,"b","b","c","c"] it's working correctly but if I have three or more of any letters for example:letter_list = ["a","a","a","b","b","

Problem with rearanging list with paired letters next to each others

2020-11-10 Thread Bischoop
Can anybody help?Here's the code that gives me a hedeache for second day https://bpa.st/XLOA If I have letter_list = ["a","a",,"b","b","c","c"] it's working correctly but if I have three or more of any letters for example:letter_list = ["a","a","a","b","b","c","c"], I'm ending up with some pair

Re: constant folding - why not more

2020-11-10 Thread Skip Montanaro
> > On the contrary, comparison remains for runtime: > >>> dis.dis(compile('1 < 2', filename='', mode='eval', > >>> optimize=2)) > 1 0 LOAD_CONST 0 (1) > 2 LOAD_CONST 1 (2) > 4 COMPARE_OP 0 (<) > 6 RETUR

ctypes struct alignment specification

2020-11-10 Thread Chris
I am working on a CUDA python API using ctypes. Within CUDA there are vector type structs defined (float2, float3, float4, int2, int3, int4, ...), all of which have an alignment specification (example of how this is specified https://stackoverflow.com/questions/12778949/cuda-memory-alignment/127

Re: Changing strings in files

2020-11-10 Thread Chris Angelico
On Wed, Nov 11, 2020 at 10:00 AM Cameron Simpson wrote: > > On 11Nov2020 07:30, Chris Angelico wrote: > >If the script's assuming it'll mostly work on small text files, it > >might be very annoying to suddenly read in a 4GB blob of video file > >just to find out that it's not text. > > You can ab

Re: Changing strings in files

2020-11-10 Thread Cameron Simpson
On 11Nov2020 07:30, Chris Angelico wrote: >If the script's assuming it'll mostly work on small text files, it >might be very annoying to suddenly read in a 4GB blob of video file >just to find out that it's not text. You can abort as soon as the decode fails. Which will usually be pretty early f

Re: Changing strings in files

2020-11-10 Thread Cameron Simpson
On 11Nov2020 07:25, Chris Angelico wrote: >If the main job of the program, as in this situation, is to read the >entire file, I would probably have it read in the first 1KB or 16KB or >thereabouts, see if that has any NUL bytes, and if not, proceed to >read in the rest of the file. But depending o

Re: constant folding - why not more

2020-11-10 Thread Chris Angelico
On Wed, Nov 11, 2020 at 4:01 AM David Kolovratník wrote: > On the contrary, comparison remains for runtime: > >>> dis.dis(compile('1 < 2', filename='', mode='eval', > >>> optimize=2)) > 1 0 LOAD_CONST 0 (1) > 2 LOAD_CONST 1 (2) >

Re: Changing strings in files

2020-11-10 Thread Chris Angelico
On Wed, Nov 11, 2020 at 6:52 AM Barry Scott wrote: > > > > > On 10 Nov 2020, at 19:30, Eli the Bearded <*@eli.users.panix.com> wrote: > > > > In comp.lang.python, Chris Angelico wrote: > >> Eli the Bearded <*@eli.users.panix.com> wrote: > >>> Read first N lines of a file. If all parse as valid UT

Re: Changing strings in files

2020-11-10 Thread Chris Angelico
On Wed, Nov 11, 2020 at 6:36 AM Eli the Bearded <*@eli.users.panix.com> wrote: > > In comp.lang.python, Chris Angelico wrote: > > Eli the Bearded <*@eli.users.panix.com> wrote: > >> Read first N lines of a file. If all parse as valid UTF-8, consider it > >> text. > >> That's probably the rough me

Re: constant folding - why not more

2020-11-10 Thread Terry Reedy
On 11/10/2020 1:03 PM, Barry Scott wrote: On 10 Nov 2020, at 14:45, David Kolovratník wrote: Dear all, I would like to learn about constant folding optimisation in Python. It seems to be implemented in Python/ast_opt.c. In order to get impression I used python3 and dis module: $ python3 -V

Re: Changing strings in files

2020-11-10 Thread Barry Scott
> On 10 Nov 2020, at 19:30, Eli the Bearded <*@eli.users.panix.com> wrote: > > In comp.lang.python, Chris Angelico wrote: >> Eli the Bearded <*@eli.users.panix.com> wrote: >>> Read first N lines of a file. If all parse as valid UTF-8, consider it text. >>> That's probably the rough method file

Re: Changing strings in files

2020-11-10 Thread Eli the Bearded
In comp.lang.python, Chris Angelico wrote: > Eli the Bearded <*@eli.users.panix.com> wrote: >> Read first N lines of a file. If all parse as valid UTF-8, consider it text. >> That's probably the rough method file(1) and Perl's -T use. (In >> particular allow no nulls. Maybe allow ISO-8859-1.) > IS

Re: Changing strings in files

2020-11-10 Thread Manfred Lotz
On Tue, 10 Nov 2020 10:57:05 +0100 "Loris Bennett" wrote: > Manfred Lotz writes: > > > On Tue, 10 Nov 2020 08:19:55 +0100 > > "Loris Bennett" wrote: > > > >> Manfred Lotz writes: > >> > >> > I have a situation where in a directory tree I want to change a > >> > certain string in all file

Re: Changing strings in files

2020-11-10 Thread Manfred Lotz
On Tue, 10 Nov 2020 22:08:54 +1100 Cameron Simpson wrote: > On 10Nov2020 10:07, Manfred Lotz wrote: > >On Tue, 10 Nov 2020 18:37:54 +1100 > >Cameron Simpson wrote: > >> Use os.walk for trees. scandir does a single directory. > > > >Perhaps better. I like to use os.scandir this way > > > >de

Re: Changing strings in files

2020-11-10 Thread Chris Angelico
On Wed, Nov 11, 2020 at 5:36 AM Eli the Bearded <*@eli.users.panix.com> wrote: > Read first N lines of a file. If all parse as valid UTF-8, consider it text. > That's probably the rough method file(1) and Perl's -T use. (In > particular allow no nulls. Maybe allow ISO-8859-1.) > ISO-8859-1 is basi

Re: Changing strings in files

2020-11-10 Thread Eli the Bearded
In comp.lang.python, Loris Bennett wrote: > Manfred Lotz writes: > > My idea was to do > > > > - os.scandir and for each file > >- check if a file is a text file ^^ > >- if it is not a text file skip that file > >- change the string as often as it

Re: constant folding - why not more

2020-11-10 Thread Barry Scott
> On 10 Nov 2020, at 14:45, David Kolovratník wrote: > > Dear all, > > I would like to learn about constant folding optimisation in Python. It seems > to be implemented in Python/ast_opt.c. In order to get impression I used > python3 and dis module: > > $ python3 -V > Python 3.7.3 I do not h

Re: Tkinter List of Canvases

2020-11-10 Thread MRAB
On 2020-11-10 10:01, ChalaoAdda wrote: Hello, I have a list of canvas of images. I would like to display all the images. But it displays the last image. Here is my code. from tkinter import * from PIL import Image, ImageTk root = Tk() canvas_width = 265 canvas_height = 130 canvases = [] r,

constant folding - why not more

2020-11-10 Thread David Kolovratník
Dear all, I would like to learn about constant folding optimisation in Python. It seems to be implemented in Python/ast_opt.c. In order to get impression I used python3 and dis module: $ python3 -V Python 3.7.3 Arithmetics expression is folded as expected: >>> dis.dis(compile('1 * 2', filename=

ANN: DIPY 1.3.0

2020-11-10 Thread Eleftherios Garyfallidis
Hello all, We are excited to announce a new release of DIPY: DIPY 1.3 is out! Please support us by citing DIPY in your papers using the following DOI: 10.3389/fninf.2014.8 DIPY 1.3.0 (Wednesday, 3 November 2020) This release received contribut

Re: Changing strings in files

2020-11-10 Thread Grant Edwards
On 2020-11-10, Manfred Lotz wrote: > What is the best way to check if a file is a text file? Step 1: define "text file" -- Grant -- https://mail.python.org/mailman/listinfo/python-list

Re: Changing strings in files

2020-11-10 Thread Cameron Simpson
On 10Nov2020 10:07, Manfred Lotz wrote: >On Tue, 10 Nov 2020 18:37:54 +1100 >Cameron Simpson wrote: >> Use os.walk for trees. scandir does a single directory. > >Perhaps better. I like to use os.scandir this way > >def scantree(path: str) -> Iterator[os.DirEntry[str]]: >"""Recursively yield D

Re: Changing strings in files

2020-11-10 Thread Chris Angelico
On Tue, Nov 10, 2020 at 9:06 PM Manfred Lotz wrote: > The reason I want to check if a file is a text file is that I don't > want to try replacing patterns in binary files (executable binaries, > archives, audio files aso). > I'd recommend two checks, then: 1) Can the file be decoded as UTF-8? 2)

Tkinter List of Canvases

2020-11-10 Thread ChalaoAdda
Hello, I have a list of canvas of images. I would like to display all the images. But it displays the last image. Here is my code. from tkinter import * from PIL import Image, ImageTk root = Tk() canvas_width = 265 canvas_height = 130 canvases = [] r, c = 0, 0 for tile in tiles: img = ti

Re: Changing strings in files

2020-11-10 Thread Manfred Lotz
On Tue, 10 Nov 2020 18:52:26 +1100 Mike Dewhirst wrote: > On 10/11/2020 5:24 pm, Manfred Lotz wrote: > > I have a situation where in a directory tree I want to change a > > certain string in all files where that string occurs. > > > > My idea was to do > > > > - os.scandir and for each file > >

Re: Changing strings in files

2020-11-10 Thread Manfred Lotz
On Tue, 10 Nov 2020 18:37:54 +1100 Cameron Simpson wrote: > On 10Nov2020 07:24, Manfred Lotz wrote: > >I have a situation where in a directory tree I want to change a > >certain string in all files where that string occurs. > > > >My idea was to do > > > >- os.scandir and for each file > > Us

Re: Changing strings in files

2020-11-10 Thread Loris Bennett
Manfred Lotz writes: > On Tue, 10 Nov 2020 08:19:55 +0100 > "Loris Bennett" wrote: > >> Manfred Lotz writes: >> >> > I have a situation where in a directory tree I want to change a >> > certain string in all files where that string occurs. >> > >> > My idea was to do >> > >> > - os.scandir and

Re: Changing strings in files

2020-11-10 Thread Manfred Lotz
On Tue, 10 Nov 2020 08:19:55 +0100 "Loris Bennett" wrote: > Manfred Lotz writes: > > > I have a situation where in a directory tree I want to change a > > certain string in all files where that string occurs. > > > > My idea was to do > > > > - os.scandir and for each file > >- check if a f

Re: Changing strings in files

2020-11-10 Thread Chris Green
Loris Bennett wrote: > Having said that, I would be interested to know what the most compact > way of doing the same thing in Python might be. > Here's my Python replace script:- #!/usr/bin/python3 # # # String replacement utility # import os import re import sys import shutil def replaceStrin

Re: Changing strings in files

2020-11-10 Thread Mike Dewhirst
On 10/11/2020 5:24 pm, Manfred Lotz wrote: I have a situation where in a directory tree I want to change a certain string in all files where that string occurs. My idea was to do - os.scandir and for each file - check if a file is a text file - if it is not a text file skip that file