Skip to main content
Multi-line string literals
Source Link
200_success
  • 145.7k
  • 22
  • 191
  • 481

Python supports string literals and multi-ling stringsline string literals. You could use those instead of using a list to encode your state image.

a = a = r""" 'hello' \n
  more """
print a

You have multiple methods called set_XXX() that return values instead of storing a value. The names of these methods could be changed to better describe what they are doing.


Wordlist.new_word() will continue to iterate over the entire file even after the selected word is found. Putting the return where you create the word variable will break the loop once you have the value you want.


Wordlist uses a hard coded string for the file name, that is specified in two different places. If you want to change to a different file, you have to remember to change both cases. This is a simple example, that may seem trivial, but this type of error is hard to track down when the code becomes larger and more complicated.

Python supports string literals and multi-ling strings. You could use those instead of using a list to encode your state image.

a = a = r""" 'hello' \n
  more """
print a

You have multiple methods called set_XXX() that return values instead of storing a value. The names of these methods could be changed to better describe what they are doing.


Wordlist.new_word() will continue to iterate over the entire file even after the selected word is found. Putting the return where you create the word variable will break the loop once you have the value you want.


Wordlist uses a hard coded string for the file name, that is specified in two different places. If you want to change to a different file, you have to remember to change both cases. This is a simple example, that may seem trivial, but this type of error is hard to track down when the code becomes larger and more complicated.

Python supports multi-line string literals. You could use those instead of using a list to encode your state image.

a = r""" 'hello' \n
  more """
print a

You have multiple methods called set_XXX() that return values instead of storing a value. The names of these methods could be changed to better describe what they are doing.


Wordlist.new_word() will continue to iterate over the entire file even after the selected word is found. Putting the return where you create the word variable will break the loop once you have the value you want.


Wordlist uses a hard coded string for the file name, that is specified in two different places. If you want to change to a different file, you have to remember to change both cases. This is a simple example, that may seem trivial, but this type of error is hard to track down when the code becomes larger and more complicated.

Source Link
unholysampler
  • 6.2k
  • 19
  • 31

Python supports string literals and multi-ling strings. You could use those instead of using a list to encode your state image.

a = a = r""" 'hello' \n
  more """
print a

You have multiple methods called set_XXX() that return values instead of storing a value. The names of these methods could be changed to better describe what they are doing.


Wordlist.new_word() will continue to iterate over the entire file even after the selected word is found. Putting the return where you create the word variable will break the loop once you have the value you want.


Wordlist uses a hard coded string for the file name, that is specified in two different places. If you want to change to a different file, you have to remember to change both cases. This is a simple example, that may seem trivial, but this type of error is hard to track down when the code becomes larger and more complicated.