Timeline for Script for creating custom hosts files
Current License: CC BY-SA 3.0
6 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jul 7, 2015 at 23:51 | comment | added | TessellatingHeckler |
NB. that "return match" isn't doing the same thing; match is a regex match object, not a boolean. return True if match else False is a neater way to convert it to a boolean in one line of Python where that matters. It doesn't exactly matter in your code, but it might in general. (But the return ('0.0.0.0' in line ... version is even neater.
|
|
Jul 7, 2015 at 20:27 | comment | added | alexwlchan |
@amt528 The “import os” thing is a mistake; I was using the os module in the hosts_file line, but I removed it and forgot to take out the import. In general, I put imports that are exclusive to the main() function within the function, just to keep them distinct from the rest of the code – I think of main() as a distinct block.
|
|
Jul 6, 2015 at 23:05 | comment | added | user77310 | Also, could you explain why import os should go in main? And based on your suggestions, should my function to make the host file have directory as a second parameter? | |
Jul 6, 2015 at 18:41 | comment | added | alexwlchan | @amt528 Ah yes, I’d missed the caret. As for your second question… um, that might be a mistake on my part. Oops, you can drop the “not”s. | |
Jul 6, 2015 at 18:28 | comment | added | user77310 | Thanks for all your help and input. I really appreciate it. I don't think I can just check for 0.0.0.0 or 127.0.0.1 within a line, because sometimes the hosts-file author comments out a block-rule due to issues. So that would return false positives. But I can use startswith(). One other question: why would "return ('0.0.0.0' not in line) and ('127.0.0.1' not in line)" be preferable to "return ('0.0.0.0' in line) or ('127.0.0.1' in line)"? | |
Jul 6, 2015 at 17:18 | history | answered | alexwlchan | CC BY-SA 3.0 |