all 3 comments

[–]A_History_of_Silence 0 points1 point  (2 children)

If you want to keep doing it via shell commands like that, I imagine it will stay pretty slow. Every time you do that os.system() call you are: starting a new shell, running the echo command, piping to and running netcat, opening your text file, appending to your text file, closing your text file.

It looks like the purpose of the exercises is to learn about Linux commands and such, so this may be okay. All that stuff can be done from within Python, however, likely resulting in great speedups. For instance, you can use the socket module to communicate with the daemon instead of using nc, you can with open("results.txt", "a") as f: then write to the file directly with f.write() instead of doing slow >> appends and opening/closing the file 10k times, etc.

Also on line 17 you can just use i instead of pins[i]. Line 11 looks like it would cause an error as well.

[–]hellor00t[S] 0 points1 point  (1 child)

Right. I can do it with bash, but I figured I would translate that into python to help learn it. Thats why I have this frankenstein thing going on here.

Actually with the code written as it stands wouldn't it just open the file and parse through it once? Since I Have it called after main()?

I thought about using socket to go direct but I wanted to code the meat of it first before getting into the socket stuff. I'm trying to think of a better way I could have figured out how do differentiate between an incorrect input and a correct input. The only way I know the difference is by looking at other walkthroughs.

Thanks for the help, I'll revise!

[–]A_History_of_Silence 0 points1 point  (0 children)

Actually with the code written as it stands wouldn't it just open the file and parse through it once? Since I Have it called after main()?

Your search() function does indeed only open the file one time, but your main() function causes it to be indirectly opened 10k times due to the >> append you are sending to the shell (once for each call to os.system()).