account name in PyGithub

I am using the package PyGithub in order to try and automate the creation of a new github repo.

from github import Github

g = Github(token)
user = g.get_user()
repo = user.create_repo(name)

After creating that repo I am creating a local one too, and simply try link them.

One of the commands I need to execute is git remote add origin [email protected]:<AccountName>/<RepoName>.git

I don't want to hard-code my account name into this script so I am trying to get that name from the Github package.
Apparently, on github, I have two 'user names' - one of them is the profile name and the other one is the account name.
When I execute user.name I get my profile name and not my account name which I need.

Is there anyway to get that account name specifically?

Answers

Looking around in the documentation I found that you can get the login name like this:

from github import Github

g = Github(token)
user = g.get_user()

print(user.login)
#OUTPUT: my_username


Posted on by Carlo Zanocco