TW79
Posts: 36
Joined: Wed Jul 02, 2014 4:09 pm

Button to create new file

Tue Jul 08, 2014 1:27 pm

All,

I'm new to Python, but have some programming experience.

I am building an RFID reader that will be controlled by push buttons. One of the buttons is to prompt the user for the name of a location, which will be typed in via a wireless keyboard. This input should be saved as the first line in a new, blank file.

I'm able to confirm the button is connected properly, but I don't know where to look for this type of scripting. A Google search doesn't return anything usable.

Where can I look, or what examples can someone provide to get me started in the right direction?

User avatar
topguy
Posts: 6523
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Button to create new file

Tue Jul 08, 2014 1:35 pm

So the button is connected to the GPIO ?
And when you say that you have verified that the button is connected that means ?

So is it reading the button status from Python that is your problem ?

TW79
Posts: 36
Joined: Wed Jul 02, 2014 4:09 pm

Re: Button to create new file

Tue Jul 08, 2014 1:40 pm

The button is connected to GPIO 22 (Pin 15). I found a sample script that waits for a button press then displays some basic text. Running this script works properly, which tells me the button is connected correctly.

I don't know how to script my end result. I need the system to create a new file on button press, and take the keyboard input to create first line in the newly-created file.

User avatar
topguy
Posts: 6523
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Button to create new file

Tue Jul 08, 2014 1:44 pm

Probably not the worst starting point....
http://www.tutorialspoint.com/python/py ... les_io.htm

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: Button to create new file

Tue Jul 08, 2014 7:40 pm

TW79 wrote:I need the system to create a new file on button press, and take the keyboard input to create first line in the newly-created file.
You've got it the wrong way round ;)
You need to get the user input (e.g. using https://docs.python.org/2/library/funct ... #raw_input ) and store it in a variable, and then create a new file with the user-input as the file contents.

Edit: And this should probably be in the Python forum.

Return to “Advanced users”