python-3.3

A ThreadPoolExecutor inside a ProcessPoolExecutor

倾然丶 夕夏残阳落幕 提交于 2020-08-21 09:44:08
问题 I am new to the futures module and have a task that could benefit from parallelization; but I don't seem to be able to figure out exactly how to setup the function for a thread and the function for a process. I'd appreciate any help anyone can shed on the matter. I'm running a particle swarm optimization (PSO). Without getting into too much detail about PSO itself, here's the basic layout of my code: There is a Particle class, with a getFitness(self) method (which computes some metric and

Format time string in Python 3.3

故事扮演 提交于 2020-04-29 10:26:26
问题 I am trying to get current local time as a string in the format: year-month-day hour:mins:seconds. Which I will use for logging. By my reading of the documentation I can do this by: import time '{0:%Y-%m-%d %H:%M:%S}'.format(time.localtime()) However I get the error: Traceback (most recent call last): File "", line 1, in ValueError: Invalid format specifier What am I doing wrong? Is there a better way? 回答1: time.localtime returns time.struct_time which does not support strftime-like

Custom Popen.communicate method gives wrong output

百般思念 提交于 2020-04-16 02:58:48
问题 Let's start by considering this code: proc_stdin.py import sys if __name__ == '__main__': for i, line in enumerate(sys.stdin): sys.stdout.write(line) test.py import subprocess def run_bad(target, input=None): proc = subprocess.Popen( target, universal_newlines=True, shell=True, stderr=subprocess.STDOUT, stdin=subprocess.PIPE if input else subprocess.DEVNULL, stdout=subprocess.PIPE, ) if input: proc.stdin.write(input) proc.stdin.flush() proc.stdin.close() lines = [] for line in iter(proc

python 3 detect caps lock status

白昼怎懂夜的黑 提交于 2020-03-24 11:06:11
问题 I've been searching for a way to identify the status of the CAPS LOCK in Python 3 and the only thing I've found applicable was a post here in Stack Overflow answered by Abhijit stating: You can use ctypes to load user32.dll and then call GetKeyState with nVirtKey = VK_CAPITAL (0x14) def get_capslock_state(): import ctypes hllDll = ctypes.WinDLL ("User32.dll") VK_CAPITAL = 0x14 return hllDll.GetKeyState(VK_CAPITAL) I've applied this to my script, but the value returned is not the anticipated 1

Python bytes literal has extra characters that aren't hex, but alter the value of the string

老子叫甜甜 提交于 2020-03-10 04:58:46
问题 I am used to the python byte literal syntax representing bytes as hex values such as b'\x7a' is the hex value 0x7a . I however have run into an issue that I don't know how it is working. I am using the ssl library for the first time and creating random values with ssl.RAND_bytes(...) It is returning strings with characters that alter the value (say when doing an int.from_bytes(...) ) Example strings I have received: b'\x12\x1f)\x8b\xe0\xd7LD' b'\x808\x8a(\x02\xb3S\xc9\xabW_\n\xf3\xbb\x80o' b'

Python 3 and matplotlib lissue on Linux

隐身守侯 提交于 2020-02-07 03:42:06
问题 I have been facing a couple of issues in using matplotlib with Python 3. After getting rid of this one, I ran into a new one. When I tried to execute the histogram demo, I get this traceback. Does anyone have an idea? My matplotlib version is: python3-matplotlib-1.2.0-8.fc18.x86_64 (i.e. 1.2 on Fedora 18). Bugs filed: Fedora Matplotlib 回答1: Add this to the top of the histogram_demo.py, just before import numpy : from matplotlib import font_manager font_manager.USE_FONTCONFIG = False Or modify

Why is dictionary ordering non-deterministic?

别来无恙 提交于 2020-01-14 14:33:09
问题 I recently switched from Python 2.7 to Python 3.3, and it seems that while in Python 2 the ordering of dictionary keys was arbitrary but consistent, in Python 3 the ordering of the keys of a dictionary obtained with e.g. vars() appears non-deterministic. If I run: class Test(object): pass parameters = vars(Test) print(list(parameters.keys())) in both Python 2.7 and Python 3.3, then: Python 2.7 consistently gives me ['__dict__', '__module__', '__weakref__', '__doc__'] With Python 3.3, I can

Does PEP 412 make __slots__ redundant?

眉间皱痕 提交于 2020-01-13 07:49:18
问题 PEP 412, implemented in Python 3.3, introduces improved handling of attribute dictionaries, effectively reducing the memory footprint of class instances. __slots__ was designed for the same purpose, so is there any point in using __slots__ any more? In an attempt to find out the answer myself, I run the following test, but the results don't make much sense: class Slots(object): __slots__ = ['a', 'b', 'c', 'd', 'e'] def __init__(self): self.a = 1 self.b = 1 self.c = 1 self.d = 1 self.e = 1

How do you set the position of a grid using Tkinter?

荒凉一梦 提交于 2020-01-13 05:46:13
问题 Is it even possible to set the absolute position of a grid within Tkinter? I am trying to create a GUI that looks like the one below, but I am probably going about it the wrong way. So if it is possible, how do you set the grid position? Target GUI: This is how my GUI is turning out, so far: As you can see, my New Contact needs to be on the right, while the Contact List should be on the left. I understand how to move the Contact List using absolute values, but can I do the same for my grid

Numpy-MKL for OS X

好久不见. 提交于 2020-01-12 19:05:24
问题 I love being able to use Christoph Gohlke's numpy-MKL version of NumPy linked to Intel's Math Kernel Library on Windows. However, I have been unable to find a similar version for OS X, preferably NumPy 1.7 linked for Python 3.3 on Mountain Lion. Does anyone know where this might be obtained? EDIT: So after a bit of hunting I found this link to evaluate Intel's Composer XE2013 studios for C++ and Fortran (both of which contain the MKL), as well as a tutorial on building NumPy and SciPy with it