Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-pipeline
csst_common
Commits
7da09866
Commit
7da09866
authored
Jun 25, 2023
by
BO ZHANG
🏀
Browse files
add randfile
parent
b0d4f4f4
Changes
2
Hide whitespace changes
Inline
Side-by-side
csst_common/utils/__init__.py
View file @
7da09866
from
._module_docstr
import
ModuleHeader
from
._module_docstr
import
ModuleHeader
from
._io
import
remove_dir
,
remove_files
from
._io
import
remove_dir
,
remove_files
from
.tempfile
import
randfile
csst_common/utils/tempfile.py
0 → 100644
View file @
7da09866
import
secrets
import
string
def
randfile
(
digits
=
20
,
ext
=
".fits"
):
"""
Parameters
----------
digits
ext
Returns
-------
Examples
--------
>>> fname = randfile(20)
>>> print(fname)
"""
# 生成包含大小写字母和数字的字符集
characters
=
string
.
ascii_letters
+
string
.
digits
# 使用secrets模块生成指定长度的随机字符串
random_string
=
''
.
join
(
secrets
.
choice
(
characters
)
for
_
in
range
(
digits
))
+
ext
return
random_string
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment