I haven't done any real Python code since I started messing with Shell Scripting in January 2012 when I started AudioScope.
Well I fished a little project out of my ANCIENT AMIGA files which created a raw hexdump of any binary file within reason for a stock A1200(HD).
Well although there was Python 1.4.0 to 2.0.1 for the classic AMIGA I could only use version 1.4.0 as this did not require an MMU or FP hardware for use.
Well the other day I decided to make it totally platform independent AND version independent and this is the result...
This task WAS difficult to do but the learning curve was worth the effort.
Boy oh boy have I forgotten a lot about Python...
Code:
# hexdump.py
#
# Original idea, (C)2006-2016, B.Walker, G0LCU.
# Issued as Creative Commons CC0 licence.
# Modified to suit _all_ versions of python.
#
# exec(open("Full path to hexdump.py").read())
# For all versions OR...
# execfile("Full path to hexdump.py")
# ...for versions 2.x.x and below.
# Works from Python 1.4.0 to 3.5.2 without modification.
#
# IMPORTANT! There is NO error checking in this code. It relies entirely
# on Python's own tracebacks for user and/or programming errors.
#
# Tested on:-
# 1) Classic AMIGA A1200(HD), with Python, 1.4.0 to 2.0.1.
# 2) Windows 8.1, with Python, 2.7.9 and 3.4.3.
# 3) OSX 10.7.5, OSX 10.11.6, with Python 2.5.x, 2.6.x, 2.7.x and 3.5.2.
# 4) Ubuntu 16.04, 64 bit, with Python 2.7.11 and 3.5.1.
#
# Obviously there are versions missed out as I no longer have them,
# but suffice it to say that this was written around an AMIGA 10 years ago
# so I decided to make it universal recently and issue as a fun project...
import sys
if sys.version[0]=="3": raw_input=input
filename=raw_input("Full path and filename, then press ENTER:- ")
binary=open(filename,"rb+")
length=len(binary.read())
array=""
for position in range(0,length,1):
binary.seek(position)
char=binary.read(1)
char=hex(ord(char))
char=char[2:]
if len(char)<=1: char="0"+char
# Remove the whitespace for a pure hex-string.
# array=array+char
array=array+char+" "
binary.close()
# Create a pseudo-array, whitespace delimited, this line can be ommitted.
# Bending the rules of print as a statement and as a function here. ;o)
print("%s" %(array))
# Save the text _hex_ dump as the original filename with the '.hex' etension.
# In this specification the HEX file length should be exactly 3 times the size
# of the original binary file length. It is deliberately whitespace delimited.
filename=filename+".hex"
hexadecimal=open(filename,"w")
hexadecimal.write(array)
hexadecimal.close()
Hi all...
As you know I like making code backwards compatible for as many platforms as possible.
This Python script was in fact dedicated for the AMIGA A1200 using Pythons 1.4.0, 1.5.2, 1.6.0, 2.0.1, and 2.4.6 as that is all we have for varying levels of upgrades from a HDD and 4MB FastRam... (1 Reply)
Hi all,
I am trying to run below python code for connecting remote windows machine from unix to run an python file exist on that remote windows machine..
Below is the code I am trying:
#!/usr/bin/env python
import wmi
c = wmi.WMI("xxxxx", user="xxxx", password="xxxxxxx")... (1 Reply)
In the awk I am trying to subtract the difference $3-$2 of each matching $4 before the first _ (underscore) and print that value in $13.
I think the awk will do that, but added comments. What I am not sure off is how to add a line or lines that will add sum each matching $13 value and put it in... (2 Replies)
Hi guys...
Sometime ago I said I was going to attempt an Android project.
I got my phone for XMAS and after installing a terminal program I realised how limited the command line is.
I do NOT intend to __root__ the phone at this point but I can read and write to certain folders.
The biggest... (14 Replies)
I am working on requirement on spreadsheet in python scripting.
I have a spreadsheet containing cell values and with background color.
I am able to read the value value but unable to get the background color of that particular cell.
Actually my requirement is to read the cell value along... (1 Reply)
Okay, so I have had this problem on openSUSE, and Debian systems now and I am hoping for a little help. I think it has something to do with Python but I couldn't find a proper Python area here.
I am trying to redirect the output of "ssh suse-server 'python -V'" to a file. It seems that no matter... (3 Replies)
I think both write at the end of the file ......
but is there a sharp difference between those 2 instruction .....
thank you
this is my 3rd question today forgive me :D (1 Reply)
Hello,
Is there some type of functional way to read things in the Python shell interpreter similar to less or more in the bash (and other) command line shells?
Example:
>>> import subprocess
>>> help(subprocess)
...
...
I'm hoping so as I hate scrolling and love how less works with... (0 Replies)