Getting special characters when I try to list out all filenames
up vote
0
down vote
favorite
I am using Google Colab and I fairly new to it, so please pardon my ignorance. I am trying to get the file names of all the frames in a certain folder.
filenames_pics = !ls {PATH}/Pictures
I do this to try to copy all the filenames.
The output I get when i try to print it is
['frame1000.pngtframe15320.pngtframe436.png frame572.png frame680.png',
'frame1004.pngtframe15324.pngtframe440.png frame576.png frame684.png',
'frame1008.pngtframe1588.pngtframe508.png frame580.png frame688.png',
'frame100.pngtframe1592.pngtframe512.png frame584.png frame692.png',
'frame1012.pngtframe16432.pngtframe516.png frame588.png frame696.png']
What is interesting is that all the first values have this 't' in it with three frame names in it, and this is just driving me mad.
All my file names are in oder
Please help!
python google-colaboratory
add a comment |
up vote
0
down vote
favorite
I am using Google Colab and I fairly new to it, so please pardon my ignorance. I am trying to get the file names of all the frames in a certain folder.
filenames_pics = !ls {PATH}/Pictures
I do this to try to copy all the filenames.
The output I get when i try to print it is
['frame1000.pngtframe15320.pngtframe436.png frame572.png frame680.png',
'frame1004.pngtframe15324.pngtframe440.png frame576.png frame684.png',
'frame1008.pngtframe1588.pngtframe508.png frame580.png frame688.png',
'frame100.pngtframe1592.pngtframe512.png frame584.png frame692.png',
'frame1012.pngtframe16432.pngtframe516.png frame588.png frame696.png']
What is interesting is that all the first values have this 't' in it with three frame names in it, and this is just driving me mad.
All my file names are in oder
Please help!
python google-colaboratory
2
replace't'
with space' '
and split on space' '
?
– mad_
Nov 7 at 18:26
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am using Google Colab and I fairly new to it, so please pardon my ignorance. I am trying to get the file names of all the frames in a certain folder.
filenames_pics = !ls {PATH}/Pictures
I do this to try to copy all the filenames.
The output I get when i try to print it is
['frame1000.pngtframe15320.pngtframe436.png frame572.png frame680.png',
'frame1004.pngtframe15324.pngtframe440.png frame576.png frame684.png',
'frame1008.pngtframe1588.pngtframe508.png frame580.png frame688.png',
'frame100.pngtframe1592.pngtframe512.png frame584.png frame692.png',
'frame1012.pngtframe16432.pngtframe516.png frame588.png frame696.png']
What is interesting is that all the first values have this 't' in it with three frame names in it, and this is just driving me mad.
All my file names are in oder
Please help!
python google-colaboratory
I am using Google Colab and I fairly new to it, so please pardon my ignorance. I am trying to get the file names of all the frames in a certain folder.
filenames_pics = !ls {PATH}/Pictures
I do this to try to copy all the filenames.
The output I get when i try to print it is
['frame1000.pngtframe15320.pngtframe436.png frame572.png frame680.png',
'frame1004.pngtframe15324.pngtframe440.png frame576.png frame684.png',
'frame1008.pngtframe1588.pngtframe508.png frame580.png frame688.png',
'frame100.pngtframe1592.pngtframe512.png frame584.png frame692.png',
'frame1012.pngtframe16432.pngtframe516.png frame588.png frame696.png']
What is interesting is that all the first values have this 't' in it with three frame names in it, and this is just driving me mad.
All my file names are in oder
Please help!
python google-colaboratory
python google-colaboratory
edited Nov 7 at 22:36
Miki
29.1k851131
29.1k851131
asked Nov 7 at 18:24
Bhaskar Ghosh
55
55
2
replace't'
with space' '
and split on space' '
?
– mad_
Nov 7 at 18:26
add a comment |
2
replace't'
with space' '
and split on space' '
?
– mad_
Nov 7 at 18:26
2
2
replace
't'
with space ' '
and split on space ' '
?– mad_
Nov 7 at 18:26
replace
't'
with space ' '
and split on space ' '
?– mad_
Nov 7 at 18:26
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
It's probably simpler to use the built-in Python os.listdir
function.
Here's a full example:
https://colab.research.google.com/drive/1EKhDSUHBfzGdRPxm9gBGPfDGQ2vX5cPe
The key snippet:
# Python code to list the directory.
import os
pictures = os.listdir('Pictures/')
for fname in pictures:
print (fname)
print ('full path', os.path.join(os.getcwd(), fname))
Hello! thank you so much. This worked like a charm to get the filenames! :)
– Bhaskar Ghosh
Nov 7 at 19:21
The output that i was trying to get was ['frame1000.png frame15320.png frame436.png frame572.png frame680.png', 'frame1004.png frame15324.png frame440.png frame576.png frame684.png', 'frame1008.png frame1588.png frame508.png frame580.png frame688.png', 'frame100.png frame1592.png frame512.png frame584.png frame692.png', 'frame1012.png frame16432.png frame516.png frame588.png frame696.png']
– Bhaskar Ghosh
Nov 7 at 19:23
add a comment |
up vote
0
down vote
You can just replace 't
with space to match the pattern
lst=['frame1000.pngtframe15320.pngtframe436.png frame572.png frame680.png',
'frame1004.pngtframe15324.pngtframe440.png frame576.png frame684.png',
'frame1008.pngtframe1588.pngtframe508.png frame580.png frame688.png',
'frame100.pngtframe1592.pngtframe512.png frame584.png frame692.png',
'frame1012.pngtframe16432.pngtframe516.png frame588.png frame696.png']
l=
import re
for i in lst:
l.append(re.sub('s{2,}|t',' ',i))
print(l)
Output:
['frame1000.png frame15320.png frame436.png frame572.png frame680.png',
'frame1004.png frame15324.png frame440.png frame576.png frame684.png',
'frame1008.png frame1588.png frame508.png frame580.png frame688.png',
'frame100.png frame1592.png frame512.png frame584.png frame692.png',
'frame1012.png frame16432.png frame516.png frame588.png frame696.png']
Hello! Thank you so much for the quick response. The output that i was trying to get was ['frame1000.png frame15320.png frame436.png frame572.png frame680.png', 'frame1004.png frame15324.png frame440.png frame576.png frame684.png', 'frame1008.png frame1588.png frame508.png frame580.png frame688.png', 'frame100.png frame1592.png frame512.png frame584.png frame692.png', 'frame1012.png frame16432.png frame516.png frame588.png frame696.png']
– Bhaskar Ghosh
Nov 7 at 18:51
@BhaskarGhosh Edited
– mad_
Nov 7 at 18:56
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
It's probably simpler to use the built-in Python os.listdir
function.
Here's a full example:
https://colab.research.google.com/drive/1EKhDSUHBfzGdRPxm9gBGPfDGQ2vX5cPe
The key snippet:
# Python code to list the directory.
import os
pictures = os.listdir('Pictures/')
for fname in pictures:
print (fname)
print ('full path', os.path.join(os.getcwd(), fname))
Hello! thank you so much. This worked like a charm to get the filenames! :)
– Bhaskar Ghosh
Nov 7 at 19:21
The output that i was trying to get was ['frame1000.png frame15320.png frame436.png frame572.png frame680.png', 'frame1004.png frame15324.png frame440.png frame576.png frame684.png', 'frame1008.png frame1588.png frame508.png frame580.png frame688.png', 'frame100.png frame1592.png frame512.png frame584.png frame692.png', 'frame1012.png frame16432.png frame516.png frame588.png frame696.png']
– Bhaskar Ghosh
Nov 7 at 19:23
add a comment |
up vote
0
down vote
accepted
It's probably simpler to use the built-in Python os.listdir
function.
Here's a full example:
https://colab.research.google.com/drive/1EKhDSUHBfzGdRPxm9gBGPfDGQ2vX5cPe
The key snippet:
# Python code to list the directory.
import os
pictures = os.listdir('Pictures/')
for fname in pictures:
print (fname)
print ('full path', os.path.join(os.getcwd(), fname))
Hello! thank you so much. This worked like a charm to get the filenames! :)
– Bhaskar Ghosh
Nov 7 at 19:21
The output that i was trying to get was ['frame1000.png frame15320.png frame436.png frame572.png frame680.png', 'frame1004.png frame15324.png frame440.png frame576.png frame684.png', 'frame1008.png frame1588.png frame508.png frame580.png frame688.png', 'frame100.png frame1592.png frame512.png frame584.png frame692.png', 'frame1012.png frame16432.png frame516.png frame588.png frame696.png']
– Bhaskar Ghosh
Nov 7 at 19:23
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
It's probably simpler to use the built-in Python os.listdir
function.
Here's a full example:
https://colab.research.google.com/drive/1EKhDSUHBfzGdRPxm9gBGPfDGQ2vX5cPe
The key snippet:
# Python code to list the directory.
import os
pictures = os.listdir('Pictures/')
for fname in pictures:
print (fname)
print ('full path', os.path.join(os.getcwd(), fname))
It's probably simpler to use the built-in Python os.listdir
function.
Here's a full example:
https://colab.research.google.com/drive/1EKhDSUHBfzGdRPxm9gBGPfDGQ2vX5cPe
The key snippet:
# Python code to list the directory.
import os
pictures = os.listdir('Pictures/')
for fname in pictures:
print (fname)
print ('full path', os.path.join(os.getcwd(), fname))
answered Nov 7 at 18:31
Bob Smith
5,2191625
5,2191625
Hello! thank you so much. This worked like a charm to get the filenames! :)
– Bhaskar Ghosh
Nov 7 at 19:21
The output that i was trying to get was ['frame1000.png frame15320.png frame436.png frame572.png frame680.png', 'frame1004.png frame15324.png frame440.png frame576.png frame684.png', 'frame1008.png frame1588.png frame508.png frame580.png frame688.png', 'frame100.png frame1592.png frame512.png frame584.png frame692.png', 'frame1012.png frame16432.png frame516.png frame588.png frame696.png']
– Bhaskar Ghosh
Nov 7 at 19:23
add a comment |
Hello! thank you so much. This worked like a charm to get the filenames! :)
– Bhaskar Ghosh
Nov 7 at 19:21
The output that i was trying to get was ['frame1000.png frame15320.png frame436.png frame572.png frame680.png', 'frame1004.png frame15324.png frame440.png frame576.png frame684.png', 'frame1008.png frame1588.png frame508.png frame580.png frame688.png', 'frame100.png frame1592.png frame512.png frame584.png frame692.png', 'frame1012.png frame16432.png frame516.png frame588.png frame696.png']
– Bhaskar Ghosh
Nov 7 at 19:23
Hello! thank you so much. This worked like a charm to get the filenames! :)
– Bhaskar Ghosh
Nov 7 at 19:21
Hello! thank you so much. This worked like a charm to get the filenames! :)
– Bhaskar Ghosh
Nov 7 at 19:21
The output that i was trying to get was ['frame1000.png frame15320.png frame436.png frame572.png frame680.png', 'frame1004.png frame15324.png frame440.png frame576.png frame684.png', 'frame1008.png frame1588.png frame508.png frame580.png frame688.png', 'frame100.png frame1592.png frame512.png frame584.png frame692.png', 'frame1012.png frame16432.png frame516.png frame588.png frame696.png']
– Bhaskar Ghosh
Nov 7 at 19:23
The output that i was trying to get was ['frame1000.png frame15320.png frame436.png frame572.png frame680.png', 'frame1004.png frame15324.png frame440.png frame576.png frame684.png', 'frame1008.png frame1588.png frame508.png frame580.png frame688.png', 'frame100.png frame1592.png frame512.png frame584.png frame692.png', 'frame1012.png frame16432.png frame516.png frame588.png frame696.png']
– Bhaskar Ghosh
Nov 7 at 19:23
add a comment |
up vote
0
down vote
You can just replace 't
with space to match the pattern
lst=['frame1000.pngtframe15320.pngtframe436.png frame572.png frame680.png',
'frame1004.pngtframe15324.pngtframe440.png frame576.png frame684.png',
'frame1008.pngtframe1588.pngtframe508.png frame580.png frame688.png',
'frame100.pngtframe1592.pngtframe512.png frame584.png frame692.png',
'frame1012.pngtframe16432.pngtframe516.png frame588.png frame696.png']
l=
import re
for i in lst:
l.append(re.sub('s{2,}|t',' ',i))
print(l)
Output:
['frame1000.png frame15320.png frame436.png frame572.png frame680.png',
'frame1004.png frame15324.png frame440.png frame576.png frame684.png',
'frame1008.png frame1588.png frame508.png frame580.png frame688.png',
'frame100.png frame1592.png frame512.png frame584.png frame692.png',
'frame1012.png frame16432.png frame516.png frame588.png frame696.png']
Hello! Thank you so much for the quick response. The output that i was trying to get was ['frame1000.png frame15320.png frame436.png frame572.png frame680.png', 'frame1004.png frame15324.png frame440.png frame576.png frame684.png', 'frame1008.png frame1588.png frame508.png frame580.png frame688.png', 'frame100.png frame1592.png frame512.png frame584.png frame692.png', 'frame1012.png frame16432.png frame516.png frame588.png frame696.png']
– Bhaskar Ghosh
Nov 7 at 18:51
@BhaskarGhosh Edited
– mad_
Nov 7 at 18:56
add a comment |
up vote
0
down vote
You can just replace 't
with space to match the pattern
lst=['frame1000.pngtframe15320.pngtframe436.png frame572.png frame680.png',
'frame1004.pngtframe15324.pngtframe440.png frame576.png frame684.png',
'frame1008.pngtframe1588.pngtframe508.png frame580.png frame688.png',
'frame100.pngtframe1592.pngtframe512.png frame584.png frame692.png',
'frame1012.pngtframe16432.pngtframe516.png frame588.png frame696.png']
l=
import re
for i in lst:
l.append(re.sub('s{2,}|t',' ',i))
print(l)
Output:
['frame1000.png frame15320.png frame436.png frame572.png frame680.png',
'frame1004.png frame15324.png frame440.png frame576.png frame684.png',
'frame1008.png frame1588.png frame508.png frame580.png frame688.png',
'frame100.png frame1592.png frame512.png frame584.png frame692.png',
'frame1012.png frame16432.png frame516.png frame588.png frame696.png']
Hello! Thank you so much for the quick response. The output that i was trying to get was ['frame1000.png frame15320.png frame436.png frame572.png frame680.png', 'frame1004.png frame15324.png frame440.png frame576.png frame684.png', 'frame1008.png frame1588.png frame508.png frame580.png frame688.png', 'frame100.png frame1592.png frame512.png frame584.png frame692.png', 'frame1012.png frame16432.png frame516.png frame588.png frame696.png']
– Bhaskar Ghosh
Nov 7 at 18:51
@BhaskarGhosh Edited
– mad_
Nov 7 at 18:56
add a comment |
up vote
0
down vote
up vote
0
down vote
You can just replace 't
with space to match the pattern
lst=['frame1000.pngtframe15320.pngtframe436.png frame572.png frame680.png',
'frame1004.pngtframe15324.pngtframe440.png frame576.png frame684.png',
'frame1008.pngtframe1588.pngtframe508.png frame580.png frame688.png',
'frame100.pngtframe1592.pngtframe512.png frame584.png frame692.png',
'frame1012.pngtframe16432.pngtframe516.png frame588.png frame696.png']
l=
import re
for i in lst:
l.append(re.sub('s{2,}|t',' ',i))
print(l)
Output:
['frame1000.png frame15320.png frame436.png frame572.png frame680.png',
'frame1004.png frame15324.png frame440.png frame576.png frame684.png',
'frame1008.png frame1588.png frame508.png frame580.png frame688.png',
'frame100.png frame1592.png frame512.png frame584.png frame692.png',
'frame1012.png frame16432.png frame516.png frame588.png frame696.png']
You can just replace 't
with space to match the pattern
lst=['frame1000.pngtframe15320.pngtframe436.png frame572.png frame680.png',
'frame1004.pngtframe15324.pngtframe440.png frame576.png frame684.png',
'frame1008.pngtframe1588.pngtframe508.png frame580.png frame688.png',
'frame100.pngtframe1592.pngtframe512.png frame584.png frame692.png',
'frame1012.pngtframe16432.pngtframe516.png frame588.png frame696.png']
l=
import re
for i in lst:
l.append(re.sub('s{2,}|t',' ',i))
print(l)
Output:
['frame1000.png frame15320.png frame436.png frame572.png frame680.png',
'frame1004.png frame15324.png frame440.png frame576.png frame684.png',
'frame1008.png frame1588.png frame508.png frame580.png frame688.png',
'frame100.png frame1592.png frame512.png frame584.png frame692.png',
'frame1012.png frame16432.png frame516.png frame588.png frame696.png']
edited Nov 7 at 18:56
answered Nov 7 at 18:30
mad_
3,1111920
3,1111920
Hello! Thank you so much for the quick response. The output that i was trying to get was ['frame1000.png frame15320.png frame436.png frame572.png frame680.png', 'frame1004.png frame15324.png frame440.png frame576.png frame684.png', 'frame1008.png frame1588.png frame508.png frame580.png frame688.png', 'frame100.png frame1592.png frame512.png frame584.png frame692.png', 'frame1012.png frame16432.png frame516.png frame588.png frame696.png']
– Bhaskar Ghosh
Nov 7 at 18:51
@BhaskarGhosh Edited
– mad_
Nov 7 at 18:56
add a comment |
Hello! Thank you so much for the quick response. The output that i was trying to get was ['frame1000.png frame15320.png frame436.png frame572.png frame680.png', 'frame1004.png frame15324.png frame440.png frame576.png frame684.png', 'frame1008.png frame1588.png frame508.png frame580.png frame688.png', 'frame100.png frame1592.png frame512.png frame584.png frame692.png', 'frame1012.png frame16432.png frame516.png frame588.png frame696.png']
– Bhaskar Ghosh
Nov 7 at 18:51
@BhaskarGhosh Edited
– mad_
Nov 7 at 18:56
Hello! Thank you so much for the quick response. The output that i was trying to get was ['frame1000.png frame15320.png frame436.png frame572.png frame680.png', 'frame1004.png frame15324.png frame440.png frame576.png frame684.png', 'frame1008.png frame1588.png frame508.png frame580.png frame688.png', 'frame100.png frame1592.png frame512.png frame584.png frame692.png', 'frame1012.png frame16432.png frame516.png frame588.png frame696.png']
– Bhaskar Ghosh
Nov 7 at 18:51
Hello! Thank you so much for the quick response. The output that i was trying to get was ['frame1000.png frame15320.png frame436.png frame572.png frame680.png', 'frame1004.png frame15324.png frame440.png frame576.png frame684.png', 'frame1008.png frame1588.png frame508.png frame580.png frame688.png', 'frame100.png frame1592.png frame512.png frame584.png frame692.png', 'frame1012.png frame16432.png frame516.png frame588.png frame696.png']
– Bhaskar Ghosh
Nov 7 at 18:51
@BhaskarGhosh Edited
– mad_
Nov 7 at 18:56
@BhaskarGhosh Edited
– mad_
Nov 7 at 18:56
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53195557%2fgetting-special-characters-when-i-try-to-list-out-all-filenames%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
replace
't'
with space' '
and split on space' '
?– mad_
Nov 7 at 18:26