V
V
versedmm2017-03-03 15:00:30
Python
versedmm, 2017-03-03 15:00:30

How to give new attributes to elements in a list?

Hello.
There is a folder with *.wav files and there is a variable that includes all these files as a list -
soundX = glob.glob("*.wav")
How to correctly access this list by element in order to extract this element for playback?
Like this:

sound4 = pygame.mixer.Sound(path.join(any_dir, 'Powerup.wav'))
sound4.play()

The way I see it is that these elements need to be given new attributes. Maybe there are other options?
python 3.5, pygame, win

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
versedmm, 2017-03-03
@versedmm

Resolved the issue.

# импортируем необходимые модули (есть лишние)
import pygame
import random
import shutil
import os
from os import path
import glob
pygame.mixer.init()

# указываем папку где находятся файлы *.wav
any_dir = path.join(path.dirname(__file__))

# Создаем переменную-список, в которые фойдут файлы *.wav
soundX  = glob.glob("*.wav")

#Собственно сам цикл, который преобразовывает
for items in range(len(soundX)):
    soundX[1] = pygame.mixer.Sound(path.join(any_dir, 'Powerup.wav'))
soundX[1].play()

pytalk.ru/forum/python/40838 - found a hint on this site.
Thanks to all.

S
sim3x, 2017-03-03
@sim3x

https://learnpythonthehardway.org/book/ex32.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question