When to use while true [closed] - python

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 7 months ago.
Improve this question
What are some acceptable use cases for using while true. I’ve heard that it’s not good practice to use while true and break. For simple use cases like let’s say a rps game, would it be worth using. If not, I’m considering to use boiler plate code.

You can use while(True) in such conditions when you need to make the code running until interrupted by the person running the code.
A use case can be fee submitting system. The program needs to be running for the entire day. There are a lot of other use cases too.

Related

Running a function with the different functionalities at different times in Python [closed]

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 1 year ago.
Improve this question
I'm looking for a way to create a function that takes two args, time and operation and it does the operation at the given time as an argument. The script should be running on a server and it reads the data from a Redis-like database. I'm trying to find a way to do that avoid using any other frameworks or non-standard packages. Have any idea about that?
See the library https://github.com/dbader/schedule and this example https://github.com/dbader/schedule/blob/master/docs/examples.rst#run-a-job-once

Is it possible to automatically re-indexing of the Plone catalog regulary? [closed]

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 want to re-index the Plone catalog automaticaly and on regular basis.
What are the advantage and disadvatage of doing so?
There are several ways to do that, for example by creating a small python script and run through instance (bin/instance1 run <your py script file>) and run it through cronjob.
My intention here to share with you, my real-life experience if your system's Database is large it could take reindexing more than days! so that would be unrealistic to plan frequent re-indexing, beside frequent re-reindexing, would not give you performance optimization (could benefit for broken indexes), instead, you could do pack your database frequently, that will give you performance
https://docs.plone.org/manage/deploying/packing.html

How to verify it's the same computer [closed]

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 3 years ago.
Improve this question
I was wondering if there's any Python code I can run that, assuming the Python code has not been tampered with, will return an ID specific to that computer that cannot be spoofed. My initial thought was to use MAC addresses, but I know those can be easily spoofed. How about CPU serial number? How would I go about doing that?
Thanks.
This is an impossible problem, as it's equivalent to effective DRM. Every identifier can be spoofed. Remember, the user can tamper with your Python code (any compiling/obfuscating/encrypting you do can be reversed, so don't bother) to return whatever identifier they want. (And even if your code were absolutely read-only, they could change the Python runtime or the OS to do whatever they want.)

How to execute a small part of C Code in Python? [closed]

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 6 years ago.
Improve this question
I have written a code in Python. There is a part in the code that does integration which has a very high computation time. But the same integration takes very less time in C. I want to run that part in C (that will take some input) and use the output to run the other code in python. In other words, I have a very large code in python, of which I want to run a small part in C. Please tell me how to do that.
You are looking for the ctypes library.

EventHandler, event, delegate based programming in Python any example would appreciate? [closed]

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 1 year ago.
Improve this question
Basically I'm a C# developer,
I know the way C# does, EventHandler, delegate, even...
but whats the best way to implement it on Python.
I think you should be able to use a function:
def do_work_and_notify(on_done):
// do work
on_done()
def send_email_on_completion():
email_send('joe#example.com', 'you are done')
do_work_and_notify(send_email_on_completion)
Functions (and even methods) in python are first-class objects that can be tossed around like anything else in the language.
This question is a lot like Python Observer Pattern: Examples, Tips? which has lots of great answers. There's even an implementation of C#-like events in Python.

Categories

Resources