Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
torch-cluster
Commits
f8f3b26f
Commit
f8f3b26f
authored
Feb 29, 2024
by
yangzhong
Browse files
添加转换脚本pymap_script.py
parent
e4a899d4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
0 deletions
+37
-0
pymap_script.py
pymap_script.py
+37
-0
No files found.
pymap_script.py
0 → 100644
View file @
f8f3b26f
import
os
import
argparse
def
replace_in_file
(
file_path
,
replacements
):
with
open
(
file_path
,
'r'
)
as
file
:
content
=
file
.
read
()
for
key
,
value
in
replacements
.
items
():
content
=
content
.
replace
(
key
,
value
)
with
open
(
file_path
,
'w'
)
as
file
:
file
.
write
(
content
)
def
scan_and_replace_files
(
directory
,
replacements
):
for
root
,
dirs
,
files
in
os
.
walk
(
directory
):
for
file_name
in
files
:
if
file_name
.
endswith
(
'.py'
):
file_path
=
os
.
path
.
join
(
root
,
file_name
)
replace_in_file
(
file_path
,
replacements
)
print
(
f
"Replaced content in file:
{
file_path
}
"
)
def
main
():
parser
=
argparse
.
ArgumentParser
(
description
=
'Python script to replace content in .py files.'
)
parser
.
add_argument
(
'directory'
,
type
=
str
,
help
=
'Path to the directory containing .py files'
)
args
=
parser
.
parse_args
()
# 指定键值对替换内容
replacements
=
{
'torch.version.cuda'
:
'torch.version.dtk'
,
'CUDA_HOME'
:
'ROCM_HOME'
}
# 执行扫描和替换
scan_and_replace_files
(
args
.
directory
,
replacements
)
if
__name__
==
'__main__'
:
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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