我使用pycharm 5.0和python3.5.我通过pycharm的内置函数(setting-project-project interpreter - "+")下载所有的liarbry.其他库看起来很好,但是一些问题发生在flask-SQLAlchemy上.
我成功导入了flask-SQLAlchemy.但是,pycharm提醒我"类'SQLAlchemy'中的"未解析的属性引用'Column'."在类'SQLAlchemy'中未解析的属性引用'关系'"等等.
我尝试了一些方法,但它们没有用.例如:1.restart 2.remove and redownload 3.refresh cache.which在PyCharm中提到显示有效代码的未解析引用错误
码:
from flask import Flask, redirect, render_template, session, url_for, flash
from flask_sqlalchemy import SQLAlchemy
from flask_bootstrap import Bootstrap
from flask_wtf import Form
from wtforms import StringField, SubmitField
import os
from wtforms.validators import data_required
basedir = os.path.abspath(os.path.dirname(__file__))
app = Flask(__name__)
app.config['SECRET_KEY'] = 'hard to guess string'
app.config['SQLALCHEMY_DATABASE_URI'] =\
'sqlite:///' + os.path.join(basedir, 'data.sqlite')
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
bootstrap = Bootstrap(app)
db = SQLAlchemy(app)
class Role(db.Model):
__tablename__ = 'roles' …Run Code Online (Sandbox Code Playgroud) 首先,我想测试生成器和列表理解之间的内存使用情况.本书给了我一个小小的代码片段,我在我的PC上运行它(python3.6,Windows),发现一些意想不到的东西.
FOllowing是我的代码,它不满足以前的意见(在sum函数中).
import tracemalloc
from time import time
def timeIt(func):
start = time()
func()
print('%s use time' % func.__name__, time() - start)
return func
tracemalloc.start()
numbers = range(1, 1000000)
@timeIt
def lStyle():
return sum([i for i in numbers if i % 3 == 0])
@timeIt
def gStyle():
return sum((i for i in numbers if i % 3 == 0))
lStyle()
gStyle()
shouldSize = [i for i in numbers if i % 3 == 0]
snapshotL = tracemalloc.take_snapshot()
top_stats …Run Code Online (Sandbox Code Playgroud) 在Cpython实现中,当我们删除dict中的键时,Cpython会将对应的条目设置为虚拟条目,为什么是虚拟条目?我可以让ertry的价值为零吗?
我不擅长C,所以我在python中嘲笑它,接下来是我的python的实现代码:
class DictEntry:
def __init__(self):
self.key = None
self.value = None
self.hash = None
def __repr__(self):
return ' %s %s %s' % (self.key, self.hash, self.value)
class Hashtable:
def __init__(self):
self.size = 8
self.used = 0
self.mask = self.size - 1
self.pow2 = 3
self.entyies = [DictEntry() for _ in range(self.size)]
def insert(self, key, item):
hash_value = _hash(key)
_key = hash_value & (self.size - 1)
if not self.is_slot_empty(_key):
_key = self.next_slot(_key, hash_value)
entry = self.entyies[_key]
entry.key = _key
entry.hash = …Run Code Online (Sandbox Code Playgroud)