Re: exec and globals and locals ...

2019-09-18 Thread Peter Otten
Eko palypse wrote: > exec('import test01', globals()) > print('f3 out', x) > > # result exception, expected but because f1 didn't throw an exception > # I'm confused. module test01 has only this two lines > x += 1 > print('f3 in:', x) The lines above run in the test01's global namespace, not in

Re: Spread a statement over various lines

2019-09-18 Thread Peter Otten
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 question I discovered fnmatch() in the > standard library, and I changed my code accordingly. I wou

Re: exec and globals and locals ...

2019-09-18 Thread dieter
Eko palypse writes: > Why does f1 work? I've expected an exception as no global dict has been > provided > ... >def f1(...): > exec("...") >... The documentation ("https://docs.python.org/3/library/functions.html#exec";) tells you: exec(object[, globals[, locals]]) ... In all cases, if the opt

Re: Spread a statement over various lines

2019-09-18 Thread Manfred Lotz
On Wed, 18 Sep 2019 22:01:34 +0200 "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('%', '.') \ > >.rep

Re: Spread a statement over various lines

2019-09-18 Thread codewizard
On Wednesday, September 18, 2019 at 9:01:21 AM UTC-4, Manfred Lotz wrote: > On Wed, 18 Sep 2019 08:30:08 +0200 > Peter Otten <__pete...@web.de> wrote: > > > Manfred Lotz wrote: > > > > > I have a function like follows > > > > > > def regex_from_filepat(fpat): > > > rfpat = fpat.replace('.',

exec and globals and locals ...

2019-09-18 Thread Eko palypse
Why does f1 work? I've expected an exception as no global dict has been provided, and why does throw f3 an exception if it does, more or less, the same as f1? x += 5 def f1(): exec("x += 1; print('f1 in:', x)") return x print('f1 out', f1()) # result => f1 in: 6 # result => f1 out 5 x

Re: Spread a statement over various lines

2019-09-18 Thread Alexandre Brault
On 2019-09-18 4:01 p.m., 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('%', '.')  \ >>    .replace('*', '.*') >> >

Re: Spread a statement over various lines

2019-09-18 Thread 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('%', '.') \ > >.replace(

Re: Spread a statement over various lines

2019-09-18 Thread Ralf M.
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('%', '.') \ .replace('*', '.*') return '^' + rfpat + '$' As I don't want to have the r

Re: Spread a statement over various lines

2019-09-18 Thread Manfred Lotz
On Wed, 18 Sep 2019 08:30:08 +0200 Peter Otten <__pete...@web.de> wrote: > Manfred Lotz wrote: > > > I have a function like follows > > > > def regex_from_filepat(fpat): > > rfpat = fpat.replace('.', '\\.') \ > > .replace('%', '.') \ > > .replace(

Re: Spread a statement over various lines

2019-09-18 Thread Manfred Lotz
On Wed, 18 Sep 2019 09:52:21 +0200 Wolfgang Maier wrote: > On 17.09.19 20:59, Manfred Lotz wrote: > > I have a function like follows > > > > def regex_from_filepat(fpat): > > rfpat = fpat.replace('.', '\\.') \ > > .replace('%', '.') \ > > .replace

Re: Obtain the file's path.

2019-09-18 Thread Cameron Simpson
On 18Sep2019 03:36, eryk sun wrote: On 9/17/19, Cameron Simpson wrote: If you just want this for your running program's internals this may not matter, but if you're recording the result somewhere then abspath might get you a more "stable" path in the above scenario. If a path has ".." compo

Re: Obtain the file's path.

2019-09-18 Thread Pankaj Jangid
Cameron Simpson writes: > On 17Sep2019 15:09, Hongyi Zhao wrote: >>See the following two methods for obtaining the file's path: >> >>os.path.realpath(file) >>or >>os.path.abspath(os.path.expanduser(file)) >> >>Which is more robust? > > My inclination is often to use abspath, because it may bette

Re: Obtain the file's path.

2019-09-18 Thread Eryk Sun
On 9/17/19, Cameron Simpson wrote: > > If you just want this for your running program's internals this may not > matter, but if you're recording the result somewhere then abspath might > get you a more "stable" path in the above scenario. If a path has ".." components, the abspath() result may be

Re: Spread a statement over various lines

2019-09-18 Thread Wolfgang Maier
On 17.09.19 20:59, Manfred Lotz wrote: > I have a function like follows > > def regex_from_filepat(fpat): > rfpat = fpat.replace('.', '\\.') \ > .replace('%', '.') \ > .replace('*', '.*') > > return '^' + rfpat + '$' > > > As I don't want to