如果你使用 flask-sqlalchemy 來操作數(shù)據(jù)庫的話,實(shí)現(xiàn)你的方法有一些難度,不過也是用方法的。
你可以看看我的這篇文章基于 oracle 的 flask 項(xiàng)目(五)——報表下載中的使 sqlalchemy 數(shù)據(jù) json 化 這一部分內(nèi)容。
1、開始畫重點(diǎn),我給你的例子就是對讓一個 flask-sqlalchemy 對象 json 化,記住是讓一個flask-sqlalchemy 對象,不是兩個也不是多個,僅僅是一個。
所以,你增加一個字段,你就得在你的 models 的類對象中加一個屬性, 根據(jù)你的例子,你需要寫如下代碼
class QaAnswer(db.Model):
__tablename__ = 'qa_answer'
id = db.Column(db.Integer, primary_key=True)
a_questionid = db.Column(db.Integer, nullable=False)
a_answerid = db.Column(db.Integer)
a_respondcontent = db.Column(db.String(255), nullable=False)
a_createtime = db.Column(db.DateTime, nullable=False)
a_likecount = db.Column(db.Integer)
a_isshow = db.Column(db.Integer)
a_userid = db.Column(db.Integer, nullable=False)
@proprety
def content()
pass
話題引到如此,你可以忽略我的文章的內(nèi)容,不要再想如何使一個 flask-sqlalchemy 對象 json 化
2、根據(jù)你的代碼的書寫格式,I 服了 U。你的類對象里都一個 a_ 的前綴,但是你的 json 對象里是沒有的。這需要你處理一下。
代碼如下:
class QaAnswer(db.Model):
__tablename__ = 'qa_answer'
id = db.Column(db.Integer, primary_key=True)
a_questionid = db.Column(db.Integer, nullable=False)
a_answerid = db.Column(db.Integer)
a_respondcontent = db.Column(db.String(255), nullable=False)
a_createtime = db.Column(db.DateTime, nullable=False)
a_likecount = db.Column(db.Integer)
a_isshow = db.Column(db.Integer)
a_userid = db.Column(db.Integer, nullable=False)
@classmethod
def to_json():
"anwserid": 變量內(nèi)容,
"respondcontent": 變量內(nèi)容,
"content": 變量內(nèi)容,
"createtime": 變量內(nèi)容,
"likecount": 變量內(nèi)容,
"userid": 變量內(nèi)容
所有的變量內(nèi)容,在你的類里都定義好。
我只能幫你到此種地步了,其它的,已經(jīng)超出我的知識儲備,獻(xiàn)丑了。
經(jīng)過一天多的仔細(xì)排查,以及Google了大量文章發(fā)現(xiàn),這種情況有如下情況
未使用pip3安裝
未給予管理員權(quán)限安裝
已經(jīng)安裝的Tensorflow有問題
隨后我卸載了Tensorflow,并刪除了site-package下面的該文件夾后,使用管理員權(quán)限重新安裝;
這次報出了一些異常,但似乎并不礙事,再次在Pycharm中import Tensorflow,ok完美運(yùn)行;
但是我發(fā)現(xiàn)自動補(bǔ)全似乎有點(diǎn)問題,我仔細(xì)檢查后,不知何時工程根目錄下面多了一個Tensorflow.py,刪除后遂解決,但是自動補(bǔ)齊的速度很慢,但我也不敢強(qiáng)求了,不出錯就是最好。
annotate 使用注解
browser.find_element_by_class_name('className').find_element_by_xpath('div')
import csv
from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen("http://en.wikipedia.org/wiki/Comparison_of_text_editors")
bsObj = BeautifulSoup(html,"lxml")
table = bsObj.findAll("table", {"class":"wikitable"})[0]
rows = table.findAll("tr")
csvFile = open("editors.csv", 'wt', newline='', encoding='utf-8')
writer = csv.writer(csvFile)
try:
for row in rows:
csvRow = []
# 注意縮進(jìn)
for cell in row.findAll(['td', 'th']):
csvRow.append(cell.get_text())
# 注意縮進(jìn)
writer.writerow(csvRow)
finally:
csvFile.close()并不存在“雙小括號”這種東西,你貼的代碼里,Dataset.from_tensor_slices函數(shù)的參數(shù)是個元組.
要是參數(shù)是列表的話,你會不會問python里([ ])的作用?HHHH
試試寫 python3 寫絕對路徑
response = requests.get('http://finance.eastmoney.com/news/cgnjj_3.html')
response.encoding # 查看響應(yīng)的編碼,我這里返回了'ISO-8859-1'
response.encoding = 'utf-8'
response.text # OK一般都往七牛云上面?zhèn)靼?,django有七牛的插件,好用的很,傳完了兩邊同時保存下地址就行啦
第一種方法:僅使用顯示圖片的接口
把圖讀進(jìn)來
把圖先顯示出去
在圖上畫畫
把畫完的圖再顯示出去
第二種方法:你使用matplotlib或opencv多好啊,推薦。
第三種方法:使用GUI編程那一套。
# 製造原 dataframe
from pandas import DataFrame
columns = ['data', 'id', 'key1']
d = {
'data': [5, 10, 9, 8, 20],
'id': [1, 2, 3, 4, 5],
'key1': ['a', 'a', 'b', 'b', 'a']
}
dataframe = DataFrame(d, columns=columns)
# 利用 id_lst 製造新 dataframe
id_lst = [2, 3]
dataframe1 = dataframe[dataframe.id.isin(id_lst)]
我回答過的問題: Python-QA
找到相關(guān)的源碼了,雖然看不懂:
static PyObject *
gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing)
{
PyThreadState *tstate = PyThreadState_GET();
PyFrameObject *f = gen->gi_frame;
PyObject *result;
if (gen->gi_running) {
const char *msg = "generator already executing";
if (PyCoro_CheckExact(gen)) {
msg = "coroutine already executing";
}
else if (PyAsyncGen_CheckExact(gen)) {
msg = "async generator already executing";
}
PyErr_SetString(PyExc_ValueError, msg);
return NULL;
}
if (f == NULL || f->f_stacktop == NULL) {
if (PyCoro_CheckExact(gen) && !closing) {
/* `gen` is an exhausted coroutine: raise an error,
except when called from gen_close(), which should
always be a silent method. */
PyErr_SetString(
PyExc_RuntimeError,
"cannot reuse already awaited coroutine");
}
else if (arg && !exc) {
/* `gen` is an exhausted generator:
only set exception if called from send(). */
if (PyAsyncGen_CheckExact(gen)) {
PyErr_SetNone(PyExc_StopAsyncIteration);
}
else {
PyErr_SetNone(PyExc_StopIteration);
}
}
return NULL;
}
if (f->f_lasti == -1) {
if (arg && arg != Py_None) {
const char *msg = "can't send non-None value to a "
"just-started generator";
if (PyCoro_CheckExact(gen)) {
msg = NON_INIT_CORO_MSG;
}
else if (PyAsyncGen_CheckExact(gen)) {
msg = "can't send non-None value to a "
"just-started async generator";
}
PyErr_SetString(PyExc_TypeError, msg);
return NULL;
}
} else {
/* Push arg onto the frame's value stack */
result = arg ? arg : Py_None;
Py_INCREF(result);
*(f->f_stacktop++) = result;
}
/* Generators always return to their most recent caller, not
* necessarily their creator. */
Py_XINCREF(tstate->frame);
assert(f->f_back == NULL);
f->f_back = tstate->frame;
gen->gi_running = 1;
gen->gi_exc_state.previous_item = tstate->exc_info;
tstate->exc_info = &gen->gi_exc_state;
result = PyEval_EvalFrameEx(f, exc);
tstate->exc_info = gen->gi_exc_state.previous_item;
gen->gi_exc_state.previous_item = NULL;
gen->gi_running = 0;
/* Don't keep the reference to f_back any longer than necessary. It
* may keep a chain of frames alive or it could create a reference
* cycle. */
assert(f->f_back == tstate->frame);
Py_CLEAR(f->f_back);
/* If the generator just returned (as opposed to yielding), signal
* that the generator is exhausted. */
if (result && f->f_stacktop == NULL) {
if (result == Py_None) {
/* Delay exception instantiation if we can */
if (PyAsyncGen_CheckExact(gen)) {
PyErr_SetNone(PyExc_StopAsyncIteration);
}
else {
PyErr_SetNone(PyExc_StopIteration);
}
}
else {
/* Async generators cannot return anything but None */
assert(!PyAsyncGen_CheckExact(gen));
_PyGen_SetStopIterationValue(result);
}
Py_CLEAR(result);
}
else if (!result && PyErr_ExceptionMatches(PyExc_StopIteration)) {
const char *msg = "generator raised StopIteration";
if (PyCoro_CheckExact(gen)) {
msg = "coroutine raised StopIteration";
}
else if PyAsyncGen_CheckExact(gen) {
msg = "async generator raised StopIteration";
}
_PyErr_FormatFromCause(PyExc_RuntimeError, "%s", msg);
}
else if (!result && PyAsyncGen_CheckExact(gen) &&
PyErr_ExceptionMatches(PyExc_StopAsyncIteration))
{
/* code in `gen` raised a StopAsyncIteration error:
raise a RuntimeError.
*/
const char *msg = "async generator raised StopAsyncIteration";
_PyErr_FormatFromCause(PyExc_RuntimeError, "%s", msg);
}
if (!result || f->f_stacktop == NULL) {
/* generator can't be rerun, so release the frame */
/* first clean reference cycle through stored exception traceback */
exc_state_clear(&gen->gi_exc_state);
gen->gi_frame->f_gen = NULL;
gen->gi_frame = NULL;
Py_DECREF(f);
}
return result;
}這難道不是看你的內(nèi)存大小么,程序運(yùn)行都是在內(nèi)存中,按理來說,只要內(nèi)存夠大,列表也是可以無限大的。嗯,我猜的。。。
可以試試 淘寶的vw 解決方案,絕大部分新機(jī)型適用。
https://www.w3cplus.com/mobil...;
如果你用vue 可以試一下我的腳手架
你參考一下我的demo gsw945/flask-sio-demo
里面有正確的和不正確的例子,也給出了說明。
對于你的例子,你只展示了執(zhí)行的主要代碼,我并不知道你的整個流程是怎樣的。如果能展示真?zhèn)€流程,我有興趣進(jìn)一步解答。
anaconda 的虛擬環(huán)境使用:
$ conda info -envs # 顯示已創(chuàng)建的python環(huán)境
$ conda create --name <虛擬環(huán)境名字> python=<python版本>
$ source activate <虛擬環(huán)境名字>
需要使用那個環(huán)境就先:
$ source activate <虛擬環(huán)境名字>
這時 pip 的相關(guān)操作都只是針對此時選中的環(huán)境, 了解這三個對于 python 虛擬環(huán)境就能滿足大部分需求了。
應(yīng)該是你沒有安裝 openssl 吧
brew install openssl1.<el-col :span=8>被element-ui的render后轉(zhuǎn)換為一個有有class的el-col和el-col-8,而對應(yīng)element-ui.css里面設(shè)置了float屬性,浮動了之后就是向頂部擠
2.而原生div中a標(biāo)簽文字就默認(rèn)是居中
3.希望可以幫到你
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
北大課工場是北京大學(xué)校辦產(chǎn)業(yè)為響應(yīng)國家深化產(chǎn)教融合/校企合作的政策,積極推進(jìn)“中國制造2025”,實(shí)現(xiàn)中華民族偉大復(fù)興的升級產(chǎn)業(yè)鏈。利用北京大學(xué)優(yōu)質(zhì)教育資源及背
博為峰,中國職業(yè)人才培訓(xùn)領(lǐng)域的先行者
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項(xiàng)目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團(tuán)項(xiàng)目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗(yàn),技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點(diǎn)難點(diǎn)突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗(yàn)。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。