Re: Sets vs lists loop behaviour if size changes

2015-10-14 Thread candide via Python-list
Thanks for the response and the reference, indeed sets and lists behave differently... -- https://mail.python.org/mailman/listinfo/python-list

Sets vs lists loop behaviour if size changes

2015-10-14 Thread candide via Python-list
If set size changes during a for loop, a runtime exception is raised: ~~ S = {2015} for z in S: S.add(42) ~~ ~~ Traceback (most recent call last): File "_.py", line 2, in for z in S: RuntimeError: Set

Re: 42**1000000 is CPU time free

2015-07-24 Thread candide
Thanks to all for your response, I was not aware that the interpreter evaluated pure litteral expressions at compile time. -- https://mail.python.org/mailman/listinfo/python-list

42**1000000 is CPU time free

2015-07-24 Thread candide
Of course, computing 42**100 is not free: # -- import time a=time.clock() N=100 42**N b=time.clock() print("CPU TIME :", b - a) # -- ~~ CPU TIME : 2.37 real0m2.412s user0m2.388s sys 0m0.016s ~~~

global and loop control variable

2015-07-23 Thread candide
About global declarations, Python Language Ref (PLR) explains: [https://docs.python.org/3.4/reference/simple_stmts.html#the-global-statement] ~ Names listed in a global statement must not be used in the same code block textually preceding that global statement.

Re: 0 + not 0

2015-07-11 Thread candide
Le samedi 11 juillet 2015 15:38:51 UTC+2, Serhiy Storchaka a écrit : > This looks as a bug to me. Please file a report on http://bugs.python.org. OK, I'll report. -- https://mail.python.org/mailman/listinfo/python-list

Re: 0 + not 0

2015-07-11 Thread candide
Le samedi 11 juillet 2015 14:05:58 UTC+2, Chris Angelico a écrit : > You'll see down below a footnote referring to this as a special case. I didn't spot the footnote and I don't regard it as dealing with a "special case": the footnote is paraphrasing the precedence hierarchy given by the table.

Re: 0 + not 0

2015-07-11 Thread candide
Le samedi 11 juillet 2015 13:31:03 UTC+2, Luuk a écrit : > > But operator precedence of 'not' is higher than of '+' Right but what does this prove? For instance, unary minus has higher precedence than exponentiation but the expression 2 ** -1 doesn't raise a syntax error. -- https://ma

Re: 0 + not 0

2015-07-11 Thread candide
Le samedi 11 juillet 2015 13:21:03 UTC+2, Chris Angelico a écrit : > I think you're misreading the table; 'not' has *lower* precedence than '+'. > Right but Python docs helps a lot in misreading ;) Following the iconicity principle, it's pretty obvious that one has to display table priority beg

0 + not 0

2015-07-11 Thread candide
>>> 0 + not 0 File "", line 1 0 + not 0 ^ SyntaxError: invalid syntax >>> What is syntactically wrong with 0 + not 0? -- https://mail.python.org/mailman/listinfo/python-list

Re: Evaluation order

2015-07-10 Thread candide
Le vendredi 10 juillet 2015 04:02:56 UTC+2, Chris Angelico a écrit : > I'm not sure what contradiction you're referring to, here. The > evaluation that you're pointing out says, as Terry showed via the > disassembly, that Python's first action is to look up the name 't' and > grab a reference t

Evaluation order

2015-07-09 Thread candide
The official doc explains that : Python evaluates expressions from left to right. cf. https://docs.python.org/3.3/reference/expressions.html#evaluation-order But consider the following snippet : >>> t=[2020, 42, 2015] >>> t*(1+int(bool(t.sort( [42, 2015, 2020] >>> Is there not some cont

Auto-completion: why not module name?

2015-03-16 Thread candide
Python 3.4 provides auto-completion facility within a Python console embedded in a command line terminal. But apparently this facility doesn't allow the user to complete with standard module name. For instance, editing the following : >>> import ma and hitting the TAB key doesn't generate

Re: What the Pythons docs means by "container" ?

2015-02-17 Thread candide
Le mercredi 18 février 2015 01:50:16 UTC+1, Chris Angelico a écrit : > > So, what's a container? It's a thing that you put other objects into. I agree with this approach. The important point to consider here is the last word in your definition : "into". There is the container and there is the

Re: What the Pythons docs means by "container" ?

2015-02-17 Thread candide
> > Shrug. It is a useful descriptive term when you want to talk about things. You Python Language Referenceb (PLR) is expected to give formal and acurate definition, not "descriptive term to talk about things". > might keep in mind that a "container"'s _primary_ purpose is usually its > conta

What the Pythons docs means by "container" ?

2015-02-17 Thread candide
Official Python documentation very frequently invokes a mysterious *container* data structure. The PLR manual explains : -- Some objects contain references to other objects; these are called containers. -- So containers contain : what a great defin

Python top learning language

2014-07-08 Thread candide
http://www.infoworld.com/d/application-development/python-bumps-java-top-learning-language-245774 -- https://mail.python.org/mailman/listinfo/python-list

Re: TypeError expected in an augmented assignment

2014-07-03 Thread candide
> >From that link: > > > > """ > > An augmented assignment expression like x += 1 can be rewritten as x = > > x + 1 to achieve a similar, but not exactly equal effect. In the > > augmented version, x is only evaluated once. Also, when possible, the > > actual operation is performed in-plac

Re: TypeError expected in an augmented assignment

2014-07-03 Thread candide
> >>> seq = [1,2] > > >>> seq.extend((3,4)) OK, this feature is referenced in the Python Library reference here : https://docs.python.org/3.2/library/stdtypes.html#typesseq-mutable not thoroughly referenced but, anyway, referenced. > > >>> seq+= {5, 6} # the order of extending is n

TypeError expected in an augmented assignment

2014-07-02 Thread candide
An hybrid list-tuple concatenation is not allowed >>> []+(1, 2) Traceback (most recent call last): File "", line 1, in TypeError: can only concatenate l

Re: Single underscore in interactive mode

2014-06-25 Thread candide
> > Please say either in a tracker issue or here where you found this > > statement. https://docs.python.org/3.4/reference/lexical_analysis.html#reserved-classes-of-identifiers -- https://mail.python.org/mailman/listinfo/python-list

Single underscore in interactive mode

2014-06-25 Thread candide
According to the official documentation (The Python Language Reference, Release 3.2): --- The special identifier _ is used in the interactive interpreter to store the result of the last evaluation; --- This description is not very

Ternary operator associativity

2014-03-06 Thread candide
According to the official documentation, the ternary operator has left-to-right associativity : --- Operators in the same box group left to right (except for comparisons, including tests, which all have the same precedence and chain from left to right -- see section Comparisons

What’s wrong with scientific Python?

2014-01-19 Thread candide
http://cyrille.rossant.net/whats-wrong-with-scientific-python/ Any comments ? -- https://mail.python.org/mailman/listinfo/python-list

Re: print function and unwanted trailing space

2013-08-31 Thread candide
Le 31/08/2013 15:59, Peter Otten a écrit : To make it crystal clear, the above was to illustrate the algorithm used in Python 2, not a suggestion. Ok sorry, I misinterpreted. > I still think you should live with a trailing space Are you sure ? The following code #

Re: print function and unwanted trailing space

2013-08-31 Thread candide
Le 31/08/2013 12:31, Peter Otten a écrit : with `softspace` saved as a file attribute, is gone in Python3. After reading http://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function I understand what you meant by "softspace". Thanks. -- http://mail.python.org/mailman/listinfo/python-l

Re: print function and unwanted trailing space

2013-08-31 Thread candide
Le 31/08/2013 13:24, Ned Batchelder a écrit : For a beginner course, the trailing space is fine, use this code. I was really expecting there was a trick but I'll follow your advice, after all the trailing space is invisible! Nevertheless, this can be quite annoying. For instance, some autom

Re: print function and unwanted trailing space

2013-08-31 Thread candide
Le 31/08/2013 12:31, Peter Otten a écrit : > softspace = False > for i in range(5): > if softspace: > print(end=" ") > print(i, end="") > softspace = True > print() The if instruction imposes useless testing (we know in advance the problem to occur at the very end of the

Re: print function and unwanted trailing space

2013-08-31 Thread candide
Le 31/08/2013 13:16, Steven D'Aprano a écrit : Of course it does. Have you actually tried it? Of course I did, redirecting the output to a file in order to spot an eventually trailing space. I did the same for the Python 3 code. -- http://mail.python.org/mailman/listinfo/python-list

Re: print function and unwanted trailing space

2013-08-31 Thread candide
Le 31/08/2013 10:43, Andreas Perstinger a écrit : > How about > > >>> print(" ".join(str(i) for i in range(5))) > 0 1 2 3 4 > Thanks for your answer. The output is stricly the same but the code doesn't suit my needs : 1) I'm porting to Python 3 a Python 2 full beginner course : the learner

print function and unwanted trailing space

2013-08-31 Thread candide
What is the equivalent in Python 3 to the following Python 2 code: # - for i in range(5): print i, # - ? Be careful that the above code doesn't add a trailing space after the last number in the list, hence the following Python 3 code

Re: is operator versus id() function

2013-04-05 Thread candide
Le vendredi 5 avril 2013 16:53:55 UTC+2, Arnaud Delobelle a écrit : > > You've fallen victim to the fact that CPython is very quick to collect > > garbage. OK, I get it but it's a fairly unexpected behavior. Thanks for the demonstrative snippet of code and the instructive answer. -- http

is operator versus id() function

2013-04-05 Thread Candide Dandide
Until now, I was quite sure that the is operator acts the same as the id builtin function, or, to be more formal, that o1 is o2 to be exactly equivalent to id(o1) == id(o2). This equivalence is reported in many books, for instance Martelli's Python in a Nutshell. But with the following code, I'

Re: Regular expression : non capturing groups are faster ?

2012-01-03 Thread candide
Le 03/01/2012 12:56, Devin Jeanpierre a écrit : The second assertion sounds more likely. It seems very odd that Python and Perl implementations are divergent on this point. Any opinion ? The Python documentation oversimplifies. You meant Perl Documentation, didn't you ? It's a commun opinio

Regular expression : non capturing groups are faster ?

2012-01-03 Thread candide
Excerpt from the Regular Expression HOWTO (http://docs.python.org/howto/regex.html#non-capturing-and-named-groups) : --- It should be mentioned that there’s no performance difference in searching between capturing and non-capturing groups; neither fo

Repeating assertions in regular expression

2012-01-03 Thread candide
The regular expression HOWTO (http://docs.python.org/howto/regex.html#more-metacharacters) explains the following # -- zero-width assertions should never be repeated, because if they match once at a given location, they can obviously be matched an infinite number o

Type object returned by the re.compile function

2011-12-27 Thread candide
The Python 2.7 official documentation here: http://docs.python.org/library/re.html#re.compile doesn't specify the type object returned by the re.compiled function. According to the documentation, re.compile returns a "regular expression object". A regular expression object seems to be an ins

Re: Regexp : repeated group identification

2011-12-14 Thread candide
Le 14/12/2011 12:34, Vlastimil Brom a écrit : "If a group is contained in a part of the pattern that matched multiple times, the last match is returned." I missed this point, your answer matches my question ;) thanks. If you need to work with the content captured in the repeated group, you

Regexp : repeated group identification

2011-12-14 Thread candide
Consider the following code # import re z=re.match('(Spam\d)+', 'Spam4Spam2Spam7Spam8') print z.group(0) print z.group(1) # outputting : Spam4Spam2Spam7Spam8 Spam8 The '(Spam\d)

Re: Pragmatics of the is operator

2011-11-26 Thread candide
Thanks to all for your response. Le 27/11/2011 00:01, Steven D'Aprano a écrit : On Sat, 26 Nov 2011 22:20:36 +0100, candide wrote: In which cases should we use the is() function ? The is() function compares identity of objects rather than values so I was wondering in which circumst

Pragmatics of the standard is() function

2011-11-26 Thread candide
In which cases should we use the is() function ? The is() function compares identity of objects rather than values so I was wondering in which circumstances comparing identities of objects is really vital. Examining well reputated Python source code, I realize that is() function is mainly used

Re: Use and usefulness of the as syntax

2011-11-17 Thread candide
Thanks to all Le 12/11/2011 13:27, Chris Angelico a écrit : > On Sat, Nov 12, 2011 at 10:56 PM, candide wrote: >> import foo as f >> >> equivalent to >> >> import foo >> f = foo >> > > Not quite, it's closer to: > > import foo &

Re: Use and usefulness of the as syntax

2011-11-17 Thread candide
Le 12/11/2011 13:29, Arnaud Delobelle a écrit : -- The second case seems to be rather widespread and causes math attribute to be private but I don't figure out why this matters. This way math doesn't get bound in the global namespace when doing "from module import *" To contextualize more,

Use and usefulness of the as syntax

2011-11-12 Thread candide
First, could you confirm the following syntax import foo as f equivalent to import foo f = foo Now, I was wondering about the usefulness in everyday programming of the as syntax within an import statement. Here are some instances retrieved from real code of such a syntax import numpy as

Re: __dict__ attribute for built-in types

2011-10-28 Thread candide
Le 28/10/2011 11:08, Hrvoje Niksic a écrit : longer be allowed for the interpreter to transparently cache them. The same goes for integers and other immutable built-in objects. On the other hand, immutability and optimization don't explain the whole thing because you can't do something like

Re: __dict__ attribute for built-in types

2011-10-28 Thread candide
Le 28/10/2011 05:02, Patrick Maupin a écrit : You can easily do that by subclassing a string: class AnnotatedStr(str): pass x = AnnotatedStr('Node1') x.title = 'Title for node 1' Less or more what I did. But requires to transport the string graph structure to the AnnotatedStr one.

Re: __dict__ attribute for built-in types

2011-10-28 Thread candide
Le 28/10/2011 10:01, Steven D'Aprano a écrit : didn't think of it. This is hardly a surprise. Wanting to add arbitrary attributes to built-ins is not exactly an everyday occurrence. Depends. Experimented programmers don't even think of it. But less advanced programmers can consider of it.

Re: __dict__ attribute for built-in types

2011-10-27 Thread candide
Le 28/10/2011 02:02, MRAB a écrit : No, built-in classes written in C have certain limitations, but why would you want to do that anyway? Mainly for learning purpose and Python better understanding. Actually, I have a class of mine for drawing graphs with the Graphviz software. The nodes

Re: __dict__ attribute for built-in types

2011-10-27 Thread candide
Le 28/10/2011 00:57, Hrvoje Niksic a écrit : was used at class definition time to suppress it. Built-in and extension types can choose whether to implement __dict__. Is it possible in the CPython implementation to write something like this : "foo".bar = 42 without raising an attribute erro

Re: __dict__ attribute for built-in types

2011-10-27 Thread candide
Le 28/10/2011 00:19, Steven D'Aprano a écrit : What, you think it goes against the laws of physics that nobody thought to mention it in the docs? No but I'm expecting from Python documentation to mention the laws of Python ... But beside this, how to recognise classes whose object does

Re: __dict__ attribute for built-in types

2011-10-27 Thread candide
Le 27/10/2011 13:03, Duncan Booth a écrit : -- where the official documentation refers to this point ? See http://docs.python.org/reference/datamodel.html for the docs about __slots__ There is also the API documentation which describes at a low level how to control whether or not instances

__dict__ attribute for built-in types

2011-10-27 Thread candide
I realize that built-in types objects don't provide a __dict__ attribute and thereby i can't set an attribute to a such object, for instance >>> a=[42,421] >>> a.foo="bar" Traceback (most recent call last): File "", line 1, in AttributeError: 'list' object has no attribute 'foo' >>> a.__dict

Re: randrange exceptional behavior

2011-10-24 Thread candide
Le 24/10/2011 22:09, MRAB a écrit : but for choice(seq) it says: Ah of course, I should have checked there """If seq is empty, raises IndexError.""" > Thanks -- http://mail.python.org/mailman/listinfo/python-list

Importing a module from a non-cwd

2011-10-24 Thread candide
Hi, It's easy to open a file not located in the current working directory (cwd). But how about importing a module? For instance, suppose I have a file, say my_file.py, located in the cwd, say /home/candide/ and suppose the module to be imported, say my_module.py, is located in the

randrange exceptional behavior

2011-10-24 Thread candide
Where is documented the behaviour of the standard function randrange in the case of an empty list ? for instance randrange(42,33) ? May I rely on an ValueError type error? -- http://mail.python.org/mailman/listinfo/python-list

Opportunity missed by Python ?

2011-10-13 Thread candide
Dart is the very new language created by Google to replace Javascript. So Python was not able to do the job? Or may be they don't know about Python at Google ;) ? -- http://mail.python.org/mailman/listinfo/python-list

Re: Usefulness of the "not in" operator

2011-10-10 Thread candide
Le 10/10/2011 10:06, John Ladasky a écrit : Who like that second one speaks? Yoda his name is. Programs in Forth he must. ;) We can add to the list : -- Tarzan -- Geronimo -- don Alexandro de la Vega dying in the arms of Zorro ... -- http://mail.python.org/mailman/listinfo/python-list

Re: Usefulness of the "not in" operator

2011-10-08 Thread candide
Le 08/10/2011 17:16, Dave Angel a écrit : You should say "... parenthesis are not necessary ("not" has LOWER precedence than "in")." I should, yes, I confess ;) In my defense, I must tell that Python document reference here : http://docs.python.org/reference/expressions.html#summary has

Re: Usefulness of the "not in" operator

2011-10-08 Thread candide
Le 08/10/2011 17:13, Thorsten Kampe a écrit : * candide (Sat, 08 Oct 2011 16:41:11 +0200) After browsing source code, I realize that parenthesis are not necessary ("not" has higher precedence than "in"). Lower precedence. Ooops, thanks. -- http://mail.python.org/mai

Re: Usefulness of the "not in" operator

2011-10-08 Thread candide
Le 08/10/2011 12:50, Jon Clements a écrit : 10 - 5 as 10 + -5 (as obviously the - is redundant as an operation), and 10 / 2 as int(10 * .5) or something, who needs a divide!? OK, I see your point but I was supposing non-membershipness seldom needed and in fact one can suppose that test memb

Re: Usefulness of the "not in" operator

2011-10-08 Thread candide
Le 08/10/2011 12:42, candide a écrit : >>> not ('th' in "python") False >>> After browsing source code, I realize that parenthesis are not necessary ("not" has higher precedence than "in"). -- http://mail.python.org/mailman/listinfo/python-list

Re: Usefulness of the "not in" operator

2011-10-08 Thread candide
Le 08/10/2011 14:01, Steven D'Aprano a écrit : > And "not in" is the obvious way to do it. > > Obvious ? Not so. I performed some code mining and it appears that even good sources make use of "not (foo in bar)" expressions. begin examples *** from drpython/drPlugin

Re: Usefulness of the "not in" operator

2011-10-08 Thread candide
Le 08/10/2011 14:41, Alain Ketterlin a écrit : Operators like "not in" and "is not" should really be considered single tokens, even though they seem to use "not". And I think they are really convenient. I realize that I was confused by the lexical form of the "not in" operator : it is made by

Usefulness of the "not in" operator

2011-10-08 Thread candide
Python provides -- the not operator, meaning logical negation -- the in operator, meaning membership On the other hand, Python provides the not in operator meaning non-membership. However, it seems we can reformulate any "not in" expression using only "not" and "in" operation. For inst

Re: What is this syntax ?

2011-06-19 Thread candide
OK, thanks for your explanation, it was just stringisation ! I erroneously focused on +x+ as a kind of placeholder unknown to me, instead of left and right concatenations ;) It would be more readable for me if it were edited >>> print '"' + x + '"' # better spacing "foo" >>> or with stri

What is this syntax ?

2011-06-19 Thread candide
With Python 2.7 : >>> x="foo" >>> print '"'+x+'"' "foo" >>> What is this curious syntax on line 2 ? Where is it documented ? -- http://mail.python.org/mailman/listinfo/python-list

Re: Equivalent code to the bool() built-in function

2011-04-18 Thread candide
Le 18/04/2011 10:33, Raymond Hettinger a écrit : # -- def bool_equivalent(x): return True if x else False It's faster to write: def bool_equivalent(x): return not not x faster and ... smarter ;) -- http://mail.python.org/mailman/listinfo/pyth

Re: Equivalent code to the bool() built-in function

2011-04-17 Thread candide
Le 17/04/2011 11:46, Ben Finney a écrit : > candide writes: > >> First because I was doubting the true interest of the bool() type. In >> fact, it appears that it's _semantically_ a shortcut for >> True if x else False. > > That bends my brain. Both ‘True’ and

Re: Equivalent code to the bool() built-in function

2011-04-17 Thread candide
Le 17/04/2011 04:39, Ben Finney a écrit : Why do you need to know? (I should have asked that question earlier.) First because I was doubting the true interest of the bool() type. In fact, it appears that it's _semantically_ a shortcut for True if x else False. I could't imagine a builtin f

Re: Equivalent code to the bool() built-in function

2011-04-16 Thread candide
Le 16/04/2011 23:13, Ben Finney a écrit : The ‘bool’ built-in is not a function. >>> type(bool) Oops, unfortunate confusion!! but built-in types and built-in functions are sometimes so similar from the user's point of view ;) All the same, you can notice that the official doc

Re: Equivalent code to the bool() built-in function

2011-04-16 Thread candide
Le 16/04/2011 23:38, Ben Finney a écrit : So the answer to the OP's question is no: the function isn't equivalent to the type, Can bool() type and bool_equivalent() function return different values ? because the OP's ‘bool_equivalent’ function necessarily uses the built-in ‘bool’ type, whi

Equivalent code to the bool() built-in function

2011-04-16 Thread candide
Consider the following code : # -- def bool_equivalent(x): return True if x else False # testing ... def foo(x): return 10*x class C: pass for x in [42, ("my","baby"), "baobab", max, foo, C] + [None, 0, "", [], {},()]: print bool(x)==bool

Re: Python IDE/text-editor

2011-04-16 Thread candide
Le 16/04/2011 15:50, Adam Tauno Williams a écrit : gedit provides a Python interpreter/console 'embedded' in the GUI (provided the plugin is enabled). I agree, cf. this screenshot : http://i52.tinypic.com/snj7a0.jpg but i'm not sure gedit run easily under Windows. Kate editor has the sa

Re: Argument of the bool function

2011-04-10 Thread candide
Le 08/04/2011 18:41, Benjamin Kaplan a écrit : bool(x=5) is just passing the value 5 as the argument "x" to the function. Anyway, passing x as a keyword argument to the bool function appears to be very rare : i did a regexp search for about 3 source-code Python files (among them offici

Re: Retrieving Python Keywords

2011-04-10 Thread candide
Le 10/04/2011 04:01, Terry Reedy a écrit : Yes. (Look in the manuals, I did : my main reference book is the Martelli's /Python in a Nutshell/ and the index doesn't refer to the keyword import or try the obvious imports ;-) The only obvious I saw was sys module. -- http://mail.python

Re: Retrieving Python Keywords

2011-04-10 Thread candide
Le 10/04/2011 04:09, John Connor a écrit : Actually this is all it takes: import keywords print keywords.kwlist >>> import keywords Traceback (most recent call last): File "", line 1, in ImportError: No module named keywords >>> so I considered first it was a joke ! ;) In fact the import

Retrieving Python Keywords

2011-04-09 Thread candide
Python is very good at introspection, so I was wondering if Python (2.7) provides any feature to retrieve the list of its keywords (and, as, assert, break, ...). -- http://mail.python.org/mailman/listinfo/python-list

Re: Argument of the bool function

2011-04-09 Thread candide
Le 10/04/2011 01:22, Robert Kern a écrit : No one is saying that every instance of "foo([arg])" in the docs means that the given argument is named such that it is available for keyword arguments. What people are saying is that for bool(), *that happens to be the case*. what a piece of luck!

Re: Argument of the bool function

2011-04-08 Thread candide
Le 09/04/2011 00:03, Ethan Furman a écrit : > bool([x]) > Convert a value to a Boolean, using the standard truth testing > procedure. > As you can see, the parameter name is 'x'. OK, your response is clarifying my point ;) I didn't realize that in the bool([x]) syntax, identifier x ref

Re: Argument of the bool function

2011-04-08 Thread candide
Le 08/04/2011 18:43, Ian Kelly a écrit : "x=42" is an assignment statement, not an expression. Right, I was confounding with C ;) In fact, respect to this question, the documentation makes things unambiguous : - In contrast to many other languages, not all language constru

Argument of the bool function

2011-04-08 Thread candide
About the standard function bool(), Python's official documentation tells us the following : bool([x]) Convert a value to a Boolean, using the standard truth testing procedure. In this context, what exactly a "value" is referring to ? For instance, >>> x=42 >>> bool(x=5) True >>> but _ex

Re: Extracting "true" words

2011-04-02 Thread candide
Le 02/04/2011 01:10, Chris Rebert a écrit : "Word" presumably/intuitively; hence the non-standard "[:word:]" POSIX-like character class alias for \w in some environments. OK Are you intentionally excluding CJK ideographs (as not "letters"/alphabetic)? Yes, CJK ideographs don't belong to t

Re: Alphabetics respect to a given locale

2011-04-02 Thread candide
Le 01/04/2011 22:55, candide a écrit : How to retrieve the list of all characters defined as alphabetic for the current locale ? Thanks for the responses. Alas, neither solution works. Under Ubuntu : # -- import string import locale print locale.getdefaultlocale() print

Re: Extracting repeated words

2011-04-02 Thread candide
Le 02/04/2011 00:42, Ian Kelly a écrit : You could use a look-ahead assertion with a captured group: regexp = r'\b(?P\w+)\b(?=.+\b(?P=dup)\b)' c = re.compile(regexp, re.IGNORECASE | re.DOTALL) c.findall(text) It works fine, lookahead assertions in action is what exatly i was looking for, ma

Alphabetics respect to a given locale

2011-04-01 Thread candide
How to retrieve the list of all characters defined as alphabetic for the current locale ? -- http://mail.python.org/mailman/listinfo/python-list

Extracting "true" words

2011-04-01 Thread candide
Back again with my study of regular expressions ;) There exists a special character allowing alphanumeric extraction, the special character \w (BTW, what the letter 'w' refers to?). But this feature doesn't permit to extract true words; by "true" I mean word composed only of _alphabetic_ letter

Extracting repeated words

2011-04-01 Thread candide
Another question relative to regular expressions. How to extract all word duplicates in a given text by use of regular expression methods ? To make the question concrete, if the text is -- Now is better than never. Although never is often better than *right* now. -

Re: Extracting subsequences composed of the same character

2011-04-01 Thread candide
Thanks, yours responses gave me the opportunity to understand the "backreference" feature, it was not clear in spite of my intensive study of the well known RE howto manual. -- http://mail.python.org/mailman/listinfo/python-list

Extracting subsequences composed of the same character

2011-03-31 Thread candide
Suppose you have a string, for instance "pyyythhooonnn ---> " and you search for the subquences composed of the same character, here you get : 'yyy', 'hh', 'ooo', 'nnn', '---', '' It's not difficult to write a Python code that solves the problem, for instance : def f(text): ch

Standard module implementation

2010-11-28 Thread candide
I was wondering if all the standard module are implemented in C. For instance, I can't find a C implementation for the minidom xml parser under Python 2.6. -- http://mail.python.org/mailman/listinfo/python-list

Splitting a sequence into pieces with identical elements

2010-08-10 Thread candide
Suppose you have a sequence s , a string for say, for instance this one : spppaeggg We want to split s into the following parts : ['s', 'ppp', 'a', '', 'e', 'ggg', ''] ie each part is a single repeated character word. What is the pythonic way to answer this question? A naive

Why is python not written in C++ ?

2010-08-01 Thread candide
Python is an object oriented langage (OOL). The Python main implementation is written in pure and "old" C90. Is it for historical reasons? C is not an OOL and C++ strongly is. I wonder if it wouldn't be more suitable to implement an OOL with another one. Has it ever been planned to rewrite i

Subsets of Python implemented in Python

2010-07-16 Thread candide
I don't understand why some parts of the Python language (or the Python standard library too) are implemented in C while some other parts are implemented in the Python language itself. For instance, lists and dictionnaries are implemented in C but sets are not. Wouldn't be better to implement

Re: Splitting numeric litterals

2010-07-14 Thread candide
MRAB a écrit : want to split them over several lines. It is somewhat unusual to have a _numeric_ literal that's very very long! I agree. But consider RSA-155 for instance ... ;) For an integer literal you could use a string literal and convert it to an integer: >>> int("1000\ 000\ 000")

Splitting numeric litterals

2010-07-14 Thread candide
The escape sequence \ENTER allows to split a string over 2 consecutive lines. On the other hand, it seems impossible to split a numeric litteral across multiple lines, compare : >>> "1000\ ... 000\ ... 000" '10' >>> 1000\ ... 000\ File "", line 2 000\ ^ SyntaxError:

List of lists surprising behaviour

2010-06-17 Thread candide
Let's the following code : >>> t=[[0]*2]*3 >>> t [[0, 0], [0, 0], [0, 0]] >>> t[0][0]=1 >>> t [[1, 0], [1, 0], [1, 0]] Rather surprising, isn't it ? So I suppose all the subarrays reférence the same array : >>> id(t[0]), id(t[1]), id(t[2]) (3077445996L, 3077445996L, 3077445996L) >>> So what

Re: Address of an immutable object

2010-05-30 Thread candide
Alf P. Steinbach a écrit : * candide, on 30.05.2010 19:38: Suppose a Python program defines an integer object with value 42. The object has an "address" we can capture with the built-in function id() : First, id() doesn't generally provide an address. I talked about

Re: Address of an immutable object

2010-05-30 Thread candide
Thanks for your responses, I should do more experiments ! -- http://mail.python.org/mailman/listinfo/python-list

Address of an immutable object

2010-05-30 Thread candide
Suppose a Python program defines an integer object with value 42. The object has an "address" we can capture with the built-in function id() : >>> a=42 >>> id(a) 152263540 >>> Now I was wondering if any integer object with value 42 will be refered at the same adress with the above id. Some e

Re: a.extend(b) better than a+=b ?

2010-04-22 Thread candide
Alf P. Steinbach a écrit : * candide: Suppose a and b are lists. What is more efficient in order to extend the list a by appending all the items in the list b ? I imagine a.extend(b)to be more efficient for only appendinding the items from b while a+=b creates a copy of a before appending

  1   2   >