Should I write "delete" at the end of a program? I know that all existing object at the end of a program are destroyed anyway, so is it a good or bad habit to delete them?
Related
I am creating a code for a project that contains a management system. SO in that I am using while True to repeat the program until the user wants to exit.
But I also have have to add if and elifs as it is a menu driven program. and use of break breaks the whole while loop.
I'll share the code as a link
https://codeshare.io/j0lkoK
if anyone could help it would be great
i tried using continue but it went to a infinite loop and same without break. I want to just break the if so that the user could go onto the next feature if they want to or completely exit it.
Thanks in advance
Say I want to ask the user a question in a CLI interface, then they type in an answer and press return.
I want to show a tick or a cross next to their answer.
How can I do this using readline?
Thoughts:
Listen for process.stdin.on 'keypress', -> and use ascii control codes to move the cursor back to end of previous line. Not sure this will work unless there is a way to cancel the keypress event.
Cancel the key press somehow <- not sure this is possible.
Maybe I have to create my own readline module by listening to keypress?
Thanks!
I'm invoking a macro within an Excel document via Powershell.
To invoke the macro, I have to run a named macro and call it in run. However, when the macro is invoked and completes successfully, a MessageBox will appear. As far as I know, this messagebox is the only way to find out if the process has completed successfully.
I have no control over the ability to remove the message box. The powershell script must wait for the macro to finish.
From the document: The documentation for this does not give an option for this situation, or so it appears.
Alternative Options I can work with: (But I'm not sure how to get to the point where the messagebox would be dismissed)
The Excel document can have code inserted within it via Powershell
Options can be changed within the document memory space
Is it possible to run a macro asynchronously and to check back on the execution of the macro?
There are a few convoluted ways to go about doing this.
1) Invoke another instance of the Excel application and run the Macro using that. Then how would you know whether it's done? You pass a global variable by reference to it. And use the OnTime functionality to keep checking every few seconds if its done or not.
An example for calling another excel instance is given here: Stop VBA-Script from "freezing" while sending MDX-Query
2) You can store your script as a .VBS file. Then you call the shell to run the VB script and again check some passed-by-reference variable.
3) Use a hidden worksheet as a buffer, which gets written upon in a particular location once the asynchronous code finishes running. Again, you need some clever OnTime programming to automatically run a polling service... and more importantly, to stop running it!
For example, I got text document. Like so:
At around 6am last Bank Holiday **Monday** I was called by our **Australian** news desk who informed me of the news. Stumbling from my bed to the lounge, still half asleep and with the remnants of an enjoyable **Sunday evening** taking revenge on my skull, I was struggling to process the notion of putting one foot in front of the other let alone news that the world's most **notorious terrorist** had been killed.
It is just for example.
Our work is to replace bold words with our own that we take from the paper docs. The operation is very routine, you scroll text, find the word, delete it, type in your new word etc.
I thought maybe there is a way to automate it? Maybe with macros or some other mechanism?
Microsoft word version is 2000. For example I see it like window where it asks: Enter this: - ok - next window - enter this - and in the end it enters all data into new file.
Yes, there is a way. It is called Mail Merge.
yes, you can totally use Word Macros to automate using find and replace.. 1) Record a macro. 2) do find and replace 3) stop recording macro 4) look at vb, at a couple of loops if you need, etc. 5) assign macro to function key (it's easy in Excel at least, never had to do with Word)
If you have a crontab job that runs every 5 minutes, how do you ensure that it won't ever overrun itself? That is, how do you make sure that the previous iteration of the crontab job completed before the next one runs?
at the beginning of your script, create a unique temp file somewhere in the file system, unless the file already exists, in which case your script is already running and you should exit. at the end of your script, delete the unique temp file.
there are other variations of this i'm sure, but they all have a similar idea. if you like this answer, please select the check mark next to it. thanks!
Use flock. It basically does what dqhendricks suggests.