0

I generated a hash value for a file in python. The value consists of both characters and numbers. If i check the data type of each value, it is showing as string for both letters and numbers. How do I convert the data type of numbers from string to int?

Thanks in Advance!

    import hashlib
    myl = []
    fobj = open('akash.txt','r')
    buffer = fobj.read()
    hsh = hashlib.sha512()
    hsh.update(buffer.encode('utf-8'))
    val = hsh.hexdigest()
    for i in val:
             print(type(i))
    fobj.close()

The hash value generated by the code is:

cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e

I expect the output to be as

    <class 'str'>
    <class 'str'>
    <class 'int'>
    ...

But this is the output Im getting

    <class 'str'>
    <class 'str'>
    <class 'str'>
    ...

1 Answer 1

1

I truly have no idea why you would want to do this, but you can try if you can convert a character in the hash string to an integer first and then print the type. Just change your loop as follows

for i in val:

    try:
        n = int(i)

    except ValueError:
        n = i

    print(f'character: {n} is {type(n)}')
Sign up to request clarification or add additional context in comments.

1 Comment

Or just for i in val: print(i, i.isnumeric())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.