On 5/23/2020 2:21 PM, Ralf M. wrote:
# Code of mod1.py #
import enum, mod2
class En(enum.Enum):
A = 1
B = 2
def main():
a = mod2.getA()
print("a is En.A:", a is En.A)
print("a:", repr(a), " En.A:", repr(En.A))
print("id(a), id(a.__class__)", id(a),
Richard Damon schreef op 23/05/2020 om 20:57:
On 5/23/20 2:21 PM, Ralf M. wrote:
Hello,
recently I wrote a small library that uses an Enum. That worked as
expected. Then I added a main() and if __name__ == "__main__" to make
it runable as script. Now Enum members that should be the same aren't
On 05/23/2020 11:57 AM, Richard Damon wrote:
I don't think Python anywhere defines that a enum will be a singleton,
and you should be checking for equality (==) not identity (is)
If you're not sure, please do a little research first. We have enough bad
information on the 'nets already.
On Sun, May 24, 2020 at 5:58 AM Kushal Kumaran wrote:
>
> "Ralf M." writes:
>
> > Below are a simplified code sample, the results when I run it and my
> > thoughts.
> >
> > # Code of mod1.py #
> > import enum, mod2
> > def main():
> > a = mod2.getA()
> > # End of mod1.py #
>
"Ralf M." writes:
> Hello,
>
> recently I wrote a small library that uses an Enum. That worked as
> expected. Then I added a main() and if __name__ == "__main__" to make
> it runable as script. Now Enum members that should be the same aren't
> identical any more, there seem to be two instances
Peter Otten wrote:
>> # Code of mod2.py #
> import __main__ as mod1
>> def getA():
>>return mod1.En.A
>> # End of mod2.py #
>
> but that would hardcode the assumption that __main__ is always mod1.py.
I should have mentioned the cyclic dependency -- if two modules import each
Richard Damon writes:
> On 5/23/20 2:21 PM, Ralf M. wrote:
>> Hello,
>>
>> recently I wrote a small library that uses an Enum. That worked as
>> expected. Then I added a main() and if __name__ == "__main__" to make
>> it runable as script. Now Enum members that should be the same aren't
>>
Ralf M. wrote:
> Hello,
>
> recently I wrote a small library that uses an Enum. That worked as
> expected. Then I added a main() and if __name__ == "__main__" to make it
> runable as script. Now Enum members that should be the same aren't
> identical any more, there seem to be two instances of
On 5/23/20 2:21 PM, Ralf M. wrote:
> Hello,
>
> recently I wrote a small library that uses an Enum. That worked as
> expected. Then I added a main() and if __name__ == "__main__" to make
> it runable as script. Now Enum members that should be the same aren't
> identical any more, there seem to be
Hello,
recently I wrote a small library that uses an Enum. That worked as
expected. Then I added a main() and if __name__ == "__main__" to make it
runable as script. Now Enum members that should be the same aren't
identical any more, there seem to be two instances of the same Enum.
I think
10 matches
Mail list logo