io

How to create dynamic plots to display on Flask?

烈酒焚心 提交于 2020-01-22 05:32:04
问题 I wish to create dynamic plots based on user input on a flask app. However I am getting the following error: string argument expected, got 'bytes' If I use io.BytesIO(), I am not getting this error, but I am not getting the plot on test.html from flask import Flask from flask import render_template import matplotlib.pyplot as plt import io import base64 app = Flask(__name__) @app.route('/plot') def build_plot(): img = io.StringIO() y = [1,2,3,4,5] x = [0,2,1,3,4] plt.plot(x,y) plt.savefig(img

IO

这一生的挚爱 提交于 2020-01-22 03:54:02
【IO input output】 在内存中存在数据交换的操作都可以认为是输入输出 比如: 内存和磁盘交互 读写操作 内存和网络交互 recv send IO密集型程序:程序执行大量的IO操作,而较少的cpu运算 特点:消耗cpu较少,运行时间长 CPU密集型程序(计算密集型):程序中大量的操作都需要cpu运算,IO操作较少 特点:消耗cpu大,运行速度快 IO分类: 阻塞IO 非阻塞IO IO多路复用 事件IO 异步IO 阻塞IO: 默认形态 效率很低的一种IO情形 阻塞情况: 1. 因为某种条件没有达成造成的阻塞 e.g. accept recv input 2. 处理IO事件的时候耗时比较长形成阻塞 e.g. 文件的读写过程,网络数据发送过程 非阻塞IO: 通过修改IO事件的属性,使其变为非阻塞的状态。(改变了第一种阻塞的状况) 通常和循环搭配使用,不断检测循环条件是否已经满足 s.setblocking() 功能:将套接字设置成非阻塞状态 参数:bool 设置为False则表示设置为非阻塞 示例: # block_server.py from socket import * from time import sleep , ctime s = socket ( ) s . bind ( ( '127.0.0.1' , 8888 ) ) s . listen ( 5 ) #

Write file need to optimised for heavy traffic part 3

…衆ロ難τιáo~ 提交于 2020-01-22 00:46:10
问题 this question is a continuation of the first 2 part, anyone who is interested to see where I come from you can refer to part 1 and part 2, but it is not necessary. write file need to optimised for heavy traffic Write file need to optimised for heavy traffic part 2 now i have a working snippet, the relevant part is below: public static class memoryStreamClass { static MemoryStream ms1 = new MemoryStream(); public static void fillBuffer(string outputString) { byte[] outputByte = Encoding.ASCII

Write array to file by columns

房东的猫 提交于 2020-01-21 16:44:49
问题 Is there a way to write columns to a file one by one? For example, I would like to write: write(1,*) 1 write(1,*) 2 And then write (possibly in another subroutine) write(1,*) 3 write(1,*) 4 in such a way that will produce an output file in the format: 1 3 2 4 without combining the arrays (e.g.) write(1,*) 1,3 write(1,*) 2,4 I'm thinking that there may be a way to move the "pointer" (of file location) back to the beginning and add spaces or something, but I really have no idea if this is

Write array to file by columns

风流意气都作罢 提交于 2020-01-21 16:43:12
问题 Is there a way to write columns to a file one by one? For example, I would like to write: write(1,*) 1 write(1,*) 2 And then write (possibly in another subroutine) write(1,*) 3 write(1,*) 4 in such a way that will produce an output file in the format: 1 3 2 4 without combining the arrays (e.g.) write(1,*) 1,3 write(1,*) 2,4 I'm thinking that there may be a way to move the "pointer" (of file location) back to the beginning and add spaces or something, but I really have no idea if this is

how to update the contain in .txt file java [closed]

…衆ロ難τιáo~ 提交于 2020-01-21 08:32:00
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . for example i have the file named file.txt which contain personal information (id,name, salary): A123 Anna 3000 A234 Alex 4000 A986 Jame 5000 How can I write a java code that allow user to enter an ID of a person

how to update the contain in .txt file java [closed]

大兔子大兔子 提交于 2020-01-21 08:31:11
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . for example i have the file named file.txt which contain personal information (id,name, salary): A123 Anna 3000 A234 Alex 4000 A986 Jame 5000 How can I write a java code that allow user to enter an ID of a person

python PIL image how to save image to a buffer so can be used later?

拥有回忆 提交于 2020-01-21 07:49:05
问题 I have a png file which should be convert to jpg and save to gridfs , I use python's PIL lib to load the file and do the converting job, the problem is I want to store the converted image to a MongoDB Gridfs, in the saving procedure, I can't just use the im.save() method. so I use a StringIO to hold the temp file but it don't work. here is the code snippet: #!/usr/bin/env python # -*- coding: utf-8 -*- from PIL import Image from pymongo import MongoClient import gridfs from StringIO import

python PIL image how to save image to a buffer so can be used later?

China☆狼群 提交于 2020-01-21 07:49:05
问题 I have a png file which should be convert to jpg and save to gridfs , I use python's PIL lib to load the file and do the converting job, the problem is I want to store the converted image to a MongoDB Gridfs, in the saving procedure, I can't just use the im.save() method. so I use a StringIO to hold the temp file but it don't work. here is the code snippet: #!/usr/bin/env python # -*- coding: utf-8 -*- from PIL import Image from pymongo import MongoClient import gridfs from StringIO import

Using overlapped IO for console input?

独自空忆成欢 提交于 2020-01-20 05:03:45
问题 I'm attempting to use overlapped IO to read input from the console by opening CONIN$ with the FILE_FLAG_OVERLAPPED flag. However, ReadFile blocks when I use it, even with an OVERLAPPED parameter. I've read some posts reporting that this is a Windows 7 bug. I am using 7 so that could be possible. Here's the code I'm using: // Create a console window AllocConsole(); AttachConsole(GetProcessId(GetModuleHandle(NULL))); HANDLE overlappedConsoleIn = CreateFile(L"CONIN$", GENERIC_READ, FILE_SHARE