python

What is the value of C _PyTime_t in Python

左心房为你撑大大i 提交于 2021-02-20 18:57:26
问题 When sleeping for a long time (like running time.sleep(3**3**3) ) in Python 3, the program returns an OverflowError with the error message "timestamp too large to convert to C _PyTime_t". What is the largest time length I can sleep? 回答1: The value should be 9223372036.854775, which is "is the maximum value for a 64-bit signed integer in computing". See this Wikipedia article. Mentioning of _PyTime_t in PEP 564: The CPython private "pytime" C API handling time now uses a new _PyTime_t type:

ImportError: No module named SpeechRecognition

冷暖自知 提交于 2021-02-20 18:56:06
问题 My code is import SpeechRecognition as sr # obtain audio from the microphone r = sr.Recognizer() with sr.Microphone() as source: print("Say something!") audio = r.listen(source) # recognize speech using Microsoft Bing Voice Recognition BING_KEY = "Somevalue" # Microsoft Bing Voice Recognition API keys 32-character lowercase hexadecimal strings try: print("Microsoft Bing Voice Recognition thinks you said " + r.recognize_bing(audio, key=BING_KEY)) except sr.UnknownValueError: print("Microsoft

Merging Dataframe chunks in Pandas

纵然是瞬间 提交于 2021-02-20 18:54:42
问题 I currently have a script that will combine multiple csv files into one, the script works fine except that we run out of ram really quickly when larger files start being used. This is an issue for one reason, the script runs on an AWS server and running out of RAM means a server crash. Currently the file size limit is around 250mb each, and that limits us to 2 files, however as the company I work is in Biotech and we're using Genetic Sequencing files, the files we use can range in size from

Merging Dataframe chunks in Pandas

…衆ロ難τιáo~ 提交于 2021-02-20 18:54:40
问题 I currently have a script that will combine multiple csv files into one, the script works fine except that we run out of ram really quickly when larger files start being used. This is an issue for one reason, the script runs on an AWS server and running out of RAM means a server crash. Currently the file size limit is around 250mb each, and that limits us to 2 files, however as the company I work is in Biotech and we're using Genetic Sequencing files, the files we use can range in size from

How to read in IRAF multispec spectra?

折月煮酒 提交于 2021-02-20 18:53:45
问题 I have a spectrum in a fits file that I generated with Iraf. The wavelength axis is encoded in the header as: WAT0_001= 'system=multispec' WAT1_001= 'wtype=multispec label=Wavelength units=angstroms' WAT2_001= 'wtype=multispec spec1 = "1 1 2 1. 2.1919422441886 4200 0. 452.53 471' WAT3_001= 'wtype=linear' WAT2_002= '.60 1. 0. 3 3 1. 4200.00000000001 1313.88904209266 1365.65012876239 ' WAT2_003= '1422.67911152069 1479.0560707956 1535.24082980747 1584.94609332243' Is there an easy way to load

What is the best way in python to write docstrings for lambda functions?

让人想犯罪 __ 提交于 2021-02-20 18:52:26
问题 I usually comment my functions using multi-line docstrings with """, as mentioned in : https://www.python.org/dev/peps/pep-0257/ def func1(x): """ This function does ... """ ... But what is the best way to comment a lambda function ? I hesitate between : # This function does ... func2 = lambda x: ... or : func2 = lambda x: ... """ This function does ... """ or else ? 回答1: tbh, even assigning a lambda to a variable seems unpythonic to me. if it needs a name, define it as a regular function.

Creating unique list of objects from multiple lists

我们两清 提交于 2021-02-20 18:50:18
问题 I have defined a custom object with multiple fields. For example say I have a Student object, which consists of a name, ID, and age. To compare two students and determine whether they are the same student or not, I implemented a __ eq__ method that will return whether the age, name, and ID of the two students match up. def __eq__(self, other): return self.name == other.name and self.ID == other.ID and self.age == other.age Bear in mind that the student is just an example, so the fact that

javascript client to Python server: XMLHttpRequest responseText is empty after Get request

佐手、 提交于 2021-02-20 18:50:12
问题 I am trying to write a chrome extension which is able to send/receive data to/from a python server script. Currently, I am at the point where the js script is making a GET request okay, the only issue being that the .responseText is always empty (even though the python script is responding with text). popup.js document.addEventListener('DOMContentLoaded', function() { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState == xhr.DONE) { var resptxt = xhr

Convert seconds to weeks-days-hours-minutes-seconds in Python

喜你入骨 提交于 2021-02-20 18:49:38
问题 I'm trying to code a Python script for 'Enter the number of Seconds' and get results in weeks, days, hours, minutes and seconds. Here is what I have, but I am not getting the correct answers. What am I doing wrong? seconds = raw_input("Enter the number of seconds:") seconds = int(seconds) minutes = seconds/60 seconds = seconds % 60 hours = minutes/60 hours = seconds/3600 minutes = minutes % 60 days = hours/24 days = minutes/1440 days = seconds/86400 hours = hours % 60 hours = minutes % 60

Set and verify SSL/TLS version used in Python MySQL connection

雨燕双飞 提交于 2021-02-20 18:49:06
问题 How can I tell the Python MySQL connector which SSL/TLS protocol to use? Either specific (e.g. TLS1.2) or minimum. How can I check which protocol is used on an established connection? I've got an app that uses mysql-connector-python (8.0.18). I connect something like this: cnx = mysql.connector.connect(user='x', password='y', host='localhost', database='xyz') Usually this gives me no trouble, but recently on a web hosting providers server it stopped working. The error I'm now getting is along