Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I would like to add some interactive capability to a python CLI application I've writen that stores data in a SQLite3 database. Currently, my app reads-in a certain type of file, parses and analyzes, puts the analysis data into the db, and spits the formatted records to stdout (which I generally pipe to a file). There are on the order of a million records in this file. Ideally, I would like to eliminate that text file situation altogether and just loop after that "parse and analyze" part, displaying a screen's worth of records, and allowing the user to page through them and enter some commands that will edit the records. The backend part I know how to do.
Can anyone suggest a good starting point for creating that pager frontend either directly in the console (like the pager "less"), through ncurses, or some other system?
You might want to take a look at urwid. It is a console user interface library for Python. The examples should be more than enough to convince you that this is what you want, if you really want to go text-console UI.
I'd use something like pygtk instead though.
After looking around a bit, I found that less and other pagers actually use curses. When I thought of curses I always imagined the blue-boxed interface with menus and mouse interaction. These are library add-ons for curses, which offer exactly the basic terminal selection and editing control functionality I'm looking for.
Tutorial on Python Curses Programming
Curses Programming with Python
On the backend, when the user attempts to move the cursor above or below the currently displayed records, I'll have sqlite fetch me the next appropriate set of records for display.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I currently have a script that automates sending Whatsapp messages. It takes an excel file full of contacts, receives a message argument and then sends the message to each contact. It's purpose is to help automate sending the same message about different services being offered to a bunch of groups.
I am making the program for a family member who is computer illiterate and am hoping to make some simple UI for them so they never have to interact with the code.
I have already been playing around in tkinter, and have figured out how to open a dialog to select the Excel file that needs to be used. I am confused about how the rest of the program would functionally work and if this is feasible for someone who has never used Tkinter before and is on a short deadline.
I was thinking it would look something like a button, to open up the dialog to choose the Excel file. A text box, to fill in the message. And, another button to open up a dialog to choose a photo to be sent along the message. Then once all that was done the program would run.
Is this functionally possible, and is Tkinter the best option to pursue? Also is this feasible first project for a novice Tkinter user?
Python is best for backend
Hey, so I think Python isn't the best language for UI at all.
In my opinion it is quite difficult to make a real good looking program with tkinter, but as I said before, Python is more for backend programming. But tkinter is not a bad choice for a simple program - if not the best. Also, the advantage of a tkinter program is that you can write your code and the GUI code in one file, which makes the program a bit more compact
But if you want a simple GUI program tkinter is you first choice
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I made a small script that solves an combinatorial optimization problem and I would like put it in a website so users can "play" with it, they could send a list of "points" to the server and this script would use a database to return the best combination of these "points".
The problem is I do not have much experience in web dev. I searched how to make an html button execute an script and I found this thread: https://stackoverflow.com/questions/48552343/how-can-i-execute-a-python-script-from-an-html-button#:~:text=To%20run%2C%20open%20command%20prompt,Hope%20this%20helpful.
But there says that an html button calling an python script is not safe. So what would be ideal What would be an ideal, safe alternative so that I could make sure that anyone who accesses my website can execute this script safely?
Well, there's no "easy" answer to your question. What you'd really need to do is to create a web-site in Python on your host computer – using a tool such as Django – and have one of the URLs supported by that website call your script.
Honestly, "what you're asking for here, really isn't the sort of question that StackOverflow is intended to answer." It's too big. Another one of the SE-family sites might be more appropriate, although I'm not quite sure which one ...
The solution that comes to mind would be setting up some Python-API (e.g. with Flask) which you could call with HTTP via JS, having different routes for different usages.
Here's a short overview of Flask showcasing how it could be used.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
So basically, what I want to do is have a user input some data in an HTML form or something (on client end). Have that data be carried over to a server, where the data is put through some python code and the processed result is sent back to the client. I know, I could use javascript to do this on the user side itself, but I want to experiment a bit and make use of some libraries like tensorflow, matplotlib and so on.
Also, is there some way, you know like Web Assembly to run python code on the client side. Like maybe, send data from server or have it fed by the user, and on some virtual environment type setup and processed ??
Note: I know flask exists and I've tried it, but I can't see the same flexibility as you know regular python code.
Thanks in advance 😊
There won't come a definite answer to your question because your question is too broad. But maybe this will give you some starting points.
I see you have two questions:
How can I use python server side
How can I use python client side
Question 1:
First of all you might know that it makes sense to perform operations on a server and not on a client. For example interacting with a central database.
Flask is already lightweight compared to Django which also uses python. If you really want to do a lot on your own you could take a look at websocket or common gateway interface (cgi).
Question 2: This is really not recommended but if you want to play around with WebAssembly and Python a good starting point is PyPyJs: https://github.com/pypyjs/pypyjs!
You can use Brython in the browser, it's pretty spiffy. Full dom-manipulation from python; fully compatible with libraries written in pure python. Really neat stuff.
As for the server-side, if you want to keep it full-python, you'll need to use something like flask, bottle, cherrypy, aiohttp,...
If you find yourself struggling; maybe try starting out writing a simple socket-based microservice? You'll then be able to either farm requests out to it from any other server; or incorporate the code in your (python) server code.
Good luck!
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have apache+mysql+django. in mysql I store some data, and use django to interact with it.
Now I need to store data from mysql into some external text file(like csv) in a propper format(I want to parse it later with jenkins as a source to parameters). How can I create some kind of event which will upload data from DB table into text file using Django(as far as I already have Django installed, and I know python itself can do this easy)?
And I want reapetable event. Like every 1 minute data will be synced. Smthng like this.
Tnaks!
I would suggest writing a custom management command that takes the information you want and writes it to your CSV. As you said, the process of writing data to a text file is easy enough in Python - using a management command would let you use the ORM directly, greatly simplifying your interaction with the database.
The second benefit of using a management command is that it's easy to run as a cronjob. Once you've written your custom command (let's call it csvsync), you can write something like this in your crontab:
* * * * * python /your/path/to/manage.py csvsync
Here's the relevant documentation for custom management commands: https://docs.djangoproject.com/en/1.7/howto/custom-management-commands/
The developers note the following in the linked docs:
Standalone scripts
Custom management commands are especially useful for running
standalone scripts or for scripts that are periodically executed from
the UNIX crontab or from Windows scheduled tasks control panel.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to develop a code that causes a currently open application (running in the background) to perform basic tasks when a certain condition is met.
Let me explain through a random example…
Imagine I am working on a Microsoft word document and I want it to print exactly every 10 minutes automatically, i.e. without having to physically click the print button. What options do I have to implement something like this? Obviously gaining access to the MS word source code is an option, but is their an easier way…perhaps using a python script?
Thanks,
David
Microsoft Office products, as well as Internet Explorer and some other programs expose a Component Object Model (COM) interface. You can find more detail about COM and how it applies to Python here (including examples). They often expose every action you could do manually in the applications, but are aimed at automation and artificial input.
For a more generic application, you could work with sending messages. There's a Windows function called 'postmessage', and another called 'sendmessage' which have several wrappers in Python.
By the way, the MS Word source code is not freely available.