python-2.7

IO Error:Cannot open image while generating barcode after freezing using py2exe

断了今生、忘了曾经 提交于 2021-02-04 20:47:25
问题 I have used pyBarcode library to generate Barcode in my software and its works perfectly fine while I load it from command line but once I freeze the entire software using py2exe I am getting IO error while generating the barcode. File "panels.pyc", line 383, in generate File "barcodeGenerator.pyc", line 9, in generate File "barcode\base.pyc", line 68, in save File "barcode\codex.pyc", line 251, in render File "barcode\base.pyc", line 103, in render File "barcode\writer.pyc", line 188, in

Reorder Multi-indexed dataframe columns based on reference

血红的双手。 提交于 2021-02-04 19:55:07
问题 I have a multi-indexed dataframe with names attached to the column levels. The data table looks something like this: (df1) TIME TMC 111N1 111P2 111N3 111P4 DATE EPOCH 0 143 113 103 NaN 1 183 NaN NaN NaN 2 NaN NaN NaN NaN 3 143 NaN NaN NaN I'd like to shuffle the columns around so that they match the order specified by the rows index of a reference dataframe (df2): A1 A2 A3 A4 A5 Name 111N3 PA PL er 0.75543 35 111P4 PA PL er 0.09413 35 111N1 PA PL er 4.21557 35 111P2 PA PL er 1.31989 35 i.e.

Appending characters to each line in a txt file with python

二次信任 提交于 2021-02-04 19:50:30
问题 I wrote the following python code snippet to append a lower p character to each line of a txt file: f = open('helloworld.txt','r') for line in f: line+='p' print(f.read()) f.close() However, when I execute this python program, it returns nothing but an empty blank: zhiwei@zhiwei-Lenovo-Rescuer-15ISK:~/Documents/1001/ass5$ python3 helloworld.py Can anyone tell me what's wrong with my codes? 回答1: Currently, you are only reading each line and not writing to the file. reopen the file in write

Scraping dynamic content through Selenium?

你说的曾经没有我的故事 提交于 2021-02-04 19:46:25
问题 I'm trying to scrap dynamic content from a Blog through Selenium but it always returns un rendered JavaScript. To test this behavior I tried to wait till iframe loads completely and printed it's content which prints fine but again when I move back to parent frame it just displays un rendered JavaScript. I'm looking for something in which I'm able to print completely rendered HTML content from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium

Handling interactive shells with Python subprocess

∥☆過路亽.° 提交于 2021-02-04 19:31:12
问题 I am trying to run multiple instances of a console-based game (dungeon crawl stone soup -- for research purposes naturally) using a multiprocessing pool to evaluate each run. In the past when I've used a pool to evaluate similar code (genetic algorithms), I've used subprocess.call to split off each process. However, with dcss being quite interactive having a shared subshell seems to be problematic. I have the code I normally use for this kind of thing, with crawl replacing other applications

Dropping columns in a dataframe

╄→гoц情女王★ 提交于 2021-02-04 15:15:12
问题 I'm on Python 2.7. I have a dataframe with 200 columns and need to drop a few. I can use the below to drop the last n columns. How do I write it so i can drop the first 10, then column 22, then 26, 10th from the last, and last 5. All in one line. df2 = df.iloc[:, :-5] 回答1: Use np.r_: import numpy as np df.drop(df.columns[np.r_[:10, 22, 26, -10, -5:0]], axis=1) np.r_ concatenates several slices. For example, np.r_[1:3, 5, 7:9, -3:0] returns array([ 1, 2, 5, 7, 8, -3, -2, -1]) . You can use

Python - Get Yesterday's date as a string in YYYY-MM-DD format

廉价感情. 提交于 2021-02-04 09:18:46
问题 As an input to an API request I need to get yesterday's date as a string in the format YYYY-MM-DD . I have a working version which is: yesterday = datetime.date.fromordinal(datetime.date.today().toordinal()-1) report_date = str(yesterday.year) + \ ('-' if len(str(yesterday.month)) == 2 else '-0') + str(yesterday.month) + \ ('-' if len(str(yesterday.day)) == 2 else '-0') + str(yesterday.day) There must be a more elegant way to do this, interested for educational purposes as much as anything

Python - Get Yesterday's date as a string in YYYY-MM-DD format

孤人 提交于 2021-02-04 09:18:25
问题 As an input to an API request I need to get yesterday's date as a string in the format YYYY-MM-DD . I have a working version which is: yesterday = datetime.date.fromordinal(datetime.date.today().toordinal()-1) report_date = str(yesterday.year) + \ ('-' if len(str(yesterday.month)) == 2 else '-0') + str(yesterday.month) + \ ('-' if len(str(yesterday.day)) == 2 else '-0') + str(yesterday.day) There must be a more elegant way to do this, interested for educational purposes as much as anything

How to change label text until pushbutton clicked in pyqt

血红的双手。 提交于 2021-02-04 08:40:24
问题 how do i change the text of a label until a push button is clicked in pyqt (how do i keep this in loop) here is the code i tried from PyQt4 import QtCore, QtGui try: _fromUtf8 = QtCore.QString.fromUtf8 except AttributeError: def _fromUtf8(s): return s try: _encoding = QtGui.QApplication.UnicodeUTF8 def _translate(context, text, disambig): return QtGui.QApplication.translate(context, text, disambig, _encoding) except AttributeError: def _translate(context, text, disambig): return QtGui

Python - Parsing JSON formatted text file with regex

邮差的信 提交于 2021-02-04 08:29:27
问题 I have a text file formatted like a JSON file however everything is on a single line (could be a MongoDB File). Could someone please point me in the direction of how I could extract values using a Python regex method please? The text shows up like this: {"d":{"__type":"WikiFileNodeContent:http:\/\/samplesite.com.‌​au\/ns\/business\/wi‌​ki","author":null,"d‌​escription":null,"fi‌​leAssetId":"034b9317‌​-60d9-45c2-b6d6-0f24‌​b59e1991","filename"‌​:"Reports.pdf"},"cre‌​atedBy":1531,"create‌