python-3.6

Websocket code works on Windows but not Linux

孤街醉人 提交于 2019-12-08 13:30:59
问题 I'm running the same code; the following works in Windows, but will run correctly on Ubuntu (16.04). import websocket import json class WhatEver(object): def __init__(self): self.ws = websocket.WebSocketApp( 'wss://beijing.51nebula.com/', on_message=self.on_ws_message, on_open=self.on_open ) def rin_forever(self): print("start run forever") self.ws.run_forever() def on_ws_message(self, ws,message): print (message) self.ws.close() def _send_msg(self, params): call = {"id": 1, "method": "call",

View does not seem to be saving all the information in my model

只愿长相守 提交于 2019-12-08 11:58:34
问题 I have a model and a view for saving books. However, when I access the information it does not appear to be complete. All queries seem to be running properly. I'm at a loss what could be going wrong my model class Book(models.Model): title = models.CharField(max_length=50) user = models.ForeignKey(CustomUser, on_delete=models.CASCADE,) cover_pic = models.FileField(null=True, blank=True) author = models.CharField(max_length=100, blank=True) description = models.TextField(max_length=1000)

How to resume file download in Python 3.5? [duplicate]

心已入冬 提交于 2019-12-08 08:47:14
问题 This question already has an answer here : How to resume file download in Python? (1 answer) Closed last year . I am using python 3.5 requests module to download a file using the following code, how to make this code "auto-resume" the download from partially downloaded file. response = requests.get(url, stream=True) total_size = int(response.headers.get('content-length')) with open(file_path + file_name, "wb") as file: for data in tqdm(iterable = response.iter_content(chunk_size = 1024),

How can I pickle a python object into a csv file?

百般思念 提交于 2019-12-08 08:17:08
问题 I am trying to pickle a python object into a csv file. I want to write the pickle of an object as the third column in my file. I want to use pickle to avoid writing serialization for my complex objects. Code to write to csv : with open(self.file_path, 'a') as csv_file: wr = csv.writer(csv_file, delimiter='|') row = ['klines', symbol] row.extend(pickle.dumps(object)) wr.writerow(row) Code to read csv : with open(self.simulation_file_name, 'r') as csv_file: line = csv_file.readline() while line

PyQt MainWindow using multiprocessing on Windows

﹥>﹥吖頭↗ 提交于 2019-12-08 07:00:50
问题 I try to create a PyQt application. In order to run process in background and keep the PyQt5 application available for new instruction, I want to use multiprocessing . On the Windows OS, when I call a function from the Qt MainWindow class with multiprocessing.process , I have an error about pickling this class. But it is running find on Linux. Here is an example: #!/usr/bin/env python3 # -*- coding: utf-8 -*- import sys import multiprocessing # from PyQt5.QtWidgets import * from PyQt5.QtGui

cx_freeze ImportError: No module named 'idna'

孤街醉人 提交于 2019-12-08 04:14:02
问题 I'm using python 3.6 Trying to make and exe from my .py file. but when I run python setup.py build it give me an error raise ImportError("No module named %r" % name) ImportError: No module named 'idna' My setup file is like this setup file 回答1: Save: # thanks to https://www.youtube.com/watch?v=GSoOwSqTSrs from cx_Freeze import setup, Executable setup( name='KutsalAklinNerde?', version='0.1', #Further information about its version description='Parse stuff', #It's description executables=

Removal of substring from all dataframe columns

只谈情不闲聊 提交于 2019-12-07 22:30:46
问题 I have a list of words(around 1000 words), I call them negative words. ['CAST','ARTICLES','SANITARY','JAN','CLAUSES','SPECIAL','ENDORSEMENT'] I'll soon be making a dataframe out of this list of words. I also have a dataframe which looks like - FileName PageNo LineNo GOODS_DESC 1 17668620 TM000004 36 CAST ARTICLES IRON SANITARY 59 17668620 TM000014 41 CRATES 60 17668620 TM000014 42 CAST ARTICLES IRON 61 17668620 TM000014 49 JAN ANIMAL AND VEGETABLE 63 17668620 TM000016 49 SETTLING AGENT 65

How to bind async method to a keystroke in Tkinter?

柔情痞子 提交于 2019-12-07 18:52:06
问题 Consider the following example: import asyncio import tkinter as tk class App(tk.Tk): def __init__(self): super().__init__() self.create_widgets() self._configure_bindings() # I believe it is not possible # to do this if the method needs # to be async as well def create_widgets(self): pass def _configure_bindings(self): self.bind('<F5>', self.spam) # what's the proper way? # does this method need to be async as well? async def spam(self, event): await self.do_something() async def do

How can I pickle a python object into a csv file?

不问归期 提交于 2019-12-07 15:29:30
I am trying to pickle a python object into a csv file. I want to write the pickle of an object as the third column in my file. I want to use pickle to avoid writing serialization for my complex objects. Code to write to csv : with open(self.file_path, 'a') as csv_file: wr = csv.writer(csv_file, delimiter='|') row = ['klines', symbol] row.extend(pickle.dumps(object)) wr.writerow(row) Code to read csv : with open(self.simulation_file_name, 'r') as csv_file: line = csv_file.readline() while line != '': line = line.strip('\n') columns = line.split('|') event_type = line.pop(0) symbol = line.pop(0)

Error building executable with cx_Freeze: IndexError: tuple index out of range

半腔热情 提交于 2019-12-07 15:15:28
Background I have made a program that I am trying to turn into an executable using CX_Freeze. The setup.py file is placed inside the same directory as all files I am working with. I don't use any extra libraries other than TKinter and OS. The program works perfectly fine normally when I run it via PyCharm>Run Version Numbers cx_Freeze ver: - 5.0 cx_Freeze .whl: - cx_Freeze-5.0-cp36-cp36m-win_amd64.whl python ver: - 3.6.0b4 pycharm ver: - 2016.3.1 This is my setup.py file import cx_Freeze import sys from cx_Freeze import setup, Executable base = None if sys.platform == 'win32': base = "Win32GUI