0
It would be possible to use the informed data in a variable in some other function other than the chdir() module AS python?
I realized that it is not possible to use variables in the exchange of directories using this method. Would another of type? (can be from another module including).
The idea would be like this:
import os
def mudardir():
a = 'Python'
os.chdir('C:/Users/','a','diretoriob')
mudardir()
As I do not know what is the username and variable of Windows itself %userprofile% is not accepted by the method, so I thought of setting earlier to later use within the function!
I am grateful for everyone’s attention!
"I realized that it is not possible to use variables in the exchange of directories using this method." <- Can you tell where you got this conclusion? In addition, your use of the method
os.chdir
does not seem to be correct. This function takes only one argument, but you are passing three.– Pablo Almeida
You’re actually getting three arguments because I added the "a" variable in the middle there to explain the idea of how I’d like it to stay. Otherwise there would be only one ('C:/Users/Python/directory') that is correct...
– Matheus Oliveira.
In fact I was able to solve the problem. I was able to use the variable data by passing it as a parameter in the function!
– Matheus Oliveira.
So what is 'a'? It is the parent directory of the directory?
– Pablo Almeida
Right. Put your solution as an answer.
– Pablo Almeida
Exactly. But in my script in some cases I would not know the name of this parent directory, so before using the method os.chdir I would need to inform in a variable what would be the name of it... Then there arose the doubt of how I would add a variable in the argument, since the method accepts only one, and with the use of the variable would be more than one.
– Matheus Oliveira.
"Right. Put your solution as an answer." -> I’m a beginner here at SOF. How can I inform the solution? Just answer my own topic?
– Matheus Oliveira.
Just swap the commas for + and take the quotes from 'a'. Yes, you can answer your own question as if it were someone else’s.
– Pablo Almeida