python-3.6

Calculate period length of recurring decimal fraction

痞子三分冷 提交于 2020-01-24 19:24:00
问题 I want to do a program in python (3.6.5) that tell the length of e.g. 1/7. The output should be for this example something like: "length: 6, repeated numbers: 142857". I got this so far: n = int(input("numerator: ")) d = int(input("denominator: ")) def t(n, d): x = n * 9 z = x k = 1 while z % d: z = z * 10 + x k += 1 print ("length:", k) print ("repeated numbers:", t) return k, z / d t(n, d) 回答1: Doing print ("repeated numbers:", t) prints the representation of the t function itself, not its

Calculate period length of recurring decimal fraction

会有一股神秘感。 提交于 2020-01-24 19:23:13
问题 I want to do a program in python (3.6.5) that tell the length of e.g. 1/7. The output should be for this example something like: "length: 6, repeated numbers: 142857". I got this so far: n = int(input("numerator: ")) d = int(input("denominator: ")) def t(n, d): x = n * 9 z = x k = 1 while z % d: z = z * 10 + x k += 1 print ("length:", k) print ("repeated numbers:", t) return k, z / d t(n, d) 回答1: Doing print ("repeated numbers:", t) prints the representation of the t function itself, not its

python 3.6: No module named _QuantLib after installation of QuantLib and QuantLib-SWIG

可紊 提交于 2020-01-24 16:56:31
问题 I am trying to install QuantLib and Python QuantLib-SWIG on Mac OSX 10.12.5 Sierra and Python 3.6.1., but get error messages: ImportError: dlopen(build/lib.macosx-10.7-x86_64- 3.6/QuantLib/_QuantLib.cpython-36m-darwin.so, 2): Symbol not found: __ ZN8QuantLib10DateParser14parseFormattedERKSsS2_ Referenced from: build/lib.macosx-10.7-x86_64- 3.6/QuantLib/_QuantLib.cpython-36m-darwin.so Expected in: flat namespace in build/lib.macosx-10.7-x86_64-3.6/QuantLib/_QuantLib.cpython-36m-darwin.so as

Enum Class method with default Enum value fails

╄→尐↘猪︶ㄣ 提交于 2020-01-24 15:29:50
问题 I am well aware that if you have a class method that uses the enum's class name for type hinting, there is a hack to get it to work for Python 3.6 and below. Instead of... class Release(Enum): ... @classmethod def get(cls, release: Release): ... You need to use the string value like so... class Release(Enum): ... @classmethod def get(cls, release: "Release"): ... I believe in Python 3.7 and above there is a pythonic way around this "hack" where you don't have to use quotes. The reason is

Enum Class method with default Enum value fails

大城市里の小女人 提交于 2020-01-24 15:29:28
问题 I am well aware that if you have a class method that uses the enum's class name for type hinting, there is a hack to get it to work for Python 3.6 and below. Instead of... class Release(Enum): ... @classmethod def get(cls, release: Release): ... You need to use the string value like so... class Release(Enum): ... @classmethod def get(cls, release: "Release"): ... I believe in Python 3.7 and above there is a pythonic way around this "hack" where you don't have to use quotes. The reason is

Enum Class method with default Enum value fails

喜你入骨 提交于 2020-01-24 15:29:06
问题 I am well aware that if you have a class method that uses the enum's class name for type hinting, there is a hack to get it to work for Python 3.6 and below. Instead of... class Release(Enum): ... @classmethod def get(cls, release: Release): ... You need to use the string value like so... class Release(Enum): ... @classmethod def get(cls, release: "Release"): ... I believe in Python 3.7 and above there is a pythonic way around this "hack" where you don't have to use quotes. The reason is

f-string with float formatting in list-comprehension

£可爱£侵袭症+ 提交于 2020-01-24 08:59:25
问题 The [f'str'] for string formatting was recently introduced in python 3.6. link. I'm trying to compare the .format() and f'{expr} methods. f ' <text> { <expression> <optional !s, !r, or !a> <optional : format specifier> } <text> ... ' Below is a list comprehension that converts Fahrenheit to Celsius. Using the .format() method it prints the results as float to two decimal points and adds the string Celsius: Fahrenheit = [32, 60, 102] F_to_C = ['{:.2f} Celsius'.format((x - 32) * (5/9)) for x in

Having problems with debugging in .vscode

好久不见. 提交于 2020-01-24 04:37:08
问题 I've had a big problem with debugging in VSCODE lately. I have tried to fix it my self by searching the site and reinstalling some of my extensions. Instead of showing my results in the debug console it writes the following output to my terminal : cd /Users/AVFL/Documents/Programming ; env "PYTHONIOENCODING=UTF-8" PYTHONUNBUFFERED=1" /usr/local/bin/python3 /Users/AVFL/.vscode/extensions/ms-python.python-2018.3.1/pythonFiles/PythonTools/visualstudio_py_launcher.py /Users/AVFL/Documents

Encoding Python Enum to JSON

老子叫甜甜 提交于 2020-01-24 04:32:35
问题 I have a dictionary where some of the keys are Enum instances (subclasses of enum.Enum). I am attempting to encode the dictionary into a JSON string using a custom JSON Encoder class as per the documentation. All I want is to have the keys in the outputted JSON be the strings of the Enum names. For example { TestEnum.one : somevalue } would be encoded to { "one" : somevalue } . I have written a simple test case, shown below, which I have tested in a clean virtualenv: import json from enum

How to create a Locust task for a dynamic list of URLs?

吃可爱长大的小学妹 提交于 2020-01-23 09:20:06
问题 I'm trying to get timing information for all my API endpoints based on the OpenAPI JSON, so I would like to do something like this in the setup method: for api_path in self.client.get('/api/doc/?format=openapi').json()['paths'].keys(): self.get_[api_path] = [@task decorated method which retrieves the API path] Or is there another way to generate tasks at runtime? 回答1: Found it in the API docs: def setup(self) -> None: for api_path in self.client.get('/api/doc/?format=openapi').json()['paths']