Re: spliting on ":"

2006-03-06 Thread Peter Hansen
Cyril Bazin wrote: > I agree. None is an object! If you want to compare an object to another > object why not using "=="? The term "compare" is ambiguous. If you want to compare for *identity*, you use "is". If you want to compare for equality, you use "==". In most cases with None you are i

Re: spliting on ":"

2006-03-06 Thread Steve Holden
Bryan Olson wrote: > Peter Hansen wrote: > >>The archives could tell you more, but basically on is usually interested >>in *identity* with a singleton object (None), not in whether the object >>on is examining happens to compare equal. A custom object could be >>designed to compare equal to No

Re: spliting on ":"

2006-03-06 Thread Cyril Bazin
On 3/6/06, Bryan Olson <[EMAIL PROTECTED]> wrote: Peter Hansen wrote:> The archives could tell you more, but basically on is usually interested> in *identity* with a singleton object (None), not in whether the object> on is examining happens to compare equal.  A custom object could be > designed to

Re: spliting on ":"

2006-03-06 Thread Bryan Olson
Peter Hansen wrote: > The archives could tell you more, but basically on is usually interested > in *identity* with a singleton object (None), not in whether the object > on is examining happens to compare equal. A custom object could be > designed to compare equal to None in certain cases, eve

Re: spliting on ":"

2006-03-06 Thread fileexit
> yyy > yyy > yyy > xxx.xxx.xxx.xxx > xxx.xxx.xxx.xxx of course you will get this result... inside the loop, when line="xxx.xxx.xxx.xxx:yyy" line.split(":") will give a list ["xxx.xxx.xxx.xxx", "yyy"], and element -1 will be "yyy" but when line="xxx.xxx.xxx.xxx" line.split(":") will give a list

Re: spliting on ":"

2006-03-04 Thread Steven D'Aprano
On Sat, 04 Mar 2006 08:54:33 -0800, ss2003 wrote: > hi > > i have a file with > > xxx.xxx.xxx.xxx:yyy > xxx.xxx.xxx.xxx:yyy > xxx.xxx.xxx.xxx:yyy > xxx.xxx.xxx.xxx > xxx.xxx.xxx.xxx > xxx.xxx.xxx.xxx:yyy > > i wanna split on ":" and get all the "yyy" and print the whole line out > so i

Re: spliting on ":"

2006-03-04 Thread Peter Hansen
Petr Jakes wrote: >>I think you're getting caught by the classic and/or trap in Python, >>trying to avoid using a simple if statement. > > What do you mean by "the classic and/or trap"? Can you give an example > please? Sure, see my subsequent reply to Cyril, elsewhere in this thread. (In summar

Re: spliting on ":"

2006-03-04 Thread Peter Hansen
Cyril Bazin wrote: > Ok, ok, there was a mistake in the code. > (Of course, it was done on prupose in order to verify if everybody is > aware ;-) > I don't know why it is preferable to compare an object to the object > "None" using "is not". > "==" is, IMHO, more simple. Simple is better than com

Re: spliting on ":"

2006-03-04 Thread Petr Jakes
> I think you're getting caught by the classic and/or trap in Python, > trying to avoid using a simple if statement. What do you mean by "the classic and/or trap"? Can you give an example please? Petr Jakes -- http://mail.python.org/mailman/listinfo/python-list

Re: spliting on ":"

2006-03-04 Thread Cyril Bazin
Ok, ok, there was a mistake in the code. (Of course, it was done on prupose in order to verify if everybody is aware ;-)I don't know why it is preferable to compare an object to the object "None" using "is not". "==" is, IMHO, more simple. Simple is better than complex. So I use "==". The correct p

Re: spliting on ":"

2006-03-04 Thread Peter Hansen
Cyril Bazin wrote: > Your file looks like a list of IP adresses. > You can use the urllib and urllib2 modules to parse IP adresses. > > import urllib2 > for line in open("fileName.txt"): > addr, port = urllib2.splitport(line) > print (port != None) and '' or port Is this what you want to

Re: spliting on ":"

2006-03-04 Thread Cyril Bazin
Your file looks like a list of IP adresses. You can use the urllib and urllib2 modules to parse IP adresses.import urllib2for line in open("fileName.txt"):    addr, port  = urllib2.splitport(line)     print (port != None) and '' or portCyril -- http://mail.python.org/mailman/listinfo/python-list

Re: spliting on ":"

2006-03-04 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > hi > > i have a file with > > xxx.xxx.xxx.xxx:yyy > xxx.xxx.xxx.xxx:yyy > xxx.xxx.xxx.xxx:yyy > xxx.xxx.xxx.xxx > xxx.xxx.xxx.xxx > xxx.xxx.xxx.xxx:yyy > > i wanna split on ":" and get all the "yyy" and print the whole line out > so i did > > print line.split(":")[-1]

Re: spliting on ":"

2006-03-04 Thread Duncan Booth
[EMAIL PROTECTED] wrote: > print line.split(":")[-1] > > but line 4 and 5 are not printed as there is no ":" to split. It should > print a "blank" at least. > how to print out lines 4 and 5 ? > eg output is > > yyy > yyy > yyy > > > yyy if ":" in line: print line.split(":")[-1] else: pr

spliting on ":"

2006-03-04 Thread s99999999s2003
hi i have a file with xxx.xxx.xxx.xxx:yyy xxx.xxx.xxx.xxx:yyy xxx.xxx.xxx.xxx:yyy xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx:yyy i wanna split on ":" and get all the "yyy" and print the whole line out so i did print line.split(":")[-1] but line 4 and 5 are not printed as there is no ":" t