python-3.5

PyCharm doesn't detect interpreter

≯℡__Kan透↙ 提交于 2019-12-21 10:49:52
问题 I'm new to programming and just started a course on Python. I want to use PyCharm, so I downloaded and intalled it (v. 4.5, community edition). I had previously installed Python 3.5 64-bit from python.org (I'm using Windows 10). To start using PyCharm, I need a project interpreter, which I can select in the settings. As far as I'm concerned, the interpreter is "py.exe", but when I select it, I get this error message: "The selected file is not a valid home for Python SDK". I also tried to use

How to create standalone executable file from python 3.5 scripts?

僤鯓⒐⒋嵵緔 提交于 2019-12-21 07:29:52
问题 Most of the programs available only support upto python version 3.4. 回答1: You can use PyInstaller which support python 3.5. To install it with pip execute in terminal: pip install pyinstaller To make the .exe file: pyinstaller --onefile script.py 来源: https://stackoverflow.com/questions/33168229/how-to-create-standalone-executable-file-from-python-3-5-scripts

Cython --embed flag in setup.py

扶醉桌前 提交于 2019-12-21 04:39:06
问题 I am starting to compile my Python 3 project with Cython, and I would like to know if it's possible to reduce my current compile time workflow to a single instruction. This is my setup.py as of now: from distutils.core import setup from distutils.extension import Extension from Cython.Build import cythonize extensions = [ Extension("v", ["version.py"]), Extension("*", ["lib/*.py"]) ] setup( name = "MyFirst App", ext_modules = cythonize(extensions), ) And this is what I run from shell to

Python3 write gzip file - memoryview: a bytes-like object is required, not 'str'

旧街凉风 提交于 2019-12-21 03:42:21
问题 I want to write a file. Based on the name of the file this may or may not be compressed with the gzip module. Here is my code: import gzip filename = 'output.gz' opener = gzip.open if filename.endswith('.gz') else open with opener(filename, 'wb') as fd: print('blah blah blah'.encode(), file=fd) I'm opening the writable file in binary mode and encoding my string to be written. However I get the following error: File "/usr/lib/python3.5/gzip.py", line 258, in write data = memoryview(data)

Pycharm - Python packaging tools not found

社会主义新天地 提交于 2019-12-20 16:24:12
问题 I'm trying to install packages in Pycharm for python3.5 interpreter. It says, Python packaging tools not found. Install packaging tools . But when I try to install, It gives this error. AttributeError: module 'setuptools.dist' has no attribute 'check_specifier' I'm using Ubuntu 16.04.2, Pycharm Community edition 2017.1.1 回答1: Run this command and you should be able to install the packaging tools in Pycharm: sudo apt install python3-pip It's python3-pip, not python-pip if you are using the

Passing asyncio loop by argument or using default asyncio loop

坚强是说给别人听的谎言 提交于 2019-12-20 09:37:26
问题 I'm using asyncio in my application and i'm a litte bit confused about passing the event loop as argument. You've three possibilities when writing a function/method using the event loop : Pass the asyncio event loop as argument Don't use an argument for the event loop and use asyncio.get_event_loop() Make it optional to pass the event loop as argument. If it is not passed, use asyncio.get_event_loop() It seems that the last case is used most of the time but even in the asyncio api the usage

My code works for a single list but not for a nested list. I need to improve it in means of functionality

允我心安 提交于 2019-12-20 07:24:01
问题 I have an assignment to do. I found out how to execute what is required in my own way but the solution is only partial. It doesn't work for a nested list. These are my codes. def calc_averages(): allprices =[ ['', '', '', '', 1.0, 2.0, 1.2, 1.3, 1.1, '', '', ''], ['', '', '', 1.2, 1.0, 2.0, 1.2, 1.3, 1.1, '', '', ''], ['', '', '', 1.2, '', 1.8, 1.3, 1.1, '', '', '', ''], ['', '', '', '', 1.0, 2.0, 1.2, 1.2, '', '', '', ''], ['', '', '', '', 1.0, 2.0, 1.1, 1.2, 1.4, 1.8, 1.9, 2.2] ] averages =

Erratic encoding of byte to string on Python 3 on Ubuntu

时间秒杀一切 提交于 2019-12-20 05:45:08
问题 I'm new to Python and am working on a sensor. I'm building my code line by line and I have trouble with the encoding/decoding part for bytes to string. Same code, sometime it works, sometime it dosen't. Here is the code: import serial import time import os port = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=1, bytesize=8) f_w = open('/home/myname/python_serial_output.txt','r+') port.send_break() while True: op = port.read(2) op_str = op.decode('utf-8') f_w.write(op_str) print(op_str)

np.isnan() == False, but np.isnan() is not False

末鹿安然 提交于 2019-12-19 10:49:11
问题 As far as I understand it, == checks for equality of value, and is checks for identity of structure behind value (as, say === in some other languages). Given that, I don't understand the following: np.isnan(30) == False Out[19]: True np.isnan(30) is False Out[20]: False It appears not to be the case with other identity checks: (5 == 4) == False Out[22]: True (5 == 4) is False Out[23]: True It appears as if np.isnan() returns False as a value, but not as identity. Why is that the case? 回答1:

How to filter a nested dictionary (pythonic way) for a specific value using map or filter instead of list comprehensions?

萝らか妹 提交于 2019-12-19 09:18:46
问题 I've a nested dictionary. >>> foo = {'m': {'a': 10}, 'n': {'a': 20}} >>> I'd like to filter specific values, based on the values of 'a'. I can use list comprehensions for the purpose. >>> [foo[n] for n in foo if foo[n]['a'] == 10] [{'a': 10}] >>> Using list alone gives me the elements from foo (and not the values of the elements) - as expected: >>> list(filter(lambda x: foo[x] if foo[x]['a']==10 else None,foo)) ['m'] >>> Using map returns me unwanted 'None' values: >>> list(map(lambda x: foo