Hi,
I too got the indent problem when importing scripts with tabs not set to 4
spaces.
My solution: rewrite the script with correct indentation with this snippet:
<code>
import os, re, shutil
import pn
def _file(root, filename):
return os.path.join(root, filename)
root = r'E:\dev\python\wx scripts'
filename = 'exemple.py' # script with "wrong" indentation
filename = _file(root, filename)
# prevent overwriting backup file
assert not os.path.exists(filename+'.bak'), 'Backup file exists already.
What we do now?'
src = pn.file_get_contents(filename).splitlines()
new = []
first, indent = True, 0
for line in src:
try:
spaces, code = re.findall('^(\s+)(.*)', line)[0]
# the first indentation gives the number of whitespaces for each
indentation
if first:
indent = spaces.count(' ')
first = False
line = ' ' * (len(spaces)/indent * 4) + code
except IndexError:
if re.match('^\t.*', line):
line = re.sub('\t', '\s'*4, line) ## not tested but should work
finally:
new.append(line)
shutil.copy2(filename, filename+'.bak')
pn.file_put_contents(filename, '\n'.join(new))
</code>
Of course if you use indentation != 4 you'll change the 4 in the script.
I'll let it up to you to replace my pn.file_xxx_contents() functions to
anything that does the job of reading/writing to a file.
BTW, I'm a user of PyScripter.
> --
> You received this message because you are subscribed to the Google Groups
"PyScripter" group.
> To unsubscribe from this group and stop receiving emails from it, send an
email to
pyscripter+...@googlegroups.com.
> To post to this group, send email to
pyscr...@googlegroups.com.
> Visit this group at
http://groups.google.com/group/pyscripter?hl=en.
> For more options, visit
https://groups.google.com/groups/opt_out.
>
>
>
>