m_from_space wrote: ↑Wed Jul 13, 2022 1:17 pm
This feels a bit blasphemous, even though I am an atheist.
Variable names have no "language". It's just common to use English in the western world, so other programmers are able to read your code. I guess you refer to using character sets as part of variable names. Python2 supports only ASCII characters for variable names. Python3 supports unicode symbols. It's still not adviced to use random unicode characters if others should be able to use your code or whatever. Now of course you can use cyrillic letters for your variables, nobody will care.
But what's your goal here anyway? Variable names are things for programmers, compilers translate them into some memory addresses and forget about them (usually). Interpreters on the other hand may use them.
If you want to use another person's class and that class has some weird unicode letters as part of variable names, maybe just write a class, that copies the former one using your own variable names.
Maybe what you're doing here is way out of my scope, that's possible too.
Sorry for answering so late. There was no notification and I didn't know that someone had answered the question. So I checked myself.
"But what's your goal here anyway? "
Since I don't know Python very well yet, I can't use complex and unknown approaches. But I need to move, experiment and practice. At the moment, I already got into a dead end so many times and spent 2-3 days on solving one problem. So most of the time I'm stuck in one place. I wanted to at least temporarily solve the issue of displaying the necessary attributes and their values in the required language, move further in terms of writing code, and if anything, return to the problem of using Cyrillic in variables later, when I gain experience and knowledge.
Sometimes I have to use things like:
Code: Select all
buttion:
text class_attr_translate[list(current_class_name.__dict__.keys())[i]]
But this does not completely solve my problems. This is just a temporary crutch. I want to skip it at least temporarily. In addition, such lines are poorly readable and not intuitive.
I asked this question on another site, and there I was advised to either use a dictionary or use the language I need in the variable name.
The second option is very convenient and solves a lot of problems. Yes, I understand about code that other programmers will probably read, and that it's good practice to write variable names and function declarations using an international language. I fully support this. This is the correct approach. But I'm working on my own game alone, and not on a program that may become quite famous in the future. I just can't imagine what would have to happen for someone from another country to be interested in this code. This is extremely unlikely. Most likely only I will see this code. I don't have any other predictions.
"Interpreters on the other hand may use them."
Yes, that worried me too. I do not believe in myself and in my abilities, so I do not look so far into the future. But you are right. In this case, it's really better to stick to one language, because that will make translation impossible or very difficult.
"If you want to use another person's class and that class has some weird unicode letters as part of variable names, maybe just write a class, that copies the former one using your own variable names."
This is a good idea. I don't know how to implement it yet, but the idea is good. Thank you. I assume you mean something like this:
Code: Select all
class Person:
def__init__(self, name)
self.name = name
class Translate(Person):
def __init__(self):
super().__init__()
"Maybe what you're doing here is way out of my scope, that's possible too."
Anyway, you helped me a lot. You have answered the question and some advice. Thank you.