我得到了教程
当我编译得到错误消息
The debugged program raised the exception unhandled NameError
"name 'BoundMetaData' is not defined"
Run Code Online (Sandbox Code Playgroud)
我使用的是最新的sqlAlchemy.
我怎么能修好这个?
阅读本文后,我修改了自己的最新版本sqlAlchemy:
from sqlalchemy import *
engine = create_engine('mysql://root:mypassword@localhost/mysql')
metadata = MetaData()
users = Table('users', metadata,
Column('user_id', Integer, primary_key=True),
Column('name', String(40)),
Column('age', Integer),
Column('password', String),
)
metadata.create_all(engine)
i = users.insert()
i.execute(name='Mary', age=30, password='secret')
i.execute({'name': 'John', 'age': 42},
{'name': 'Susan', 'age': 57},
{'name': 'Carl', 'age': 33})
s = users.select()
rs = s.execute()
row = rs.fetchone()
print 'Id:', row[0]
print 'Name:', row['name']
print 'Age:', row.age …Run Code Online (Sandbox Code Playgroud) 我有一个数组,其中包含我想用分页显示的数据.
$display_array = Array
(
[0] => "0602 xxx2",
[1] => "0602 xxx3",
[2] => 5 // Total= 2+3
[3] => "0602 xxx3",
[4] => "0602 saa4",
[5] => 7 // Total = 3+4
)
Run Code Online (Sandbox Code Playgroud)
我尝试过这样的事情
function pagination($display_array, $page)
{
global $show_per_page;
$page = $page < 1 ? 1 : $page;
$start = ($page - 1) * $show_per_page;
$end = $page * $show_per_page;
for($i = $start; $i < $end; $i++)
{
////echo $display_array[$i] . "<p>";
// How to manipulate this? …Run Code Online (Sandbox Code Playgroud) Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> str_version = '??????'
>>> type(str_version)
<class 'str'>
>>> print (str_version)
??????
>>> unicode_version = '??????'.decode('utf-8')
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
unicode_version = '??????'.decode('utf-8')
AttributeError: 'str' object has no attribute 'decode'
>>>
Run Code Online (Sandbox Code Playgroud)
我的unicode字符串有什么问题?
例如,我通过将字典作为参数传递来调用此函数:
>>> inv_map({'a':1, 'b':2, 'c':3, 'd':2})
{1: ['a'], 2: ['b', 'd'], 3: ['c']}
>>> inv_map({'a':3, 'b':3, 'c':3})
{3: ['a', 'c', 'b']}
>>> inv_map({'a':2, 'b':1, 'c':2, 'd':1})
{1: ['b', 'd'], 2: ['a', 'c']}
Run Code Online (Sandbox Code Playgroud)
如果
map = { 'a': 1, 'b':2 }
Run Code Online (Sandbox Code Playgroud)
我只能将此地图反转为:
inv_map = { 1: 'a', 2: 'b' }
Run Code Online (Sandbox Code Playgroud)
通过使用这个
dict((v,k) for k, v in map.iteritems())
Run Code Online (Sandbox Code Playgroud)
任何人都知道如何为我的情况这样做?
我有6个表,我将做一个单独的SQL语句:
1)participant
***********
+id_participant
+id_poste
+name
+email
2) profile_formaion
****************
+id_poste
+id_formation
3) formation
*********
+id_formation
+lable
4) poste
*********
+id_poste
+label
5) session
*********
+id_session
+id_formaion
+lable
6) session_composition
*********
+id_session
+id_participant
Run Code Online (Sandbox Code Playgroud)
EXAMPLE:
数据:参与者
1 | 2 | user1 | user1@mail.com
2 | 3 | user2 | user2@mail.com
Run Code Online (Sandbox Code Playgroud)
数据:profile_formation
2 | 3
2 | 4
Run Code Online (Sandbox Code Playgroud)
DATA:形成
1 |formation1
2 |formation2
3 |formation3
4 |formation4
Run Code Online (Sandbox Code Playgroud)
数据:poste
1 |Poste1
2 |Poste2
3 |Poste3
Run Code Online (Sandbox Code Playgroud)
DATA:会话
1 |1 /* id_session 1 to id_formation …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用我的Play-2.5项目配置Swagger.
我按照本教程进行了操作,但仅适用于较旧版本的Play而不使用Play-2.5.随着项目迁移到Play-2.5,我们不得不删除swagger配置.
首先,问题似乎是Play-2.5中的静态控制器与非静态控制器,但我最终证明自己是错的.我正面临这个错误
type ApiHelpController is not a member of package controllers
GET /api-docs controllers.ApiHelpController.getResources
Run Code Online (Sandbox Code Playgroud)
如果任何人知道Play-2.5 for Java的 Swagger配置链接,请指导.
PS:有Scala的教程不适用于java.
java playframework swagger-ui swagger-play2 playframework-2.5
在我的views.py中,我有一个方法:
#......
def get_filter_result(self, customer_type, tag_selected):
list_customer_filter=[]
customers_filter = Customer.objects.filter(Q(type__name=customer_type),
Q(active=True),
Q(tag__id=tag_selected))
for customer_filter in customers_filter:
customer_filter.list_authorize_sale_type = sale_type_selected(customer_filter.authorize_sale_type)
list_customer_filter.append(customer_filter)
return list_customer_filter
Run Code Online (Sandbox Code Playgroud)
**我的案例tag_selected是用户选中的复选框值我遇到了tag_selected(是列表= 1,2,3,...)从我的网址传递的问题
/?customer_type=TDO&tag=2 ===>filter okay
/?customer_type=TDO&tag=3 ===>filter okay
?customer_type=TDO&tag=2,3 ===>How Can I add And condition in filter?
Run Code Online (Sandbox Code Playgroud)
例如
if len(tag_selected)==1:
customers_filter = Customer.objects.filter(Q(type__name=customer_type),
Q(active=True),
Q(tag__id=tag_selected))
else:
customers_filter = Customer.objects.filter(Q(type__name=customer_type),
Q(active=True),
Q(tag__id=tag_selected[0])
Q(tag__id=tag_selected[1])
Q(tag__id=tag_selected[2])
...
)
Run Code Online (Sandbox Code Playgroud) 以下代码适合我:
# -*- coding: utf-8 -*-
N = int(raw_input("N="))
l=[]
i = 0
while i<N:
n = raw_input("e"+str(i)+"=")
l.append(n)
i = i+1
print l
Run Code Online (Sandbox Code Playgroud)
但是,为什么我不能通过使用l[i] = raw_input("e"+str(i)+"=")来简化它呢?
示例:(不起作用)
# -*- coding: utf-8 -*-
N = int(raw_input("N="))
l=[]
i = 0
while i<N:
l[i] = raw_input("e"+str(i)+"=")
i = i+1
print l
Run Code Online (Sandbox Code Playgroud) 我想限制用户输入,以便提供Nobeys N >0或N < 100.
我应该使用if... else或try... except?你能提供两种方法的例子吗?
我想要 Union 2 数组$A和$B示例:
$A = Array(
0=>array(
'lable' =>"label0",
'id_poste'=>1,
'id_part'=>11
),
1=>array(
'lable' =>"label1",
'id_poste'=>2,
'id_part'=>12
),
2=>array(
'lable' =>"label2",
'id_poste'=>3,
'id_part'=>13
),
3=>array(
'lable' =>"label3",
'id_poste'=>4,
'id_part'=>14
)
);
$B = Array(
0=>array(
'lable' =>"label0",
'id_poste'=>1,
'id_part'=>11
),
1=>array(
'lable' =>"label1_X",
'id_poste'=>2,
'id_part'=>12
),
2=>array(
'lable' =>"label2",
'id_poste'=>3,
'id_part'=>13
),
3=>array(
'lable' =>"label3_X",
'id_poste'=>4,
'id_part'=>14
)
);
Run Code Online (Sandbox Code Playgroud)
这两个数组之间的并集结果将是
/*
$result => Array(
0=>array(
'lable' =>"label0",
'id_poste'=>1,
'id_part'=>11
),
1=>array(
'lable' =>"label1",
'id_poste'=>2,
'id_part'=>12 …Run Code Online (Sandbox Code Playgroud) python ×5
php ×3
mysql ×2
array-merge ×1
arrays ×1
dictionary ×1
django ×1
django-q ×1
duplicates ×1
inverse ×1
java ×1
pagination ×1
python-3.x ×1
sql ×1
sqlalchemy ×1
swagger-ui ×1
unicode ×1