Python Forum
code works in python shell, but not in a terminal
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
code works in python shell, but not in a terminal
#4
Well the idle3 editor is set to put 4 spaces for a tab.

The bit of my little program that does the work was very difficult to indent. In the end, I tried this, which works every time in the idle3 python shell.

for sheet in sheets:
	activeDirectory = pathToPhotos + sheet + '/'
	print('the active photo directory is ' + activeDirectory)
	for filename in os.listdir(activeDirectory):
			if not (filename.endswith('.jpg')):
				continue
			for rowNum in range(beginRow, wb[sheet].max_row + 1):
				getName = filename.split('.')
				if (getName[0] == wb[sheet].cell(row=rowNum, column=col).value):
					print('found the name! Name is: %s ' % (getName[0]))
					print('Putting pic in row ' + str(rowNum))
					img = Image(activeDirectory + filename)
					wb[sheet].add_image(img, 'A' + str(rowNum))
Seems like the indents are all over the place, but it works each time in the python shell. However, in a bash terminal, it never gets that far, because of the above mentioned problem with the colon.
Reply


Messages In This Thread
RE: code works in python shell, but not in a terminal - by Pedroski55 - Sep-09-2018, 11:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  My code works on Jupyter Lab/Notebook, but NOT on Visual Code Editor jst 4 1,134 Nov-15-2023, 06:56 PM
Last Post: jst
  Help creating shell scrip for python file marciokoko 10 1,457 Sep-16-2023, 09:46 PM
Last Post: snippsat
  invoking python in Terminal Euler 2 668 Aug-25-2023, 06:17 AM
Last Post: perfringo
  Code works but doesn't give the right results colin_dent 2 761 Jun-22-2023, 06:04 PM
Last Post: jefsummers
  Launch Python IDLE Shell from terminal Pavel_47 5 1,311 Feb-17-2023, 02:53 PM
Last Post: Pavel_47
  Python VS Code: using print command twice but not getting output from terminal kdx264 4 1,147 Jan-16-2023, 07:38 PM
Last Post: Skaperen
  Code used to work 100%, now sometimes works! muzicman0 5 1,523 Jan-13-2023, 05:09 PM
Last Post: muzicman0
  Can a program execute code in iPython shell and get result? deanhystad 3 1,792 Jun-17-2022, 03:45 AM
Last Post: Larz60+
  batch file for running python scipt in Windows shell MaartenRo 2 1,954 Jan-21-2022, 02:36 PM
Last Post: MaartenRo
  Pyspark - my code works but I want to make it better Kevin 1 1,821 Dec-01-2021, 05:04 AM
Last Post: Kevin

Forum Jump:

User Panel Messages

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