python-3.6

Error building executable with cx_Freeze: IndexError: tuple index out of range

你说的曾经没有我的故事 提交于 2019-11-28 14:46:00
Background I have made a program that I am trying to turn into an executable using CX_Freeze. The setup.py file is placed inside the same directory as all files I am working with. I don't use any extra libraries other than TKinter and OS. The program works perfectly fine normally when I run it via PyCharm>Run Version Numbers cx_Freeze ver: - 5.0 cx_Freeze .whl: - cx_Freeze-5.0-cp36-cp36m-win_amd64.whl python ver: - 3.6.0b4 pycharm ver: - 2016.3.1 This is my setup.py file import cx_Freeze import sys from cx_Freeze import setup, Executable base = None if sys.platform == 'win32': base = "Win32GUI

Python multiprocessing: abort map on first child error

烂漫一生 提交于 2019-11-28 14:31:31
What's the proper way of aborting multiprocessing when one of the child aborts and/or throw an Exception? I found various questions around that ( generic multiprocessing error handling , how to close multiprocessing pool on exception but without answer , ...), but no clear answer on how to stop multiprocessing on child exception. For instance, I expect the following code: def f(x): sleep(x) print(f"f({x})") return 1.0 / (x - 2) def main(): with Pool(4) as p: try: r = p.map(f, range(7)) except Exception as e: print(f"oops: {e}") p.close() p.terminate() print("end") if __name__ == '__main__':

ZMQ DEALER - ROUTER Communication

蹲街弑〆低调 提交于 2019-11-28 12:59:19
I am currently working on a project that requires some communication over the network of a different data types from some entities of a distributed system and I am using ZMQ. The main goal of the project is to have a central node which services clients which can connect at any time. For each client connected, the central node should manage the message communication between the two. Currently, and by the moment, all communication is happening over TCP. The clients need to send and receive messages at any time so they are ZMQ_DEALER type sockets and the central node is ZMQ_ROUTER Initially, the

Create an abstract Enum class

﹥>﹥吖頭↗ 提交于 2019-11-28 12:02:21
I'm trying to create an abstract enum ( Flag actually) with an abstract method. My final goal is to be able to create a string representation of compound enums, based on the basic enums I defined. I'm able to get this functionality without making the class abstract. This is the basic Flag class and an example implementation: from enum import auto, Flag class TranslateableFlag(Flag): @classmethod def base(cls): pass def translate(self): base = self.base() if self in base: return base[self] else: ret = [] for basic in base: if basic in self: ret.append(base[basic]) return " | ".join(ret) class

How to change the python version of already existing virtualenv? [duplicate]

♀尐吖头ヾ 提交于 2019-11-28 11:26:32
This question already has an answer here: Can existing virtualenv be upgraded gracefully? 4 answers I have created a virtual environment using python 3.6, then I've made a system upgrade and I've got python 3.7 installed system wide. Now I can't execute python files in that virtual environment because it's searching for python 3.6. How can I upgrade the virtualenv python version to match the system wide version or how to downgrade the python version for that particular virtual environment? I'm using manjaro. See this link which explains it well. Virtualenvwrapper comes with some convenient

Provide __classcell__ example for Python 3.6 metaclass

强颜欢笑 提交于 2019-11-28 11:12:47
Per the 3.6.0 docs: CPython implementation detail : In CPython 3.6 and later, the __class__ cell is passed to the metaclass as a __classcell__ entry in the class namespace. If present, this must be propagated up to the type.__new__ call in order for the class to be initialized correctly. Failing to do so will result in a DeprecationWarning in Python 3.6, and a RuntimeWarning in the future. Can someone provide an example of doing this correctly? An example where it's actually needed? The warning is raised if you use the zero argument super super().__method__(args) that relies on __class__ being

Tensorflow execution time

对着背影说爱祢 提交于 2019-11-28 09:38:57
问题 I have a function within a Python script that I am calling multiple times (https://github.com/sankhaMukherjee/NNoptExpt/blob/dev/src/lib/NNlib/NNmodel.py): I have simplified the function significantly for this example. def errorValW(self, X, y, weights): errVal = None with tf.Session() as sess: sess.run(tf.global_variables_initializer()) nW = len(self.allW) W = weights[:nW] B = weights[nW:] for i in range(len(W)): sess.run(tf.assign( self.allW[i], W[i] )) for i in range(len(B)): sess.run(tf

Can I postpone/defer the evaluation of f-strings?

南笙酒味 提交于 2019-11-28 08:51:58
I am using template strings to generate some files and I love the conciseness of the new f-strings for this purpose, for reducing my previous template code from something like this: template_a = "The current name is {name}" names = ["foo", "bar"] for name in names: print (template_a.format(**locals())) Now I can do this, directly replacing variables: names = ["foo", "bar"] for name in names: print (f"The current name is {name}") However, sometimes it makes sense to have the template defined elsewhere -- higher up in the code, or imported from a file or something. This means the template is a

repeating the rows of a data frame

元气小坏坏 提交于 2019-11-28 04:20:24
问题 I'm trying repeat the rows of a dataframe. Here's my original data: pd.DataFrame([ {'col1': 1, 'col2': 11, 'col3': [1, 2] }, {'col1': 2, 'col2': 22, 'col3': [1, 2, 3] }, {'col1': 3, 'col2': 33, 'col3': [1] }, {'col1': 4, 'col2': 44, 'col3': [1, 2, 3, 4] }, ]) which gives me col1 col2 col3 0 1 11 [1, 2] 1 2 22 [1, 2, 3] 2 3 33 [1] 3 4 44 [1, 2, 3, 4] I'd like to repeat the rows depending on the length of the array in col3 i.e. I'd like to get a dataframe like this one. col1 col2 0 1 11 1 1 11

Python asyncio.semaphore in async-await function

冷暖自知 提交于 2019-11-28 02:04:35
I am trying to teach myself Python's async functionality. To do so I have built an async web scraper. I would like to limit the total number of connections I have open at once to be a good citizen on servers. I know that semaphore's are a good solution, and the asyncio library has a semaphore class built in. My issue is that Python complains when using yield from in an async function as you are combining yield and await syntax. Below is the exact syntax I am using... import asyncio import aiohttp sema = asyncio.BoundedSemaphore(5) async def get_page_text(url): with (yield from sema): try: resp