python-3.6

Build f-strings from normal strings

烈酒焚心 提交于 2020-01-04 06:36:06
问题 I'm trying the new f-strings, and I'm wondering if it's possible to "compile" a normal string into an f-string. So to have control on the evaluation time of the f-string, and be capable of defining f-strings before consuming them. Example pseudo-code: a = 'normal string with some curly {inside}' inside = 'in it!' print(a.make_f_string()) >>> 'normal string with some curly in it!' So basically my need is to define the f-string before the variable that it contains. or make a string an f-string.

Spark 2.3 AsyncEventQueue Error and Warning

不打扰是莪最后的温柔 提交于 2020-01-04 05:48:08
问题 I'm running a memory intensive code where I've created a pipeline which consists of : Finding the best number of bin value using Shimazaki and Shinomoto's Bin Width algorithm. Creating a new column by Bucketizing the same column with the respective bin values found from above. Calculating a Weight of Evidence by 8 sequencial SQL queries. Config: Python - 3.6 Spark - 2.3 Environment - Standalone machine (16 GB RAM and 500 GB HDD with i7 processor) IDE - Pycharm My doubt is, it is working as

Why are f-strings faster than str() to parse values?

心已入冬 提交于 2020-01-03 08:28:12
问题 I was playing around with f-strings, (see PEP 498), and I decided to check the speed of the f-string parse, (e.g. f"{1}") in comparison with the usual str parse (e.g str(1)). But for my surprise, when I checked the velocity of both methods with the timeit function, I found out that >>> from timeit import timeit >>> timeit("f'{1}'") 0.1678762999999961 whereas >>> timeit("str(1)") 0.3216999999999999 or even the repr func, which in most of the cases is faster than str cast >>> timeit("repr(1)")

Attaching pdf file to an EmailMessage?

老子叫甜甜 提交于 2020-01-03 04:58:18
问题 I am trying to set up an automated email sending script. I am using the email module and the EmailMessage object from the email.message module and am sending the email using the smtplib module. I would like to be able to attach a .pdf file to an email but the documentation for the add_attachment() method for EmailMessage() is not very helpful and I'm not even sure I should be using it. Here is what I have so far with irrelevant information removed: import time import smtplib from email

How to create a filename with the current date and time in python when query is ran

南楼画角 提交于 2020-01-03 02:25:50
问题 When I run my query below, it creates a file called ‘mycsvfile’. However is there a way to add the current date and timestamp when the CSV file is created? For example if I run this query now the file should be named mycsvfile20171012 – 10:00:00 (something like that). Could someone edit my code and show me how to do this please? My code: from elasticsearch import Elasticsearch import csv es = Elasticsearch(["9200"]) # Replace the following Query with your own Elastic Search Query res = es

Sending an sms via way2sms using Python 3

孤街醉人 提交于 2020-01-03 02:24:08
问题 I've been trying to send free sms using way2sms. I found this link where it seemed to work on python 3: https://github.com/shubhamc183/way2sms I've saved this file as way2sms.py: import requests from bs4 import BeautifulSoup class sms: def __init__(self,username,password): ''' Takes username and password as parameters for constructors and try to log in ''' self.url='http://site24.way2sms.com/Login1.action?' self.cred={'username': username, 'password': password} self.s=requests.Session() #

What is the correct format to write float value to file in Python

眉间皱痕 提交于 2020-01-02 21:53:45
问题 I have a bunch of float values, for example: x1 = 1.11111111 x2 = 2.22222222 I want to write these values to a file: f = open("a.dat", "w+") f.write("This is x1: ",x1) f.write("\n") #I want to separate the 2 lines f.write("This is x2: ",x2) At this point I got an error on the second line: write() takes exactly one argument (2 given) How do I write to file such that when I open it, I see this format: This is x1: 1,1111111 This is x2: 2,2222222 And yes, the file has to be ***.dat It's not .txt

Confusion about multiprocessing and workers in Keras fit_generator() with windows 10 in spyder

谁说胖子不能爱 提交于 2020-01-02 03:30:10
问题 In the documentation for fit_generator() (docs: https://keras.io/models/sequential/#fit_generator) it says that the parameter use_multiprocessing accepts a bool that if set to True allows process-based threading. It also says that the parameter workers is an integer that designates how many process to spin up if using process-based threading. Apparently it defaults to 1 (a single process based thread) and if set to 0 it will execute the generator on the main thread. What I thought this meant

Missing dependencies causing Keyring error when opening Spyder3 on Ubuntu18?

六月ゝ 毕业季﹏ 提交于 2020-01-02 02:46:09
问题 I'm fairly new to programming and such. I'm trying to use Spyder3, and I keep getting this error (below). I am using Geforce 1080ti, Ubuntu 18.04.01, python3.3.6, python2 is not installed. I tried $ pip3 install keyring, which is now installed but still receiving error. $ spyder3 Error initializing plugin EntryPoint('Windows (alt)', 'keyrings.alt.Windows', None, Distribution('keyrings.alt', '3.0')). Traceback (most recent call last): File "/home/usr/.local/lib/python3.6/site-packages/keyring

Can you overload the Python 3.6 f-string's “operator”?

戏子无情 提交于 2020-01-02 00:59:08
问题 In Python 3.6, you can use f-strings like: >>> date = datetime.date(1991, 10, 12) >>> f'{date} was on a {date:%A}' '1991-10-12 was on a Saturday' I want to overload the method receiving the '%A' above. Can it be done? For example, if I wanted to write a dumb wrapper around datetime , I might expect this overloading to look something like: class MyDatetime: def __init__(self, my_datetime, some_other_value): self.dt = my_datetime self.some_other_value = some_other_value def __fstr__(self,