2

I want to loop my python code for Raspberry pi

 2 years ago
source link: https://www.codesd.com/item/i-want-to-loop-my-python-code-for-raspberry-pi.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

I want to loop my python code for Raspberry pi

advertisements

here is my code and I don't know how loop it.Thanks to help me out!!

#!/usr/bin/python
import os
os.system('clear')

#Clear Fenetre et import

print "Test programme";

#Splash

Bacvar = raw_input("Code pour Bac:")

Prodvar = raw_input("Code pour Produit:")
code = str(Bacvar)+str(Prodvar)

#Entree de variables

print code
with open("test.txt", "wt") as out_file:
 out_file.write(code + "\n")

#Export vers txt

So basically the program is connected to a raspberry pi and a barcode scanner. The user will scan a box. I want that data to be exported as "code" to a txt file and after the file has been exported, To loop to the beginning of the code. I tried a while True: but it didn't seem to work work.

So when a code is exported to my txt file by scanning an item. The second code which is generated should be exported to the same txt but at the second line and so on.

Thank you!


The trick is to use exception and the event KeyboardInterrupt for example.

try:
    while True:
        #your code
except KeyboardInterrupt:
    break

When you will hit a keyboard key, you will exit your infinite loop. Now does it work on Raspberry Pi with an I/O input... It should but keep us aware ^^


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK