I am not getting the reason why my python script is not working though I hv put all the things correctly as my knowledge.The below test I did and it worked fine.But when I import the MySQLdb in my script it gives error as no module name MySQLdb.
**C:\Python26>python
Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
import MySQLdb
**
Kindly let me know the reason for this error.
And all the development is going on in windows XP, python 2.6, mysql 4.0.3
Earlier 1 hour back I have posted the question but some mistake was there in the question itself..
seems like the path is not set properly.
Related
According to the documentation of PySimpleGUI, the popup element should have an argument called button_justification, which position the button in 'right' or 'left', or 'center' within the popup window.
When i added button_justification='center' to the popup element in my project it raised the error: popup() got an unexpected keyword argument 'button_justification'. What's the problem?
Image
Not all enhancements added into the PyPI version.
Download from GitHub
There is code in the PySimpleGUI package that upgrades your previously pip installed package to the latest version checked into GitHub.
You can use the commands psgmain to run the test harness or psgupgrade to invoke the GitHub upgrade code.
or, you can call sg.main(), like
d:\>python
Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import PySimpleGUI as sg
>>> sg.main()
I am attempting to change a directory via its IP address or using it's unc (as I am working in windows). This is due to the external server being mapped to different drives for different users.
Using os.chdir(r'path\\to\remote\directory') does not seem to work and I wonder if there are any alternatives that python doesn't hate i.e. an IP address?
Works fine for me:
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.chdir(r"\\myserver\myshare")
>>> os.getcwd()
'\\\\myserver\\myshare'
It's hard to tell if the r'path\\to\remote\directory' typo is also in your actual code and how you determined it "does not work".
I use Windows 7, 64bit, with installed Python 2.7 and Oracle instant client 10.2.0.3.
I try to set up connection with Oracle database from python. In order to do this, I download cx_Oracle-5.1.2-10g.win32-py2.7.msi and install it.
upd. it's an error. i meant cx_Oracle-5.1.2-10g.win-amd64-py2.7.msi
Then I try to connect use code like this
import cx_Oracle
ad = cx_Oracle.makedsn('127.0.0.1', '1521', 'XE')
con = cx_Oracle.connect('user', 'password', ad)
And check that connection is set up correctly by selecting some rows from database table.
And at this moment happens something interesting.
I perform described actions in three different environments: Sublime Text 3, Python Console and ipython.
The problem is in ST3 and in ipython this chunk of code silently crashes on line with cx_Oracle.connect (I checked that with print statement in different places).
But in python console and idle it works just fine. Moreover sometimes it works properly in ipython, but I cannot understand why and when. In ST3 it never works.
ST shows message [Finished in 0.4s with exit code 3221226356]
To demonstrate behavior in python and ipython console I attach copypaste of simple case from cmd. It just exits from ipython.
C:\Users\Alexey>python
Python 2.7.7 (default, Jun 1 2014, 14:21:57) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>> cx_Oracle.connect()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cx_Oracle.DatabaseError: ORA-12560: TNS:protocol adapter error
>>> exit()
C:\Users\Alexey>ipython
Python 2.7.7 (default, Jun 1 2014, 14:21:57) [MSC v.1500 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 2.2.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import cx_Oracle
In [2]: cx_Oracle.connect()
C:\Users\Alexey>
Where is the problem? How can I solve it?
Thanks in advance.
PS. I tried to handle exception in ST3 and ipython such as
try:
cx_Oracle.connect()
except Exception as e:
print e
but script terminates on cx_Oracle.connect() and no message appears.
I tried this environment myself and did not experience the same behavior. Perhaps use faulthandler or gdb or some equivalent to figure out where the crash is taking place? cx_Oracle is still maintained (by me) so if you can find a bug I'll happily fix it! It may also be a problem with IPython or ST3 or in some interaction between these two and cx_Oracle. Since I can't replicate the problem, however, you'll need to provide a stack trace of some sort so we can proceed further.
I'm new to python, and I'm trying to get a basic working understanding of changing the working directory and working with .py files. At the moment, I've changed the directory to where a couple of my .py files are, but when I go to import them, I get a time lag of over a minute for each one. Is that to be expected? Any idea what's going on? Here's what I'm doing:
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import os
>>> os.getcwd()
'C:\\Python33'
>>> os.chdir("C:/Users/MarketResearch")
>>> import EarningsDownload
>>> import RatingsChanges
>>>
Sounds like your module is actually doing work when it is imported. This is (usually) a bad idea. What you should do instead is put your setup code into a function, say setup() or initialize(), and then call it after importing:
import earnings_download
earnings_download.initialize()
Getting two different modification time when calculated from different Python versions on Windows XP.
Python2.4
C:\Copy of elisp>c:\python24\python
Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.getmtime("auto-complete-emacs-lisp.el")
1251684178
>>> ^Z
Python2.6
C:\Copy of elisp>C:\Python26\python
Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.getmtime("auto-complete-emacs-lisp.el")
1251687778.0
>>>
There is a difference of 3600 seconds reported by Python2.6 and Python2.4.
What is the reason of this strange behavior?
It's a bug in Microsoft's implementation of the C standard library. Python 2.4 used to use the stdlib fstat call to get file information, and hence could end up an hour out in locales that use DST.
In Python 2.5 and later, os.stat calls the direct Win32-only API to get file information when running on Windows, resulting in the correct output. See this thread for more.
There is a difference of 3600 seconds ...
This should be the kicker. It's a timezone problem, pure and simple.
Now all you have to do is find out why 2.4 and 2.6 are using different timezone information :-)