Frank Millman schreef op 20/07/2022 om 13:04:
>> On Wed, 20 Jul 2022 at 18:34, Frank Millman wrote:
>>> >>>
>>> >>> x = list(range(10))
>>> >>>
>>> >>> '{x[1]}'.format(**vars())
>>> '1'
>>> >>>
>>> >>> '{x[-1]}'.format(**vars())
>>> Traceback (most recent call last):
>>> File "",
I did a few tests
# test 1
def f():
i = 1
print(locals())
exec('y = i; print(y); print(locals())')
print(locals())
a = eval('y')
print(locals())
u = a
print(u)
f()
{'i': 1}
1
{'i': 1, 'y': 1}
{'i': 1, 'y': 1}
{'i': 1, 'y': 1, 'a': 1}
1
# test 2
def f():
i = 1
offtopic
If you want a pure-python but definitely a more hacky implementation,
you can play around with inspect.stack() and get the variables from
the outer frames.
# code:
x = 32
y = 42
printf("Hello x={x}, y={y}", x=27)
# output:
Hello x=27, y=42
The implementation of printf() was never re
On 7/20/22, george trojan wrote:
>
> 1. This works as I expect it to work:
>
> def f():
> i = 1
> print(locals())
> exec('y = i; print(y); print(locals())')
> print(locals())
> exec('y *= 2')
> print('ok:', eval('y'))
> f()
In CPython, the locals of a function scope (as op
> On 20 Jul 2022, at 18:09, Tianhe wrote:
>
> Python by default builds the library `libpythonMAJOR.MINOR.a` and
> statically links it into the interpreter. Also it has an `--enable-shared`,
> (https://docs.python.org/3/using/configure.html#cmdoption-enable-shared)
> flag, which will build a sh
I wish I could understand the following behaviour:
1. This works as I expect it to work:
def f():
i = 1
print(locals())
exec('y = i; print(y); print(locals())')
print(locals())
exec('y *= 2')
print('ok:', eval('y'))
f()
{'i': 1}
1
{'i': 1, 'y': 1}
{'i': 1, 'y': 1}
ok: 2
On 7/20/22 05:04, Frank Millman wrote:
> I think the preferred style these days is f'{x[-1]}' which works."
>
> Unfortunately the 'f' option does not work for me in this case, as I am
> using a string object, not a string literal.
For that you could consider
https://pypi.org/project/f-yeah/
(s
On Wed, 20 Jul 2022 at 23:50, Peter Otten <__pete...@web.de> wrote:
>
> I found
>
> https://peps.python.org/pep-3101/
>
> """
> PEP 3101 – Advanced String Formatting
> ...
> An example of the ‘getitem’ syntax:
>
> "My name is {0[name]}".format(dict(name='Fred'))
>
> It should be noted that the use
On 20/07/2022 12:08, Chris Angelico wrote:
On Wed, 20 Jul 2022 at 20:55, Frank Millman wrote:
On 2022-07-20 11:37 AM, Chris Angelico wrote:
> On Wed, 20 Jul 2022 at 18:34, Frank Millman wrote:
>>
>> Hi all
>>
>> C:\Users\E7280>python
>> Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38
On 20/07/2022 11:37, Chris Angelico wrote:
On Wed, 20 Jul 2022 at 18:34, Frank Millman wrote:
Hi all
C:\Users\E7280>python
Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64
bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>
On Wed, 20 Jul 2022 at 21:06, Frank Millman wrote:
> I saw this from Paul Rubin - for some reason his posts appear in google
> groups, but not python-list.
>
> "It seems to only want integer constants. x[2+2] and x[k] where k=2
> don't work either.
Yes, that's for the same reason that x[spam] can
On Wed, 20 Jul 2022 at 20:55, Frank Millman wrote:
>
> On 2022-07-20 11:37 AM, Chris Angelico wrote:
> > On Wed, 20 Jul 2022 at 18:34, Frank Millman wrote:
> >>
> >> Hi all
> >>
> >> C:\Users\E7280>python
> >> Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64
> >> bit (AMD6
On 2022-07-20 12:31 PM, Frank Millman wrote:
On 2022-07-20 11:37 AM, Chris Angelico wrote:
On Wed, 20 Jul 2022 at 18:34, Frank Millman wrote:
Hi all
C:\Users\E7280>python
Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64
bit (AMD64)] on win32
Type "help", "copyright"
On 2022-07-20 11:37 AM, Chris Angelico wrote:
On Wed, 20 Jul 2022 at 18:34, Frank Millman wrote:
Hi all
C:\Users\E7280>python
Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64
bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
On 7/20/22, Mike Dewhirst wrote:
> On 20/07/2022 4:43 am, David Raymond wrote:
>> C:\Program Files\Python310\Scripts>..\python.exe -m pip install --upgrade
>> pip
>> ERROR: Could not install packages due to an OSError: [WinError 32] The
>> process cannot access the file because it is being used by
On Wed, 20 Jul 2022 at 18:34, Frank Millman wrote:
>
> Hi all
>
> C:\Users\E7280>python
> Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64
> bit (AMD64)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>>
> >>> x = list(range(10))
> >
Hi all
C:\Users\E7280>python
Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64
bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> x = list(range(10))
>>>
>>> '{x[1]}'.format(**vars())
'1'
>>>
>>> '{x[-1]}'.format(**vars())
17 matches
Mail list logo