python-3.6

requests.get in python giving connection timeout error

試著忘記壹切 提交于 2019-12-07 14:35:52
问题 Language Ver: Python 3.6.3 IDE Ver: PyCharm 2017.2.3 I was trying to parse a weather website to print weather for a place. As I am learning Python, previously I used urllib.request.urlopen(url).read() and it worked. Now, I am modifying the code to BeautifulSoup4 and requests module. Below is my code: from bs4 import * import requests url = "https://www.accuweather.com/en/in/dhenkanal/189844/weather-forecast/189844" data = requests.get(url) soup = BeautifulSoup(data.text, "html.parser") print

No module named openpyxl - Python 3.6 - OSX

陌路散爱 提交于 2019-12-07 09:49:25
I've installed openpyxl from the Terminal using pip3 install openpyxl without any problems. I've even double-checked by simply running import openpyxl from the Terminal window once Python is running, and it imports no problem. The problem starts when I try and import openpyxl from a script I'm building to work with a spreadsheet. I'm using Sublime Text and can't even get past the import openpyxl at the beginning of the script without running into the following error: Traceback (most recent call last): File "/Users/wcw/Desktop/test.py", line 1, in import openpyxl ImportError: No module named

Rounding to specific numbers in Python 3.6

会有一股神秘感。 提交于 2019-12-07 07:05:03
问题 I'm trying to make a dive table that has some numbers that aren't in a pattern that I can see so I have to manually add all the values, but I need to grab the input and round it to the nearest number in the dictionary. I'll need to convert the input back to string for the output to be correct: CODE: class DepthTable: def __init__(self): self.d35 = {"10": "A", "19": "B", "25": "C", "29": "D", "32": "E", "36": "F", } def getpressureGroup(self, depth, time): if depth == "35": output = self.d35

How to call a async function from a synchronized code Python

陌路散爱 提交于 2019-12-07 05:54:00
问题 So I'm locked to a python 3.6.2 interpreter that follows my desktop application. What I want is to call an async function from a synchronized method or function. When calling the python function from the desktop application it has to be a normal function which can not be awaited. From the desktop application I am able to send a list of urls, and what I want is to send back response from every url in an async matter. here is my try I've marked the SyntaxError which I don't know how to bypass.

PyCharm and f-strings

╄→гoц情女王★ 提交于 2019-12-07 04:38:18
问题 I am using the latest stable PyCharm 2016.1.4 and Python 3.6a1. Whenever I use the "f-strings" (PEP-498) PyCharm is complaining about f being an unresolved reference : Is the literal string interpolation not supported by PyCharm yet? Or, should I have enabled or configured it separately? 回答1: The Literal String Interpolation is now supported in PyCharm 2016.3, the relevant feature request: PY-18972 implement support for PEP 498 (f-strings) Note that the stable 3.6 is scheduled to be released

ModuleNotFoundError: Python 3.6 does not find modules while Python 3.5 does

别等时光非礼了梦想. 提交于 2019-12-07 02:21:41
问题 I wanted to upgrade my python version from 3.5 to 3.6. Since I am using WinPython, I have downloaded and installed the recent version just as I did it before with version 3.5. However, if I use version 3.6 I get a ModuleNotFoundError whenever I import a self-created module. A minimal example: I created a file t1.py that contains only a pass statement and a file t2.py containing the following code: import t1 print("done") Both files are in the same folder D:\MyProject\src . Now when I run the

Transform string to f-string

一世执手 提交于 2019-12-06 22:41:50
问题 How do I transform a classic string to an f-string ? : variable = 42 user_input = "The answer is {variable}" print(user_input) The answer is {variable} f_user_input = # Here the operation to go from a string to an f-string print(f_user_input) The answer is 42 回答1: An f-string is syntax , not an object type. You can't convert an arbitrary string to that syntax, the syntax creates a string object, not the other way around. I'm assuming you want to use user_input as a template, so just use the

Tensorflow: AttributeError: 'NoneType' object has no attribute 'original_name_scope'

人走茶凉 提交于 2019-12-06 20:28:28
I am trying to run some python tensorflow code on a debian 9.5 stretch system on google cloud. I am Using tensorflow GPU version of this (the latest version) with the approriate CODA and cuDNN software installed. Here is my code: import tensorflow as tf mnist = tf.keras.datasets.mnist (x_train, y_train),(x_test, y_test) = mnist.load_data() x_train = tf.keras.utils.normalize(x_train, axis=1) # scales all values between 0 and 1 on pixel image x_test = tf.keras.utils.normalize(x_test, axis=1) model = tf.keras.models.Sequential() model.add (tf.keras.layers.Flatten()) # flattens the 28x28 pixels

How to create a self-referential Python 3 Enum?

自闭症网瘾萝莉.ら 提交于 2019-12-06 18:55:39
问题 Can I create an enum class RockPaperScissors such that ROCK.value == "rock" and ROCK.beats == SCISSORS , where ROCK and SCISSORS are both constants in RockPaperScissors ? 回答1: Enum members are instances of the type. This means you can just use a regular property: from enum import Enum class RockPaperScissors(Enum): Rock = "rock" Paper = "paper" Scissors = "scissors" @property def beats(self): lookup = { RockPaperScissors.Rock: RockPaperScissors.Scissors, RockPaperScissors.Scissors:

What are formatted string literals in Python 3.6?

╄→гoц情女王★ 提交于 2019-12-06 17:12:40
问题 One of the features of Python 3.6 are formatted strings. This SO question(String with 'f' prefix in python-3.6) is asking about the internals of formatted string literals, but I don't understand the exact use case of formatted string literals. In which situations should I use this feature? Isn't explicit better than implicit? 回答1: Simple is better than complex. So here we have formatted string. It gives the simplicity to the string formatting, while keeping the code explicit (comprared to