Re: Symlinks already present

2020-09-03 Thread Greg Ewing

On 2/09/20 6:55 am, Eryk Sun wrote:

According to POSIX (st_dev, st_ino), it's the same directory, yet the
".." entry evaluates depending on the path parsing context:

 >>> os.lstat('test1/spam/..').st_ino == os.lstat('test1').st_ino
 True
 >>> os.lstat('test2/spam/..').st_ino == os.lstat('test2').st_ino
 True


What happens if you go one level deeper? I.e. is
os.lstat('test1/spam/eggs/../..').st_ino == os.lstat('test1').st_ino
and
os.lstat('test2/spam/eggs/../..').st_ino == os.lstat('test2').st_ino
?

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


Re: Symlinks already present

2020-09-03 Thread Eryk Sun
On 9/3/20, Greg Ewing  wrote:
> On 2/09/20 6:55 am, Eryk Sun wrote:
>> According to POSIX (st_dev, st_ino), it's the same directory, yet the
>> ".." entry evaluates depending on the path parsing context:
>>
>>  >>> os.lstat('test1/spam/..').st_ino == os.lstat('test1').st_ino
>>  True
>>  >>> os.lstat('test2/spam/..').st_ino == os.lstat('test2').st_ino
>>  True
>
> What happens if you go one level deeper? I.e. is
> os.lstat('test1/spam/eggs/../..').st_ino == os.lstat('test1').st_ino
> and
> os.lstat('test2/spam/eggs/../..').st_ino == os.lstat('test2').st_ino
> ?

Those two examples return true. Going a level deeper to 'spam/eggs'
doesn't change the behavior of the graft at "test2/spam".

An interesting case is bind mounting a directory on one of its child
directories. For example, if "spam" is mounted on "spam/mount_spam":

>>> s = os.lstat('spam/mount_spam/mount_spam/..')
>>> s.st_ino == os.lstat('spam').st_ino
True

The namespace graft only occurs at "spam/mount_spam". So
"spam/mount_spam/mount_spam" is the original filesystem directory, for
which the ".." entry references "spam". It's also consistent with
"spam/mount_spam" being bound to "spam".
-- 
https://mail.python.org/mailman/listinfo/python-list


Regex to change multiple lines

2020-09-03 Thread Termoregolato
Hi. I've on file, containing multiple lines, and I need to change every 
occurrence of a sequence between two chars, in this case "%%".


-- original
This is the %%text that i must modify%%, on a line, %%but also
on the others%% that are following

I need to change to

-- desidered
This is the text that i must modify, on a line, but also
on the others that are following

I've tryed with this small code

rebarredtext = r'~~([^>]*)~~'
text = mycontent
  for line in re.findall(rebarredtext, text):
text = text.replace("~~" + line + "~~", "" + line + "")


but it changes only the biggest occurrence: how can I do to change all 
occurrences? I'm really a regex newbie, TIA


-- test
This is the text that i must modify%%, on a line, %%but also
on the others that are following
--
https://mail.python.org/mailman/listinfo/python-list


Re: Regex to change multiple lines

2020-09-03 Thread Chris Angelico
On Fri, Sep 4, 2020 at 12:16 AM Termoregolato  wrote:
>
> Hi. I've on file, containing multiple lines, and I need to change every
> occurrence of a sequence between two chars, in this case "%%".
>
> -- original
> This is the %%text that i must modify%%, on a line, %%but also
> on the others%% that are following
>
> I need to change to
>
> -- desidered
> This is the text that i must modify, on a line, but also
> on the others that are following
>
> I've tryed with this small code
>
> rebarredtext = r'~~([^>]*)~~'

The trouble here is that the bit in the middle will take as much as it
possibly can, even though that includes the marker. (BTW, you're
inconsistent here as to whether the marker is "%%" or "~~".) I'm not
sure why you're excluding ">" from this group, but I presume that
that's intentional.

To solve this, you can make the asterisk "non-greedy" by adding a
question mark after it:

rebarredtext = r'~~([^>]*?)~~'

Now it matches as *little* as it possibly can.

Additionally, you can get the regex engine to do the work of replacing, too.

re.sub(rebarredtext, r'\1', txt)

That'll do the whole loop and everything; it replaces every match of
the regex with the given replacement text, where "\1" takes whatever
was inside the parentheses.

Regular expressions are incredibly powerful, but unfortunately hard to
debug, so all you can do is test and tinker :)

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


Re: Regex to change multiple lines

2020-09-03 Thread Tim Chase
On 2020-09-03 16:10, Termoregolato wrote:
> -- original
> This is the %%text that i must modify%%, on a line, %%but also
> on the others%% that are following
> 
> I need to change to
> 
> -- desidered
> This is the text that i must modify, on a line, but
> also on the others that are following

Should be able to use

 :%s/%%\(\_.\{-}\)%%/\1<\/del>/g

It simplifies slightly if you use a different delimiter

 :%s@%%\(\_.\{-}\)%%@\1@g

-tim



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


Re: Regex to change multiple lines

2020-09-03 Thread Tim Chase
Derp, sorry about the noise.  I mistook this message for a similar
dialog over on the Vim mailing list.

For Python, you want

  re.sub(r"%%(.*?)%%", r"\1", s, flags=re.S)

or put the flag inline

  re.sub(r"(?s)%%(.*?)%%", r"\1", s)

-tim

On 2020-09-03 09:27, Tim Chase wrote:
> On 2020-09-03 16:10, Termoregolato wrote:
> > -- original
> > This is the %%text that i must modify%%, on a line, %%but also
> > on the others%% that are following
> > 
> > I need to change to
> > 
> > -- desidered
> > This is the text that i must modify, on a line,
> > but also on the others that are following  
> 
> Should be able to use
> 
>  :%s/%%\(\_.\{-}\)%%/\1<\/del>/g
> 
> It simplifies slightly if you use a different delimiter
> 
>  :%s@%%\(\_.\{-}\)%%@\1@g
> 
> -tim
> 
> 
> 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What kind of magic do I need to get python to talk to Excel xlsm file?

2020-09-03 Thread Ian Hill
If you don't need to do any specific data analysis using pandas, try
openpyxl.

It will read xlsm files and it quite straight forward to use.

https://openpyxl.readthedocs.io/en/stable/

pip install openpyxl.

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


Replacement for pygtk?

2020-09-03 Thread Grant Edwards
Many years ago I wrote an app that uses pygtk for it's GUI.  I still
use the app occasionally, and would like to keep it alive.  Emerge
informs me that dev-python/pygtk is scheduled for removal.

Is pygobject the replacement for pygtk?

--
Grant


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


Pyserial and some half-duplex woes.

2020-09-03 Thread Mark Barton

Hey All,

I am using Microchip's Python program to download 
code to a PIC32 microprocessor via Pyserial. There 
is also Microchip's bootloader code running on the 
PIC side. This works very well using the a 
standard serial hardware directly connected to a 
USB to serial adapter to one of the PIC's UARTs. 
However in our application the hardware is a 
single wire thus requiring a half-duplex 
communications. Fortunately Microchip's protocol 
lends itself to half-duplex communications, 
however the problem is that both the PIC and the 
Python program will receive an echo when one of 
the other transmits due to the hardware design. It 
other words the PIC will receive what it transmits 
and the same on the Python side. The PIC side is 
easily fixed by simply turning off receive during 
transmit. I don't think I can do this on the 
Python side at least there nothing in Pyserial's 
documentation that you can do that.


I have tried to do some flushing of the receive 
buffer, but I haven't been too successful. Perhaps 
that is due to timing.


I thought I would reach out to see if anyone may 
have had a similar experience.


Thanks for any help.

Mark


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


Re: Regex to change multiple lines

2020-09-03 Thread Termoregolato

Il 03/09/20 16:10, Termoregolato wrote:


I need to change every occurrence of a sequence between two chars


Thanks to all for your replies, it's time to learn regular expressions, 
but now I've some valid pointers from you.


The work I must do here, to explain, is to get some markdown files, and 
add the strikethrough in a different color from the original, so I've do 
a bit of confusion between markdown "~~" and my "%%" in examples, where 
I wanted to reduce the number of lines.

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


Re: Replacement for pygtk?

2020-09-03 Thread Grant Edwards
On 2020-09-03, Grant Edwards  wrote:
> [...]
>
> Is pygobject the replacement for pygtk?

It seems to be.  I've started porting my pygtk app, and it's going
pretty smoothly.  I've already got my two custom widgets working.
Oddly, the main module provided by the gobject package is called "gi".


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


Re: Regex to change multiple lines

2020-09-03 Thread Chris Angelico
On Fri, Sep 4, 2020 at 5:36 AM Termoregolato  wrote:
>
> Il 03/09/20 16:10, Termoregolato wrote:
>
> > I need to change every occurrence of a sequence between two chars
>
> Thanks to all for your replies, it's time to learn regular expressions,
> but now I've some valid pointers from you.
>
> The work I must do here, to explain, is to get some markdown files, and
> add the strikethrough in a different color from the original, so I've do
> a bit of confusion between markdown "~~" and my "%%" in examples, where
> I wanted to reduce the number of lines.

Hmm. Have you considered using CSS to do this? Markdown is generally
fairly easy to style with CSS.

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


Re: Replacement for pygtk?

2020-09-03 Thread Michael Torrie
On 9/3/20 1:17 PM, Grant Edwards wrote:
> On 2020-09-03, Grant Edwards  wrote:
>> [...]
>>
>> Is pygobject the replacement for pygtk?
> 
> It seems to be.  I've started porting my pygtk app, and it's going
> pretty smoothly.  I've already got my two custom widgets working.
> Oddly, the main module provided by the gobject package is called "gi".

It stands for "gobject introspection." The nice thing about the gi
module is it can wrap any gobject-based library, not just GTK+ proper.
So if someone made a custom widget in Vala, for example, you could
access it via gi.  It's a neat idea. My only problem with it is the
resulting Python API is not always as pythonic as pygtk code was.  I
can't think of any specific examples at the moment, however.  It's
pretty much good enough to not care too much.  Similar arguments can be
made against PyQt as well.  Especially with PyQt the end result feels a
bit like writing C++ with a python syntax.

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


Re: Threading plus multiprocessing plus cv2 error

2020-09-03 Thread Python
On Sat, Aug 29, 2020 at 06:24:10PM +1000, John O'Hagan wrote:
> Dear list
> 
> Thanks to this list, I haven't needed to ask a question for
> a very long time, but this one has me stumped.
> 
> Here's the minimal 3.8 code, on Debian testing:
> 
> -
> from multiprocessing import Process
> from threading import Thread
> from time import sleep
> import cv2
> 
> def show(im, title, location):
> cv2.startWindowThread()
> cv2.namedWindow(title)
> cv2.moveWindow(title, *location)
> cv2.imshow(title, im)
> sleep(2) #just to keep window open
> 
> im1 = cv2.imread('/path/to/image1')
> im2 = cv2.imread('/path/to/image2')
> 
> Thread(target=show, args=(im1, 'im1', (600,0))).start()
> sleep(1)
> Process(target=show, args=(im2, 'im2', (0, 0))).start()
> -
> 
> Here's the error:
> 
> -
> [xcb] Unknown sequence number while processing queue
> [xcb] Most likely this is a multi-threaded client and XInitThreads has
> not been called 
> [xcb] Aborting, sorry about that.
> python3: ../../src/xcb_io.c:260: poll_for_event: Assertion
> `!xcb_xlib_threads_sequence_lost' failed.
> -

It's hard to say EXACTLY what the nature of the error is, without
knowing what the underlying libraries are doing.  But from this one
thing is clear:  You are starting a new thread, and then forking a new
process.  This is very likely to break, because contrary to what
several people have said in this thread, the new thread WILL NOT be
copied to the new program, so in the new process, part of your program
is literally missing.  This can have all kinds of consequences.

For that reason, you can't spawn a new thread and then fork a new
process, in that order, and expect your program to function correctly.
Whatever your program does that depends on that new thread won't work
correctly, because that thread does not exist in the child (new
process).  You can, however, do those things in the reverse order and
it should be fine... new threads will be started in both processes
(unless you take steps to ensure only one of the processes creates the
thread).  Both processes retain their integrity and should run fine.

> There's no error without the sleep(1), nor if the Process is started
> before the Thread, nor if two Processes are used instead, nor if two
> Threads are used instead. IOW the error only occurs if a Thread is
> started first, and a Process is started a little later.

Hopefully my explanation above makes it clear why all of those things
are true, other than the sleep() issue.  That one is most likely just
a timing issue:  Whatever resource is causing the problem hasn't been
set up yet or the critical thread or process has already finished
execution before the issue can arise, or something of the sort.  When
you start new threads or processes, usually there's some delay as your
OS schedules each process/thread to run, which is somewhat random
based on how the scheduler works and how loaded the system is.  Such
timing problems (bugs that seem to happen randomly with each run of
the program, or over time in a long-executing program) are common in
multi-threaded programs that are written incorrectly, especially when
the state of one thread depends on the state of the other thread, and
the two don't synchronize correctly.  This is another way that the
first problem above can manifest, too: The threads can't synchronize
because one of them does not exist!

Hope that helps.



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


compile error building building Python-3.8.5 on Debian 8.11 (yes, old!)

2020-09-03 Thread Cameron Simpson
I've built 3.8.5 on a few other machines happily recently.

Building Python 3.8.5, running make and gcc (Debian 4.9.2-10+deb8u2) 
4.9.2 I get this:

% gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 
-Wall-std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter 
-Wno-missing-field-initializers -Werror=implicit-function-declaration  
-I./Include/internal  -I.  -I./Include-DPy_BUILD_CORE -o Modules/gcmodule.o 
Modules/gcmodule.c
Modules/gcmodule.c: In function 'collect.constprop':
Modules/gcmodule.c:126:50: warning: array subscript is above array bounds 
[-Warray-bounds]
 #define GEN_HEAD(state, n) (&(state)->generations[n].head)
  ^
Modules/gcmodule.c:1036:43: note: in expansion of macro 'GEN_HEAD'
 gc_list_merge(GEN_HEAD(state, i), GEN_HEAD(state, generation));
   ^
Modules/gcmodule.c:126:50: warning: array subscript is above array bounds 
[-Warray-bounds]
 #define GEN_HEAD(state, n) (&(state)->generations[n].head)
  ^
Modules/gcmodule.c:1036:43: note: in expansion of macro 'GEN_HEAD'
 gc_list_merge(GEN_HEAD(state, i), GEN_HEAD(state, generation));
   ^
Modules/gcmodule.c:126:50: warning: array subscript is above array bounds 
[-Warray-bounds]
 #define GEN_HEAD(state, n) (&(state)->generations[n].head)
  ^
Modules/gcmodule.c:1036:43: note: in expansion of macro 'GEN_HEAD'
 gc_list_merge(GEN_HEAD(state, i), GEN_HEAD(state, generation));
   ^

Any thoughts?

I'll try a few other minor versions meanwhile...

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


Re: compile error building building Python-3.8.5 on Debian 8.11 (yes, old!)

2020-09-03 Thread Chris Angelico
On Fri, Sep 4, 2020 at 3:01 PM Cameron Simpson  wrote:
>
> I've built 3.8.5 on a few other machines happily recently.
>
> Building Python 3.8.5, running make and gcc (Debian 4.9.2-10+deb8u2)
> 4.9.2 I get this:
>
> % gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv 
> -O3 -Wall-std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter 
> -Wno-missing-field-initializers -Werror=implicit-function-declaration  
> -I./Include/internal  -I.  -I./Include-DPy_BUILD_CORE -o 
> Modules/gcmodule.o Modules/gcmodule.c
> Modules/gcmodule.c: In function 'collect.constprop':
> Modules/gcmodule.c:126:50: warning: array subscript is above array bounds 
> [-Warray-bounds]
>  #define GEN_HEAD(state, n) (&(state)->generations[n].head)
>   ^
> Modules/gcmodule.c:1036:43: note: in expansion of macro 'GEN_HEAD'
>  gc_list_merge(GEN_HEAD(state, i), GEN_HEAD(state, generation));
>^
> Modules/gcmodule.c:126:50: warning: array subscript is above array bounds 
> [-Warray-bounds]
>  #define GEN_HEAD(state, n) (&(state)->generations[n].head)
>   ^
> Modules/gcmodule.c:1036:43: note: in expansion of macro 'GEN_HEAD'
>  gc_list_merge(GEN_HEAD(state, i), GEN_HEAD(state, generation));
>^
> Modules/gcmodule.c:126:50: warning: array subscript is above array bounds 
> [-Warray-bounds]
>  #define GEN_HEAD(state, n) (&(state)->generations[n].head)
>   ^
> Modules/gcmodule.c:1036:43: note: in expansion of macro 'GEN_HEAD'
>  gc_list_merge(GEN_HEAD(state, i), GEN_HEAD(state, generation));
>^
>
> Any thoughts?
>

Those are warnings; if there are errors that block compilation, they
aren't in what you quoted above.

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