I made a SHA256SUM-Checker-for-Windows, need help! #21481
-
This is how my [SHA256SUM-Checker-for-Windows] works. Step 3: Then user needs to delete unnecessary part by themself. Step 4: Open hash.exe which is a command line application. Then the user needs to input the file name. Step 5: After that the program will generate the hash from the file. Step 6: Lastly, the user can copy the hash into the input field. The program will compare two hashes for you. But how can I make the program remove those unnecessary part for me? Thank you! For more screenshots please visit my repositories. GitHub gingshow/SHA256SUM-Checker-for-WindowsContribute to gingshow/SHA256SUM-Checker-for-Windows development by creating an account on GitHub. |
Beta Was this translation helpful? Give feedback.
Replies: 12 comments
-
Step 2: The user needs to open SHA256SUM.txt manually. how can I make the program remove those unnecessary part for me? Thank you! For more screenshot please visit my repositories. Here is my code: gingshow/SHA256SUM-Checker-for-Windows/blob/master/dist/hash.py
This file has been truncated. show original |
Beta Was this translation helpful? Give feedback.
-
gingshow:
Each line in the SHA-256 sums file has the hash, then spaces, then the filename. You can split that using a regular expression with two capturing groups. One thing to consider is how to find the right file(s) in that list. A common approach would be to expect the files in the list exist and have the same name on the local system, and to check them all (nonexistent files get an error message). The A few other things I’m thinking of reading that code:
|
Beta Was this translation helpful? Give feedback.
-
Thank you very much. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your suggestion! gingshow/SHA256SUM-Checker-for-Windows/blob/acd4ed46cb6fa078fba2a87dd8f1e616520a46e4/dist/hash.py
This file has been truncated. show original |
Beta Was this translation helpful? Give feedback.
-
I’m sorry to say, but that won’t work at all: The code now checks if the hash entered by the user is the same as the last hash in the What I meant is to use a regular expression (using Python module
Then for each I couldn’t resist completing the example above myself, if you’d like to see the result look here: https://gist.github.com/airtower-luna/a5df5d6143c8e9ffe7eb5deb5797a0e0sha256check.py
This file has been truncated. show original
It’s pure Python, so it’ll work on any OS/platform supported by Python. |
Beta Was this translation helpful? Give feedback.
-
Hi airtower-luna when I executed your code. It got an error. Why is this happened? line 30, in |
Beta Was this translation helpful? Give feedback.
-
I did some edited on my code according to your example code. Now my program can read the checksum file without asking the user for a hash. gingshow/SHA256SUM-Checker-for-Windows/blob/e780f788ea56aad76e7213fa71dc96cb58ce033e/dist/hash.py
This file has been truncated. show original |
Beta Was this translation helpful? Give feedback.
-
gingshow:
My script expects the name of the checksum file on the command line, instead of requiring it to be named You could replace the
There are a lot more possible error conditions, e.g the file might not exist or not have the right format. As for the latest version of your script, the biggest issue is that it creates two new files ( And in situations where you really need a file to store intermediate data, use a temporary file. Python has the |
Beta Was this translation helpful? Give feedback.
-
Hey airtower-luna! Thank you very much. gingshow/SHA256-Checker/blob/8ffdfd5da76ecfe88e8537f4c305b1175300329a/dist/hash.py
This file has been truncated. show original |
Beta Was this translation helpful? Give feedback.
-
Nice, those extra files are gone now. 🙂 From a user point of view I’d still wonder why you need to ask for a filename when all the names are right there in the checksum file. From my technical point of view I’m wondering: Why aren’t you using regular expressions to read the checksum file? 🐱 |
Beta Was this translation helpful? Give feedback.
-
Thank you 😀 Q: From a user point of view I’d still wonder why you need to ask for a filename when all the names are right there in the checksum file. Q: From my technical point of view I’m wondering: Why aren’t you using regular expressions to read the checksum file? This is my new SHA256-Checker repository location. Thank you! gingshow/SHA256-CheckerA simply SHA256-Checker written in Python. Contribute to gingshow/SHA256-Checker development by creating an account on GitHub. |
Beta Was this translation helpful? Give feedback.
-
gingshow:
Valid! 😄 I’d still recommend learning about them soon, they’re extremely useful for a lot of common programming problems, and this would be a good opportunity. And I still think it’d be much more user-friendly to just verify all files listed in the checksum file than asking the user to type one of them. 😉 |
Beta Was this translation helpful? Give feedback.
Each line in the SHA-256 sums file has the hash, then spaces, then the filename. You can split that using a regular expression with two capturing groups. One thing to consider is how to find the right file(s) in that list. A common approach would be to expect the files in the list exist and have the same name on the local system, and to check them all (nonexistent files get an error message). The
pathlib
module might be helpful with handling file names.A few other things I’m thinking of reading that code: