python 3.4 shell, why need to reimport same module (never restart shell) - python-3.x

Today it happened to me multiple times. I was using Python 3.4.4 shell on win32. I imported datetime, and did some input like 'print(datetime.datetime.now().date())' and got output right. After a while, I had to type "import datetime" again in order to do similar work (like 'datetime.datetime.now(datetime.timezone.utc)')
I think the similar problem happened to me before with other module?
Can anyone explain? I was looking for answers here and google but with no luck.

Related

Is there a python module in linux similar to win32gui for sending input to inactive windows

Basically title, is there anything like this? I googled around a bit but couldn't find anything relevant to Linux only... win32gui postcommand is what I'm looking for an equivalent on Linux
The module python-libxdo should be able to achieve what you wanted to do.
In particular, you can hardcode window id.

I have tried many methods and I couldn't find solution. So how to convert Python file to executables?

Python : 3.5
PYinstaller : 3.5
Win64
cx_Freeze : 6.0
According to the above information, I have tried to convert Python project to exe but it does not work.
First I have tried pyinstaller but the process throw some error:
After that, I have tried cx_Freeze and it works, but the exe are working on some computer but not on every computer that have same platform.
I don't know what I can do. I looked for google and stackoverflow but there are unsolved problems or I couldn't see the solution.
Later I have tried to change python version but doesn't work again. Computers that have tried to running the exe, have same OS platform, I'm sure.
By the way, if you receive the following cx_Freeze error, resolving like this:
Build\exe.win-amd64-3.7\lib\scipy\spatial\cKDTree.cp37-win_amd64
change to
Build\exe.win-amd64-3.7\lib\scipy\spatial\ckdtree.cp37-win_amd64
Program uses the following modules : tkinter, pydicom, skimage, PIL, cv2, etc.
Primarily Program has 2 page that content code but I made single file for I came across this sentence "It's worth noting that pyinstaller can compile to a single .exe file"
What do you suggest I do? Thanks for your help.
Edit: I have been tried "Auto-py-to-exe" but I got an error (Fatal Error : Failed to execute script")
Edit2: I tried to run outside the anaconda. I think its work. But I'm still testing.
Edit3: I have tried to change python version, GUI was opened another computer but the program is not work properly. the program works on my computer but not on another computers
If you are not able to convert python file to executable format, you can try using auto py-to-exe library.
This library contains a GUI format to convert .py files to .exe
Here you can find auto py-to-exe with usage instructions,
https://pypi.org/project/auto-py-to-exe/

How to syntax check Python?

I'm writing just a simple Python 3 program (beginner here) and I want to syntax check the code rather than just run it and see errors. How can I do this?
I've done python3 -m py_compile sender.py but nothing changes or is displayed. I'm using version 3.5.2 in Ubuntu, and sender.py is in the directory that I'm currently in.
There are some Python editors than can do this.
For example, Spyder and PyCharm.
They highlight the code segments that have problems.
If you are looking for tools similar to regular compilers, then you can have a look at this stackoverflow question and this with good answers.

Getting python to type

How would I get python to type for me. The only thing I've found was on SendKeys but I can't find the version for python 3.5. Is there any built in module I can use to get python to type for me?
The win32api, assuming windows, has what you need in the keybd_event() function. Documentation here. As for built-ins, not aware of anything like that. Also, see this page.

Novice with Python

I have just downloaded Python 3.3.2 to use on windows7 and run the msi file to install. After installation I have tried using the prog only to find that every time I run my initial print 'hello world' it keeps reporting a syntax error.
I have tried both single and double quotes but each time reports a syntax. It will add say 8 + 9 and return the answer but no joy with using a print statement.
I have tried both the shell and a new window but without success.
Any advice please much appreciated.
If you are using Python 3.x, you have to do print('hello world').
In Python 2.x, print was a statement, like if, for, etc. Now it is a function, thus the ().
You're probably using instructions for a python-2 program, where print was a statement, rather than a function. In python >= 3, you have to do print(something), rather than just print something.

Resources