LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-23-2017, 08:11 AM   #1
konkura
LQ Newbie
 
Registered: Apr 2011
Posts: 22

Rep: Reputation: 1
extract elements from single element tuple in python


Hi friends,

I have single element tuples pulled out from asterisk database, when looped over rows look like this:

('10.1.1.128:5060:3600:222:sip:222@10.1.1.128:5060',)
('10.1.1.115:5060:3600:217:sip:217@10.1.1.115:5060',)
('10.1.1.105:5060:3600:213:sip:213@10.1.1.105:5060',)
('10.1.1.107:5060:3600:204:sip:204@10.1.1.107:5060',)

how do I extract element like ip address or ports which are delimited
with ':'? I cannot slice with indexes because lengths of elements between ':' doesn't have fixed length.

Thx!
 
Old 09-23-2017, 11:00 AM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: Slackware
Posts: 7,702

Rep: Reputation: 2983Reputation: 2983Reputation: 2983Reputation: 2983Reputation: 2983Reputation: 2983Reputation: 2983Reputation: 2983Reputation: 2983Reputation: 2983Reputation: 2983
You're looking for str.split.

Code:
>>> t = ('10.1.1.128:5060:3600:222:sip:222@10.1.1.128:5060',)                   
>>> t[0]
'10.1.1.128:5060:3600:222:sip:222@10.1.1.128:5060'                              
>>> t[0].split(':') 
['10.1.1.128', '5060', '3600', '222', 'sip', '222@10.1.1.128', '5060']
>>> t[0].split(':')[0]
'10.1.1.128'

Last edited by dugan; 09-23-2017 at 11:02 AM.
 
1 members found this post helpful.
Old 09-23-2017, 12:43 PM   #3
konkura
LQ Newbie
 
Registered: Apr 2011
Posts: 22

Original Poster
Rep: Reputation: 1
That's it! Thx!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sending tuple output to a file using python shwhooda Programming 2 06-28-2012 07:39 PM
Python, find unique values in a tuple or dictionary action_owl Programming 2 05-11-2010 08:16 PM
How to extract information element from Beacon Frame. Mr.J Linux - Wireless Networking 0 04-25-2009 10:49 PM
[interesting question] find an element which is sum of two other elements George2 Programming 3 06-09-2006 01:48 PM
arrays of elements with [gcc4]array type has incomplete element type lmmix Linux - Software 0 02-26-2005 09:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration