python-3.5

Python subprocess: chaining commands with subprocess.run

和自甴很熟 提交于 2019-12-08 08:26:32
问题 I'm experimenting with subprocess.run in Python 3.5. To chain two commands together, I would have thought that the following should work: import subprocess ps1 = subprocess.run(['ls'], universal_newlines=True, stdout=subprocess.PIPE) ps2 = subprocess.run(['cowsay'], stdin=ps1.stdout) However, this fails with: AttributeError: 'str' object has no attribute 'fileno' ps2 was expecting a file-like object, but the output of ps1 is a simple string. Is there a way to chain commands together with

Heroku Python3.5 Import Error : No module named ='_tkinter'

[亡魂溺海] 提交于 2019-12-08 05:01:16
问题 While deploying in Heroku and adding customized buildpacks such as libspatialindex, another error occurred where Python 3.5 now looks for Tkinter. Locally, by installing using sudo apt-get tk-dev this would be solved and trying out the suggestion from this similar problem: import matplotlib failing on Heroku, the error still persists. Here are my buildpacks: https://github.com/heroku/heroku-buildpack-apt heroku/python https://github.com/julienfr112/libspatialindex-buildpack.git And my Aptfile

Generate 1D NumPy array of concatenated ranges

眉间皱痕 提交于 2019-12-08 04:30:31
问题 I want to generate a following array a : nv = np.random.randint(3, 10+1, size=(1000000,)) a = np.concatenate([np.arange(1,i+1) for i in nv]) Thus, the output would be something like - [0, 1, 2, 3, 0, 1, 2, 3, 4, 0, 1, 2, 0, 1, 2, 3, 4, 5, 0, ...] Does there exist any better way to do it? 回答1: Here's a vectorized approach using cumulative summation - def ranges(nv, start = 1): shifts = nv.cumsum() id_arr = np.ones(shifts[-1], dtype=int) id_arr[shifts[:-1]] = -nv[:-1]+1 id_arr[0] = start # Skip

Python subprocess: chaining commands with subprocess.run

大城市里の小女人 提交于 2019-12-08 03:40:30
I'm experimenting with subprocess.run in Python 3.5. To chain two commands together, I would have thought that the following should work: import subprocess ps1 = subprocess.run(['ls'], universal_newlines=True, stdout=subprocess.PIPE) ps2 = subprocess.run(['cowsay'], stdin=ps1.stdout) However, this fails with: AttributeError: 'str' object has no attribute 'fileno' ps2 was expecting a file-like object, but the output of ps1 is a simple string. Is there a way to chain commands together with subprocess.run ? Turns out that subprocess.run has an input argument to handle this: ps1 = subprocess.run([

SSL and Tkinter not present on source build of Python 3.5.2, Debian Linux

送分小仙女□ 提交于 2019-12-08 02:56:17
问题 I just now downloaded Python 3.5.2 onto my Debian machine and built it with: ./configure make make test sudo make install Everything worked, but in the make test output, it showed the installer as having skipped certain tests due to the modules _tkinter and _ssl not being installed. Furthermore, the lack of SSL makes me unable to use pip. This also happened on my build of 3.5.1, but I assumed that it was just an early, buggy version. How can I fix this? I especially need SSL in order to send

How to bind async method to a keystroke in Tkinter?

柔情痞子 提交于 2019-12-07 18:52:06
问题 Consider the following example: import asyncio import tkinter as tk class App(tk.Tk): def __init__(self): super().__init__() self.create_widgets() self._configure_bindings() # I believe it is not possible # to do this if the method needs # to be async as well def create_widgets(self): pass def _configure_bindings(self): self.bind('<F5>', self.spam) # what's the proper way? # does this method need to be async as well? async def spam(self, event): await self.do_something() async def do

python logging output on both GUI and console

血红的双手。 提交于 2019-12-07 18:37:32
问题 Given this little snippet: import sys import os import logging from PyQt5 import QtGui, QtWidgets, QtCore log = logging.getLogger("Foo") logging.basicConfig( level=logging.INFO, format='%(levelname)s: %(filename)s - %(message)s') log.setLevel(logging.DEBUG) class ConsolePanelHandler(logging.Handler): def __init__(self, parent): logging.Handler.__init__(self) self.parent = parent def emit(self, record): self.parent.write(self.format(record)) class Foo(QtWidgets.QWidget): def __init__(self,

tkinter Checkbutton widget returning wrong boolean value

不打扰是莪最后的温柔 提交于 2019-12-07 17:25:01
问题 I have a simple GUI here that's suppose to return a boolean value depending on whether the check button is checked or not. I've set the boolean variable to False hence the empty check button. What I don't understand is that when I check the button, the function binded to that widget returns a False instead of True. Why is that? Here's the code... from tkinter import * from tkinter import ttk def getBool(event): print(boolvar.get()) root = Tk() boolvar = BooleanVar() boolvar.set(False) cb =

pip3 install pyautogui fails with error code 1 Mac OS

半腔热情 提交于 2019-12-07 15:53:49
问题 I tried installing the autogui python extension: pip3 install pyautogui And this installation attempt results in the following error message: Collecting pyautogui Using cached PyAutoGUI-0.9.33.zip Complete output from command python setup.py egg_info: Traceback (most recent call last): File "<string>", line 1, in <module> File "/private/var/folders/00/zcr6mkx90hg7kr4x_ks6nhhw0000gn/T/pip-build-edy15oyn/pyautogui/setup.py", line 6, in <module> version=__import__('pyautogui').__version__, File

How to run the Tornado event loop alongside a Kivy GUI?

北城余情 提交于 2019-12-07 15:43:00
问题 My client application uses a Kivy GUI (Kivy has its own event loop) and connects to the server using the WebSocket protocol with Tornado (Tornado also has an event loop). That's why the connection part is asynchronous. I want the user to interact with the UI while a Tornado client is running an infinite asynchronous loop of listening for server messages. Here's some example code: client_test.py from tornado.ioloop import IOLoop from tornado.websocket import websocket_connect class