python-3.6

Are sets ordered like dicts in python3.6

与世无争的帅哥 提交于 2019-11-27 01:33:35
Due to changes in dict implementation in Python 3.6 it is now ordered by default. Do set s preserve order as well now? I could not find any information about it but as both of those data structures are very similar in the way they work under the hood I thought it might be the case. I know there is no promise for dict s to be ordered in all cases but they are most of the time. As stated in Python docs: The order-preserving aspect of this new implementation is considered an implementation detail and should not be relied upon No, set s are still unordered. You can verify this just by displaying a

f-strings in Python 3.6

我们两清 提交于 2019-11-27 01:17:39
I really like to delve into code style and it's interesting to know whether from now on in all cases it would be better to use the new style. I'm using a lot the .format() in my Python 3.5 projects, and I'm afraid that it will be deprecated during the next Python versions because of this new kind of string literals. >>> name = "Test" >>> f"My app name is {name}." 'My app name is Test.' Does the formatted string feature come to fully replace the old format() ? I understand that it based on the idea that: Simple is better than complex. However, what about performance issues, does any difference

Microsoft Windows Python-3.6 PyCrypto installation error

时间秒杀一切 提交于 2019-11-27 00:31:07
pip install pycrypto works fine with python3.5.2 but fails wiht python3.6 with the following error: inttypes.h(26): error C2061: syntax error: identifier 'intmax_t' The file include\pyport.h in Python installation directory does not have #include < stdint.h > anymore. This leaves intmax_t undefined. A workaround for Microsoft VC compiler is to force include stdint.h via OS environment variable CL : Open command prompt Setup VC environment by runing vcvars*.bat (choose file name depending on VC version and architecture) set CL=-FI"Full-Path\stdint.h" (use real value for Full-Path for the

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

限于喜欢 提交于 2019-11-26 23:16:06
问题 This question already has an answer here: Can existing virtualenv be upgraded gracefully? 5 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

SyntaxError: unexpected EOF while parsing

江枫思渺然 提交于 2019-11-26 22:46:04
问题 I am getting error while running this part of the code. tried some of the existing solutions, none of them helped elec_and_weather = pd.read_csv(r'C:\HOUR.csv', parse_dates=True,index_col=0) # Add historic DEMAND to each X vector for i in range(0,24): elec_and_weather[i] = np.zeros(len(elec_and_weather['DEMAND'])) elec_and_weather[i][elec_and_weather.index.hour==i] = 1 # Set number of hours prediction is in advance n_hours_advance = 24 # Set number of historic hours used n_hours_window = 24

How to use type hints in python 3.6?

本秂侑毒 提交于 2019-11-26 22:22:49
I noticed python 3.5 and python 3.6 added a lot of features about static type checking, so I tried with the following code(in python 3.6, stable version). from typing import List a: List[str] = [] a.append('a') a.append(1) print(a) What surprised me was that, python didn't give me an error or warning, although 1 was appended to a list which should only contain strings. Pycharm detected the type error and gave me a warning about it, but it was not obvious and it was not shown in the output console, I was afraid sometimes I might miss it. I would like the following effects: If it's obvious that

ModuleNotFoundError: What does it mean __main__ is not a package?

∥☆過路亽.° 提交于 2019-11-26 17:16:42
I am trying to run a module from the console. The structure of my directory is this: I am trying to run the module p_03_using_bisection_search.py , from the problem_set_02 directory using: $ python3 p_03_using_bisection_search.py The code inside p_03_using_bisection_search.py is: __author__ = 'm' from .p_02_paying_debt_off_in_a_year import compute_balance_after def compute_bounds(balance: float, annual_interest_rate: float) -> (float, float): # there is code here, but I have omitted it to save space pass def compute_lowest_payment(balance: float, annual_interest_rate: float) -> float: # there

conda install python=3.6 UnsatisfiableError

ⅰ亾dé卋堺 提交于 2019-11-26 16:58:17
问题 I currently have Python 3.5.2 installed via Anaconda Continuum. I'm trying to upgrade to Python 3.6 but I'm getting the below error when I try to run conda install python=3.6 : UnsatisfiableError: The following specifications were found to be in conflict: - enum34 -> python 2.6*|2.7*|3.3*|3.5* - python ==3.6.0 Use "conda info " to see the dependencies for each package. What might be causing this? 回答1: You have enum34 installed, which requires 2.6-3.5. Installing Python 3.6 is thus not

Nested f-strings

喜欢而已 提交于 2019-11-26 16:38:52
问题 Thanks to David Beazley's tweet, I've recently found out that the new Python 3.6 f-strings can also be nested: >>> price = 478.23 >>> f"{f'${price:0.2f}':*>20s}" '*************$478.23' Or: >>> x = 42 >>> f'''-{f"""*{f"+{f'.{x}.'}+"}*"""}-''' '-*+.42.+*-' While I am surprised that this is possible, I am missing on how practical is that, when would nesting f-strings be useful? What use cases can this cover? Note: The PEP itself does not mention nesting f-strings, but there is a specific test

String with 'f' prefix in python-3.6

烂漫一生 提交于 2019-11-26 16:13:34
I'm trying out Python 3.6. Going through new code, I stumbled upon this new syntax: f"My formatting string!" It seems we can do things like this: >>> name = "George" >>> print(f"My cool string is called {name}.") My cool string is called George. Can anyone shed some light on the inner workings of this? In particular what is the scope of the variables that an f-prefixed string can take? Kwong Leong See PEP 498 Literal String Interpolation : The expressions that are extracted from the string are evaluated in the context where the f-string appeared. This means the expression has full access to