Re: Checking for valid date input and convert appropriately

2013-02-21 Thread rob . marshall17
The datetime function: strptime() DOES check the date for validity. So try something like: from datetime import datetime def get_date(): while True: try: date_in = raw_input("Enter date (dd mm ): ") date_out = datetime.strptime(date_in,"%d %m %Y").strftime("%Y-%m-%d")

Re: Can I Import table from txt file into form letter using Python?

2013-02-21 Thread rob . marshall17
Using the data you supplied as is, you could try something like: def print_cities(filename): # cnt is used just to know if it's time for a newline cnt = 0 cities = open(filename,'r').readlines() for city in cities: # Make sure we have a valid population if re.match('\d+$',city.spli