python-3.x

How can I iterate over worksheets in win32com?

天涯浪子 提交于 2021-02-18 18:58:28
问题 I generate an xlsx file with lots of sheets and I want to take me at specific position when I open it manually with Excel. This function does the job but for one sheet only. How can I apply it to all of the sheets in workbook? import win32com.client def select_cell(): xl = win32com.client.gencache.EnsureDispatch('Excel.Application') wb = xl.Workbooks.Open(r'H:\Files\1.xlsx') ws = xl.ActiveSheet ws.Range('B100').Select() wb.Close(True) xl.Quit() select_cell() I want to make something like this

How can I iterate over worksheets in win32com?

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-18 18:56:21
问题 I generate an xlsx file with lots of sheets and I want to take me at specific position when I open it manually with Excel. This function does the job but for one sheet only. How can I apply it to all of the sheets in workbook? import win32com.client def select_cell(): xl = win32com.client.gencache.EnsureDispatch('Excel.Application') wb = xl.Workbooks.Open(r'H:\Files\1.xlsx') ws = xl.ActiveSheet ws.Range('B100').Select() wb.Close(True) xl.Quit() select_cell() I want to make something like this

Python Decimal to Binary Recursive

拜拜、爱过 提交于 2021-02-18 18:21:28
问题 I am writing a function that takes a parameter 'n' that will convert a decimal to a binary number using a recursive formula. This is what I have for a non-recursive function but I need to figure out how to write it recursively. def dec2bin(n): bStr = '' if n < 0: return 'Must be a positive integer' elif n == 0: return '0' else: bStr += str(n%2) return bStr 回答1: Think about your base case. For what inputs would it make sense to just write the answer directly into your program? 0? 1? Probably

AttributeError: 'MyMainWindow' object has no attribute 'pushButton'

江枫思渺然 提交于 2021-02-18 18:17:49
问题 Trying to proceed click button event in my code but got some issue. AttributeError: 'MyMainWindow' object has no attribute 'pushButton' Seems, like clicked event can`t find pushbutton from my subclass. Probably i did some mistakes in syntax, so really waiting for your help guys. Sorry if the question very banal, pyQt5 is simply new for me, trying to figure out in all of this. Here is my files. ui_main.py # -*- coding: utf-8 -*- # Form implementation generated from reading ui file '1.ui' # #

applying pandas cut within a groupby

谁说我不能喝 提交于 2021-02-18 18:15:15
问题 I'm trying to create bins (A_bin) within a DataFrame based on one column (A), and then create unique bins (B_bin) based on another column (B) within each of the original bins. df = pd.DataFrame({'A': [4.5, 5.1, 5.9, 6.3, 6.7, 7.5, 7.9, 8.5, 8.9, 9.3, 9.9, 10.3, 10.9, 11.1, 11.3, 11.9], 'B': [3.2, 2.7, 2.2, 3.3, 2.1, 1.8, 1.4, 1.0, 1.8,2.4, 1.2, 0.8, 1.4, 0.6, 0, -0.4]}) df['A_bin'] = pd.cut(df['A'], bins=3) df['B_bin'] = df.groupby('A_bin')['B'].transform(lambda x: pd.cut(x, bins=2)) This

How to parse deeply nested JSON to pandas dataframe?

◇◆丶佛笑我妖孽 提交于 2021-02-18 18:14:49
问题 Below is the code that parses the following nested jsons to corresponding pandas dataframe : import pandas as pd def flatten_json(nested_json): """ Flatten json object with nested keys into a single level. Args: nested_json: A nested json object. Returns: The flattened json object if successful, None otherwise. """ out = {} def flatten(x, name=''): if type(x) is dict: for a in x: flatten(x[a], name + a + '_') elif type(x) is list: i = 0 for a in x: flatten(a, name + str(i) + '_') i += 1 else:

applying pandas cut within a groupby

故事扮演 提交于 2021-02-18 18:13:39
问题 I'm trying to create bins (A_bin) within a DataFrame based on one column (A), and then create unique bins (B_bin) based on another column (B) within each of the original bins. df = pd.DataFrame({'A': [4.5, 5.1, 5.9, 6.3, 6.7, 7.5, 7.9, 8.5, 8.9, 9.3, 9.9, 10.3, 10.9, 11.1, 11.3, 11.9], 'B': [3.2, 2.7, 2.2, 3.3, 2.1, 1.8, 1.4, 1.0, 1.8,2.4, 1.2, 0.8, 1.4, 0.6, 0, -0.4]}) df['A_bin'] = pd.cut(df['A'], bins=3) df['B_bin'] = df.groupby('A_bin')['B'].transform(lambda x: pd.cut(x, bins=2)) This

center multi-line text in python output

大兔子大兔子 提交于 2021-02-18 18:06:02
问题 OK, so this seems like a really basic question, but I can't find a workable answer anywhere, so here goes. I have some text: text = ''' Come and see the violence inherent in the system. Help! Help! I'm being repressed! Listen, strange women lyin' in ponds distributin' swords is no basis for a system of government. Supreme executive power derives from a mandate from the masses, not from some farcical aquatic ceremony. The Lady of the Lake, her arm clad in the purest shimmering samite held

How to check programmatically with python if any other application is playing audio/video

放肆的年华 提交于 2021-02-18 18:03:11
问题 I need to check if any application is playing any kind of media. Most importantly I want my Python program to detect whichever application is playing audio. The name of the application the audio is playing. And any related data are welcome. I searched this up before posting here. I got many results, but unfortunately those are not for python. They were made for languages like C and C++. My spec for your reference: Operating System: Windows 10 Python Version 3.8 来源: https://stackoverflow.com

When do the threads in python die if the method thread.stop() or thread.join() is not called?

我与影子孤独终老i 提交于 2021-02-18 18:03:10
问题 Here is a snippet of code: def display(): threading.Timer(1,display).start() print("Number") display() For this code I want to ask the following things: Every second new thread spawns, is that right? Every second the last thread dies because the function executes completely so the older thread dies, is that right? If not then what is happening? 回答1: Timer derives from Thread , so yes: many threads are started. Threads die when their invoked functions return (or throw) whether or not you call