What are run time inputs in python3? - python

I have been recently been trying out this app called compiler(on android) and whenever I try run code it is asking for something called a runtime input? I am new to coding so I really don't know what it means. Another issue is that when I try to run inputs e.g input("hi: ") I am unable, to type anything in the terminal, wondering if there is any fix? In advance thanks to anyone who responds.For some reasons the staic terminal does not apply to other ides such as pycharm or pydroidenter image description here

This is a common issue in the most of the online ide. You have to provide your input in that alert box and hit run.
The reason it happens is because your code is not running on your device instead running on a remote server which only allocates limited time(3-5 seconds) for your code to execute, so to make full use of that time, you are asked to give all the input beforehand so that program doesn't have to wait for user input and waste that precious time.
Also, you can't expect prompt messages to work here as they are working in an offline ide.

Related

Translating unix written python for windows to use in RoboDK

I have a script written in python that is used as a driver for a robot in RoboDK. The problem I was having initially was the driver was not recognising the COM port and therefore was not connecting. I’ve solved this by changing the if statement to
if connected is True:
The issue I’m having is, there’s a line of code that reads
data = sys.stdin.readLine()
which I’ve been informed won’t work on windows.
In RDK the program runs and sits at “waiting” but does not progress even when the simulation is run to control the movement of the real robot.
Please keep in mind, although I’ve some experience coding, I’ve never worked directly with a robot or anything of the likes like this, this is for a university project and it seems to be the biggest roadblock so far so any help would be very much appreciated as all web searches so far have been fruitless. Thank you for reading and thank you for any input you may be able to provide.

How to simulate the run button with a command line in Pycharm

I'm working on a script using the PyAutoGUI module. Sometimes the script gets stuck in a while loop because it's looking for pictures/images that are not shown due to connection problems etc. If this happens I want the program to start again from zero, so I want to simulate the play/run-button in Pycharm with a command line. Is this possible?
What it sounds like you want to do is restart your program if it doesnt respond. A similiar question appears to have been posted here: Python help - Need the ability to restart the script when it hangs or automatically set a timer so I would reccommend having a look at that. Simulating the run button in Pycharm might seem like a good idea at first but it is very specific and a bad practice to simulate user actions like that unless there is absolutely no viable alternative.
Thanks to Patel I managed to solve my issue. You can use ctrl+f5 to restart a script so now when I'm stuck in a while loop I'm using this code:
#Click toolbar Pycharm
pyautogui.moveTo(1672,15,1)
pyautogui.click()
#Rerun the script
pyautogui.hotkey("ctrl","f5")

"sh: Error: Can't open display" when I try to start a program from python

I have this really strange problem, basically I want to start xpdf (or Libreoffice) from my Python script, that is started by a systemd-service. When I start the script from terminal everything is working fine, but when I plug in my USB device that start the Service, I'll get this Error in my syslog:
sh[2321]: Error: Can't open Display
This error has something to do with X11, that's what my Google searches tell me.
So, my question is: How can I properly run a program like xpdf or libreoffice from Python?
import subprocess
subprocess.call("/usr/bin/xpdf")
This is it, basically. I know that it has something to do with the graphical enviroment, but I don't know how I can solve it.
The X display system has very good security to stop random local processes from just displaying stuff to the local screen (It was more a problem in the old days of expensive Sun and SGI systems where computer labs would often let users telnet to other boxes. Much fun could be had!).
If the user running the xpdf is the same user as the one who's logged into the X session, then you simply need to tell xpdf where to connect it's UI to. This is usually done by exporting DISPLAY=:0 to the environment, which means "connect to the first local screen". Most X programs also support -display :0 argument.
So do:
/usr/bin/xpdf -display :0
or:
DISPLAY=:0 /usr/bin/xpdf
It's very unlikely that you have more than one X session so :0 will work 99% of the time.
Since the issue is that xpdf isn't finding a display to connect to, we have two basic options: find and authenticate with an existing display, or make a new one. The latter is usually easier, something like:
xinit /usr/bin/xpdf -fullscreen $PDFFILE -- :2
This would start a new X display :2 running only xpdf, not even a window manager.
It finally worked, after trying and going crazy for around 2 weeks.
What worked was
os.system("DISPLAY=:0 /usr/bin/xpdf)
I know that subprocess.call is the better way to call the program, but it doesn't seem to work right now.
I'll try the way that Yann suggested later on, but for now I'm just overwhelmed with joy that it just works.
Thank you all for your help, I really appreciate it!

PyCharm: After each word is typed, there is a delay where one is unable to type

In PyCharm (JetBrains), I have been having trouble with typing full statements without getting an interuption. I first thought it was due to me not having updated the software, so I updated it, but the problem remains.
So if I type any statement or word, PyCharm seems to delay before I can proceed. An example:
import csv
Even before I finish typing "import" - if I delay a keystroke - PyCharm begins to "think" and the window is not accessible for about one to two seconds (quite literally). I assume it is going to give me suggestions or show a tip/error about the code.
Any thoughts to prevent this from happening?
Edit:
Windows 8.1; PyCharm 2016.2
Code Complete turned off via Settings->Editor->General->Code Completion, but did not solve problem.
Key PC Spec:
Intel Core i5-337U
4GB Ram
64-bit
Edit2:
I receive this error when I run anything now, including simply print("test"):
Process finished with exit code -1073741511 (0xC0000139)
Will separate the question somewhere else, since this may be a separate problem altogether.
Try disabling code completion. I believe that your computer can't search through all of Python's librarys fast enough so it freezes for a bit.

How do I spawn a process and ignore all user prompts?

I'm trying to automate mounting and unmounting of UNC drives with Python on Windows. I'm using the subprocess module to the execute the various commands so I can log their output. However, the NET USE command occasionally prompts the user for input (like a password). Usually things work well, but since I am using subprocess.communicate(), my program hangs indefinitely when NET USE asks my "subprocess" for input. Of course, I have no idea it's asking for input. It just sits there waiting patiently and making me frustrated.
This is a more general problem than just NET USE, so please don't go that route. There are other instances where some (other) program asks for input and my program freezes. Any thoughts?
Some programs are smart and realize that if there is no way for a user to input anything, then they shouldn't even ask. For such programs, you can add "stdin=open('/dev/null')" to the subprocess.Popen options.
In the more difficult case, where the program really insists on interacting, all you can do is provide the interaction yourself.
EDIT: I should mention that the pexpect library is a great way to do such interaction.

Categories