Python Forum
How to split name.jpg and get the string name
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to split name.jpg and get the string name
#4
Thanks, that did it! I used:

# put the pics in the excel file in column 1
for filename in os.listdir(pathToPhotos):
	if not (filename.endswith('.jpg')):
		continue
	for rowNum in range(beginRow, ws.max_row + 1):
		getName = filename.split('.')
		if (getName[0] == ws.cell(row=rowNum, column=col).value):
			print('found the name! Name is: %s ' % (getName[0]))
			print('Putting pic in row ' + str(rowNum))
			img = Image(pathToPhotos + filename)
			ws.add_image(img, 'A' + str(rowNum))
Which worked fine. However, other sheets in this excel file already had photos which I had manually inserted. Luckily, I saved the file as filename_copy.xlsx , because, when I looked, all the other photos for old classes were gone!! I do not know why!
I managed to copy the new class sheet with photos into the old excel file which saved the day.
Reply


Messages In This Thread
RE: How to split name.jpg and get the string name - by Pedroski55 - Sep-12-2017, 11:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  doing string split with 2 or more split characters Skaperen 22 2,949 Aug-13-2023, 01:57 AM
Last Post: Skaperen
Sad How to split a String from Text Input into 40 char chunks? lastyle 7 1,332 Aug-01-2023, 09:36 AM
Last Post: Pedroski55
  [split] Parse Nested JSON String in Python mmm07 4 1,686 Mar-28-2023, 06:07 PM
Last Post: snippsat
  Split string using variable found in a list japo85 2 1,413 Jul-11-2022, 08:52 AM
Last Post: japo85
  Split string knob 2 1,957 Nov-19-2021, 10:27 AM
Last Post: ghoul
  Split string between two different delimiters, with exceptions DreamingInsanity 2 2,139 Aug-24-2020, 08:23 AM
Last Post: DreamingInsanity
  split string enigma619 1 2,138 May-20-2020, 02:47 PM
Last Post: perfringo
  Split string with multiple delimiters and keep the string in "groups" DreamingInsanity 4 6,877 May-12-2020, 09:31 AM
Last Post: DeaD_EyE
  Split a long string into other strings with no delimiters/characters krewlaz 4 2,909 Nov-15-2019, 02:48 PM
Last Post: ichabod801
  input string split Eric7Giants 3 3,141 Nov-13-2019, 07:19 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020