If you have a lot of files to do this to, I would suggest learning at
least a little bit of perl.  It might not be as nice an option as a
python tab manager (depending on your point of view), though.

Perl uses regular expressions.  In case you'd like to see how to do
your tab-space replacement, the following bit of code would convert
tabs to 4 spaces.

Take care,

Mike Z

#----------------------------------
use strict;
use warnings;
my $file = $ARGV[0];
open(IN,$file) or die $!;
open(OUT,">".$file."notab") or die $!;
while(<IN>){
   $_ =~ s/\t/    /g;
   print OUT $_;
}
close(IN);
close(OUT);
exit;
#----------------------------------

On Tue, Jan 26, 2010 at 9:09 AM, Jason Vertrees
<jason.vertr...@schrodinger.com> wrote:
> David,
>
> Oh, the joys of open-source.  Here's my solution for you:
>  (1) load your file in your favorite editor
>  (2) determine user-desired tab stop setting
>  (3) convert all tabs to spaces in your editor (or search replace tabs
> with X-spaces)
>  (4) save your file
>
> One warning though, I have seen some interpreters crash when they
> encounter spaces over tabs.
>
> -- Jason
>
> On Tue, Jan 26, 2010 at 9:12 AM, David Hall <li...@cowsandmilk.net> wrote:
>> During my editing of dynoplot.py, I noticed that there were some
>> whitespace issues.  Normally I consider whitespace a bikeshedding
>> topic, but in python, it is significant, so it matters.  When tabs and
>> spaces are mixed, our own personal settings for how tabs are displayed
>> in an editor makes a huge difference in whether the script is
>> understandable.
>>
>> I checked out the git repo of pymol scripts (
>> http://github.com/jlec/Pymol-script-repo/ ) and did some analysis
>>
>> First, these files switch between some lines where all indenting is
>> tabs to lines where all indenting is spaces:
>> Objects_and_Selections/color_objects.py has 8 tab lines and 34 space lines
>> ThirdParty_Scripts/WFMesh.py has 52 tab lines and 21 space lines
>> biochemical_scripts/pucker.py has 167 tab lines and 5 space lines
>> math_geo_cgo/modevectors.py has 160 tab lines and 2 space lines
>> structural_biology_scripts/DynoPlot.py has 82 tab lines and 27 space lines
>> structural_biology_scripts/Rotamers.py has 86 tab lines and 22 space lines
>> structural_biology_scripts/kabsch.py has 51 tab lines and 4 space lines
>>
>> Second, there are files where the indenting inside a line switches
>> back and forth (numbers are the counts of lines that have both tabs
>> and spaces in indenting):
>> Objects_and_Selections/color_objects.py: 19
>> ThirdParty_Scripts/WFMesh.py: 29
>> ThirdParty_Scripts/transform_odb.py: 6
>> math_geo_cgo/modevectors.py: 12
>> structural_biology_scripts/DynoPlot.py: 83
>> structural_biology_scripts/Rotamers.py: 86
>> structural_biology_scripts/kabsch.py: 1
>>
>> I've tried using pindent.py (
>> http://svn.python.org/projects/python/trunk/Tools/scripts/pindent.py )
>> and PythonTidy ( http://pypi.python.org/pypi/PythonTidy/ ) to
>> generally fix these, but they both run into problems.  Is there a
>> general solution out in the python world to automatically fix this?  I
>> don't care whether it produces tabs or spaces.  I just want one or the
>> other.  If someone points me to something, I'm more than willing to
>> run it on these scripts, push them back to github and copy them back
>> onto the wiki.
>>
>> -David
>>
>> ------------------------------------------------------------------------------
>> The Planet: dedicated and managed hosting, cloud storage, colocation
>> Stay online with enterprise data centers and the best network in the business
>> Choose flexible plans and management services without long-term contracts
>> Personal 24x7 support from experience hosting pros just a phone call away.
>> http://p.sf.net/sfu/theplanet-com
>> _______________________________________________
>> PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
>> Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
>> Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net
>>
>
>
>
> --
> Jason Vertrees, PhD
> PyMOL Product Manager
> Schrodinger, LLC
>
> (e) jason.vertr...@schrodinger.com
> (o) +1 (603) 374-7120
>
> ------------------------------------------------------------------------------
> The Planet: dedicated and managed hosting, cloud storage, colocation
> Stay online with enterprise data centers and the best network in the business
> Choose flexible plans and management services without long-term contracts
> Personal 24x7 support from experience hosting pros just a phone call away.
> http://p.sf.net/sfu/theplanet-com
> _______________________________________________
> PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
> Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
> Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net
>

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net

Reply via email to