Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm writing a script in Python, but when I attempt to run it a cross cursor appears and lets me take screenshots. But that's not part of my program, and the rest of the script never executes at all!
The minimal code that produces this behavior is:
import fiona
import scipy
It's a known issue which regularly happens to some.
Without a python shebang line the script is treated as a shell script. And line import module is treated as a command to run import application, which is present on your system (part of ImageMagick, I guess) and makes a screenshot saving it to the specified file.
It got solved by adding the shebang:
#!/usr/bin/env python
but I really don't understand why...
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have a python file with no argparse implementation in its __main__, yet, I'm interested in having a look at the functions and modules implemented in it from the commandline. I'm tempted to write a function to perform such exploration but I wanted to find out first whether this is already available.
EDIT 1: to make it more concrete, I'm interested in names of functions and classes + their docs.
You may be looking for a tool like python-fire.
From the repository:
Python Fire is a library for automatically generating command line interfaces (CLIs) from absolutely any Python object. [...] Python Fire helps with exploring existing code or turning other people's code into a CLI.
It is available as a package on pip.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I heard that it is not possible to give input to the python program In VS Code and for this issue We should open the python file on Command Prompt.
I wonder is it really true? Because Sometimes I write code on VS Code it asks for Input but sometimes It doesn't show anything. So what is going on?
The official python extension of VSCode provides Run and Debugging, almost like a IDE. It's impossible not to support input.
As for the source of your misunderstanding, it may be an extension like Code Runner, which does not support input, just quickly help you run the code and display the output.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Before you get confused, I am going to compile it with the auto-py-to-exe module after, its just the source code is in python. How do I do this?
If Python is not installed you wouldn't even be able to run a script to check if it's installed.
I'm pretty sure there isn't from inside the Python script. Because the interpreter isn't installed, so it'll never be able to understand HOW to execute the script at all.
You'll have to check outside in whatever is initiating the Python script and the compilation (bash script?) and do it there.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
It seems to me python -m myscript and python myscript do the same thing: running a script.
What is the purpose of using -m? Thanks.
In some cases, especially for very small projects, python script.py and python -m script will be pretty much the same.
The biggest difference is when your module lives in a package and has relative imports. If you have a script that import something like from .module import some_name, you will most likely get a ModuleNotFoundError when you run it with python package/scripy.py. On the other hand, python -m package.script will produce whatever output you expected.
You can load modules and invoke them as script. The exact file name or path is not needed. Example:
python -mjson.tool myfile.json
This will print a formatted version of myfile.json, and it loads the module json.tool for this. Python searches for this module automatically. You don't need to know the exact path.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I make web applications using Ruby on Rails as my backend. I use React and Flux on the frontend, which is JavaScript. I can fully use the debugging tools I need. I simply add the line of code "debugger" anywhere in my app, so that execution stops there. I use byebug gem in Rails. When the "debugger" line of code is executed on backend code, the debugging happens on the command line; when it happens in JavaScript code, the debugging happens in Chrome Dev Tools. In other words, I can work very quickly to debug.
What is the equivalent convenient debugging tool in Python? In other words, what should a person who can already program in general, and just wants to rapidly be able to debug in Python use? I am using Atom editor (like I use when I am making a web app).
You can use pdb
To add a breakpoint, insert:
import pdb; pdb.set_trace()
where you want to stop.
NB:
Since python 3.7, you just can do
breakpoint()
In the debugger mode you can use the following commands.