我使用Vaadin编写了以下代码.www.google.com
当用户单击按钮时,代码将打开页面.
我的问题是,有没有办法指定要在新标签页中打开页面?
谢谢.
button.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
getUI().getPage().setLocation("http://www.google.com");
}
});
Run Code Online (Sandbox Code Playgroud) 我正在尝试逐行读取以下文件并检查文件中是否存在值。我目前正在尝试的方法不起作用。我究竟做错了什么?
如果该值存在,我什么都不做。如果没有,那么我将它写入文件。
文件.txt:
123
345
234
556
654
654
Run Code Online (Sandbox Code Playgroud)
代码:
file = open("file.txt", "a+")
lines = file.readlines()
value = '345'
if value in lines:
print('val ready exists in file')
else:
# write to file
file.write(value)
Run Code Online (Sandbox Code Playgroud) 我已经搜索了很长时间,但我真的无法弄清楚这一点.
如何在用户单击Vaadin中的按钮时将用户重定向到新的外部链接(例如www.google.com)?
到目前为止,我唯一能做的就是将链接放入链接中
Link link = new Link("link", new ExternalResource("http://www.google.com"));
Run Code Online (Sandbox Code Playgroud)
有人可以帮我解决这个问题吗?
我发现这段代码可以读取特定文件的所有行。
如何编辑它以使其一一读取目录“文件夹”中的所有文件(html、文本、php .etc),而不必指定每个文件的路径?我想在目录中的每个文件中搜索关键字。
path = '/Users/folder/index.html'
files = glob.glob(path)
for name in files:
try:
with open(name) as f:
sys.stdout.write(f.read())
except IOError as exc:
if exc.errno != errno.EISDIR:
raise
Run Code Online (Sandbox Code Playgroud) 我试图使用python连接到服务器并将我的本地目录中的一些文件上传到/ var/www/html但每次我尝试这样做时都会收到此错误:
错误:ftplib.error_perm:553无法创建文件.
我已经在路径上做了一个chown和一个chmod -R 777.我正在使用vsftpd并已启用写入启用.有没有人有任何想法?
码:
ftp = FTP('ipaddress')
ftp.login(user='user', passwd = 'user')
ftp.cwd('/var/www/html')
for root, dirs, files in os.walk(path):
for fname in files:
full_fname = os.path.join(root, fname)
ftp.storbinary('STOR' + fname, open(full_fname, 'rb'))
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个连接到我的服务器并通过SFTP发送一些文件的python脚本.但问题是我一直在努力
IOError:失败
有谁知道为什么会这样?我本地PC上的目录有多个文件.
码:
import paramiko
import os
local_path = "/home/user/Desktop/test"
remote_path = "/home/user/files/html/"
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('ipaddress', username="user", password="user")
sftp = ssh.open_sftp()
for root, dirs, files in os.walk(local_path):
for fname in files:
full_fname = os.path.join(root, fname)
sftp.put(full_fname, remote_path)
sftp.close()
ssh.close()
Run Code Online (Sandbox Code Playgroud)
追溯:
Traceback (most recent call last):
File "ftp_test.py", line 16, in <module>
sftp.put(full_fname, remote_path)
File "/usr/local/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 669, in put
return self.putfo(fl, remotepath, file_size, callback, confirm)
File "/usr/local/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 621, in putfo
with self.file(remotepath, 'wb') as fr:
File …
Run Code Online (Sandbox Code Playgroud) 我在Vaadin中编写了以下代码.
问题是对齐不起作用.我将它设置为bottom_center,但组件都粘贴在我的Web浏览器的顶部(top_center).
任何人都可以帮我解决这个问题吗?
谢谢!
VerticalLayout layout = new VerticalLayout();
VerticalLayout layout1 = new VerticalLayout();
Panel panel = new Panel();
panel.setWidth("500px");
panel.setHeight("300px");
Button button = new Button("Enter");
Button login = new Button("Login");
layout1.addComponent(textfield);
layout1.addComponent(button);
layout1.addComponent(login);
layout.addComponent(panel);
layout.setComponentAlignment(panel, Alignment.BOTTOM_CENTER);
layout1.setComponentAlignment(textfield, Alignment.BOTTOM_CENTER);
layout1.setComponentAlignment(login, Alignment.BOTTOM_CENTER);
layout1.setComponentAlignment(button, Alignment.BOTTOM_CENTER);
Run Code Online (Sandbox Code Playgroud) 我写的这段代码创建了2个面板.目的是让其中一个直接在另一个之上,两者之间没有空间,但问题是它们之间存在巨大差距.
谁能帮我解决这个问题?
码:
Panel panel = new Panel();
Panel Logo = new Panel();
VerticalLayout layout1 = new VerticalLayout();
VerticalLayout layout2 = new VerticalLayout();
panel.setWidth("500px");
panel.setHeight("300px");
Logo.setWidth("500px");
Logo.setHeight("100px");
Logo.addStyleName(Runo.PANEL_LIGHT);
Label label = new Label("test");
label.setWidth(null);
Button test = new Button("test");
first.setStyleName("test");;
first.setClickShortcut(KeyCode.ENTER, null);
layout1.addComponent(test);
layout2.addComponent(label);
layout.addComponent(Logo);
layout.addComponent(panel);
layout.setComponentAlignment(panel, Alignment.MIDDLE_CENTER);
layout1.setComponentAlignment(test, Alignment.MIDDLE_CENTER);
layout2.setComponentAlignment(label, Alignment.MIDDLE_CENTER);
layout.setSizeFull();
layout1.setSizeFull();
layout2.setSizeFull();
setContent(layout);
panel.setContent(layout1);
Logo.setContent(layout2);
Run Code Online (Sandbox Code Playgroud) #include <iostream>
using namespace std;
class object{
object* Next;
};
int main()
{
char* c = new char[64];
reinterpret_cast<object*>(c);
c->Next;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么我会收到错误
main.cpp:21:8: error: request for member ‘Next’ in ‘* c’, which is of non-class type ‘char’
Run Code Online (Sandbox Code Playgroud)
当我尝试访问Next指针时,即使我已将分配的内存转换为对象类型?如何访问Next指针?
我只使用了char类型,因为我想准确分配64字节的内存.
我正在尝试在我的 flutter 应用程序中实现 CupertinoActionSheet,但我一直失败。我很确定我拥有所有必要的东西,但我一直遇到以下错误:
使用不包含导航器的上下文请求导航器操作。
我不明白为什么我会收到这个错误。实现 CupertinoActionSheet 的正确方法是什么?
代码:
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Center(
child: Container(
color: Colors.black,
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Card(
elevation: 20,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 180.0),
child: CupertinoButton(
color: Colors.black,
child: Text(
'Click me',
style: TextStyle(color: Colors.white),
), …
Run Code Online (Sandbox Code Playgroud) 我编写了以下代码.我试图在面板中一个接一个地将这两个文本集中在一起,如下所示:
Your name is:
1
Run Code Online (Sandbox Code Playgroud)
谁能告诉我怎么做呢?
谢谢.
码:
VerticalLayout layout1 = new VerticalLayout();
layout.setSizeFull();
layout1.setSizeFull();
Label label = new Label("Your name is: ");
label.setStyleName(Runo.LABEL_H1);
Label label1 = new Label(name);
label1.setStyleName(Runo.LABEL_H1);
layout1.addComponent(label);
layout1.addComponent(label1);
layout1.setComponentAlignment(label, Alignment.MIDDLE_CENTER);
layout1.setComponentAlignment(label1, Alignment.MIDDLE_CENTER);
layout.setComponentAlignment(panel, Alignment.MIDDLE_CENTER);
setContent(layout);
panel.setContent(layout1);
Run Code Online (Sandbox Code Playgroud)
输出:
我正在使用 flutter 和 firebase 来创建一个应用程序。下面的函数从我的 firebase 数据库中获取一些数据,但问题是获取数据所需的时间太长。如何确保应用程序先等待 Firebase 获取数据完成,然后再继续?
我想做一些类似于等待的事情,但我不知道我是否可以这样做:
await Firestore.instance...
Run Code Online (Sandbox Code Playgroud)
代码:
void getData() {
Firestore.instance
.collection('collection')
.document('document')
.get()
.then((DocumentSnapshot ds) {
var count = ds.data.length;
for(var i = 0; i < count; i ++){
Firestore.instance
.collection('collection')
.document('document')
.get()
.then((DocumentSnapshot dss) {
// do something
});
}
});
}
Run Code Online (Sandbox Code Playgroud) 给出下面的代码:
def start(update, context):
context.bot.send_message(chat_id=update.effective_chat.id, text="I'm a bot, please talk to me!")
Run Code Online (Sandbox Code Playgroud)
是否可以定期调用此函数并使我的机器人自动将消息发送给用户,而不是用户键入“/start”
java ×5
vaadin ×5
python ×4
flutter ×2
c++ ×1
dart ×1
firebase ×1
ftp ×1
paramiko ×1
python-2.7 ×1
python-3.7 ×1
python-3.x ×1
telegram ×1
telegram-bot ×1