On Wed, Nov 27, 2013 at 10:20:03PM +0100, spir wrote:
> On 11/26/2013 12:59 PM, Steven D'Aprano wrote:
> >On Tue, Nov 26, 2013 at 10:01:14AM +, Alan Gauld wrote:
> >
> >>>Is there a method to compare a substring, without building a substring
> >>>from the big one? Like startswith or endswith, b
On 11/28/2013 02:34 AM, Alan Gauld wrote:
Not so. If you are looking for a string and know the string ends with that
string you want the end point to exclude the known result at the end. And it is
a startswith because you are checking from the
start of the substring.
Ah, thank you, Alan!
Denis
On 11/28/2013 02:12 AM, Walter Prins wrote:
Sorry to wade in after all the other answers you've had, but a)
string.find() does not *require* start and end indexes, they are optional:
http://docs.python.org/2/library/string.htmlAnd b) if you're just trying
to find out whether a substring exist
On 27/11/13 21:20, spir wrote:
py> s.startswith("bcd", 1, -1) and s.endswith("bcd", 1, -1)
True
Hum, I don't understand the reasoning, here.
* First, why use the end-index param? (Here in this case, or in any
other)? It contradicts the idea of starting with in my view, but also is
useless for
Hi,
On 27 November 2013 21:20, spir wrote:
> All in all, startswith plus start-index only seems to work fine, I guess.
> What is wrong? string.find also works (someone suggested it on the
> python-ideas mailing list) but requires both start- and end- indexes. Also,
> startswith returns true/fal
On 11/26/2013 12:59 PM, Steven D'Aprano wrote:
On Tue, Nov 26, 2013 at 10:01:14AM +, Alan Gauld wrote:
Is there a method to compare a substring, without building a substring
>from the big one? Like startswith or endswith, but anywhere inside the
string?
test = s[1, -1] == "bcd"#
Hi Denis,
For reference, you can explore the documentation to find out what strings
can do:
http://docs.python.org/3/library/stdtypes.html#text-sequence-type-str
> What is the method to get a code or list of codes inside a string:
> s = "abcde"
> c = s.code(2)
> ass
On Tue, Nov 26, 2013 at 6:34 AM, Steven D'Aprano wrote:
>
> I think that views would be useful for *very large strings*, but very
> large probably means a lot larger than you might think. For small
> strings, say under a few hundred or perhaps even thousand characters,
> making a copy of the subst
Pleae use ReplyAll to include the list.
> c = ord(s[2])
>
>Yes, that's it: i forgot about Python's builtin functions, only searched among
>methods. Then, two more questions:
>-1- Why isn't this a str method? s.ord() [or better s.code()] looks natural,
>doesn't it?Because it operates on a single
On 26/11/13 11:59, Steven D'Aprano wrote:
test = s.startswith("bcd", 1, -1)
That doesn't work, unfortunately:
py> s = "abcdZZZ"
py> s[1:-1] == "bcd"
False
py> s.startswith("bcd", 1, -1)
True
Oops.
You'd have to do both startswith() and endswith() tests, and even then
it doesn't work:
On Tue, Nov 26, 2013 at 10:01:14AM +, Alan Gauld wrote:
> >Is there a method to compare a substring, without building a substring
> >from the big one? Like startswith or endswith, but anywhere inside the
> >string?
> > test = s[1, -1] == "bcd"# no!, builds a substring
>
> I assume you
On Tue, Nov 26, 2013 at 10:19:46AM +0100, spir wrote:
> What is the method to get a code or list of codes inside a string:
> s = "abcde"
> c = s.code(2)
> assert(c == 0x63)
> ?
Use indexing to get the character you want, then ord() to return its
ordinal value.
ord(s[2])
> ===
On 26/11/13 09:19, spir wrote:
What is the method to get a code or list of codes inside a string:
s = "abcde"
c = s.code(2)
assert(c == 0x63)
If I understand what you want then I think its the ord() function
you are looking for
c = ord(s[2])
=== sub compare ===
Is there a m
Hello,
I am coming back to Python after quite a long time, have forgotten everything,
and don't know anything of python 3. I use python 3.3 for its nice unicode text
type.
=== codes ===
What is the method to get a code or list of codes inside a string:
s = "abcde"
c = s.code(
14 matches
Mail list logo