0
I have a date of birth where I need the program to read the information and enter the day, month and year using pyautogui. For the WRITE function to work, I need to transform the date, which is an integer, into an str. The place where I need to enter these dates, have 2 digits: 01, 02, 03... 14... 30 and 31. When the str has 2 digits (from 10 below) the program runs smoothly and type the dozens without problems, but when the date becomes with 1 digit, it prints only one house and can not type the 06, for example and typing only 6 not the.
> > import datetime
import pyautogui
> >
> > data_atual = datetime.datetime.now()
day = data_atual.day day =
> > str(day)
> >
> > pyautogui.write(day) # nesse caso imprime 24 pq hj é 24 mas em dias 1,2,3...9 eu tenho problemas.
The pyautogui does not print integer numbers, so there is a need to transform the integer number into one str, but complicates it into 1-digit numbers only. One solution I found to fix this was to include an IF for every result from 1 to 9:
> if day == '1':
> pyautogui.write('01')
elif day == '2':
> pyautogui.write('02')
.
.
.
elif day == '9':
> pyautogui.write('09') else:
> pyautogui.write(day)
I would like something simpler to insert a 0 in Sting day when it had only 1 digit without having to use as many command lines as in if. The insertion of 0 must come forward to transform 1, 2, 3... in 01, 02, 03...
Another solution I found was:
if day <= '9':
day = ('0' + day)
else:
day = day
Speechless... unlocked me again... did not know this documentation...helped a lot! I will start looking at this now and I will take a course!... vlw
– G̶e̶r̶a̶l̶d̶o̶ J̶u̶n̶i̶o̶r̶