小编alf*_*eon的帖子

Python-向文件编号添加前导 0

我是 python 和编程新手,通常我的文件夹中有 1200 个文本文件,格式如下:
James - 1 - How to... .txt
Sarah - 2 - How to... .txt
Steph - 3 - How to ... .txt
...
玛丽亚 - 200 - 如何... .txt
...
拉什福德 - 1200 - 如何... .txt

我想重命名 1000 以下的文件以添加前导 0,以便它们都具有相同的位数,例如 0001、0050、0300

到目前为止,这是我的代码,但我卡住了:

#!python3

import os
from tkinter import filedialog

cleaned_files = []

root_folder = filedialog.askdirectory()
os.chdir(root_folder)
folder_files = os.listdir(root_folder)

# Filter out files starting with '.' and '_'
cleaned_files = []
for item in folder_files: …
Run Code Online (Sandbox Code Playgroud)

python python-3.x

5
推荐指数
1
解决办法
7592
查看次数

有没有办法让 Firebase 实时数据库存在系统更快地检测到断开连接

我正在创建一个 Flutter 应用程序,必须几乎立即检测到用户从实时/firestore 数据库中脱机并通知其他用户相同的情况。

我已经尝试了在实时数据库中订阅 .info/connected 的推荐方法,并更新了 Firestore 数据库。

FirebaseDatabase.instance
        .reference()
        .child('.info')
        .child('connected')
        .onValue
        .listen((data) {
      if (data.snapshot.value == false) {
        // Internet has been disconnected
        setState(() {
          state.connected = false;
        });
        userFirestoreRef.updateData({
          'status': 'offline',
          'lastChanged': FieldValue.serverTimestamp(),
        });
      }
      userDbRef.onDisconnect().update({
        'status': 'offline',
        'lastChanged': ServerValue.timestamp
      }).then((_) async {
        // This resolves as soon as the server gets the request, not when the user disconnects
        setState(() {
          state.connected = true;
        });
        await userDbRef.update({
          'status': 'online',
          'lastChanged': ServerValue.timestamp,
        }).catchError((e) => debugPrint('Error in realtime …
Run Code Online (Sandbox Code Playgroud)

firebase firebase-realtime-database flutter google-cloud-firestore

5
推荐指数
1
解决办法
2229
查看次数