python-3.7

Retrieving python 3.6 handling of re.sub() with zero length matches in python 3.7

耗尽温柔 提交于 2019-12-01 16:14:05
问题 handling of zero length matches has changed with python 3.7. Consider the following with python 3.6 (and previous): >>> import re >>> print(re.sub('a*', 'x', 'bac')) xbxcx >>> print(re.sub('.*', 'x', 'bac')) x We get the following with python 3.7: >>> import re >>> print(re.sub('a*', 'x', 'bac')) xbxxcx >>> print(re.sub('.*', 'x', 'bac')) xx I understand this is the standard behavior of PCRE. Furthermore, re.finditer() seems to have always detected the additional match: >>> for m in re

How to save selected Items to Qsettings from QListWidget, QTableWidget

天涯浪子 提交于 2019-12-01 12:20:47
I am Using PyQt5 and Py3.7, I am trying to loop through all my Qlistwidgets and save their string data, but also save all selected items on that widget. I slightly modified the loop from here , but am having some trouble getting the selected items to save and restore using the listwidget array loop. I checked the docs but can't seem to understand how to add additional options into the array (such as save all selected items), from the Qt docs for SetArrayIndex, here . My listWidgets have selectionMode set to MultiSelection. I am currently saving using this: def save_list_data(self): self

How to save selected Items to Qsettings from QListWidget, QTableWidget

寵の児 提交于 2019-12-01 10:26:44
问题 I am Using PyQt5 and Py3.7, I am trying to loop through all my Qlistwidgets and save their string data, but also save all selected items on that widget. I slightly modified the loop from here, but am having some trouble getting the selected items to save and restore using the listwidget array loop. I checked the docs but can't seem to understand how to add additional options into the array (such as save all selected items), from the Qt docs for SetArrayIndex, here. My listWidgets have

Context variables in Python

狂风中的少年 提交于 2019-12-01 03:51:35
问题 Suppose that I have a function in my Python application that define some kind of context - a user_id for example. This function call other functions that do not take this context as a function argument. For example: def f1(user, operation): user_id = user.id # somehow define user_id as a global/context variable for any function call inside this scope f2(operation) def f2(operation): # do something, not important, and then call another function f3(operation) def f3(operation): # get user_id if

How to use blocking functions with asyncio

帅比萌擦擦* 提交于 2019-11-30 16:07:21
I'm using django ORM in a project(outside of django). My workflow is selecting objects by the django ORM and then send it to a message queue using an asyncio lib The problem is you can't call blocking functions in async environment and you can not use async/await in blocking environment. I have come up with 2 solutions: The whole program should be async. And use loop.run_in_executor to call blocking functions when needed. The whole program should be sync. And use asyncio.run() (Python 3.7) to call async functions needed. I can't decide which one is better approach. I know a similar question

Installing numpy with pip on windows 10 for python 3.7

泪湿孤枕 提交于 2019-11-30 12:57:09
问题 I installed python 3.7 on my Windows 10 laptop since it has been officially released as of today (06/28/2018). Then i tried to install numpy package using pip pip install numpy The install proceeds but finally fails with the below error : source = func(extension, build_dir) File "numpy\core\setup.py", line 675, in get_mathlib_info raise RuntimeError("Broken toolchain: cannot link a simple C program") RuntimeError: Broken toolchain: cannot link a simple C program ------------------------------

Installing numpy with pip on windows 10 for python 3.7

早过忘川 提交于 2019-11-30 05:28:46
I installed python 3.7 on my Windows 10 laptop since it has been officially released as of today (06/28/2018). Then i tried to install numpy package using pip pip install numpy The install proceeds but finally fails with the below error : source = func(extension, build_dir) File "numpy\core\setup.py", line 675, in get_mathlib_info raise RuntimeError("Broken toolchain: cannot link a simple C program") RuntimeError: Broken toolchain: cannot link a simple C program ---------------------------------------- Command ""c:\program files\python37\python.exe" -u -c "import setuptools, tokenize;__file__=

How to use blocking functions with asyncio

大城市里の小女人 提交于 2019-11-29 15:35:34
问题 I'm using django ORM in a project(outside of django). My workflow is selecting objects by the django ORM and then send it to a message queue using an asyncio lib The problem is you can't call blocking functions in async environment and you can not use async/await in blocking environment. I have come up with 2 solutions: The whole program should be async. And use loop.run_in_executor to call blocking functions when needed. The whole program should be sync. And use asyncio.run() (Python 3.7) to

Class inheritance in Python 3.7 dataclasses

强颜欢笑 提交于 2019-11-28 20:14:58
I'm currently trying my hands on the new dataclass constructions introduced in Python 3.7. I am currently stuck on trying to do some inheritance of a parent class. It looks like the order of the arguments are botched by my current approach such that the bool parameter in the child class is passed before the other parameters. This is causing a type error. from dataclasses import dataclass @dataclass class Parent: name: str age: int ugly: bool = False def print_name(self): print(self.name) def print_age(self): print(self.age) def print_id(self): print(f'The Name is {self.name} and {self.name} is

Tweepy won't install on python 3.7; shows “syntax error”

有些话、适合烂在心里 提交于 2019-11-28 14:16:48
Before I begin, I'd like to preface that I'm relatively new to python, and haven't had to use it much before this little project of mine. I'm trying to make a twitter bot as part of an art project, and I can't seem to get tweepy to import. I'm using macOS High Sierra and Python 3.7. I first installed tweepy by using pip3 install tweepy and this appeared to work, as I'm able to find the tweepy files in finder. However, when I simply input import tweepy into the IDLE, I get this error: Traceback (most recent call last): File "/Users/jacobhill/Documents/CicadaCacophony.py", line 1, in <module>