Python Forum
How to include Variable in File Path
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to include Variable in File Path
#3
(Jan-05-2020, 12:53 AM)ichabod801 Wrote: You should look into the format method of strings, or the even newer f-string syntax (Python 3.6+).

# format method
current_sound = playsound("C:/Users/thoma/Desktop/test/{}.mp3".format(item_list[current_item_index]["som"]))
# f-string
current_sound = playsound(f"C:/Users/thoma/Desktop/test/{item_list[current_item_index]['som']}.mp3")

Thank your for the answer!

i've got an error: TypeError: 'module' object is not callable
Reply


Messages In This Thread
How to include Variable in File Path - by penahuse - Jan-05-2020, 12:43 AM
RE: How to include Variable in File Path - by penahuse - Jan-05-2020, 01:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to include one script into another? MorningWave 8 596 Mar-21-2024, 10:34 PM
Last Post: MorningWave
  working directory if using windows path-variable chitarup 2 780 Nov-28-2023, 11:36 PM
Last Post: chitarup
  how include a python code in notpad++ plugin akbarza 2 684 Sep-25-2023, 08:25 PM
Last Post: deanhystad
  Regex Include and Exclude patterns in Same Expression starzar 2 853 May-23-2023, 09:12 AM
Last Post: Gribouillis
  File path by adding various variables Mishal0488 2 1,098 Apr-28-2023, 07:17 PM
Last Post: deanhystad
  Need help on how to include single quotes on data of variable string hani_hms 5 2,164 Jan-10-2023, 11:26 AM
Last Post: codinglearner
  Script File Failure-Path Error? jerryf 13 3,584 Nov-30-2022, 09:58 AM
Last Post: jerryf
  How to include input as part of variable name Mark17 4 2,567 Oct-01-2021, 06:45 PM
Last Post: Mark17
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,253 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  [solved] subdictionaries path as variable paul18fr 4 2,718 May-18-2021, 08:12 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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