I am making a program in Python which I'll send to other people in our company. The aim of the program is to show which programs are downloaded and not from a list. The problem is that the program is not installed in the same place on every device.
How can I check if a program is downloaded or not?
only found this:
import os
os.path.exists(c:\.......)
Related
I wrote a Python script that generates a QR Code containing the user's contact information, and now I can't find a solid way to deliver it to the users. This is made for a group of people with no programming knowledge, so I need to make it very simple. I used tkinter to make a window in which the user can input their data, and then the QR code is generated in their Downloads folder.
My first thought was to make a .exe file using auto-py-to-exe, which worked on my machine, but didn't work on someone else's for some strange reason (they simply couldn't open it, not even a dialogue box appeared giving a reason why).
I'm running out of ideas here, open to any and all suggestions.
You could do a simple streamlit app.
If your code can be public, you can push it to github and deploy it from there. It's free and should be straight forward.
I wrote a python script to run some simple tasks and this issue has been happening randomly at times.
Upon clicking on .py file, a cmd prompt window appears for a some microseconds and closes immediately without showing any text.
I thought this issue was because the code finished running too fast at first but the code doesnt actually run. I know this because the code involves sending a text message on discord through the requests module and I can see post-running that no text has been sent.
If it was the prior assumed issue, I would've just added some input for the program to recieve but my program has an infinite while loop in it which should be already enough to keep the cmd window open. Hence I dont understand what's causing this.
The last time it happened I somehow found a solution which I followed step by step and was able to resolve it but its happening again now and I cant find that solution again unfortunately. From vague memory, I recall the solution involved running some commands on windows terminal.
Are you double clicking the .py file? If so, it may not work in some situations. What you should do is open up your cmd and type the following.
C:\Users\Admin> python filename.py
You can replace filename with your file's name.
If you are using Mac or any Apple devices, you will need to replace python with python3.
I started learning Python this week, and I am trying to automate adding a new user to both active directory, and on Office 365.
I have managed to add the user to AD using a client and a bot, and also use another script to generate the correct New-MsolUser syntax for Powershell.
How do I get Python to open Powershell and run the output of "o365command"?
Also will I need to connect to the tenant every time I do this so will I need to incorporate this into the script as well?
Happy to show the code I have if needed.
If you provide the output from Python as JSON to a file, then PowerShell can import that directly. See ConvertFrom-Json (ConvertFrom-Json).
As for running PowerShell from Python, look at: Running an outside program (executable) in Python?
It's not something I've ever tried but good luck.
I'm trying to create the nim game in unity with some nice 3d graphics. For those who don't know, nim is a solved game which means that, assuming both players play perfectly, we can know who will win at the first turn.
I want to make 4 game modes:
Two players who play against each other.
The player plays against the computer who plays perfectly.
The computer plays against a bot the user wrote in python.
The player plays against a bot he wrote in python.
I learnt about this game in computer science class in high school, and we were given an exercise to write a program that will win a simpler version of this game.
That's why I want to include the last two modes: To let students write their bots in python and test it in my game. I think it can turn out very cool.
However, that means I need to figure out how to run a python script from c# script in unity. I know I can use Process in c# to run the external python script, but that requires me to know the location of the python executable.
I could make a settings menu, so the user can set the path to python there, but I don't like the fact that the user will have to deal with path settings.
I learnt that, on windows, I can download an embeddable zip which contains the python interpreter (python.exe) and simply ship this with the game so the user doesn't even need to have python installed on their machine. However, I couldn't find any similar zip for other platforms, specifically linux and mac.
So, my question is how should I run python scripts in unity? Is there a way to embed the python interpreter for both windows, mac and linux, or should I make a settings menu for configuring the python path and use processes?
If somebody can give me an idea for how to use python in unity, I'd really appreciate this.
Note: I want to use python 3 for the scripting, so solutions that work for python 2 only can't help me at all.
Thanks in advance.
You can use System.Diagnostics.Process.Start and start cmd with it
string strCmdText;
strCmdText= "python script.py";
System.Diagnostics.Process.Start("CMD.exe",strCmdText);```
Only python 2.7.5, python 3 is not functional
Python and Unity
but if you just want to use a python as Bot, i suggest you to communicate via TCP (socket) or others ways...
I have a Raspberry Pi running Linux. My plan is that I can plug in a USB in the robot and have and it will run the python files. the reason I chose this method is that it allows for easy editing and debugging of the scripts.
Is there a way to execute my files when the USB is inserted?
Try to use os.path.exists to detect whether the pendrive is there in an infinite loop and when detected execute code on pendrive using os.system and break out of loop .
Check this link out: https://ubuntuforums.org/showthread.php?t=1648939
Looks like you should consider writing a script that navigates to the directory of the file and runs "python yourscript.py". The details on getting the script to autorun are there.