ANN: pyc -- python compiler in python

2005-10-12 Thread Chad Crabtree (IT - Kelly Services)

-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


REMINDER: SoCal Piggies: October 13, 7 PM at USC

2005-10-12 Thread Grig Gheorghiu
The Southern California Python Interest Group will meet on October 13
at 7 PM at USC. Directions are available at
http://socal-piggies.org/scp/USC_Salvatori_Computer_Science_Center,_room_222
(note that there is a room change: this time we'll meet in room 322 and
not 222).

The theme for the meeting is Python graphics and visualization.
Presentations:

PIL tutorial -- Brian Leair
matplotlib overview -- Diane Trout
Creating sparklines with matplotlib -- Grig Gheorghiu

Please consider joining us if you are in the area.

For more details on SoCal Piggies activities, see the group's home page
at http://socal-piggies.org/scp.

Grig

-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: TurboGears /.-ed, new == True or new == True

2005-10-12 Thread Sybren Stuvel
Andy Leszczynski enlightened us with:
 should not it be:

 2 def save(self, pagename, data, submit, new):
 3 hub.begin()
 4 if new == True:
 5 page = Page(pagename=pagename, data=data)
 6 else:
 7 page = Page.byPagename(pagename)
 8 page.data = data

 instead of:

 4 if new == True:

No it should not. The values passed to the function are the strings
passed by the GET request, hence all strings. There are methods of
dealing with this - read the rest of the documentation.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: bizarro world (was Re: Python Doc Problem Example: sort() (reprise))

2005-10-12 Thread Bryan
mr. xah... would you be willing to give a lecture at pycon 2006?  i'm sure you 
would draw a huge crowd and a lot of people would like to meet you in person...

thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: piping out binaries properly

2005-10-12 Thread Paul Rubin
Erik Max Francis [EMAIL PROTECTED] writes:
  I've written lots of things whose standard out was designed
  specifically to be read by another program, but never as binary data.
 
 Plenty of applications use that functionality and depend on it.  See
 cjpeg, djpeg, the pbmplus library, and so forth.

Also tar cf files... | compress  tarball.Z used to be a standard
idiom, now replaced by tar cfz ... which does about the same thing under
the covers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: bizarro world (was Re: Python Doc Problem Example: sort() (reprise))

2005-10-12 Thread Lasse Vågsæther Karlsen
Bryan wrote:
 mr. xah... would you be willing to give a lecture at pycon 2006?  i'm 
 sure you would draw a huge crowd and a lot of people would like to meet 
 you in person...
 
 thanks.
 

I think that would be a highly un-pythonesque crowd. Python isn't much 
in the sense of limitations, but that crowd probably needs to be limited 
in one way or another, like only 2 rotten fruits per person or similar.

-- 
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:[EMAIL PROTECTED]
PGP KeyID: 0x2A42A1C2
-- 
http://mail.python.org/mailman/listinfo/python-list

Adding a __filename__ predefined attribute to 2.5?

2005-10-12 Thread Rune Strand
Is it an idea to include a new __filename__ predefined attribute to
2.5, so that __file__ contains the entire path to the module, and
__filename__ only the name of the module?

For instance it's useful to include a not-static reference to the
filename in a scripts usage() section and it's cumbersome to extract
the filename or to do module imports just to parse it.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: piping out binaries properly

2005-10-12 Thread Fredrik Lundh
Andy Leszczynski wrote:

 when I run under Unix I got:

 $ python u.py  u.bin
 $ od -t x1 u.bin
 000 41 41 0a 41 41

 and under Windows/Cygwin following:

 $ python u.py  u.bin
 $ od -t x1 u.bin
 000 41 41 0d 0a 41 41
 006

 The question is how can I pipe out binary content properly and platform
 independently?

$ python -h
usage: python [option] ... [-c cmd | file | -] [arg] ...
Options and arguments (and corresponding environment variables):
...
-u : unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x)
...

/F



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HELP: Searching File Manager written in Python

2005-10-12 Thread anton
To answer to you both:

The Norton Commander was a popular file manager for DOS,
but the idea of the 2 window concept is still used by a lot of
software.

On Linux the one I use is Midnight Commander (mc).

On Windows there are the 7-zip file manager see http://www.7-zip.org/
(7-zip is also a new compression format which is very good, there
exist also a linux command line version)

- Speed Commander is also a Windows filemanager.

- Atol is based on GTK runs on Linux and Windows
(http://atol.sourceforge.net/)
but is not written in python or cannot run commands
(I also get always error messages at startup that some drives are
missing, perhaps my cdrom or my zip drive, but this happens with
Gimp too - so I believe GTK is the problem)

But actually I work on Windows, thats why I am searching
something which works on windows or better on Windows and Linux

Perhaps some Python+wxWindows Application would be best.

There exist a port of Atol to python+wxPython on:

http://sourceforge.net/projects/wxpyatol

But the project is stopped and abandonware ...

 Thanks a lot  for now :-) I will have a look on your suggestions.

  Stephane

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A problem while using urllib

2005-10-12 Thread Steve Holden
Johnny Lee wrote:
 Alex Martelli wrote:
 
Johnny Lee [EMAIL PROTECTED] wrote:
   ...

   try:
  webPage = urllib2.urlopen(url)
   except urllib2.URLError:

   ...

   webPage.close()
   return True


   But every time when I ran to the 70 to 75 urls (that means 70-75
urls have been tested via this way), the program will crash and all the
urls left will raise urllib2.URLError until the program exits. I tried
many ways to work it out, using urllib, set a sleep(1) in the filter (I
thought it was the massive urls crashed the program). But none works.
BTW, if I set the url from which the program crashed to base url, the
program will still crashed at the 70-75 url. How can I solve this
problem? thanks for your help

Sure looks like a resource leak somewhere (probably leaving a file open
until your program hits some wall of maximum simultaneously open files),
but I can't reproduce it here (MacOSX, tried both Python 2.3.5 and
2.4.1).  What version of Python are you using, and on what platform?
Maybe a simple Python upgrade might fix your problem...


Alex
 
 
 Thanks for the info you provided. I'm using 2.4.1 on cygwin of WinXP.
 If you want to reproduce the problem, I can send the source to you.
 
 This morning I found that this is caused by urllib2. When I use urllib
 instead of urllib2, it won't crash any more. But the matters is that I
 want to catch the HTTP 404 Error which is handled by FancyURLopener in
 urllib.open(). So I can't catch it.
 

I'm using exactly that configuration, so if you let me have that source 
I could take a look at it for you.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List performance and CSV

2005-10-12 Thread Magnus Lycka
[EMAIL PROTECTED] wrote:
 But a really fast approach is to use a dictionary or other structure
 that turns the inner loop into a fast lookup, not a slow loop through
 the 'Customers' list. 

Another approach is to sort both sequences, loop over
both in one loop and just update the index for the smaller
item. Something like this (below, I'm assuming no duplicates
in the lists, and I don't know if that's true for your [2]):

  l1 = (1,2,4,6,7,8,9)
  l2 = (2,5,6,7,9,10)
  i1 = i2 = 0
  while 1:
... if l1[i1]==l2[i2]:
... print l1[i1], 'is in both'
... i1 += 1; i2 += 1
... elif l1[i1]l2[i2]:
... i1 += 1
... else:
... i2 += 1
...
2 is in both
6 is in both
7 is in both
9 is in both
Traceback (most recent call last):
   File stdin, line 2, in ?
IndexError: tuple index out of range

Unless I'm terribly confused, this will lead to m+n iterations
in the worst case. (Of course, the sort operations are something
like O(n log n) I guess.)

By the way, you might be able to use sets too: How fast is
Set.intersection?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: Phases of the moon

2005-10-12 Thread Cruise Director

Ulrich Hobelmann wrote:
 Paul F. Dietz wrote:
  Bart Lateur wrote:
 
  As a similar example: I've been told by various women independently,
  that there are more babies born near a full moon.
 
  That's also a myth.

 Right, everybody knows that it's not natural (moon) light that
 influences reproductive behavior, it's artificial light -- TV.

 When TV is turned off by a power failure, lots of people that usually
 never have sex start making love, and lots of people that usually use
 contraception lose their minds and forget about it.

 9 months later more babies are born, unless that's also a myth.

But the myth in question is babies being *born* under natural or
artificial light.  Not being conceived.


Cheers,
Brandon J. Van Every
   (cruise (director (of SeaFunc)
   '(Seattle Functional Programmers)))
http://groups.yahoo.com/group/SeaFunc

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can we save print msg into a file when script running ?

2005-10-12 Thread Steve Holden
black wrote:
 hi all~
 
 in my .py file there are a few print to trace out some message and i
 wonder if we can save it into a specified file when that script get
 running. if so, i may just check that file to c how the script is
 running. can anyone show me a right direction ?
 
 one million tks~
 
On Unix platforms you can run your script with a redirection of the 
standard output:

python myscript.py  somefile.txt 

[The ampersand runs the command in the background]. Then you can monitor 
the content of the output file with

tail -f somefile.txt

which will show you the last part of the file and further additions as 
long as you let the tail command run.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can we save print msg into a file when script running ?

2005-10-12 Thread Maksim Kasimov
black wrote:
 hi all~
 
 in my .py file there are a few print to trace out some message and i
 wonder if we can save it into a specified file when that script get
 running. if so, i may just check that file to c how the script is
 running. can anyone show me a right direction ?
 
 one million tks~
 

script.py  script.log 21

-- 
Best regards,
Maksim Kasimov
mailto: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Adding a __filename__ predefined attribute to 2.5?

2005-10-12 Thread Steve Holden
Rune Strand wrote:
 Is it an idea to include a new __filename__ predefined attribute to
 2.5, so that __file__ contains the entire path to the module, and
 __filename__ only the name of the module?
 
 For instance it's useful to include a not-static reference to the
 filename in a scripts usage() section and it's cumbersome to extract
 the filename or to do module imports just to parse it.
 
No. It's not usually a good idea to remove complexity from your program 
by adding it (where most of the time it's not needed) to the underlying 
system. Here's a clue as to how you might do without __file__ altogether:

[EMAIL PROTECTED] ~/Projects/Python
$ cat test78.py
import sys
print sys.argv

[EMAIL PROTECTED] ~/Projects/Python
$ python test78.py can we say live with it?
['test78.py', 'can', 'we', 'say', 'live', 'with', 'it?']

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A problem while using urllib

2005-10-12 Thread Johnny Lee

Steve Holden wrote:
 Johnny Lee wrote:
  Alex Martelli wrote:
 
 Johnny Lee [EMAIL PROTECTED] wrote:
...
 
try:
   webPage = urllib2.urlopen(url)
except urllib2.URLError:
 
...
 
webPage.close()
return True
 
 
But every time when I ran to the 70 to 75 urls (that means 70-75
 urls have been tested via this way), the program will crash and all the
 urls left will raise urllib2.URLError until the program exits. I tried
 many ways to work it out, using urllib, set a sleep(1) in the filter (I
 thought it was the massive urls crashed the program). But none works.
 BTW, if I set the url from which the program crashed to base url, the
 program will still crashed at the 70-75 url. How can I solve this
 problem? thanks for your help
 
 Sure looks like a resource leak somewhere (probably leaving a file open
 until your program hits some wall of maximum simultaneously open files),
 but I can't reproduce it here (MacOSX, tried both Python 2.3.5 and
 2.4.1).  What version of Python are you using, and on what platform?
 Maybe a simple Python upgrade might fix your problem...
 
 
 Alex
 
 
  Thanks for the info you provided. I'm using 2.4.1 on cygwin of WinXP.
  If you want to reproduce the problem, I can send the source to you.
 
  This morning I found that this is caused by urllib2. When I use urllib
  instead of urllib2, it won't crash any more. But the matters is that I
  want to catch the HTTP 404 Error which is handled by FancyURLopener in
  urllib.open(). So I can't catch it.
 

 I'm using exactly that configuration, so if you let me have that source
 I could take a look at it for you.

 regards
   Steve
 --
 Steve Holden   +44 150 684 7255  +1 800 494 3119
 Holden Web LLC www.holdenweb.com
 PyCon TX 2006  www.python.org/pycon/


I've sent the source, thanks for your help.

Regrads,
Johnny

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HELP: Searching File Manager written in Python

2005-10-12 Thread Andrew Markebo
Checked Total Commander? 

Has an sort of open API to plugins, and either do a python 'proxy' or
maybe just execute a script.

Next step might be using win32com or SWIG to set up the interface..

Just some ideas.

 /Andy
-- 
 Everything that was magical was just a way of describing the world in
words it couldn't ignore.
- Pyramids by Terry Pratchett

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Adding a __filename__ predefined attribute to 2.5?

2005-10-12 Thread Rune Strand
I Steve,

I know it's several ways to isolate the filename. I just want to avoid
the overhead of importing sys or os  to achieve it.

Currently I have this in my scripts:
__filename__ = __file__.replace('\\', '/').rsplit('/', 1)[-1]

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A problem while using urllib

2005-10-12 Thread Steve Holden
Johnny Lee wrote:
 Steve Holden wrote:
 
Johnny Lee wrote:

Alex Martelli wrote:


Johnny Lee [EMAIL PROTECTED] wrote:
  ...


  try:
 webPage = urllib2.urlopen(url)
  except urllib2.URLError:

  ...


  webPage.close()
  return True


  But every time when I ran to the 70 to 75 urls (that means 70-75
urls have been tested via this way), the program will crash and all the
urls left will raise urllib2.URLError until the program exits. I tried
many ways to work it out, using urllib, set a sleep(1) in the filter (I
thought it was the massive urls crashed the program). But none works.
BTW, if I set the url from which the program crashed to base url, the
program will still crashed at the 70-75 url. How can I solve this
problem? thanks for your help

Sure looks like a resource leak somewhere (probably leaving a file open
until your program hits some wall of maximum simultaneously open files),
but I can't reproduce it here (MacOSX, tried both Python 2.3.5 and
2.4.1).  What version of Python are you using, and on what platform?
Maybe a simple Python upgrade might fix your problem...


Alex


Thanks for the info you provided. I'm using 2.4.1 on cygwin of WinXP.
If you want to reproduce the problem, I can send the source to you.

This morning I found that this is caused by urllib2. When I use urllib
instead of urllib2, it won't crash any more. But the matters is that I
want to catch the HTTP 404 Error which is handled by FancyURLopener in
urllib.open(). So I can't catch it.


I'm using exactly that configuration, so if you let me have that source
I could take a look at it for you.

[...]
 
 I've sent the source, thanks for your help.
 
[...]
Preliminary result, in case this rings bells with people who use urllib2 
quite a lot. I modified the error case to report the actual message 
returned with the exception and I'm seeing things like:

http://www.holdenweb.com/./Python/webframeworks.html
Message: urlopen error (120, 'Operation already in progress')
Start process 
http://www.amazon.com/exec/obidos/ASIN/0596001886/steveholden-20
Error: IOError while parsing 
http://www.amazon.com/exec/obidos/ASIN/0596001886/steveholden-20
Message: urlopen error (120, 'Operation already in progress')
.
.
.

So at least we know now what the error is, and it looks like some sort 
of resource limit (though why only on Cygwin betas me) ... anyone, 
before I start some serious debugging?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Adding a __filename__ predefined attribute to 2.5?

2005-10-12 Thread Stefan Rank
on 12.10.2005 10:02 Diez B. Roggisch said the following:
 Rune Strand wrote:
 
Currently I have this in my scripts:
__filename__ = __file__.replace('\\', '/').rsplit('/', 1)[-1]
 
 This is neither platform independent nor less overhead. This is:
 
 import os
 __filname__ = os.path.split(__file__)[-1]
 

I would say that::

   import os
   filename = os.path.basename(__file__)

is even more explicit.

And with one of the several existing 'path' modules it would be::

   from path import path
   filename = path(__file__).basename


I am sorry if I missed this on this list,
but was there a decision on the idea of including an object-oriented
path class in the standard library?

cheers,
stefan

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's Performance

2005-10-12 Thread bruno modulix
Alex Stapleton wrote:
 
 On 9 Oct 2005, at 19:04, Bruno Desthuilliers wrote:
 
 
 Laszlo Zsolt Nagy a écrit :
(snip)
 Do you want to know how many internal string operations are done  inside
 the Python interpreter? I believe it is not a useful information.  There
 are benchmarks testing the *real performance* of Python.

 For example: http://www.osnews.com/story.php?news_id=5602


 A benchmark stating that Python is interpreted is bullshit.

 Except it is interpreted. What is your point?

Nope. It's byte-compiled, just like Java. What do you think those .pyc
files are exactly ?

-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python's Performance

2005-10-12 Thread bruno modulix
Donn Cave wrote:
 Quoth Fredrik Lundh [EMAIL PROTECTED]:
 | Alex Stapleton wrote
 |
 |  Except it is interpreted.
 |
 | except that it isn't.  Python source code is compiled to byte code, which
 | is then executed by a virtual machine.  if the byte code for a module is up
 | to date, the Python runtime doesn't even look at the source code.
 
 Fair to say that byte code is interpreted?  Seems to require an
 application we commonly call an interpreter.

If so, Java is interpreted too. The only difference between Java and
Python here is that Python is smart enough to call the compiler by itself.

-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why asci-only symbols?

2005-10-12 Thread Martin v. Löwis
Mike Meyer wrote:
 Out of random curiosity, is there a PEP/thread/? that explains why
 Python symbols are restricted to 7-bit ascii?

No PEP yet; I meant to write one for several years now.

The principles would be
- sources must use encoding declarations
- valid identifiers would follow the Unicode consortium guidelines,
   in particular: identifiers would be normalized in NFKC (I think),
   adjusted in the ASCII range for backward compatibility (i.e.
   not introducing any additional ASCII characters as legal identifier
   characters)
- __dict__ will contain Unicode keys
- all objects should support Unicode getattr/setattr (potentially
   raising AttributeError, of course)
- open issue: what to do on the C API (perhaps nothing, perhaps
   allowing UTF-8)

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A problem while using urllib

2005-10-12 Thread Steve Holden
Steve Holden wrote:
 Johnny Lee wrote:
 [...]
 
I've sent the source, thanks for your help.

 
 [...]
 Preliminary result, in case this rings bells with people who use urllib2 
 quite a lot. I modified the error case to report the actual message 
 returned with the exception and I'm seeing things like:
 
 http://www.holdenweb.com/./Python/webframeworks.html
 Message: urlopen error (120, 'Operation already in progress')
 Start process 
 http://www.amazon.com/exec/obidos/ASIN/0596001886/steveholden-20
 Error: IOError while parsing 
 http://www.amazon.com/exec/obidos/ASIN/0596001886/steveholden-20
 Message: urlopen error (120, 'Operation already in progress')
 .
 .
 .
 
 So at least we know now what the error is, and it looks like some sort 
 of resource limit (though why only on Cygwin betas me) ... anyone, 
 before I start some serious debugging?
 
I realized after this post that WingIDE doesn't run under Cygwin, so I 
modified the code further to raise an error and give us a proper 
traceback. I also tested the program under the standard Windows 2.4.1 
release, where it didn't fail, so I conclude you have unearthed a Cygwin 
socket bug. Here's the traceback:

End process http://www.holdenweb.com/contact.html
Start process http://freshmeat.net/releases/192449
Error: IOError while parsing http://freshmeat.net/releases/192449
Message: urlopen error (120, 'Operation already in progress')
Traceback (most recent call last):
   File Spider_bug.py, line 225, in ?
 spider.run()
   File Spider_bug.py, line 143, in run
 self.grabUrl(tempUrl)
   File Spider_bug.py, line 166, in grabUrl
 webPage = urllib2.urlopen(url).read()
   File /usr/lib/python2.4/urllib2.py, line 130, in urlopen
 return _opener.open(url, data)
   File /usr/lib/python2.4/urllib2.py, line 358, in open
 response = self._open(req, data)
   File /usr/lib/python2.4/urllib2.py, line 376, in _open
 '_open', req)
   File /usr/lib/python2.4/urllib2.py, line 337, in _call_chain
 result = func(*args)
   File /usr/lib/python2.4/urllib2.py, line 1021, in http_open
 return self.do_open(httplib.HTTPConnection, req)
   File /usr/lib/python2.4/urllib2.py, line 996, in do_open
 raise URLError(err)
urllib2.URLError: urlopen error (120, 'Operation already in progress')

Looking at that part of the course of urrllib2 we see:

 headers[Connection] = close
 try:
 h.request(req.get_method(), req.get_selector(), req.data, 
headers)
 r = h.getresponse()
 except socket.error, err: # XXX what error?
 raise URLError(err)

So my conclusion is that there's something in the Cygwin socket module 
that causes problems not seen under other platforms.

I couldn't find any obviously-related error in the Python bug tracker, 
and I have copied this message to the Cygwin list in case someone there 
knows what the problem is.

Before making any kind of bug submission you should really see if you 
can build a program shorter that the existing 220+ lines to demonstrate 
the bug, but it does look to me like your program should work (as indeed 
it does on other platforms).

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

-- 
http://mail.python.org/mailman/listinfo/python-list


crosswords helper program

2005-10-12 Thread gg
I plan to write a program in Python in order to help me doing 
crosswords, I was wondering if such a program already existed.

Basically it will get the number of letters of the word (5, 10, 12...) 
then the letters known (B in second letter, E in 5th letter...) and then 
search in a dictionary the words matching this criteria

Regards

Gerard
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nicer way of strip and replace?

2005-10-12 Thread Markus Rosenstihl
On 2005-10-12 01:29:28 +0200, Paul Rubin http://[EMAIL PROTECTED] said:
 
 Oh cool.  I think you could even say:
 
rechnung = list(read_file)
 
 instead of the for loop.

Yes, that is working too.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Adding a __filename__ predefined attribute to 2.5?

2005-10-12 Thread Rune Strand
Excuse me, do you suffer from a bad hair-day? I didn't say it is
platform independant. It's ok for my use on Linux and Windows. If you
cannot imagine any other usecase for a __filename__ attribute, that's
your problem, not mine.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Jargons of Info Tech industry

2005-10-12 Thread Casper H.S.Dik
Steven D'Aprano [EMAIL PROTECTED] writes:

On Tue, 11 Oct 2005 14:27:30 +, axel wrote:

 I don't know how much spam other people receive but on one account I
 hardly receive any as I reserve it for friends and business. On another
 I had about 40 spam messages which took all of ten seconds to delete.
 Hardly a serious matter.

Can I remind you that spam is approximately 70% of all email traffic these
days? Most of that is blocked by the ISPs, but even so you are obviously
one of the lucky few.

95% - 99% of all email, not 70% (just ask your ISP).

A large percentage of the cost of email is the cost of getting
rid of SPAM; and that cannot happen without colleteral damage in the
form of lost valid email, not just because of improper filtering but
also because the more layers are there to touch the email the bigger
the chances that it does not arrive.

My work email address, on the other hand, is another story. We run a two
layer defence: blocking blacklisted addresses at our mail server, and spam
assassin at the individual user level. Even with that, I get about 100
spams a day delivered into my inbox, although many of those are addressed
to generic email addresses which are automatically forwarded to me.

Same here: Sun probably tosses 99% of the email directed at me, yet
I get well over 100 spams/day.

Casper
-- 
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Adding a __filename__ predefined attribute to 2.5?

2005-10-12 Thread Fredrik Lundh
Rune Strand wrote:

 I know it's several ways to isolate the filename. I just want to avoid
 the overhead of importing sys or os  to achieve it.

those modules are already imported when Python gets to your code, so
the only overhead you're saving is a little typing.

 Currently I have this in my scripts:
 __filename__ = __file__.replace('\\', '/').rsplit('/', 1)[-1]

wow.  that's one lousy optimization...

here's a *shorter* piece of code, which is also readable and portable, and
a lot easier to type on most keyboards:

   import os
   __filename__ = os.path.basename(__file__)

/F 



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: crosswords helper program

2005-10-12 Thread Lasse Vågsæther Karlsen
gg wrote:
 I plan to write a program in Python in order to help me doing 
 crosswords, I was wondering if such a program already existed.
 
 Basically it will get the number of letters of the word (5, 10, 12...) 
 then the letters known (B in second letter, E in 5th letter...) and then 
 search in a dictionary the words matching this criteria
 
 Regards
 
 Gerard

Pretty straightforward with a regular expression:

import re
words = [BULLETIN, BALLPARK, BUSINESS]
r = re.compile(^BU..N..S$, re.IGNORECASE)
for word in words:
 if r.match(word):
 print word

You would probably want to allow the user to input both some basic 
format for your program and convert it to a regular expression as well 
as input a full pattern, because then the user can have words that have 
a U or a E in the second letter, simply because he doesn't know which 
one is right yet.

-- 
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:[EMAIL PROTECTED]
PGP KeyID: 0x2A42A1C2
-- 
http://mail.python.org/mailman/listinfo/python-list


mod_python mptest.py works publisher not

2005-10-12 Thread Python_it
I'm going to work with mod_python.

I install mod_python 3.2.2b for python 2.4.

If i test my install with
mptest.py
see this link:
http://www.modpython.org/live/mod_python-3.2.2b/doc-html/modpython.html
IT WORKS!

But if i try this:

Directory C:\...
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
/Directory

http://www.modpython.org/live/mod_python-3.2.2b/doc-html/tut-pub.html

It don't work!

I Get the following message:

Mod_python error: PythonHandler mod_python.publisher

Traceback (most recent call last):

  File C:\Program
Files\Python24\Lib\site-packages\mod_python\apache.py, line 299, in
HandlerDispatch
result = object(req)

  File C:\Program
Files\Python24\Lib\site-packages\mod_python\publisher.py, line 204, in
handler
module = page_cache[req]

  File C:\Program
Files\Python24\Lib\site-packages\mod_python\cache.py, line 77, in
__getitem__
return self._checkitem(name)[2]

  File C:\Program
Files\Python24\Lib\site-packages\mod_python\cache.py, line 119, in
_checkitem
value = self.build(key, name, opened, entry)

  File C:\Program
Files\Python24\Lib\site-packages\mod_python\publisher.py, line 77, in
build
return ModuleCache.build(self, key, req, opened, entry)

  File C:\Program
Files\Python24\Lib\site-packages\mod_python\cache.py, line 367, in
build
module = new.module(re_not_word.sub('_',key))

AttributeError: 'module' object has no attribute 'module'


HELP?

-- 
http://mail.python.org/mailman/listinfo/python-list


another error in tagging program

2005-10-12 Thread enas khalil
hello all
i have run the following code :# the taggerI interfacefrom nltk.tagger import *from nltk.tokenizer import WhitespaceTokenizerfrom nltk.tokenizer import *from nltk.token import *
# Using UnigramTagger##Before aUnigramTagger can be used to tag data ,it must be trained on training corpus,# it uses this corpus to determine which tags are most common for each word . UnigramTaggers# are trained using the train method which takes a tagged corpus:# tag2.txt is a tagged trainning corpustagged_txt_str=open('tag2.txt').read()tagged_txt_token=Token(TEXT=tagged_txt_str)WhitespaceTokenizer().tokenize(tagged_txt_token)#TaggedTokenizer().tokenize(tagged_txt_token)#Tagger().tokenize(tagged_txt_token)tagger=UnigramTagger()tagger.train(tagged_txt_token) 

and got the following error :
Traceback (most recent call last): File "F:\MSC first Chapters\error correct.py", line 19, in -toplevel- tagger.train(tagged_txt_token) File "C:\Python24\Lib\site-packages\nltk\tagger\__init__.py", line 332, in train tag = subtok[TAG]KeyError: 'TAG' 
please help 
thanks 
enas
		 Yahoo! Music Unlimited - Access over 1 million songs. Try it free.-- 
http://mail.python.org/mailman/listinfo/python-list

Re: [Info] PEP 308 accepted - new conditional expressions

2005-10-12 Thread Chris Smith
 Sebastian == Sebastian Bassi [EMAIL PROTECTED] writes:

Sebastian On 9/30/05, Reinhold Birkenfeld [EMAIL PROTECTED] wrote:
 after Guido's pronouncement yesterday, in one of the next
 versions of Python there will be a conditional expression with
 the following syntax: X if C else Y

Sebastian I don't understand why there is a new expression, if
Sebastian this could be accomplished with:

Sebastian if C: X else: Y

Sebastian What is the advantage with the new expression?

One very frequent use case is building a string.
Instead of:

if X==0:
   filler=yes
else:
   filler=no
return the answer is %s % filler


What I really want to do is take four lines of conditional, and put
them into one, as well as blow off dealing with a 'filler' variable:

return the answer is  + yes if X==0 else no


Or whatever the final release syntax is.
Conditional expressions are a nice way to shim something in place, on
an acute basis.  Chronic use of them could lead to a full-on plate of
spaghetti, where you really wanted code.
They can be impenitrable.  Whenever I'm dealing with them in C/C++, I
always line the ?, the :, and the ; characters vertically, which may
seem a bit excessive in terms of whitespace, but provides a nice
hieroglyph over on the right side of the screen, to make things
obvious.
Best,
Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


wrapping single classes in an extension module

2005-10-12 Thread Stefan Behnel
Hi!

In a project, I'm providing an API that is made up by augmenting XML DOM
elements with tag specific attributes and methods. These actually operate on
the DOM and fulfill the need of making the DOM API more user friendly and
domain specific.

I currently use PyXML/4DOM and I'm considering moving the project to a
different package of XML tools that (in addition to XPath) supports RelaxNG,
XSLT, etc. out-of-the-box. My preferred candidate would be lxml (based on
libxml2, which supports basically all XML standards), but it is backed by
classes written in C, which effectively prohibits my current approach of
sticking methods into objects generated by the parser API (the __slots__ 
problem).

I guess I'd have to go for a more general wrapper for the XML API that
/replaces/ the respective objects (Elements) by my own subclasses whereever
they may occurr, i.e. as return values of various functions, as content of
containers that are being passed around, etc. This looks like a lot of work to
me...

Therefore my question: Can anyone imagine a simpler way of approaching this
problem? My main interest is to extend the API of XML handling by my domain
specific one to make usable through the same objects.

Thanks in advance,
Stefan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need a spider library

2005-10-12 Thread Fredrik Lundh
Laszlo Zsolt Nagy wrote:

 The question: is there a good library for Python for extraction links and 
 images
 out  of (possibly malformed) HTML soucre code?

http://www.crummy.com/software/BeautifulSoup/

/F 



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: bizarro world

2005-10-12 Thread Piet van Oostrum
 Bryan [EMAIL PROTECTED] (B) wrote:

B omg!!! wow!!! after reading this i feel like i just stepped in to some
B bizarro world.  

So why do you have to repeat the whole thing?? I have kill-filed XL, and
now you put the message in my face. Please don't react to this drivel.
-- 
Piet van Oostrum [EMAIL PROTECTED]
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need a spider library

2005-10-12 Thread Laszlo Zsolt Nagy
Fredrik Lundh wrote:

Laszlo Zsolt Nagy wrote:

  

The question: is there a good library for Python for extraction links and 
images
out  of (possibly malformed) HTML soucre code?



http://www.crummy.com/software/BeautifulSoup/
  

Thanks a lot! This is just what I wanted. Why it is not part of the 
standard Python library yet? :-)

-- 
http://mail.python.org/mailman/listinfo/python-list


A Tree class, my $0.02 contribution to the python community.

2005-10-12 Thread Antoon Pardon
Comments are welcome:

  http://www.pardon-sleeuwaegen.be/antoon/avltree.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to(can we ?) pass argument to .py script ?

2005-10-12 Thread billie
It's quite simple. If this usage example can helps you...

### parser
try:
opts, args = getopt.getopt(sys.argv[1:], h, e, p:, [help])
mode = 'reply' # default mode
pwd = ' ' # default pass (blank)
for o, a in opts:
if o == '--help' or o == '-h':
print helper()
os._exit(0)
if o == '-h':
print helper()
os._exit(0)
if o == '-e':
mode = 'echo/reply'
if o == '-p':
pwd = a
if len(args)  3 :
print  ERR: Too much few arguments.\n Type %s -h for help. \
%(sys.argv[0])
os._exit(0)
if len(args)  3:
print \
 ERR: Too much arguments.\n Type -h and \
look example to send argumented commands.
os._exit(0)
except:
print  ERR: Invalid Option.\n Type %s -h for help. \
%(sys.argv[0])
os._exit(0)
### /parser 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need a spider library

2005-10-12 Thread Walter Dörwald
Laszlo Zsolt Nagy wrote:

 [...]
 For example this malformed link:
 
 a href=page.htmlSample link/a
 
 could be converted to:
 
 ['page.html','http://samplesite.current_location/page.html','Samle link']

Your options AFAIK are:
* Beautiful Soup (http://www.crummy.com/software/BeautifulSoup/)
* Various implementations of tidy (uTidyLib, mxTidy)
* XIST (http://www.livinglogic.de/Python/xist)

For XIST code that extracts the above info from a HTML page looks like this:

import sys
from ll import url
from ll.xist import parsers
from ll.xist.ns import html

def links(u):
node = parsers.parseURL(u, tidy=True, base=None)
for x in node//html.a:
   yield str(x[href]), str(u/str(x[href])), unicode(x)

for data in links(url.URL(sys.argv[1])):
print data

This outputs something like:

('http://www.python.org/', 'http://www.python.org/', u'\r\n')
('http://www.python.org/search/', 'http://www.python.org/search/', 
u'Search')
('http://www.python.org/download/', 'http://www.python.org/download/', 
u'Download')
('http://www.python.org/doc/', 'http://www.python.org/doc/', 
u'Documentation')
...

Hope that helps,
Walter Dörwald
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C Extension - return an array of longs or pointer?

2005-10-12 Thread Brandon K
All the veteran programmers out there can correct me, but the way I did 
it in my extension was this:

static PyObject *wrap_doNumberStuff(PyObject* self, PyObject* args)
{
char* in = 0;
char* x = 0;
long* result = 0;
int i = 0;
PyObject* py = PyTuple_New()
int ok = PyArg_ParseTuple(args,ss,in, x);
if(!ok) return NULL;

result = doNumberStuff(in,x):
len = sizeof(result)/sizeof(long)
for(i;i  len; i++)
PyTuple_SET_ITEM(py, i,Py_BuildValue(l,*result[i])
}

Simple enough idea...i'm not quite sure if I've done everything 
correctly with the pointers, but I'm sure you can figure that out, the 
algorithm is simple enough.

 Hi,
I have been posting about writing a C extension for Python...so far,
 so good.  At least for the simple functions that I need to wrap.
 
 Ok, my c function looks like...
 
 MY_NUM *doNumberStuff(const char *in, const char *x) { ... }
 
 MY_NUM is defined as, typedef unsigned long MY_NUM;  (not sure if that
 matters, or can i just create a wrapper which handles longs?)
 
 anyhow..for my wrapper I have this..
 
 static PyObject *wrap_doNumberStuff(PyObject *self, PyObject args) {
 char *in = 0;
 char *x = 0;
 long *result = 0;
 int ok = PyArg_ParseTuple(args, ss, in, x);
 if (!ok) return 0;
 
 result = doNumberStuff(in, x);
 
 return Py_BuildValue(l, result);
 }
 
 ...my question is...in the c code, result is a pointer to an array of
 longs, how can I get the returned result to be a list or something
 similar to an array in Python?
 
 ...I also have a function which returns a character array (denoted by a
 char *)...would it work the same as the previous question?
 
 Thanks!!
 


== Posted via Newsgroups.com - Usenet Access to over 100,000 Newsgroups 
==
Get Anonymous, Uncensored, Access to West and East Coast Server Farms! 
== Highest Retention and Completion Rates! HTTP://WWW.NEWSGROUPS.COM ==


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE dedent/unindent key bindings for non-us keybord?

2005-10-12 Thread Adriaan Renting
You could try using the Qscintilla based Eric3 IDE, it uses Ctrl-i and 
Ctrl-Shift-i. 
 
[EMAIL PROTECTED] 10/02/05 5:52 pm  
|What could be wrong here, and do you have any other suggestions for a 
|dedent key binding that may work on a non-us/swedish keyboard (or 
|maybe an alternative editor for python code). 
| 
|Thanks. 
| 
|
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C Extension - return an array of longs or pointer?

2005-10-12 Thread Brandon K
I'm sorry...I just woke up and forgot my C...must have left it in the 
Coffee...Anyway, i made a few mistakes (can't initialize blank 
tuple...function should return a value, lol).

static PyObject* wrap_doNumberStuff(PyObject* self, PyObject* args)
{
char* in = 0;
char* x = 0;
long* result = 0;
int i = 0;
PyObject* py = NULL;
if(!PyArg_ParseTuple(args,ss,in,x) return NULL;

result = doNumberStuff(in,x);
len = sizeof(result)/sizeof(long);
py = PyTuple_New(len);
for(i; i  len; i++)
PyTuple_SET_ITEM(py, i, Py_BuildValue(l,*result[i]);

return py;
}

Additionally, the Python/C api in the docs tells you all of these nifty 
little abstract layer functions that you can call from your extension.

 All the veteran programmers out there can correct me, but the way I did 
 it in my extension was this:
 
 static PyObject *wrap_doNumberStuff(PyObject* self, PyObject* args)
 {
 char* in = 0;
 char* x = 0;
 long* result = 0;
 int i = 0;
 PyObject* py = PyTuple_New()
 int ok = PyArg_ParseTuple(args,ss,in, x);
 if(!ok) return NULL;
 
 result = doNumberStuff(in,x):
 len = sizeof(result)/sizeof(long)
 for(i;i  len; i++)
 PyTuple_SET_ITEM(py, i,Py_BuildValue(l,*result[i])   
 }
 
 Simple enough idea...i'm not quite sure if I've done everything 
 correctly with the pointers, but I'm sure you can figure that out, the 
 algorithm is simple enough.
 


== Posted via Newsgroups.com - Usenet Access to over 100,000 Newsgroups 
==
Get Anonymous, Uncensored, Access to West and East Coast Server Farms! 
== Highest Retention and Completion Rates! HTTP://WWW.NEWSGROUPS.COM ==


-- 
http://mail.python.org/mailman/listinfo/python-list


C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
static PyObject *wrap_doStuff(PyObject *self, PyObject *args) {
// this will store the result in a Python object
PyObject *finalResult;

// get arguments from Python
char *result = 0;
char *in= 0;
char *aString = 0;
char *bString = 0;
MY_NUM *a;
MY_NUM *b;
int ok = PyArg_ParseTuple(args, sss, in, aString, bString);
if (!ok) return 0;

// do work to get a and b
// count - returns an int;  GetVal - returns a char *
a = GetVal(aString, count(aString, ,));
b = GetVal(bString, count(bString, ,));

// make function call, which returns a char *
result = doStuff(in, a, b);

// save result in Python string
finalResult = PyString_FromString(result);

// free memory
PyMem_Free(result);
PyMem_Free(a);
PyMem_Free(b);

// return the result as a Python string
return finalResult;
}

...from python I can call this function 4 times...works fine.  WHen I
call it for the fifth time python.exe crashes.  im thinking some memory
problem in the wrapper function perhaps...but I am not sure.  The
actually C function, doStuff can be called 5, 6,7...N times without a
problem
so i know its gotta be my wrapper.

Any ideas?  Thanks!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C Extension - return an array of longs or pointer?

2005-10-12 Thread Java and Swing
Interesting...thanks.  Any good tutorials out there, other than the
python doc for ext?


thanks.

Brandon K wrote:
 All the veteran programmers out there can correct me, but the way I did
 it in my extension was this:

 static PyObject *wrap_doNumberStuff(PyObject* self, PyObject* args)
 {
   char* in = 0;
   char* x = 0;
   long* result = 0;
   int i = 0;
   PyObject* py = PyTuple_New()
   int ok = PyArg_ParseTuple(args,ss,in, x);
   if(!ok) return NULL;

   result = doNumberStuff(in,x):
   len = sizeof(result)/sizeof(long)
   for(i;i  len; i++)
   PyTuple_SET_ITEM(py, i,Py_BuildValue(l,*result[i])
 }

 Simple enough idea...i'm not quite sure if I've done everything
 correctly with the pointers, but I'm sure you can figure that out, the
 algorithm is simple enough.

  Hi,
 I have been posting about writing a C extension for Python...so far,
  so good.  At least for the simple functions that I need to wrap.
 
  Ok, my c function looks like...
 
  MY_NUM *doNumberStuff(const char *in, const char *x) { ... }
 
  MY_NUM is defined as, typedef unsigned long MY_NUM;  (not sure if that
  matters, or can i just create a wrapper which handles longs?)
 
  anyhow..for my wrapper I have this..
 
  static PyObject *wrap_doNumberStuff(PyObject *self, PyObject args) {
  char *in = 0;
  char *x = 0;
  long *result = 0;
  int ok = PyArg_ParseTuple(args, ss, in, x);
  if (!ok) return 0;
 
  result = doNumberStuff(in, x);
 
  return Py_BuildValue(l, result);
  }
 
  ...my question is...in the c code, result is a pointer to an array of
  longs, how can I get the returned result to be a list or something
  similar to an array in Python?
 
  ...I also have a function which returns a character array (denoted by a
  char *)...would it work the same as the previous question?
 
  Thanks!!
 


 == Posted via Newsgroups.com - Usenet Access to over 100,000 Newsgroups 
 ==
 Get Anonymous, Uncensored, Access to West and East Coast Server Farms!
 == Highest Retention and Completion Rates! HTTP://WWW.NEWSGROUPS.COM 
 ==

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
update:
if I use C's free(result), free(a) free(b) instead of PyMem_Free...I
only get one successfuly use/call of doStuff.

i.e.
// this works
doStuff(...)

// python crashes here
doStuff(...)

Java and Swing wrote:
 static PyObject *wrap_doStuff(PyObject *self, PyObject *args) {
   // this will store the result in a Python object
   PyObject *finalResult;

   // get arguments from Python
   char *result = 0;
   char *in= 0;
   char *aString = 0;
   char *bString = 0;
   MY_NUM *a;
   MY_NUM *b;
   int ok = PyArg_ParseTuple(args, sss, in, aString, bString);
   if (!ok) return 0;

   // do work to get a and b
   // count - returns an int;  GetVal - returns a char *
   a = GetVal(aString, count(aString, ,));
   b = GetVal(bString, count(bString, ,));

   // make function call, which returns a char *
   result = doStuff(in, a, b);

   // save result in Python string
   finalResult = PyString_FromString(result);

   // free memory
   PyMem_Free(result);
   PyMem_Free(a);
   PyMem_Free(b);

   // return the result as a Python string
   return finalResult;
 }

 ...from python I can call this function 4 times...works fine.  WHen I
 call it for the fifth time python.exe crashes.  im thinking some memory
 problem in the wrapper function perhaps...but I am not sure.  The
 actually C function, doStuff can be called 5, 6,7...N times without a
 problem
 so i know its gotta be my wrapper.
 
 Any ideas?  Thanks!

-- 
http://mail.python.org/mailman/listinfo/python-list


calling matlab

2005-10-12 Thread Mohammed Smadi
Hi;

Does anyone know if we can call matlab for a python or bash script while 
feeding the matlab script some command line arguments?  I have an 
interactive matlab script which i want to automate by feeding the args 
from a script.

I know this is probably more suitable to a matlab group but any ideas will 
be appreciated.

thanks
moe smadi

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting C++ array into Python

2005-10-12 Thread Adriaan Renting
try using SWIG?
You give very little information about how you are trying to accomplish this. 
From your mention of C++ you seem to mean a vector, not an array, I suggest you 
read the documentation of SWIG, and maybe someone can help you if you give a 
clear example of what you are trying to accomplish, how, and why it fails.

Adriaan Renting.  
  
Deshdeep, Singh (IE10) [EMAIL PROTECTED] 10/04/05 7:33 am  

 I am extending C++ application with python. I am not able to convert a C++ 
array in Python.
 
 If anyone has the experience of the below :-   
  1)How to handle the C++ array in the Python code and how to input 
that from the script ?   
 
 Awaiting for the solution   
 
 Regards   
 DD   
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE dedent/unindent key bindings for non-us keybord?

2005-10-12 Thread Franz Steinhaeusler
On Wed, 12 Oct 2005 14:58:18 +0200, Adriaan Renting
[EMAIL PROTECTED] wrote:

You could try using the Qscintilla based Eric3 IDE, it uses Ctrl-i and 
Ctrl-Shift-i. 
 

That is possible.

But what has it to do with the original post?

Apart from that, in Idle you can bind them it to Ctrl-i and Ctrl-Shift-i
also.

-- 
Franz Steinhaeusler
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
one more update...

if I remove PyMem_Free and free(...) ...so no memory clean up...I can
still only call doStuff 4 times, the 5th attemp crashes Python.

Java and Swing wrote:
 update:
 if I use C's free(result), free(a) free(b) instead of PyMem_Free...I
 only get one successfuly use/call of doStuff.

 i.e.
 // this works
 doStuff(...)

 // python crashes here
 doStuff(...)

 Java and Swing wrote:
  static PyObject *wrap_doStuff(PyObject *self, PyObject *args) {
  // this will store the result in a Python object
  PyObject *finalResult;
 
  // get arguments from Python
  char *result = 0;
  char *in= 0;
  char *aString = 0;
  char *bString = 0;
  MY_NUM *a;
  MY_NUM *b;
  int ok = PyArg_ParseTuple(args, sss, in, aString, bString);
  if (!ok) return 0;
 
  // do work to get a and b
  // count - returns an int;  GetVal - returns a char *
  a = GetVal(aString, count(aString, ,));
  b = GetVal(bString, count(bString, ,));
 
  // make function call, which returns a char *
  result = doStuff(in, a, b);
 
  // save result in Python string
  finalResult = PyString_FromString(result);
 
  // free memory
  PyMem_Free(result);
  PyMem_Free(a);
  PyMem_Free(b);
 
  // return the result as a Python string
  return finalResult;
  }
 
  ...from python I can call this function 4 times...works fine.  WHen I
  call it for the fifth time python.exe crashes.  im thinking some memory
  problem in the wrapper function perhaps...but I am not sure.  The
  actually C function, doStuff can be called 5, 6,7...N times without a
  problem
  so i know its gotta be my wrapper.
  
  Any ideas?  Thanks!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Antoon Pardon
Op 2005-10-12, Java and Swing schreef [EMAIL PROTECTED]:
 static PyObject *wrap_doStuff(PyObject *self, PyObject *args) {
   // this will store the result in a Python object
   PyObject *finalResult;

   // get arguments from Python
   char *result = 0;
   char *in= 0;
   char *aString = 0;
   char *bString = 0;
   MY_NUM *a;
   MY_NUM *b;
   int ok = PyArg_ParseTuple(args, sss, in, aString, bString);
   if (!ok) return 0;

   // do work to get a and b
   // count - returns an int;  GetVal - returns a char *
   a = GetVal(aString, count(aString, ,));
   b = GetVal(bString, count(bString, ,));

   // make function call, which returns a char *
   result = doStuff(in, a, b);

   // save result in Python string
   finalResult = PyString_FromString(result);

   // free memory
   PyMem_Free(result);
   PyMem_Free(a);
   PyMem_Free(b);

   // return the result as a Python string
   return finalResult;
 }

 ...from python I can call this function 4 times...works fine.  WHen I
 call it for the fifth time python.exe crashes.  im thinking some memory
 problem in the wrapper function perhaps...but I am not sure.  The
 actually C function, doStuff can be called 5, 6,7...N times without a
 problem
 so i know its gotta be my wrapper.

 Any ideas?  Thanks!

Well assuming your doStuff is a C function that knows nothing of python.
it might be the PyMem_Free(result).
http://docs.python.org/api/memoryInterface.html says the following:

void PyMem_Free(void *p)
Frees the memory block pointed to by p, which must have been
returned by a previous call to PyMem_Malloc() or PyMem_Realloc().
Otherwise, or if PyMem_Free(p) has been called before, undefined
behavior occurs. If p is NULL, no operation is performed.

But your result wasn't allocated by a PyMem_Malloc, it was returned
to you by a C function.

-- 
Antoon Pardon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: searching python/gui developper in germany

2005-10-12 Thread malv
Hans Georg Krauthaeuser wrote:
 Dear all,

 for the measurements in our labs we have developed python scripts that
 are pretty fine for our needs. Basically, we have classes and call the
 appropriate methods from the command line (or by other scripts). So, we
 don't have any GUI.

 Now, an external customer want to use our software and -- as you can
 imagine -- we want a pretty GUI.

 So, we are looking for someone who can develop such a pretty GUI for us
 (of course for money). OS is Windows (XP). We are not fixed to a special
 toolkit -- it just should look nice and do the job.

 Best would be someone from our region (Magdeburg, Germany).

 If someone is interested: contact me by email, please.

 Best regards
 Hans Georg Krauthaeuser
http://www.die-offenbachs.de/detlev/eric3.html
If you run SuSE9.3 or SuSE 10.0, everything is there. Simply install
eric or eric3.
There is also a great gui design utility in the installation.
You'll be going in no time.
malv

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
Antoon,
   I just saw that to.  I updated the code like so...

static PyObject *wrap_doStuff(PyObject *self, PyObject *args) {
// this will store the result in a Python object
PyObject *finalResult;

// get arguments from Python
char *result = 0;
char *in= 0;
char *aString = 0;
char *bString = 0;
MY_NUM *a = (MY_NUM *) PyMem_Malloc((20 * sizeof(MY_NUM) + 1);  //
the array will be 20 long
MY_NUM *b = (MY_NUM *) PyMem_Malloc((20 * sizeof(MY_NUM) + 1); //
the array will be 20 long
int ok = PyArg_ParseTuple(args, sss, in, aString, bString);
if (!ok) return 0;

// do work to get a and b
// count - returns an int;  GetVal - returns a MY_NUM * (a pointer
to a MY_NUM array)
a = GetVal(aString, count(aString, ,));
b = GetVal(bString, count(bString, ,));

// make function call, which returns a char *
result = doStuff(in, a, b);

// save result in Python string
finalResult = PyString_FromString(result);

// free memory
PyMem_Free(a);
PyMem_Free(b);
free(aString);
free(bString);
free(result);

// return the result as a Python string
return finalResult;
  }

..as you can see, i malloc'ed memory, and free'd the memory.  However,
I still have python crashing (after only 3 successful calls to
doStuff).  And yes, doStuff is a plain C function...nothing related to
Python.


Antoon Pardon wrote:
 Op 2005-10-12, Java and Swing schreef [EMAIL PROTECTED]:
  static PyObject *wrap_doStuff(PyObject *self, PyObject *args) {
  // this will store the result in a Python object
  PyObject *finalResult;
 
  // get arguments from Python
  char *result = 0;
  char *in= 0;
  char *aString = 0;
  char *bString = 0;
  MY_NUM *a;
  MY_NUM *b;
  int ok = PyArg_ParseTuple(args, sss, in, aString, bString);
  if (!ok) return 0;
 
  // do work to get a and b
  // count - returns an int;  GetVal - returns a char *
  a = GetVal(aString, count(aString, ,));
  b = GetVal(bString, count(bString, ,));
 
  // make function call, which returns a char *
  result = doStuff(in, a, b);
 
  // save result in Python string
  finalResult = PyString_FromString(result);
 
  // free memory
  PyMem_Free(result);
  PyMem_Free(a);
  PyMem_Free(b);
 
  // return the result as a Python string
  return finalResult;
  }
 
  ...from python I can call this function 4 times...works fine.  WHen I
  call it for the fifth time python.exe crashes.  im thinking some memory
  problem in the wrapper function perhaps...but I am not sure.  The
  actually C function, doStuff can be called 5, 6,7...N times without a
  problem
  so i know its gotta be my wrapper.
 
  Any ideas?  Thanks!

 Well assuming your doStuff is a C function that knows nothing of python.
 it might be the PyMem_Free(result).
 http://docs.python.org/api/memoryInterface.html says the following:

 void PyMem_Free(void *p)
 Frees the memory block pointed to by p, which must have been
 returned by a previous call to PyMem_Malloc() or PyMem_Realloc().
 Otherwise, or if PyMem_Free(p) has been called before, undefined
 behavior occurs. If p is NULL, no operation is performed.

 But your result wasn't allocated by a PyMem_Malloc, it was returned
 to you by a C function.
 
 -- 
 Antoon Pardon

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
Antoon,
   I just saw that to.  I updated the code like so...

static PyObject *wrap_doStuff(PyObject *self, PyObject *args) {
// this will store the result in a Python object
PyObject *finalResult;

// get arguments from Python
char *result = 0;
char *in= 0;
char *aString = 0;
char *bString = 0;
MY_NUM *a = (MY_NUM *) PyMem_Malloc((20 * sizeof(MY_NUM) + 1);  //
the array will be 20 long
MY_NUM *b = (MY_NUM *) PyMem_Malloc((20 * sizeof(MY_NUM) + 1); //
the array will be 20 long
int ok = PyArg_ParseTuple(args, sss, in, aString, bString);
if (!ok) return 0;

// do work to get a and b
// count - returns an int;  GetVal - returns a MY_NUM * (a pointer
to a MY_NUM array)
a = GetVal(aString, count(aString, ,));
b = GetVal(bString, count(bString, ,));

// make function call, which returns a char *
result = doStuff(in, a, b);

// save result in Python string
finalResult = PyString_FromString(result);

// free memory
PyMem_Free(a);
PyMem_Free(b);
free(aString);
free(bString);
free(result);

// return the result as a Python string
return finalResult;
  }

..as you can see, i malloc'ed memory, and free'd the memory.  However,
I still have python crashing (after only 3 successful calls to
doStuff).  And yes, doStuff is a plain C function...nothing related to
Python.


Antoon Pardon wrote:
 Op 2005-10-12, Java and Swing schreef [EMAIL PROTECTED]:
  static PyObject *wrap_doStuff(PyObject *self, PyObject *args) {
  // this will store the result in a Python object
  PyObject *finalResult;
 
  // get arguments from Python
  char *result = 0;
  char *in= 0;
  char *aString = 0;
  char *bString = 0;
  MY_NUM *a;
  MY_NUM *b;
  int ok = PyArg_ParseTuple(args, sss, in, aString, bString);
  if (!ok) return 0;
 
  // do work to get a and b
  // count - returns an int;  GetVal - returns a char *
  a = GetVal(aString, count(aString, ,));
  b = GetVal(bString, count(bString, ,));
 
  // make function call, which returns a char *
  result = doStuff(in, a, b);
 
  // save result in Python string
  finalResult = PyString_FromString(result);
 
  // free memory
  PyMem_Free(result);
  PyMem_Free(a);
  PyMem_Free(b);
 
  // return the result as a Python string
  return finalResult;
  }
 
  ...from python I can call this function 4 times...works fine.  WHen I
  call it for the fifth time python.exe crashes.  im thinking some memory
  problem in the wrapper function perhaps...but I am not sure.  The
  actually C function, doStuff can be called 5, 6,7...N times without a
  problem
  so i know its gotta be my wrapper.
 
  Any ideas?  Thanks!

 Well assuming your doStuff is a C function that knows nothing of python.
 it might be the PyMem_Free(result).
 http://docs.python.org/api/memoryInterface.html says the following:

 void PyMem_Free(void *p)
 Frees the memory block pointed to by p, which must have been
 returned by a previous call to PyMem_Malloc() or PyMem_Realloc().
 Otherwise, or if PyMem_Free(p) has been called before, undefined
 behavior occurs. If p is NULL, no operation is performed.

 But your result wasn't allocated by a PyMem_Malloc, it was returned
 to you by a C function.
 
 -- 
 Antoon Pardon

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A problem while using urllib

2005-10-12 Thread Steve Holden
Johnny Lee wrote:
 Steve Holden wrote:
 
Steve Holden wrote:

Johnny Lee wrote:
[...]

So my conclusion is that there's something in the Cygwin socket module
that causes problems not seen under other platforms.

I couldn't find any obviously-related error in the Python bug tracker,
and I have copied this message to the Cygwin list in case someone there
knows what the problem is.

Before making any kind of bug submission you should really see if you
can build a program shorter that the existing 220+ lines to demonstrate
the bug, but it does look to me like your program should work (as indeed
it does on other platforms).

[...]
 
 
 But if you change urllib2 to urllib, it works under cygwin. Are they
 using different mechanism to connect to the page?
 
I haven't looked into it that deeply. Perhaps you can take a look at the 
library code to see what the differences are?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

-- 
http://mail.python.org/mailman/listinfo/python-list


Very dumb question

2005-10-12 Thread Laszlo Zsolt Nagy
I have a program with this code fragment:

print len(data)
print data[:50]
raise SystemExit

This prints:

20381
!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN

But if I change 50 to 51

print len(data)
print data[:51]
raise SystemExit

then it prints

20381
 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN

After all, only the last 50 bytes are printed. The string is the same 
(length 20381) in both cases.
Surprisingly, I can print more than 50 characters, this works:

print 012345678901234567890123456789012345678901234567890123456789A

I'm sure it is my mistake, but I don't know what am I doing wrong. Do 
you have an idea?
Thanks,

   Les

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
Sorry about the double post...

anyhow, after putting in debug statements I found that it was crashing
when it called, free(result)so I removed the free(result).

now it crashes when it gets to, b = GetVal(bString, count(bString,
,));

..any ideas?

Java and Swing wrote:
 Antoon,
I just saw that to.  I updated the code like so...

 static PyObject *wrap_doStuff(PyObject *self, PyObject *args) {
   // this will store the result in a Python object
   PyObject *finalResult;

   // get arguments from Python
   char *result = 0;
   char *in= 0;
   char *aString = 0;
   char *bString = 0;
   MY_NUM *a = (MY_NUM *) PyMem_Malloc((20 * sizeof(MY_NUM) + 1);  //
 the array will be 20 long
   MY_NUM *b = (MY_NUM *) PyMem_Malloc((20 * sizeof(MY_NUM) + 1); //
 the array will be 20 long
   int ok = PyArg_ParseTuple(args, sss, in, aString, bString);
   if (!ok) return 0;

   // do work to get a and b
   // count - returns an int;  GetVal - returns a MY_NUM * (a pointer
 to a MY_NUM array)
   a = GetVal(aString, count(aString, ,));
   b = GetVal(bString, count(bString, ,));

   // make function call, which returns a char *
   result = doStuff(in, a, b);

   // save result in Python string
   finalResult = PyString_FromString(result);

   // free memory
   PyMem_Free(a);
   PyMem_Free(b);
   free(aString);
   free(bString);
   free(result);

   // return the result as a Python string
   return finalResult;
   }

 ..as you can see, i malloc'ed memory, and free'd the memory.  However,
 I still have python crashing (after only 3 successful calls to
 doStuff).  And yes, doStuff is a plain C function...nothing related to
 Python.


 Antoon Pardon wrote:
  Op 2005-10-12, Java and Swing schreef [EMAIL PROTECTED]:
   static PyObject *wrap_doStuff(PyObject *self, PyObject *args) {
 // this will store the result in a Python object
 PyObject *finalResult;
  
 // get arguments from Python
 char *result = 0;
 char *in= 0;
 char *aString = 0;
 char *bString = 0;
 MY_NUM *a;
 MY_NUM *b;
 int ok = PyArg_ParseTuple(args, sss, in, aString, bString);
 if (!ok) return 0;
  
 // do work to get a and b
 // count - returns an int;  GetVal - returns a char *
 a = GetVal(aString, count(aString, ,));
 b = GetVal(bString, count(bString, ,));
  
 // make function call, which returns a char *
 result = doStuff(in, a, b);
  
 // save result in Python string
 finalResult = PyString_FromString(result);
  
 // free memory
 PyMem_Free(result);
 PyMem_Free(a);
 PyMem_Free(b);
  
 // return the result as a Python string
 return finalResult;
   }
  
   ...from python I can call this function 4 times...works fine.  WHen I
   call it for the fifth time python.exe crashes.  im thinking some memory
   problem in the wrapper function perhaps...but I am not sure.  The
   actually C function, doStuff can be called 5, 6,7...N times without a
   problem
   so i know its gotta be my wrapper.
  
   Any ideas?  Thanks!
 
  Well assuming your doStuff is a C function that knows nothing of python.
  it might be the PyMem_Free(result).
  http://docs.python.org/api/memoryInterface.html says the following:
 
  void PyMem_Free(void *p)
  Frees the memory block pointed to by p, which must have been
  returned by a previous call to PyMem_Malloc() or PyMem_Realloc().
  Otherwise, or if PyMem_Free(p) has been called before, undefined
  behavior occurs. If p is NULL, no operation is performed.
 
  But your result wasn't allocated by a PyMem_Malloc, it was returned
  to you by a C function.
  
  -- 
  Antoon Pardon

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Tree class, my $0.02 contribution to the python community.

2005-10-12 Thread Steve Holden
Antoon Pardon wrote:
 Comments are welcome:
 
   http://www.pardon-sleeuwaegen.be/antoon/avltree.html
Does this type bear any relationship at all to what most people call a 
tree, which is a bifurcated data structure? Or do you call it a tree for 
some other reason?

Sounds like cdict might be a better name ...

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can we save print msg into a file when script running ?

2005-10-12 Thread black
unluckly i am with windows, anyway tks !

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can we save print msg into a file when script running ?

2005-10-12 Thread black
quote:
===
script.py  script.log 21
===

what does 21 mean pls ?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Very dumb question

2005-10-12 Thread Rocco Moretti
Laszlo Zsolt Nagy wrote:
 Laszlo Zsolt Nagy wrote:
 
 I have a program with this code fragment:

print len(data)
print data[:50]
raise SystemExit

 This prints:

 20381
 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN

 But if I change 50 to 51

print len(data)
print data[:51]
raise SystemExit

 then it prints

 20381
 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN

 After all, only the last 50 bytes are printed. The string is the same 
 (length 20381) in both cases.
  

 Hmm, I checked on Windows now and it is working. But it is bad on 
 FreeBSD/Python 2.4.1
 Very strange. len(data[:100]) returns 100, but if I try to print it, 
 only the first 50 characters printed.
 
   Les

Is 'data' a Unicode string, or do you have some terminal control 
charachters in the string? Most printable ASCII charachters are between 
32 and 126. What does this print?:

print [i for (i,c) in enumerate(data) if not (32 = ord(c) = 126)]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Tree class, my $0.02 contribution to the python community.

2005-10-12 Thread dataw0lf
Steve Holden wrote:

 Does this type bear any relationship at all to what most people call a 
 tree, which is a bifurcated data structure? Or do you call it a tree for 
 some other reason?

I'd think that the 'avl' part would answer that question.

!google avl tree

-- 

Joshua Simpson -- dataw0lf.org
Lead Network Administrator/Engineer Aero-Graphics Inc.
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Very dumb question

2005-10-12 Thread bruno modulix
Laszlo Zsolt Nagy wrote:
 I have a program with this code fragment:
 
print len(data)
print data[:50]
raise SystemExit
 
 This prints:
 
 20381
 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN
 
 But if I change 50 to 51
 
print len(data)
print data[:51]
raise SystemExit
 
 then it prints
 
 20381
 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN
 
 After all, only the last 50 bytes are printed. The string is the same
 (length 20381) in both cases.
(snip

 I'm sure it is my mistake, but I don't know what am I doing wrong. Do
 you have an idea?

I assume the code snippets are exact copy/paste so this is not a typo
(like print data[51:] ...) - and I can't reproduce it here... even with
a string of 20381 characters.

mmm...

type(data) ???



-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Very dumb question

2005-10-12 Thread Peter Otten
Laszlo Zsolt Nagy wrote:

 I have a program with this code fragment:
 
 print len(data)
 print data[:50]
 raise SystemExit
 
 This prints:
 
 20381
 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN
 
 But if I change 50 to 51
 
 print len(data)
 print data[:51]
 raise SystemExit
 
 then it prints
 
 20381
 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN

The closest I can get to your situation is

[on linux]
 print abc\rx[:4]
abc
 print abc\rx[:5]
xbc

i. e. a character after a 'carriage return' ('\r') overwrites part of the
string which therefore doesn't seem to grow. Try 

print repr(data[:51]) 

to see what's really in your data string.

Peter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can we save print msg into a file when script running ?

2005-10-12 Thread Peter Otten
black wrote:

 in my .py file there are a few print to trace out some message and i
 wonder if we can save it into a specified file when that script get
 running. if so, i may just check that file to c how the script is
 running. can anyone show me a right direction ?

If you don't feel comfortable with the command line you can stick

import sys
sys.stdout = open(mylogfile.txt, w)

at the beginning of your file.

Peter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
ok, further digging...I found that in the C function GetVal...it is
crashing where I try to malloc some memory. Note, I have no problems
when running this from C..just from Python using my wrapper.

GetVal looks something like..
MY_NUM *GetVal(const char *in, const int x) {
MY_NUM *results, *returnResults;
results = (MY_NUM *) malloc((x * sizeof(MY_NUM) + 1);
returnResults = results;
// ..do more work..
return returnResults;
}

I put in print statements into the C code and found that it is crashing
at the line where I malloc some space for results.

...any ideas why this is crashing when calling from Python via C
wrapper?

Java and Swing wrote:
 Sorry about the double post...

 anyhow, after putting in debug statements I found that it was crashing
 when it called, free(result)so I removed the free(result).

 now it crashes when it gets to, b = GetVal(bString, count(bString,
 ,));

 ..any ideas?

 Java and Swing wrote:
  Antoon,
 I just saw that to.  I updated the code like so...
 
  static PyObject *wrap_doStuff(PyObject *self, PyObject *args) {
  // this will store the result in a Python object
  PyObject *finalResult;
 
  // get arguments from Python
  char *result = 0;
  char *in= 0;
  char *aString = 0;
  char *bString = 0;
  MY_NUM *a = (MY_NUM *) PyMem_Malloc((20 * sizeof(MY_NUM) + 1);  //
  the array will be 20 long
  MY_NUM *b = (MY_NUM *) PyMem_Malloc((20 * sizeof(MY_NUM) + 1); //
  the array will be 20 long
  int ok = PyArg_ParseTuple(args, sss, in, aString, bString);
  if (!ok) return 0;
 
  // do work to get a and b
  // count - returns an int;  GetVal - returns a MY_NUM * (a pointer
  to a MY_NUM array)
  a = GetVal(aString, count(aString, ,));
  b = GetVal(bString, count(bString, ,));
 
  // make function call, which returns a char *
  result = doStuff(in, a, b);
 
  // save result in Python string
  finalResult = PyString_FromString(result);
 
  // free memory
  PyMem_Free(a);
  PyMem_Free(b);
  free(aString);
  free(bString);
  free(result);
 
  // return the result as a Python string
  return finalResult;
}
 
  ..as you can see, i malloc'ed memory, and free'd the memory.  However,
  I still have python crashing (after only 3 successful calls to
  doStuff).  And yes, doStuff is a plain C function...nothing related to
  Python.
 
 
  Antoon Pardon wrote:
   Op 2005-10-12, Java and Swing schreef [EMAIL PROTECTED]:
static PyObject *wrap_doStuff(PyObject *self, PyObject *args) {
// this will store the result in a Python object
PyObject *finalResult;
   
// get arguments from Python
char *result = 0;
char *in= 0;
char *aString = 0;
char *bString = 0;
MY_NUM *a;
MY_NUM *b;
int ok = PyArg_ParseTuple(args, sss, in, aString, bString);
if (!ok) return 0;
   
// do work to get a and b
// count - returns an int;  GetVal - returns a char *
a = GetVal(aString, count(aString, ,));
b = GetVal(bString, count(bString, ,));
   
// make function call, which returns a char *
result = doStuff(in, a, b);
   
// save result in Python string
finalResult = PyString_FromString(result);
   
// free memory
PyMem_Free(result);
PyMem_Free(a);
PyMem_Free(b);
   
// return the result as a Python string
return finalResult;
}
   
...from python I can call this function 4 times...works fine.  WHen I
call it for the fifth time python.exe crashes.  im thinking some memory
problem in the wrapper function perhaps...but I am not sure.  The
actually C function, doStuff can be called 5, 6,7...N times without a
problem
so i know its gotta be my wrapper.
   
Any ideas?  Thanks!
  
   Well assuming your doStuff is a C function that knows nothing of python.
   it might be the PyMem_Free(result).
   http://docs.python.org/api/memoryInterface.html says the following:
  
   void PyMem_Free(void *p)
   Frees the memory block pointed to by p, which must have been
   returned by a previous call to PyMem_Malloc() or PyMem_Realloc().
   Otherwise, or if PyMem_Free(p) has been called before, undefined
   behavior occurs. If p is NULL, no operation is performed.
  
   But your result wasn't allocated by a PyMem_Malloc, it was returned
   to you by a C function.
   
   -- 
   Antoon Pardon

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C Extension - return an array of longs or pointer?

2005-10-12 Thread Bernhard Herzog
Brandon K [EMAIL PROTECTED] writes:

   long* result = 0;
[...]
   result = doNumberStuff(in,x);
   len = sizeof(result)/sizeof(long);

I don't think this will do what you appear to expect it to do.

  Bernhard

-- 
Intevation GmbH http://intevation.de/
Skencil   http://skencil.org/
Thuban  http://thuban.intevation.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can we save print msg into a file when script running ?

2005-10-12 Thread Steve Holden
black wrote:
 quote:
 ===
 script.py  script.log 21
 ===
 
 what does 21 mean pls ?
 
It's Unix shell-speak for send the standard error stream to the same 
place as the standard output. Probably a syntax error on Windows ...

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Very dumb question

2005-10-12 Thread David Stockwell
Indeed,Are you writing a new book?

http://www.amazon.com/exec/obidos/ASIN/1563052857/wildwierdmathpro


David
---
Surf a wave to the future with a free tracfone 
http://cellphone.duneram.com/index.html




From: Laszlo Zsolt Nagy [EMAIL PROTECTED]
To: python-list@python.org
Subject: Very dumb question
Date: Wed, 12 Oct 2005 15:39:29 +0200
I have a program with this code fragment:

 print len(data)
 print data[:50]
 raise SystemExit

This prints:

20381
!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN

But if I change 50 to 51

 print len(data)
 print data[:51]
 raise SystemExit

then it prints

20381
  !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN

After all, only the last 50 bytes are printed. The string is the same
(length 20381) in both cases.
Surprisingly, I can print more than 50 characters, this works:

print 012345678901234567890123456789012345678901234567890123456789A

I'm sure it is my mistake, but I don't know what am I doing wrong. Do
you have an idea?
Thanks,

Les

--
http://mail.python.org/mailman/listinfo/python-list


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Very dumb question

2005-10-12 Thread Laszlo Zsolt Nagy


I assume the code snippets are exact copy/paste so this is not a typo
(like print data[51:] ...) - and I can't reproduce it here... even with
a string of 20381 characters.
  

Yes, they were cut out. type(data) returns 'type str'.
The data was downloaded from a website, it starts with

!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN
http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd;

Even if it had special control characters in it, I do not understand the 
effect (printing only the first 50 chars).
But probably it is an issue with the terminal, since it is working fine 
on Windows.

  Les

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Jargons of Info Tech industry

2005-10-12 Thread Mike Meyer
Casper H.S. Dik [EMAIL PROTECTED] writes:
 Steven D'Aprano [EMAIL PROTECTED] writes:
Can I remind you that spam is approximately 70% of all email traffic these
days? Most of that is blocked by the ISPs, but even so you are obviously
one of the lucky few.

 95% - 99% of all email, not 70% (just ask your ISP).

 A large percentage of the cost of email is the cost of getting
 rid of SPAM; and that cannot happen without colleteral damage in the
 form of lost valid email, not just because of improper filtering but
 also because the more layers are there to touch the email the bigger
 the chances that it does not arrive.

I'd like to take this opportunity to correct myself. I said that I
(and another poster) didn't have a spam problem. That's wrong. We
don't *appear* to have a spam problem, but that's just an
illusion. Our ISPs are spending money - as indicated by Mr. Dik - on
filtering spam. They're also spending money to deal with complaints
about spam from their customers - in both senses of the sentence, and
to pay for the bandwidth the spam is eating up. The bulk providers
they buy their bandwidth from also have higher costs to provide
bandwidth for spam.

These costs are passed on to us. So while we may not have an obvious
spam problem, we have one in the sense that spam takes money from our
pockets.

mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Very dumb question

2005-10-12 Thread Laszlo Zsolt Nagy

i. e. a character after a 'carriage return' ('\r') overwrites part of the
string which therefore doesn't seem to grow. Try 

print repr(data[:51]) 

to see what's really in your data string.
  

Yes, that was it! Thanks for you help. I thought it will be something 
obvious.
The server returned carriage returns in the HTML source code, and I 
tried to print that. :-)

   Les

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Info] PEP 308 accepted - new conditional expressions

2005-10-12 Thread Dave Hansen
On Tue, 11 Oct 2005 01:06:30 -0400, George Sakkis
[EMAIL PROTECTED] wrote:

Dave Hansen [EMAIL PROTECTED] wrote:

 On Mon, 10 Oct 2005 16:42:34 -0500, Terry Hancock
 [EMAIL PROTECTED] wrote:

 On Sunday 09 October 2005 07:50 am, phil hunt wrote:
  On Fri, 7 Oct 2005 01:05:12 -0500, Terry Hancock [EMAIL PROTECTED] 
  wrote:
  GvR's syntax has the advantage of making grammatical sense in English 
  (i.e.
  reading it as written pretty much makes sense).
 
  I know, let's re-write Python to make it more like COBOL! That's
  bound to be a winner!
 
 Whereas the natural order of condition affirmative negative is natural
 for what reason?  That it is so in C?

 And Basic, and Fortran, and Lisp, and just about any programming
 language you care to name, including python (if Condition: Affirmative
 else: Negative).

Block delimiters (curly braces, if/fi, begin/end, etc.) are also in just about 
any language but this
didn't stop python using indentation instead, so what's your point ? 
Conformity and backwards

The point is order of execution.  The condition is tested first, so it
should appear first.  I can think of no other language besides Perl
where that is not the case.  Admittedly, I don't know every other, or
even a large number, of other languages.

compatibility should not be top priorities in language design; fortunately for 
python, they're not.

Conformity I'd agree with, backwards capatibility I strongly disagree.
Breaking existing programs is a Bad Thing(tm).  All the code I wrote
for Python 1.52 still seems to work in 2.4.

Regards,

   -=Dave
-- 
Change is inevitable, progress is not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Make SimpleXMLRPCServer Require Auth?

2005-10-12 Thread John Abel
John Abel wrote:

Hi,

I implemented a SimpleXMLRPCServer, modified it slightly to restrict 
clients based on their IP, but I need to take it a stage further, and 
add user authentication.  I would appreciate any pointers as to how I 
might go about this, or any packages which already provide this.  I'm 
guessing that I'll need to make changes to BaseHTTPServer.

Thanks

J
  

Never mind, managed to modify SimpleXMLRPCServer with code from the 
digest examples in Python sandbox.

J
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Info] PEP 308 accepted - new conditional expressions

2005-10-12 Thread Dave Hansen
On Wed, 12 Oct 2005 13:02:20 +0200, Piet van Oostrum [EMAIL PROTECTED]
wrote:

 Paul Rubin http://[EMAIL PROTECTED] (PR) wrote:

[...]

PR Yeah, if C then A else B is a ancient tradition stretching from
PR Algol-60 to OCAML, and who knows what all else in between.  I'm not
PR sure what Guido saw in the A if C else B syntax but it's not a big deal.

I suspect it is because if C then A else B gives problems in the parser
because it would have difficulty to distinguish this in time from the if
statement. This is because the parser doesn't use a very strong formalism. 

So lose the if.

   R = C then A else B

I don't think python uses the question mark for anything.  Throw that
in, if it makes parsing easier:

   R = C ? then A else B

Regards,

   -=Dave
-- 
Change is inevitable, progress is not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Adding a __filename__ predefined attribute to 2.5?

2005-10-12 Thread Diez B. Roggisch

Rune Strand wrote:
 Excuse me, do you suffer from a bad hair-day? I didn't say it is
 platform independant. It's ok for my use on Linux and Windows. If you
 cannot imagine any other usecase for a __filename__ attribute, that's
 your problem, not mine.

I think you are the one who wants __filename__, not me. So I don't have
to have any usecase for it.

And requesting random features built into the interpreter without even
specifying a usecase  - as remote as it may be - isn't very likely
happen, don't you think? Which I wanted to express with my apparently
misunderstood solve_my_problem()-example.

And if your solution isn't platform-independent and one (several people
actually) provides you with one that is short and concise and no
overhead at all - well, that _could_ trigger a cool, didn't know about
that-reaction. But obviously, it hasn't. 

Diez

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Adding a __filename__ predefined attribute to 2.5?

2005-10-12 Thread Diez B. Roggisch

Diez B. Roggisch wrote:

 And requesting random features built into the interpreter without even
 specifying a usecase  - as remote as it may be - isn't very likely
 happen, don't you think? Which I wanted to express with my apparently
 misunderstood solve_my_problem()-example.

Reread your post - you did specify it. So forget about that. Maybe I
_have_ a bad hair day - even though I'm pretty bald.  Might be because
of too much JAVA these days... *sigh*

Sorry.

Diez

-- 
http://mail.python.org/mailman/listinfo/python-list


Agile Job Opening at Lond Island, NY

2005-10-12 Thread dimus
We are looking for an Agile/XP developer to expand our small team of
programmers (5 members). This is a full time position.

For more information about this posting go to:
http://naples.cc.sunysb.edu/Admin/CampusJob.nsf/af51a98c4c56cd5c85256731006ae132/ed74d7b69bd353428525709200571558?OpenDocument

Candidates may apply online through the link above or send resumes to:
Linda Greenstein
Medical Informatics Department
SUNY 8330
Stony Brook, NY
11794-8330

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: calling matlab

2005-10-12 Thread Robert Kern
Mohammed Smadi wrote:
 Hi;
 
 Does anyone know if we can call matlab for a python or bash script while 
 feeding the matlab script some command line arguments?  I have an 
 interactive matlab script which i want to automate by feeding the args 
 from a script.

Depending on how interactive it is, you should look at the subprocess
module in the stdlib or pexpect.

  http://docs.python.org/lib/module-subprocess.html
  http://pexpect.sourceforge.net/

-- 
Robert Kern
[EMAIL PROTECTED]

In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die.
  -- Richard Harter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can we save print msg into a file when script running ?

2005-10-12 Thread Fredrik Lundh
Steve Holden wrote:

 what does 21 mean pls ?

 It's Unix shell-speak for send the standard error stream to the same
 place as the standard output. Probably a syntax error on Windows ...

 more test.py
import sys
sys.stdout.write(stdout!\n)
sys.stderr.write(stderr!\n)

 python test.py out
stderr!

 python test.py 2out
stdout!

 python test.py out 21
more out
stdout!
stderr!

 ver
Microsoft Windows XP [Version 5.1.2600]

/F 



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Tree class, my $0.02 contribution to the python community.

2005-10-12 Thread George Sakkis
Antoon Pardon [EMAIL PROTECTED] wrote:
 Comments are welcome:

   http://www.pardon-sleeuwaegen.be/antoon/avltree.html

How about adding two shortcut methods, nextkey(k) and prevkey(k), to return the 
next and previous
key respectively ? For instance nextkey would be equivalent to (untested):

def nextkey(self, key):
iter = self[key:]
first = iter.next()
if key not in self: return first
else: return iter.next()

Also for consistency, nextvalue(k), prevvalue(k), nextitem(k), previtem(k) 
would be reasonable
additions.

And a question: what does step do if the keys are not integers since you 
restrict step to be integer
?

George


-- 
http://mail.python.org/mailman/listinfo/python-list


Windows memory pointers in Python?

2005-10-12 Thread Gregory Piñero
Hi guys,

I'm really lost of on this one. How can I turn this (VB?) code
into Python? Basically I call a function exposed from a dll and
it returns me what I believe is a pointer to a location in
memory? Now I need to read that area to get the string I
need. This link has the solution but it is written in VB:
http://www.contactreview.com/mb/showflat.php/Cat/0/Number/15670/an/0/page/14 (it's the third post down)

I have to think Python would have something similiar.
Below is my relevant source code just in case you need that too.

I really appriciate any help anyone might have.
-- Gregory PiñeroChief Innovation OfficerBlended Technologies(www.blendedtechnologies.com)

#---My code: (testing the GOLDMINE API)
from ctypes import *
windll.LoadLibrary('GM6S32.dll')
windll.GM6S32.GMW_LoadBDE('J:\\','J:\\GMBase\\',r'J:\\Common\\','user','pw')
windll.GM6S32.GMW_NV_SetValue(container,AccountNo, (310)555-1212)
#finally, I call a function to see what I stored:
windll.GM6S32.GMW_NV_GetValue(container, AccountNo, '(none)')
#it returns 16236360 
#Now I need to access the string related to this somewhere ...




-- 
http://mail.python.org/mailman/listinfo/python-list

Listen for directory events

2005-10-12 Thread Bell, Kevin
Anyone have any advice on listening for directory events?  

I'd like to fire off my script if new files are added to a directory.
Right now, I've set up my script as a scheduled task (Windows XP) and
when the script is run periodically, it initially looks for new files
and does it's magic if there are some.  I assume I could have python
check for new files then sleep for a bit, and check again.  If I did it
that way, would I run into problems running other py scripts while the
first one was active?  I read about processes being protected from each
other, but didn't really grok it in fullness.

Kev


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Bernhard Herzog
Java and Swing [EMAIL PROTECTED] writes:

 static PyObject *wrap_doStuff(PyObject *self, PyObject *args) {
[...]
   char *aString = 0;
   char *bString = 0;
[...]
   int ok = PyArg_ParseTuple(args, sss, in, aString, bString);
[...]
   free(aString);
   free(bString);

aString and bString are pointers to memory managed by the strings in
your args tuple.  You must not free them!  The memory is automatically
managed by Python.

   Bernhard

-- 
Intevation GmbH http://intevation.de/
Skencil   http://skencil.org/
Thuban  http://thuban.intevation.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting C++ array into Python

2005-10-12 Thread Larry Bates
Like others, without more information on what you have tried we are
just guessing.  Many times I've used the struct.unpack() module to
unpack C arrays into python objects.  Don't know if this will help,
but thought I'd pass it along.  Post some code and we can help more.

-Larry Bates

Adriaan Renting wrote:
 try using SWIG?
 You give very little information about how you are trying to accomplish this. 
 From your mention of C++ you seem to mean a vector, not an array, I suggest 
 you read the documentation of SWIG, and maybe someone can help you if you 
 give a clear example of what you are trying to accomplish, how, and why it 
 fails.
 
 Adriaan Renting.  
   
 
Deshdeep, Singh (IE10) [EMAIL PROTECTED] 10/04/05 7:33 am  
 
 
  I am extending C++ application with python. I am not able to convert a C++ 
 array in Python.
  
  If anyone has the experience of the below :-   
   1)How to handle the C++ array in the Python code and how to 
 input that from the script ?   
  
  Awaiting for the solution   
  
  Regards   
  DD   
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows memory pointers in Python?

2005-10-12 Thread Gregory Piñero
Well, I think I've got it after a bit of research:

c_char_p(address) seems to do the trick. Thus it would be:
ctypes.c_char_p(address)

Of course still let me know if this is somehow WRONG, or if there
is a better way, but this seems good. Thanks again ctypes!
http://starship.python.net/crew/theller/ctypes/
-Greg
On 10/12/05, Gregory Piñero [EMAIL PROTECTED] wrote:
Hi guys,

I'm really lost of on this one. How can I turn this (VB?) code
into Python? Basically I call a function exposed from a dll and
it returns me what I believe is a pointer to a location in
memory? Now I need to read that area to get the string I
need. This link has the solution but it is written in VB:
http://www.contactreview.com/mb/showflat.php/Cat/0/Number/15670/an/0/page/14
 (it's the third post down)

I have to think Python would have something similiar.
Below is my relevant source code just in case you need that too.

I really appriciate any help anyone might have.
-- Gregory PiñeroChief Innovation OfficerBlended Technologies(www.blendedtechnologies.com
)

#---My code: (testing the GOLDMINE API)
from ctypes import *
windll.LoadLibrary('GM6S32.dll')
windll.GM6S32.GMW_LoadBDE('J:\\','J:\\GMBase\\',r'J:\\Common\\','user','pw')
windll.GM6S32.GMW_NV_SetValue(container,AccountNo, (310)555-1212)
#finally, I call a function to see what I stored:
windll.GM6S32.GMW_NV_GetValue(container, AccountNo, '(none)')
#it returns 16236360 
#Now I need to access the string related to this somewhere ...





-- Gregory PiñeroChief Innovation OfficerBlended Technologies(www.blendedtechnologies.com)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Listen for directory events

2005-10-12 Thread Larry Bates
Googling for python watch for directory changes turns these
links:

http://tgolden.sc.sabren.com/python/win32_how_do_i/watch_directory_for_changes.html
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/156178
http://www.amk.ca/python/simple/dirwatch.html

One of those should help you out.

Google is your friend!

Larry Bates


Bell, Kevin wrote:
 Anyone have any advice on listening for directory events?  
 
 I'd like to fire off my script if new files are added to a directory.
 Right now, I've set up my script as a scheduled task (Windows XP) and
 when the script is run periodically, it initially looks for new files
 and does it's magic if there are some.  I assume I could have python
 check for new files then sleep for a bit, and check again.  If I did it
 that way, would I run into problems running other py scripts while the
 first one was active?  I read about processes being protected from each
 other, but didn't really grok it in fullness.
 
 Kev
 
 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
thanks for the tip, however even when I do not free aString or bString,
i'm still crashing at the malloc in the c function, not the wrapper.


Bernhard Herzog wrote:
 Java and Swing [EMAIL PROTECTED] writes:

  static PyObject *wrap_doStuff(PyObject *self, PyObject *args) {
 [...]
char *aString = 0;
  char *bString = 0;
 [...]
  int ok = PyArg_ParseTuple(args, sss, in, aString, bString);
 [...]
  free(aString);
  free(bString);

 aString and bString are pointers to memory managed by the strings in
 your args tuple.  You must not free them!  The memory is automatically
 managed by Python.

Bernhard

 --
 Intevation GmbH http://intevation.de/
 Skencil   http://skencil.org/
 Thuban  http://thuban.intevation.org/

-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Listen for directory events

2005-10-12 Thread Tim Golden
[Bell, Kevin]

| Anyone have any advice on listening for directory events?  

Would this be of any use?

http://tgolden.sc.sabren.com/python/win32_how_do_i/watch_directory_for_changes.html

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Bernhard Herzog
Java and Swing [EMAIL PROTECTED] writes:

 thanks for the tip, however even when I do not free aString or bString,
 i'm still crashing at the malloc in the c function, not the wrapper.

Do you have any more places where you use free incorrectly?  In my
experience, calling free with invalid values can corrupt the data
structures used by the memory allocator in such a way that subsequent
malloc calls crash.

   Bernhard

-- 
Intevation GmbH http://intevation.de/
Skencil   http://skencil.org/
Thuban  http://thuban.intevation.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


slots? SLOTS?

2005-10-12 Thread tin gherdanarra
Dear pythonista,

what is a slot in python? I stumbled over
it in several meta-reflection discussions and
hard-core developer talk, but found no
mention of it in the language reference.

Google coughs up more interesting banter
about it, but no specifics. Is it a feature
that was once planned (for 2.2 or so) and
later abandoned? I find no *new* talk about
it.

Thanks for your attention
Tin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing
As far as my C Wrapper functions are concerned...I no longer have the
need for free(...).  I do use PyMem_Free, for structures I allocated by
using PyMem_New(...).

In my C code I do have things such as...

char *foo(const char *in) {
char *tmp;
tmp = (char *) malloc((strlen(in) * sizeof(char)) + 1);
strcpy(tmp, in);
...
...
free(tmp);
return someValue;
}

Is that appropriate?  I was under the impression that when you malloc
memory, you free it when done.

I also have things like...

char *bar(char *in) {
char *results, *finalResults;
results = (char *) malloc(...);
finalResults = results;

while (...) { *results++ = some_val; }

return finalResults;
}

...is that correct?

As I mentioned earlier, when I run these functions from C I have no
troubles...I can run them 5, 10, 15 times, etc.  From Python, using my
wrapper function is when I have trouble.

Thanks in advance.

Bernhard Herzog wrote:
 Java and Swing [EMAIL PROTECTED] writes:

  thanks for the tip, however even when I do not free aString or bString,
  i'm still crashing at the malloc in the c function, not the wrapper.

 Do you have any more places where you use free incorrectly?  In my
 experience, calling free with invalid values can corrupt the data
 structures used by the memory allocator in such a way that subsequent
 malloc calls crash.

Bernhard

 --
 Intevation GmbH http://intevation.de/
 Skencil   http://skencil.org/
 Thuban  http://thuban.intevation.org/

-- 
http://mail.python.org/mailman/listinfo/python-list


Scope problem with nested functions.

2005-10-12 Thread AddisonN



I'm having trouble resolving a 
scope problem. I have a module, called from another script, with this 
structure:

def parseFile(file, myLocation, 
defaults):
 # 
initialisation.
 
ccyMappings = {}

 def 
getCcyMappings()
 global 
ccyMappings
 # read values into 
ccyMappings.
ccyMappings['CAN'] 
= ['CAD'] # for example.

 def mapCcy(myCcy): if 
ccyMappings.has_key(myCcy): 
return ccyMapping['myCcy'] 
else: return myCcy 


My problem is that, although 
the ccyMappings dictionary is populated within the def getCcyMappings() 
function, the value goes to 'None' when I leave it and so is not available when 
the mapCcy function is called. I've used the global scope declaration 
successfully before, but not with nested functions like this, 
admittedly.

Any assistance gratefully 
received.

Nick.




**
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.
Information Technology International (ITI) +44 (0)20 7315 8500
**


-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python's garbage collection was Re: Python reliability

2005-10-12 Thread Jorgen Grahn
On Mon, 10 Oct 2005 20:37:03 +0100, Tom Anderson [EMAIL PROTECTED] wrote:
 On Mon, 10 Oct 2005, it was written:
...
 There is no way you can avoid making garbage.  Python conses everything, 
 even integers (small positive ones are cached).

 So python doesn't use the old SmallTalk 80 SmallInteger hack, or similar? 

If the SmallInteger hack is something like this, it does:

 a = 42
 b = 42
 a is b
True
 a = 42000
 b = 42000
 a is b
False


... which I guess is what if referred to above as small positive
ones are cached.

/Jorgen

-- 
  // Jorgen Grahn jgrahn@   Ph'nglui mglw'nafh Cthulhu
\X/algonet.se   R'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: slots? SLOTS?

2005-10-12 Thread Simon Brunning
On 12/10/05, tin gherdanarra [EMAIL PROTECTED] wrote:
 what is a slot in python?

http://www.python.org/doc/current/ref/slots.html

--
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Bernhard Herzog
Java and Swing [EMAIL PROTECTED] writes:

 char *foo(const char *in) {
 char *tmp;
 tmp = (char *) malloc((strlen(in) * sizeof(char)) + 1);
 strcpy(tmp, in);
 ...
 ...
 free(tmp);
 return someValue;
 }

 Is that appropriate?  I was under the impression that when you malloc
 memory, you free it when done.

Looks fine.  I hope someValue does not point somewhere into the tmp
buffer, though.

 I also have things like...

 char *bar(char *in) {
 char *results, *finalResults;
 results = (char *) malloc(...);
 finalResults = results;

 while (...) { *results++ = some_val; }

 return finalResults;
 }

Seems OK, too, assuming the results buffer is big enough.

   Bernhard

-- 
Intevation GmbH http://intevation.de/
Skencil   http://skencil.org/
Thuban  http://thuban.intevation.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C Wrapper Function, crashing Python?

2005-10-12 Thread Java and Swing

Bernhard Herzog wrote:
 Java and Swing [EMAIL PROTECTED] writes:

  char *foo(const char *in) {
  char *tmp;
  tmp = (char *) malloc((strlen(in) * sizeof(char)) + 1);
  strcpy(tmp, in);
  ...
  ...
  free(tmp);
  return someValue;
  }
 
  Is that appropriate?  I was under the impression that when you malloc
  memory, you free it when done.

 Looks fine.  I hope someValue does not point somewhere into the tmp
 buffer, though.

  someValue doesn't.


  I also have things like...
 
  char *bar(char *in) {
  char *results, *finalResults;
  results = (char *) malloc(...);
  finalResults = results;
 
  while (...) { *results++ = some_val; }
 
  return finalResults;
  }

 Seems OK, too, assuming the results buffer is big enough.

results = (char *) malloc((sizeof(char) * strlen(in) + 1);
..should be big enough.  At any rate, it works four times in a row
before it fails.

I wonder what else or how else to solve this.  Why is malloc'ing
the memory crashing it!?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Info] PEP 308 accepted - new conditional expressions

2005-10-12 Thread Roy Smith
Chris Smith  [EMAIL PROTECTED] wrote:
What I really want to do is take four lines of conditional, and put
them into one, as well as blow off dealing with a 'filler' variable:

return the answer is  + yes if X==0 else no

I would write this as:

return the answer is  + (yes if X==0 else no)

Adding the parens makes it clearer.  I've long since given up trying
to remember operator precedence (except for the most basic like
multiplication is stronger than addition) and use parens with wild
abandon.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: calling matlab

2005-10-12 Thread hrh1818
There is a module named pymat avvailable from
http://sourceforge.net/projects/pymat that provides a limited set of
functions for intertfacing Python to Matlab. The functions are:
open for opening a Matlab session
close for closing a Matlab session
eval for evaluating a Matlab command
put for sending a matrix to Matlab
get for getting a matrix from Matlab

Mohammed, you might want to look at this module to see if it has the
functionality you need.

Howard

Mohammed Smadi wrote:
 Hi;

 Does anyone know if we can call matlab for a python or bash script while
 feeding the matlab script some command line arguments?  I have an
 interactive matlab script which i want to automate by feeding the args
 from a script.

 I know this is probably more suitable to a matlab group but any ideas will
 be appreciated.
 
 thanks
 moe smadi

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C Extension - return an array of longs or pointer?

2005-10-12 Thread Jorgen Grahn
On 12 Oct 2005 04:46:34 -0700, Java and Swing [EMAIL PROTECTED] wrote:
...
 ...my question is...in the c code, result is a pointer to an array of
 longs, how can I get the returned result to be a list or something
 similar to an array in Python?

RTFM. There are API functions to create an empty list [] and to append
objects to a list. PyList_something(), I think.

 ...I also have a function which returns a character array (denoted by a
 char *)...would it work the same as the previous question?

You might want to return this as a Python string, even if it's just random
octet data garbage. Depends on what that data really represents, but it's a
common idiom, and modules like struct and array expect their data to be
strings. Note that Python strings may contain NUL bytes.

/Jorgen

-- 
  // Jorgen Grahn jgrahn@   Ph'nglui mglw'nafh Cthulhu
\X/algonet.se   R'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >