python-3.5

Cooperative yield in asyncio

爷,独闯天下 提交于 2019-12-13 02:38:18
问题 I'm running a long CPU-intensive task on a (tornado) webserver. I don't want to offload this task to a thread (for now). How do I correctly "yield" control during this long-running task to the eventloop, so that web requests are still being served (note: I'm using "yield" in a cooperative-scheduling sense here, not in a generator-sense, or the python keyword yield ). My suggestion would be to do an await asyncio.sleep(0) , however is there a guarantee that this is not just implemented as a

Pyparsing OR operation use shortest string when more than two match

徘徊边缘 提交于 2019-12-12 23:40:57
问题 I need to parse some statements but want the flexibility of using multiple words to signal the of the statement. eg. string = """ start some statement end other stuff in between start some other statement. other stuff in between start another statement """ in this case end , . and end of line are the tokens that will signal the end of the statement I am looking for. I tried the following: from pyparsing import restOfLine, SkipTo skip_to_end_of_line = restOfLine skip_to_dot = SkipTo('.',

Python 3.6 Path Confusion

心已入冬 提交于 2019-12-12 22:45:26
问题 I'm having issues when running the "python3" command along with "pip3" to install several python modules. It seems like my pip3 is linked to python 3.6 (which is what I want to use), but python3 is linked to 3.5. See below : pip3 --version pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6) python3 --version Python 3.5.2 I'd like to run python3.6, and I am thinking that my PATH variable may be incorrect (or something to that extent). Thanks 回答1: configure your .bash_profile

Error while installing cv2 in pycharm - python 3.5.3

旧城冷巷雨未停 提交于 2019-12-12 18:19:24
问题 I am getting error while installing cv2 package from project interpreter. Error occured: Non zero exit code(1) When I execute command, pip install cv2..it gives error as, Could not find a version that satisfies the requirement cv2(from versions: )No matching distribution found for cv2 Please help me solve this error. 回答1: The package name is actually opencv-python . So you should do: pip install opencv-python However, the package is only available on pypi for version 3, not for version 2. I

Python3.5 installation fails: cannot open libpython3.5m.so.1.0

雨燕双飞 提交于 2019-12-12 12:47:11
问题 I'm trying to install Python 3.5.2 on CentOS 7. The build appears to succeed, but executing python3 elicits python3: error while loading shared libraries: libpython3.5m.so.1.0: cannot open shared object file: No such file or directory I checked this question as the only link that appeared to help. ldd does show the file as missing, and it does not seem to exist anywhere, although /usr/lib/libpython3.5m.so exists. By any chance, is /usr/lib/libpython3.5m.so the correct file? I have no problem

Unable to unbind a function using tkinter

僤鯓⒐⒋嵵緔 提交于 2019-12-12 12:33:40
问题 I am working with Tkinter in Python 3.5 and I encounter a weird problem. I used the tkinterbook about events and bindings to write this simple example: from tkinter import * root = Tk() frame = Frame(root, width=100, height=100) def callback(event): print("clicked at", event.x, event.y) # frame.unbind("<Button-1>", callback) frame.bind("<Button-1>", callback) frame.pack() root.mainloop() It works fine, but if I try to unbind the callback (just uncomment the line), it fails with the following

Iterate over all items in json object

梦想与她 提交于 2019-12-12 10:28:10
问题 After loading json from a file via data = json.load(fp) I want to iterate over all items that were in json, excluding of course all special Python symbols. How is this done properly? 回答1: data should be an ordinary collection at this point, so you'd iterate over it the same way you'd iterate over any other list/dict/whatever. The fact that it came from load doesn't incur any extra requirements on your part. Here's an example that uses loads , which is similar in principle: import json my_json

UnicodeDecodeError, utf-8 invalid continuation byte

淺唱寂寞╮ 提交于 2019-12-12 09:42:47
问题 I m trying to extract lines from a log file , using that code : with open('fichier.01') as f: content = f.readlines() print (content) but its always makes the error statement Traceback (most recent call last): File "./parsepy", line 4, in <module> content = f.readlines() File "/usr/lib/python3.5/codecs.py", line 321, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 2213: invalid continuation byte

python 3.5 in statsmodels ImportError: cannot import name '_representation'

那年仲夏 提交于 2019-12-12 08:47:21
问题 I cannot manage to import statsmodels.api correctly when i do that I have this error: File "/home/mlv/.local/lib/python3.5/site-packages/statsmodels/tsa/statespace/tools.py", line 59, in set_mode from . import (_representation, _kalman_filter, _kalman_smoother, ImportError: cannot import name '_representation' I already try to re-install or update it, that does not change. plese i need help =) 回答1: Please see the github report for more detail. It turns out that statsmodels is dependent upon

Python 3 UnicodeEncodeError: 'ascii' codec can't encode characters

爱⌒轻易说出口 提交于 2019-12-12 08:43:30
问题 I've just started to learn Python but I already ran into troubles. I have a simple script with just one command: #!/usr/bin/env python3 print("Příliš žluťoučký kůň úpěl ďábelské ódy.") # Text in Czech When I try to run this script: python3 hello.py I get this message: Traceback (most recent call last): File "hello.py", line 2, in <module> print("P\u0159\xedli\u0161 \u017elu\u0165ou\u010dk\xfd k\u016fn \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy.") UnicodeEncodeError: 'ascii' codec can't encode