Opposite of split

John Posner jjposner at optimum.net
Mon Aug 16 20:33:14 CEST 2010

On 8/16/2010 12:44 PM, Alex van der Spek wrote:
> Anybody catches any other ways to improve my program (attached), you are
> most welcome.

1. You don't need to separate out special characters (TABs, NEWLINEs, 
etc.) in a string. So:


... can be ...


BTW, I think you made a couple of "lucky errors" in this statement. 
Where there are two consecutive apostrophe (') characters, did you mean 
to put a plus sign in between? Your statement is valid because the 
Python interpreter concatenates strings for you:

    >>> x = 'foo''bar'
    >>> x == 'foobar'

    >>> x = 'foo'  'bar'
    >>> x == 'foobar'

2. Take a look at the functions in the os.path module:


These functions might simplify your pathname manipulations. (I didn't 
look closely enough to know for sure.)

3. An alternative to:


   ... is ...

   alf.write("\t".join((tp, vf, vq, al, bt, vs)) + "\n")

4. I suggest using a helper function to bring that super-long 
column-heading line (alf.write('Timestamp ...) under control:

   def multi_field_names(base_name, count, sep_string):
       names = [base_name + " " + str(i) for i in range(1, count+1)]
       return sep_string.join(names)


More information about the Python-list mailing list