Python Forum
Cannot get simple i/o to function. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Cannot get simple i/o to function. (/thread-19120.html)

Pages: 1 2


Cannot get simple i/o to function. - jerryi - Jun-13-2019

My first post. I am new to Python and am using Sublime Text Editor with Python 3. Sample code below was pasted from a tutorial file, io.py
It runs, and it asks me to type something. I type a string into the response box and hit enter. Nothing happens.
I have been running numerous learning files w/o problem. Just cannot get i/o to work properly. It seems I need to do something special to get i/o running. Haven't created any projects yet. just small files. I wrote a program to print out all the prime numbers from 2 to a million, for example, without difficulty.

All help would be appreciated.


txt = input("Type something to test this out: ")

# Note that in version 3, the print() function
# requires the use of parenthesis.
print("Is this what you just said? ", txt)



RE: Cannot get simple i/o to function. - joe_momma - Jun-13-2019

you need to format the string and you can do it multiply ways:
print("Is this what you just said? %s" %(txt)) # first
print("Is this what you just said? {0}".format(txt)) #second
print(f"Is this what you just said? txt") # 3.7 and higher



RE: Cannot get simple i/o to function. - jerryi - Jun-13-2019

Thx joe_momma for suggestions, but none of the four bottom lines work.

My original program functions on Android Pydroid 3,
but I cannot get Sublime Text versions on W10 to work with either of my two PCs (desktop or laptop).

txt = input("Type something to test this out: ")
# print("a) Is this what you just said? txt") # does not work on pc with Sublime Text; works on Pydroid 3 for Android
# print("b) Is this what you just said? %s" %(txt)) # first suggestion by joe_momma (fails with Sublime Text)
# print("c) Is this what you just said? {0}".format(txt)) # second
printf(f"d) Is this what you just said? txt") # third 3.7 and higher suggested by joe_momma



RE: Cannot get simple i/o to function. - noisefloor - Jun-14-2019

@jerryi: Your code in the original post as well as joe_momma's code is syntatically correct Python, so it should work. If it doesn't work on your system with, it's a specific problem of your system.

How do you run the code? In case you run it on Win by double-clicking the .py file, you may never see the output, as the window is closed right after the print function finished - which is faster you than you can read. Open the cmd line instead and type python3 io.py, than the cmd window remains open and you can read the output.

Regards, noisefloor


RE: Cannot get simple i/o to function. - buran - Jun-14-2019

as @noisefloor said - all 4 snippets should work. It's not clear what you mean by "I type a string into the response box and hit enter." what "response box"? Follow @noisefloor advice to run the script from cmd


RE: Cannot get simple i/o to function. - ThomasL - Jun-14-2019

In this thread "Is this a bug?"
i found this answer
Quote:When you execute code in Sublime (either via a build system or interactively in the console), there is no way to capture input. More technically, the console is connected to stdout and stderr but not stdin. So it’s not possible to run an interactive program from within Sublime directly.



RE: Cannot get simple i/o to function. - jerryi - Jun-16-2019

I appreciate the help I have received and am progressing gradually. I hsve a goal to teach a few inner-city students some elementary coding this summer, and have selected Python3 as a teaching platform. I am a retired mechanical engineer, but I am completely new to the language, I already appreciate its value and appeal. Because most of these students are refugees from places like Burma Thailand, Nepal, etc., they do not have access to laptop computers for our class. So I decided to put Python 3.7.3 on a few older laptops that I obtained for almost-free, and to use Sublime as our editor and work platform. That seems to be working fine for my desktop PC at home and for my Lenovo Ideapad. Both installations were fairly easy to accomplish.

However, I am not progressing as well in setting up an old Dell Latitude D630 with W10. I cannot seem to get program output through Sublime: Only an indication of elapsed time. I am in the dark re. what to do to configure Sublime properly for functionality. I can run a snippet through the command prompt, so Python 3 is doing its job, but Sublime will not even spit out a response to print("Hello"). When I hit ctrl-b, it just responds [Finished in 0.6 s], with no Hello greeting.

 print("Hello") 



RE: Cannot get simple i/o to function. - DeaD_EyE - Jun-16-2019

If you're acting legal and respect the licensing, it's expensive to buy copies of Windows.
I don't use sublime, but if you google for CTRL + B,, sublime would only
compile the code, not run it. It's a bit uncommon for Python, because this step is implicitly done by Python itself.
CTRL + Shift + B should run the code, but you should also know how to run
a Python program in a terminal. Since Python 3.5 the program py.exe is delivered. This is just a runner, which
finds the right interpreter on your system. So, if you're teaching Python on Windows, you should know this.


RE: Cannot get simple i/o to function. - jerryi - Jun-16-2019

Thank you, DeaD-EyE. I fumbled around and discovered that if I click Tools > Build System > Python
and then click Tools > Build > Ctrl-B and then click Build > Results > Show Results and then hit escape to get rid of the old results in the bottom part of my screen, then ctrl-b becomes functional. I have no idea what this is all about or why it seems so convoluted to get everything to function, and I am not sure which of my steps were necessary and which ones were not. And I could not find a 'coherent-to-me' explanation, but I will now consider the issue resolved. Maybe someday I will find enough explanations to understand what is going on. Meanwhile, I will truck on, and warn the kids not to mess with the Tools options when things aren't broken.


RE: Cannot get simple i/o to function. - ThomasL - Jun-16-2019

Maybe just watch a tutorial how to set up Sublime Text