I have a difficult problem. I want to setup windows scheduler to run a python script every day. To make my program simple, I want to:
start with input 10 today, add 5, return 15
start with yesterday's return, add 5, return the value (start with 15, add 5, return 20)
......
etc
Does anyone know if this is possible?
you could write the return to a text file then the next day the program reads the text file and starts with the number it reads from the text file then re-writes the new value to the text file
this way you can save data while the program isnt running and retreive it later
Hope that help :)
Create a .py file with your code in it. You can keep track of the numbers in a text file or XML document and read/parse as necessary on a daily basis, then overwrite, pass it as an argument (data.txt or xml). Create it initially with the starting value.
I'd format it as XML, since Python has a bunch of nice XML Parsers.
<xml>
<data>10</data>
</xml>
Drop the following into a batch or cmd file (.bat, .cmd)
c:\<path_to_python>\python.exe c:\<full_path>\yourfile.py c:\<full_path>\data.xml
Schedule the batch to run in Windows Scheduler using proper credentials.
Related
Working on a data transfer program, to move data from an oracle database to another
application that I cant see or change. I have to create several text files described below and drop them off on sftp site.
I am converting from a 20+ year old SQR report. (yes SQR) :(
I have to create text files that have a format as such an_alpa_code:2343,34533,4442,333335,.....can be thousands or numbers separated by comma.
The file may have only 1 line, but the file might be 48k in size.
There is no choice on the file format, it is required this way.
Tried using Oracle UTL_FILE, but that cannot deal with a line over 32k in length, so looking for an alterative. Python is a language my company has approved for use, so I am hoping it could do this
I too once [was forced] to use SQR many years ago, and so you have my sympathy.
python can definitely do this. If you set the end argument of the print command to an empty string, then you can ensure that no new line is output:
print("Hello world",end='')
perl could also be a good candidate language.
print("Hello world");
Both python and perl have Oracle client libraries.
This gave me one long line
file_obj = open("writing.txt", "w")
for i in range(0,10000):
file_obj.write("mystuff"+str(i)+",")
# file_obj.write('\n')
file_obj.close()
When I try to write something, such as variables, the code is renamed to the file name on the computer.
For example, if I write:
a = 20
f = 15
print(a+f)
then the code file will automatically be renamed to the first line, i.e. "a = 20"
Then, when I try to run the code, the program outputs nothing but "Python" and some incomprehensible words.
What could it be related to?
enter image description here
enter image description here
I installed the latest version of Visual Stuio Code with Python, they are new, so there should be no problems. But this time it went wrong.
After reinstalling the program, the problem remains.
First of all, if there is no special requirement, please do not use Code Runner to run the script, using the official extension Python is a better choice.
In addition, the dot on your file label means that you have not saved the file, you can add the following setting to enable automatic saving in the settings.
"files.autoSave": "afterDelay",
You may have created the file using the following method. File --> New File... --> Python File. At this time, the file has not been named, also not saved. You can see that there is no such file in the resource manager list at this time.
So the file label shows the first line of codes. This is a feature of vscode, you can refer to this link. And because the file has not been saved, there will be problems executing the script.
You can rename the script file directly (F2), or vscode will remind you to name the file when saving. Another way to create a file is to right click and choose New File..., enter filename and end with .py extension.
I am wondering would it be possible to save few line of code (as it is) from a script (in python) to a textile while running the script in Pycharm which I run every time with new arguments, and I would like to save these arguments with other results automatically, so that I can know which arguments leads to which results, I don't have to add them manually and it's automatically saved in text file to my path.
Example!
For example I want to save the following line of python code from the script to a text file so that I can know I have multiplied the loss2 with 0.75:
"return loss + 0.75*loss2"
OR
"self.lstm = tf.keras.layers.Bidirectional(LSTM(80, return sequences=False,return_state=False),merge mode='ave')"
I want to save these kind of scripts (while running) it as a text file specifically in Pycharm.
I'm using VBA on Excel to run a Python script. Here's what my module looks like:
Sub PythonButton()
RetVal = Shell("C:\Python27\python.exe C:\Users\myName\Desktop\test.py", 1)
End Sub
My command window opens up and appears to give some feedback but the window only remains for a split second. How do I get this window to stay open until, say, the user presses a key?
I ended up using a batch file with a "pause" in it instead:
Sub PythonButton()
RetVal = Shell("C:\Users\myName\Desktop\start.bat", 1)
End Sub
I let my batch file run the python script instead.
This is my first time using this so be kind :) basically my question is I am making a program that opens many Microsoft Word 2007 docs and reads from a certain table in that document and writes that info to an excel file there is well in excess of 1000 word docs. I have all of this working but the only problem when I run my code it does not close MSword after opening each doc I have to manually do this at the end of the program run by opening word and selecting exit word option from the Home menu. Another problem is also if a run this program consecutively on the second run everything goes to hell it prints the same thing repeatedly no matter which doc is selected I think this may have to do with how MSword is deciding which doc is active e.g. is it still opening the last active document that was not closed from the last run. Anyways here is my code for the opening and closing part I wont bore you guys with the rest::
MSWord = win32com.client.Dispatch("Word.Application")
MSWord.Visible = 0
# Open a specific file
#myWordDoc = tkFileDialog.askopenfilename()
MSWord.Documents.Open("C:\\Documents and Settings\\fdosier" + chosen_doc)
#Get the textual content
docText = MSWord.Documents[0].Content
charText = MSWord.Documents[0].Characters
# Get a list of tables
ListTables = MSWord.Documents[0].Tables
------Main Code---------
MSWord.Documents.Close
MSWord.Documents.Quit
del MSWord
Basically, Python is not VBA, so this:
MSWord.Documents.Close
is equivalent to:
getattr(MSWord.Documents, "Close")
i.e. you just get some method object and do nothing with it. You need to call the method with the call operator (the parentheses :) :
MSWord.Documents.Close()
Accordingly for .Quit.
Before your MSWord.Quit did you try using:
MSWord.ActiveWindow.Close
Or even more simpley just doing
MSWord.Quit
I dont really understand if you are trying to close a document or the application.
I think you need a MSWord.Quit at the end (before and/or instead of the the del)