compound strip() string problem

Dylan Wilson goandspamyourself at doamin.com
Fri Apr 8 08:31:09 EDT 2005


Hi,
I'm new to python and i have a string problem.
My problem is this
--------------------------------------------------------------------------
 >>>import time
 >>>time = time.asctime()
 >>>time
'Fri Apr 08 22:14:14 2005'
 >>>ti = time[0:13]
 >>>me = time[14:16]
 >>>time = ti + me
 >>>time
'Fri Apr 08 2214'
--------------------------------------------------------------------------
Now i need to compond that string remove the whitespace if you will.Well
i read up on strip(), lstrip() and rstrip() and all i could deduce was 
that they striped the whitespace from the start and/or end of the 
string.But I tried that anyway and failed.Is there an easier way than i 
did it below? I'm sorry it's ugly and tedious.
--------------------------------------------------------------------------
#!/bin/bash/env python

import os, time

#Figure out what os this is
platform = os.name

#Create string with date, time and extension for our pcap file
ext = '.out'
time = time.asctime()
ti = time[0:13]       #
me = time[14:16]     #
time = ti + me      #There has to be a better way to do this?
fo = time[0:3]       #
rm = time[4:7]        #
at  = time[11:18]
time = fo + rm + at + ext

#Get rid of yukkies
del ti, me, ext, fo, rm, at

#create command string
flag = '-w'
wincommand = 'c:/progra~1/ethereal/tethereal'
lincommand = '/usr/sbin/./tethereal'

#run tethereal and send the output to a pcap file DDDMMMHHMM.out

if platform == 'nt':
     os.system('%s %s %s' % (wincommand, flag, time))

if platform == 'posix':
     os.system('%s %s %s' % (lincommand, flag, time))
--------------------------------------------------------------------------
Thanks,
Dylan



More information about the Python-list mailing list