D'Arcy J.M. Cain wrote:
On Mon, 7 Sep 2009 15:29:23 +1000
"jwither" wrote:
Given a string (read from a file) which contains raw escape sequences,
(specifically, slash n), what is the best way to convert that to a parsed
string, where the escape sequence has been replaced (specifically, by a
N
On 8 Sep, 05:39, Steven D'Aprano
wrote:
> On Mon, 07 Sep 2009 01:54:09 -0700, Niklas Norrthon wrote:
> > Others have answered how to replace '\\n' with '\n'. For a more general
> > approach which will handle all string escape sequences allowed in python
> > (including '\xdd' and similar), python's
"ryles" wrote in message
news:b96be200-9762-4f92-bd0d-9be076bcd...@y20g2000vbk.googlegroups.com...
>
>> There's probably a more general method covering all the escape
>> sequences, but for just \n:
>>
>> your_string = your_string.replace("\\n", "\n")
>
> py> s = "hello\\r\\n"
> py> s
> 'hello\\r
On Mon, 07 Sep 2009 01:54:09 -0700, Niklas Norrthon wrote:
> Others have answered how to replace '\\n' with '\n'. For a more general
> approach which will handle all string escape sequences allowed in python
> (including '\xdd' and similar), python's eval can be used:
eval can do so much more tha
On Mon, 7 Sep 2009 15:29:23 +1000
"jwither" wrote:
> Given a string (read from a file) which contains raw escape sequences,
> (specifically, slash n), what is the best way to convert that to a parsed
> string, where the escape sequence has been replaced (specifically, by a
> NEWLINE token)?
I
On 7 Sep, 07:29, "jwither" wrote:
> Given a string (read from a file) which contains raw escape sequences,
> (specifically, slash n), what is the best way to convert that to a parsed
> string, where the escape sequence has been replaced (specifically, by a
> NEWLINE token)?
>
> James Withers
Othe
> There's probably a more general method covering all the escape
> sequences, but for just \n:
>
> your_string = your_string.replace("\\n", "\n")
py> s = "hello\\r\\n"
py> s
'hello\\r\\n'
py> s.decode("string_escape")
'hello\r\n'
py>
--
http://mail.python.org/mailman/listinfo/python-list
"Chris Rebert" wrote in message
news:mailman.1075.1252306208.2854.python-l...@python.org...
> On Sun, Sep 6, 2009 at 10:29 PM, jwither wrote:
>> Given a string (read from a file) which contains raw escape sequences,
>> (specifically, slash n), what is the best way to convert that to a parsed
>>
On Sun, Sep 6, 2009 at 10:29 PM, jwither wrote:
> Given a string (read from a file) which contains raw escape sequences,
> (specifically, slash n), what is the best way to convert that to a parsed
> string, where the escape sequence has been replaced (specifically, by a
> NEWLINE token)?
There's p
On Sep 6, 11:29 pm, "jwither" wrote:
> Given a string (read from a file) which contains raw escape sequences,
> (specifically, slash n), what is the best way to convert that to a parsed
> string, where the escape sequence has been replaced (specifically, by a
> NEWLINE token)?
>
> James Withers
1
On Sep 6, 10:29 pm, "jwither" wrote:
> Given a string (read from a file) which contains raw escape sequences,
> (specifically, slash n), what is the best way to convert that to a parsed
> string, where the escape sequence has been replaced (specifically, by a
> NEWLINE token)?
>
> James Withers
I
Given a string (read from a file) which contains raw escape sequences,
(specifically, slash n), what is the best way to convert that to a parsed
string, where the escape sequence has been replaced (specifically, by a
NEWLINE token)?
James Withers
--
http://mail.python.org/mailman/listinfo/p
MRAB wrote:
In Python 3.x a backslash doesn't have a special meaning in a raw
string, except that it can prevent a following quote from ending the
string, but the backslash is still included. Why? How useful is that? I
think it would've been simpler if a backslash had _no_ special effect,
not ev
andrew cooke wrote:
MRAB wrote:
andrew cooke wrote:
MRAB wrote:
[...]
The other special case is with \u in a Unicode string:
>>> ur"\u0041"
u'A'
this isn't true for 3.0:
r"\u0041"
'\\u0041'
(there's no "u" because it's a string, not a bytes literal)
and as far as i can tell, that's cor
MRAB wrote:
> andrew cooke wrote:
>> MRAB wrote:
>> [...]
>>> The other special case is with \u in a Unicode string:
>>>
>>> >>> ur"\u0041"
>>> u'A'
>>
>> this isn't true for 3.0:
>>
> r"\u0041"
>> '\\u0041'
>>
>> (there's no "u" because it's a string, not a bytes literal)
>>
>> and as far as
andrew cooke wrote:
MRAB wrote:
[...]
The other special case is with \u in a Unicode string:
>>> ur"\u0041"
u'A'
this isn't true for 3.0:
r"\u0041"
'\\u0041'
(there's no "u" because it's a string, not a bytes literal)
and as far as i can tell, that's correct behaviour according to the d
MRAB wrote:
[...]
> The other special case is with \u in a Unicode string:
>
> >>> ur"\u0041"
> u'A'
this isn't true for 3.0:
>>> r"\u0041"
'\\u0041'
(there's no "u" because it's a string, not a bytes literal)
and as far as i can tell, that's correct behaviour according to the docs.
andrew
-
Jim Garrison wrote:
Tim Chase wrote:
>>> r"a\"
SyntaxError: EOL while scanning string literal (, line 1)
It seems the parser is interpreting the backslash as an escape
character in a raw string if the backslash is the last character.
Is this expected?
Yep...as documented[1], "even a raw s
On Thu, Mar 12, 2009 at 3:28 PM, Jim Garrison wrote:
> OK, I'm curious as to the reasoning behind saying that
>
> When an 'r' or 'R' prefix is present, a character following a
> backslash is included in the string without change, and all
> backslashes are left in the string.
>
> which sounds
> > Yep...as documented[1], "even a raw string cannot end in an odd number
> > of backslashes".
>
> So how do you explain this?
>
> >>> r'a\'b'
> "a\\'b"
That doesn't "end in an odd number of backslashes."
Python is __repr__esenting a raw string as a "regular" string.
Literally they
Tim Chase wrote:
>>> r"a\"
SyntaxError: EOL while scanning string literal (, line 1)
It seems the parser is interpreting the backslash as an escape
character in a raw string if the backslash is the last character.
Is this expected?
Yep...as documented[1], "even a raw string cannot end in a
Jim Garrison wrote:
> OK, I'm curious as to the reasoning behind saying that
>
> When an 'r' or 'R' prefix is present, a character following a
> backslash is included in the string without change, and all
> backslashes are left in the string.
>
> which sounds reasonable, but then sa
Jim Garrison wrote:
> >>> r"a\b"
>'a\\b'
> >>> r"a\"
>SyntaxError: EOL while scanning string literal (, line 1)
> >>> r"a\ "
>'a\\ '
> >>> r"a\""
>'a\\"'
>
> It seems the parser is interpreting the backslash as an escape
> character in a raw string if the backslash is th
Tim Chase wrote:
>>> r"a\"
SyntaxError: EOL while scanning string literal (, line 1)
It seems the parser is interpreting the backslash as an escape
character in a raw string if the backslash is the last character.
Is this expected?
Yep...as documented[1], "even a raw string cannot end in a
>>> r"a\"
SyntaxError: EOL while scanning string literal (, line 1)
It seems the parser is interpreting the backslash as an escape
character in a raw string if the backslash is the last character.
Is this expected?
Yep...as documented[1], "even a raw string cannot end in an odd
number of b
I'm an experienced Perl developer learning Python, but I seem to
be missing something about raw strings. Here's a transcript of
a Python shell session:
Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more infor
[EMAIL PROTECTED] wrote:
On Jun 24, 5:38 am, "Mark Tolonen" <[EMAIL PROTECTED]> wrote:
In Python 3k I believe you can put a * next to one of the variables to
hold multiple arguments. That'll be aidful!
IDLE 3.0b1
>>> a,b,*c=[1,2,3,4,5]
>>> c
[3, 4, 5]
>>> a,*b,c = [1,2,3,4,5]
>>> b
[2, 3, 4
On Jun 24, 5:38 am, "Mark Tolonen" <[EMAIL PROTECTED]> wrote:
> "Andreu" <[EMAIL PROTECTED]> wrote in messagenews:[EMAIL PROTECTED]
> > Yes, ... don't ask me why, but in fact v1,v2,v3 = str1.split()
> > does not seem to work. My original problem was I forgot about
> > the parenthesis as Tim point
"Andreu" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
Yes, ... don't ask me why, but in fact v1,v2,v3 = str1.split()
does not seem to work. My original problem was I forgot about
the parenthesis as Tim point out. So I ended up converting to a
list as in: v = str1.split() and acc
Yes, ... don't ask me why, but in fact v1,v2,v3 = str1.split()
does not seem to work. My original problem was I forgot about
the parenthesis as Tim point out. So I ended up converting to a
list as in: v = str1.split() and accessing the elements using
v[0] v[1] ect...it is working now. Thanks.
A
On Jun 23, 4:45 pm, Andreu <[EMAIL PROTECTED]> wrote:
> I want to split a sentence and assign each word to a variable.
> In Ruby I can do it as:
>
> v1,v2,v3,v4,v5 = str1.split
>
> Which will be the Python equivalent ? Thanks.
>
> Andrew.
Well a straight copy would be...
>>> example = "Hello, how
Wow...about ten seconds to get a kind response
Thanks Tim.
Andrew.
Tim Golden wrote:
Andreu wrote:
I want to split a sentence and assign each word to a variable.
In Ruby I can do it as:
v1,v2,v3,v4,v5 = str1.split
Which will be the Python equivalent ? Thanks.
That would be:
str1 = "T
Andreu wrote:
I want to split a sentence and assign each word to a variable.
In Ruby I can do it as:
v1,v2,v3,v4,v5 = str1.split
Which will be the Python equivalent ? Thanks.
That would be:
str1 = "The quick brown fox jumps"
v1, v2, v3, v4, v5 = str1.split ()
TJG
--
http://mail.python.org/m
I want to split a sentence and assign each word to a variable.
In Ruby I can do it as:
v1,v2,v3,v4,v5 = str1.split
Which will be the Python equivalent ? Thanks.
Andrew.
--
http://mail.python.org/mailman/listinfo/python-list
On 28 srp, 14:15, Steve Holden <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > On 28 srp, 07:05, Zentrader <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > NEW TEXT : "Hello world;\nHello:\n\t\t\n\n\n\n\n\nHello2"
> >> If you are doing all of this to format the output i
> >>> Short_Text="n=90; if n==90:print 'ok'"
> >>> compound_lines = Short_Text.split(";")
> >>> for line in compound_lines:
> ... line = line.replace(":", ":\n")
> ... print line
> ...
> n=90
> if n==90:
> print 'ok'
A variation of this will work if the input file isn't too
compl
[EMAIL PROTECTED] wrote:
> On 28 srp, 07:05, Zentrader <[EMAIL PROTECTED]> wrote:
[EMAIL PROTECTED] wrote:
> NEW TEXT : "Hello world;\nHello:\n\t\t\n\n\n\n\n\nHello2"
>> If you are doing all of this to format the output into columns,
>> Python's print() or write() will do this, and is eas
On 28 srp, 07:05, Zentrader <[EMAIL PROTECTED]> wrote:
> > > [EMAIL PROTECTED] wrote:
> > > > NEW TEXT : "Hello world;\nHello:\n\t\t\n\n\n\n\n\nHello2"
>
> If you are doing all of this to format the output into columns,
> Python's print() or write() will do this, and is easier as well. Some
> mor
> > [EMAIL PROTECTED] wrote:
> > > NEW TEXT : "Hello world;\nHello:\n\t\t\n\n\n\n\n\nHello2"
If you are doing all of this to format the output into columns,
Python's print() or write() will do this, and is easier as well. Some
more info on what you want to do will clear things up.
--
http://ma
On Jul 27, 11:26 am, Wildemar Wildenburger <[EMAIL PROTECTED]>
wrote:
> [EMAIL PROTECTED] wrote:
> >> If I understand you correctly you want to replace ";" by ";\n" and ":"
> >> by ":\n\t\t\t\t\t\t\t".
> >> Well guess what? The replace() method does just this. Have a read:
> >> http://docs.python.o
[EMAIL PROTECTED] wrote:
>> If I understand you correctly you want to replace ";" by ";\n" and ":"
>> by ":\n\t\t\t\t\t\t\t".
>> Well guess what? The replace() method does just this. Have a read:
>> http://docs.python.org/lib/string-methods.html>
>>
> No,that's not what I need...
> When this f
On 27 srp, 19:29, Wildemar Wildenburger <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > I have one question about string.I am trying to make an function to
> > analyze line of some text, this is my example: "HELLO;HELLO2:WORLD:",
> > if that function in this text find ";" and ":" ( in t
[EMAIL PROTECTED] wrote:
> I have one question about string.I am trying to make an function to
> analyze line of some text, this is my example: "HELLO;HELLO2:WORLD:",
> if that function in this text find ";" and ":" ( in this example will
> find both)
>
> e.g that function must return this:
>
>
On Jul 27, 8:23 am, [EMAIL PROTECTED] wrote:
> Hello,
>
> I have one question about string.I am trying to make an function to
> analyze line of some text, this is my example: "HELLO;HELLO2:WORLD:",
> if that function in this text find ";" and ":" ( in this example will
> find both)
>
> e.g that
Hello,
I have one question about string.I am trying to make an function to
analyze line of some text, this is my example: "HELLO;HELLO2:WORLD:",
if that function in this text find ";" and ":" ( in this example will
find both)
e.g that function must return this:
"HELLO;\nHELLO2:\n\t\t\t\t\t\t
Tim Roberts wrote:
> "Iain King" <[EMAIL PROTECTED]> wrote:
> >
> >You probably want:
> >
> >s.sendto('\xff'*6 + ('\x%s\x%s\x%s\x%s\x%s\x%s' % (str01, str02, str03,
> > sttr04, str05, str06))*16, ('192.168.1.255', 80))
>
> You probably should TRY suggestions before you post them. That will get an
"Iain King" <[EMAIL PROTECTED]> wrote:
>
>You probably want:
>
>s.sendto('\xff'*6 + ('\x%s\x%s\x%s\x%s\x%s\x%s' % (str01, str02, str03,
> sttr04, str05, str06))*16, ('192.168.1.255', 80))
You probably should TRY suggestions before you post them. That will get an
"invalid \x escape". \x must be f
[EMAIL PROTECTED] wrote:
> mac_string = '001485e55503' (This is the mac address of a computer.)
> Since the MAC adddress are hexadecimal, how should I go about it here.
>
> Please help, every help is appreciated. Thanks
I could not quite understand what you are trying to achieve, but
it appears
I will try this one too...thanks for your response.
Iain King wrote:
> [EMAIL PROTECTED] wrote:
> > mac_string = '001485e55503' (This is the mac address of a computer.)
> >
> > I am using wake on LAN python script to start computer remote.It uses
> > format like this
> >
> > s.sendto('\xff'*6
Many Thanks!! It worked like a charm.
Fredrik Lundh wrote:
> [EMAIL PROTECTED] wrote:
>
> > mac_string = '001485e55503' (This is the mac address of a computer.)
> >
> > I am using wake on LAN python script to start computer remote.It uses
> > format like this
> >
> > s.sendto('\xff'*6 + '\x0
[EMAIL PROTECTED] wrote:
> mac_string = '001485e55503' (This is the mac address of a computer.)
>
> I am using wake on LAN python script to start computer remote.It uses
> format like this
>
> s.sendto('\xff'*6 + '\x00\x014\x85\xe5\x55\x03'*16, ('192.168.1.255',
> 80))
>
> where '\x00\x14\x8
[EMAIL PROTECTED] wrote:
> mac_string = '001485e55503' (This is the mac address of a computer.)
>
> I am using wake on LAN python script to start computer remote.It uses
> format like this
>
> s.sendto('\xff'*6 + '\x00\x014\x85\xe5\x55\x03'*16, ('192.168.1.255',
> 80))
>
> where '\x00\x14\x8
mac_string = '001485e55503' (This is the mac address of a computer.)
I am using wake on LAN python script to start computer remote.It uses
format like this
s.sendto('\xff'*6 + '\x00\x014\x85\xe5\x55\x03'*16, ('192.168.1.255',
80))
where '\x00\x14\x85\xe5\x55\x03' is the MAC address to be u
Nico Grubert wrote:
> > This sounds like a homework problem. You might try splitting the name
> > at the e's, check the length of the resulting list and do that many
> > nested loops.
>
> This was my idea too but I am wondering if there are any scripts for
> tasks like this.
>
> Nico
def combine
> This sounds like a homework problem. You might try splitting the name
> at the e's, check the length of the resulting list and do that many
> nested loops.
This was my idea too but I am wondering if there are any scripts for
tasks like this.
Nico
--
http://mail.python.org/mailman/listinfo/py
This sounds like a homework problem. You might try splitting the name
at the e's, check the length of the resulting list and do that many
nested loops.
On 1/10/06, Nico Grubert <[EMAIL PROTECTED]> wrote:
> Hi there,
>
> I have a string 'Michèle' that represents the firstname of a person.
>
> What
Hi there,
I have a string 'Michèle' that represents the firstname of a person.
What's the best way to get all possible versions of this name if I
consider to use these characters: e, è, é, ê
I'd like to have a function that returns a list of the following names
when passing 'Michèle' as parame
SRY, that last bit of code got messed up. Hopefully it will look right
now...
#define two functions first, then use them.
def loopfunc(looping):
while looping:
guess= input("guess a number. see if you can guess what I'm thinking")
if guess == number:
print "you got it!"
looping=False
playagain("
"Xavier Morel" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Fredrik Lundh wrote:
>> "SeNTry" wrote:
>>
>>> My first post here as I just begin to learn programming in general and
>>> python in particular. I have all the noobie confused questions, but as
>>> I
>>> work thru the t
Fredrik Lundh wrote:
> "SeNTry" wrote:
>
>> My first post here as I just begin to learn programming in general and
>> python in particular. I have all the noobie confused questions, but as I
>> work thru the tutorials I'm sure I'll find most my answers.
>>
>> This one is eluding me tho... I am wo
"SeNTry" wrote:
> My first post here as I just begin to learn programming in general and
> python in particular. I have all the noobie confused questions, but as I
> work thru the tutorials I'm sure I'll find most my answers.
>
> This one is eluding me tho... I am working in the tutorials, writin
Hi Everyone,
My first post here as I just begin to learn programming in general and
python in particular. I have all the noobie confused questions, but as I
work thru the tutorials I'm sure I'll find most my answers.
This one is eluding me tho... I am working in the tutorials, writing scripts
Phil Thompson wrote:
>> Michael McGarry wrote:
>>> Hi,
>>>
>>> How do I convert from a qt.QString to a Python string?
>>>
>>> Michael
>> Apparently the ascii() method of QString does this. (I answered my own
>> question).
>
> Or use the str() builtin.
>
> Phil
unicode() is even better because Q
Michael McGarry wrote:
Michael McGarry wrote:
Hi,
How do I convert from a qt.QString to a Python string?
Michael
Apparently the ascii() method of QString does this. (I answered my own
question).
sorry for wasting newsgroup space.
Depending on the kind of string you have, latin1() may be a better
> Michael McGarry wrote:
>> Hi,
>>
>> How do I convert from a qt.QString to a Python string?
>>
>> Michael
> Apparently the ascii() method of QString does this. (I answered my own
> question).
Or use the str() builtin.
Phil
--
http://mail.python.org/mailman/listinfo/python-list
Michael McGarry wrote:
Hi,
How do I convert from a qt.QString to a Python string?
Michael
Apparently the ascii() method of QString does this. (I answered my own
question).
sorry for wasting newsgroup space.
--
http://mail.python.org/mailman/listinfo/python-list
Hi,
How do I convert from a qt.QString to a Python string?
Michael
--
http://mail.python.org/mailman/listinfo/python-list
67 matches
Mail list logo