This question already has answers here:
How to read a Kubernetes Deployment with python kubernetes client
(2 answers)
Closed last year.
I'm writing a python program that prints some kind of data of an existing kubernetes cluster as a first step.
I need to print the annotations of a given deployment. I tried a read the documentation and unfortunately got some lost. Anyone can show me an example?
Here is the example python script,
https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/AppsV1Api.md#read_namespaced_deployment
Once you get the api_response, you may have to do,
print(api_response.metadata.annotations)
Related
This question already has answers here:
How do I execute a string containing Python code in Python?
(14 answers)
Closed 5 months ago.
This post was edited and submitted for review 5 months ago and failed to reopen the post:
Original close reason(s) were not resolved
How do I execute a string containing Python, without creating a new file, using excec() or using "os" module?
I've seen the similiar question, but the answeres always kind of created some "new file"(for example created something like this), or went out of the current code, but i want it to stay inside the code and execute it.
Example:
string_base64 = "eCA9ICJoZWxsbyBmZWxsb3ciCgoKcHJpbnQoeCkKeCA9ICJoZWxsbyBmZWxsb3ciCgoKcHJpbnQoeCkKeCA9ICJoZWxsbyBmZWxsb3ciCgoKcHJpbnQoeCkKeCA9ICJoZWxsbyBmZWxsb3ciCgoKcHJpbnQoeCk="
This b64 code has inside it strings and commands (+ For example imports) and it needs to run in the current file, without using exec() or modules
This Thread and the answers, didn't answer the question!
Buildin exec function seems to be doing exactly what you want:
https://docs.python.org/3/library/functions.html#exec
This question already has answers here:
How to write to a file, using the logging Python module?
(12 answers)
Closed 7 months ago.
Currently I am using the print function to write log messages:
print("...creating new data...")
(I am using the docker image tiangolo/uvicorn-gunicorn-fastapi:python3.7 to run my service).
But in the standard log I can see only the last few messages. I want to archive my log messages over days and month.
How is it possible to write a message in Python in a separate log file?
You can use logging. Here an example
This question already has answers here:
How to execute script on schedule?
(3 answers)
Closed 1 year ago.
I have my python scripts which execute every weekday and refreshes tableau datasets. This is all being done incremental refresh on a daily basis.
Now, during weekends instead of manual refresh, I want these scripts to run with a full refresh. Any ideas on how we can achieve this?
Example:
I have tasks in my script like
#Run Tasks
refresh_tableA()
refresh_tableB()
refresh_tableC()
refresh_tablemain(i)
refresh_tableD()
Where the refresh_maintable() is an incremental refresh. Want that to trigger to a full refresh on weekends.
You need to have two cron entries.
week days only - call the python code and order it to create partial refresh
wekends - call the python code and order it to create full refresh
I think what you are looking for is a scheduler.
You have 2 options here either use Task Scheduler/Cronjob (Based on your OS) or using python library for this.
I think there is library for cronjob in python pycron.
That way you can schedule you scripts easily. let me know if you still dont understand the flow or want code. Most probably you'll find something on github.
This question already has answers here:
How do I run a Python script from C#?
(8 answers)
Run a python script from unity, to use its output (text file) in my game later
(4 answers)
Closed 1 year ago.
I want to make a Unity game that gives data to a subprogram written in Python and this subprogram gives back an answer, that is then processed in the C# game.
I don't really know how to approach this.
Can I run python code from C# somehow or do I let two separate programs running, that exchange data somehow?
Both programs also need access to the same database.
You can make a python server using flask or fastAPI and then access it from C#. I am not sure how to get that done with C#(I dont know C# :( ), but there must be some libraries to call servers. Also, you could save the database on the cloud such as mongoDB.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Python: single instance of program
What is the best way to insure that only 1 copy of a python script is running? I am having trouble with python zombies. I tired creating a write lock using open("lock","w"), but python doesn't notify me if the file already has a write lock, it just seems to wait.
Try:
import os
os.open("lock", os.O_CREAT|os.O_EXCL)
The documentation for os.open and its flags.
Your question is similar to this one: What is the best way to open a file for exclusive access in Python?. The answers given there should help you with your issue.
(Use the flag combination portalocker.LOCK_EX!|portalocker.LOCK_NB to return quickly. If the file is locked by another process, your script should get an exception.)