import bottle
from bottle import route, run
@route('/', method='GET')
def homepage():
return {'foo' : 'bar'}
if __name__=='__main__':
bottle.debug(True)
run(host='0.0.0.0', port= 8080, reloader = True)
Run Code Online (Sandbox Code Playgroud)
这个配置将返回表示从网页上的HTTP状态代码200,我应该怎么做返回相同的内容,但有,比方说,202状态码字典JSON对象?
我正在尝试使用Java学习套接字,并且我成功地将数据发送到在我自己的机器上运行的ServerSocket.当我尝试使用readline从这个套接字读取时(所以我可以回显我自己发送的消息)我的程序挂起并且不会返回.
这是代码:
public static void main(String[] args) throws UnknownHostException, IOException {
TCPClient cli = new TCPClient("127.0.0.1", "15000");
try {
cli.ostream.writeUTF("Teste");
String echo = cli.istream.readLine(); //it hangs in this line
System.out.println(echo);
}
Run Code Online (Sandbox Code Playgroud)
TCPClient是我定义的类,所以我可以在我的homwework上使用swing之前在更简单的界面上测试我的程序.这是代码:
public class TCPClient {
public DataOutputStream ostream = null;
public BufferedReader istream = null;
public TCPClient(String host, String port) throws UnknownHostException {
InetAddress ip = InetAddress.getByName(host);
try {
Socket socket = new Socket(host, Integer.parseInt(port));
ostream = new DataOutputStream(socket.getOutputStream());
istream = new BufferedReader(new InputStreamReader(socket.getInputStream()));
} catch (IOException ex) { …Run Code Online (Sandbox Code Playgroud) 我在尝试编译下面的代码片段时遇到以下错误(使用g ++):
error: invalid initialization of non-const reference of type
‘std::vector<pos,std::allocator<pos> >&’ from a temporary of
type ‘std::vector<pos, std::allocator<pos> >&
(*)(std::vector<pos, std::allocator<pos> >&)’
Run Code Online (Sandbox Code Playgroud)
这是生成错误的代码:
struct pos{
int start;
int end;
int distance;
int size;
};
bool compare_pos(pos a, pos b)
{
if (a.distance != b.distance)
return (a.distance < b.distance);
else
return (a.size < b.size);
}
vector<pos> sort_matches(vector<pos>& matches)
{
//vector<pos> sorted_matches(matches);
vector<pos> sorted_matches();
//sort(sorted_matches.begin(), sorted_matches.end(), compare_pos);
return sort_matches;
}
Run Code Online (Sandbox Code Playgroud)
真正的代码将取消注释两个注释行,但即使是注释的示例也会给我错误.我究竟做错了什么?
我正在做一个返回VARCHAR2和其他一些字段的查询.正如我在Oracle文档中发现的那样,我正在通过此VARCHAR2对结果进行排序,并且遇到与语言排序相关的一些问题.例如:
SELECT id, my_varchar2 from my_table ORDER BY MY_VARCHAR2;
Run Code Online (Sandbox Code Playgroud)
将返回:
ID MY_VARCHAR2
------ -----------
3648 A
3649 B
6504 C
7317 D
3647 0
Run Code Online (Sandbox Code Playgroud)
我需要它返回字符串"0"作为此序列的第一个元素,因为它将比较ASCII值.字符串可以有多个字符,因此我不能使用ascii函数,因为它忽略除第一个字符之外的任何字符.
最好的方法是什么?
我有一个变量,它的内容,我需要从远程服务器获取,所以我宁愿等到真正需要的内容.我想如果使用一个属性,但似乎我做错了.根据例子.
def download():
return 'content from remote server'
class Foo:
def __init__(self):
self.downloaded_bar = False
self.bar = None
@property
def bar():
if not self.downloaded:
self.bar = download()
self.downloaded = True
return self.bar
f = Foo()
print f.bar #prints None, I expected 'content from remote server'
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我有一些像下面的代码,它的工作原理,但我只想显示"数字%"而不是只显示一个数字.这就是我所拥有的:
<h:outputtext value="#{somebean.doubleValue}">
<f:convertnumber maxfractiondigits="2">
</h:outputtext>
Run Code Online (Sandbox Code Playgroud)
如果我在value属性中放入"%"符号,转换器将无法工作(我相信因为评估结果不仅仅是一个数字),但是如果我将"%"符号放在其他outputtext标记中,则会有一个换行符出现在数字和它之间.我不希望这样.
<h:outputtext value="#{somebean.doubleValue}">
<f:convertnumber maxfractiondigits="2">
</h:outputtext>
<h:outputtext value="%"> <!--prints a new line-->
Run Code Online (Sandbox Code Playgroud)
在jsf上实现"xx.xx%"格式化的最佳方法是什么?