Scott W Dunning writes:
> Hello, i am working on a project for learning python and I’m stuck.
> The directions are confusing me. Please keep in mind I’m very ne to
> this.
Scott, please default to asking these “covered in a beginner Python
course” questions at the Python tutor forum
https://mai
Hello, i am working on a project for learning python and I’m stuck. The
directions are confusing me. Please keep in mind I’m very ne to this. The
directions are long so I’ll just add the paragraphs I’m confused about and my
code if someone could help me out I’d greatly appreciate it! Also, w
Terry Reedy writes:
> On 2/27/2014 7:07 AM, Mark H. Harris wrote:
>
>> Oh, and one more thing... whoever is doing the work on IDLE these
>> days, nice job! It is stable, reliable, and just works/
>> appreciate it!
>
> As one of 'them', thank you for the feedback. There are still some
> bugs, bu
hugocoolens writes:
> It often happens I start a python-script I wrote some time ago on another
> system and get messages like "module_x is missing". I then perform an
> apt-cache search module_x, followed by an apt-get install
> name_of_missing_module.deb
> I was wondering whether someone here
On Friday, February 28, 2014 11:16:18 PM UTC-6, Ian wrote:
> How would you propose doing that? Bear in mind that while Python
> knows that tuples specifically are immutable, it doesn't generally
> know whether a type is immutable.
I was going to bed, and then thought of the solution. Allow th
On Sat, Mar 1, 2014 at 5:16 PM, Mark H. Harris wrote:
> This is what I mean... the error message is telling the user that it cannot
> do what he has requested, and yet IT DID. You have one of two scenarios:
> 1) the message is arbitrarily lying and it really can assign an immutable's
> ite
On Sat, Mar 1, 2014 at 4:30 PM, Mark H. Harris wrote:
> hi Chris, yeah... well think again of the switch block in C... the switch
> block selects a branch based on an integral number (int character) that is
> generally a return code from a function. The function hides all of that
> logic.
On Friday, February 28, 2014 11:16:18 PM UTC-6, Ian wrote:
> How would you propose doing that? Bear in mind that while Python
> knows that tuples specifically are immutable, it doesn't generally
> know whether a type is immutable.
hi Ian, consider the problem... its a "cake" and "eat it too
On Friday, February 28, 2014 11:34:56 PM UTC-6, Ian wrote:
> One very common example of tuples containing lists is when lists are
> passed to any function that accepts *args, because the extra arguments
> are passed in a tuple. A similarly common example is when returning
> multiple objects from
On Fri, Feb 28, 2014 at 9:45 PM, Mark H. Harris wrote:
> I really believe IMHO that the error should have come when you made the list
> an item of a tuple. An immutable object should have NO REASON to contain a
> mutable object like list... I mean the whole point is to eliminate the
> overhea
On Friday, February 28, 2014 8:01:45 PM UTC-6, Chris Angelico wrote:
>
> Does your switch construct have to handle the magic of GT_1 meaning ">
> 1", or do you first figure out where it falls with an if/elif tree?
> ChrisA
hi Chris, yeah... well think again of the switch block in C... the
On Fri, Feb 28, 2014 at 6:27 PM, Eric Jacoboni wrote:
> Anyway, the TypeError should rollback, not commit the mistake.
The Python interpreter isn't a database. It can't rollback the object
because the operation that was performed may not be reversible.
Consider for example a socket class where t
On Fri, Feb 28, 2014 at 5:22 PM, Mark H. Harris wrote:
> I really think this is a bug; honestly. IMHO it should be an error to use
> += with an immutable type and that means not at all. In other words, the
> list should not even be considered, because we're talking about changing a
> tuple
On Friday, February 28, 2014 7:27:17 PM UTC-6, Eric Jacoboni wrote:
> I agree with that too... My error was to first consider the list, then
> the tuple... I should have considered the tuple first...
> Anyway, the TypeError should rollback, not commit the mistake.
I believe so too, but I'm not o
On Friday, February 28, 2014 8:15:38 PM UTC-6, Ned Batchelder wrote:
> Mark, if you are going to advocate for a feature, find a good use case,
> this one is absurd. Where did the constants GT_1 etc, come from?
Not at all. Think of the C switch block... if you read about it in the K & R
you'l
Gregory Ewing writes:
> Ben Finney wrote:
> > That whole chapter of the tutorial talks about “variable” and “variable
> > assignment”, when IMO it should avoid those terms and use the clearer
> > terminology of “reference”, “name”, and “binding a name to a value”.
>
> What about all the other thi
On Sat, 01 Mar 2014 13:03:53 +1100, Chris Angelico wrote:
> On Sat, Mar 1, 2014 at 12:59 PM, Steven D'Aprano
> wrote:
>> However, the example as given won't quite work. You never instantiate
>> the Idle etc. classes, which means the methods won't work. You need to
>> make them class methods or st
Mark H. Harris wrote:
if (n**2 < D(1)):
a = __atan__(n)
elif (n == D(1)):
a = gpi/4
elif (n == D(-1)):
a = -(gpi/4)
elif (n < D(-1)):
a = __atan__Lt_neg1__(n)
else:
a = __atan__Gt_1__(n)
That's not a candidate for a switch statement,
Ben Finney wrote:
That whole chapter of the tutorial talks about “variable” and “variable
assignment”, when IMO it should avoid those terms and use the clearer
terminology of “reference”, “name”, and “binding a name to a value”.
What about all the other things that can be assigned
to but aren't
On 2/28/14 8:08 PM, Mark H. Harris wrote:
On Friday, February 28, 2014 6:40:06 PM UTC-6, Ned Batchelder wrote:
I don't understand: you show an if/elif chain that cannot be expressed
as a switch statement (because it uses < ), and then conclude that
Python needs a switch statement? That doesn'
On Sat, Mar 1, 2014 at 12:59 PM, Steven D'Aprano
wrote:
> However, the example as given won't quite work. You never instantiate the
> Idle etc. classes, which means the methods won't work. You need to make
> them class methods or static methods, or perform some metaclass magic
> prevent them from
On Sat, Mar 1, 2014 at 12:08 PM, Mark H. Harris wrote:
> On Friday, February 28, 2014 6:40:06 PM UTC-6, Ned Batchelder wrote:
>
>>
>> I don't understand: you show an if/elif chain that cannot be expressed
>> as a switch statement (because it uses < ), and then conclude that
>> Python needs a switc
On Sat, Mar 1, 2014 at 10:06 AM, Marko Rauhamaa wrote:
> A colleague of mine taught me decades back that the whole point of OO
> was the avoidance of if and switch statements. So if your code has an if
> or switch statement, chances are you are doing something wrong.
>
> I agree.
*boggle*
Are yo
On Sat, 01 Mar 2014 03:06:38 +0200, Marko Rauhamaa wrote:
> Steven D'Aprano :
>
>> I can only imagine you mean something like this:
>>
>> class Outer:
>> class InnerOne:
>> ...
>>
>> class InnerTwo:
>> ...
>>
>> class InnerThree:
>> ...
>>
>>
> No, I mean this:
On Sat, Mar 1, 2014 at 6:20 AM, Marko Rauhamaa wrote:
> Your example:
>
> compare_key = {
> # Same target(s).
> ast.Assign: lambda node: ' '.join(dump(t) for t in node.targets),
> # Same target and same operator.
> ast.AugAssign: lambda node: dump(node.target) +
Marko Rauhamaa writes:
> Ben Finney :
>
> > They are *not* necessarily distinct from other strings with equal
> > value, defined elsewhere. That's what has been pointed out to you
> > many times.
>
> That point is completely irrelevant. The state objects only need to be
> distinct from each other
On Sat, Mar 1, 2014 at 11:22 AM, Mark H. Harris wrote:
> lists within a tuple should be converted to tuples.If you want a tuple to
> hold a list, make it a list in the first place. Tuples should not be
> changed... and as you point out... half changing a tuple is not a good
> condition if
On Friday, February 28, 2014 7:10:49 PM UTC-6, Mark Lawrence wrote:
> I think you're talking nonsense. I've been happily using dict dispatch
> tables for years and, like Steven and presumably many others, find them
> dead easy to read. Perhaps you should invest in a better optician
> and/or g
Le 01/03/2014 01:22, Mark H. Harris a écrit :
> I'll address the second first by asking a question... should an immutable
> type (object) be able to hold (contain) mutable objects ... should tuples be
> allowed to hold lists?
>
> lists within a tuple should be converted to tuples.If you w
On 01/03/2014 01:10, Marko Rauhamaa wrote:
Ben Finney :
>From each other, of course they're distinct, because they are unequal.
They are *not* necessarily distinct from other strings with equal
value, defined elsewhere. That's what has been pointed out to you many
times.
That point is comple
On 01/03/2014 00:03, Marko Rauhamaa wrote:
Dict dispatch tables are elegant, attractive and efficient if you are
using pre-existing functions or functions you can create using lambda:
I beg to differ. The dict dispatch tables are very hard to read. The
fully blown-out if-else chain beats it i
Ben Finney :
>>From each other, of course they're distinct, because they are unequal.
>
> They are *not* necessarily distinct from other strings with equal
> value, defined elsewhere. That's what has been pointed out to you many
> times.
That point is completely irrelevant. The state objects only
On Friday, February 28, 2014 6:40:06 PM UTC-6, Ned Batchelder wrote:
>
> I don't understand: you show an if/elif chain that cannot be expressed
> as a switch statement (because it uses < ), and then conclude that
> Python needs a switch statement? That doesn't make any sense.
>
Forgive me.
Steven D'Aprano :
> I can only imagine you mean something like this:
>
> class Outer:
> class InnerOne:
> ...
>
> class InnerTwo:
> ...
>
> class InnerThree:
> ...
>
No, I mean this:
class StateMachine:
def __init__(self):
sm = self
On 01/03/2014 00:40, Ned Batchelder wrote:
On 2/28/14 6:36 PM, Mark H. Harris wrote:
On Friday, February 28, 2014 3:03:25 PM UTC-6, Marko Rauhamaa wrote:
Marko
... and between me and you, here is a snip from dmath.py from the
atan(x) function:
if (n**2 < D(1)):
a = __atan
On Sat, 01 Mar 2014 02:11:53 +0200, Marko Rauhamaa wrote:
> Ben Finney :
>
>> As has been pointed out to you, the whole point here is that string
>> objects often *are not* distinct, despite conceptually having distinct
>> cretion in the source.
>
> You know full well that this initialization cr
Ariel Argañaraz writes:
> Hi, I would like to know which is the best framework to persist my
> python objects in disk.
The Python Wiki has a directory of tools for object persistence in
Python https://wiki.python.org/moin/PersistenceTools>.
--
\ “Our task must be to free ourselves from ou
Marko Rauhamaa writes:
> Ben Finney :
>
> > As has been pointed out to you, the whole point here is that string
> > objects often *are not* distinct, despite conceptually having distinct
> > cretion in the source.
>
> You know full well that this initialization creates references to
> distinct ob
On Sat, 01 Mar 2014 02:03:51 +0200, Marko Rauhamaa wrote:
> Steven D'Aprano :
>
>> You can't have it both ways: you cannot claim that switch or case is
>> more readable than a chain of if...elif, and then propose a syntax
>> which is effectively a chain of if...elif while still claiming it is an
On 2/28/14 6:36 PM, Mark H. Harris wrote:
On Friday, February 28, 2014 3:03:25 PM UTC-6, Marko Rauhamaa wrote:
Marko
... and between me and you, here is a snip from dmath.py from the atan(x)
function:
if (n**2 < D(1)):
a = __atan__(n)
elif (n == D(1)):
a = g
"Mark H. Harris" :
> if (n**2 < D(1)):
> a = __atan__(n)
> elif (n == D(1)):
> a = gpi/4
> elif (n == D(-1)):
> a = -(gpi/4)
> elif (n < D(-1)):
> a = __atan__Lt_neg1__(n)
> else:
> a = __atan__Gt_1__(n)
Drop the outermost parentheses in
Hi, I would like to know which is the best framework to persist my python
objects in disk.
I heard about ZODB (http://www.zodb.org/en/latest/index.html)
is this the best or there is another ?
--
Ariel Argañaraz
--
https://mail.python.org/mailman/listinfo/python-list
On Fri, 28 Feb 2014 14:25:54 +0200, Marko Rauhamaa wrote:
> Chris Angelico :
>
>> On Fri, Feb 28, 2014 at 10:30 PM, Marko Rauhamaa
>> wrote:
>>> Chris Angelico :
>>>a.state = a.INIT
>>
>> In theory, yes. If that's all people will ever do, then you can safely
>> use == to check. Why are you u
On Thursday, February 27, 2014 10:01:39 AM UTC-6, Eric Jacoboni wrote:
>
> ('spam', [10, 30, 20], 'eggs')
>
> I get a TypeError for an illegal operation, but this operation is still
>
> completed?
hi Eric, others have answered your question specifically, but the issue (which
is recurring) b
Ben Finney :
> As has been pointed out to you, the whole point here is that string
> objects often *are not* distinct, despite conceptually having distinct
> cretion in the source.
You know full well that this initialization creates references to
distinct objects:
class ABC:
IDLE = "
Steven D'Aprano :
> You can't have it both ways: you cannot claim that switch or case is
> more readable than a chain of if...elif, and then propose a syntax
> which is effectively a chain of if...elif while still claiming it is
> an improvement. It's not. All you've done is introduce an element o
Marko Rauhamaa writes:
> Mark Lawrence :
>
> > http://c2.com/cgi/wiki?SwitchStatementsSmell
>
> Your brief summary, please, Mark?
>
> Anyway, the first 1000 lines or so that I managed to read from that page
> stated a valid principle, which however doesn't invalidate the existence
> of a switch s
On Friday, February 28, 2014 3:03:25 PM UTC-6, Marko Rauhamaa wrote:
>
> Marko
... and between me and you, here is a snip from dmath.py from the atan(x)
function:
if (n**2 < D(1)):
a = __atan__(n)
elif (n == D(1)):
a = gpi/4
elif (n == D(-1)):
a = -(gpi/4
On Fri, 28 Feb 2014 21:20:52 +0200, Marko Rauhamaa wrote:
> Your example:
[snip]
I'm not going to show the example as quoted by you, because my news
client is wrapping it in ugly ways and I don't want to spend the time
fixing it. I'll just say that, as given, it's a great big wall of text, a
s
Neil Cerutti writes:
> On 2014-02-28, Ben Finney wrote:
> > Right. I would like, ideally, for the Python documentation to
> > avoid mentioning that term entirely; and I would hope for that
> > to promote a better understanding of Python's data model.
>
> I like the characteristic of Python that
Marko Rauhamaa writes:
> Ben Finney :
>
> > First reason: This is better done by making it clear the value is an
> > arbitrary object that won't be compared for equality. Just use
> > ‘object()’ to creeate each value and be done with it. That's a hack,
> > but it's better than pretending you'll u
Mark Lawrence :
> http://c2.com/cgi/wiki?SwitchStatementsSmell
Your brief summary, please, Mark?
Anyway, the first 1000 lines or so that I managed to read from that page
stated a valid principle, which however doesn't invalidate the existence
of a switch statement.
A colleague of mine taught me
On Fri, 28 Feb 2014 20:53:15 +0200, Marko Rauhamaa wrote:
> "Mark H. Harris" :
>
>> I think the real issue is about the syntax... because of python's
>> unique indent strategy going back to ABC, a pythonized switch statement
>> would play havoc with the many text parsers out there used for
>> dev
On 28/02/2014 21:03, Marko Rauhamaa wrote:
"Mark H. Harris" :
Yep, my point exactly. nice illustration.
So now, for you and me: let's compare.
if key is ast.Assign:
return ' '.join(dump(t) for t in node.targets)
elif key is ast.AugAssign:
# Same target and same o
"Mark H. Harris" :
> Yep, my point exactly. nice illustration.
So now, for you and me: let's compare.
if key is ast.Assign:
return ' '.join(dump(t) for t in node.targets)
elif key is ast.AugAssign:
# Same target and same operator.
return dump(node.target) + dump(
On Friday, February 28, 2014 1:20:52 PM UTC-6, Marko Rauhamaa wrote:
>
> Which do *you* find more readable?
>
Yep, my point exactly. nice illustration.
--
https://mail.python.org/mailman/listinfo/python-list
On Friday, February 28, 2014 1:39:11 PM UTC-6, Mark H. Harris wrote:
> On Friday, February 28, 2014 1:34:27 AM UTC-6, Steven D'Aprano wrote:
>
>
>
> > Now that Python has a fast C implementation of Decimal, I would be happy
>
> > for Python 4000 to default to decimal floats, and require specia
On Friday, February 28, 2014 1:34:27 AM UTC-6, Steven D'Aprano wrote:
> Now that Python has a fast C implementation of Decimal, I would be happy
> for Python 4000 to default to decimal floats, and require special syntax
> for binary floats. Say, 0.1b if you want a binary float, and 0.1 for a
>
On Friday, February 28, 2014 12:37:37 PM UTC-6, Chris Angelico wrote:
>
> Are you aware that IEEE 754 includes specs for decimal floats? :)
>
Yes. I am from back in the day... way back... so 754 1985 is what I have
been referring to.
IEEE 854 1987 and the generalized IEEE 754 2008 have
Chris Angelico :
> On Sat, Mar 1, 2014 at 5:53 AM, Marko Rauhamaa wrote:
>> A dict dispatch table is just awful.
>
> Really? How is that? I've used them, often. Yes, there are times when
> I could express something more cleanly with a C-style switch
> statement, but other times the dispatch table
On Sat, Mar 1, 2014 at 5:53 AM, Marko Rauhamaa wrote:
> A dict dispatch table is just awful.
Really? How is that? I've used them, often. Yes, there are times when
I could express something more cleanly with a C-style switch
statement, but other times the dispatch table is fundamentally
cleaner. I
"Mark H. Harris" :
> I think the real issue is about the syntax... because of python's
> unique indent strategy going back to ABC, a pythonized switch
> statement would play havoc with the many text parsers out there used
> for development (TestWrangler, and many others).
I also took a look at th
On Sat, Mar 1, 2014 at 5:34 AM, Mark H. Harris wrote:
> Yes. ... and for clarification back to one of my previous comments, when I
> refer to 'float' I am speaking of the IEEE binary floating point
> representation built-in everywhere... including the processor!... not the
> concept of tra
On Friday, February 28, 2014 9:11:49 AM UTC-6, Steven D'Aprano wrote:
> >> Now that Python has a fast C implementation of Decimal, I would be
> >> happy for Python 4000 to default to decimal floats, and require special
> >> syntax for binary floats. Say, 0.1b if you want a binary float, and 0.1
>
On Friday, February 28, 2014 2:54:12 AM UTC-6, Wolfgang Maier wrote:
> Since by now, I guess, we all agree that using the string representation is
> the wrong approach, you can simply use Decimal instead of D() throughout
> your code.
> Best,
> Wolfgang
hi Wolfgang, ...right... I'm going to
On Friday, February 28, 2014 8:41:49 AM UTC-6, Wolfgang Maier wrote:
> Hi Mark,
>
> here is an enhancement for your epx function.
>
> Wolfgang
hi Wolfgang, thanks much! As a matter of point in fact, I ran into this
little snag and didn't understand it, because I was thinking that outside o
On Friday, February 28, 2014 9:50:09 AM UTC-6, Steven D'Aprano wrote:
> > PS On the topic of enums, when are we getting support for a switch
> > statement?
> http://legacy.python.org/dev/peps/pep-3103/
> http://legacy.python.org/dev/peps/pep-0275/
>
I have reviewed these peps, and I heard Guido
On Fri, 28 Feb 2014 12:02:03 +0200, Marko Rauhamaa wrote:
> PS On the topic of enums, when are we getting support for a switch
> statement?
http://legacy.python.org/dev/peps/pep-3103/
http://legacy.python.org/dev/peps/pep-0275/
--
Steven
--
https://mail.python.org/mailman/listinfo/python-li
On Thursday, February 27, 2014 7:49:07 PM UTC-8, Alec Taylor wrote:
> Are there libraries for doing this?
>
> I would like to autogenerate JSON-schema for use inside an API explorer.
>
> However whenever there is a schema change; I would only like to change
> the schema in one place (where possib
On Sat, Mar 1, 2014 at 2:29 AM, Marko Rauhamaa wrote:
> BTW, here's a syntax that doesn't introduce any new keywords:
>
>with self.state from Connection.State:
>if CONNECTING or CONNECTED:
>...
>elif DISONNECTING:
>...
>else:
>...
Ok
On Sat, Mar 1, 2014 at 2:11 AM, Steven D'Aprano
wrote:
>> or there needs to be a system for constructing literals
>> of non-built-in types. And if Decimal becomes built-in, then why that
>> and not <>?
>
> 'Cos we have ten fingers and in count in decimal :-P
We talk in words and characters, so we
Chris Angelico :
> Can you elaborate on this "nonliteral constants" point? How is it a
> problem if DISCONNECTING isn't technically a constant? It follows the
> Python convention of being in all upper-case, so the programmer
> understands not to rebind it. Is the problem that someone might
> (naiv
On 02/28/2014 01:46 AM, Ben Finney wrote:
> Steven D'Aprano writes:
>
>> On Fri, 28 Feb 2014 09:43:58 +0200, Marko Rauhamaa wrote:
>>>class Connection:
>>>IDLE = "IDLE"
>> [...]
>>>CONNECTED = "CONNECTED"
>> [...]
>>>def disconnect(self):
>>>...
>>>
On Fri, 28 Feb 2014 19:52:45 +1100, Chris Angelico wrote:
> On Fri, Feb 28, 2014 at 6:34 PM, Steven D'Aprano
> wrote:
>> On Fri, 28 Feb 2014 16:00:10 +1100, Chris Angelico wrote:
>>
>>> If we had some other tag, like 'd', we could actually construct a
>>> Decimal straight from the source code. Si
On 28/02/2014 11:38, Marko Rauhamaa wrote:
Switch statements provide for excellent readability in parsers and state
machines, for example. They also allow the Python compiler to optimize
the statement internally unlike long if-else chains.
There are umpteen recipes for switch statements so tak
Uhh, the curse of not copy-pasting everything:
> >>> exp(20)
should, of course, read
>>> epx(19)
> Traceback (most recent call last):
> File "", line 1, in
> epx(19)
> File "C:\Python34\dmath_rev.py", line 27, in epx
> n *= q
> decimal.Overflow: []
>
--
https://mail.py
On Sat, Mar 1, 2014 at 1:41 AM, Joshua Landau wrote:
> Would it be better to add a check here, such that if this gets raised
> to the top-level it includes a warning ("Addition was inplace;
> variable probably mutated despite assignment failure")?
That'd require figuring out whether or not the va
Mark H. Harris gmail.com> writes:
>
> If you get a chance, take a look at the dmath.py code on:
>
>https://code.google.com/p/pythondecimallibrary/
>
Hi Mark,
here is an enhancement for your epx function.
Your current version comes with the disadvantage of potentially storing
extremely l
On 27 February 2014 16:14, Chris Angelico wrote:
> On Fri, Feb 28, 2014 at 3:01 AM, Eric Jacoboni
> wrote:
>>
> a_tuple = ("spam", [10, 30], "eggs")
> a_tuple[1] += [20]
>> Traceback (most recent call last):
>> File "", line 1, in
>> TypeError: 'tuple' object does not support item ass
On Sat, Mar 1, 2014 at 1:26 AM, Marko Rauhamaa wrote:
> Python isn't "averse" to the switch statement because it would be not
> that useful. Rather, the problem is that Python doesn't have nonliteral
> constants (scheme has builtin symbols). It is difficult to come up with
> truly Pythonic syntax
On Thursday, February 27, 2014 2:33:35 AM UTC-8, Mark H. Harris wrote:
> No... was not aware of gmpy2... looks like a great project! I am wondering
> why it would be sooo much faster?
For multiplication and division of ~1000 decimal digit numbers, gmpy2 is ~10x
faster. The numbers I gave were f
On 2014-02-28, Ben Finney wrote:
> "Mark H. Harris" writes:
>> So, yeah, thinking about variables is just not going away.
>
> Right. I would like, ideally, for the Python documentation to
> avoid mentioning that term entirely; and I would hope for that
> to promote a better understanding of Pytho
Neil Cerutti :
> Check out Go's switch statement for an example of what it might
> look like in Python. Except you'd get it without labeled break or
> the fallthrough statement.
No need for the fallthrough (except that multiple cases should be
supported).
Labeled breaks wouldn't be needed becaus
On 2014-02-28, Marko Rauhamaa wrote:
> Chris Angelico :
>> Python currently has dispatch tables and if/elif chains, and a
>> strong cultural aversion to switch. You could change that by
>> coming up with some *really* awesome proposal, but you'll be
>> fighting against the tide a bit.
>
> It's eas
Chris Angelico :
> On Fri, Feb 28, 2014 at 10:30 PM, Marko Rauhamaa wrote:
>> Chris Angelico :
>>a.state = a.INIT
>
> In theory, yes. If that's all people will ever do, then you can safely
> use == to check. Why are you using is?
The main reason to use "is" is to indicate that the object is
On Fri, Feb 28, 2014 at 10:38 PM, Marko Rauhamaa wrote:
> Chris Angelico :
>
>> Python currently has dispatch tables and if/elif chains, and a strong
>> cultural aversion to switch. You could change that by coming up with
>> some *really* awesome proposal, but you'll be fighting against the
>> tid
On Fri, Feb 28, 2014 at 10:30 PM, Marko Rauhamaa wrote:
> Chris Angelico :
>
>> String literals will often be interned if they look like (especially,
>> if they *are*) identifiers, so if you want to prevent other strings
>> from happening to match, you can't trust 'is'.
>>
>> [...]
>>
>> If you're
Chris Angelico :
> Python currently has dispatch tables and if/elif chains, and a strong
> cultural aversion to switch. You could change that by coming up with
> some *really* awesome proposal, but you'll be fighting against the
> tide a bit.
It's easy have a "cultural aversion" when the language
Chris Angelico :
> String literals will often be interned if they look like (especially,
> if they *are*) identifiers, so if you want to prevent other strings
> from happening to match, you can't trust 'is'.
>
> [...]
>
> If you're using strings as state values, you should be using == to
> compare
On Fri, Feb 28, 2014 at 9:02 PM, Marko Rauhamaa wrote:
> PS On the topic of enums, when are we getting support for a switch
> statement?
I don't see that they're particularly connected. In my C code, I've
used enums frequently as quick constants, often never switching on
them. Conversely, I often
On Fri, Feb 28, 2014 at 9:02 PM, Marko Rauhamaa wrote:
> Yes, enums are long overdue. However, since any distinct objects will
> do, there is nothing preventing you from using string objects.
>
String literals will often be interned if they look like (especially,
if they *are*) identifiers, so if
Ben Finney :
> There are two reasons why I think this is *still* not a justification
> for using ‘is’ with string values:
>
> First reason: This is better done by making it clear the value is an
> arbitrary object that won't be compared for equality. Just use
> ‘object()’ to creeate each value and
On Fri, 28 Feb 2014 14:49:07 +1100, Alec Taylor wrote:
> Are there libraries for doing this?
>
> I would like to autogenerate JSON-schema for use inside an API explorer.
>
> However whenever there is a schema change; I would only like to change
> the schema in one place (where possible).
>
> E.
On Fri, Feb 28, 2014 at 6:43 PM, Marko Rauhamaa wrote:
> Here's a use case for "is" with strings (or ints):
>
>class Connection:
>IDLE = "IDLE"
>CONNECTING = "CONNECTING"
>CONNECTED = "CONNECTED"
>DISCONNECTING = "DISCONNECTING"
>DISCONNECTED = "DISCONNE
Mark H. Harris gmail.com> writes:
>
> On Thursday, February 27, 2014 10:26:59 PM UTC-6, Chris Angelico wrote:
>
> > Create Decimal values from strings, not from the str() of a float,
> > which first rounds in binary and then rounds in decimal.
> >
>
> Thanks Chris... another excellent point.
On Fri, Feb 28, 2014 at 6:34 PM, Steven D'Aprano wrote:
> On Fri, 28 Feb 2014 16:00:10 +1100, Chris Angelico wrote:
>
>> If we had some other tag, like 'd', we could actually construct a
>> Decimal straight from the source code. Since source code is a string,
>> it'll be constructed from that stri
Steven D'Aprano writes:
> On Fri, 28 Feb 2014 09:43:58 +0200, Marko Rauhamaa wrote:
> >class Connection:
> >IDLE = "IDLE"
> [...]
> >CONNECTED = "CONNECTED"
> [...]
> >def disconnect(self):
> >...
> >if self.state is CONNECTED:
> >
On Fri, 28 Feb 2014 09:43:58 +0200, Marko Rauhamaa wrote:
> Chris Angelico :
>
>> Simple rule of thumb: Never use 'is' with strings or ints. They're
>> immutable, their identities should be their values. Playing with 'is'
>> will only confuse you, unless you're specifically going for
>> introspec
98 matches
Mail list logo