Compound Condition WHILE Loop Syntax Error – How to fix❓ /u/SIGCPT Python Education

Compound Condition WHILE Loop Syntax Error – How to fix❓ /u/SIGCPT Python Education

#!/usr/bin/env python3
#readiwriteo.py

import os import pdb;

FI = open(‘/Users/PyDir/PYTxtInputestFile.txt’,’r’)

n = 0
n_incrementer = 0
n = int(input (“# of Rec Outs: “))
n_incrementer == n
While n != 0 and n_incrementer < n_incrementer + 1 :

”’
readiwriteo.py
While n != 0 and n_incrementer < n_incrementer + 1 :
SyntaxError:invalid syntax
”’
n -= 1
n_incrementer += 1
linei = FI.readline()
FO = open(‘/Users/PyDir/TesterOFile’+’_xl’ + str(n_incrementer) +’.txt’ ,’w’)
FO.write(linei)
print(linei.strip())
FO.close

My Objective is to write each line in the Input File starting w line 1 and creating an Output File identified with line number as part of the Output File.

And I am attempting to use an integer to limit the number of Input File Lines read and Output Files written.

And I can not figure out the correct syntax. Any assistance with this would be much appreciated?

submitted by /u/SIGCPT
[link] [comments]

​r/learnpython #!/usr/bin/env python3 #readiwriteo.py import os import pdb; FI = open(‘/Users/PyDir/PYTxtInputestFile.txt’,’r’) n = 0 n_incrementer = 0 n = int(input (“# of Rec Outs: “)) n_incrementer == n While n != 0 and n_incrementer < n_incrementer + 1 : ”’ readiwriteo.py While n != 0 and n_incrementer < n_incrementer + 1 : SyntaxError:invalid syntax ”’ n -= 1 n_incrementer += 1 linei = FI.readline() FO = open(‘/Users/PyDir/TesterOFile’+’_xl’ + str(n_incrementer) +’.txt’ ,’w’) FO.write(linei) print(linei.strip()) FO.close My Objective is to write each line in the Input File starting w line 1 and creating an Output File identified with line number as part of the Output File. And I am attempting to use an integer to limit the number of Input File Lines read and Output Files written. And I can not figure out the correct syntax. Any assistance with this would be much appreciated? submitted by /u/SIGCPT [link] [comments] 

#!/usr/bin/env python3
#readiwriteo.py

import os import pdb;

FI = open(‘/Users/PyDir/PYTxtInputestFile.txt’,’r’)

n = 0
n_incrementer = 0
n = int(input (“# of Rec Outs: “))
n_incrementer == n
While n != 0 and n_incrementer < n_incrementer + 1 :

”’
readiwriteo.py
While n != 0 and n_incrementer < n_incrementer + 1 :
SyntaxError:invalid syntax
”’
n -= 1
n_incrementer += 1
linei = FI.readline()
FO = open(‘/Users/PyDir/TesterOFile’+’_xl’ + str(n_incrementer) +’.txt’ ,’w’)
FO.write(linei)
print(linei.strip())
FO.close

My Objective is to write each line in the Input File starting w line 1 and creating an Output File identified with line number as part of the Output File.

And I am attempting to use an integer to limit the number of Input File Lines read and Output Files written.

And I can not figure out the correct syntax. Any assistance with this would be much appreciated?

submitted by /u/SIGCPT
[link] [comments]  #!/usr/bin/env python3 #readiwriteo.py import os import pdb; FI = open(‘/Users/PyDir/PYTxtInputestFile.txt’,’r’) n = 0 n_incrementer = 0 n = int(input (“# of Rec Outs: “)) n_incrementer == n While n != 0 and n_incrementer < n_incrementer + 1 : ”’ readiwriteo.py While n != 0 and n_incrementer < n_incrementer + 1 : SyntaxError:invalid syntax ”’ n -= 1 n_incrementer += 1 linei = FI.readline() FO = open(‘/Users/PyDir/TesterOFile’+’_xl’ + str(n_incrementer) +’.txt’ ,’w’) FO.write(linei) print(linei.strip()) FO.close My Objective is to write each line in the Input File starting w line 1 and creating an Output File identified with line number as part of the Output File. And I am attempting to use an integer to limit the number of Input File Lines read and Output Files written. And I can not figure out the correct syntax. Any assistance with this would be much appreciated? submitted by /u/SIGCPT [link] [comments]

Read more

I want to learn how to run programs on the GPU. /u/Capusotes Python Education

I want to learn how to run programs on the GPU. /u/Capusotes Python Education

My idea is to do physical simulations and display them on the screen in real time.

I’ve been doing some things with pyopencl.(but without displaying on the screen)

To do these simulations, are pyopencl and pyopengl the best?

What should I learn? Could you recommend me some tutorial, video or book? I’ve been reading “OpenCL programming Guide” and “OpenCl in Action” but I found them very tedious.

I’m a beginner, I only know a little bit of Python and a little bit of C.

Thanks.

submitted by /u/Capusotes
[link] [comments]

​r/learnpython My idea is to do physical simulations and display them on the screen in real time. I’ve been doing some things with pyopencl.(but without displaying on the screen) To do these simulations, are pyopencl and pyopengl the best? What should I learn? Could you recommend me some tutorial, video or book? I’ve been reading “OpenCL programming Guide” and “OpenCl in Action” but I found them very tedious. I’m a beginner, I only know a little bit of Python and a little bit of C. Thanks. submitted by /u/Capusotes [link] [comments] 

My idea is to do physical simulations and display them on the screen in real time.

I’ve been doing some things with pyopencl.(but without displaying on the screen)

To do these simulations, are pyopencl and pyopengl the best?

What should I learn? Could you recommend me some tutorial, video or book? I’ve been reading “OpenCL programming Guide” and “OpenCl in Action” but I found them very tedious.

I’m a beginner, I only know a little bit of Python and a little bit of C.

Thanks.

submitted by /u/Capusotes
[link] [comments]  My idea is to do physical simulations and display them on the screen in real time. I’ve been doing some things with pyopencl.(but without displaying on the screen) To do these simulations, are pyopencl and pyopengl the best? What should I learn? Could you recommend me some tutorial, video or book? I’ve been reading “OpenCL programming Guide” and “OpenCl in Action” but I found them very tedious. I’m a beginner, I only know a little bit of Python and a little bit of C. Thanks. submitted by /u/Capusotes [link] [comments]

Read more

Issue With “mouse.get_position()” In The Mouse Module /u/i_count_sheepatwork Python Education

Issue With “mouse.get_position()” In The Mouse Module /u/i_count_sheepatwork Python Education

Hello, I am fairly new to working with Linux and coding, and have been trying python for only a few days.

I am trying to use the “‘mouse.get_position()” function from the Mouse Module but am having some difficulties.

Issues:

  1. First Problem – If I run the following code the mouse position will only update if my mouse is INSIDE the PyCharm program window, and the moment my mouse leaves that window it just updates with the last position the mouse was in, when inside the window. (I can resize the window while the program is running and it will still only update while the mouse cursor is inside)
  2. Second Problem – Running the same code but instead in the Linux terminal wont even update the the mouse position anymore and only repeat the last position the mouse was in when running the program.

Code:

import mouse import time while True: mouse_x, mouse_y = mouse.get_position() print(f'X:{mouse_x}, Y:{mouse_y}') time.sleep(0.25)import mouse 

Important Notes??:

I am running on the latest version of Ubuntu (fresh install and to my knowledge all packages updated)

The python project is running in a virtual environment

(also if anyone wants I could screen record my issues to possibly share it that way)

submitted by /u/i_count_sheepatwork
[link] [comments]

​r/learnpython Hello, I am fairly new to working with Linux and coding, and have been trying python for only a few days. I am trying to use the “‘mouse.get_position()” function from the Mouse Module but am having some difficulties. Issues: First Problem – If I run the following code the mouse position will only update if my mouse is INSIDE the PyCharm program window, and the moment my mouse leaves that window it just updates with the last position the mouse was in, when inside the window. (I can resize the window while the program is running and it will still only update while the mouse cursor is inside) Second Problem – Running the same code but instead in the Linux terminal wont even update the the mouse position anymore and only repeat the last position the mouse was in when running the program. Code: import mouse import time while True: mouse_x, mouse_y = mouse.get_position() print(f’X:{mouse_x}, Y:{mouse_y}’) time.sleep(0.25)import mouse Important Notes??: I am running on the latest version of Ubuntu (fresh install and to my knowledge all packages updated) The python project is running in a virtual environment (also if anyone wants I could screen record my issues to possibly share it that way) submitted by /u/i_count_sheepatwork [link] [comments] 

Hello, I am fairly new to working with Linux and coding, and have been trying python for only a few days.

I am trying to use the “‘mouse.get_position()” function from the Mouse Module but am having some difficulties.

Issues:

  1. First Problem – If I run the following code the mouse position will only update if my mouse is INSIDE the PyCharm program window, and the moment my mouse leaves that window it just updates with the last position the mouse was in, when inside the window. (I can resize the window while the program is running and it will still only update while the mouse cursor is inside)
  2. Second Problem – Running the same code but instead in the Linux terminal wont even update the the mouse position anymore and only repeat the last position the mouse was in when running the program.

Code:

import mouse import time while True: mouse_x, mouse_y = mouse.get_position() print(f'X:{mouse_x}, Y:{mouse_y}') time.sleep(0.25)import mouse 

Important Notes??:

I am running on the latest version of Ubuntu (fresh install and to my knowledge all packages updated)

The python project is running in a virtual environment

(also if anyone wants I could screen record my issues to possibly share it that way)

submitted by /u/i_count_sheepatwork
[link] [comments]  Hello, I am fairly new to working with Linux and coding, and have been trying python for only a few days. I am trying to use the “‘mouse.get_position()” function from the Mouse Module but am having some difficulties. Issues: First Problem – If I run the following code the mouse position will only update if my mouse is INSIDE the PyCharm program window, and the moment my mouse leaves that window it just updates with the last position the mouse was in, when inside the window. (I can resize the window while the program is running and it will still only update while the mouse cursor is inside) Second Problem – Running the same code but instead in the Linux terminal wont even update the the mouse position anymore and only repeat the last position the mouse was in when running the program. Code: import mouse import time while True: mouse_x, mouse_y = mouse.get_position() print(f’X:{mouse_x}, Y:{mouse_y}’) time.sleep(0.25)import mouse Important Notes??: I am running on the latest version of Ubuntu (fresh install and to my knowledge all packages updated) The python project is running in a virtual environment (also if anyone wants I could screen record my issues to possibly share it that way) submitted by /u/i_count_sheepatwork [link] [comments]

Read more

Why does this multi-threaded program never end? /u/eggtrie Python Education

Why does this multi-threaded program never end? /u/eggtrie Python Education

This is my solution to https://leetcode.com/problems/print-zero-even-odd/

The question is:

You are given an instance of the class ZeroEvenOdd that has three functions: zero, even, and odd. The same instance of ZeroEvenOdd will be passed to three different threads:

Thread A: calls zero() that should only output 0's. Thread B: calls even() that should only output even numbers. Thread C: calls odd() that should only output odd numbers. 

Modify the given class to output the series “010203040506…” where the length of the series must be 2n.

import threading class ZeroEvenOdd: def __init__(self, n): self.n = n self._cond_var = threading.Condition() self._shared_idx = 0 # printNumber(x) outputs "x", where x is an integer. def zero(self, printNumber: 'Callable[[int], None]') -> None: while self._shared_idx < self.n: with self._cond_var: # The wait() method releases the lock, and then blocks until another thread # awakens it by calling notify() or notify_all(). self._cond_var.wait_for(lambda: self._shared_idx&1 == 0) printNumber(0) self._shared_idx += 1 self._cond_var.notify_all() def even(self, printNumber: 'Callable[[int], None]') -> None: self._print_nonzero_when(printNumber, lambda: self._shared_idx%2 == 1) def odd(self, printNumber: 'Callable[[int], None]') -> None: self._print_nonzero_when(printNumber, lambda: self._shared_idx%2 == 0) def _print_nonzero_when(self, printNumber, predicate): while self._shared_idx < self.n: with self._cond_var: self._cond_var.wait_for(predicate) printNumber(int(ceil(self._shared_idx/2))) self._shared_idx += 1 self._cond_var.notify_all() 

However, if I run this code on my computer locally, it does work.

from math import ceil import threading class ZeroEvenOdd: def __init__(self, n): self.n = n self._cond_var = threading.Condition() self._shared_idx = 0 def zero(self) -> None: with self._cond_var: while self._shared_idx < self.n: # The wait() method releases the lock, and then blocks until another thread # awakens it by calling notify() or notify_all(). self._cond_var.wait_for(lambda: self._shared_idx&1 == 0) print(0) self._shared_idx += 1 self._cond_var.notify_all() def even(self) -> None: self._print_nonzero_when(print, lambda: self._shared_idx%4 == 1) def odd(self) -> None: self._print_nonzero_when(print, lambda: self._shared_idx%4 == 3) def _print_nonzero_when(self, print, predicate): with self._cond_var: while self._shared_idx < self.n: self._cond_var.wait_for(predicate) print(int(ceil(self._shared_idx/2))) self._shared_idx += 1 self._cond_var.notify_all() zeo = ZeroEvenOdd(2) # with ThreadPoolExecutor(max_workers=3) as executor: # executor.submit(zeo.odd) # executor.submit(zeo.zero) # executor.submit(zeo.even) threads = [ threading.Thread(target=zeo.odd), threading.Thread(target=zeo.even), threading.Thread(target=zeo.zero), ] for t in threads: t.start() for t in threads: t.join() 

submitted by /u/eggtrie
[link] [comments]

​r/learnpython This is my solution to https://leetcode.com/problems/print-zero-even-odd/ The question is: You are given an instance of the class ZeroEvenOdd that has three functions: zero, even, and odd. The same instance of ZeroEvenOdd will be passed to three different threads: Thread A: calls zero() that should only output 0’s. Thread B: calls even() that should only output even numbers. Thread C: calls odd() that should only output odd numbers. Modify the given class to output the series “010203040506…” where the length of the series must be 2n. import threading class ZeroEvenOdd: def __init__(self, n): self.n = n self._cond_var = threading.Condition() self._shared_idx = 0 # printNumber(x) outputs “x”, where x is an integer. def zero(self, printNumber: ‘Callable[[int], None]’) -> None: while self._shared_idx < self.n: with self._cond_var: # The wait() method releases the lock, and then blocks until another thread # awakens it by calling notify() or notify_all(). self._cond_var.wait_for(lambda: self._shared_idx&1 == 0) printNumber(0) self._shared_idx += 1 self._cond_var.notify_all() def even(self, printNumber: ‘Callable[[int], None]’) -> None: self._print_nonzero_when(printNumber, lambda: self._shared_idx%2 == 1) def odd(self, printNumber: ‘Callable[[int], None]’) -> None: self._print_nonzero_when(printNumber, lambda: self._shared_idx%2 == 0) def _print_nonzero_when(self, printNumber, predicate): while self._shared_idx < self.n: with self._cond_var: self._cond_var.wait_for(predicate) printNumber(int(ceil(self._shared_idx/2))) self._shared_idx += 1 self._cond_var.notify_all() However, if I run this code on my computer locally, it does work. from math import ceil import threading class ZeroEvenOdd: def __init__(self, n): self.n = n self._cond_var = threading.Condition() self._shared_idx = 0 def zero(self) -> None: with self._cond_var: while self._shared_idx < self.n: # The wait() method releases the lock, and then blocks until another thread # awakens it by calling notify() or notify_all(). self._cond_var.wait_for(lambda: self._shared_idx&1 == 0) print(0) self._shared_idx += 1 self._cond_var.notify_all() def even(self) -> None: self._print_nonzero_when(print, lambda: self._shared_idx%4 == 1) def odd(self) -> None: self._print_nonzero_when(print, lambda: self._shared_idx%4 == 3) def _print_nonzero_when(self, print, predicate): with self._cond_var: while self._shared_idx < self.n: self._cond_var.wait_for(predicate) print(int(ceil(self._shared_idx/2))) self._shared_idx += 1 self._cond_var.notify_all() zeo = ZeroEvenOdd(2) # with ThreadPoolExecutor(max_workers=3) as executor: # executor.submit(zeo.odd) # executor.submit(zeo.zero) # executor.submit(zeo.even) threads = [ threading.Thread(target=zeo.odd), threading.Thread(target=zeo.even), threading.Thread(target=zeo.zero), ] for t in threads: t.start() for t in threads: t.join() submitted by /u/eggtrie [link] [comments] 

This is my solution to https://leetcode.com/problems/print-zero-even-odd/

The question is:

You are given an instance of the class ZeroEvenOdd that has three functions: zero, even, and odd. The same instance of ZeroEvenOdd will be passed to three different threads:

Thread A: calls zero() that should only output 0's. Thread B: calls even() that should only output even numbers. Thread C: calls odd() that should only output odd numbers. 

Modify the given class to output the series “010203040506…” where the length of the series must be 2n.

import threading class ZeroEvenOdd: def __init__(self, n): self.n = n self._cond_var = threading.Condition() self._shared_idx = 0 # printNumber(x) outputs "x", where x is an integer. def zero(self, printNumber: 'Callable[[int], None]') -> None: while self._shared_idx < self.n: with self._cond_var: # The wait() method releases the lock, and then blocks until another thread # awakens it by calling notify() or notify_all(). self._cond_var.wait_for(lambda: self._shared_idx&1 == 0) printNumber(0) self._shared_idx += 1 self._cond_var.notify_all() def even(self, printNumber: 'Callable[[int], None]') -> None: self._print_nonzero_when(printNumber, lambda: self._shared_idx%2 == 1) def odd(self, printNumber: 'Callable[[int], None]') -> None: self._print_nonzero_when(printNumber, lambda: self._shared_idx%2 == 0) def _print_nonzero_when(self, printNumber, predicate): while self._shared_idx < self.n: with self._cond_var: self._cond_var.wait_for(predicate) printNumber(int(ceil(self._shared_idx/2))) self._shared_idx += 1 self._cond_var.notify_all() 

However, if I run this code on my computer locally, it does work.

from math import ceil import threading class ZeroEvenOdd: def __init__(self, n): self.n = n self._cond_var = threading.Condition() self._shared_idx = 0 def zero(self) -> None: with self._cond_var: while self._shared_idx < self.n: # The wait() method releases the lock, and then blocks until another thread # awakens it by calling notify() or notify_all(). self._cond_var.wait_for(lambda: self._shared_idx&1 == 0) print(0) self._shared_idx += 1 self._cond_var.notify_all() def even(self) -> None: self._print_nonzero_when(print, lambda: self._shared_idx%4 == 1) def odd(self) -> None: self._print_nonzero_when(print, lambda: self._shared_idx%4 == 3) def _print_nonzero_when(self, print, predicate): with self._cond_var: while self._shared_idx < self.n: self._cond_var.wait_for(predicate) print(int(ceil(self._shared_idx/2))) self._shared_idx += 1 self._cond_var.notify_all() zeo = ZeroEvenOdd(2) # with ThreadPoolExecutor(max_workers=3) as executor: # executor.submit(zeo.odd) # executor.submit(zeo.zero) # executor.submit(zeo.even) threads = [ threading.Thread(target=zeo.odd), threading.Thread(target=zeo.even), threading.Thread(target=zeo.zero), ] for t in threads: t.start() for t in threads: t.join() 

submitted by /u/eggtrie
[link] [comments]  This is my solution to https://leetcode.com/problems/print-zero-even-odd/ The question is: You are given an instance of the class ZeroEvenOdd that has three functions: zero, even, and odd. The same instance of ZeroEvenOdd will be passed to three different threads: Thread A: calls zero() that should only output 0’s. Thread B: calls even() that should only output even numbers. Thread C: calls odd() that should only output odd numbers. Modify the given class to output the series “010203040506…” where the length of the series must be 2n. import threading class ZeroEvenOdd: def __init__(self, n): self.n = n self._cond_var = threading.Condition() self._shared_idx = 0 # printNumber(x) outputs “x”, where x is an integer. def zero(self, printNumber: ‘Callable[[int], None]’) -> None: while self._shared_idx < self.n: with self._cond_var: # The wait() method releases the lock, and then blocks until another thread # awakens it by calling notify() or notify_all(). self._cond_var.wait_for(lambda: self._shared_idx&1 == 0) printNumber(0) self._shared_idx += 1 self._cond_var.notify_all() def even(self, printNumber: ‘Callable[[int], None]’) -> None: self._print_nonzero_when(printNumber, lambda: self._shared_idx%2 == 1) def odd(self, printNumber: ‘Callable[[int], None]’) -> None: self._print_nonzero_when(printNumber, lambda: self._shared_idx%2 == 0) def _print_nonzero_when(self, printNumber, predicate): while self._shared_idx < self.n: with self._cond_var: self._cond_var.wait_for(predicate) printNumber(int(ceil(self._shared_idx/2))) self._shared_idx += 1 self._cond_var.notify_all() However, if I run this code on my computer locally, it does work. from math import ceil import threading class ZeroEvenOdd: def __init__(self, n): self.n = n self._cond_var = threading.Condition() self._shared_idx = 0 def zero(self) -> None: with self._cond_var: while self._shared_idx < self.n: # The wait() method releases the lock, and then blocks until another thread # awakens it by calling notify() or notify_all(). self._cond_var.wait_for(lambda: self._shared_idx&1 == 0) print(0) self._shared_idx += 1 self._cond_var.notify_all() def even(self) -> None: self._print_nonzero_when(print, lambda: self._shared_idx%4 == 1) def odd(self) -> None: self._print_nonzero_when(print, lambda: self._shared_idx%4 == 3) def _print_nonzero_when(self, print, predicate): with self._cond_var: while self._shared_idx < self.n: self._cond_var.wait_for(predicate) print(int(ceil(self._shared_idx/2))) self._shared_idx += 1 self._cond_var.notify_all() zeo = ZeroEvenOdd(2) # with ThreadPoolExecutor(max_workers=3) as executor: # executor.submit(zeo.odd) # executor.submit(zeo.zero) # executor.submit(zeo.even) threads = [ threading.Thread(target=zeo.odd), threading.Thread(target=zeo.even), threading.Thread(target=zeo.zero), ] for t in threads: t.start() for t in threads: t.join() submitted by /u/eggtrie [link] [comments]

Read more

python-vlc doesn’t react to volume while buffering /u/Healthy_Frosting_318 Python Education

python-vlc doesn’t react to volume while buffering /u/Healthy_Frosting_318 Python Education

Hey everyone! I have this following code. I’m building a media player with crossfading functionality. For that I’m using two vlc instances that play one song each. Everything is working so far, except the fade in of the next song. During fadein, the song will play a few samples at full volume, regardless of the audio_set_volume setting. I guess this has something to do with the buffering of the first samples, which will ignore the volume setting.

Here is some example code of how I did it, you can hear the fadein works, but only after playing a few ms on full volume:

Anyone have an idea how to solve this or is it a limitation of the vlc library?

Thanks!

import vlc import time # Simple VLC Player with fade-in class SimpleAudioPlayer: def __init__(self, audio_file): # Initialize VLC instance and media player self.instance = vlc.Instance() self.player = self.instance.media_player_new() self.audio_file = audio_file def play_fadein(self): # Load media media = self.instance.media_new(self.audio_file) self.player.set_media(media) # Set volume to 0 and mute before playback starts self.player.audio_set_volume(0) self.player.audio_set_mute(True) # Start playback print("Starting playback (muted)...") self.player.play() # Simulate fade-in by gradually increasing the volume print("Fade-in...") self.player.audio_set_mute(False) for volume in range(100): # Gradually increase volume self.player.audio_set_volume(volume) time.sleep(0.01) # Wait 10 ms between steps print("Playback running at full volume.") time.sleep(10) self.stop() def stop(self): # Stop playback self.player.stop() print("Playback stopped.") # Test the player if __name__ == "__main__": audio_file = "song.wav" player = SimpleAudioPlayer(audio_file) player.play_fadein() 

submitted by /u/Healthy_Frosting_318
[link] [comments]

​r/learnpython Hey everyone! I have this following code. I’m building a media player with crossfading functionality. For that I’m using two vlc instances that play one song each. Everything is working so far, except the fade in of the next song. During fadein, the song will play a few samples at full volume, regardless of the audio_set_volume setting. I guess this has something to do with the buffering of the first samples, which will ignore the volume setting. Here is some example code of how I did it, you can hear the fadein works, but only after playing a few ms on full volume: Anyone have an idea how to solve this or is it a limitation of the vlc library? Thanks! import vlc import time # Simple VLC Player with fade-in class SimpleAudioPlayer: def __init__(self, audio_file): # Initialize VLC instance and media player self.instance = vlc.Instance() self.player = self.instance.media_player_new() self.audio_file = audio_file def play_fadein(self): # Load media media = self.instance.media_new(self.audio_file) self.player.set_media(media) # Set volume to 0 and mute before playback starts self.player.audio_set_volume(0) self.player.audio_set_mute(True) # Start playback print(“Starting playback (muted)…”) self.player.play() # Simulate fade-in by gradually increasing the volume print(“Fade-in…”) self.player.audio_set_mute(False) for volume in range(100): # Gradually increase volume self.player.audio_set_volume(volume) time.sleep(0.01) # Wait 10 ms between steps print(“Playback running at full volume.”) time.sleep(10) self.stop() def stop(self): # Stop playback self.player.stop() print(“Playback stopped.”) # Test the player if __name__ == “__main__”: audio_file = “song.wav” player = SimpleAudioPlayer(audio_file) player.play_fadein() submitted by /u/Healthy_Frosting_318 [link] [comments] 

Hey everyone! I have this following code. I’m building a media player with crossfading functionality. For that I’m using two vlc instances that play one song each. Everything is working so far, except the fade in of the next song. During fadein, the song will play a few samples at full volume, regardless of the audio_set_volume setting. I guess this has something to do with the buffering of the first samples, which will ignore the volume setting.

Here is some example code of how I did it, you can hear the fadein works, but only after playing a few ms on full volume:

Anyone have an idea how to solve this or is it a limitation of the vlc library?

Thanks!

import vlc import time # Simple VLC Player with fade-in class SimpleAudioPlayer: def __init__(self, audio_file): # Initialize VLC instance and media player self.instance = vlc.Instance() self.player = self.instance.media_player_new() self.audio_file = audio_file def play_fadein(self): # Load media media = self.instance.media_new(self.audio_file) self.player.set_media(media) # Set volume to 0 and mute before playback starts self.player.audio_set_volume(0) self.player.audio_set_mute(True) # Start playback print("Starting playback (muted)...") self.player.play() # Simulate fade-in by gradually increasing the volume print("Fade-in...") self.player.audio_set_mute(False) for volume in range(100): # Gradually increase volume self.player.audio_set_volume(volume) time.sleep(0.01) # Wait 10 ms between steps print("Playback running at full volume.") time.sleep(10) self.stop() def stop(self): # Stop playback self.player.stop() print("Playback stopped.") # Test the player if __name__ == "__main__": audio_file = "song.wav" player = SimpleAudioPlayer(audio_file) player.play_fadein() 

submitted by /u/Healthy_Frosting_318
[link] [comments]  Hey everyone! I have this following code. I’m building a media player with crossfading functionality. For that I’m using two vlc instances that play one song each. Everything is working so far, except the fade in of the next song. During fadein, the song will play a few samples at full volume, regardless of the audio_set_volume setting. I guess this has something to do with the buffering of the first samples, which will ignore the volume setting. Here is some example code of how I did it, you can hear the fadein works, but only after playing a few ms on full volume: Anyone have an idea how to solve this or is it a limitation of the vlc library? Thanks! import vlc import time # Simple VLC Player with fade-in class SimpleAudioPlayer: def __init__(self, audio_file): # Initialize VLC instance and media player self.instance = vlc.Instance() self.player = self.instance.media_player_new() self.audio_file = audio_file def play_fadein(self): # Load media media = self.instance.media_new(self.audio_file) self.player.set_media(media) # Set volume to 0 and mute before playback starts self.player.audio_set_volume(0) self.player.audio_set_mute(True) # Start playback print(“Starting playback (muted)…”) self.player.play() # Simulate fade-in by gradually increasing the volume print(“Fade-in…”) self.player.audio_set_mute(False) for volume in range(100): # Gradually increase volume self.player.audio_set_volume(volume) time.sleep(0.01) # Wait 10 ms between steps print(“Playback running at full volume.”) time.sleep(10) self.stop() def stop(self): # Stop playback self.player.stop() print(“Playback stopped.”) # Test the player if __name__ == “__main__”: audio_file = “song.wav” player = SimpleAudioPlayer(audio_file) player.play_fadein() submitted by /u/Healthy_Frosting_318 [link] [comments]

Read more

input() function in Visual Studio Code? /u/West_Culture1257 Python Education

input() function in Visual Studio Code? /u/West_Culture1257 Python Education

So, I am brand new to coding, I’m talking day one. I’ve looked up answers to my questions in many google searches and tutorials but it feels like in order to understand the answer I need to have already known 10 other things related to it. Was wondering if someone here could explain it a bit more plainly haha. I’m having a hard time understanding the input() function, and how to use it in Visual Studio Code. I installed Code Runner and toggled on ‘Run code in Terminal’, and followed a tutorial to the letter and am still getting this error message in the terminal as shown in the code block after the “>>>”.

I don’t understand why it’s saying ‘name’ isn’t defined when to me that’s what it looked like I did because of the = sign. Could someone please help me figure out what’s going wrong before I pull my hair out? Explain it assuming I know literally nothing else about Python or VSC except for how to create a new file and use the print() function. Thanks a million.

name = input("Enter your name: ") print("Your name is: ", name) >>> print("Your name is: ", name) Traceback (most recent call last): File "<python-input-15>", line 1, in <module> print("Your name is: ", name) ^^^^ NameError: name 'name' is not defined >>> 

submitted by /u/West_Culture1257
[link] [comments]

​r/learnpython So, I am brand new to coding, I’m talking day one. I’ve looked up answers to my questions in many google searches and tutorials but it feels like in order to understand the answer I need to have already known 10 other things related to it. Was wondering if someone here could explain it a bit more plainly haha. I’m having a hard time understanding the input() function, and how to use it in Visual Studio Code. I installed Code Runner and toggled on ‘Run code in Terminal’, and followed a tutorial to the letter and am still getting this error message in the terminal as shown in the code block after the “>>>”. I don’t understand why it’s saying ‘name’ isn’t defined when to me that’s what it looked like I did because of the = sign. Could someone please help me figure out what’s going wrong before I pull my hair out? Explain it assuming I know literally nothing else about Python or VSC except for how to create a new file and use the print() function. Thanks a million. name = input(“Enter your name: “) print(“Your name is: “, name) >>> print(“Your name is: “, name) Traceback (most recent call last): File “<python-input-15>”, line 1, in <module> print(“Your name is: “, name) ^^^^ NameError: name ‘name’ is not defined >>> submitted by /u/West_Culture1257 [link] [comments] 

So, I am brand new to coding, I’m talking day one. I’ve looked up answers to my questions in many google searches and tutorials but it feels like in order to understand the answer I need to have already known 10 other things related to it. Was wondering if someone here could explain it a bit more plainly haha. I’m having a hard time understanding the input() function, and how to use it in Visual Studio Code. I installed Code Runner and toggled on ‘Run code in Terminal’, and followed a tutorial to the letter and am still getting this error message in the terminal as shown in the code block after the “>>>”.

I don’t understand why it’s saying ‘name’ isn’t defined when to me that’s what it looked like I did because of the = sign. Could someone please help me figure out what’s going wrong before I pull my hair out? Explain it assuming I know literally nothing else about Python or VSC except for how to create a new file and use the print() function. Thanks a million.

name = input("Enter your name: ") print("Your name is: ", name) >>> print("Your name is: ", name) Traceback (most recent call last): File "<python-input-15>", line 1, in <module> print("Your name is: ", name) ^^^^ NameError: name 'name' is not defined >>> 

submitted by /u/West_Culture1257
[link] [comments]  So, I am brand new to coding, I’m talking day one. I’ve looked up answers to my questions in many google searches and tutorials but it feels like in order to understand the answer I need to have already known 10 other things related to it. Was wondering if someone here could explain it a bit more plainly haha. I’m having a hard time understanding the input() function, and how to use it in Visual Studio Code. I installed Code Runner and toggled on ‘Run code in Terminal’, and followed a tutorial to the letter and am still getting this error message in the terminal as shown in the code block after the “>>>”. I don’t understand why it’s saying ‘name’ isn’t defined when to me that’s what it looked like I did because of the = sign. Could someone please help me figure out what’s going wrong before I pull my hair out? Explain it assuming I know literally nothing else about Python or VSC except for how to create a new file and use the print() function. Thanks a million. name = input(“Enter your name: “) print(“Your name is: “, name) >>> print(“Your name is: “, name) Traceback (most recent call last): File “<python-input-15>”, line 1, in <module> print(“Your name is: “, name) ^^^^ NameError: name ‘name’ is not defined >>> submitted by /u/West_Culture1257 [link] [comments]

Read more

Ask Anything Monday – Weekly Thread /u/AutoModerator Python Education

Ask Anything Monday – Weekly Thread /u/AutoModerator Python Education

Welcome to another /r/learnPython weekly “Ask Anything* Monday” thread

Here you can ask all the questions that you wanted to ask but didn’t feel like making a new thread.

* It’s primarily intended for simple questions but as long as it’s about python it’s allowed.

If you have any suggestions or questions about this thread use the message the moderators button in the sidebar.

Rules:

  • Don’t downvote stuff – instead explain what’s wrong with the comment, if it’s against the rules “report” it and it will be dealt with.
  • Don’t post stuff that doesn’t have absolutely anything to do with python.
  • Don’t make fun of someone for not knowing something, insult anyone etc – this will result in an immediate ban.

That’s it.

submitted by /u/AutoModerator
[link] [comments]

​r/learnpython Welcome to another /r/learnPython weekly “Ask Anything* Monday” thread Here you can ask all the questions that you wanted to ask but didn’t feel like making a new thread. * It’s primarily intended for simple questions but as long as it’s about python it’s allowed. If you have any suggestions or questions about this thread use the message the moderators button in the sidebar. Rules: Don’t downvote stuff – instead explain what’s wrong with the comment, if it’s against the rules “report” it and it will be dealt with. Don’t post stuff that doesn’t have absolutely anything to do with python. Don’t make fun of someone for not knowing something, insult anyone etc – this will result in an immediate ban. That’s it. submitted by /u/AutoModerator [link] [comments] 

Welcome to another /r/learnPython weekly “Ask Anything* Monday” thread

Here you can ask all the questions that you wanted to ask but didn’t feel like making a new thread.

* It’s primarily intended for simple questions but as long as it’s about python it’s allowed.

If you have any suggestions or questions about this thread use the message the moderators button in the sidebar.

Rules:

  • Don’t downvote stuff – instead explain what’s wrong with the comment, if it’s against the rules “report” it and it will be dealt with.
  • Don’t post stuff that doesn’t have absolutely anything to do with python.
  • Don’t make fun of someone for not knowing something, insult anyone etc – this will result in an immediate ban.

That’s it.

submitted by /u/AutoModerator
[link] [comments]  Welcome to another /r/learnPython weekly “Ask Anything* Monday” thread Here you can ask all the questions that you wanted to ask but didn’t feel like making a new thread. * It’s primarily intended for simple questions but as long as it’s about python it’s allowed. If you have any suggestions or questions about this thread use the message the moderators button in the sidebar. Rules: Don’t downvote stuff – instead explain what’s wrong with the comment, if it’s against the rules “report” it and it will be dealt with. Don’t post stuff that doesn’t have absolutely anything to do with python. Don’t make fun of someone for not knowing something, insult anyone etc – this will result in an immediate ban. That’s it. submitted by /u/AutoModerator [link] [comments]

Read more