Pergunta

Can you please help me guys. I believe I've got pretty easy questions but don't want to stuff up with my assignment. I'm going to have Class in my module, this class will have few functions.

I just want to be sure it works alright and this is a not ugly code practice. I.e. my first function test_info accepts one parameter test_code and returns something and the second function check_class accepts two parameter, one of them is called test_code as well

Can I use same argument name: test_code? Is it normal code practice?

 def test_info (self, test_code):
   my_test_code = test_code
   #here we'll be using my_test_code to get info from txt file and return other info


 def check_class (self, test_code, other_arg):
   my_test_code = test_code
   #here some code goes

Also is it fine to use my_test_code in both functions to get argument value or is it better to use different ones like my_test_code_g etc.

Many thanks

Foi útil?

Solução

Yes you may.

The two variables test_code are defined only in the scope of their respective functions and therefore will not interfere with one another since the other functions lie outside their scope.

Same goes for my_test_code

Read online about variable scopes. Here is a good start

Outras dicas

There is no technical reason to resolve this one way or another. But if the variables don't serve exactly the same purpose in both functions, it's confusing for a human reader if they have the same name.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top