python-win32com excel com model started generating errors

I had the same issue and I resolved it by following the instructions here: https://mail.python.org/pipermail/python-win32/2007-August/006147.html Deleting the gen_py output directory and re-running makepy SUCCEEDS and subsequently the test application runs OK again. So the symptom is resolved, but any clues as to how this could have happened. This is a VERY long running application (think … Read more

Python Assign value to variable during condition in while Loop [duplicate]

2020 answer: Since Python 3.8, the “walrus operator” := exists that does exactly what you want: while data := fgetcsv(fh, 1000, “,”) != False: pass (if that fgetcsv function existed) 2013 answer: You can’t do that in Python, no assignment in expressions. At least that means you won’t accidentally type == instead of = or … Read more

Understanding the Python with statement and context managers

The contextlib.contextmanager function decorator provides a handy way of providing a context manager without the need to write a full-fledged ContextManager class of your own (with __enter__ and __exit__ methods, so you don’t have to remember the arguments to the __exit__ method, or that the __exit__ method must return True in order to suppress the … Read more

Pandas: Change day

You can use .apply and datetime.replace, eg: import pandas as pd from datetime import datetime ps = pd.Series([datetime(2014, 1, 7), datetime(2014, 3, 13), datetime(2014, 6, 12)]) new = ps.apply(lambda dt: dt.replace(day=1)) Gives: 0 2014-01-01 1 2014-03-01 2 2014-06-01 dtype: datetime64[ns]

Python – How to concatenate to a string in a for loop? [duplicate]

That’s not how you do it. >>> ”.join([‘first’, ‘second’, ‘other’]) ‘firstsecondother’ is what you want. If you do it in a for loop, it’s going to be inefficient as string “addition”/concatenation doesn’t scale well (but of course it’s possible): >>> mylist = [‘first’, ‘second’, ‘other’] >>> s = “” >>> for item in mylist: … … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)