I am creating the fields with pass and class name, as it is important to name like this, so i could not make it as it is not allow in python to use keyword as a variable, what should i do to bypass keywords as variable or any other solution to make it.
username = fields.Text(string='Username')
pass = fields.Text(string='Password')
reply = fields.Text(string='Reply')
calledstationid = fields.Text(string='Called Station ID')
callingstationid = fields.Text(string='Calling Station ID')
authdate = fields.Datetime(string='Auth Date')
class = fields.Text(string='Class')
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Comptabilité
- Inventaire
- PoS
- Project
- MRP
Cette question a été signalée
You cannot use overwrite Python's keywords. This is a built-in protection of the language to prevent confusion and potential catastrophic errors. Attempting to overwrite a keyword would result in a SyntaxError: SyntaxError: invalid syntax
But why is it so important to use these names? Because, even if it was possible it would be bad practice to overwrite existing keywords. Moreover, the variable names are only used in the backend and database and you can modify, with the string parameter, how they look on the frontend. Alternatively, you could add an underscore to the variable names (e.g., class_ = field.Text())
I hope this helps
In Python, certain keywords like pass and class are reserved and cannot be used as variable names. To bypass this restriction, you can add an underscore (_) or a prefix to your variable names. Here's an example of how you can modify your code to overcome this issue:
username = fields.Text(string='Username')
password = fields.Text(string='Password')
reply = fields.Text(string='Reply')
called_station_id = fields.Text(string='Called Station ID')
calling_station_id = fields.Text(string='Calling Station ID')
auth_date = fields.Datetime(string='Auth Date')
class_name = fields.Text(string='Class')
In this code, I have added underscores or changed the variable names slightly to avoid using reserved keywords. By doing so, you can use meaningful names for your fields without conflicting with Python's keywords.
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !
Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !
S'inscrirePublications associées | Réponses | Vues | Activité | |
---|---|---|---|---|
|
2
févr. 24
|
1498 | ||
|
4
déc. 24
|
30556 | ||
|
1
déc. 24
|
1388 | ||
|
2
janv. 24
|
3342 | ||
|
2
janv. 24
|
2227 |