2

I am building a flask application to control GPIO on my raspberry pi. I am using the larger application Flask structure because even though my app isn't huge I very much enjoy having everything in separate files.

One thing I am not sure about is how to go about importing RPi.GPIO so that circular/redundant imports don't occur. In this tutorial GPIO is imported into what would be the views.py in my file structure. But the author also uses GPIO inside the if __name__ == "__main__" block for initialization code.

Where would the if __name__ == "__main__" initilization code go for my file structure? I was thinking putting it in run.py right before app.run(debug=True) but I am not sure if this is where it is typically placed.

Secondly, If I import GPIO into the place where my initialization code goes will I run into circular/redundant import problems if I also import it in views?

user8363
  • 55
  • 1
  • 9

1 Answers1

0

If you look on github, you can see the convention is usually to do something like put main.py, or app.py to build app, then in another file such as run.py, uwsgi.py, server.py where app is imported in and ran.

user5275692
  • 603
  • 1
  • 6
  • 11