python-3.x

Tkinter window changes dimensions or resolution when I use pyplot

时间秒杀一切 提交于 2021-02-10 14:58:37
问题 First time posting, but have found these forums incredibly helpful with my python learning! I have a problem when I call plt.plot as it's resizing my tkinter window. I've tried this in python 2.7 and 3.5 both seem to have the issue. Below is just some sample code to re-create the problem. You don't even need to show the graph for this problem to be re-created as soon as you plot the data it resizes. Before After from tkinter import * import matplotlib.pyplot as plt x = [1,2,3,4,5] master = Tk

How to pip install to an external drive?

佐手、 提交于 2021-02-10 14:57:13
问题 I have a USB with a python installation that I carry around with me & use on computers that don't have python installed/don't allow you to install modules. I'd like to install a python package onto it but have been having trouble. Let me use the package rebound-cli for example. If I pip install rebound-cli , the package is installed onto my PC installation of python D:\Program Files (x86)\Python36-32 . The directory of my USB python installation is H:\.bin\Program Files\Python . I've tried

How to make a Python set case insensitive? [duplicate]

佐手、 提交于 2021-02-10 14:57:07
问题 This question already has answers here : How to get Case Insensitive Python SET (6 answers) How do I do a case-insensitive string comparison? (9 answers) Closed 2 years ago . I have the following script to import and export random TXT/CSV files from CLI, everything that passes has to be unique and case insensitive output in UTF-8, can I accomplish this with a set variable? I'm quite new to Python so every comment or suggestion is welcome! This is my current script; import hashlib import sys

Cant scrape google search results with beautifulsoup

北慕城南 提交于 2021-02-10 14:55:51
问题 I want to scrape google search results , but whenever i try to do so, the program returns an empty list from bs4 import BeautifulSoup import requests keyWord = input("Input Your KeyWord :") url = f'https://www.google.com/search?q={keyWord}' src = requests.get(url).text soup = BeautifulSoup(src, 'lxml') container = soup.findAll('div', class_='g') print(container) 回答1: To get correct result page from google, specify User-Agent http header. For only english results put hl=en parameter in URL:

How to pip install to an external drive?

情到浓时终转凉″ 提交于 2021-02-10 14:55:10
问题 I have a USB with a python installation that I carry around with me & use on computers that don't have python installed/don't allow you to install modules. I'd like to install a python package onto it but have been having trouble. Let me use the package rebound-cli for example. If I pip install rebound-cli , the package is installed onto my PC installation of python D:\Program Files (x86)\Python36-32 . The directory of my USB python installation is H:\.bin\Program Files\Python . I've tried

Making an object move in an orbit when I have the x and y coordinates

匆匆过客 提交于 2021-02-10 14:53:23
问题 This code is mostly just the generic start up of a pygame window but I'm trying to make it so the object moves (the planet object I've made) in the orbit around the sun object I've made for the coordinates I've given it. I know the x and y values are updating but I don't understand why the object doesn't move. #import the library import pygame import math #classes class button: def _init_ (self,screen, colour, x, y, width,height, letter): self.screen = screen self.colour = colour self.x = x

Making an object move in an orbit when I have the x and y coordinates

我的未来我决定 提交于 2021-02-10 14:53:06
问题 This code is mostly just the generic start up of a pygame window but I'm trying to make it so the object moves (the planet object I've made) in the orbit around the sun object I've made for the coordinates I've given it. I know the x and y values are updating but I don't understand why the object doesn't move. #import the library import pygame import math #classes class button: def _init_ (self,screen, colour, x, y, width,height, letter): self.screen = screen self.colour = colour self.x = x

librosa installation via pip failing

做~自己de王妃 提交于 2021-02-10 14:52:04
问题 Python version is 3.4.2 (env) ishandutta2007@MacBook-Pro:~/Documents/Projects/my_proj$ pip install librosa Collecting librosa Collecting joblib>=0.12 (from librosa) Using cached https://files.pythonhosted.org/packages/69/91/d217cec1fe6eac525ca964cd67e4f79b1d4ce68b64cb82d0b9ae1af2311e/joblib-0.12.5-py2.py3-none-any.whl Collecting numba>=0.38.0 (from librosa) Collecting scikit-learn!=0.19.0,>=0.14.0 (from librosa) Using cached https://files.pythonhosted.org/packages/9b/bc

Assigning elements in a numpy array of zeros

给你一囗甜甜゛ 提交于 2021-02-10 14:51:08
问题 I am trying to draw a "one" on a numpy array np.zeros((28, 28)) by assigning certain rows and columns to 255. I have written the following code: one = np.zeros((28, 28)) one[12:15][5:23] = 255 The output I'm getting after this is a simple array of zeros with no changes. Can anyone please explain this strange behavior? Bonus If you interchange [12:15] and [5:23] , rows 17 to 19 are filled with 255. 回答1: The notation you are using is valid but does something very different from what you expect.

Creating nested dictionaries from a list containing paths

空扰寡人 提交于 2021-02-10 14:50:49
问题 I have a list containing paths. For example: links=['main', 'main/path1', 'main/path1/path2', 'main/path1/path2/path3/path4', 'main/path1/path2/path3/path5', 'main/path1/path2/path3/path4/path6'] I want to create a nested dictionary to store these paths in order. Expected output: Output = {‘main’: {‘path1’: {‘path2’: {‘path3’: {‘path4’: {‘path6’: {} }},‘path5’:{}}}}} I am new to python coding (v 3.+) and I am unable to solve it. It gets confusing after i reach path 3 as there is path 4 (with