I am new to PyCharm and I have 'Process finished with exit code 0' instead of getting (683, 11) as a result (please see attachment), could you guys help me out please? Much appreciate it!
That is good news! It means that there is no error with your code. You have run it right through and there is nothing wrong with it. Pycharm returns 0 when it has found no errors (plus any output you give it) and returns 1 as well as an error message when it encounters errors.
Editors and scripts do not behave like the interactive terminal, when you run a function it does not automatically show the the result. You need to actually tell it to do it yourself.
Generally you just print the results.
If you use print(data.shape) it should return what you expect with the success message Process finished with exit code 0.
exit code 0 means you code run with no error.
Let's give a error code for example(clearly in the below image): in below code, the variable lst is an empty list,
but we get the 5 member in it(which not exists), so the program throws IndexError, and exit 1 which means there is error with the code.
You can also define exit code for analysis, for example:
ERROR_USERNAME, ERROR_PASSWORD, RIGHT_CODE = 683, 11, 0
right_name, right_password = 'xy', 'xy'
name, password = 'xy', 'wrong_password'
if name != right_name:
exit(ERROR_USERNAME)
if password != right_password:
exit(ERROR_PASSWORD)
exit(RIGHT_CODE)
I would recommend you to read up onexit codes.
exit 0 means no error.
exit 1 means there is some error in your code.
This is not pyCharm or python specific. This is a very common practice in most of the programming languages. Where exit 0 means the successful execution of the program and a non zero exit code indicates an error.
Almost all the program(C++/python/java..) return 0 if it runs successful.That isn't specific to pycharm or python.
In program there is no need to invoke exit function explicitly when it runs success it invoke exit(0) by default, invoke exit(not_zero_num) when runs failed.
You can also invoke exit function with different code(num) for analysis.
You can also see https://en.wikipedia.org/wiki/Exit_(system_call) for more details.
What worked for me when this happened was to go to
Run --> Edit Configurations --> Execution --> check the box Run with
Python Console (which was unchecked).
This means that the compilation was successful (no errors). PyCharm and command prompt (Windows OS), terminal (Ubuntu) don't work the same way. PyCharm is an editor and if you want to print something, you explicitly have to write the print statement:
print(whatever_you_want_to_print)
In your case,
print(data.shape)
I think there's no problem in your code and you could find your print results (and other outputs) in the tab 5: Debug rather than 4: Run.
I just ran into this, but couldn't even run a simple print('hello world') function.
Turns out Comodo's Firewall was stopping the script from printing. This is a pretty easy fix by deleting Python out of the Settings > Advanced > Script Analysis portion of Comodo.
Good Luck
I had same problem with yours. And I finally solve it
I see you are trying to run code "Kaggle - BreastCancer.py"
but your pycharm try to run "Breast.py" instead of your code.
(I think Breast.py only contains functions so pycharm can run without showing any result)
Check on tab [Run] which code you are trying to run.
Your starting the program's run from a different file than you have open there. In Run (alt+shift+F10), set the python file you would like to run or debug.
Related
I tried running the below code but VS Code is showing syntax error. I checked on internet and notes but found the loop is fine.
i = 1
while i <= 5:
print(i)
i = i + 1
While loop showing syntax error
I don't think there is anything wrong with your code but you should try to create a new folder preferably outside of Appdata. or One drive folder
There isn't anything wrong with your actual code. When I run it it executes as you would expect. I think the problem must be the way you are executing the program. I think you are attempting to run it in the python interpreter. Where it says "2:Python" you want it to be like "cmd" or "Code" or something and then you can just type in python loop.py maybe try clicking the plus next to it or select the first option in the dropdown.
Windows environment, python 2.7, latest nosetest.
Looking at nosetest docs, and googling around, nowhere do I see that nosetest sets the cmd line errorlevel on test failure.
We need this so that our build system can detect test failure.
Questions are:
Does Nosetest set the cmd line, errorlevel? (if so, where are docs)
If not, what is the appropriate way to handle this? (must my build parse some log output, or?)
%errorlevel% on windows is the return code of the application, typically the argument given to the exit(int) call (exit code). These return codes are the same as unittest, but the documentation is not very explicit:
The testRunner argument can either be a test runner class or an already created instance of it. By default main calls sys.exit() with an exit code indicating success or failure of the tests run.
In the above sentence By default is to understand as if the call argument exit is not set to False:
main supports being used from the interactive interpreter by passing in the argument exit=False. This displays the result on standard output without calling sys.exit()
(New in 2.7 and 3.1. In older version, sys.exit is always called.)
I found no special documentation about the return code, but looking at the source, one can find that exit code is 0 for success, 1 for error (same for unittest alone) and 2 if the usage help has to be printed (given arguments when calling as standalone program are incorrect). Specific for nose, when program is asked to display version or list plugins, exit code is 0 too.
When I pass my mpirun command through terminal, the normal (and expected) outcome is an output file with a bunch of data in it.
However when I pass the code through my python script, all of the output files that are expected are created, however they contain no data. Is there any global explanation for this? I have tried the code many different ways, using both os.system and subprocess. I have also tried running the code in the background as well as just running. And I have also tried just having the program spit out the data vs. saving it to the output file, and all give the same result.
Here is the code:
os.system("mpirun -np 4 /home/mike/bin/Linux-ifort_XE_openmpi-1.6_emt64/v2_0_1/Pcrystal > mgo.out")
The simplest way to get that behavior is if mpirun is not being successfully run.
For instance if, from the command line, I run
not_actually_a_command > myFile.txt
myFile.txt will be created, but will be empty (the "command not found" message is printed to stderr so won't be caught by ">").
Try using the fully resolved path to mpirun
There doesn't seem to be something inherently wrong with your approach. When I do
os.system("echo hello, world >hello.txt")
it ends up with "hello, world" in it, so if you get your command to run it should work for you.
You should start with providing a complete path
os.system("/complete/path/to/mpirun
and print the result, print(os.system...etc.),
and post the error so we know what is wrong.
When using the subprocess module it may require a "shell=True"
Where can I find information about meaning of exit codes of "python" process on Unix? For instance, if I do "python thisfiledoesntexist.py", I get exit code 2
Summary:
from errno import errorcode
print errorcode[2]
As stated, mostly the error codes come from the executed script and sys.exit().
The example with a non-existing file as an argument to the interpreter fall in a different category. Though it's stated nowhere I would guess, that these exit codes are the "standard" Linux error codes. There is a module called errno that provides these error numbers (the exit codes come from linux/include/errno.h.
I.e.: errno.ENOENT (stands for for "No such file or directory") has the number 2 which coincides with your example.
The Python manual states this regarding its exit codes:
Some systems have a convention for assigning specific meanings to specific exit codes, but these are generally underdeveloped; Unix programs generally use 2 for command line syntax errors and 1 for all other kind of errors.
So, since you specified thisfiledoesntexist.py as a command line argument, you get a return code of 2 (assuming the file does not, in fact, exist. In that case I'd recommend renaming it to thisfiledoesexist.py. ;) )
Other that such parsing errors, the return code is determined by the Python program run. 0 is returned unless you specify another exit code with sys.exit. Python itself does not interfere.
Maybe exit code constants from os module can help you. Also have a look at sys.exit documentation.
Unfortunately, there is no 100% guarantee that Python's exit codes will be what the documentation claims they will be: os._exit allows the Python programmer to define which exit code is supposed to be used, which means python file_exists_but_claims_that_it_does_not.py could exit with os.EX_DATAERR.
EDIT-4
I've gotten my sitecustomize.py to execute, but it tosses up an error. Here's the code for it.
The error is:
Error in sitecustomize; set PYTHONVERBOSE for traceback:
RuntimeError: maximum recursion depth exceeded while calling a Python object
I'm not terribly advanced with Python yet, so I figured I'd comment out only the lines I did not think Iwould need. No encoding issues are showing up, so I just commented out lines 23-104, but that didn't help either.
EDIT-3
I also happened to have 2.5.1 installed, so I compiled another script with that.
print 'This will test carriage returns on Windows with PyDev on Eclipse Helios'
print'Type something:',
test = raw_input()
print('You entered the following ascii values:')
for c in test:
print(str(ord(c)))
This ran fine, and resulted in
This will test carriage returns on Windows with PyDev on Eclipse Helios
Type something: g
You entered the following ascii values:
103
So this is possibly a Python3 thing only? I know it's not the interpreter, because I'm able to run it in command prompt just fine. What gives?
EDIT-2
Just tested with Helios, still having the same problem. Here's my test program:
print('This will test carriage returns on Windows with PyDev on Eclipse Helios.')
print('Type something:', end='')
test = input()
print('You entered the following ascii values:')
for c in test:
print(str(ord(c)))
And here's the output when I type 'g' and press Enter:
This will test carriage returns on Windows with PyDev on Eclipse Helios.
Type something:g
You entered the following ascii values:
103
13
In the grand scheme of things, it's a small issue. I could use input().rstrip() and it works. But the workaround shouldn't even be necessary. I'm typing twice as much as I should need to in a language that I'm using because it's concise and pretty.
EDIT-1
This is Eclipse 3.5. Unfortunately that's the latest version that's been approved for use at work. I'm going to try 3.6 at home to see if that's any different, but I wouldn't be able to use it anyway.
(original question)
I've been learning some basic Python, and decided to go with PyDev since it supported Python 3 as well as having all the nice code snippet and auto complete features.
However, I'm running into that darned carriage return issue on Windows.
My searches always lead me back to this mailing list:
http://www.mail-archive.com/python-list#python.org/msg269758.html
So I have grabbed the sitecustomize.py file, tried to include it in the Python path for my configured interpreter, as well as my project, but to no avail.
Has anybody else managed to work through this? Or maybe knows how to get the new sitecustomize.py to actually execute so it can override input() and raw_input()?
I know I could always make a short module with my own replacement input() function, but I'd really like to fix the problem at its root. Aptana acknowledges the issue ( http://pydev.org/faq.html#why_raw_input_input_does_not_work_correctly ) but offers no solution. Thanks in advance for your help.
Figured out a hack to make it work locally to my Python installation. In \Lib\site-packages\ make a script called "sitecustomize.py", and put this code in it:
original_input = builtins.input
def input(prompt=''):
return original_input(prompt).rstrip('\r')
input.__doc__ = original_input.__doc__
builtins.input = input
I don't know anything about the side effects of this, or what sort of error checking I should be doing, but it works if you're using PyDev on Windows to write scripts with Python3.
Found out some more things about sitecustomize.py and how it relates to site.py.
I don't know how to add my own sitecustomize.py to PYTHONPATH for execution only in a PyDev project, so I just stuck it in ${Python31dir}\Libs\site-packages. The module runs now, but generates errors.