我可以得到我当前的工作目录
my_dir=$(pwd)
echo $my_dir
/files/work/test
Run Code Online (Sandbox Code Playgroud)
我怎么知道/files/work 我不想更改目录。我只需要获取/files/work目录。
我正在使用蓝图来构建 Web 应用程序。我遇到会话不持久的问题。我可以开始会话,但是当我单击链接时会话丢失了。我做错了什么?我没有使用数据库登录我只是硬编码。当我提交时,我会执行
session['username'] = me。在我登录后重定向到的页面上,它可以工作。但是,当我单击该页面上的链接时,会话丢失了。该
会议[“用户名”]不见了。我也设置了我的密钥。它是硬编码在我的配置文件中。在我的 admin 文件夹中,我有一个带有登录名的路由文件。登录有效,但是当我单击链接转到其他页面时,用户名丢失了。
C:.
????blueprintsite
????admin
? ????templates
? ? ????admin
? ????__pycache__
????reports
? ????__pycache__
????users
? ????templates
? ? ????site
? ????__pycache__
????static
? ????css
? ????fonts
? ????images
? ? ????media
? ? ????people
? ? ????preview
Run Code Online (Sandbox Code Playgroud) 我正在将数据插入到我的一个表中,并且我不断获得锁定。
insert into inventory_files(id, pro_id) values(30,6569);
Run Code Online (Sandbox Code Playgroud)
我收到以下错误。
Error Code: 1205. Lock wait timeout exceeded; try restarting transaction 51.004 sec
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED ;
Run Code Online (Sandbox Code Playgroud)
然后插入该数据。
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ ;
Run Code Online (Sandbox Code Playgroud)
我插入其他表没有任何问题。任何其他建议。
我也跑了。
SHOW ENGINE INNODB STATUS;
Run Code Online (Sandbox Code Playgroud)
没有桌子被锁。
'InnoDB', '', '
2017-08-04 13:57:34 0x7f0c44461700 INNODB 监视器输出 从过去 29 秒计算出的每秒平均值
背景话题
srv_master_thread 循环:93 srv_active、0 srv_shutdown、2985 srv_idle
srv_master_thread 日志刷新并写入:3076
信号量
操作系统等待数组信息:保留计数 29
操作系统等待数组信息:信号计数 29
RW 共享旋转 0,轮次 52,操作系统等待 26
RW-excl 自旋 0、轮数 0、OS 等待 0
RW-sx 自旋 …
如何使我的光标成为准备好的语句和字典。我有以下内容。
cursor(cursor_class = MySQLCursorPrepared)
prints <class 'mysql.connector.cursor.MySQLCursorPrepared'>
cursor(dictionary = True)
prints <class 'mysql.connector.cursor.MySQLCursorDict'>
Run Code Online (Sandbox Code Playgroud)
所以我用字典覆盖了准备好的语句。我正在为 python3 使用 mysql 连接器。
我试过了
cursor(prepared=True,dictionary=True)
Run Code Online (Sandbox Code Playgroud)
错误与
Cursor not available with given criteria: dictionary, prepared
Run Code Online (Sandbox Code Playgroud)
有趣的是
cursor(cursor_class = MySQLCursorPrepared,dictionary = True)
Run Code Online (Sandbox Code Playgroud)
我没有收到错误,但数据不是字典类型。
我在Perl中创建了一个哈希 my %hash = (2 => 'dog', 1 => 'cat');
当我打印$hash{3}它时错误(use of uninitialzed value in print)是预期的.但是,如果不是哈希值,有没有办法默认值?
当我尝试将以下 HTML 插入元素时
<div class="frontpageclass"><h3 id="feature_title">The Title</h3>... </div>
Run Code Online (Sandbox Code Playgroud)
bs4 正在像这样替换它:
<div class="frontpageclass"><h3 id="feature_title">The Title </h3>... <div></div>
Run Code Online (Sandbox Code Playgroud)
我正在使用string,但它仍然弄乱了格式。
with open(html_frontpage) as fp:
soup = BeautifulSoup(fp,"html.parser")
found_data = soup.find(class_= 'front-page__feature-image')
found_data.string = databasedata
Run Code Online (Sandbox Code Playgroud)
如果我尝试使用,found_data.string.replace_with我会收到 NoneType 错误。found_data是标签类型。
我找到了要替换的文本,但是当我打印时soup格式发生了变化。<div id="content">stuff here</div>变成<div id="content">stuff here</div>. 我怎样才能保存数据?我已经尝试过print(soup.encode(formatter="none")),但这会产生相同的错误格式。
from bs4 import BeautifulSoup
with open(index_file) as fp:
soup = BeautifulSoup(fp,"html.parser")
found = soup.find("div", {"id": "content"})
found.replace_with(data)
Run Code Online (Sandbox Code Playgroud)
当我打印时found,我得到正确的格式:
>>> print(found)
<div id="content">stuff</div>
Run Code Online (Sandbox Code Playgroud)
index_file内容如下:
<!DOCTYPE html>
<head>
Apples
</head>
<body>
<div id="page">
This is the Id of the page
<div id="main">
<div id="content">
stuff here
</div>
</div>
footer should go here
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 您如何使用类似 mysql 连接器和 python 编写查询。我试图避免 sql 注入并且使用 ORM 不是一种选择。
param = 'bob'
select_query = mysql_conn.query_db("select * from table_one where col_name like '%?%' order by id asc limit 5", param)
Run Code Online (Sandbox Code Playgroud)
无论我在查询执行时发送什么,我都会得到相同的结果。我应该一无所获。
当我使用以下查询时,出现错误。
select_query = mysql_conn.query_db("select * from table_one where col_name like %s order by id asc limit 5", param)
Run Code Online (Sandbox Code Playgroud)
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行的“%s order by id asc limit 5”附近使用的正确语法
Mysql是自动递增6。我不确定为什么或如何解决这些问题。
create table new_table(tinyint unsigned primary key auto_increment,
display_name varchar(50));
Run Code Online (Sandbox Code Playgroud)
我也用过
create table new_table(int unsigned primary key auto_increment,
display_name varchar(50));
Run Code Online (Sandbox Code Playgroud)
我认为我没有做任何奇怪的事情。
行计数如何工作。我正在使用pyodbc,并且始终返回-1。
return_query = conn.query_db_param(query, q_params)
print(return_query.rowcount)
def query_db_param(self, query, params):
self.cursor.execute(query,params)
print(self.cursor.rowcount)
Run Code Online (Sandbox Code Playgroud) python ×5
python-3.x ×5
mysql ×4
bash ×1
create-table ×1
flask ×1
perl ×1
primary-key ×1
pyodbc ×1
session ×1
shell ×1
wildcard ×1