Question: (Closed) Rename files that are stored in a list in python
gravatar for Jonas.Koch
20 months ago by
Jonas.Koch0 wrote:


I generated a list that contains 3 text files

list = [path/A.txt, path/B.txt, path/C.txt]

Now, I want to remove the paths of the filenames, so that I have:

list = [A.txt, B.txt, C.txt]

I tried to use the os.path.basename() function in a for loop:

for file in list: file = os.path.basename(file)

I know this does not work out and I have to adress the indices of the files in the list somehow, but I got stuck...

Can someone help me with this issue?


ADD COMMENTlink modified 20 months ago • written 20 months ago by Jonas.Koch0

Hello Jonas.Koch!

We believe that this post does not fit the main topic of this site.

not related to bioinformatics

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.


ADD REPLYlink written 20 months ago by Pierre Lindenbaum131k

I agree this isn't clear how it relates to bioinformatics, but here's some help

(If the paths are all the same length)

my_list=["path/A.txt", "path/B.txt", "path/C.txt"]
[x[5:] for x in my_list]

['A.txt', 'B.txt', 'C.txt']
ADD REPLYlink written 20 months ago by goodez480
Please log in to add an answer.
The thread is closed. No new answers may be added.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1331 users visited in the last hour