I\'m working on my python script to get the 12 hours time.
I want to get the 7 hour instead of 07.
self.getControl(4203).setLab
You can use lstrip to remove a given character from the left side of the result (if it exists):
hour = time.strftime("%I").lstrip('0')
print(hour)
As Derek mentions in his answer, you can strip leading zeros for a more portable solution.
>>> print(time.strftime("%I").lstrip('0'))
2
If you are on a Linux platform that uses glibc though, you have a few additional options.
Use %l. Notice that this leaves has a space at the beginning, in place of the 0:
>>> print(time.strftime("%l"))
2
Use %-I. This does not have the leading 0 or leading space.
>>> print(time.strftime("%-I"))
2
These two options work on Linux systems that use glibc, because Python uses the strftime() from that library.