Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (19.9k points)

I have a Python code in which I am using useruser as my username:

zipfolder('shared-photo.zip', 'C:\Users\useruser\company\folder-images') 

How can I update this code to get the logged-in username?

For example this is what I tried:

myuser = os.popen("echo %username%").read().replace("\n","")

...and then when I print myuser, I get the right username:

print(myuser)

How can I use this variable in my code, instead of useruser?

1 Answer

0 votes
by (25.1k points)

You can do in 2 ways:

E.g. 1: concatenation - zipfolder("tgs-stealed", "C:\Users\\" + myuser + "\company\folder-images")

2. String format() - zipfolder("tgs-stealed", "C:\Users\{}\company\folder-images".format(myuser))

Related questions

0 votes
1 answer
0 votes
2 answers
asked Sep 12, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Jun 22, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...