生成桌面路径并打开CSV内部密码保护的RAR,而无需在终端中留下密码跟踪[分享我的知识]

发布于 2025-02-02 03:45:28 字数 381 浏览 2 评论 0 原文

我将 csv 文件用作 dataframe 桌面上的文件

由于每个用户都有不同的名称,生成了桌面的不同路径,因此我还将自动生成路径,无论用户的名称如何路径字符串。

这将是我今天对Stackoverflow社区的贡献!

注意:随时为此需要发布改进的模型。

Answer my own question – share your knowledge, Q&A-style

I'm use a CSV file as Dataframe, but it's inside a password-protected RAR file on the Desktop.

As each user has a different name generating a different path to the Desktop, I will also generate the path automatically regardless of the user's name, so that I can use it on any computer with Windows without having to change the path string.

This will be my contribution to the StackOverflow community today!

Note: feel free to publish improved models for this need.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

¢蛋碎的人ぎ生 2025-02-09 03:45:28
from rarfile import RarFile
from getpass import getpass
import pandas as pd
import os

desktop = os.environ['USERPROFILE'] + '\Desktop' # create desktop path

rar_files = RarFile(desktop + '\archive_rar.rar', 'r') # open RAR file

specific_file = rar_files.open('file_inside_rar.csv',pwd=getpass()) # open csv file that is inside RAR

print('\033[A\033[A') # Clear row of the password request in the terminal

df = pd.read_csv(specific_file) # Dataframe created from csv file

print(df.iloc[0].values[0]) # row 0, value 0
print(df.iloc[1].values[0]) # row 1, value 0
print(df.iloc[2].values[0]) # row 2, value 0

终端中的字符串看起来像这样:

getpass()会要求您提供 rar 文件的密码:

Password:

您将输入密码文本不会显示!

完成输入密码后,按 Enter

然后 print('\ 033 [a \ 033 [a')将清除终端中的现有文本:


row_1_value

然后是第一个 print print> print :

row_1_value
row_2_value

然后第三<代码>打印:

row_1_value
row_2_value
row_3_value
from rarfile import RarFile
from getpass import getpass
import pandas as pd
import os

desktop = os.environ['USERPROFILE'] + '\Desktop' # create desktop path

rar_files = RarFile(desktop + '\archive_rar.rar', 'r') # open RAR file

specific_file = rar_files.open('file_inside_rar.csv',pwd=getpass()) # open csv file that is inside RAR

print('\033[A\033[A') # Clear row of the password request in the terminal

df = pd.read_csv(specific_file) # Dataframe created from csv file

print(df.iloc[0].values[0]) # row 0, value 0
print(df.iloc[1].values[0]) # row 1, value 0
print(df.iloc[2].values[0]) # row 2, value 0

The string in the terminal will look like this:

getpass() will ask you for the password of the RAR file:

Password:

You will type but the password text will not appear!

When finished typing the password, press ENTER.

Then print('\033[A\033[A') will clear the existing text in the terminal:


then first print:

row_1_value

then second print:

row_1_value
row_2_value

then third print:

row_1_value
row_2_value
row_3_value
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文