regular expressions help

2019-09-19 Thread Pradeep Patra
Hi all, I was playing around with regular expressions and testing the simple regular expression and its notworking for some reason. I want to search "my-dog" at any of the place in a string and return the index but its not working. I tried both in python 3.7.3 and 2.7.x. Can anyone please help? I

Re: regular expressions help

2019-09-19 Thread David
On Thu, 19 Sep 2019 at 17:51, Pradeep Patra wrote: > > pattern=re.compile(r'^my\-dog$') > matches = re.search(mystr) > > In the above example both cases(match/not match) the matches returns "None" Hi, do you know what the '^' character does in your pattern? -- https://mail.python.org/mailman/lis

Re: regular expressions help

2019-09-19 Thread Pradeep Patra
I am using python 2.7.6 but I also tried on python 3.7.3. On Thursday, September 19, 2019, Pradeep Patra wrote: > Beginning of the string. But I tried removing that as well and it still > could not find it. When I tested at www.regex101.com and it matched > successfully whereas I may be wrong. C

Re: Spread a statement over various lines

2019-09-19 Thread Manfred Lotz
On Thu, 19 Sep 2019 08:36:04 +0200 Peter Otten <__pete...@web.de> wrote: > Manfred Lotz wrote: > > >> Not related to your question, but: > >> You seem to try to convert a Windows wildcard pattern to a regex > >> pattern. > > > > No, I'm on Linux. > > > > Shortly, after I had posted the questi

Re: regular expressions help

2019-09-19 Thread David
On Thu, 19 Sep 2019 at 18:41, Pradeep Patra wrote: > On Thursday, September 19, 2019, Pradeep Patra > wrote: >> On Thursday, September 19, 2019, David wrote: >>> On Thu, 19 Sep 2019 at 17:51, Pradeep Patra >>> wrote: >>> > pattern=re.compile(r'^my\-dog$') >>> > matches = re.search(mystr) >>

Re: regular expressions help

2019-09-19 Thread Pradeep Patra
Thanks David for your quick help. Appreciate it. When I tried on python 2.7.3 the same thing you did below I got the error after matches.group(0) as follows: AttributeError: NoneType object has no attribute 'group'. I tried to check 'None' for no match for re.search as the documentation says but

Re: regular expressions help

2019-09-19 Thread David
On Thu, 19 Sep 2019 at 19:34, Pradeep Patra wrote: > Thanks David for your quick help. Appreciate it. When I tried on python 2.7.3 > the same thing you did below I got the error after matches.group(0) as > follows: > > AttributeError: NoneType object has no attribute 'group'. > > I tried to che

Re: exec and globals and locals ...

2019-09-19 Thread Eko palypse
> In all cases, if the optional parts are omitted, the code is executed in the > current scope. ... > > > You can see from it that "globals" is optional. > And that, if "globals" is missing, then > "exec" is executed in the current scope ("f1" in your case). Thank you for your answer, and that

Re: exec and globals and locals ...

2019-09-19 Thread Eko palypse
> Then it should be clear that the name 'test01' is put into globals(), if > load_module() doesn't throw an exception. No sharing or nesting of > namespaces takes place. Thank you too for your answer. Ok, that means that in every case when exec imports something it has its own global namespace,

Re: Spread a statement over various lines

2019-09-19 Thread Peter Otten
Manfred Lotz wrote: >> Where does '%' come from? >> > > '%' was a mistake as I had replied myself to my initial question. Oh, sorry. I missed that. -- https://mail.python.org/mailman/listinfo/python-list

Re: exec and globals and locals ...

2019-09-19 Thread Richard Damon
On 9/19/19 6:16 AM, Eko palypse wrote: >> In all cases, if the optional parts are omitted, the code is executed in the >> current scope. ... >> >> >> You can see from it that "globals" is optional. >> And that, if "globals" is missing, then >> "exec" is executed in the current scope ("f1" in your

Re: exec and globals and locals ...

2019-09-19 Thread Eko palypse
Am Donnerstag, 19. September 2019 12:45:35 UTC+2 schrieb Richard Damon: > On 9/19/19 6:16 AM, Eko palypse wrote: > >> In all cases, if the optional parts are omitted, the code is executed in > >> the current scope. ... > >> > >> > >> You can see from it that "globals" is optional. > >> And that, i

Re: exec and globals and locals ...

2019-09-19 Thread Peter Otten
Eko palypse wrote: >> Then it should be clear that the name 'test01' is put into globals(), if >> load_module() doesn't throw an exception. No sharing or nesting of >> namespaces takes place. > > Thank you too for your answer. Ok, that means that in every case when exec > imports something it has

Re: exec and globals and locals ...

2019-09-19 Thread Eko palypse
Am Donnerstag, 19. September 2019 12:56:59 UTC+2 schrieb Peter Otten: > Eko palypse wrote: > > >> Then it should be clear that the name 'test01' is put into globals(), if > >> load_module() doesn't throw an exception. No sharing or nesting of > >> namespaces takes place. > > > > Thank you too for

Re: exec and globals and locals ...

2019-09-19 Thread Richard Damon
On 9/19/19 6:52 AM, Eko palypse wrote: > Am Donnerstag, 19. September 2019 12:45:35 UTC+2 schrieb Richard Damon: >> On 9/19/19 6:16 AM, Eko palypse wrote: In all cases, if the optional parts are omitted, the code is executed in the current scope. ... You can see from it th

Re: exec and globals and locals ...

2019-09-19 Thread Bev In TX
I’m not the OP, but I want to thank you for that clarification. I had previously not understood the ramifications of the following in section “7. Simple statements” in “The Python Language Reference”: “An augmented assignment expression like x += 1 can be rewritten as x = x + 1 to achieve a si

Re: exec and globals and locals ...

2019-09-19 Thread Peter Otten
Richard Damon wrote: > On 9/19/19 6:16 AM, Eko palypse wrote: >>> In all cases, if the optional parts are omitted, the code is executed in >>> the current scope. ... >>> >>> >>> You can see from it that "globals" is optional. >>> And that, if "globals" is missing, then >>> "exec" is executed in th

Re: exec and globals and locals ...

2019-09-19 Thread Peter Otten
Eko palypse wrote: > Thank you, I'm currently investigating importlib and read that > __builtins__ might be another alternative. > My ultimate goal would be to have objects available without the need to > import them, regardless whether used in a script directly or used in an > imported module. I

Re: regular expressions help

2019-09-19 Thread Pradeep Patra
Thanks David /Anthony for your help. I figured out the issue myself. I dont need any ^, $ etc to the regex pattern and the plain string (for exp my-dog) works fine. I am looking at creating a generic method so that instead of passing my-dog i can pass my-cat or blah blah. I am thinking of creating

Re: Unicode UCS2, UCS4 and ... UCS1

2019-09-19 Thread Gregory Ewing
Eli the Bearded wrote: There isn't anything called UCS1. Apparently there is, but it's not a character set, it's a loudspeaker. https://www.bhphotovideo.com/c/product/1205978-REG/yorkville_sound_ucs1_1200w_15_horn_loaded.html -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Unable to start Python with Windows 7

2019-09-19 Thread cdoare.ext
Hi, I am no more able to start Python from Windows 7 environment. I have the following message : "The Application was unable to start correctly, (0xC142). Click OK to close the application" Do you have any idea where the problem is ? Bests regards, ___ Christian Doa

Re: exec and globals and locals ...

2019-09-19 Thread Eko palypse
No, I have to correct myself x = 5 def f1(): exec("x = x + 1; print('f1 in:', x)") return x print('f1 out', f1()) results in the same, for me confusing, results. f1 in: 6 f1 out 5 Eren -- https://mail.python.org/mailman/listinfo/python-list

Re: Unable to start Python with Windows 7

2019-09-19 Thread Eko palypse
Am Donnerstag, 19. September 2019 17:52:48 UTC+2 schrieb cdoa...@orange.com: > Hi, > I am no more able to start Python from Windows 7 environment. > I have the following message : > "The Application was unable to start correctly, (0xC142). Click OK to > close the application" > > Do you have

Re: exec and globals and locals ...

2019-09-19 Thread Peter Otten
Eko palypse wrote: > No, I have to correct myself > > x = 5 > def f1(): > exec("x = x + 1; print('f1 in:', x)") > return x > print('f1 out', f1()) > > results in the same, for me confusing, results. > > f1 in: 6 > f1 out 5 Inside a function exec assignments go to a *copy* of the local

Re: exec and globals and locals ...

2019-09-19 Thread Eko palypse
First thank you for all the answers, very much appreciated. I assume the root cause might be explained by the zen of python as well. If the implementation is hard to explain, it's a bad idea. Maybe I need to rethink my implementation :-) Eren -- https://mail.python.org/mailman/listinfo/python-l

Re: exec and globals and locals ...

2019-09-19 Thread Eko palypse
Am Donnerstag, 19. September 2019 18:31:43 UTC+2 schrieb Peter Otten: > Eko palypse wrote: > > > No, I have to correct myself > > > > x = 5 > > def f1(): > > exec("x = x + 1; print('f1 in:', x)") > > return x > > print('f1 out', f1()) > > > > results in the same, for me confusing, result

Re: Unicode UCS2, UCS4 and ... UCS1

2019-09-19 Thread MRAB
On 2019-09-19 09:55, Gregory Ewing wrote: Eli the Bearded wrote: There isn't anything called UCS1. Apparently there is, but it's not a character set, it's a loudspeaker. https://www.bhphotovideo.com/c/product/1205978-REG/yorkville_sound_ucs1_1200w_15_horn_loaded.html The OP might mean Py_UCS

Re: regular expressions help

2019-09-19 Thread Chris Angelico
On Fri, Sep 20, 2019 at 1:07 AM Pradeep Patra wrote: > > Thanks David /Anthony for your help. I figured out the issue myself. I > dont need any ^, $ etc to the regex pattern and the plain string (for exp > my-dog) works fine. I am looking at creating a generic method so that > instead of passing

Re: exec and globals and locals ...

2019-09-19 Thread Peter Otten
Eko palypse wrote: > Am Donnerstag, 19. September 2019 18:31:43 UTC+2 schrieb Peter Otten: >> Eko palypse wrote: >> >> > No, I have to correct myself >> > >> > x = 5 >> > def f1(): >> > exec("x = x + 1; print('f1 in:', x)") >> > return x >> > print('f1 out', f1()) >> > >> > results in t

Re: exec and globals and locals ...

2019-09-19 Thread Eko palypse
Am Donnerstag, 19. September 2019 20:24:49 UTC+2 schrieb Peter Otten: > Eko palypse wrote: > > > Am Donnerstag, 19. September 2019 18:31:43 UTC+2 schrieb Peter Otten: > >> Eko palypse wrote: > >> > >> > No, I have to correct myself > >> > > >> > x = 5 > >> > def f1(): > >> > exec("x = x + 1;

Re: What about idea of making a "Pythonic Lisp"...i.e. a Lisp that more closely resembles the syntax of Python?

2019-09-19 Thread Cecil Westerhof
Paul Rubin writes: > Python 3.7.3 (default, Apr 3 2019, 05:39:12) > Type "help", "copyright", "credits" or "license" for more information. > >>> a = range(10) > >>> b = reversed(a) > >>> sum(a) == sum(b) > True > >>> sum(b) == sum(a) > False Why does this happen?

Re: What about idea of making a "Pythonic Lisp"...i.e. a Lisp that more closely resembles the syntax of Python?

2019-09-19 Thread Chris Angelico
On Fri, Sep 20, 2019 at 5:16 AM Cecil Westerhof wrote: > > Paul Rubin writes: > > > Python 3.7.3 (default, Apr 3 2019, 05:39:12) > > Type "help", "copyright", "credits" or "license" for more information. > > >>> a = range(10) > > >>> b = reversed(a) > > >>> sum(a) == sum(b) >

Re: Spread a statement over various lines

2019-09-19 Thread Ralf M.
Am 18.09.2019 um 22:22 schrieb Chris Angelico: On Thu, Sep 19, 2019 at 6:20 AM Ralf M. wrote: Am 17.09.2019 um 20:59 schrieb Manfred Lotz: I have a function like follows def regex_from_filepat(fpat): rfpat = fpat.replace('.', '\\.') \ .replace('%', '.') \

Re: Spread a statement over various lines

2019-09-19 Thread Ralf M.
Am 18.09.2019 um 22:24 schrieb Alexandre Brault: On 2019-09-18 4:01 p.m., Ralf M. wrote: I don't know the exact rules of Windows wildcards, so there may be even more cases of unexpected behavior. If anyone knows where to find the complete rules (or a python module that implements them), I woul

Re: exec and globals and locals ...

2019-09-19 Thread jfong
>>> x = 3 >>> def foo(): ... exec("print(globals(), locals()); x = x + 1; print(globals(), locals())") ... >>> foo() {'foo': , '__package__': None, '__builtins__': , '__loader__': , '__doc__': None, '__name__': '__main__', '__spec__': None, 'x': 3} {} {'foo': , '__package__': None, '__builti

Re: numpy results in segmentation fault

2019-09-19 Thread Aldwin Pollefeyt
use: num_arr1 = numpy.array(tgt_arr1, dtype=int) num_arr2 = numpy.array(tgt_arr2, dtype=int) On Mon, Sep 16, 2019 at 5:36 PM Pradeep Patra wrote: > Yes it is crashing in the hackerrank site and the testcases fails with > segmentation fault. I tried to install numpy with 3.7.3 and it is for som