On 2024-03-20 at 09:49:54 +0100,
Roel Schroeven via Python-list wrote:
> You haven't only checked for None! You have rejected *every* falsish value,
> even though they may very well be acceptable values.
OTOH, only you can answer these questions about your situations.
Every application, every i
Op 19/03/2024 om 0:44 schreef Gilmeh Serda via Python-list:
On Mon, 18 Mar 2024 10:09:27 +1300, dn wrote:
> YMMV!
> NB your corporate Style Guide may prefer 'the happy path'...
If you only want to check for None, this works too:
>>> name = None
>>> dafault_value = "default"
>>> name or default
It's too complicated, there's no need for this
def __init__(self, config):
self.__dict__ = config
self.connection = None
"""
other code .
"""
Note that you need to keep the fields in the config dict named the same as
the fields you want to be assigne
Tobiah writes:
> I should mention that I wanted to answer your question,
> but I wouldn't actually do this. I'd rather opt for
> your self.config = config solution. The config options
> should have their own namespace.
>
> I don't mind at all referencing foo.config['option'],
> or you could mak
I should mention that I wanted to answer your question,
but I wouldn't actually do this. I'd rather opt for
your self.config = config solution. The config options
should have their own namespace.
I don't mind at all referencing foo.config['option'],
or you could make foo.config an object by its
ith a view to asking forgiveness rather than
permission, is there some simple way just to assign the dictionary
elements which do in fact exist to self-variables?
class Foo():
def __init__(self, config):
for key, val in config.iteritems():
setattr(self
dn wrote:
>Loris Bennett wrote:
>> However, with a view to asking forgiveness rather than
>> permission, is there some simple way just to assign the dictionary
>> elements which do in fact exist to self-variables?
>
>Assuming config is a dict:
>
> self.
If we are bringing up other languages, let's return to what was part of the
original question.
How van a dictionary be used in python if your goal is to sort of use it to
instantiate it into a set of variables and values inside the local or global or
other namespaces? Can we learn any
On 18/03/24 04:11, Peter J. Holzer via Python-list wrote:
On 2024-03-17 17:15:32 +1300, dn via Python-list wrote:
On 17/03/24 12:06, Peter J. Holzer via Python-list wrote:
On 2024-03-16 08:15:19 +, Barry via Python-list wrote:
On 15 Mar 2024, at 19:51, Thomas Passin via Python-list
wrote
On 2024-03-17 17:15:32 +1300, dn via Python-list wrote:
> On 17/03/24 12:06, Peter J. Holzer via Python-list wrote:
> > On 2024-03-16 08:15:19 +, Barry via Python-list wrote:
> > > > On 15 Mar 2024, at 19:51, Thomas Passin via Python-list
> > > > wrote:
> > > > I've always like writing using
On 17/03/24 12:06, Peter J. Holzer via Python-list wrote:
On 2024-03-16 08:15:19 +, Barry via Python-list wrote:
On 15 Mar 2024, at 19:51, Thomas Passin via Python-list
wrote:
I've always like writing using the "or" form and have never gotten bit
I, on the other hand, had to fix a prod
On 2024-03-16 08:15:19 +, Barry via Python-list wrote:
> > On 15 Mar 2024, at 19:51, Thomas Passin via Python-list
> > wrote:
> > I've always like writing using the "or" form and have never gotten bit
>
> I, on the other hand, had to fix a production problem that using “or”
> introducted.
>
On 16/03/24 21:15, Barry via Python-list wrote:
On 15 Mar 2024, at 19:51, Thomas Passin via Python-list
wrote:
I've always like writing using the "or" form and have never gotten bit
I, on the other hand, had to fix a production problem that using “or”
introducted.
I avoid this idiom beca
On 3/16/2024 8:12 AM, Roel Schroeven via Python-list wrote:
Barry via Python-list schreef op 16/03/2024 om 9:15:
> On 15 Mar 2024, at 19:51, Thomas Passin via Python-list
wrote:
> > I've always like writing using the "or" form and have never gotten
bit
I, on the other hand, had to fix a p
Barry via Python-list schreef op 16/03/2024 om 9:15:
> On 15 Mar 2024, at 19:51, Thomas Passin via Python-list
wrote:
>
> I've always like writing using the "or" form and have never gotten bit
I, on the other hand, had to fix a production problem that using “or”
introducted.
I avoid this
> On 15 Mar 2024, at 19:51, Thomas Passin via Python-list
> wrote:
>
> I've always like writing using the "or" form and have never gotten bit
I, on the other hand, had to fix a production problem that using “or”
introducted.
I avoid this idiom because it fails on falsy values.
Barry
--
htt
of control.
-Original Message-
From: Python-list On
Behalf Of Dan Sommers via Python-list
Sent: Friday, March 15, 2024 5:33 PM
To: python-list@python.org
Subject: Re: Configuring an object via a dictionary
On 2024-03-15 at 15:48:17 -0400,
Thomas Passin via Python-list wrote:
> [...] And I sup
On 3/15/2024 5:33 PM, Dan Sommers via Python-list wrote:
On 2024-03-15 at 15:48:17 -0400,
Thomas Passin via Python-list wrote:
[...] And I suppose there is always the possibility that sometime in
the future an "or" clause like that will be changed to return a
Boolean, which one would expect an
question, the __init__(), are at least
equally-important considerations (see below)!
I could of course simply test each element of the dictionary before
trying to use. I could also just write
self.config = config
but then addressing the elements will add more clutter to the code.
By
On 2024-03-15 at 15:48:17 -0400,
Thomas Passin via Python-list wrote:
> [...] And I suppose there is always the possibility that sometime in
> the future an "or" clause like that will be changed to return a
> Boolean, which one would expect anyway.
Not only is the current value is way more usefu
entifier']
self.group_base = config['group_base']
self.group_identifier = config['group_identifier']
self.owner_base = config['owner_base']
However, some entries in the configuration might be missing. What is
the best way of dealing with t
x27;]
>> self.user_identifier = config['user_identifier']
>> self.group_base = config['group_base']
>> self.group_identifier = config['group_identifier']
>> self.owner_base = config['owner_base']
>>
>> However,
;group_identifier']
self.owner_base = config['owner_base']
However, some entries in the configuration might be missing. What is
the best way of dealing with this?
I could of course simply test each element of the dictionary before
trying to use. I could also just write
sel
On 3/15/24 03:30, Loris Bennett via Python-list wrote:
Hi,
I am initialising an object via the following:
self.source_name = config['source_name']
config.get('source_name', default_if_not_defined) is a common technique...
--
https://mail.python.org/mailman/listinfo/python-list
x27;]
However, some entries in the configuration might be missing. What is
the best way of dealing with this?
I could of course simply test each element of the dictionary before
trying to use. I could also just write
self.config = config
but then addressing the elements will add m
On 3/7/24 07:11, Varuna Seneviratna via Python-list wrote:
If a dictionary key has a Python list as its value, you can read the values
one by one in the list using a for-loop like in the following.
d = {k: [1,2,3]}
for v in d[k]:
print(v)
No tutorial describes this, why?
What is the
On 2024-03-07 14:11, Varuna Seneviratna via Python-list wrote:
If a dictionary key has a Python list as its value, you can read the values
one by one in the list using a for-loop like in the following.
d = {k: [1,2,3]}
for v in d[k]:
print(v)
No tutorial describes this, why?
What is
If a dictionary key has a Python list as its value, you can read the values
one by one in the list using a for-loop like in the following.
d = {k: [1,2,3]}
> for v in d[k]:
> print(v)
No tutorial describes this, why?
What is the Python explanation for this behaviour?
Varuna
--
On 21Jan2024 23:39, bagra...@live.com wrote:
class NameMe(dict):
def __missing__(self, key):
return key
I would need to know more about what it might be used for. What larger
problem led you to writing a `dict` subclass with this particular
`__missing__` implementation?
--
https:/
class NameMe(dict):
def __missing__(self, key):
return key
--
https://mail.python.org/mailman/listinfo/python-list
I don’t see what is surprising. The interface for a dictionary never specified
the ordering of the keys, so I would not be surprised to see it vary based on
release, platform, values of keys inserted, number of items in the dictionary,
etc.
—
Gerard Weatherby | Application Architect NMRbox
On Mon, Aug 1, 2022 at 4:42 PM Dan Stromberg wrote:
>
> > Yes, but I'm pretty sure that's been true for a LONG time. The hashes
>> > for small integers have been themselves for as long as I can remember.
>> > But the behaviour of the dictionary, when
, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
> > >
> > > Just sayin'. :-)
> >
> > Yes, but I'm pretty sure that's been true for a LONG time. The hashes
> > for small integers have been themselves for as long as I can remember.
> >
uot;license" for more information.
> > >>> [hash(x) for x in range(20)]
> > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
> >
> > Just sayin'. :-)
>
> Yes, but I'm pretty sure that's been true for a LONG time. Th
1, 12, 13, 14, 15, 16, 17, 18, 19]
>
> Just sayin'. :-)
Yes, but I'm pretty sure that's been true for a LONG time. The hashes
for small integers have been themselves for as long as I can remember.
But the behaviour of the dictionary, when fed such keys, is what's
changed.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
On 2022-08-01 at 13:41:11 -0700,
Dan Stromberg wrote:
> keys = [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7, 12, 11]
>
> dict_ = {}
> for key in keys:
> dict_[key] = 1
$ python
Python 3.10.5 (main, Jun 6 2022, 18:49:26) [GCC 12.1.0] on linux
Type "help", "copyright", "credits" or "license" for more
On Mon, Aug 1, 2022 at 1:41 PM Dan Stromberg wrote:
> On 1.4 through 2.1 I got descending key order. I expected the keys to be
> scattered, but they weren't.
>
I just noticed that 1.4 was ascending order too - so it was closer to 2.2
than 1.5.
I guess that's kind of beside the point though - it
On Tue, 2 Aug 2022 at 06:50, Skip Montanaro wrote:
>
> >
> > So I decided to write a little test program to run on a variety of
> > CPythons, to confirm what I was thinking.
> >
> > And instead I got a surprise.
> >
> > On 1.4 through 2.1 I got descending key order. I expected the keys to be
> >
>
> So I decided to write a little test program to run on a variety of
> CPythons, to confirm what I was thinking.
>
> And instead I got a surprise.
>
> On 1.4 through 2.1 I got descending key order. I expected the keys to be
> scattered, but they weren't.
>
> On 2.2 through 3.5 I got ascending ke
Hi folks.
I'm still porting some code from Python 2.7 to 3.10.
As part of that, I saw a list being extended with a dict.values(), and
thought perhaps it wasn't ordered as intended on Python 2.7, even though
the problem would conceivably just disappear on 3.10.
So I decided to write a little test
On Thu, Jun 9, 2022 at 1:52 PM Michael F. Stemper
wrote:
> On 09/06/2022 12.52, Chris Angelico wrote:
> > On Fri, 10 Jun 2022 at 03:44, Dave wrote:
>
> >> Before I write my own I wondering if anyone knows of a function that
> will print a nicely formatted diction
On 2022-06-09, Dennis Lee Bieber wrote:
> However, the Gmane list<>NNTP gateway server DOES make the tutor
> list available to news readers (unfortunately, the comp.lang.python
> <> list <> Gmane has been read-only since last fall (unless things
> have changed recently) so I'm stuck with the spam
On 09Jun2022 21:35, Dave wrote:
>I quite like the format that JSON gives - thanks a lot!
Note that JSON output is JavaScript notation, not Python. The `pprint`
module (which has `pprint` and `pformat` functions) outputs Python
notation.
If you're just writing for human eyes, JSON is fine, thou
On 09/06/2022 12.52, Chris Angelico wrote:
On Fri, 10 Jun 2022 at 03:44, Dave wrote:
Before I write my own I wondering if anyone knows of a function that will print
a nicely formatted dictionary?
By nicely formatted I mean not all on one line!
https://docs.python.org/3/library
of a function that will print
a nicely formatted dictionary?
By nicely formatted I mean not all on one line!
Cheers
Dave
--
https://mail.python.org/mailman/listinfo/python-list
Hi,
I quite like the format that JSON gives - thanks a lot!
Cheers
Dave
> On 9 Jun 2022, at 20:02, Stefan Ram wrote:
>
> Since nicety is in the eyes of the beholder, I would not
> hesitate to write a custom function in this case. Python
> has the standard modules "pprint" and "json".
>
>
On 6/9/22 11:52, Chris Angelico wrote:
> On Fri, 10 Jun 2022 at 03:44, Dave wrote:
>>
>> Hi,
>>
>> Before I write my own I wondering if anyone knows of a function that will
>> print a nicely formatted dictionary?
>>
>> By nicely format
pprint may have what you want in
pprint.pprint() but you can write a function for yourself that takes a
dictionary and loops through items and prints them one per line and, if you
feel like it, also prints how many items there are and your own custom touches
such as doing them alphabetically
On Fri, 10 Jun 2022 at 03:44, Dave wrote:
>
> Hi,
>
> Before I write my own I wondering if anyone knows of a function that will
> print a nicely formatted dictionary?
>
> By nicely formatted I mean not all on one line!
>
https://docs.python.org/3/library/pprint.html
f
On 2022-06-09 11:43, Dave wrote:
Hi,
Before I write my own I wondering if anyone knows of a function that will print
a nicely formatted dictionary?
By nicely formatted I mean not all on one line!
It's called "pretty-printing". Have a look at the 'pprint' module.
-
On Thu, Jun 9, 2022 at 11:44 AM Dave wrote:
>
> Hi,
>
> Before I write my own I wondering if anyone knows of a function that will
> print a nicely formatted dictionary?
>
> By nicely formatted I mean not all on one line!
>>> import json
>>> d = {
Hi,
Before I write my own I wondering if anyone knows of a function that will print
a nicely formatted dictionary?
By nicely formatted I mean not all on one line!
Cheers
Dave
--
https://mail.python.org/mailman/listinfo/python-list
Yes, that works. This is my first day with C API dictionaries. Now that
you've explained it, it makes perfect sense. Thanks much.
Jen
Feb 14, 2022, 17:24 by ros...@gmail.com:
> On Tue, 15 Feb 2022 at 12:07, Jen Kris via Python-list
> wrote:
>
>>
>> I created a
On Tue, 15 Feb 2022 at 12:07, Jen Kris via Python-list
wrote:
>
> I created a dictionary with the Python C API and assigned two keys and values:
>
> PyObject* this_dict = PyDict_New();
> const char *key = "key1";
> char *val = "data_01";
> PyObject* v
I created a dictionary with the Python C API and assigned two keys and values:
PyObject* this_dict = PyDict_New();
const char *key = "key1";
char *val = "data_01";
PyObject* val_p = PyUnicode_FromString(val);
int r = PyDict_SetItemString(this_dict, key, val_p);
// Add
On 1/8/2021 2:56 AM, Umar Draz wrote:
I want to replace duplicate values with empty "" in my dictionary. Here is
my original dictionary.
items = [
{'client': 'xyz', 'name': "Ilir Meta", 'rating': 0.06, 'total': 100
On 2021-01-08 09:56, Umar Draz wrote:
I want to replace duplicate values with empty "" in my dictionary. Here is
my original dictionary.
items = [
{'client': 'xyz', 'name': "Ilir Meta", 'rating': 0.06, 'total': 100
I want to replace duplicate values with empty "" in my dictionary. Here is
my original dictionary.
items = [
{'client': 'xyz', 'name': "Ilir Meta", 'rating': 0.06, 'total': 100},
{'client': 'xyz'
On Fri, Oct 02, 2020 at 09:25:58PM +0100, Shaozhong SHI wrote:
> Hi, All,
>
> I was trying to handle the value of "personRoles" in a part of json
> dictionary.
>
> Can anyone tell me various ways to handle this?
I'm not sure if I understand what you're a
Hi, All,
I was trying to handle the value of "personRoles" in a part of json
dictionary.
Can anyone tell me various ways to handle this?
Regards,
Shao
"regulatedActivities": [
{
"name": "Accommodation for persons who require nursing or
ormation.
>>> d = dict(a=1)
>>> for k in d: del d["a"]
...
Traceback (most recent call last):
File "", line 1, in
RuntimeError: dictionary changed size during iteration
If you look at the 2.7 mailbox code you'll find that the iteritems() method
delegate
produces
> >the error:-
> >
> >RuntimeError: dictionary changed size during iteration
> >
> >I can sort of see why I'm getting the error but have two questions:
> >
> >1 - Why doesn't it error in Python 2?
>
> The dict internal impl
On 23Aug2020 10:00, Chris Green wrote:
>I have a (fairly) simple little program that removes old mail messages
>from my junk folder. I have just tried to upgrade it from Python 2 to
>Python 3 and now, when it finds any message[s] to delete it produces
>the error:-
>
>Runtim
I have a (fairly) simple little program that removes old mail messages
from my junk folder. I have just tried to upgrade it from Python 2 to
Python 3 and now, when it finds any message[s] to delete it produces
the error:-
RuntimeError: dictionary changed size during iteration
I can sort of
Thank you for the help! Based on your response/recommendation, I am
thinking that my entire approach to solving my problem is very poor. I am
trying to pull slices from a dataframe, store them in a nested dictionary,
retrieve them, perform calculations, store the results in the same nested
Aaron wrote:
> When creating a nested dictionary of dataframes, how can I name a
> dictionary based on a list name of the dataframe?
>
> Given the following:
>
> # START CODE
> import pandas as pd
>
> cars = {'Brand': ['Honda Civic',
When creating a nested dictionary of dataframes, how can I name a
dictionary based on a list name of the dataframe?
Given the following:
# START CODE
import pandas as pd
cars = {'Brand': ['Honda Civic','Toyota Corolla'],
'Price': [22000,2500
On 17Nov2019 12:26, Iranna Mathapati wrote:
How to remove duplicates dict from the list of dictionary based on one
of
the duplicate elements in the dictionary,
l = [{"component":"software", "version":"1.2" },
{"component":"
Hi,
How to remove duplicates dict from the list of dictionary based on one of
the duplicate elements in the dictionary,
l = [{"component":"software", "version":"1.2" },
{"component":"hardware", "version":"2.2"
On 06/28/2019 09:06 AM, CrazyVideoGamez wrote:
> How do you insert an item into a dictionary? For example, I make a dictionary
> called "dictionary".
>
> dictionary = {1: 'value1', 2: 'value3'}
>
> What if I wanted to add a value2 in the m
On Sat, Jun 29, 2019 at 1:51 AM Jon Ribbens via Python-list
wrote:
>
> On 2019-06-28, Larry Martell wrote:
> > On Fri, Jun 28, 2019 at 11:10 AM CrazyVideoGamez
> > wrote:
> >>
> >> How do you insert an item into a dictionary? For example, I make a
On 2019-06-28, Larry Martell wrote:
> On Fri, Jun 28, 2019 at 11:10 AM CrazyVideoGamez
> wrote:
>>
>> How do you insert an item into a dictionary? For example, I make a
>> dictionary called "dictionary".
>>
>> dictionary = {1: 'value1', 2:
On Fri, Jun 28, 2019 at 11:10 AM CrazyVideoGamez
wrote:
>
> How do you insert an item into a dictionary? For example, I make a dictionary
> called "dictionary".
>
> dictionary = {1: 'value1', 2: 'value3'}
>
> What if I wanted to add a value2
You simply assign to the key, like so:
dictionary[3] = 'value2'
But it isn't clear what you mean by "in the middle".
On Fri, Jun 28, 2019 at 11:10 AM CrazyVideoGamez
wrote:
> How do you insert an item into a dictionary? For example, I make a
> dictionary call
How do you insert an item into a dictionary? For example, I make a dictionary
called "dictionary".
dictionary = {1: 'value1', 2: 'value3'}
What if I wanted to add a value2 in the middle of value1 and value3?
--
https://mail.python.org/mailman/listinfo/python-list
Phu Sam wrote:
> The condition 'if not fibs.get(n):' will not work because
> n = 0
> fibs.get(0) is 0 so not 0 is 1
>
> Here is the modified code that works:
>
> fibs={0:0,1:1}
> def rfib(n):
> if n == 0 or n == 1:
> return fibs[n]
> else:
> fibs[n]=rfib(n-2
The condition 'if not fibs.get(n):' will not work because
n = 0
fibs.get(0) is 0 so not 0 is 1
Here is the modified code that works:
fibs={0:0,1:1}
def rfib(n):
if n == 0 or n == 1:
return fibs[n]
else:
fibs[n]=rfib(n-2)+rfib(n-1)
return fibs[n]
>>>
Le 24/02/2019 à 05:21, Himanshu Yadav a écrit :
fibs={0:0,1:1}
def rfib(n):
global fibs
if not fibs.get(n):
fibs[n]=rfib(n-2)+rfib(n-1)
return fibs[n]
Why it is gives error??
Nothing to do with the malfunction, but you dont need
to define fibs as globa
On 2019-02-24 04:21, Himanshu Yadav wrote:
fibs={0:0,1:1}
def rfib(n):
global fibs
if not fibs.get(n):
fibs[n]=rfib(n-2)+rfib(n-1)
return fibs[n]
Why it is gives error??
What error?
--
https://mail.python.org/mailman/listinfo/python-list
Himanshu Yadav wrote:
> fibs={0:0,1:1}
> def rfib(n):
> global fibs
>if not fibs.get(n):
> fibs[n]=rfib(n-2)+rfib(n-1)
> return fibs[n]
Please use cut and paste to make sure you are not introducing new errors
like the inconsistent indentation above.
> Why
fibs={0:0,1:1}
def rfib(n):
global fibs
if not fibs.get(n):
fibs[n]=rfib(n-2)+rfib(n-1)
return fibs[n]
Why it is gives error??
--
https://mail.python.org/mailman/listinfo/python-list
jf...@ms4.hinet.net於 2018年12月28日星期五 UTC+8下午4時04分07秒寫道:
> eryk sun at 2018/12/27 UTC+8 PM 6:58:33 wrote:
> > On 12/27/18, jf...@ms4.hinet.net wrote:
> > >
> > > I still don't get it. When I change it to using list comprehension, the
> > > problem is still there. (it now has no late-binding variable
eryk sun at 2018/12/27 UTC+8 PM 6:58:33 wrote:
> On 12/27/18, jf...@ms4.hinet.net wrote:
> >
> > I still don't get it. When I change it to using list comprehension, the
> > problem is still there. (it now has no late-binding variable, right? :-)
> >
> class Too:
> > ... XS = [15, 15, 15,
On Fri, Dec 28, 2018 at 8:47 AM eryk sun wrote:
>
> On 12/27/18, Chris Angelico wrote:
> >
> > Class scope is special, and a generator expression within that class
> > scope is special too. There have been proposals to make these kinds of
> > things less special, but the most important thing to r
On 12/27/18, Chris Angelico wrote:
>
> Class scope is special, and a generator expression within that class
> scope is special too. There have been proposals to make these kinds of
> things less special, but the most important thing to remember is that
> when you create a generator expression, it
On Fri, Dec 28, 2018 at 3:31 AM Ian Kelly wrote:
>
> On Wed, Dec 26, 2018 at 11:21 PM Chris Angelico wrote:
> >
> > On Thu, Dec 27, 2018 at 1:56 PM wrote:
> > >
> > > I saw the code below at stackoverflow. I have a little idea about the
> > > scope of a class, and list comprehension and generat
On Wed, Dec 26, 2018 at 11:21 PM Chris Angelico wrote:
>
> On Thu, Dec 27, 2018 at 1:56 PM wrote:
> >
> > I saw the code below at stackoverflow. I have a little idea about the scope
> > of a class, and list comprehension and generator expressions, but still
> > can't figure out why Z4 works and
On 12/27/18, jf...@ms4.hinet.net wrote:
>
> I still don't get it. When I change it to using list comprehension, the
> problem is still there. (it now has no late-binding variable, right? :-)
>
class Too:
> ... XS = [15, 15, 15, 15]
> ... Z4 = [val for val in XS]
> ... Z5 = [XS[0]
On 12/26/2018 9:53 PM, jf...@ms4.hinet.net wrote:
I saw the code below at stackoverflow. I have a little idea about the scope of
a class, and list comprehension and generator expressions, but still can't
figure out why Z4 works and Z5 not. Can someone explain it? (in a
not-too-complicated way:
eryk sun於 2018年12月27日星期四 UTC+8下午2時31分58秒寫道:
> On 12/26/18, jf...@ms4.hinet.net wrote:
> > I saw the code below at stackoverflow. I have a little idea about the scope
> > of a class, and list comprehension and generator expressions, but still
> > can't figure out why Z4 works and Z5 not. Can someon
On 12/26/18, jf...@ms4.hinet.net wrote:
> I saw the code below at stackoverflow. I have a little idea about the scope
> of a class, and list comprehension and generator expressions, but still
> can't figure out why Z4 works and Z5 not. Can someone explain it? (in a
> not-too-complicated way:-)
>
>
On Thu, Dec 27, 2018 at 1:56 PM wrote:
>
> I saw the code below at stackoverflow. I have a little idea about the scope
> of a class, and list comprehension and generator expressions, but still can't
> figure out why Z4 works and Z5 not. Can someone explain it? (in a
> not-too-complicated way:-)
greetings,
1)
Z4 = sum(val for val in XS)
is same as
Z4 = sum(XS)
2)
class Foo()
can also ne written as
class Foo:
3)
in Foo.x you are using the class just to assoxiate some variables with a
name. what is the purpose of tge script / what are you trying to do?
Abdur-Rahmaan Janhangeer
htt
I saw the code below at stackoverflow. I have a little idea about the scope of
a class, and list comprehension and generator expressions, but still can't
figure out why Z4 works and Z5 not. Can someone explain it? (in a
not-too-complicated way:-)
class Foo():
XS = [15, 15, 15, 15]
Z4 =
,
sorry about that.
https://stackoverflow.com/questions/53924235/why-doesnt-a-dictionary-work-in-classes
By the way, I remember having a problem in the past when writing a list
comprehension which uses a variable name that was also used outside
the list comprehension. for example "[i * 2 for i in
אורי wrote:
> Why does this not work:
>
> class User(ValidateUserPasswordMixin, PermissionsMixin, Entity,
> AbstractBaseUser):
> GENDER_VALID_VALUES = [choice[0] for choice in GENDER_CHOICES]
> GENDERS_DICT = {GENDER_FEMALE: GENDER_FEMALE_STRING, GENDER_MALE:
> ALL_GENDERS = [GENDER
On 12/25/18, אורי wrote:
>
> ALL_GENDERS = [GENDERS_DICT[gender] for gender in GENDER_VALID_VALUES]
>
> (it throws an exception: `NameError: name 'GENDERS_DICT' is not defined`)
Python 3 comprehensions have their own scope. This prevents the side
effect of defining the comprehension's loop variab
emale") and the other two tuples something similar? You
already declared similar (but all lowercase) strings above. So what is this odd
notation for:
_("Female")
If that section fails, then GENDER_CHOICES does not get created. Did you not
get an error message for that?
Bu
On 12/25/2018 7:45 AM, אורי wrote:
Why does this not work:
class User(ValidateUserPasswordMixin, PermissionsMixin, Entity,
AbstractBaseUser):
GENDER_UNKNOWN = 0
> ...
Indent needed here. I presume you used tabs, which disappeared in
transmission, but I cannot cut and paste to run this.
-
Why does this not work:
class User(ValidateUserPasswordMixin, PermissionsMixin, Entity,
AbstractBaseUser):
GENDER_UNKNOWN = 0
GENDER_FEMALE = 1
GENDER_MALE = 2
GENDER_OTHER = 3
GENDER_MAX_VALUE_PLUS_ONE = 4
GENDER_FEMALE_STRING = 'female'
GENDER_MALE_STRING = 'male'
GENDER_OTHER_STRING = 'other'
1 - 100 of 4108 matches
Mail list logo