View Single Post
pycage's Avatar
Posts: 3,404 | Thanked: 4,474 times | Joined on Oct 2005 @ Germany
#3
Originally Posted by kevinm2k View Post
Hi,

Im just starting development in PyQT, and I have quite a basic thing i'm trying to do which I would find quite easy using something like PHP, but i'm struggling with python.

Not sure if im posting in correct place.. but

Basically I have a string like the following:

name:Example;
link:www.google.com;
datetime:20100209
|
name:Example2;
link:www.yahoo.co.uk;
datetime:20090808

So each result is seperated by a pipe (|) and key value pairs are seperated by a semi colon, then by a colon.

I want the ability to put these in to some kind of array so I can create a results page with lets say the following:

Result 1
Name: Example
Link: www.google.com
Datetime: 20100209

Result 2
Name: Example2
Link: www.yahoo.co.uk
Datetime: 20090808

Could someone help me with this snippet?

Thanks
Something like this...

Code:
for result in data.split("|"):
  for line in result.split("\n"):
    idx = line.find(":")
    key = line[:idx]
    value = line[idx + 1:]
    print "%s: %s" % (key, value)
__________________
Tidings - RSS and Podcast aggregator for Jolla - https://github.com/pycage/tidings
Cargo Dock - file/cloud manager for Jolla - https://github.com/pycage/cargodock
 

The Following User Says Thank You to pycage For This Useful Post: