Code work in PyCharm but doesn't work when lauching through python console - python-3.x

I have been working on a project and in the end it's suppose to print an output in a notepad file and it works perfectly in pycharm but as soon as I launch my file with python it crash every time I execute the code
I am 100% sure that the problem lies between the line I copied and pasted and I know that if start the project in pycharm with the python console setting active it work too so it may be some right problem? that's the conclusion I came with althought I'm not sure and I don't have any idea how to fix it even with my research. Ho and I,ve checked too and my python is up-to-date
number_of_product = [0,0,0,0]
Total = 0
with open("Bill.txt", "w+") as Bill:
Bill.write("{0} ChocoMilk\n".format(number_of_product[0]))
Bill.write("{0} Katkit\n".format(number_of_product[1]))
Bill.write("{0} N&N's\n".format(number_of_product[2]))
Bill.write("{0} SourJoes\n".format(number_of_product[3]))
Bill.write("Total : {0}$".format(Total))
The result should be 5 line of text written in a notepad file.

I found the problem: I was opening the Pycharm file by clicking "Open with" python3.7 and Windows wasn't giving me all the right I needed.
You need to change the basic application that runs the program from Pycharm to Python itself.

Related

.exe doesn't work after converting from .py with auto-py-to-exe

everyone!
I'm new in programing.
I faced the problem that my .exe doesn't work after I converted it from .py file.
File is prety simple. It's load data from excel to scv using pandas and time just for the logs.
I haven't caught any errors during the convrting proccess, but when I open .exe, it shows only terminal with flickering cursor.
I also add "--exclude-module" for other instaled modules which wasn't used in my program. It helped decrise size of the end .exe file, but still it doesn't work.
If you have any ideas, please share with me.
I found the solution in this answer https://stackoverflow.com/a/71626038/17618130 Basicly it offers to use raw Pyinstaller without auto-py-to-exe But i'v found that it is still working only on windows server, but don't work on Windows 10. So I still need help(

Linux Ubuntu how to start standard application scribus from python eclipse anaconda

I edited my question, hope it is described better now.
I am working on a software that gives me a nice PDF with lots of matplotlib graphics, depending on the data I get.
So think of a database of pages and then the software decides which pages are chosen and filled with changed images, The text stays the same.
So for instance for data1 I get page1-4 and page7 and page 9. For data2 I get page1-4 and page6. Saved as PDF. I am doing this manually with Quark which needs to be changed. I hope I can figure out the scripting to do so.
But for starters I cant start scribus from the developing enviroment. Eclipse Anaconda on Ubuntu.
import subprocess
subprocess.run('scribus')
works fine in terminal, but gives me an error in Eclipse which I cant figure out.
File "/home/b256/anaconda3/envs/test/lib/python3.7/site.py", line 178
file=sys.stderr)
^
SyntaxError: invalid syntax
This seems to be some Python 2 error in the site.py file
???? Is this some anaconda python path error ??
It's not really clear to me, what you want to achieve, but you're welcome to have a look at a script of mine:
https://github.com/aoloe/scribus-script-repository/blob/master/imposition/imposition.py
This is probably a bit more complex than what you are trying to achieve:
the script gets started from the terminal,
if it notices that it has not been started from inside of Scribus (the exception on import scribus)...
... it starts Scribus with itself as the Script to be run.
the script runs again, this time from inside of Scribus...
... now there is no exception when importing scribus and the body of the script runs.
Of course, it's simpler if you start a script that launches Scribus with other scripts.
For you the most important line is probably:
call(['scribus', '-g', '-py', sys.argv[0]] + arguments + ['--', file])
It's starting Scribus from Python
with as little GUI as possible (-g) and
launches the script sys.argv[0]
with a few arguments and
after the -- tells Scribus what file to open.

Python file immediately closes

As an assignment for one of my classes, the professor had us download a file containing python code as well as a couple of text files that the python code will analyze.
The problem is, when I click to open the python file, the command window opens, then immediately closes. I can get it to stop from closing if I click on it fast enough, but that stops the code from loading, and any keystroke causes it to close again.
It's the same file every other student downloaded and used with no issue. I've tried re-downloading the file, re-installing python, even trying on a different computer. I've also tried opening it by entering the path file name in the command window with no success. Also no luck trying it in Jupyter Notebook or CodeLab. (And of course, no luck experimenting with the slew of possible solutions on previous Stack Overflow, Reddit, etc. questions).
Any ideas on the potential cause and/or solution?
Edit: cause unknown, but the solution was opening the file with Sypder console.
the file closes immediately because It ended and returned 0, to stop that from happening you can add at the end of the python code something like that:
ending = input("press key to exit")
or just import time and use
time.sleep(5)
you can open your file in the cmd/terminal window and you will be able to see the results

I can't get pythons output viewer to run

I just downloaded python on a new pc and now whenever I try to create a script the output viewer just closes down immediately when I launch it as a python file.
My original script was
import secrets
secrets.token_hex(32)
but it just closes down immediately. I thought that it was something with my code so I tried to just make the simple "hello world" script.
(print) "I hope this work"
and I had the same result as the first script, the output window opened up then immediately closed down.
I can get it to work using the python shell but I prefer doing all my coding using notepad++ and it would a real pain in the behind if I can't get that to work.
This is expected behavior if you run your scripts as you described, by opening them in Explorer. Your script completes execution in a terminal window, then closes immediately.
If you absolutely insist on running them on double click and still want to see your console, I suggest you create a .bat file at your python path with contents like this:
python -i %1
and them bind your double-click handler to use that file on .py extension. That way, Python will execute your file and go into CLI mode, preserving your terminal window and allowing you to type further commands.
My other guess would be that you want a console plugin to work right within Notepad++, in that case use nppexec: https://sourceforge.net/projects/npp-plugins/files/NppExec/

Why does komodo edit require a duplicate .py file to execute my commands?

I am using Komodo edit 7.1 on a macbook pro running OS X mountain lion
Note that the duplicated file needs a space at the beginning. e.g:
to execute hello-world.py, I wrote the code given in the lesson but when running the command i get an error
/bin/sh: /usr/bin/pythonhello-world.py: No such file or directory.
When I create a file name: _hello-world.py (the underscore is actually white space) and execute it from there, the command completes the action correctly
'/usr/bin/python hello-world.py' returned 0.
Interestingly enough, the code for the duplicated file can be blank, somehow it is choosing the proper file.
p.s. obviously I am brand new at this. I have searched google for similar problems but haven't found what I need. Please help!
Thank you
The path to the python executable is not setup correctly. Use the Terminal to fix it.

Resources