Re: simple string question

2009-09-08 Thread Scott David Daniels
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

Re: simple string question

2009-09-07 Thread Niklas Norrthon
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

Re: simple string question

2009-09-07 Thread jwither
"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

Re: simple string question

2009-09-07 Thread Steven D'Aprano
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

Re: simple string question

2009-09-07 Thread D'Arcy J.M. Cain
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

Re: simple string question

2009-09-07 Thread Niklas Norrthon
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

Re: simple string question

2009-09-07 Thread ryles
> 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

Re: simple string question

2009-09-07 Thread jwither
"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 >>

Re: simple string question

2009-09-06 Thread Chris Rebert
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

Re: simple string question

2009-09-06 Thread 7stud
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

Re: simple string question

2009-09-06 Thread Sean DiZazzo
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

simple string question

2009-09-06 Thread jwither
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

Re: Raw String Question

2009-03-13 Thread Lie Ryan
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

Re: Raw String Question

2009-03-13 Thread MRAB
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

Re: Raw String Question

2009-03-13 Thread andrew cooke
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

Re: Raw String Question

2009-03-12 Thread MRAB
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

Re: Raw String Question

2009-03-12 Thread andrew cooke
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 -

Re: Raw String Question

2009-03-12 Thread MRAB
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

Re: Raw String Question

2009-03-12 Thread Miles
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

Re: Raw String Question

2009-03-12 Thread Albert Hopkins
> > 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

Re: Raw String Question

2009-03-12 Thread Jim Garrison
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

Re: Raw String Question

2009-03-12 Thread Duncan Booth
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

Re: Raw String Question

2009-03-12 Thread Nick Craig-Wood
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

Re: Raw String Question

2009-03-12 Thread Jim Garrison
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

Re: Raw String Question

2009-03-12 Thread Tim Chase
>>> 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

Raw String Question

2009-03-12 Thread Jim Garrison
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

Re: String question

2008-06-24 Thread Terry Reedy
[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

Re: String question

2008-06-24 Thread cokofreedom
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

Re: String question

2008-06-23 Thread Mark Tolonen
"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

Re: String question

2008-06-23 Thread Andreu
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

Re: String question

2008-06-23 Thread cokofreedom
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

Re: String question

2008-06-23 Thread Andreu
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

Re: String question

2008-06-23 Thread Tim Golden
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

String question

2008-06-23 Thread Andreu
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

Re: a simple string question

2007-07-28 Thread vedrandekovic
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

Re: a simple string question

2007-07-28 Thread Zentrader
> >>> 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

Re: a simple string question

2007-07-28 Thread Steve Holden
[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

Re: a simple string question

2007-07-28 Thread vedrandekovic
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

Re: a simple string question

2007-07-27 Thread Zentrader
> > [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

Re: a simple string question

2007-07-27 Thread Zentrader
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

Re: a simple string question

2007-07-27 Thread Wildemar Wildenburger
[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

Re: a simple string question

2007-07-27 Thread vedrandekovic
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

Re: a simple string question

2007-07-27 Thread Wildemar Wildenburger
[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: > >

Re: a simple string question

2007-07-27 Thread Zentrader
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

a simple string question

2007-07-27 Thread vedrandekovic
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

Re: String Question

2006-06-30 Thread Iain King
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

Re: String Question

2006-06-30 Thread Tim Roberts
"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

Re: String Question

2006-06-28 Thread Martin v. Löwis
[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

Re: String Question

2006-06-28 Thread diffuser78
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

Re: String Question

2006-06-28 Thread diffuser78
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

Re: String Question

2006-06-28 Thread Iain King
[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

Re: String Question

2006-06-28 Thread Fredrik Lundh
[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

String Question

2006-06-28 Thread diffuser78
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

Re: String question - find all possible versions of a person's firstname

2006-01-11 Thread bonono
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

Re: String question - find all possible versions of a person's firstname

2006-01-10 Thread Nico Grubert
> 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

Re: String question - find all possible versions of a person's firstname

2006-01-10 Thread Jeff Gercken
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

String question - find all possible versions of a person's firstname

2006-01-10 Thread Nico Grubert
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

Re: Horribly noobful string question

2005-12-14 Thread SeNTry
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("

Re: Horribly noobful string question

2005-12-14 Thread SeNTry
"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

Re: Horribly noobful string question

2005-12-13 Thread Xavier Morel
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

Re: Horribly noobful string question

2005-12-13 Thread Fredrik Lundh
"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

Horribly noobful string question

2005-12-13 Thread SeNTry
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

Re: Qt String Question

2004-12-13 Thread Detlev Offenbach
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

Re: Qt String Question

2004-12-13 Thread Pierre Barbier de Reuille
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

Re: Qt String Question

2004-12-13 Thread Phil Thompson
> 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

Re: Qt String Question

2004-12-12 Thread Michael McGarry
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

Qt String Question

2004-12-12 Thread Michael McGarry
Hi, How do I convert from a qt.QString to a Python string? Michael -- http://mail.python.org/mailman/listinfo/python-list