0
   Result :
   test1edited.csv
   test2edited.csv
   test3edited.csv           
   test4edited.csv
   test5edited.csv

I want to change testedited.csv into c(c1, c2, c3, c4, c5).csv.

Do you know how to change the file name using python code above?

platanus
  • 49
  • 7
  • Does this answer your question? [How can I concatenate str and int objects?](https://stackoverflow.com/questions/25675943/how-can-i-concatenate-str-and-int-objects) – Michael Delgado Jun 08 '20 at 06:27
  • Specifically, use a for loop `for i in range(5)` and then build your input and output file names from there. Or, if you'd like to use glob, use [replace](https://docs.python.org/3.8/library/stdtypes.html#str.replace) to modify the string. – Michael Delgado Jun 08 '20 at 06:28
  • @Michael Delgado - It doesn't answer regarding my question - 'How can I concatenate str and in object?'...... And let me know clearly how to solve my problems using example code. – platanus Jun 08 '20 at 06:56
  • Can you show us what you've tried and why it's not working? – Michael Delgado Jun 08 '20 at 07:02
  • @Michael Delgado - Can you check my code? – platanus Jun 08 '20 at 08:31
  • Instead of taking the up to the last four characters, `f[:-4]`, just take the number - `f[4:-4]` – Michael Delgado Jun 08 '20 at 08:39
  • @MichaelDelgado Delgado - When I change as f[r:-4], it occurs error-"FileNotFoundError: [Errno 2] No such file or directory: 'A/test1edited.csv'". – platanus Jun 08 '20 at 08:53
  • @MichaelDelgado Delgado - I automatically want to change test*edted.csv into c*.csv. Do you know how to solve the problem? – platanus Jun 08 '20 at 09:00
  • This is a super simple string substitution question. Check out the python docs on [string methods](https://docs.python.org/3.8/library/stdtypes.html#string-methods). You can use f.replace('test', 'c')` to replace occurrences of the substring `'test'` with `'c'`. – Michael Delgado Jun 08 '20 at 09:05

0 Answers0