[Tutor] genfromtxt and dtype to convert data to correct format

Sydney Shall s.shall at virginmedia.com
Wed May 18 13:13:25 EDT 2016


On 18/05/2016 14:14, Ek Esawi wrote:
> OPS! Sorry, I made a mistake on the posting. My output is in a string
> format as shown below. I want the 1st and 8th integers, the 3rd string
> which is OK as, the 2nd date and the rest time. I tried several
> combinations of dtype but could not get the date and time data to without
> the single quote -string format.
>
>
>
>
> [ (b'312171', '1995-07-01', b'Old', '13:37:00', '01:43:00', '04:42:00',
> '13:16:00', b'162', '13:19:00')
>  (b'358237', '1993-05-25', b'Old', '12:22:00', '01:31:00', '04:16:00',
> '12:03:00', b'160', '12:13:00')
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
Try the following;

line1 = [ (b'312171', '1995-07-01', b'Old', '13:37:00', '01:43:00', 
'04:42:00','13:16:00', b'162', '13:19:00')]
line2 = [(b'358237', '1993-05-25', b'Old', '12:22:00', 
'01:31:00','04:16:00','12:03:00', b'160', '12:13:00')]

item1A = line1[0][0]
item1B = line1[0][7]
item2A = line2[0][0]
item2B = line2[0][7]
print item1A, item1B
print item2A, item2B


-- 
Sydney


More information about the Tutor mailing list