compound strip() string problem

2005-04-08 Thread Dylan Wilson
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
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newline at EOF Removal

2006-01-09 Thread Dylan Wilson
Do you mean somthing like this?

>>> f = open("file.txt")
>>> w = open('outfile.txt', 'w')
>>> for line in f.split('\n'):
...w.write(line)
...
>>> w.close()
>>> '\n' in open('/home/wandleg/outfile.txt').read()
False

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pop line from file

2006-02-15 Thread Dylan Wilson
Try open.readline()

>>>help(open)
...

-- 
http://mail.python.org/mailman/listinfo/python-list


file()

2008-07-18 Thread Dylan Wilson
well, I'm in the beginings of making a random sentence generator for a mod my 
friend makes, but I want the nouns, verbs pastverbs, etc. to be easily 
customizable by editing a file, but, last night file() worked fine and today 
it's saying " line 1: `read_who = file('who.ini', 'r')'"

here's what I have so far, but for reference it's possible I'm just being an 
idiot because I'm very new to Python and programming in general



read_who = file('who.ini', 'r')
who = read_who.read()

read_what = file('what.ini', 'r')
what = read_what.read()

read_end = file('end.ini', 'r')
end = read_end.read()

read_because = file('because.ini', 'r')
because = read_because.read()

read_the = file('the.ini', 'r')
da = read_the.read()

read_period = file('punc.ini', 'r')
period = read_period.read()
prd = read_period.read()

read_nouns = file('nouns.ini', 'r')
nouns = read_nouns.read()

read_verbs = file('verbs.ini', 'r')
verbs = read_verbs.read()

read_pastverbs = file('pastverbs.ini', 'r')
pastverbs = read_pastverbs.read()



  --
http://mail.python.org/mailman/listinfo/python-list