473,407 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

indentation preservation/restoration

I have (inadvertently) wiped out the functionality of my personal
python snippets by eliminating leading space. I have also just visited
http://www.python.org/tim_one/000419.html and saw a piece of code with
the indentation gone. Python code is fragile in this regard. One
solution that occurs to me is that a "indentation code" could be
appended to a script which could be used to rebuild the script if
necessary. e.g. if we let letters represent the number of spaces before
a line and numbers to indicate how many lines have that spacing, then
A2E2A1 could represent the leading space on the code,

# A Hello Program
def hi():
msg = 'hello world!'
return msg
print hi()

If the line returns are gone (as they are at the url above) then this
wouldn't work and perhaps the number of characters on each line could
be encoded as well. I'm not sure what the best way to do that would be.
I'm not sure where the best time and place to add such a coding to file
would be, however. If you do as I did to my library (anyone?) then
having the code placed at the bottom of the script as save time
wouldn't have helped in the recovery. Placing the code with scripts
that are placed on the web or archived might be smart.

Any thoughts?

/c

Jan 2 '06 #1
5 1174
sm****@gmail.com wrote:
I have (inadvertently) wiped out the functionality of my personal
python snippets by eliminating leading space. I have also just visited
http://www.python.org/tim_one/000419.html and saw a piece of code with
the indentation gone. Python code is fragile in this regard. One
solution that occurs to me is that a "indentation code" could be
appended to a script which could be used to rebuild the script if
necessary. e.g. if we let letters represent the number of spaces before
a line and numbers to indicate how many lines have that spacing, then
A2E2A1 could represent the leading space on the code,

# A Hello Program
def hi():
msg = 'hello world!'
return msg
print hi()

If the line returns are gone (as they are at the url above) then this
wouldn't work and perhaps the number of characters on each line could
be encoded as well. I'm not sure what the best way to do that would be.
I'm not sure where the best time and place to add such a coding to file
would be, however. If you do as I did to my library (anyone?) then
having the code placed at the bottom of the script as save time
wouldn't have helped in the recovery. Placing the code with scripts
that are placed on the web or archived might be smart.

Any thoughts?

/c


Usually the problem can be solved by looking at the source code of an
HTML page. The people programming Python are not always good
Web-programmer and forget to put their code into textarea or pre tags in
order to make the code pastable directly from the web page.

This seems also to be for the mentioned page the case. So go to see the
source code of the HTML page in your editor and you will get the lost
spaces.

Claudio
Jan 2 '06 #2
On Mon, 02 Jan 2006 14:19:15 -0800, smichr wrote:
I have (inadvertently) wiped out the functionality of my personal
python snippets by eliminating leading space. I have also just visited
http://www.python.org/tim_one/000419.html and saw a piece of code with
the indentation gone. Python code is fragile in this regard. One
solution that occurs to me is that a "indentation code" could be
appended to a script which could be used to rebuild the script if
necessary. e.g. if we let letters represent the number of spaces before
a line and numbers to indicate how many lines have that spacing, then
A2E2A1 could represent the leading space on the code,


What a great idea! I had a similar problem, your scheme could be adapted
to solve that too. I accidentally deleted all the numeric literals from my
Python code, and Python is fragile in this regard. So we could have a
"number code" appended to a script which could be used to rebuild the
script if necessary: e.g. a code like "E,D,CA" means the fourth token of
the fifth line is 31.

With a little bit of work, this could be expanded to add redundancy for
not just indentation and numeric literals, but also string literals,
keywords, operators, and anything else. Using compression and
error-correcting codes should mean that your Python scripts will then be
safe from absolutely anything short of deleting the entire file -- and for
that, you have backups.

--
Steven.

Jan 3 '06 #3
Steven D'Aprano wrote:
With a little bit of work, this could be expanded to add redundancy for
not just indentation and numeric literals, but also string literals,
keywords, operators, and anything else.


When I copy and assign to variable 'post' the reply posted here on
c.l.p. starting with "On Mon, 02" and ending with "- \nSteven." and run
it through the hidden() function below with the indices indicated, I
can see what you were really thinking.

The point is well taken: one must consider leading space as an
important part of the code. This is just one of those things that's so
easy to shift around, however. You don't have to work very hard with an
editor's text manipulations to lose it.

That's life. I know.
/c

###
def hidden(t,indx):
msg=[]
for i in indx:
msg.append(t[i])
return ''.join(msg)
thought=[40, 47, 51, 106, 179, 180, 181, 182, 395, 396, 399,
1129, 1143, 1194, 1224, 1225, 1226]
print hidden(post,thought)
###

Jan 3 '06 #4
I can't believe I forgot that trick :-| Thanks for the helpful
reminder.

/c

Jan 3 '06 #5
sm****@gmail.com wrote:
Steven D'Aprano wrote:

With a little bit of work, this could be expanded to add redundancy for
not just indentation and numeric literals, but also string literals,
keywords, operators, and anything else.

When I copy and assign to variable 'post' the reply posted here on
c.l.p. starting with "On Mon, 02" and ending with "- \nSteven." and run
it through the hidden() function below with the indices indicated, I
can see what you were really thinking.

The point is well taken: one must consider leading space as an
important part of the code. This is just one of those things that's so
easy to shift around, however. You don't have to work very hard with an
editor's text manipulations to lose it.

That's life. I know.
/c

###
def hidden(t,indx):
msg=[]
for i in indx:
msg.append(t[i])
return ''.join(msg)
thought=[40, 47, 51, 106, 179, 180, 181, 182, 395, 396, 399,
1129, 1143, 1194, 1224, 1225, 1226]
print hidden(post,thought)
###


The subject of spaces in Python has been discussed over and over here in
a manner which reminds sometimes of threads caused by simple trolling.

It is so easy to mix different things into one when not beeing able to
see clearly what is what. Writing code is one thing, data security is
another and compression also another thing. From the point of view of
programming it is a origin of additional efforts required when all the
aspects are mixed together into a data format which is to be processed.
It would be much cleaner and easy to understand when staying separate,
i.e. format first, than a compression scheme for it, than secure storage
media system.

The conclusion out of it?

From my point of view adding redundancy already at the level of source
code is the wrong way to go and not worth to consider.
Such efforts belong to the design of a secure storage media system or
are covered by usage of a versioning system.

Claudio
Jan 3 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tommy.Vincent | last post by:
Hi, its newbie question. I have one production server(A) ,one backup server(B),additional server(C). my database backup are moved from A to C in regular basis. My problem is that when...
0
by: Richard | last post by:
hi, I am using SQL SERVER 2000. My query is, Can I restore my 60 transactional log file backup in one sql statement,giving condition where it is suppose to start and end.
1
by: Tommy.Vincent | last post by:
Hi, When i use to work on Windows 2000 advance server and Sql 2000 I was able to do network restoration by using a mapped drive where my backup use to be lying.What i did was I assigned...
1
by: Thyagu | last post by:
Hi, Does a database restoration perform any update-statistics/defragmentation by default. We observed a marked improvement in performance when we restored the a database from an high end...
2
by: bharadwaj | last post by:
any automated restoration script is available in sql server2000. I want to do the restoration for 10 databases(full backup,latest differential backup) in other server. Pls do the needful.
0
by: bharadwaj | last post by:
Hi, I am trying to do restoration for n databases using automated script.The script is given below. it is not giving errors while job execution ,but restoration is not happening.(no record is in...
0
by: bharadwaj | last post by:
hi, i am trying to do master restoration using the following steps. 1.net stop MSSQLServer 2.sqlservr -m 3.use MASTER go RESTORE DATABASE master FROM disk='master.BAK' replace, MOVE...
1
Ali Rizwan
by: Ali Rizwan | last post by:
Hi all, I want to disable auto restoration of windows. Suppose if i delete a file say explorer.exe after a while it will create again by windows. If i change any registery it will restore...
0
by: Now You Know | last post by:
Water Damage Restoration 24 hour open 7 Days Phone 1 877 364 5264 When disaster strikes such as a washing machine overflow, bath overflow, burst pipe, rainwater from balcony etc, water damage...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.