Re: on slices, negative indices, which are the equivalent procedures?

2021-08-06 Thread Chris Angelico
On Sat, Aug 7, 2021 at 5:22 AM Boris Dorestand wrote: > > Jach Feng writes: > > >> > s = "Jack Brandom" > >> > s[3 : -13 : -1] > >> >> 'kcaJ' > >> >> I have no idea how to replace that -13 with a positive index. Is it > >> >> possible at all? > > That's not possible because a positive ind

Re: on slices, negative indices, which are the equivalent procedures?

2021-08-06 Thread Boris Dorestand
Jach Feng writes: >> > s = "Jack Brandom" >> > s[3 : -13 : -1] >> >> 'kcaJ' >> >> I have no idea how to replace that -13 with a positive index. Is it >> >> possible at all? > That's not possible because a positive index is relative to the leftmost item > 0 And the middle index is al

Re: Ask for help on using re

2021-08-06 Thread jak
Il 06/08/2021 12:57, Jach Feng ha scritto: jak 在 2021年8月6日 星期五下午4:10:05 [UTC+8] 的信中寫道: Il 05/08/2021 11:40, Jach Feng ha scritto: I want to distinguish between numbers with/without a dot attached: text = 'ch 1. is\nch 23. is\nch 4 is\nch 56 is\n' re.compile(r'ch \d{1,}[.]').findall(text) ['c

Re: Ask for help on using re

2021-08-06 Thread Jon Ribbens via Python-list
On 2021-08-06, jak wrote: > Il 06/08/2021 16:17, jak ha scritto: >> Il 06/08/2021 12:57, Jach Feng ha scritto: >>> That's an interest solution! Where the '|' operator in re.compile() >>> was documented? >> >> I honestly can't tell you, I've been using it for over 30 years. In any >> case you can

Re: Ask for help on using re

2021-08-06 Thread Jach Feng
jak 在 2021年8月6日 星期五下午4:10:05 [UTC+8] 的信中寫道: > Il 05/08/2021 11:40, Jach Feng ha scritto: > > I want to distinguish between numbers with/without a dot attached: > > > text = 'ch 1. is\nch 23. is\nch 4 is\nch 56 is\n' > re.compile(r'ch \d{1,}[.]').findall(text) > > ['ch 1.', 'ch 23.']

Re: Ask for help on using re

2021-08-06 Thread jak
Il 06/08/2021 16:17, jak ha scritto: Il 06/08/2021 12:57, Jach Feng ha scritto: jak 在 2021年8月6日 星期五下午4:10:05 [UTC+8] 的信中寫道: Il 05/08/2021 11:40, Jach Feng ha scritto: I want to distinguish between numbers with/without a dot attached: text = 'ch 1. is\nch 23. is\nch 4 is\nch 56 is\n' re.compi

Re: Ask for help on using re

2021-08-06 Thread Jach Feng
ast 在 2021年8月5日 星期四下午11:29:15 [UTC+8] 的信中寫道: > Le 05/08/2021 à 17:11, ast a écrit : > > Le 05/08/2021 à 11:40, Jach Feng a écrit : > >> I want to distinguish between numbers with/without a dot attached: > >> > > text = 'ch 1. is\nch 23. is\nch 4 is\nch 56 is\n' > > re.compile(r'ch \d{1,

Re: Ask for help on using re

2021-08-06 Thread jak
Il 05/08/2021 11:40, Jach Feng ha scritto: I want to distinguish between numbers with/without a dot attached: text = 'ch 1. is\nch 23. is\nch 4 is\nch 56 is\n' re.compile(r'ch \d{1,}[.]').findall(text) ['ch 1.', 'ch 23.'] re.compile(r'ch \d{1,}[^.]').findall(text) ['ch 23', 'ch 4 ', 'ch 56 '

Re: on slices, negative indices, which are the equivalent procedures?

2021-08-06 Thread Jach Feng
> > s = "Jack Brandom" > > s[3 : -13 : -1] > >> 'kcaJ' > >> I have no idea how to replace that -13 with a positive index. Is it > >> possible at all? That's not possible because a positive index is relative to the leftmost item 0 Below is some rules of slice usage which I collected so

Re: on slices, negative indices, which are the equivalent procedures?

2021-08-06 Thread Jack Brandom
"Michael F. Stemper" writes: > On 05/08/2021 12.35, Jack Brandom wrote: >> The FAQ at >>https://docs.python.org/3/faq/programming.html#what-s-a-negative-index >> makes me think that I can always replace negative indices with >> positive >> ones --- even in slices, although the FAQ seems not t

Re: on slices, negative indices, which are the equivalent procedures?

2021-08-06 Thread Michael F. Stemper
On 05/08/2021 12.35, Jack Brandom wrote: The FAQ at https://docs.python.org/3/faq/programming.html#what-s-a-negative-index makes me think that I can always replace negative indices with positive ones --- even in slices, although the FAQ seems not to say anything about slices. With slices, i

on slices, negative indices, which are the equivalent procedures?

2021-08-06 Thread Jack Brandom
The FAQ at https://docs.python.org/3/faq/programming.html#what-s-a-negative-index makes me think that I can always replace negative indices with positive ones --- even in slices, although the FAQ seems not to say anything about slices. With slices, it doesn't seem to always work. For insta

Re: Ask for help on using re

2021-08-06 Thread ast
Le 06/08/2021 à 02:57, Jach Feng a écrit : ast 在 2021年8月5日 星期四下午11:29:15 [UTC+8] 的信中寫道: Le 05/08/2021 à 17:11, ast a écrit : Le 05/08/2021 à 11:40, Jach Feng a écrit : import regex # regex is more powerful that re text = 'ch 1. is\nch 23. is\nch 4 is\nch 56 is\n' regex.findall(r'ch \d++(?!

Re: Defining a Python enum in a C extension - am I doing this right?

2021-08-06 Thread Serhiy Storchaka
03.08.21 13:03, Bartosz Golaszewski пише: > Just a follow-up: this is how I did it eventually: I think it can be simpler. 1. No need to create the __main__ module. You can just create a dict. If some attributes are required (e.g. __name__) it is easy to set them in the Python code (__name__ = 'py

Re: Flask – how to write csv file & save using prefilled value of the filename (response.headers["Content-Disposition"]="attachment; filename=xxx")

2021-08-06 Thread MRAB
On 2021-08-06 16:50, Suretha Weweje wrote: I am trying to upload a CSV file with flask, read and process one line at a time while iterating through all rows of the file and write the results back to a new CSV file. My python script produces the correct results on its own, but I am not able to ge

Flask – how to write csv file & save using prefilled value of the filename (response.headers["Content-Disposition"]="attachment; filename=xxx")

2021-08-06 Thread Suretha Weweje
I am trying to upload a CSV file with flask, read and process one line at a time while iterating through all rows of the file and write the results back to a new CSV file. My python script produces the correct results on its own, but I am not able to get the same results when using Flask. I am new