It is better to follow PEP8 which says that import statements, such as in your case, should use multiple lines:
import re import randomWhatever the programming language you use, it is better to avoid input/output operations whenever you can. So instead of storing the countries' names in a text file, you can choose a suitable Python data structure for the purpose.
When someone reads your main program, he must straightforwardly knows what it is doing. It is not the case with your main.py file where I see lot of distracting information and noise. For example, you should save all those constants in a separate module you may call configurations.py, cfg.py, settings.py or whatever name you think it fits into the your project's architecture.
Choose meaningful names: while most of the names you chose are edible, I believe you still can make some improvements for few of them. That is the case, for example, of
nameFilewhich is too vague and does not bring any information apart from the one of the assignment operation itself:nameFile = "names.txt". Sure it is a name of a file, but only after reading your program's statement that one can guess what you would mean bynameFileand start to suggest you right away a more suitable and informative name such ascountries_names. Note in my suggestion there is not the container's name. I mean, I am not pushing the reader of your code to know programming details such as whether you stored the information in a file or this or that data structure. Names should be "high level" and independent from the data structure they represent. This offers you the advantage not to spot the same name in your program to re-write it just because you changed the store data from a file to an other data structure. This also applies tosyllableRgx: for sure when someone readssyllableRgx = re.compile(r"...")he understands you are storing the result of a regex expression. But you should change this name to something better for the reasons I explained just before.You should follow the standard naming conventions. For example,
syllableCountsandsegmentDatashould be writtensyllable_countsandsegment_datarespectively.I want to use camelCase No. When develop in a given programming language, adopt its spirit and philosophy. It is like when you join a new company's developer team: adapt yourself to themselves, and do not ask them to adapt themselves to your habits and wishes.