python-3.7

String format printing with python3: print from unpacked array *some* of the time

岁酱吖の 提交于 2019-12-10 14:54:36
问题 In my question a few minutes ago, I asked about how to print using python's str.format printing, when the strings are stored in an array. Then answer was clearly unpack the list, like this: # note that I had to play with the whitespace because the {} text is 2 characters, while its replacement is always one hex_string = r''' _____ / \ / \ ,----( {} )----. / \ / \ / {} \_____/ {} \ \ / \ / \ / \ / )----( {} )----( / \ / \ / \_____/ \ \ {} / \ {} / \ / \ / `----( {} )----' \ / \_____/ '''

Python 3.6 DateTime Strptime Returns error while Python 3.7 works well

限于喜欢 提交于 2019-12-10 13:09:02
问题 I just created a data type for my date data, which returns a datetime.datetime object Here is the code: import datetime class Date: def __new__(cls, dateTime, *args, **kwargs): return datetime.datetime.strptime(dateTime, "%Y-%m-%dT%H:%M:%S.%f%z") So everytime I give this class an ISO-8601 it should return the datetime object from the string... Python 3.7 Example: Date("2018-12-09T08:56:12.189Z") # Returns => datetime.datetime(2018, 12, 9, 8, 56, 12, 189000, tzinfo=datetime.timezone.utc) This

Python 3.7 - asyncio.sleep() and time.sleep()

六月ゝ 毕业季﹏ 提交于 2019-12-10 09:53:25
问题 When I go to the asyncio page, the first example is a hello world program. When I run it on python 3.73 , I can't see any different from the normal one, can anyone tell me the difference and give a non-trivial example? In [1]: import asyncio ...: ...: async def main(): ...: print('Hello ...') ...: await asyncio.sleep(5) ...: print('... World!') ...: ...: # Python 3.7+ ...: asyncio.run(main()) Hello ... ... World! In [2]: In [2]: import time ...: ...: def main(): ...: print('Hello ...') ...:

Trying to install packages with Python 3.7.2 pip causes TSL/SSL errors

六眼飞鱼酱① 提交于 2019-12-10 03:48:53
问题 I'm running on: Amazon Linux AMI 2018.03.0 Linux ip-xxx-yy-z-ww 4.14.77-70.59.amzn1.x86_64 #1 SMP Mon Nov 12 22:02:45 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux Multi-python environment. It has both Python 2.7.15 and 3.7.2 installed. Regular (Python2) pip works without a hitch. When I try to run pip3 install flask I get the following errors: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. Collecting flask Retrying (Retry(total=4, connect

How do I add a timeout to multiprocessing.connection.Client(..) in Python 3.7?

佐手、 提交于 2019-12-10 00:23:37
问题 I've got two Python programs running. Program A connects to program B with the multiprocessing module: # Connection code in program A # ----------------------------- import multiprocessing import multiprocessing.connection ... connection = multiprocessing.connection.Client( ('localhost', 19191), # <- address of program B authkey='embeetle'.encode('utf-8') # <- authorization key ) ... connection.send(send_data) recv_data = connection.recv() It works perfectly most of the time. However,

How to run Spyder with Python 3.7 with Anaconda

走远了吗. 提交于 2019-12-09 12:24:28
问题 I have installed Anaconda on a Windows 10 machine which comes with Spyder and Python 3.6 but I wish to upgrade to Python 3.7 To create an Anaconda Environment with Python 3.7 is easy by using: conda create --name py37 python=3.7 or: conda create --name py370 python=3.7.0 --channel conda-forge However starting Spyder in this environment will throw it back to Python 3.6. I tried specifing the python.exe (for version 3.7) directly in Tools -> Settings of Spyder, however upon restarting the

How to add text on top of an image in tkinter

拥有回忆 提交于 2019-12-08 18:22:27
I want to know how to add text on to of an image in tkinter. I type in the following code: import PIL from PIL import ImageFont from PIL import Image from PIL import ImageDraw draw=ImageDraw.Draw("maybe.png") pixellat=ImageFont.truetype("pixellat.ttf",18) draw.text((125, 125),"This is a test",(255,255,255),font=pixellat) But I get this error: Traceback (most recent call last): File "/usr/local/lib/python3.7/site- packages/PIL/ImageDraw.py", line 344, in Draw return im.getdraw(mode) AttributeError: 'str' object has no attribute 'getdraw' During handling of the above exception, another exception

How to add text on top of an image in tkinter

依然范特西╮ 提交于 2019-12-08 07:02:52
问题 I want to know how to add text on to of an image in tkinter. I type in the following code: import PIL from PIL import ImageFont from PIL import Image from PIL import ImageDraw draw=ImageDraw.Draw("maybe.png") pixellat=ImageFont.truetype("pixellat.ttf",18) draw.text((125, 125),"This is a test",(255,255,255),font=pixellat) But I get this error: Traceback (most recent call last): File "/usr/local/lib/python3.7/site- packages/PIL/ImageDraw.py", line 344, in Draw return im.getdraw(mode)

How to force VSCode to use Python 3 instead of Python 2?

独自空忆成欢 提交于 2019-12-07 11:49:24
问题 Using macOS. I'm using VSCode 1.28.2 and I am wondering how I can force VSCode to use Python 3 instead of Python 2. Unless I use the shebang: #!/usr/bin/env python3 , I always get an ImportError or some other problem, even though the intrepreter is using Python 3.7. Image here: If I use the shebang, the code works and the output in the Terminal is: <bound method Response.raise_for_status of <Response [200]>> I am using the Python Extension by Microsoft.(https://marketplace.visualstudio.com

RuntimeError: asyncio.run() cannot be called from a running event loop

那年仲夏 提交于 2019-12-07 07:37:09
问题 I am trying to learn about asyncio for a websockets client. Every piece of code I try gets the following error: RuntimeError: asyncio.run() cannot be called from a running event loop I have tried the most simple code and it always gives that RuntimeError. I tried installing the full anaconda distribution again, etc, and can´t find what the problem might be. I am using Spyder 3.3.3 with Python 3.7.3 An example of code that should work: import asyncio async def main(): print('hello') await