Python Forum
Changing Directory based on user input
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Changing Directory based on user input
#13
(Aug-13-2020, 02:54 PM)GOTO10 Wrote: Your assignment statements on line 6 and 7 are not doing what you think they are. In each case, you are assigning a variable to the value returned by a function call. Both of these functions just return the Python default value of None, so if you use them later (as you do with new_path in line 26), you are passing a value of None. When you make the call on line 26, you need to ensure that you are passing a valid path and filename, so make sure you're assigning your path variables the values you actually want them to contain.

Also, be aware that os.makedirs('Thumbnails') will fail if the Thumbnails folder already exists. Here is one way to correctly assign a variable to the desired thumbnails path and create that folder only if it doesn't already exist (this do:

path = input("Where are your images? > ")
# you should probably add code here to verify that the path entered by the user is valid before proceeding
thumb_path = (path + '\\Thumbnails')
if not os.path.exists(thumb_path):
    os.mkdir(thumb_path)

Thank you for that - that's a great help!

The images are saving to the created folder (which is great) but I am now getting the print message from line 13 (regarding invalid file type) - is there a way in which I can still keep the

 new_size.save( "Thumbnail " + fn + ext)
that now works, but make sure that it doesn't print the error?

I am hoping that this will be my last question with this - I really appreciate your help with this.

Many thanks,
paulmerton4pope
Reply


Messages In This Thread
RE: Changing Directory based on user input - by paulmerton4pope - Aug-14-2020, 10:59 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to create a menu and execute a function based on user selection in python? Thedarkphoenix 1 1,327 Nov-23-2022, 07:53 PM
Last Post: Larz60+
Question Simulate an answer based on user input [Beginner needs guidance] Bombardini 1 1,291 Nov-12-2022, 03:47 AM
Last Post: deanhystad
  Print user input into triangle djtjhokie 1 2,385 Nov-07-2020, 07:01 PM
Last Post: buran
  sys.stdin to do a word count based on user entry Kaltex 3 3,693 Jul-19-2020, 01:54 PM
Last Post: deanhystad
  how to add the user input from file into list wilson20 8 4,337 May-03-2020, 10:52 PM
Last Post: Larz60+
  Writing a function that changes its answer based on user input SirRavenclaw 2 2,818 Dec-21-2019, 09:46 PM
Last Post: Clunk_Head
  Print the longest str from user input edwdas 5 4,167 Nov-04-2019, 02:02 PM
Last Post: perfringo
  how to add user input to a dictionary to a graph KINGLEBRON 3 3,045 Jul-31-2019, 09:09 PM
Last Post: SheeppOSU
  New to Python - tiny coding assistance on user input function and assign to variable Mountain_Duck 1 2,519 Mar-23-2019, 06:54 PM
Last Post: Yoriz
  Extracting list element with user input valve 1 2,587 Mar-11-2019, 07:37 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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