python-3.5

difference between LinearRegression and svm.SVR(kernel=“linear”)

不打扰是莪最后的温柔 提交于 2019-12-06 03:45:49
问题 First there are questions on this forum very similar to this one but trust me none matches so no duplicating please. I have encountered two methods of linear regression using scikit's sklearn and I am failing to understand the difference between the two, especially where in first code there's a method train_test_split() called while in the other one directly fit method is called. I am studying with multiple resources and this single issue is very confusing to me. First which uses SVR X = np

How to check if a file is already opened (in the same process)

余生长醉 提交于 2019-12-06 00:04:50
问题 And I'd like to specifically achieve that with the try catch construct. This related question suggests that I can do: try: open(fileName, 'wb+') except: print("File already opened!") raise However, it doesn't work me. I can open the same file multiple times without any problem: fileObj1 = open(fileName, 'wb+') fileObj2 = open(fileName, 'wb+') Is it because I have Python 3.5? Or because I'm using Raspbian? Thanks for the help! 回答1: You open the same file but assign them to different variables.

Can't import Pyperclip

故事扮演 提交于 2019-12-05 20:44:21
I am having trouble importing Pyperclip in IDLE. I am running windows 7 (64-bit). I have Python 3.5.2 Installed on: C:\Python\Python35. I opened command prompt and initiated the install by typing pip install pyperclip after changing directory to C:\Python\Python35\Scripts. It successfully installed Pyperclip-1.5.27. I then went to IDLE and typed in import pyperclip but the following error is showing up: Traceback (most recent call last): File "", line 1, in import pyperclip ImportError: No module named 'pyperclip' I tried to fix this by adding "C:\Python\Python35" to the end of the "Path"

Including Python.h in Qt application causes undefined reference to Qt functions

喜你入骨 提交于 2019-12-05 19:44:28
I'd like to include Python.h (from the Python distribution in my Anaconda folder) in my project to call a python script. The program compiles fine when I don't include python. But as soon as I do, I get undefined reference errors to functions implemented in Qt classes (so not my own functions!). The python version I'd like to include is 3.5.5 . The part that confuses me most is undefined reference to QJsonValue::toString() . This method is implemented inline so how can its implementation not be found? According to QtCreator the problem originates in a compiled object that tries to call this

How to run the Tornado event loop alongside a Kivy GUI?

烂漫一生 提交于 2019-12-05 18:59:10
My client application uses a Kivy GUI (Kivy has its own event loop) and connects to the server using the WebSocket protocol with Tornado (Tornado also has an event loop). That's why the connection part is asynchronous. I want the user to interact with the UI while a Tornado client is running an infinite asynchronous loop of listening for server messages. Here's some example code: client_test.py from tornado.ioloop import IOLoop from tornado.websocket import websocket_connect class RequestSender: url = 'server url here (no scheme)' async def _connect(self): self.conn = await websocket_connect(

tkinter Checkbutton widget returning wrong boolean value

萝らか妹 提交于 2019-12-05 18:32:37
I have a simple GUI here that's suppose to return a boolean value depending on whether the check button is checked or not. I've set the boolean variable to False hence the empty check button. What I don't understand is that when I check the button, the function binded to that widget returns a False instead of True. Why is that? Here's the code... from tkinter import * from tkinter import ttk def getBool(event): print(boolvar.get()) root = Tk() boolvar = BooleanVar() boolvar.set(False) cb = Checkbutton(root, text = "Check Me", variable = boolvar) cb.bind("<Button-1>", getBool) cb.pack() root

How do you call a function in a function?

核能气质少年 提交于 2019-12-05 18:23:37
I saw two other questions like this but they didn't work... So my question is, I have a function, and I'm making another one in which I need to call the first function. I don't have experience in Python, but I know that in languages like Matlab is possible as long as they're in the same directory. A basic example: def square(x): square = x * x (and saved) now in my new function I want to use the function square i tried: def something (y, z) import square something = square(y) + square(z) return something which displays: builtins.TypeError: 'module' object is not callable What should I do? No

Creating a deepcopy of class instance with nested weakref to it

空扰寡人 提交于 2019-12-05 16:20:42
I have two classes: a parent class and a container class. The parent class instance has matching container class instance as a weak reference. There is a problem while deep copying the parent instance, the weakref is still linking to the original instance. Here is a minimal example: import weakref from copy import deepcopy class Container: def __init__(self, parent): self.parent = weakref.ref(parent) class Parent: def __init__(self): self.container = Container(self) if __name__ == '__main__': parent1 = Parent() assert(parent1 is parent1.container.parent()) parent2 = deepcopy(parent1) assert

Python 3 type check not works with use typing module?

北战南征 提交于 2019-12-05 16:14:25
Why does type checking not work in Python 3? I have done the following code with type checks or hints: import typing def hello(message: str): print(type(message)) print(message) hello('Hello!') hello(1) hello(1.1) It produces valid output (but no errors on int or float). <class 'str'> Hello! <class 'int'> 1 <class 'float'> 1.1 Why does it works this way? Maybe I don't understand the typing module and Python hints. Python's type hints are informational only. Type checking or automatic coercion of argument types are not part of the language. See PEP 3107 : Function annotations are nothing more

Boost Python and Cmake with Ubuntu and Python3.5

时间秒杀一切 提交于 2019-12-05 13:46:34
I'm having issues getting Boost Python to compile with Cmake. Everything works fine when compiled manually. Here is how I set everything up and ran it : Install python 3.5 : sudo apt-get install python3-dev Download the lastest version of Boost from http://www.boost.org/ Run bootstrap with correct flags : ./bootstrap.sh --with-python=python3.5 Compile Boost in directory : ./b2 Install Boost headers to /usr/local/include and Boost libs to /usr/lib/x86_64-linux-gnu sudo ./b2 install Compile example with proper flags : g++ greet_binding.cpp -I/usr/include/python3.5m -I/usr/local/include -lboost