[Tutor] Excel com strange behavior

2008-08-29 Thread johan nilsson
Dear all,

I have a problem with talking to Excel. Somehow the command Workbooks.Add()
gives me problems?
If I open a workbook in Excel, then I get the trace back below. I can not
say that I quite understand why this does not work. Any insights would be
highly appreciated.

If I manually open the workbook, I can fill the data in the sheet

Johan


 from win32com.client import Dispatch
 xlApp = Dispatch(Excel.Application)
 xlApp.Visible = 1
 xlApp.Workbooks.Add()

Traceback (most recent call last):
  File pyshell#67, line 1, in module
xlApp.Workbooks.Add()
  File
c:\pythonxy\python\lib\site-packages\pywin32-2.11-py2.5-win32.egg\win32com\client\dynamic.py,
line 467, in __getattr__
if self._olerepr_.mapFuncs.has_key(attr): return
self._make_method_(attr)
  File
c:\pythonxy\python\lib\site-packages\pywin32-2.11-py2.5-win32.egg\win32com\client\dynamic.py,
line 295, in _make_method_
methodCodeList =
self._olerepr_.MakeFuncMethod(self._olerepr_.mapFuncs[name], methodName,0)
  File
c:\pythonxy\python\lib\site-packages\pywin32-2.11-py2.5-win32.egg\win32com\client\build.py,
line 297, in MakeFuncMethod
return self.MakeDispatchFuncMethod(entry, name, bMakeClass)
  File
c:\pythonxy\python\lib\site-packages\pywin32-2.11-py2.5-win32.egg\win32com\client\build.py,
line 318, in MakeDispatchFuncMethod
s = linePrefix + 'def ' + name + '(self' + BuildCallList(fdesc, names,
defNamedOptArg, defNamedNotOptArg, defUnnamedArg, defOutArg) + '):'
  File
c:\pythonxy\python\lib\site-packages\pywin32-2.11-py2.5-win32.egg\win32com\client\build.py,
line 604, in BuildCallList
argName = MakePublicAttributeName(argName)
  File
c:\pythonxy\python\lib\site-packages\pywin32-2.11-py2.5-win32.egg\win32com\client\build.py,
line 542, in MakePublicAttributeName
return filter( lambda char: char in valid_identifier_chars, className)
  File
c:\pythonxy\python\lib\site-packages\pywin32-2.11-py2.5-win32.egg\win32com\client\build.py,
line 542, in lambda
return filter( lambda char: char in valid_identifier_chars, className)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x83 in position 52:
ordinal not in range(128)

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] RE expressions

2008-08-15 Thread Johan Nilsson

Hi all python experts


I am trying to work with BeautifulSoup and re and running into one problem.

What I want to do is open a webpage and get some information. This is  
working fine
I then want to follow  some of links on this page and proces them. I  
manage to get links that I am interested in filtered out with by simple re  
expressions. My problem is that I now have a number of string that look  
like


'text  http:\123\interesting_adress\etc\etc\ more text'

I have figured out that if it wasn't for the \ a simple
p=re.compile('\\w+\') would do the trick. From what I understand \w only  
covers the set [a-zA-Z0-9_] and hence not the \.
I assume the solution is just in front of my eyes, and I have been looking  
on the screen for too long. Any hints would be appreciated.



In [72]: p=re.compile('\w+\')

In [73]: p.findall('asdsa123abc123jggfds')
Out[73]: ['123abc123']

In [74]: p.findall('asdsa123abc\123jggfds')
Out[74]: ['123abcS']

/Johan

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Windows problem with large(?) files

2006-02-02 Thread johan nilsson
Dear group,I have a few files that contains data in IEEE 754 format. I need to transform them into a csv file, to be able to read these files in another program. Each file has 3 samples of I and Q. I did develop the attached script. I am sure not the best, but it worked at home on my Linux installation Python 
2.4. I was then very confident that it would work also on my work pc (XP with python 2.3). It does not, I get the following error Traceback (most recent call last): File C:\Python23\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py, line 310, in RunScript
 exec codeObject in __main__.__dict__ File E:\OFDMA_test\iqw.py, line 16, in ? x[i/4]=unpack('f',a[i:i+4])[0]error: unpack str size does not match formatapparently the XP box thinks the file is alot shorter, and that can't be as it is the same file from the same media (USB stick). What is going wrong here?
/Johanimport osfrom struct import *from scipy import *f=file(c:\\tmp\\FSL_good_SNR\\Last_IQ.iqw,'r')a=f.read()f.close()x=zeros(len(a)/4)+0.0
for i in range (0, len(a),4): x[i/4]=unpack('f',a[i:i+4])[0]y=x[0:len(x)/2-1]+1j*x[len(x)/2:len(x)-1]writer = file(c:\\tmp\\FSL_good_SNR\\IQ.csv, 'w')for item in y: writer.write
(repr(real(item))+','+repr(imag(item))+'\n')writer.close()
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Windows problem with large(?) files

2006-02-02 Thread johan nilsson
Thanks Danny!that solved it.JohanOn 2/2/06, Danny Yoo [EMAIL PROTECTED] wrote:
On Thu, 2 Feb 2006, johan nilsson wrote: apparently the XP box thinks the file is alot shorter, and that can't be
 as it is the same file from the same media (USB stick). What is going wrong here?Hi Johan,Is it possible that you need to treat the file as a binary file?It'srare, but very possible that something like:
f = open(somefilename,'r')a = f.read()will give you different results on different platforms, because newlinetranslation occurs on the Windows end of things.(\n -- \r\n or visa
versa)So if your file coincidently has bytes with the sequential values:## ord('\r'), ord('\n')(13, 10)##then we should expect to see those two bytes collapsed down to a single
one through the mechanism of newline translation.But if this is happening, there's an easy fix:f = open(somefilename,'rb')a = f.read()where we open the file in binary mode.
Good luck!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Advise...

2005-01-28 Thread Johan Nilsson




Jacob,

Apart from all the other comments you received, here are my thoughts.

I think you could do one more thing to speed up your calculations and
that is to use a more efficient method. The Reimann sum is not a very
efficient. 
One simple method that is rahter popular is Simpson's rule.

The calculations are not much more complicated than what you already
have




You then you just need to make sure that the number of intervals are
even. 

Johan

Jacob S. wrote:
Hi all.
  
  
 Long time no see. (About five days, right?)
  
Anyway, I know the first thing that some of you are going to say is
using eval(). I don't want a whole
  
guilt trip on security risks and all that. I do not want to share the
code with anyone else while it's on my
  
computer, and I sure don't have anyone near me that knows python. I
would be surprised if more than 50
  
people in Portland, IN knew anything about python. So security is not a
problem. I guess what I'm
  
looking for is someone who knows the Reimann Sum better than I do and
can tell me whether I can do
  
something to make it more efficient. It's horribly slow with ten
thousand steps-- I don't know the notation
  
very well, but it loops the loop O(step*(maximum-minimum)) times, which
is horribly sucky.
  
 In case anyone doesn't know, Reimann's sum is the computer's version
of the definite integral, the area
  
under a curve in a particular domain.
  
  
Basic input and output.
  
If a curve is a straight line, say y = x, the area under the line on an
interval can be found by geometric means.
  
However, if you use a parabola, or any other function, say y = 3*x**2,
  
  
  
What is the function? 3*x*x
  
What is the minimum? 2
  
What is the maximum? 5
  
117.000435
  
  
Which, considering that it is supposed to be exactly 117, It's darn
good. Unfortunately, it also takes about
  
10 seconds to do all that.
  
Any suggestions? Any advice? TIA
  
Jacob Schmidt
  
  
  

  
from __future__ import division
  
import psyco
  
psyco.full()
  
fofx = raw_input("What is the function? ")
  
minimum = raw_input("What is the minimum? ")
  
maximum = raw_input("What is the maximum? ")
  
minimum = float(minimum)
  
maximum = float(maximum)
  
total = 0
  
step = 10
  
x = minimum
  
while minimum = x = maximum:
  
 area = eval(fofx)*1/step
  
 total = total+area
  
 x = x+1/step
  
print total
  
# 
___
  
Tutor maillist - Tutor@python.org
  
http://mail.python.org/mailman/listinfo/tutor
  




inline: img108.gif___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How does import work?

2005-01-28 Thread Johan Nilsson
Hi all,
I am rather new to python. I am trying to write a program using the 
scipy package. I have come across a problem that confuses me, and I hope 
that someone could give me an hint on how to solve this.

Here is what I do
Start idle
 from scipy.signal.signaltools import *
/Traceback (most recent call last):
 File pyshell#0, line 1, in -toplevel-
   from scipy.signal.signaltools import *
ImportError: No module named signaltools/
So I try the methodic way and this works, giving me access to the 
functions I need

 from scipy import *
 from scipy.signal import *
 from scipy.signal.signaltools import *
Now what confuses me is that when I put the above three lines in a file 
(of course without the ) and execute them I get a long error message.

/ Traceback (most recent call last):
 File /home/johan/pyton/import_test.py, line 5, in -toplevel-
   from scipy.signal import *
 File /usr/local/lib/python2.3/site-packages/scipy_base/ppimport.py, 
line 270, in __getattr__
   module = self._ppimport_importer()
 File /usr/local/lib/python2.3/site-packages/scipy_base/ppimport.py, 
line 233, in _ppimport_importer
   raise PPImportError,\
PPImportError: Traceback (most recent call last):
 File /usr/local/lib/python2.3/site-packages/scipy_base/ppimport.py, 
line 243, in _ppimport_importer
   module = __import__(name,None,None,['*'])
 File /usr/lib/python2.3/site-packages/scipy/signal/__init__.py, line 
11, in ?
 File /usr/lib/python2.3/site-packages/scipy/signal/ltisys.py, line 
14, in ?
 File /usr/local/lib/python2.3/site-packages/scipy_base/ppimport.py, 
line 270, in __getattr__
   module = self._ppimport_importer()
 File /usr/local/lib/python2.3/site-packages/scipy_base/ppimport.py, 
line 233, in _ppimport_importer
   raise PPImportError,\
PPImportError: Traceback (most recent call last):
 File /usr/local/lib/python2.3/site-packages/scipy_base/ppimport.py, 
line 243, in _ppimport_importer
   module = __import__(name,None,None,['*'])
 File /usr/lib/python2.3/site-packages/Numeric/Matrix.py, line 5, in ?
   import LinearAlgebra
 File 
/usr/local/lib/python2.3/site-packages/Numeric/LinearAlgebra.py, line 
8, in ?
   import lapack_lite
ImportError: 
/usr/local/lib/python2.3/site-packages/Numeric/lapack_lite.so: undefined 
symbol: dgesdd_/

What I dont understand is how can the import statements work, when I 
type them in manually in IDLE and not when I execute them in a file? Has 
anyone come across this type of behavior before?

Johan
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor