Python: Is it possible to setup a folder trigger? [duplicate] - python

This question already has answers here:
How do I watch a file for changes?
(28 answers)
Closed 8 years ago.
I would like to monitor the directory using python. Whenever there is a new file the program will notify the user.
Current I am using a loop, which run os.listdir, to poll the directory regularly. However this is very inefficient. Is there any way that I could setup some software trigger (in Python) to enhance the efficiency?
Thanks in advance

See http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html for Windows and http://sourceforge.net/projects/python-fam/ for Linux. Also, you can check out https://github.com/gorakhargosh/watchdog/, which is multi-platform.

Related

What is the fastest way to execute commands in python? [duplicate]

This question already has answers here:
Speed difference betwen subprocess.call() and os.system()
(1 answer)
fastest way to invoke a process from python?
(1 answer)
Closed 11 months ago.
I'm writing a Python script and I need to call some commands, for example creating directories, deleting files, execute docker commands, git commands, make command etc.
What is the fastest way to invoke such commands?
Should I use os.system or subprocess?
The Python script will run on Windows and Linux.

Pycharm detection [duplicate]

This question already has an answer here:
How to check if python unit test started in PyCharm or not?
(1 answer)
Closed 6 years ago.
I want to know whether python script is started from PyCharm. Next string
in_pycharm = 'original_argv' in dir(sys) and 'pydevd' in sys.original_argv[0]
works ok for Debug and don't work for Run.
Can anyone recommend me better way?
Simplest solution is probably to have pycharm specify an environment variable, something like INPYCHARM=1, then check os.environ.get('INPYCHARM')==1. You can specify the environment variable in the Run/Debug configuration menu (from the Run drop-down menu).
Edit: Looks like PYCHARM_HOSTED is specified in os.environ by default, so the following should work (tested on pycharm 5.0.4).
in_pycharm = 'PYCHARM_HOSTED' in os.environ

Opening other Python 3 files using tkinter [duplicate]

This question already has answers here:
How do you run your own code alongside Tkinter's event loop?
(5 answers)
Closed 6 years ago.
I am currently working on making a program using tkinter that when pressing a button it opens the Python program, however I am having some problems with it. I have tried using os.system('filename.py'). That opens the file, but then crashes the GUI, making the user have to restart the GUI. I have also tried importing it as a module but that just does the same as when using os.system.
Can anyone possibly help me open a Python file in a completely new window/terminal?
The problem is filename.py will not be recognised by your os.
Instead of that use:
os.system('python filename.py')
This will successfully open your python file inside your GUI
Hope this helps

Is it possible to make python into an executable file? [duplicate]

This question already has answers here:
Create a single executable from a Python project [closed]
(3 answers)
Closed 9 years ago.
Is there a way to make python an executable file on a mac, windows, or unix?
Nothing fancy in a GUI, but open a terminal window or a console window and run like somebody executed the application through terminal.
If there's no easy way to do this, can someone direct me to any reading material? Thank you!
You can use PyInstaller (http://www.pyinstaller.org/), there is also py2exe (http://www.py2exe.org/).
My experiences with PyInstaller on Linux show that it tends to place a lot of shared libs which may sometimes clash with your distribution so it's sometimes necessary to trim it down a bit afterwards.

How can i make a application with single .exe file using python? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
py2exe - generate single executable file
I made a application.exe from application.py using "pyinstaller".There are so many .dll file generated during this process. How can i make a application with single .exe file
Have you tried the --onefile option to PyInstaller? See the documentation on the subject.

Categories

Resources