While I don't like that syntax, we do know that sets are unhashable, so we
can be certain that that would be a TypeError if it was meant to construct
a set containing a set. (ie. {{foo}} will always result in a TypeError in
python).
On Thu, Jun 8, 2017 at 1:40 PM Chris Angelico
On Fri, Jun 9, 2017 at 6:02 AM, MRAB wrote:
> It could also be used on the RHS to pack:
>
a = 1
b = 2
c = 3
d = 4
foo = {{a, b, c, d}}
The trouble with that is that it's syntactically identical to creating
a set containing a set containing
Welcome to the group, Joannah!
Now that you've been introduced to packing and unpacking in Python, I would
suggest learning the complete syntax, because it's a very useful feature.
>>> a, b = "hi" # you can unpack any iterable
>>> a
'h'
>>> b
'i'
>>> a, b = 1, 2 # this is the same as: a, b =
On 2017-06-08 20:16, Nick Badger wrote:
Well, it's not deliberately not destructive, but I'd be more in favor of
dict unpacking-assignment if it were spelled more like this:
>>> foo = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
>>> {'a': bar, 'b': baz, **rest} = foo
>>> bar
1
>>>
On 06/08/2017 12:22 PM, Brett Cannon wrote:
Already exists, been discussed, and rejected:
https://bugs.python.org/issue29447 .
Ah, right, because the returned object is not a file path. Makes sense.
--
~Ethan~
___
Python-ideas mailing list
On Thu, 8 Jun 2017 at 08:27 Ethan Furman wrote:
> On 06/08/2017 06:42 AM, Antoine Pietri wrote:
> > Hello everyone!
> >
> > A very common pattern when dealing with temporary files is code like
> this:
> >
> > with tempfile.TemporaryDirectory() as tmpdir:
> >
Well, it's not deliberately not destructive, but I'd be more in favor of
dict unpacking-assignment if it were spelled more like this:
>>> foo = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
>>> {'a': bar, 'b': baz, **rest} = foo
>>> bar
1
>>> baz
2
>>> rest
{'c': 3, 'd': 4}
On Thu, Jun 8, 2017 at 9:42 AM, Antoine Pietri
wrote:
> My proposal is to define __fspath__() for TemporaryDirectory and
> NamedTemporaryFile so that we can pass those directly to the library
> functions instead of having to use the .name attribute explicitely.
>
+1
On 06/08/2017 06:42 AM, Antoine Pietri wrote:
Hello everyone!
A very common pattern when dealing with temporary files is code like this:
with tempfile.TemporaryDirectory() as tmpdir:
tmp_path = tmpdir.name
os.chmod(tmp_path)
os.foobar(tmp_path)
On 8 June 2017 at 17:49, Paul Moore wrote:
> On 8 June 2017 at 08:15, Stephen J. Turnbull
> wrote:
>> If you like this feature, and wish it were in Python, I genuinely wish
>> you good luck getting it in. My point is just that in
Hello everyone!
A very common pattern when dealing with temporary files is code like this:
with tempfile.TemporaryDirectory() as tmpdir:
tmp_path = tmpdir.name
os.chmod(tmp_path)
os.foobar(tmp_path)
open(tmp_path).read(barquux)
PEP 519
Thanks for response on automatic tuple unpack. My bad I dint know about
this all along.
Infact this works same way Go does. I have been analyzing why we would
really need such a function (allow function to return multiple types) in
python given we have this feature( automatic tuple unpack) and
On Jun 8, 2017 1:35 AM, "Greg Ewing" wrote:
C Anthony Risinger wrote:
> Incredibly useful and intuitive, and for me again, way more generally
> applicable than iterable unpacking. Maps are ubiquitous.
>
Maps with a known, fixed set of keys are relatively uncommon
Lucas Wiman writes:
> > Maps with a known, fixed set of keys are relatively uncommon
> > in Python, though.
>
> This is false in interacting with HTTP services, where frequently you're
> working with deserialized JSON dictionaries you expect to be in a precise
> format (and fail if not).
Hi Lucas,
I would consider converting the dict into a namedtuple then.
Essentially the namedtuple acts as a specification for expected fielsds:
abc = namedtuple("ABC", "a b c")
d = {"a":1, "b": 2, "c":3} # presumably you got this from reading some JSON
abc(**d)
# returns: ABC(a=1, b=2, c=3)
>
> Maps with a known, fixed set of keys are relatively uncommon
> in Python, though.
This is false in interacting with HTTP services, where frequently you're
working with deserialized JSON dictionaries you expect to be in a precise
format (and fail if not).
On Wed, Jun 7, 2017 at 11:32 PM,
C Anthony Risinger wrote:
Incredibly useful and
intuitive, and for me again, way more generally applicable than iterable
unpacking. Maps are ubiquitous.
Maps with a known, fixed set of keys are relatively uncommon
in Python, though. Such an object is more likely to be an
object with named
One existing way to do this:
a, b, c = (mydict[k] for k in ('a', 'b', 'c'))
--
Greg
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
18 matches
Mail list logo