Excel file read/write?
As far as I know, there is pyXLWriter for writing and xlrd for reading. Is there such thing so that one can open an Excel file into memory and read/update any sheet/cell on the fly. One analogy to this is the ConfigParser module. Any info would be much appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Re: Excel file read/write?
Thanks for the reply. > > Most folk would seem to be using pyExcelerator rather than pyXLWriter. > It is much more up to date, it just hasn't been worked on for a year, I will give it a shot. > 1. Python COM interface (part of > http://sourceforge.net/projects/pywin32/) with lots of users (and hence > readily available help in this newsgroup), examples, etc -- but > requires (a) Windows OS (b) Microsoft Excel I am not into COM as it is kind of anti-intuitive, at least to me. > > 2. OpenOffice.org has a built-in Python -- 2.n where n is a small > number :-( and almost impenetrable documentation -- Sybren Stuvel has > published some examples: http://www.stuvel.eu/ooo-python > but my guess is that all the users of the OOo interface could fit in a > taxi. Hmmm..., I have 2.4.2 and would not like to down grade myself. > > 3. Gnumeric is rumoured to have a similar scripting facility. Well, I would like to stick with the MS crowd, at least for the moment. Cheers! P -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib en https
> > As I recall, ActiveState doesn't distribute the SSL package that the > > python.org package contains. But... It is possible to copy the SSL > > related files from a python.org package into the ActiveState > > installation. > Are there any instructions on doing this? My Python installation from cygwin seems to have SSL but not the ActiveState. However, I really like the ActiveState PythonWin UI. I would be much appreciated if anyone can provide pointer to get the SSL in AS Python to work. Thanks in advance. P -- http://mail.python.org/mailman/listinfo/python-list
ctypes pointer to pointer
Hi, I have a C function in the dll does the following: DLL_API int dll_foo(char **data, size_t *size) { strcpy(*data, "hello"); *size = strlen(*data); return 0; } So I would call the function as such, char data[8]; size_t size; int status = dll_foo(&data, &size); I have tried the following in Python but not able to get it working... Any help would be appreciated! from ctypes import * mydll = windll.mydll array = c_char * 8 data = array() size = c_long() status = mydll.dll_foo(byref(data), byref(size)) Traceback (most recent call last): File "", line 1, in ? WindowsError: exception: access violation writing 0x mydll.dll_foo(POINTER(data), byref(size)) Traceback (most recent call last): File "", line 1, in ? File "C:\Python24\Lib\site-packages\ctypes\__init__.py", line 197, in POINTER return _pointer_type_cache[cls] TypeError: unhashable type out = c_char_p(data.raw) mydll.dll_foo(byref(out), byref(size)) Traceback (most recent call last): File "", line 1, in ? ValueError: Procedure probably called with too many arguments (8 bytes in excess) mydll..dll_foo(out, byref(size)) Traceback (most recent call last): File "", line 1, in ? WindowsError: exception: access violation writing 0x6C6C6568 temp = create_string_buffer('\000' * 32) mydll.dll_foo(temp, byref(size)) Traceback (most recent call last): File "", line 1, in ? WindowsError: exception: access violation writing 0x mydll.dll_foo(byref(temp), byref(size)) Traceback (most recent call last): File "", line 1, in ? WindowsError: exception: access violation writing 0x -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes pointer to pointer
Thanks for the help. I've figured it out. BTW, DLL_API is defined as #ifdef MYDLL_EXPORTS #define DLL_API __declspec(dllexport) #else #define DLL_API __declspec(dllimport) #endif size = c_int() data = c_char_p('\0' * 8) mydll = cdll.mydll # Use cdll instead of windll to avoid warnings status = mydll.dll_foo(byref(data), byref(size)) -- http://mail.python.org/mailman/listinfo/python-list
windows background process
Hi, I am using Python 2.4.4 on Windows XP SP2. I am trying to start a process (infinite loop application) in the background and I've tried several options and none of them seem to work. Any help would be much appreciated. Thanks, P 1. # This works on PythonWin interactive window, but the python.exe process hangs until mycmd.exe process dies >>> os.popen("mycmd.exe myargs") # works if __name__ == '__main__': os.popen("mycmd.exe myargs") # hangs 2. >>> os.system("mycmd.exe myargs") # hangs, as expected 3. os.spawnl(os.P_NOWAIT, 'mycmd.exe', 'myargs') # mycmd.exe not started os.spawnv(os.P_NOWAIT, 'mycmd.exe', tuple('myargs')) # mycmd.exe not started 4. # Works, but not portable. My code is expected to run on *nix later on os.system('start /B "dummy title" "mycmd.exe" myargs') -- http://mail.python.org/mailman/listinfo/python-list
Re: windows background process
Some update... I just found out that the following seems to work, import subprocess subprocess.Popen(' myargs', executable='mycmd.exe') However, it does not work with "my path\\mycmd.exe" subprocess.Popen(' myargs', executable='"my path\\mycmd.exe"') # error -- http://mail.python.org/mailman/listinfo/python-list
Re: windows background process
Gabriel Genellina wrote: > os.spawnl(os.P_NOWAIT, 'mycmd.exe', 'mycmd.exe', 'first_arg', 'second_arg') > That is, you must provide explicitely the value for argv[0] (executable) > Remember to quote appropiately any parameter with embedded spaces > (including the executable). On Python 2.5 you could use > subprocess.list2cmdline > Right, this works. Before, I didn't realize that the full path goes to the 2nd and 3rd argument of spawnl. Thanks for the help. P -- http://mail.python.org/mailman/listinfo/python-list
Windows SetLocalTime
I am trying to set the system time on my Windows computer, but avoid using the DOS command (date, time). Does anyone know what parameter to pass to function SetLocalTime? CSharp ref http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/813b4ef504f77a43/24fc37c6c9148961?lnk=gst&q=SetLocalTime&rnum=2#24fc37c6c9148961 Thanks a bunch, P >>> import ctypes >>> import pywintypes >>> t = pywintypes.Time(time.time()) >>> ctypes.windll.kernel32.SetLocalTime(t) Traceback (most recent call last): File "", line 1, in ? ArgumentError: argument 1: exceptions.TypeError: Don't know how to convert parameter 1 >>> ctypes.windll.kernel32.SetLocalTime(ctypes.addressof(t)) Traceback (most recent call last): File "", line 1, in ? TypeError: invalid type -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows SetLocalTime
Yes, thank you. I found the function SetLocalTime or SetSystemTime to set the time from MSDN http://msdn2.microsoft.com/en-us/library/ms724942.aspx. I am having trouble passing parameter to the functions in Python. Rob Williscroft wrote: > > Google will usually find the documentation of anything in the > Windows API however sometimes it also helps to add "msdn" to > your search as in: > -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows SetLocalTime
Thank you. It works :-) P Rob Williscroft wrote: > Ok I see, you will probably need these 2 bits of the ctypes > documentation: > > http://docs.python.org/lib/ctypes-structures-unions.html > http://docs.python.org/lib/ctypes-pointers.html > > From there on geting to this is farly straight forward: -- http://mail.python.org/mailman/listinfo/python-list
Re: array of class
> > Or more compactly: > > > > words = [Word(w) for w in 'this is probably what you want'.split()] > > print words > > I didn't want to introduce yet some more "confusing" stuff !-) Indeed, the for loop is perfectly fine and totally readable. Let's save the "confusing stuff" to the Perl folks. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to pass variable to test class
Thanks for replying. I need to pass some external values to the test cases because I want to run the same tests in different environments such as lab/instrument setup. Regards, Podi -- http://mail.python.org/mailman/listinfo/python-list
Do anyone already have code to copy nested files to a flat directory?
Hi, I am trying to copy all files under a directory tree to a single directory (in Windows). I can well write the script myself, but was wonder if anyone has done it so I won't be reinventing the wheel. Thanks in advance. Requirement: # Source file set source\file1.txt source\file2.doc source\dir1\file3.ini source\dir2\file4.exe # Desired target file set target\file1.txt target\file2.doc target\file3.ini target\file4.exe -- http://mail.python.org/mailman/listinfo/python-list
Re: Do anyone already have code to copy nested files to a flat directory?
OK, please don't bother. Here is my wheel :-) import os import shutil def CopyFlat(source, target): count = 0 for root, dirs, files in os.walk(source): for file in files: count += 1 name = root + '\\' + file print '%04d Copying' % count, name, if os.access(target + '\\' + file, os.F_OK): print 'Already exist and replaced!' else: print shutil.copy(name, target) print '%d files copied' % count -- http://mail.python.org/mailman/listinfo/python-list
Re: Do anyone already have code to copy nested files to a flat directory?
Thanks for all the suggestions. Now the wheel comes with bells and whistles ;) -- http://mail.python.org/mailman/listinfo/python-list
How to call functions in Advapi32.dll using ctypes
I have ctypes version 0.9.6 and Python 2.4.2 running on Windows XP Professional. When I tried to use some functions in the Advapi32.dll, some functions are available and some are not. Is this a bug or feature by design? In the example below, I am trying to examine the 'InitiateSystemShutdown' function which is from Advapi32.dll as advertised by Microsoft http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shutdown/base/initiatesystemshutdown.asp Thanks, P >>> import ctypes >>> advapi32 = ctypes.oledll.LoadLibrary('Advapi32.dll') >>> advapi32.InitiateSystemShutdown Traceback (most recent call last): File "", line 1, in ? File "C:\Python24\lib\site-packages\ctypes\__init__.py", line 395, in __getattr__ func = self._OlecallFuncPtr(name, self) AttributeError: function 'InitiateSystemShutdown' not found >>> -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming Tutorial for absolute beginners
For tutorial in Windows, I think it is better to use the more user-friendly interpreter from http://activestate.com/store/languages/register.plex?id=ActivePython. Advise the user to just click on the "Next" button without submitting the optional contact information. My $0.02 -- http://mail.python.org/mailman/listinfo/python-list
Re: How to call functions in Advapi32.dll using ctypes
> Have you tried calling InitiateSystemShutdownA mentioned in the > documentation? Thanks! This function exists. However, advapi32.InitiateSystemShutdownA("", 'This is a test', 30, 1, 1) returns 0 though. I will need to play with it a bit more... -- http://mail.python.org/mailman/listinfo/python-list
How to create a single executable console application?
I followed the instructions from http://starship.python.net/crew/theller/moin.cgi/SingleFileExecutable Copied the second setup.nsi, setup.py, single.py and everything works like a champ. I then replaced "single.exe" by "hello.exe" in setup.nsi. Created hello.py as follows: #! python def main(): print 'Hello world' if __name__ == '__main__': main() #End of file And changed setup.py as follows: #! python from distutils.core import setup import py2exe sys.argv.append('py2exe') setup( console=["hello.py"] ) # End of file After running python setup.py, dist\hello.exe was created and it runs fine ("Hello world" printed on the console). Compiled setup.nsi, and hello.exe was created in current directory. However, when executed, nothing was printed. I might just missed something obvious. Can anyone help me? Has anyone built a single executable for console application? Please post your .nsi file. Thanks very much, P -- http://mail.python.org/mailman/listinfo/python-list
Re: How to create a single executable console application?
Alright, pythoneers, here is what I have found from http://wiki.wxpython.org/index.cgi/CreatingStandaloneExecutables. This is much easier than the py2exe + nullsoft combo :) Cheers! The mcillian installer development is discontinued. mirror: http://davidf.sjsoft.com/mirrors/mcmillan-inc/installer_dnld.html Continued development(not tested yet): http://pyinstaller.hpcf.upr.edu/cgi-bin/trac.cgi This works on Win32. Unzip the Installer in a directory of your choice, and cd there. Configure the Installer by running: python Configure.py Python must be in your PATH for this to work, if it's not, type from the command prompt: PATH=%PATH%;c:\python23 where c:\python23 must be replaced with the root of your python installation. Then, assuming the source code is app.py (placed in c:\source): python Makespec.py --upx --onefile --noconsole c:\source\app.py python Build.py app\app.spec Replace 'app' everywhere above with your application name. You will end up with app\app.exe under the Installer dir.This is a one file .exe containing all the application. If you don't want a one-file build, suppress the option --onefile above. If you don't have upx installed (or don't want to use it), suppress the option --upx above. The option --noconsole is needed to produce a windows gui application, instead of a console one (so the command shell won't pop up when you run the application). -- http://mail.python.org/mailman/listinfo/python-list
Re: How to create a single executable console application?
Alright, pythoneers, here is what I have found from http://wiki.wxpython.org/index.cgi/CreatingStandaloneExecutables. This is much easier than the py2exe + nullsoft combo :) Cheers! The mcillian installer development is discontinued. mirror: http://davidf.sjsoft.com/mirrors/mcmillan-inc/installer_dnld.html Continued development(not tested yet): http://pyinstaller.hpcf.upr.edu/cgi-bin/trac.cgi This works on Win32. Unzip the Installer in a directory of your choice, and cd there. Configure the Installer by running: python Configure.py Python must be in your PATH for this to work, if it's not, type from the command prompt: PATH=%PATH%;c:\python23 where c:\python23 must be replaced with the root of your python installation. Then, assuming the source code is app.py (placed in c:\source): python Makespec.py --upx --onefile --noconsole c:\source\app.py python Build.py app\app.spec Replace 'app' everywhere above with your application name. You will end up with app\app.exe under the Installer dir.This is a one file .exe containing all the application. If you don't want a one-file build, suppress the option --onefile above. If you don't have upx installed (or don't want to use it), suppress the option --upx above. The option --noconsole is needed to produce a windows gui application, instead of a console one (so the command shell won't pop up when you run the application). -- http://mail.python.org/mailman/listinfo/python-list
How to pass variable to test class
Hi, Newbie question about unittest. I am having trouble passing a variable to a test class object. MyCase class will potentially have many test functions. Any help would be much appreciated. Thanks, P # File MyCase.py import unittest class MyCase(unittest.TestCase): def __init__(self, value): super(MyCase, self).__init__() self.value = value def test1(self): print self.value def test2(self): print 'world' if __name__ == '__main__': msg = 'Hello' myCase = MyCase(msg) suite = unittest.TestSuite() suite.addTest(myCase) unittest.TextTestRunner(verbosity=2).run(suite) D:\MyWorks>MyCase.py Traceback (most recent call last): File "D:\MyWorks\MyCase.py", line 14, in ? myCase = MyCase(msg) File "D:\MyWorks\MyCase.py", line 5, in __init__ super(MyCase, self).__init__() File "C:\Python24\lib\unittest.py", line 208, in __init__ raise ValueError, "no such test method in %s: %s" % \ ValueError: no such test method in : runTest -- http://mail.python.org/mailman/listinfo/python-list