在Python 3和Python 2中,__repr__
是否应该返回字节或unicode?参考和报价是理想的。
Here's some information大约2-3兼容性,但我没有看到答案。
答案 0 :(得分:8)
类型为function getStats() {
var url = "https://stats.nba.com/stats/leaguedashplayerstats?College=&Conference=&Country=&DateFrom=&DateTo=&Division=&DraftPick=&DraftYear=&GameScope=&GameSegment=&Height=&LastNGames=0&LeagueID=00&Location=&MeasureType=Base&Month=0&OpponentTeamID=0&Outcome=&PORound=0&PaceAdjust=N&PerMode=Totals&Period=0&PlayerExperience=&PlayerPosition=&PlusMinus=N&Rank=N&Season=2017-18&SeasonSegment=&SeasonType=Regular+Season&ShotClockRange=&StarterBench=&TeamID=0&VsConference=&VsDivision=&Weight=";
var api = url;
fetch(api)
.then(function(response){
return response.json();
})
.then(function(data){
console.log(data);
})
.catch(function(error){
console.log("There is an error.", error);
})
}
(对于python2.x和python3.x):
str
必须如此,因为>>> type(repr(object()))
<class 'str'>
默认调用__str__
如果前者不存在,但__repr__
返回{{1} }}
对于那些不知道的人,在python3.x中,__str__
是表示unicode的类型。在python2.x中,str
是表示字节的类型。
答案 1 :(得分:1)
这两种语言的Python 3.6.4 (default, Dec 21 2017, 18:54:30)
>>> type(repr(()))
<class 'str'>
Python 2.7.14 (default, Nov 7 2017, 17:59:11)
>>> type(repr(()))
<type 'str'>
:
2018-01-16T00:11:32.891Z [[31merror[0m] akka.actor.OneForOneStrategy
[sourceThread=userservice-v1-akka.actor.default-dispatcher-18, akkaTimestamp=
00:11:32.877UTC, akkaSource=akka://userservice-v1/user/slickOffsetStorePrepare-singleton/singleton/slickOffsetStorePrepare,
sourceActorSystem=userservice-v1] - You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right syntax to use near '"read_side_offsets" ("read_side_id" VARCHAR(255) NOT NULL,"tag" VARCHAR(255) NOT' at line 1 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
near '"read_side_offsets" ("read_side_id" VARCHAR(255) NOT NULL,"tag" VARCHAR(255) NOT' at line 1
2018-01-16T00:11:32.896Z [[31merror[0m] akka.actor.OneForOneStrategy
[sourceThread=userservice-v1-akka.actor.default-dispatcher-20, akkaTimestamp=
00:11:32.885UTC, akkaSource=akka://userservice-v1/user/jdbcCreateTables-singleton/singleton/jdbcCreateTables,
sourceActorSystem=userservice-v1] - You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right syntax to use near
'"journal" ("ordering" BIGINT AUTO_INCREMENT NOT NULL,"deleted" BOOLEAN DEFAULT f'
at line 1 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near '"journal" ("ordering" BIGINT
AUTO_INCREMENT NOT NULL,"deleted" BOOLEAN DEFAULT f' at line 1
(那里有一个元组。)