os.path.getmtime on windows, error: 206 - path or extension too long
I have very long path on windows and i get error when try to get
modification time. So i tried do chdir path and then get file. It now
gives me error that file doesn't exists
# code
def getmtimeWIN32(p):
mycwd = os.getcwd()
if p.startswith('?\\'):
p = p.replace('?\\', '', 1)
p = os.path.splitdrive(p)
r = p[0] # root - dir name
p = p[1]
p = os.path.split(p)
f = p[1] # filename
d = p[0]
l = d.split('\\');
if r != '': # if root is not empty change to root (it not works
when script is on other partition than file)
os.chdir('/')
for i in l:
if i != '':
os.chdir(i)
#print i
print os.getcwd()
os.path.getmtime(f)
os.chdir(mycwd)
# /code
it works for other files so i suppose it is not my fault. I know there
is a win32 module but i can't find any documentation for it (what is
the purpose to create app without docs?). Any idea?
I searched google but there where only 2 options. Use chdir (not
working) or use win32api (where is no documentation).
(python 2.5)
--
http://mail.python.org/mailman/listinfo/python-list
Re: os.path.getmtime on windows, error: 206 - path or extension too long
On Jan 21, 11:50 am, mynthon wrote:
> I have very long path on windows and i get error when try to get
> modification time. So i tried do chdir path and then get file. It now
> gives me error that file doesn't exists
>
> # code
> def getmtimeWIN32(p):
> mycwd = os.getcwd()
>
> if p.startswith('?\\'):
> p = p.replace('?\\', '', 1)
>
> p = os.path.splitdrive(p)
> r = p[0] # root - dir name
> p = p[1]
> p = os.path.split(p)
> f = p[1] # filename
> d = p[0]
> l = d.split('\\');
>
> if r != '': # if root is not empty change to root (it not works
> when script is on other partition than file)
> os.chdir('/')
>
> for i in l:
> if i != '':
> os.chdir(i)
> #print i
> print os.getcwd()
> os.path.getmtime(f)
> os.chdir(mycwd)
> # /code
>
> it works for other files so i suppose it is not my fault. I know there
> is a win32 module but i can't find any documentation for it (what is
> the purpose to create app without docs?). Any idea?
>
> I searched google but there where only 2 options. Use chdir (not
> working) or use win32api (where is no documentation).
>
> (python 2.5)
ok, what ive found:
os.chdir('very_long_path')
# works
os.listdir('very_long_path')
# gives:
Traceback (most recent call last):
File "", line 1, in
TypeError: listdir() argument 1 must be (buffer overflow), not str
os.chdir('very_long_path')
os.listdir('.')
#works
os.chdir('very_long_path')
os.path.getmtime(os.listdir('.')[0])
#throws exception (path not exists)
os.chdir('very_long_path')
open(os.listdir('.')[0])
#throws exception (path not exists)
--
http://mail.python.org/mailman/listinfo/python-list
Re: os.path.getmtime on windows, error: 206 - path or extension too long
On Jan 21, 2:13 pm, mynthon wrote:
> On Jan 21, 11:50 am, mynthon wrote:
>
>
>
> > I have very long path on windows and i get error when try to get
> > modification time. So i tried do chdir path and then get file. It now
> > gives me error that file doesn't exists
>
> > # code
> > def getmtimeWIN32(p):
> > mycwd = os.getcwd()
>
> > if p.startswith('?\\'):
> > p = p.replace('?\\', '', 1)
>
> > p = os.path.splitdrive(p)
> > r = p[0] # root - dir name
> > p = p[1]
> > p = os.path.split(p)
> > f = p[1] # filename
> > d = p[0]
> > l = d.split('\\');
>
> > if r != '': # if root is not empty change to root (it not works
> > when script is on other partition than file)
> > os.chdir('/')
>
> > for i in l:
> > if i != '':
> > os.chdir(i)
> > #print i
> > print os.getcwd()
> > os.path.getmtime(f)
> > os.chdir(mycwd)
> > # /code
>
> > it works for other files so i suppose it is not my fault. I know there
> > is a win32 module but i can't find any documentation for it (what is
> > the purpose to create app without docs?). Any idea?
>
> > I searched google but there where only 2 options. Use chdir (not
> > working) or use win32api (where is no documentation).
>
> > (python 2.5)
>
> ok, what ive found:
>
> os.chdir('very_long_path')
> # works
>
> os.listdir('very_long_path')
> # gives:
> Traceback (most recent call last):
> File "", line 1, in
> TypeError: listdir() argument 1 must be (buffer overflow), not str
>
> os.chdir('very_long_path')
> os.listdir('.')
> #works
>
> os.chdir('very_long_path')
> os.path.getmtime(os.listdir('.')[0])
> #throws exception (path not exists)
>
> os.chdir('very_long_path')
> open(os.listdir('.')[0])
> #throws exception (path not exists)
i dont have a solution but workaround.
I can map long path as drive:
longPath = "c:\\documents and settings\\usermth\\my documents\
\..blablablabla"
# map path as drive b: (notice "" around path to avoid problems with
spaces)
os.system('subst b: "%s"' % longPath)
longPath = 'b:\\'
--
http://mail.python.org/mailman/listinfo/python-list
Re: os.path.getmtime on windows, error: 206 - path or extension too long
On Jan 21, 2:58 pm, mynthon wrote:
> On Jan 21, 2:13 pm, mynthon wrote:
>
>
>
> > On Jan 21, 11:50 am, mynthon wrote:
>
> > > I have very long path on windows and i get error when try to get
> > > modification time. So i tried do chdir path and then get file. It now
> > > gives me error that file doesn't exists
>
> > > # code
> > > def getmtimeWIN32(p):
> > > mycwd = os.getcwd()
>
> > > if p.startswith('?\\'):
> > > p = p.replace('?\\', '', 1)
>
> > > p = os.path.splitdrive(p)
> > > r = p[0] # root - dir name
> > > p = p[1]
> > > p = os.path.split(p)
> > > f = p[1] # filename
> > > d = p[0]
> > > l = d.split('\\');
>
> > > if r != '': # if root is not empty change to root (it not works
> > > when script is on other partition than file)
> > > os.chdir('/')
>
> > > for i in l:
> > > if i != '':
> > > os.chdir(i)
> > > #print i
> > > print os.getcwd()
> > > os.path.getmtime(f)
> > > os.chdir(mycwd)
> > > # /code
>
> > > it works for other files so i suppose it is not my fault. I know there
> > > is a win32 module but i can't find any documentation for it (what is
> > > the purpose to create app without docs?). Any idea?
>
> > > I searched google but there where only 2 options. Use chdir (not
> > > working) or use win32api (where is no documentation).
>
> > > (python 2.5)
>
> > ok, what ive found:
>
> > os.chdir('very_long_path')
> > # works
>
> > os.listdir('very_long_path')
> > # gives:
> > Traceback (most recent call last):
> > File "", line 1, in
> > TypeError: listdir() argument 1 must be (buffer overflow), not str
>
> > os.chdir('very_long_path')
> > os.listdir('.')
> > #works
>
> > os.chdir('very_long_path')
> > os.path.getmtime(os.listdir('.')[0])
> > #throws exception (path not exists)
>
> > os.chdir('very_long_path')
> > open(os.listdir('.')[0])
> > #throws exception (path not exists)
>
> i dont have a solution but workaround.
> I can map long path as drive:
>
> longPath = "c:\\documents and settings\\usermth\\my documents\
> \..blablablabla"
>
> # map path as drive b: (notice "" around path to avoid problems with
> spaces)
> os.system('subst b: "%s"' % longPath)
>
> longPath = 'b:\\'
you can also use \\?\ prefix but ONLY FOR unicode strings
os.path.getmtime("?\\c:\\very lon path\\blablabla") #will not work
os.path.getmtime(u"?\\c:\\very lon path\\blablabla") #will work
--
http://mail.python.org/mailman/listinfo/python-list
wxPython.button.disabled still catching clicks
Hello! (sorry for my english) I have a problem with buttons in wxPython. When button is disabled (by .Disable() or .Enable(False)) it is grayed out but still receive clicks. Eg. i have button that disable itself, runs long action and enable itself: def onClick(self, evt): self.btn.Enable(False) for i in range (1000): print i self.btn.Enable(True) when for loop is running button is greyed out and when i click on it nothing happens but when loop ends another one is started because button "remebered" thad i click on it when was diabled. My only idea is to reposition button outside frame instead of disabling it but this solution is...not good. thanks for any help. Ive searched groups, google and it looks that only i have this problem :) -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython.button.disabled still catching clicks
On Dec 23, 11:58 am, Aaron Brady wrote:
> On Dec 23, 4:50 am, mynthon wrote:
>
>
>
> > Hello! (sorry for my english)
>
> > I have a problem with buttons in wxPython. When button is disabled
> > (by .Disable() or .Enable(False)) it is grayed out but still receive
> > clicks.
>
> > Eg. i have button that disable itself, runs long action and enable
> > itself:
>
> > def onClick(self, evt):
> > self.btn.Enable(False)
> > for i in range (1000):
> > print i
> > self.btn.Enable(True)
>
> > when for loop is running button is greyed out and when i click on it
> > nothing happens but when loop ends another one is started because
> > button "remebered" thad i click on it when was diabled. My only idea
> > is to reposition button outside frame instead of disabling it but this
> > solution is...not good.
>
> > thanks for any help. Ive searched groups, google and it looks that
> > only i have this problem :)
>
> No, it is very common. During your for loop, the loop is dominating
> the process completely. Events are just building up in the app's
> message queue, and don't get handled until after you yield on control.
>
> If you need to run a long task, look into threading, the OnIdle
> method, the 'multiprocessing' module, or pump messages during your
> long task.
ok, maybe someone will need it. I dont know how it works because i
didnt have time to read docs and i cannot explain everything. I used
google and wxPython demo (in tree: wxpython overview / process and
events / process)
class leftPanel(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id, style=wx.BORDER_SUNKEN)
# here you have to define new process, IDLE event, and
onPRocessEnd event
self.process = None
self.GetParent().Bind(wx.EVT_IDLE, self.onIdle)
self.Bind(wx.EVT_END_PROCESS, self.onProcessEnd)
# create button and bind event to it
self.runScriptBtn = wx.Button(self, -1, 'RUN ME!', (10,220))
self.runScriptBtn.Bind(wx.EVT_BUTTON, self.onClick,
self.runScriptBtn)
def onClick(self, evt):
# disable button
self.runScriptBtn.Enable(False)
# here you have to enter command to run
# previusly i heve here exec('python myScript.py')
# but now it will be a subprocess
cmd = 'python xxx1.py'
#create new process
self.process = wx.Process(self)
# dont know what it is for
self.process.Redirect()
# execute cmd command
pid = wx.Execute(cmd, wx.EXEC_ASYNC, self.process)
def onIdle(self, evt):
# beacuse this method is called only when app enters idle mode
# the line below is nedded to "simulate" entering idle mode
# dont know how it works but it works
evt.RequestMore(True)
# here is some code to catch subprocess output
if self.process is not None:
stream = self.process.GetInputStream()
if stream.CanRead():
text = stream.read()
print text
def onProcessEnd(self, evt):
# here is some code to catch subprocess output
# when it is destroyed
stream = self.process.GetInputStream()
if stream.CanRead():
text = stream.read()
print text
# dont know it is necessary
self.process.CloseOutput()
# remove (clear) process object
self.process.Destroy()
self.process = None
# show button again
self.runScriptBtn.Enable()
--
http://mail.python.org/mailman/listinfo/python-list
Re: wxPython.button.disabled still catching clicks
On Dec 23, 6:12 pm, Mike Driscoll wrote:
> On Dec 23, 7:27 am,mynthon wrote:
>
>
>
> > On Dec 23, 11:58 am, Aaron Brady wrote:
>
> > > On Dec 23, 4:50 am,mynthon wrote:
>
> > > > Hello! (sorry for my english)
>
> > > > I have a problem with buttons in wxPython. When button is disabled
> > > > (by .Disable() or .Enable(False)) it is grayed out but still receive
> > > > clicks.
>
> > > > Eg. i have button that disable itself, runs long action and enable
> > > > itself:
>
> > > > def onClick(self, evt):
> > > > self.btn.Enable(False)
> > > > for i in range (1000):
> > > > print i
> > > > self.btn.Enable(True)
>
> > > > when for loop is running button is greyed out and when i click on it
> > > > nothing happens but when loop ends another one is started because
> > > > button "remebered" thad i click on it when was diabled. My only idea
> > > > is to reposition button outside frame instead of disabling it but this
> > > > solution is...not good.
>
> > > > thanks for any help. Ive searched groups, google and it looks that
> > > > only i have this problem :)
>
> > > No, it is very common. During your for loop, the loop is dominating
> > > the process completely. Events are just building up in the app's
> > > message queue, and don't get handled until after you yield on control.
>
> > > If you need to run a long task, look into threading, the OnIdle
> > > method, the 'multiprocessing' module, or pump messages during your
> > > long task.
>
> > ok, maybe someone will need it. I dont know how it works because i
> > didnt have time to read docs and i cannot explain everything. I used
> > google and wxPython demo (in tree: wxpython overview / process and
> > events / process)
>
> > class leftPanel(wx.Panel):
> > def __init__(self, parent, id):
> > wx.Panel.__init__(self, parent, id, style=wx.BORDER_SUNKEN)
>
> > # here you have to define new process, IDLE event, and
> > onPRocessEnd event
> > self.process = None
> > self.GetParent().Bind(wx.EVT_IDLE, self.onIdle)
> > self.Bind(wx.EVT_END_PROCESS, self.onProcessEnd)
>
> > # create button and bind event to it
> > self.runScriptBtn = wx.Button(self, -1, 'RUN ME!', (10,220))
> > self.runScriptBtn.Bind(wx.EVT_BUTTON, self.onClick,
> > self.runScriptBtn)
>
> > def onClick(self, evt):
> > # disable button
> > self.runScriptBtn.Enable(False)
>
> > # here you have to enter command to run
> > # previusly i heve here exec('pythonmyScript.py')
> > # but now it will be a subprocess
> > cmd = 'pythonxxx1.py'
>
> > #create new process
> > self.process = wx.Process(self)
>
> > # dont know what it is for
> > self.process.Redirect()
>
> > # execute cmd command
> > pid = wx.Execute(cmd, wx.EXEC_ASYNC, self.process)
>
> > def onIdle(self, evt):
> > # beacuse this method is called only when app enters idle mode
> > # the line below is nedded to "simulate" entering idle mode
> > # dont know how it works but it works
> > evt.RequestMore(True)
>
> > # here is some code to catch subprocess output
> > if self.process is not None:
> > stream = self.process.GetInputStream()
> > if stream.CanRead():
> > text = stream.read()
> > print text
>
> > def onProcessEnd(self, evt):
> > # here is some code to catch subprocess output
> > # when it is destroyed
> > stream = self.process.GetInputStream()
> > if stream.CanRead():
> > text = stream.read()
> > print text
>
> > # dont know it is necessary
> > self.process.CloseOutput()
>
> > # remove (clear) process object
> > self.process.Destroy()
> > self.process = None
>
> > # show button again
> > self.runScriptBtn.Enable()
>
> I'm pretty sure there's a better way to do this. If you disable the
> button and click on it, you'll notice that it isn't firing events, so
> something else is going on here. It seems like the wx.Frame or
> wx.Application is queuing the mouse button clicks or something. I
> would post to the wxPython mailing list:http://wxpython.org/maillist.php
>
> They'll be better able to address this and they'll probably have a
> simpler solution too.
>
> Mike
I changed it. Now i'm running separate thread instead of process.
First example at:
http://wiki.wxpython.org/LongRunningTasks
--
http://mail.python.org/mailman/listinfo/python-list
imp.load_source() - explanation needed
Hi!
I need help. I don't understand what doc says.
I load module from path testmod/mytest.py using imp.load_source(). My
code is
import imp
testmod = imp.load_source('koko', 'testmod/mytest.py)
print testmod
but i don't understand whatt is first (name) argument for. Docs says
that "The name argument is used to create or access a module object."
But i still don't understand. I cant do this
import imp
testmod = imp.load_source('koko', 'testmod/mytest.py)
print koko
How i can access module object using its name? Is " print sys.modules
['koko'] " only way or am i missing something?
--
http://mail.python.org/mailman/listinfo/python-list
logging module, SMTPHandler and gmail in python 2.6
You cannot use gmail account for sending emails with logging module.
It is because google requires TLS connection and logging module
doesn't support it. To use gmail you have to extend
logging.handlers.SMTPHandler class and override SMTPHandler.emit()
method. Here is source code.
(There really should be option to add user comments on pythons
documentation page!)
#--code--#
import logging
import logging.handlers
class TlsSMTPHandler(logging.handlers.SMTPHandler):
def emit(self, record):
"""
Emit a record.
Format the record and send it to the specified addressees.
"""
try:
import smtplib
import string # for tls add this line
try:
from email.utils import formatdate
except ImportError:
formatdate = self.date_time
port = self.mailport
if not port:
port = smtplib.SMTP_PORT
smtp = smtplib.SMTP(self.mailhost, port)
msg = self.format(record)
msg = "From: %s\r\nTo: %s\r\nSubject: %s\r\nDate: %s\r\n\r
\n%s" % (
self.fromaddr,
string.join(self.toaddrs, ","),
self.getSubject(record),
formatdate(), msg)
if self.username:
smtp.ehlo() # for tls add this line
smtp.starttls() # for tls add this line
smtp.ehlo() # for tls add this line
smtp.login(self.username, self.password)
smtp.sendmail(self.fromaddr, self.toaddrs, msg)
smtp.quit()
except (KeyboardInterrupt, SystemExit):
raise
except:
self.handleError(record)
logger = logging.getLogger()
gm = TlsSMTPHandler(("smtp.gmail.com", 587), 'b...@my_company.com',
['ad...@my_company.com'], 'Error found!',
('[email protected]', 'top_secret_gmail_password'))
gm.setLevel(logging.ERROR)
logger.addHandler(gm)
try:
1/0
except:
logger.exception('FFFUU-')
#--/code--#
see also fortmatted version at
http://mynthon.net/howto/-/python/python%20-%20logging.SMTPHandler-how-to-use-gmail-smtp-server.txt.
--
http://mail.python.org/mailman/listinfo/python-list
Re: editor with autocompletion
On 4 Gru, 13:37, Tim Chase wrote: > > So I want an editor with auto complete. > > I there any such tool in Python ?(not only in python any other) > > I want it for my new lang > > vim? emacs? or do you want the editor to be written in Python? > > -tkc Try ActiveState Komodo (or free version: Komodo Edit): http://www.activestate.com/komodo_edit/ -- http://mail.python.org/mailman/listinfo/python-list
