python-3.x

Continuously Update A File

五迷三道 提交于 2021-02-19 07:17:09
问题 Ultimately I need to make info from the Spotify API available to an app that will display "current song" info, including cue time. So will need to be continuously polling the API, as well as updating the data source the App is polling. I'm still trying to wrap my head around thinking of data in terms of streams as opposed to files. So I came up with this little experiment for how a file can be continuously updated: import itertools for i in itertools.count(start=0, step=1): f = open('info.txt

Continuously Update A File

浪尽此生 提交于 2021-02-19 07:16:07
问题 Ultimately I need to make info from the Spotify API available to an app that will display "current song" info, including cue time. So will need to be continuously polling the API, as well as updating the data source the App is polling. I'm still trying to wrap my head around thinking of data in terms of streams as opposed to files. So I came up with this little experiment for how a file can be continuously updated: import itertools for i in itertools.count(start=0, step=1): f = open('info.txt

Python Class: Singleton or Not Singleton by Passing a Value?

ε祈祈猫儿з 提交于 2021-02-19 07:06:41
问题 I have a Python 3 class that is currently a singleton defined using a @singleton decorator, but occasionally it needs to not be a singleton. Question: Is it possible to do something similar to passing a parameter when instantiating an object from the class and this parameter determines whether the class is a singleton or not a singleton? I am trying to find an alternative to duplicating the class and making that not a singleton, but then we will have tons of duplicated code. Foo.py def

How can I make class properties immutable?

 ̄綄美尐妖づ 提交于 2021-02-19 06:52:06
问题 @property is a nice way to define getters. When the property is mutable, the reference returned can be used to modify the property in ways not controlled by the class definition. I'll use a banana stand as a motivating analogy, but this issue applies to any class that wraps a container. class BananaStand: def __init__(self): self._money = 0 self._bananas = ['b1', 'b2'] @property def bananas(self): return self._bananas def buy_bananas(self, money): change = money basket = [] while change >= 1

pyinstaller and geckodriver generate issue after compile to exe

a 夏天 提交于 2021-02-19 06:24:05
问题 I hope i will get help here. I'm writing program who will read and export to txt 'devices live logging events' every two minutes. Everything works fine until i generate exe file. What is more interesting, program works on my enviroment(geckodriver and python libraries installed), but does not work on computers without python enviroment. Even if I generate exe with --onedir. Any ideas or tips? part of code is below(without tkinter): browser = webdriver.Firefox() def logs(): global writing

Convert canvas' mouse coords to geographic coords

落爺英雄遲暮 提交于 2021-02-19 06:10:51
问题 I'm trying to create a map with all the cities of Italy using Python-Tkinter and Canvas . I found a picture of a map of Italy with a few highlighted cities online and inserted it to my Canvas . After that I used a function to determine what are the canvas coordinates of the 2 highlighted cities using: import tkinter as tk class Map(): #Creator-Function def __init__(self,parent): self.canvas=tk.Canvas(width=995,height=971,bg='black') self.canvas.pack(expand=0,fill='none') self.gif=tk

Convert canvas' mouse coords to geographic coords

非 Y 不嫁゛ 提交于 2021-02-19 06:10:18
问题 I'm trying to create a map with all the cities of Italy using Python-Tkinter and Canvas . I found a picture of a map of Italy with a few highlighted cities online and inserted it to my Canvas . After that I used a function to determine what are the canvas coordinates of the 2 highlighted cities using: import tkinter as tk class Map(): #Creator-Function def __init__(self,parent): self.canvas=tk.Canvas(width=995,height=971,bg='black') self.canvas.pack(expand=0,fill='none') self.gif=tk

How to solve azure keyvault secrets (Unauthorized) AKV10032: Invalid issuer. error in Python

那年仲夏 提交于 2021-02-19 05:55:07
问题 I am using the azure-keyvault-secrets package to manage my resources secrets in Python 3.8, developping in PyCharm. But when I am running the following: import os from azure.keyvault.secrets import SecretClient from azure.identity import DefaultAzureCredential VAULT_URL = os.environ["VAULT_URL"] credential = DefaultAzureCredential() client = SecretClient( vault_url=VAULT_URL, credential=credential ) client.set_secret('my-secret-name', 'my-secret-value') I get the following error:

Conecting to MySQL in a remote server from python

♀尐吖头ヾ 提交于 2021-02-19 05:46:07
问题 I'm using Python 3.5, pymysql 0.7.6 on MacOS X 10.12. I'm trying to use python to access a MySQL database in a remote server. I have no problems to access from the command line using: ssh root@XXX.XXX.XXX.XXX root@XXX.XXX.XXX.XXX's password: my_server_password and then in the server: mysql my_database -p Enter password: my_database_password And it works and I can do all sort of things with my database. Now, I try to do the same within python, following the documentation or the numerous

Python: Automatically reconnect ssh tunnel after remote server gone down

匆匆过客 提交于 2021-02-19 05:32:30
问题 I have implemented a function to establish an ssh-tunnel in Python, so I can insert data in a DB behind a NAT (no port forwarding available). import paramiko from sshtunnel import SSHTunnelForwarder def fnc_ssh_tunnel(): try: sshServer = SSHTunnelForwarder( (SSH_IP, SSH_PORT), ssh_username = SSH_USER, ssh_password = SSH_PASS, set_keepalive = float(SSH_KEEP_ALIVE), remote_bind_address = (DB_IP, DB_PORT), ) sshServer.start() localPort = sshServer.local_bind_port logPrint("SSH Tunnel Started to