By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,965 Members | 1,962 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,965 IT Pros & Developers. It's quick & easy.

Hex editor - Python beginner's code open to review

P: n/a
CC
Hi:

http://web.newsguy.com/crcarl/python/hexl.py

This is my first Python program other than tutorial code snippet
experimentation. I chose a hex line editor. I may do a hex screen
editor once this is done, if I feel like playing with the curses module.
Or move straight to wxPython.

This is unfinished, and is really just a hex viewer at this point. It
seems like a good point to stop and see what others think. I would be
interested to hear any comments.

My command parsing if of course crude, brute-force, and not very
scalable. I am doing some reading on this subject, and will be trying
to do a more generalized approach in the next revision. This is going
to be a subject where I need to learn a lot, because I have 2-3
embedded applications in C that need varying levels of command parsers,
so I will be seeking to improve this skill considerably.

Thanks for input.

--
_____________________
Christopher R. Carlen
cr***@bogus-remove-me.sbcglobal.net
SuSE 9.1 Linux 2.6.5
Aug 11 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Aug 10, 10:36 pm, CC <cr...@BOGUS.sbcglobal.netwrote:
Hi:

http://web.newsguy.com/crcarl/python/hexl.py

This is my first Python program other than tutorial code snippet
experimentation. I chose a hex line editor. I may do a hex screen
editor once this is done, if I feel like playing with the curses module.
Or move straight to wxPython.

This is unfinished, and is really just a hex viewer at this point. It
seems like a good point to stop and see what others think. I would be
interested to hear any comments.

My command parsing if of course crude, brute-force, and not very
scalable. I am doing some reading on this subject, and will be trying
to do a more generalized approach in the next revision. This is going
to be a subject where I need to learn a lot, because I have 2-3
embedded applications in C that need varying levels of command parsers,
so I will be seeking to improve this skill considerably.

Thanks for input.

--
_____________________
Christopher R. Carlen
cr...@bogus-remove-me.sbcglobal.net
SuSE 9.1 Linux 2.6.5
Looks like mostly clean code to me. I don't understand why you declare
"Offset" globally twice. Wouldn't it make more sense to just stick it
at the top of the file like your "Hexdigits" variable? I'm also not
sure if your style follows the style guide...then again, mine probably
doesn't either. You can check it out here though:

http://www.python.org/doc/essays/styleguide.html

Rather than using if/else statements for error checking, you may want
to consider using try/except:

http://docs.python.org/tut/node10.html

That my 2!

Mike

Aug 13 '07 #2

P: n/a
ky******@gmail.com wrote:
On Aug 10, 10:36 pm, CC <cr...@BOGUS.sbcglobal.netwrote:
>Hi:

http://web.newsguy.com/crcarl/python/hexl.py

This is my first Python program other than tutorial code snippet
experimentation. I chose a hex line editor. I may do a hex screen
editor once this is done, if I feel like playing with the curses module.
Or move straight to wxPython.

This is unfinished, and is really just a hex viewer at this point. It
seems like a good point to stop and see what others think. I would be
interested to hear any comments.

My command parsing if of course crude, brute-force, and not very
scalable. I am doing some reading on this subject, and will be trying
to do a more generalized approach in the next revision. This is going
to be a subject where I need to learn a lot, because I have 2-3
embedded applications in C that need varying levels of command parsers,
so I will be seeking to improve this skill considerably.

Thanks for input.

--
_____________________
Christopher R. Carlen
cr...@bogus-remove-me.sbcglobal.net
SuSE 9.1 Linux 2.6.5

Looks like mostly clean code to me. I don't understand why you declare
"Offset" globally twice. Wouldn't it make more sense to just stick it
at the top of the file like your "Hexdigits" variable? I'm also not
sure if your style follows the style guide...then again, mine probably
doesn't either. You can check it out here though:

http://www.python.org/doc/essays/styleguide.html
Nowadays the standard for Python style is PEP 8, which represents an
update on the above.

http://www.python.org/dev/peps/pep-0008/
Rather than using if/else statements for error checking, you may want
to consider using try/except:

http://docs.python.org/tut/node10.html

That my 2!
"if" statements are best if the errors are predictable, "try/except"for
the less predictable ones, or when it would be difficult to ensure
correct program flow with "if".

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Aug 13 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.