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
MMCV
Commits
50537ddf
Unverified
Commit
50537ddf
authored
Jun 01, 2021
by
lizz
Committed by
GitHub
Jun 01, 2021
Browse files
Imporve windows support for list_from_file (#1043)
Signed-off-by:
lizz
<
lizz@sensetime.com
>
parent
b028a1f9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
4 deletions
+5
-4
mmcv/fileio/parse.py
mmcv/fileio/parse.py
+5
-4
No files found.
mmcv/fileio/parse.py
View file @
50537ddf
# Copyright (c) Open-MMLab. All rights reserved.
def
list_from_file
(
filename
,
prefix
=
''
,
offset
=
0
,
max_num
=
0
):
def
list_from_file
(
filename
,
prefix
=
''
,
offset
=
0
,
max_num
=
0
,
encoding
=
'utf-8'
):
"""Load a text file and parse the content as a list of strings.
Args:
...
...
@@ -8,19 +8,20 @@ def list_from_file(filename, prefix='', offset=0, max_num=0):
offset (int): The offset of lines.
max_num (int): The maximum number of lines to be read,
zeros and negatives mean no limitation.
encoding (str): Encoding used to open the file. Default utf-8.
Returns:
list[str]: A list of strings.
"""
cnt
=
0
item_list
=
[]
with
open
(
filename
,
'r'
)
as
f
:
with
open
(
filename
,
'r'
,
encoding
=
encoding
)
as
f
:
for
_
in
range
(
offset
):
f
.
readline
()
for
line
in
f
:
if
max_num
>
0
and
cnt
>=
max_num
:
if
0
<
max_num
<=
cnt
:
break
item_list
.
append
(
prefix
+
line
.
rstrip
(
'
\n
'
))
item_list
.
append
(
prefix
+
line
.
rstrip
(
'
\n
\r
'
))
cnt
+=
1
return
item_list
...
...
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