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
#2
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")
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
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 ichabod801 - Jan-05-2020, 12:53 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to include one script into another? MorningWave 8 568 Mar-21-2024, 10:34 PM
Last Post: MorningWave
  working directory if using windows path-variable chitarup 2 764 Nov-28-2023, 11:36 PM
Last Post: chitarup
  how include a python code in notpad++ plugin akbarza 2 666 Sep-25-2023, 08:25 PM
Last Post: deanhystad
  Regex Include and Exclude patterns in Same Expression starzar 2 823 May-23-2023, 09:12 AM
Last Post: Gribouillis
  File path by adding various variables Mishal0488 2 1,074 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,115 Jan-10-2023, 11:26 AM
Last Post: codinglearner
  Script File Failure-Path Error? jerryf 13 3,523 Nov-30-2022, 09:58 AM
Last Post: jerryf
  How to include input as part of variable name Mark17 4 2,545 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,239 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  [solved] subdictionaries path as variable paul18fr 4 2,687 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