Packt published an article about xtopdf - creating PDF from Plain Text, DBF, CSV, TDV, and XLS Data

2006-08-19 Thread vasudevram
Hi group,

This is an article I wrote for Packt Publishing -
http://www.packtpub.com :

Using xtopdf, a PDF creation toolkit -
http://www.packtpub.com/article/Using_xtopdf

It shows how to use xtopdf - http://sourceforge.net/projects/xtopdf -
to create PDF from plain text, DBF, CSV, TDV and XLS data.

Use of both command-line and the GUI tools in xtopdf is covered.

xtopdf is written in Python and requires the ReportLab toolkit.

The GUI tools are written in wxPython - http://www.wxpython.org.

Enjoy
Vasudev Ram
~~
Software consulting and training
http://www.dancingbison.com
~~

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

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


Re: Search or compai problem

2006-08-19 Thread Gabriel Genellina

At Saturday 19/8/2006 01:16, [EMAIL PROTECTED] wrote:


it is really lstusers (it is an L not a # 1),   Some of the output from
print lstUsers has the output of None.  I and trying to filter the None
out of the list.  I come from a perl background and this is how I do
thing in perl


None is a unique object used as nothing or no value.
Try reading the Python tutorial, it's easy and you will learn a lot of things.


Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: text editor suggestion?

2006-08-19 Thread John Salerno
BartlebyScrivener wrote:
 John Salerno wrote:
 
 Ok, I know it's been asked a million times, but I have a more specific
 question so hopefully this won't be just the same old post.
 
 You got 65 answers last time :)
 
 http://tinyurl.com/rsfjq
 
 rd
 

Hmm, I forgot all about that. Although I think the few editors I tried 
recently was a result of that thread! I guess none of the suggestions 
worked out for me. Oh well, I'll just keep trying different ones.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: text editor suggestion?

2006-08-19 Thread John Salerno
Ben Finney wrote:

 The two big names in text editing, Vim and Emacs, will both meet these
 criteria easily. They also have the advantage that you'll find one or
 the other, or both, on just about any Unix system intended for use by
 a programmer.

 There is also an enormous amount of support for both these editors,
 for all manner of text editing tasks, available online. It's a good
 idea to learn at least one of them very well, rather than learn a
 bunch of less-popular editors for specific tasks.
 

I'd really like to learn vim, but I spent days just trying to figure out 
how to get the syntax highlighting and indentation working, where these 
settings are and how to edit them, and it still doesn't work for me. It 
just feels so insurmountable that I can't even start working with it yet 
because I don't know how to tailor the settings.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: couple more questions about sqlite

2006-08-19 Thread John Salerno
Dennis Lee Bieber wrote:

   SQLite, in whatever incarnation, is a file server database. There
 is no separate database server running -- each application is linked
 directly to the code that opens and processes the database file(s).
 
   If SQLite is supplied with the impending Python 2.5, then the
 code/library to access the database file is included. If one is running
 Python 2.4, then one needs to obtain the third-party pysqlite package --
 which, as I recall, includes the runtime library that does the database
 file work.
 
   The only reason, then, to download the stand-alone SQLite package
 (not the python package) would be to obtain the command line query/admin
 tool.

Thanks, that was a great response that pretty much covered everything I 
was wondering. I would need pysqlite right now (2.4), or sqlite3 (2.5), 
and I don't necessarily need the command line program if I'm using 
Python as an interface.

What is really confusing is that I did a search for 'sqlite' in my 
Ubuntu repositories and it came up with entries like this:

python2.4-pysqlite1.1   python interface to SQLite 3
python2.4-pysqlite2 python interface to SQLite 3
python2.4-pysqlite  python interface to SQLite 2
python-pysqlite1.1  python interface to SQLite 3
python-pysqlite2python interface to SQLite 3
python-sqlite   python interface to SQlite 2

Needless to say, the numbering had me banging my head against my desk.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: text editor suggestion?

2006-08-19 Thread Ant

John Salerno wrote:

 I'd really like to learn vim, but I spent days just trying to figure out
 how to get the syntax highlighting and indentation working, where these
 settings are and how to edit them, and it still doesn't work for me. It
 just feels so insurmountable that I can't even start working with it yet
 because I don't know how to tailor the settings.

FWIW I started to use vim 2 years ago, and hated every minute of it.
However, it was installed on every unix/linux box I have known, and so
I gradually learned the most common commands. Recently I have been
using gvim on windows, which comes pre-configured to syntax highlight
etc. It isn't very good at running the current buffer as far as I can
tell though, so I still have a command line open currently.

jEdit is also a very good editor with the same sort of feature set as
vim. Bit slower to load, but much more user freindly and a very
powerful editor core. With a few extra plugins (console and Jython
interpreter for example) it has all of the features you want, including
he ability to write macros in python. (Note vim is also customisable
using python).

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


Re: efficient memoize decorator?

2006-08-19 Thread Ziga Seilnacht
[EMAIL PROTECTED] wrote:
 im plugging away at the problems at
 http://www.mathschallenge.net/index.php?section=project
 im trying to use them as a motivator to get into advanced topics in
 python.
 one thing that Structure And Interpretation Of Computer Programs
 teaches is that memoisation is good.
 all of the memoize decorators at the python cookbook seem to make my
 code slower.
 is using a decorator a lazy and inefficient way of doing memoization?
 can anyone point me to where would explain how to do it quickly. or is
 my function at fault?

Your problem is that you are mixing psyco and memoize decorators;
psyco cannot accelerate inner functions that use nested scopes (see
http://psyco.sourceforge.net/psycoguide/unsupported.html ).
You could try using the memoize decorator from:
http://wiki.python.org/moin/PythonDecoratorLibrary ,
which doesn't use functions with closures, or use Fredrik Lundh's
solution which puts memoization directly into the function.

Ziga

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


Re: couple more questions about sqlite

2006-08-19 Thread John Machin

Robert Kern wrote:
 John Machin wrote:
  John Salerno wrote:
  John Machin wrote:
 
  Your confusion is quite understandable. I started looking at sqlite
  when the announcement that it would be included in Python 2.5 came out.
  Puzzlement reigned. I ended up with the following up the front of my
  experimental module:
  So does this mean that when 2.5 is released, all I need is the built-in
  module sqlite3?
 
  Plus the command-line utility, which AFAICT is not included with Python
  2.5.

 Why? The sqlite3 module links to the library; it doesn't need a separate
 executable. Or is that what you meant (since one generally never installs the
 library without also installing the executable, too)?

Hi, Robert,

Sorry if that and the earlier message were unclear. The Python module
does Python DPAPI without any help from the standalone executable.
AFAICT (so far) the standalone executable also links to the library; it
provides a command-line interface to most/all the underlying sqlite
functionality. This is my understanding, but as stated earlier, I
haven't been playing with it for long, and maybe the Python module goes
way beyond DBAPI and I haven't stumbled on the extra goodies yet.

Regards,
John

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


Re: sum and strings

2006-08-19 Thread Bill Pursell

Georg Brandl wrote:
 Paul Rubin wrote:
  Sybren Stuvel [EMAIL PROTECTED] writes:
  Because of there should only be one way to do it, and that way should
  be obvious. There are already the str.join and unicode.join methods,
 
  Those are obvious???

 Why would you try to sum up strings? Besides, the ''.join idiom is quite
 common in Python.

One could extend this argument to dissallow the following:
 foo + bar

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


Re: Documenting a package with Pydoc

2006-08-19 Thread Rob Cowie
Anyone?

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


sending values over classes

2006-08-19 Thread Rafał Janas
Hi,

How to read/write value over different classes (in different files)
Something like global values?

Thanks
Rafał
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: efficient memoize decorator?

2006-08-19 Thread [EMAIL PROTECTED]
thanks, i was not just being lazy. i wanted to play with decorators and
tell people on the forums how cool python is :)
cheers for getting back to me, i could have done that myself i think,
bar the error checking. do you have any links on good practice in
python (i do think i am very lazy re: error checking and would like to
make myself better)

cheers, tom

Fredrik Lundh wrote:

 [EMAIL PROTECTED] wrote:

  all of the memoize decorators at the python cookbook seem to make my
  code slower.

 if you want good performance, use the following pattern:

  def col(n, count, memo={}):
   try:
   return memo[n, count]
  except KeyError:
   # ... calculate value ...
   memo[n, count] = value
  return value

 for some access patterns, the following may be faster:

  def col(n, count, memo={}):
   value = memo.get((n, count))
  if value is None:
   # ... calculate value ...
   memo[n, count] = value
  return value

 to get maximum performance, make the memo dictionary public, and make
 the check at the original call site.

  is using a decorator a lazy and inefficient way of doing memoization?
 
 lazy, yes.  inefficient?  it depends.
 
 /F

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


Re: efficient memoize decorator?

2006-08-19 Thread [EMAIL PROTECTED]
does not seem to work for standalone functions, this is a method
decorator only then?

Traceback (most recent call last):
  File prob14memoize.py, line 94, in ?
length = col(i,1)
  File prob14memoize.py, line 49, in __call__
object = self.cache[args] = self.fn(self.instance, *args)
AttributeError: 'Memoize' object has no attribute 'instance'

cheers, tom


Gabriel Genellina wrote:

 At Friday 18/8/2006 17:14, [EMAIL PROTECTED] wrote:

 sorry
 memoize is
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496879

 This implementation uses cPickle to generate a key from the supplied
 function arguments, which is very slow and defeats the purpose of memoizing.
 In your example -function with no keyword arguments- use the much
 simpler implementation from
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/325205 NOT
 the original recipe but the comment by Chris Spencer titled A
 working example.



 Gabriel Genellina
 Softlab SRL





 __
 Preguntá. Respondé. Descubrí.
 Todo lo que querías saber, y lo que ni imaginabas,
 está en Yahoo! Respuestas (Beta).
 ¡Probalo ya! 
 http://www.yahoo.com.ar/respuestas

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


Re: efficient memoize decorator?

2006-08-19 Thread [EMAIL PROTECTED]
am i correct in thinking that psyco will just not accelerate, rather
than break code it cannot deal with? that has been a pretty standard
import on all my programs
tom


Ziga Seilnacht wrote:

 [EMAIL PROTECTED] wrote:
  im plugging away at the problems at
  http://www.mathschallenge.net/index.php?section=project
  im trying to use them as a motivator to get into advanced topics in
  python.
  one thing that Structure And Interpretation Of Computer Programs
  teaches is that memoisation is good.
  all of the memoize decorators at the python cookbook seem to make my
  code slower.
  is using a decorator a lazy and inefficient way of doing memoization?
  can anyone point me to where would explain how to do it quickly. or is
  my function at fault?

 Your problem is that you are mixing psyco and memoize decorators;
 psyco cannot accelerate inner functions that use nested scopes (see
 http://psyco.sourceforge.net/psycoguide/unsupported.html ).
 You could try using the memoize decorator from:
 http://wiki.python.org/moin/PythonDecoratorLibrary ,
 which doesn't use functions with closures, or use Fredrik Lundh's
 solution which puts memoization directly into the function.
 
 Ziga

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


Small Troll on notation of variables over time

2006-08-19 Thread Hendrik van Rooyen
Hi there,

I can write:

s = 'some string'
then print s[1] will be the string 'o'

and a while later I can write:

s = 'other some string'
then print s[1] will be the string 't'

and then:

s = [1,2,3,4]
then print s[1] will be the number 2

and still later:

s = {1:'boo',2:'foo',3:'shoo'}
when print s[1] will yield the string 'boo'

Now how about introducing an index that works over time,
such that s{0} (the default so as to not break any existing code) 
implies the current object bound to the name s,
with s{1} being the previous one, and so on...

This will mean that s{2}[1] is the string 't'
and s{3}[1] is the string 'o'
while s{4} should be None...

It should be easy to implement this, as all that needs to be done is to 
change the pointer (or whatever) to the object with a stack of them
at the time the binding or rebinding is done...

I first thought of using s{-1} for the previous value but that 
suffers from the regrettable disadvantage that it implies the 
existence of an s{1} - i.e. a future value - and I could not think
of a way to achieve this - so the minus sign adds no information 
and should therefore be left out...

What do you guys think?

- Hendrik

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


Re: text editor suggestion?

2006-08-19 Thread BartlebyScrivener

 Oh well, I'll just keep trying different ones.

If you demand power and cross-platform compatibility, I think you
already know your choices are Xemacs or Vim 7.0. They are both modal
and therefore difficult to learn, at first, but later you enjoy the
pleasures of interface Zen:

http://tinyurl.com/osys2

rd

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


Re: efficient memoize decorator?

2006-08-19 Thread [EMAIL PROTECTED]
I suppose that lesson should not suprise me, programming is a subtle
art that i need spend some time mastering

thanks to all that have replied

tom


Fredrik Lundh wrote:

 Gabriel Genellina wrote:

  This implementation uses cPickle to generate a key from the supplied
  function arguments, which is very slow and defeats the purpose of
  memoizing.

 depends on the cost of recreating an object, of course.  it's a bit
 surprising that so many programmers seem to think that there are one
 size fits all solutions to caching and memoization...
 
 /F

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


How to get the ascii code of Chinese characters?

2006-08-19 Thread many_years_after
Hi,everyone:

 Have you any ideas?

 Say whatever you know about this.


thanks.

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


Re: Text to MP3 using pyTTS - Non-programmer question

2006-08-19 Thread Ravi Teja

[EMAIL PROTECTED] wrote:
 Thanks for the script. Are there any online python intrepreters?

 I'd like to play around with the script. I don't have access to my home
 PC.

You probably will have to wait till you get to yours. There were some
AJAXian ones but I doubt that you will find a free (assuming that you
meant that) online interpreter on a MS Windows box that allows you to
install your modules and give you an FTP or such account to get the
recorded file back.

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


Re: How to get the ascii code of Chinese characters?

2006-08-19 Thread Philippe Martin
many_years_after wrote:

 Hi,everyone:
 
  Have you any ideas?
 
  Say whatever you know about this.
 
 
 thanks.
Hi,

You mean unicode I assume:
http://www.rikai.com/library/kanjitables/kanji_codes.unicode.shtml

Regards,

Philippe

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


Re: text editor suggestion?

2006-08-19 Thread Philippe Martin
John Salerno wrote:

 Ok, I know it's been asked a million times, but I have a more specific
 question so hopefully this won't be just the same old post. I've tried a
 few different editors, and I really like UltraEdit, but it's
 Windows-only and I'm working more on Linux nowadays.
 
 Here are my criteria:
 
 1. syntax highlighting (highly customizable)
 2. auto/smart indenting
 3. ability to run script
 4. light-weight text editor, not an IDE
 5. cross-platform (not really necessary, but nice)
 
 That's pretty much all I need. It's nice when you can customize a bunch
 of other stuff too, but those are the most important.
 
 I've tried vim, but I really don't feel like taking the time to learn
 how to use it, given that I just like to casually program (not to
 mention that I prefer to use the mouse when navigating a document
 sometimes).
 
 I also just started using Scite, and I really like it, except I find its
 syntax highlighting to be very inflexible. You aren't able to define
 your own groups of words -- you have to use what's given, basically. One
 thing I like about UltraEdit is that you simply define as many groups of
 keywords as you want and then assign a style to each one. Scite has a
 very strange and rigid method of highlighting.
 
 So hopefully some of you might have some suggestions. My requirements
 are minimal, but I'm still not happy with the syntax highlighting I'm
 seeing in a lot of editors out there.


Emacs would be my choice.

Philippe

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


Re: Documenting a package with Pydoc

2006-08-19 Thread Gabriel Genellina

At Friday 18/8/2006 11:45, Rob Cowie wrote:


Pydoc seems to be capable of writing documentation for all modules
within a package by simply pointing it to the package on the command
line...

pydoc -w packagename_without_/

Certainly, the method writedocs() appears to descend into a directory
and create docs for each importable object.

Perhaps I'm doing something wrong but when I do this, pydoc reports
that no Python documentation can be found for each of the contents of
the package. Of course, if I point pydoc directly to the modules, it
succeeds.

Am I doing something wrong?


That appears to be a bug. In pydoc.writedocs, when iterating over the 
package directory contents, it uses inspect.getmodulename(path). That 
returns the bare filename (without path nor extension) (is it ok???), 
and later the resolve() function can't load the module because it 
lacks package information.


For simple cases this patch may work: In writedocs, add the following 
line at the beginning:

if pkgpath=='' and ispackage(dir): pkgpath = os.path.basename(dir) + '.'

This works for top level packages located at sys.path, but not for 
packages located elsewhere.


By example, I can generate now the docs for pychart:

python c:\apps\python\lib\pydoc.py -w c:\apps\python\lib\site-packages\pychart



Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: text editor suggestion?

2006-08-19 Thread mystilleef
http://scribes.sourceforge.net/

Flash Demo: http://scribes.sourceforge.net/snippets.htm

GIF Demo: http://www.minds.may.ie/~dez/images/blog/scribes.html

Scribes is simple, slim, sleek and fast. It has no learning curve and
conveys a no nonsense approach to text editing. You won't need to edit
configuration files in lisp, read manuals or sacrifice your unborn
grand daugther to the geek goddesses. It's also written in Python. Some
people have described it as TextMate for Linux.

Version 0.3 will be released in few days and will feature

- remote editing
- a document browser to show all files opened by the editor
- recent files menu
- more steriods...


John Salerno wrote:
 Ok, I know it's been asked a million times, but I have a more specific
 question so hopefully this won't be just the same old post. I've tried a
 few different editors, and I really like UltraEdit, but it's
 Windows-only and I'm working more on Linux nowadays.

 Here are my criteria:

 1. syntax highlighting (highly customizable)
 2. auto/smart indenting
 3. ability to run script
 4. light-weight text editor, not an IDE
 5. cross-platform (not really necessary, but nice)

 That's pretty much all I need. It's nice when you can customize a bunch
 of other stuff too, but those are the most important.

 I've tried vim, but I really don't feel like taking the time to learn
 how to use it, given that I just like to casually program (not to
 mention that I prefer to use the mouse when navigating a document
 sometimes).

 I also just started using Scite, and I really like it, except I find its
 syntax highlighting to be very inflexible. You aren't able to define
 your own groups of words -- you have to use what's given, basically. One
 thing I like about UltraEdit is that you simply define as many groups of
 keywords as you want and then assign a style to each one. Scite has a
 very strange and rigid method of highlighting.

 So hopefully some of you might have some suggestions. My requirements
 are minimal, but I'm still not happy with the syntax highlighting I'm
 seeing in a lot of editors out there.

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


Re: Small Troll on notation of variables over time

2006-08-19 Thread Chris Johnson

Hendrik van Rooyen wrote:
 Hi there,

 I can write:

 s = 'some string'
 then print s[1] will be the string 'o'

 and a while later I can write:

 s = 'other some string'
 then print s[1] will be the string 't'

 and then:

 s = [1,2,3,4]
 then print s[1] will be the number 2

 and still later:

 s = {1:'boo',2:'foo',3:'shoo'}
 when print s[1] will yield the string 'boo'

 Now how about introducing an index that works over time,
 such that s{0} (the default so as to not break any existing code)
 implies the current object bound to the name s,
 with s{1} being the previous one, and so on...

 This will mean that s{2}[1] is the string 't'
 and s{3}[1] is the string 'o'
 while s{4} should be None...

 It should be easy to implement this, as all that needs to be done is to
 change the pointer (or whatever) to the object with a stack of them
 at the time the binding or rebinding is done...

 I first thought of using s{-1} for the previous value but that
 suffers from the regrettable disadvantage that it implies the
 existence of an s{1} - i.e. a future value - and I could not think
 of a way to achieve this - so the minus sign adds no information
 and should therefore be left out...

 What do you guys think?

I think it's pointless. If you want access to more than one of these
variables, don't use the same name.

That and if a symbol is still in scope, then all of its previous values
still have active references, so they won't get deallocated by the
garbage collector, meaning a lot of overhead that most people will not
take advantage of.

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


Re: efficient memoize decorator?

2006-08-19 Thread Gabriel Genellina

At Saturday 19/8/2006 07:58, [EMAIL PROTECTED] wrote:


am i correct in thinking that psyco will just not accelerate, rather
than break code it cannot deal with? that has been a pretty standard
import on all my programs


Don't optimize what doesn't deserve optimization... That's a pretty 
standard mantra.




Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: How to get the ascii code of Chinese characters?

2006-08-19 Thread John Machin
many_years_after wrote:
 Hi,everyone:

  Have you any ideas?

  Say whatever you know about this.


Perhaps you had better explain what you mean by ascii code of Chinese
characters. Chinese characters (hanzi) can be represented in many
ways on a computer, in Unicode as well as many different legacy
encodings, such as GB, GBK, big5, two different 4-digit telegraph
codes, etc etc. They can also be spelled out in roman letters with or
without tone indications (digits or accents) in the pinyin system --
is that what you mean by ascii code?

Perhaps you might like to tell us what you want to do in Python with
hanzi and ascii codes, so that we can give you a specific answer.
With examples, please -- like what are the ascii codes for the two
characters in the common greeting that comes across in toneless pinyin
as ni hao?

Cheers,
John

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


Re: efficient memoize decorator?

2006-08-19 Thread Gabriel Genellina

At Saturday 19/8/2006 07:56, [EMAIL PROTECTED] wrote:


does not seem to work for standalone functions, this is a method
decorator only then?

Traceback (most recent call last):
  File prob14memoize.py, line 94, in ?
length = col(i,1)
  File prob14memoize.py, line 49, in __call__
object = self.cache[args] = self.fn(self.instance, *args)
AttributeError: 'Memoize' object has no attribute 'instance'


For a standalone function, you should remove __del__ and 
self.instance, but I haven't tried it...




Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: Small Troll on notation of variables over time

2006-08-19 Thread John Machin

Hendrik van Rooyen wrote:
[snip]
 What do you guys think?

The subject said it all. You should find some other way of entertaining
yourself on the weekends :-)

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


Re: Small Troll on notation of variables over time

2006-08-19 Thread Gabriel Genellina

At Saturday 19/8/2006 07:49, Hendrik van Rooyen wrote:


Now how about introducing an index that works over time,
such that s{0} (the default so as to not break any existing code)
implies the current object bound to the name s,
with s{1} being the previous one, and so on...


Doing that *always* for *all* names would be ridiculous - objects 
would never get garbage collected, by example. And 
99.% of programs don't need that behavior at all.

So just implement that for your use case - if you have any!



Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: Subprocess quote problem

2006-08-19 Thread Lawrence D'Oliveiro
In message [EMAIL PROTECTED], Adriano
Monteiro wrote:

 Failed to open input file /home/adriano/umit/test/targets for reading
 QUITTING!

Which is not the same as saying:

  Failed to open input file /home/adriano/umit/test/targets for reading
  QUITTING!

Spot the difference?

 command = ['nmap', '-T', 'Aggressive', '-n', '-F', '-iL',
 '/home/adriano/umit/test/targets']

Why exactly where you putting quotes within quotes in the path? That kind of
thing is only necessary when typing things on the shell command line, to
prevent the shell itself misinterpreting things, like putting word breaks
in the wrong places or having wrong behaviours triggered by special
characters.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: couple more questions about sqlite

2006-08-19 Thread Joel Rosdahl
John Salerno [EMAIL PROTECTED] writes:

 What is really confusing is that I did a search for 'sqlite' in my
 Ubuntu repositories and it came up with entries like this:

 python2.4-pysqlite1.1   python interface to SQLite 3
 python2.4-pysqlite2 python interface to SQLite 3
 python2.4-pysqlite  python interface to SQLite 2

That's python2.4-sqlite, not python2.4-pysqlite. The reason for both
having pythonX.Y-foo and python-foo packages is Debian's (and
therefore Ubuntu's) Python package policy.

 python-pysqlite1.1  python interface to SQLite 3
 python-pysqlite2python interface to SQLite 3
 python-sqlite   python interface to SQlite 2

 Needless to say, the numbering had me banging my head against my
 desk.

Sorry to hear that, and I can understand that the names are a bit
confusing.

Here's the story behind the mess:

In the beginning (well, at least in 2003 when I found out about
SQLite), SQLite was up to version 2.something and the Python module
was called sqlite.py. While the Python module *project* was called
pysqlite 0.something, Debian modules were generally called python-foo
when providing the module foo; hence the name python-sqlite.

Then, SQLite 3 was released (incompatible with SQLite 2 databases),
and pysqlite 1.1 was released with the same module name (sqlite.py)
and API as the old sqlite.py module but linked against SQLite 3. I
decided not to package that version but instead wait for pysqlite 2, a
rewritten and improved version linked against SQLite 3 and with a new
Python API.

pysqlite 2 was released and the Python module was called
pysqlite2.dbapi2. I didn't think python-sqlite3 would be a good name
for the Debian package since there were actually two different
pysqlite versions (both actively maintained) linked against SQLite3,
so I ended up calling the package python-pysqlite2, following the name
and version of the pysqlite project instead of the module.

Finally, by request of Debian users, I also packaged the other
pysqlite version linked against SQLite 3 giving the package
python-pysqlite1.1.

Oh, and then there's python-apsw too. :-)

Regards,
Joel (maintainer of Debian's Python-related sqlite packages)

-- 
Joel Rosdahl [EMAIL PROTECTED]
Key BB845E97; fingerprint 9F4B D780 6EF4 5700 778D  8B22 0064 F9FF BB84 5E97
-- 
http://mail.python.org/mailman/listinfo/python-list


write eof without closing

2006-08-19 Thread cage
hello

can i write a eof to a file descriptor without closing it?
like:
fd.write(EOF)
or something

grts,
ruben
-- 
http://mail.python.org/mailman/listinfo/python-list


Zope hosting

2006-08-19 Thread Frank Krugmann
I'am searching a cheap ZPP Hoster.
Some informations?

Greetings
Escorial2000 


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


Re: timezones and time_t

2006-08-19 Thread Eyal Lotem
MrBlueSky wrote:

 Hi,
 I've got a Python application that (as well as lots of other stuff!)
 has to translate time_t values into strings in the TZ of the users
 choice.  Looking at the Python Library Reference, I can see no platform
 independent way of setting the TZ that time.localtime() returns -
 tzset() is marked as only available on Unix and that is indeed the
 case.
 
 Is there really nothing shipped as standard?  I'm using Python 2.4.3
 on Windows XP.
 
 If not, what's the de-facto standard... pytz?
 
 Ta!
 
 John

All of the timezone stuff in the standard C/Python libraries is very badly
named and the use of implicit 'TZ' variables in various functions without a
hint in their __doc__ is also annoying.

Basically, I recommend just doing your own TZ translation:
time.asctime(time.gmtime(time.time() + TZOFFSET))


My name recommendations for alternative time interface (t=float-time_t,
tt=timetuple, local_ prefix=function converts via tz parameters):

time.time - time.gmt
Return the current GMT as a float time_t

time.local_t - time.
Return the current Local Time as a float time_t
If argument is given, convert it to local format.

time.asctime - time.str
Return the given time_t as a string. No conversions done.

time.ctime - time.local_str 
Remove in favor of: time.str(time.local_t)

time.mktime - time.t_of_tt
time.gmtime - time.tt_of_t
time.localtime - Remove in favor of: time.tt_of_t(time.local_t)

These functions above will prevent a lot of confusion, because you are
forced to either use: time.local_t or time.gmt, and thus you are aware of
what the time_t you are using means. When you use time.str no implicit
conversion takes place as in time.ctime, and confusion is avoided.

Do you think this is worth a PEP?

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


Re: write eof without closing

2006-08-19 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], cage wrote:

 can i write a eof to a file descriptor without closing it?
 like:
   fd.write(EOF)
 or something

What do you expect this to to?  Writing a byte to the file and you don't
know which value this byte has?

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: text editor suggestion?

2006-08-19 Thread milosz
Did you try gedit?
It has an options, which you need, I think.
Regards.

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


tkinter btn visual state with tkMessageBox

2006-08-19 Thread jmdeschamps
why is the button sunken when called through a bind method, and not
with the command attribute?
Thank you!


## Cut'nPaste example
from Tkinter import *
import tkMessageBox

class Vue(object):
def __init__(self):
self.root=Tk()
self.root.title(test button visual state)
self.b1=Button(self.root,text=tkMessageBox.showinfo with bind
:-() #,command=self.showMsg)
self.b1.bind(Button,self.showMsg)
self.b2=Button(self.root,text=tkMessageBox.showinfo with
command :-),command=self.showMsg)
self.b1.pack()
self.b2.pack()
self.root.mainloop()
def showMsg(self,evt=1):
if evt==1:
txt=From button with command
else:
txt=From button with bind
tkMessageBox.showinfo(Test of button, txt)

if __name__==__main__:
v=Vue()

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


Re: Questions on unittest behaviour

2006-08-19 Thread Roy Smith
In article [EMAIL PROTECTED],
 Collin Winter [EMAIL PROTECTED] wrote:

 While working on a test suite for unittest these past few weeks, I've
 run across some behaviours that, while not obviously wrong, don't
 strike me as quite right, either. Submitted for your consideration:
 
 1) TestCase.tearDown() is only run if TestCase.setUp() succeeded. It
 seems to me that tearDown() should always be run, regardless of any
 failures in setUp() or the test method itself.

I look at setUp() as a constructor.  It's the constructor's job to either 
completely construct an object, or clean up after itself.  With your 
example:

  def setUp(self)
  lock_file(testfile) # open_socket(), connect_to_database(), etc
 
  something_that_raises_an_exception()
 
  def tearDown(self):
  if file_is_locked(testfile):
  unlock_file(testfile)

It would be cleaner to just do:

def setUp(self):
  lock_file()
  try:
something_that_raises_an_exception()
  except 
unlock_file()
raise

 In this pseudo-code example, the file won't be unlocked if some later
 operation in setUp() raises an exception. I propose that
 TestCase.run() be changed to always run tearDown(), even if setUp()
 raise an exception.

While this might simplify setUp() methods, it complicates tearDown()s, 
because now they can't be sure what environment they're running in.  One 
way or the other, somebody has to deal with exceptions in setUp().  Keeping 
the exception handling code as close to the source of the exception seems 
like the right thing to do.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get the ascii code of Chinese characters?

2006-08-19 Thread Philippe Martin
Philippe Martin wrote:

 many_years_after wrote:
 
 Hi,everyone:
 
  Have you any ideas?
 
  Say whatever you know about this.
 
 
 thanks.
 Hi,
 
 You mean unicode I assume:
 http://www.rikai.com/library/kanjitables/kanji_codes.unicode.shtml
 
 Regards,
 
 Philippe

Hi, 

I have received a personnal email on this:

Kanji is indeed a Japanese subset of the Chinese Character set.

I just thought it would be relevant as it includes ~47000 characters.

If I hurt any feeling, sorry.

Regards,

Philippe

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


Re: Small Troll on notation of variables over time

2006-08-19 Thread Hendrik van Rooyen

 John Machin [EMAIL PROTECTED] wrote:



| 
| Hendrik van Rooyen wrote:
| [snip]
|  What do you guys think?
| 
| The subject said it all. You should find some other way of entertaining
| yourself on the weekends :-)

This is the right answer...

*grin* - well - at least you *were* warned... - Hendrik

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


Re: PyThreadState_Swap(NULL)

2006-08-19 Thread Jack Diederich
On Fri, Aug 18, 2006 at 02:21:40PM -0700, Bryan wrote:

 i've written a program that uses python c api code that lives in a 
 shared library that is loaded by a custom apache module (mod_xxx).  this 
 python c api code all works correctly under our test server and under 
 apache but only if mod_python isn't loaded.  when apache loads 
 mod_python as shown in the http.conf snippet below, 
 PyThreadState_Swap(NULL) in mod_xxx returns NULL.  when the snippet of 
 code in http.conf is commented out, it works again.  what do i have to 
 do to have mod_xxx code work correctly when apache loads mod_python?
 
 
 failure case when apache loads mod_python:
  Py_Initialize() succeeded
  PyThreadState_Swap(NULL) failed
 
 
 sucess case when apache doesn't load mod_python:
  Py_Initialize() succeeded
  PyThreadState_Swap(NULL) succeeded
 

Running multiple python interpreters in the same process isn't supported.
It works OK for most things but some low-level guts are shared between
interpreters so it is possible to run into trouble.

You aren't running multiple interpreters in the same process.  You and
mod_python both think you are in charge and end up nuking each other's 
states. Py_Initialize() resets the global state and shouldn't be called 
more than once.  You can create more than one sub-interpreter (check out
the mod_python source for how, the source is small and readable).

The best thing to do would be to load your module last and conitionally
call Py_Initialize() if someone else hasn't already.

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


Re: How to get the ascii code of Chinese characters?

2006-08-19 Thread many_years_after
hi:

what I want to do is just to make numbers as people input some Chinese
character(hanzi,i mean).The same character will create the same
number.So I think ascii code can do this very well.

John Machin wrote:
 many_years_after wrote:
  Hi,everyone:
 
   Have you any ideas?
 
   Say whatever you know about this.
 

 Perhaps you had better explain what you mean by ascii code of Chinese
 characters. Chinese characters (hanzi) can be represented in many
 ways on a computer, in Unicode as well as many different legacy
 encodings, such as GB, GBK, big5, two different 4-digit telegraph
 codes, etc etc. They can also be spelled out in roman letters with or
 without tone indications (digits or accents) in the pinyin system --
 is that what you mean by ascii code?

 Perhaps you might like to tell us what you want to do in Python with
 hanzi and ascii codes, so that we can give you a specific answer.
 With examples, please -- like what are the ascii codes for the two
 characters in the common greeting that comes across in toneless pinyin
 as ni hao?
 
 Cheers,
 John

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


Re: how do you get the name of a dictionary?

2006-08-19 Thread Duncan Booth
Tim Chase wrote:

  [name for name in dir() if id(eval(name)) == id(banana)]
 ['banana', 'spatula']
 

Please, if you are going to do something like this, then please at least 
use the 'is' operator. Using id(expr1)==id(expr2) is just plain stupid: it 
will actually work in this case, but as soon as you get into a mindset of 
testing for the same object by comparing object ids you are going to shoot 
yourself in the foot.

The first of the following tests returns True, which looks sensible at 
first glance (even though it shouldn't), but what of the second one?

 class C:
def method1(self): pass
def method2(self): pass


 inst = C()
 id(inst.method1)==id(inst.method1)
True
 id(inst.method1)==id(inst.method2)
True

Much better to use 'is' and get consistent results

 inst.method1 is inst.method1
False

(In case I didn't make it clear, the problem in general with comparing the 
result of calling 'id' is that as soon as the first call to id returns, any 
object created when evaluating its parameter can be freed, so the second 
call to id can reuse memory and get the same answer even though the objects 
are different.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: write eof without closing

2006-08-19 Thread Grant Edwards
On 2006-08-19, cage [EMAIL PROTECTED] wrote:

 can i write a eof to a file descriptor without closing it?

No.  Not on Windows, OS-X, or Unix.  There is no such thing as
an eof.

On CP/M Ctrl-Z is used as EOF for text files.

-- 
Grant Edwards
[EMAIL PROTECTED]

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


=?utf-8?Q?Re:_Packt_published_an_article_about_xtopdf_=2D_creating_PDF_from_Plain=0A=09Text, _DBF, _CSV, _TDV, _and_XLS_Data?=

2006-08-19 Thread david_wahler
I'll be out of the office until approximately August 20th. If you have any 
questions, please email [EMAIL PROTECTED]

-- David Wahler


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


Re: Zope 3.3.0 beta 2 released!

2006-08-19 Thread david_wahler
I'll be out of the office until approximately August 20th. If you have any 
questions, please email [EMAIL PROTECTED]

-- David Wahler


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


Packt published an article about xtopdf - creating PDF from Plain Text, DBF, CSV, TDV, and XLS Data

2006-08-19 Thread vasudevram
Hi group,

This is an article I wrote for Packt Publishing -
http://www.packtpub.com :

Using xtopdf, a PDF creation toolkit -
http://www.packtpub.com/article/Using_xtopdf

It shows how to use xtopdf - http://sourceforge.net/projects/xtopdf -
to create PDF from plain text, DBF, CSV, TDV and XLS data.

Use of both command-line and the GUI tools in xtopdf is covered.

xtopdf is written in Python and requires the ReportLab toolkit.

The GUI tools are written in wxPython - http://www.wxpython.org.

Enjoy
Vasudev Ram
~~
Software consulting and training
http://www.dancingbison.com
~~

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


Re: write eof without closing

2006-08-19 Thread cage
Marc 'BlackJack' Rintsch schreef:
 In [EMAIL PROTECTED], cage wrote:
 
 can i write a eof to a file descriptor without closing it?
 like:
  fd.write(EOF)
 or something
 
 What do you expect this to to?  Writing a byte to the file and you don't
 know which value this byte has?
 
 Ciao,
   Marc 'BlackJack' Rintsch

ok let me explain this a bit more...
I want to use a program that has a 'pipe' mode, in which you can use 
stdin to send commands to the program. I found out that, when in pipe 
mode and you are using the keyboard as input source you can do Ctrl-D to 
'signal' the program that you have finished typing your command. The 
program parses and then performs the command, and it doesn't quit. It 
quits after 'Quit\n' + Ctrl-D
Now I want a python script to provide the input, how do i do that? I now 
use popen to be able to write to the program's stdin (p_stdin)
I noticed that when i do a p_stdin.close() it acts as a 'ctrl-d' in that 
the program recognizes the signal to process the command, but then I 
cannot use p_stdin anymore to do p_stdin.write(...)

grts,
ruben
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get the ascii code of Chinese characters?

2006-08-19 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED],
many_years_after wrote:

 what I want to do is just to make numbers as people input some Chinese
 character(hanzi,i mean).The same character will create the same
 number.So I think ascii code can do this very well.

No it can't.  ASCII doesn't contain Chinese characters. 

http://en.wikipedia.org/wiki/ASCII

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: write eof without closing

2006-08-19 Thread Tim Chase
 can i write a eof to a file descriptor without closing it?
 
 No.  Not on Windows, OS-X, or Unix.  There is no such thing as
 an eof.
 
 On CP/M Ctrl-Z is used as EOF for text files.

Common Dos/Window convention also uses ctrl+Z (0x1a) for EOF.

c:\ copy con test.txt
hello
^Z
c:\

*nix usually uses ctrl+D (0x04) as an EOF signal...and OS-X being 
Unixish also uses the same.

bash$ cat  test.txt
hello
^D
bash$

Don't know about Macs earlier than OS-X.

I don't know if there are problems (triggering an actual EOF and 
closing the file) writing either of these ascii characters in 
ascii/text mode (may vary between platforms?), but there are no 
problems writing either of these characters in binary mode.

-tkc



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


Re: tkinter btn visual state with tkMessageBox

2006-08-19 Thread Hendrik van Rooyen

 [EMAIL PROTECTED] wrote:

To: python-list@python.org


| why is the button sunken when called through a bind method, and not
| with the command attribute?
| Thank you!
|
|
| ## Cut'nPaste example
| from Tkinter import *
| import tkMessageBox
|
| class Vue(object):
| def __init__(self):
| self.root=Tk()
| self.root.title(test button visual state)
| self.b1=Button(self.root,text=tkMessageBox.showinfo with bind
| :-() #,command=self.showMsg)
| self.b1.bind(Button,self.showMsg)

8---

change this to :

   self.b1.bind(ButtonRelease,self.showMsg)

Problem is that a button sinks in when you press it and springs back when
you release it...

and the Button leaves it sunken - because when you release, the control is
no longer there

- Hendrik




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


Re: PyThreadState_Swap(NULL)

2006-08-19 Thread Bryan
Jack Diederich wrote:
 On Fri, Aug 18, 2006 at 02:21:40PM -0700, Bryan wrote:
 i've written a program that uses python c api code that lives in a 
 shared library that is loaded by a custom apache module (mod_xxx).  this 
 python c api code all works correctly under our test server and under 
 apache but only if mod_python isn't loaded.  when apache loads 
 mod_python as shown in the http.conf snippet below, 
 PyThreadState_Swap(NULL) in mod_xxx returns NULL.  when the snippet of 
 code in http.conf is commented out, it works again.  what do i have to 
 do to have mod_xxx code work correctly when apache loads mod_python?


 failure case when apache loads mod_python:
  Py_Initialize() succeeded
  PyThreadState_Swap(NULL) failed


 sucess case when apache doesn't load mod_python:
  Py_Initialize() succeeded
  PyThreadState_Swap(NULL) succeeded

 
 Running multiple python interpreters in the same process isn't supported.
 It works OK for most things but some low-level guts are shared between
 interpreters so it is possible to run into trouble.
 
 You aren't running multiple interpreters in the same process.  You and
 mod_python both think you are in charge and end up nuking each other's 
 states. Py_Initialize() resets the global state and shouldn't be called 
 more than once.  You can create more than one sub-interpreter (check out
 the mod_python source for how, the source is small and readable).
 
 The best thing to do would be to load your module last and conitionally
 call Py_Initialize() if someone else hasn't already.
 
 -Jack


thanks for replying jack. i tested what you suggested.

i put our module after mod_python, commented out Py_Initialize(), and 
Py_IsInitialized() returned True, but PyThreadState_Swap() failed.

i put our module before mod_python, called Py_Initialize(), and 
Py_IsInitialized() returned True, but PyThreadState_Swap() failed.

i removed mod_python and our module succeeded.

i even tested combinations of calling and PyEval_InitThreads() but didn't work 
either.


bryan

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


Re: write eof without closing

2006-08-19 Thread Lars
cage wrote:
 I want to use a program that has a 'pipe' mode, in which you can use 
 stdin to send commands to the program. I found out that, when in pipe 
 mode and you are using the keyboard as input source you can do Ctrl-D to 
 'signal' the program that you have finished typing your command. The 
 program parses and then performs the command, and it doesn't quit. It 
 quits after 'Quit\n' + Ctrl-D
 Now I want a python script to provide the input, how do i do that? I now 
 use popen to be able to write to the program's stdin (p_stdin)
 I noticed that when i do a p_stdin.close() it acts as a 'ctrl-d' in that 
 the program recognizes the signal to process the command, but then I 
 cannot use p_stdin anymore to do p_stdin.write(...)

You might want to check the pty module in the Standard Library, and/or 
Pexpect (http://pexpect.sf.net/)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: write eof without closing

2006-08-19 Thread Diez B. Roggisch
cage schrieb:
 Marc 'BlackJack' Rintsch schreef:
 In [EMAIL PROTECTED], cage wrote:

 can i write a eof to a file descriptor without closing it?
 like:
 fd.write(EOF)
 or something

 What do you expect this to to?  Writing a byte to the file and you don't
 know which value this byte has?

 Ciao,
 Marc 'BlackJack' Rintsch
 
 ok let me explain this a bit more...
 I want to use a program that has a 'pipe' mode, in which you can use 
 stdin to send commands to the program. I found out that, when in pipe 
 mode and you are using the keyboard as input source you can do Ctrl-D to 
 'signal' the program that you have finished typing your command. The 
 program parses and then performs the command, and it doesn't quit. It 
 quits after 'Quit\n' + Ctrl-D
 Now I want a python script to provide the input, how do i do that? I now 
 use popen to be able to write to the program's stdin (p_stdin)
 I noticed that when i do a p_stdin.close() it acts as a 'ctrl-d' in that 
 the program recognizes the signal to process the command, but then I 
 cannot use p_stdin anymore to do p_stdin.write(...)

According to wikipedia (german version, but I bet you can get that info 
using the english one, too) C-d sends EOT - end of transmission. Which 
is ascii 0x04.

So I suggest you try writing

\x04

to the pipe. Maybe that works.

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


Re: write eof without closing

2006-08-19 Thread cwarren89
Writing the binary value for ^D into the stream will not do anything.
That value signals the shell to close the stream, as such it only has
significance when you're typing something into the shell.

To the OP: writing an EOF to a stream without closing it makes no
sense. EOF means just that--end of file. Once the program reaches an
EOF, it can't read any more values from the stream, so keeping it open
to write more stuff into it wouldn't even work.

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


[ANN] clnum-1.3 Class Library For Numbers Python Binding

2006-08-19 Thread Raymond L. Buvel
The clnum package adds rational numbers and arbitrary precision floating
point numbers in real and complex form to Python. Also provides
arbitrary precision floating point replacements for the functions in the
math and cmath standard library modules.

Home page: http://calcrpnpy.sourceforge.net/clnum.html

Changes in 1.3

* Added combinatorial functions.

* Improved the performance of converting very large Python longs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: write eof without closing

2006-08-19 Thread cwarren89
Actually, nevermind. It appears that receiving an EOF from a stream
tells it when to stop 'reading', not necessarily that the stream is
closed. What a weird behavior.

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


how to use python com server in c++?

2006-08-19 Thread Leo Jay
dear all,
i have a python com server like this:

import win32com.server.register

class HelloWorld:
_reg_clsid_ = {B0EB5AAB-0465-4D54-9CF9-04ADF7F73E4E}
_reg_desc_  = 'Python test com server'
_reg_progid_= Leojay.ComServer
_public_methods_= ['Add', 'Mul']

def Add(self, a, b):
return a+b
def Mul(self, a, b):
return a*b


if __name__ == '__main__':
win32com.server.register.UseCommandLine(HelloWorld)


after registering the com server, i can use it in visual basic .net:
Dim a As Integer = 5
Dim b As Integer = 8
Dim h As Object = CreateObject(Leojay.ComServer)
MsgBox(h.Add(a, b).ToString() +   + h.Mul(a, b).ToString())

but i don't know how to use it in visual c++.

who has any idea about using this com server in viusal c++?
a detailed sample of early binding would be better, thanks.



-- 
Best Regards,
Leo Jay
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] ratfun-2.3 Polynomials and Rational Functions

2006-08-19 Thread Raymond L. Buvel
The ratfun module provides classes for defining polynomial and rational
function (ratio of two polynomials) objects. These objects can be used
in arithmetic expressions and evaluated at a particular point.

Home page:  http://calcrpnpy.sourceforge.net/ratfun.html

Note: If you are using rpncalc-1.2 or later, this module is already
included.  This release is for folks who don't want rpncalc.

Changes in 2.3

* Update the included clnum package.

* Improved the formatting of the string representation of a polynomial.

* Polynomial and rational function evaluation now works with array inputs.
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] rpncalc-2.4 RPN Calculator for Python

2006-08-19 Thread Raymond L. Buvel
The rpncalc package adds an interactive Reverse Polish Notation (RPN)
interpreter to Python.  This interpreter allows the use of Python as
an RPN calculator.  You can easily switch between the RPN interpreter
and the standard Python interpreter.

Home page:  http://calcrpnpy.sourceforge.net/

Changes in 2.4

* Update the included clnum package.

* Added combinatorial functions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get the ascii code of Chinese characters?

2006-08-19 Thread Thorsten Kampe
* many_years_after (2006-08-19 12:18 +0100)
 Hi,everyone:
 
  Have you any ideas?
 
  Say whatever you know about this.

contradictio in adiecto
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: text editor suggestion?

2006-08-19 Thread Thorsten Kampe
* John Salerno (2006-08-19 02:20 +0100)
 Ok, I know it's been asked a million times, but I have a more specific 
 question so hopefully this won't be just the same old post. I've tried a 
 few different editors, and I really like UltraEdit, but it's 
 Windows-only and I'm working more on Linux nowadays.
 
 Here are my criteria:
 
 1. syntax highlighting (highly customizable)
 2. auto/smart indenting
 3. ability to run script
 4. light-weight text editor, not an IDE
 5. cross-platform (not really necessary, but nice)

EditPad Pro - runs perfectly under Wine

http://www.editpadpro.com/convenience.html
http://www.editpadpro.com/wine.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyThreadState_Swap(NULL)

2006-08-19 Thread Jack Diederich
On Sat, Aug 19, 2006 at 09:08:21AM -0700, Bryan wrote:
 Jack Diederich wrote:
  On Fri, Aug 18, 2006 at 02:21:40PM -0700, Bryan wrote:
  i've written a program that uses python c api code that lives in a 
  shared library that is loaded by a custom apache module (mod_xxx).  this 
  python c api code all works correctly under our test server and under 
  apache but only if mod_python isn't loaded.  when apache loads 
  mod_python as shown in the http.conf snippet below, 
  PyThreadState_Swap(NULL) in mod_xxx returns NULL.  when the snippet of 
  code in http.conf is commented out, it works again.  what do i have to 
  do to have mod_xxx code work correctly when apache loads mod_python?
 
 
  failure case when apache loads mod_python:
   Py_Initialize() succeeded
   PyThreadState_Swap(NULL) failed
 
 
  sucess case when apache doesn't load mod_python:
   Py_Initialize() succeeded
   PyThreadState_Swap(NULL) succeeded
 
  
  Running multiple python interpreters in the same process isn't supported.
  It works OK for most things but some low-level guts are shared between
  interpreters so it is possible to run into trouble.
  
  You aren't running multiple interpreters in the same process.  You and
  mod_python both think you are in charge and end up nuking each other's 
  states. Py_Initialize() resets the global state and shouldn't be called 
  more than once.  You can create more than one sub-interpreter (check out
  the mod_python source for how, the source is small and readable).
  
  The best thing to do would be to load your module last and conitionally
  call Py_Initialize() if someone else hasn't already.
  
  -Jack
 
 
 thanks for replying jack. i tested what you suggested.
 
 i put our module after mod_python, commented out Py_Initialize(), and 
 Py_IsInitialized() returned True, but PyThreadState_Swap() failed.
 
 i put our module before mod_python, called Py_Initialize(), and 
 Py_IsInitialized() returned True, but PyThreadState_Swap() failed.
 
 i removed mod_python and our module succeeded.
 
 i even tested combinations of calling and PyEval_InitThreads() but didn't 
 work 
 either.

I'm out of my depth here, I only know that this kind of thing is tricky.
I think you need to explicitly spawn a new sub-interpreter or at least a new
thread state from the existing interpreter.   Your best bet is to ask on the
mod_python mailing list.  Those guys actually do this kind of thing so if you
are going to get good advice it will be from them.

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


Re: write eof without closing

2006-08-19 Thread Philippe Martin
cage wrote:

 hello
 
 can i write a eof to a file descriptor without closing it?
 like:
 fd.write(EOF)
 or something
 
 grts,
 ruben

No but there is an EOF to the file anyway, even if it is open.

I recall under MS-DOS, you could create a file of size N without writing to
it (some INT21 or 9 ? call to modify the FAT) ... not really possible
anymore.

Philippe


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


Re: How to get the ascii code of Chinese characters?

2006-08-19 Thread Gerhard Fiedler
On 2006-08-19 12:42:31, Marc 'BlackJack' Rintsch wrote:

 many_years_after wrote:
 
 what I want to do is just to make numbers as people input some Chinese
 character(hanzi,i mean).The same character will create the same
 number.So I think ascii code can do this very well.
 
 No it can't.  ASCII doesn't contain Chinese characters. 

Well, ASCII can represent the Unicode numerically -- if that is what the OP
wants. For example, U+81EC (all ASCII) is one possible -- not very
readable though g -- representation of a Hanzi character (see
http://www.cojak.org/index.php?function=code_lookupterm=81EC).

(I don't know anything about Hanzi or Mandarin... But that's Unicode, so
this works :)

Gerhard

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


Re: sending values over classes

2006-08-19 Thread Rob Wolfe
Rafał Janas [EMAIL PROTECTED] writes:

 Hi,

 How to read/write value over different classes (in different files)
 Something like global values?

You need to be more specific about what exactly you're trying
to accomplish. Some code whould be great.

Maybe import statement is what you're looking for. You can import
a class from another module (file) to current module (file) and use it.

BTW on pl.comp.lang.python you can meet helpful people too :)

-- 
HTH,
Rob
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Optimizing Inner Loop Copy

2006-08-19 Thread danielx
Mark E. Fenner wrote:
 Paul McGuire wrote:

  Mark E. Fenner [EMAIL PROTECTED] wrote in message
  news:[EMAIL PROTECTED]
  Hello all,
 
  snip
 
  Here's my class of the objects being copied:
 
  class Rule(list):
  def __init__(self, lhs=None, rhs=None, nClasses=0, nCases=0):
  self.nClasses = nClasses
  self.nCases = nCases
 
  Ok, so here are some bigger picture kind of questions.
 
  1. Do you need to construct all these Rule objects in the first place?

 Sorry, I had a nice response written out ... and I lost it.  Here's the
 summary.  Unfortunately, yes, the algorithm this code implements goes to
 great lengths to ensure that each possible Rule is generated only once.

 
  2. More of an OO question than a performance question, but why does Rule
  inherit from list in the first place?  Is Rule *really* a list, or is it
  just implemented using a list?

 It is the later.  And it is a moderate abuse to say that the Rule _isa_
 list.  Aside from the two integer statistics (nClasses, nCounts), the RHS
 and LHS can be merged and we can say that the rule is [(tuple1), ...,
 (tupleN), (tupleRHS)] with the RHS being Rule[-1].  However, in that case,
 I went for OO principles and kept the two logical parts separate.

 B/c of the frequency of list operations, it's better to be able to use
 thisRule.append() or thisRule[i] then thisRule.lhs.append() or
 thisRule.lhs[i].  Where speed doesn't matter, I have the more appropriate
 thisRule.addLHS().

 Yes, I could do dot removal (i.e., localize the attribute lookups), but
 when we iterate over a whole set of Rules, this still leave the
 localization assignment inside an inner loop.

Then maybe you can assign an unbound method (eg, append =
list.append), then pass in your instance as the first argument (eg
append( myList, newElement )). Even if you localize a bound method,
it should save some time, no?


  If the latter, then you might look at
  moving Rule's list contents into an instance variable, maybe something
  called
  self.contents.  Then you can be more explicit about appending to
  self.contents when you want to add lhs to the contents of the Rule.  For
  example, why are you calling extend, instead of just using slice notation
  to
  copy lhs?  Ah, because then you would have to write something like self =
  lhs[:], which doesn't look like it will work very well.  On the other
  hand, if you use containment/delegation instead of inheritance, you can
  use the
  more explicit self.contents = lhs[:].  In fact now you have much more
  control over the assemblage of rules from other rules.
 

 Fortunately, the Rules are only assembled in one way ... appending to that
 copy that started the thread.  Incidentally, by speeding up Rule.__init__
 and inlining it (instead of calling Rule.copy which called Rule.__init__),
 that is no longer my bottleneck *phew*.


  In the original post, you state: the left hand side of a rule (e.g., a
  rule is a  b  c - d) is self and three other pieces of information are
  kept around, two ints and a right hand side
 
  What other aspects of list are you using in Rule?  Are you iterating over
  its contents somewhere?  Then implement __iter__ and return
  iter(self.contents).  Are you using if rule1: and implicitly testing if
  its length is nonzero?  Then implement __nonzero__ and return
  operator.truth(self.contents).  Do you want to build up rules
  incrementally
  using += operator?  Then implement __iadd__ and do
  self.contents.extend(other.contents), or self.contents +=
  other.contents[:] (no need to test for None-ness of other.contents, we
  ensure in our constructor that self.contents is always a list, even if its
  an empty one).
 

 Well, I do several of these things ... many of them inside inner loops
 (there's a sequence of inner loops ... the algorithms choice, not mine).
 Each of these that are implemented (and not left to Python's builtin list
 methods), is an extra level of function call overhead.  This has been a
 secondary project for me over a number of years ... so I have to look at my
 early revisions, but I think my original architecture was an explicit
 self.lhs = [] attribute.  And it was REALLY slow.  When Python allowed
 inheritence from builtin objects, I tried it and got a nice win (I think!).

  Save inheritance for the true is-a relationships among your problem
  domain
  classes.  For instance, define a base Rule class, and then you can extend
  it with things like DeterministicRule, ProbabilisticRule, ArbitraryRule,
  etc. But don't confuse is-implemented-using-a with is-a.
 

 Well, I know the difference and choose to break the rule intentionally
 *chuckle*.  After the initial prototype, speed trumped OO.
 
  -- Paul
 
 Thanks for your comments, Paul.
 
 Regards,
 Mark

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


How to catch these kind of bugs in Python?

2006-08-19 Thread asincero
Is there anyway to catch the following type of bug in Python code:

message = 'This is a message'
# some code
# some more code
if some_obscure_condition:
   nessage = 'Some obscure condition occured.'
# yet more code
# still more code
print message


In the above example, message should be set to 'Some obscure condition
occured.' if some_obscure_condition is True.  But due to a lack of
sleep, and possibly even being drunk, the programmer has mistyped
message.  These types of bugs would easily be caught in languages that
have a specific keyword or syntax for declaring variables before use.
I'm still fairly new to using Python on a more than casual basis, so I
don't know if Python has anyway to help me out here.

-- Arcadio

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


Re: sending values over classes

2006-08-19 Thread Rafał Janas
Hi,

Exactly I want to set global value (like session - who is log in)
I writing simple program with more than one class - every window has different
class in different file.
Example:
2 files (main and wind). Main is main window and wind is child window.
I want to send value from main to child from entry to entry and I know how to do
it
But I can't send value from child to main.

My main.py
#!/usr/bin/env python

#--
# main.py
# Dave Reed
# 08/19/2006
#--

import sys
import wind
from GladeWindow import *
global dupa
#--

class Main(GladeWindow):

#--

def __init__(self):

''' '''
self.init()

#--

def init(self):

filename = 'main.glade'

widget_list = [
'pokoj',
'entry1',
'button1',
]

handlers = [
'on_button1_clicked',
]

top_window = 'pokoj'
GladeWindow.__init__(self, filename, top_window, widget_list, handlers)
#--

def on_button1_clicked(self, *args):
#self.wind=wind.Wind(self)
#self.wind.top_window='win1'
#self.wind.show()
dupa='test123'
b=wind.Wind()
b.show()




#--

def main(argv):

w = Main()
w.show()
gtk.main()

#--

if __name__ == '__main__':
main(sys.argv)


And wind.py

#!/usr/bin/env python

#--
# wind.py
# Dave Reed
# 08/19/2006
#--

import sys
#import main
from GladeWindow import *

#--

class Wind(GladeWindow):

#--

def __init__(self):

''' '''
#self.main=main
self.init()

#--

def init(self):

filename = 'wind.glade'

widget_list = [
'win1',
'entry1',
'button1',
]

handlers = [
'on_button1_clicked',
]

top_window = 'win1'
GladeWindow.__init__(self, filename, top_window, widget_list, handlers)
#--

def on_button1_clicked(self, *args):
#self.main.widgets['entry1'].set_text(self.widgets['entry1'].get_text())
self.widgets['entry1'].set_text(dupa)





#--

def main(argv):

w = Wind()
w.show()
gtk.main()

#--

if __name__ == '__main__':
main(sys.argv)

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


Re: How to catch these kind of bugs in Python?

2006-08-19 Thread Jorge Godoy
asincero [EMAIL PROTECTED] writes:

 In the above example, message should be set to 'Some obscure condition
 occured.' if some_obscure_condition is True.  But due to a lack of
 sleep, and possibly even being drunk, the programmer has mistyped
 message.  These types of bugs would easily be caught in languages that
 have a specific keyword or syntax for declaring variables before use.
 I'm still fairly new to using Python on a more than casual basis, so I
 don't know if Python has anyway to help me out here.

Unit testing, running pylint, pychecker, etc.

-- 
Jorge Godoy  [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to catch these kind of bugs in Python?

2006-08-19 Thread dave . brueck
asincero wrote:
 Is there anyway to catch the following type of bug in Python code:

 message = 'This is a message'
 if some_obscure_condition:
nessage = 'Some obscure condition occured.'
 print message


 In the above example, message should be set to 'Some obscure condition
 occured.' if some_obscure_condition is True.  But due to a lack of
 sleep, and possibly even being drunk, the programmer has mistyped
 message.  These types of bugs would easily be caught in languages that
 have a specific keyword or syntax for declaring variables before use.

There are tools that help (e.g. pychecker), but there are a few things
to consider:

1) If the programmer is sleepy/drunk, you're going to have other bugs
too (logical errors, not handling all cases, etc.)

2) Other languages would catch *some* types of these bugs, but would
still miss some of them (I can see a sleepy programmer also using the
wrong variable instead of just mistyping the right one).

So while a tool might assist, it's worth your while to also consider
some strategies for tackling the above two problems and, in the
process, the sleepy-programmer-mistype bugs will get caught as well.
Some type of testing is probably the best answer - be it reusable unit
tests or, at the very least, some interactive testing of code snippets
(which Python makes really easy to do).

-Dave

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


Embedding python: GCC gives errors of undefined reference to Py_* functions.

2006-08-19 Thread Shuaib
Hey!

I am trying to embedd python into a C programe of mine. But when I try
to compile the C code, gcc gives errors like undefined reference to
`Py_Finalize' and the same kind for all the other functions. I have
incuded Python.h.

Any idea what might be wrong?

Thanks.

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


install patch on windows

2006-08-19 Thread djoefish
Does anyone know how to install a patch on Winodws? For example, I want
to install the patch 'ocmalloc-free-arenas.diff' in Python 2.3.

thanks...

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


Google groups api

2006-08-19 Thread fooshm
Hello,
Is there any module for searching google groups, something like
PyGoogle ?

Thank you in advance,
Efi

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


Stopping all threads from other thread

2006-08-19 Thread amadeusz . jasak
Hello,
it is possible to stop all threads (application) from thread of
application:
App
 |-MainThread
 |-WebServer
 |-CmdListener # From this I want to stop App
 
The sys.exit isn't working...

Amadeusz Jasak (Poland)

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


Re: Embedding python: GCC gives errors of undefined reference to Py_* functions.

2006-08-19 Thread Shuaib
OK, I am not ashamed to admit that I am ashamed as I didn't search the
group for my problem before posting it yet again. The solution was
right there.

I have link in my libpython2.4.so while compiling.

$gcc -I/usr/include/python2.4/ -lpython2.4  -o foo foo.c


Shuaib wrote:
 Hey!

 I am trying to embedd python into a C programe of mine. But when I try
 to compile the C code, gcc gives errors like undefined reference to
 `Py_Finalize' and the same kind for all the other functions. I have
 incuded Python.h.
 
 Any idea what might be wrong?
 
 Thanks.

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


Re: install patch on windows

2006-08-19 Thread Tim Golden
djoefish wrote:
 Does anyone know how to install a patch on Winodws? For example, I want
 to install the patch 'ocmalloc-free-arenas.diff' in Python 2.3.

You can get patch (and quite a lot besides) for win32 from
the UnxUtils project:

http://sourceforge.net/projects/unxutils

TJG

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


Re: ratfun-2.3 Polynomials and Rational Functions

2006-08-19 Thread Bas
Are there any differences between this module and the one already
present in numpy?

http://www.scipy.org/doc/numpy_api_docs/numpy.lib.polynomial.html

Cheers,
Bas

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


Re: install patch on windows

2006-08-19 Thread djoefish

Tim Golden wrote:
 djoefish wrote:
  Does anyone know how to install a patch on Winodws? For example, I want
  to install the patch 'ocmalloc-free-arenas.diff' in Python 2.3.

 You can get patch (and quite a lot besides) for win32 from
 the UnxUtils project:

 http://sourceforge.net/projects/unxutils
 
 TJG

Thanks, but that project seems to be dead

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


Re: install patch on windows

2006-08-19 Thread Jorge Godoy
djoefish [EMAIL PROTECTED] writes:

 Tim Golden wrote:
 djoefish wrote:
  Does anyone know how to install a patch on Winodws? For example, I want
  to install the patch 'ocmalloc-free-arenas.diff' in Python 2.3.

 You can get patch (and quite a lot besides) for win32 from
 the UnxUtils project:

 http://sourceforge.net/projects/unxutils
 
 TJG

 Thanks, but that project seems to be dead

The files there didn't work?

-- 
Jorge Godoy  [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Python complaining about CherryPY?

2006-08-19 Thread Thomas McLean
Hi all,

First post to the list, so first off, I'm new to Python and everything
surrounding it so if you can please ignore my ignorance.

I setup a cherryPY server so that I could use sabnzbd but once, I have
installed/configured what I was told by the tutorials and everything else.
I run ubuntu x86 dapper FYI.

The error messages I get from the logs are as follows (which don't really
mean to muchto me):

19/Aug/2006:20:55:33 HTTP INFO Traceback (most recent call last):
  File /usr/lib/python2.4/site-packages/cherrypy/_cphttptools.py, line
110, in _run
applyFilters('before_finalize')
  File /usr/lib/python2.4/site-packages/cherrypy/filters/__init__.py,
line 151, in applyFilters
method()
  File
/home/tam/www/sites/domain1/htdocs/SABnzbd/sabnzbd/utils/multiauth/filter.py,
line 59, in beforeFinalize
cherrypy.response.body = rsrc.callable(rsrc.instance,
  File /home/tam/www/sites/domain1/htdocs/SABnzbd/sabnzbd/interface.py,
line 116, in index
info, pnfo_list, bytespersec = build_header()
  File /home/tam/www/sites/domain1/htdocs/SABnzbd/sabnzbd/interface.py,
line 933, in build_header
header = { 'version':sabnzbd.__version__, 'paused':sabnzbd.paused(),
  File /home/tam/www/sites/domain1/htdocs/SABnzbd/sabnzbd/__init__.py,
line 753, in paused
return DOWNLOADER.paused
AttributeError: 'NoneType' object has no attribute 'paused'

127.0.0.1 - - [19/Aug/2006:20:55:33] POST /sabnzbd/ HTTP/1.1 500 791
http://localhost:8080/sabnzbd/; Mozilla/5.0 (X11; U; Linux i686; en-US;
rv:1.8.0.4) Gecko/20060608 Ubuntu/dapper-security Firefox/1.5.0.4


So if anyone can shed some light on this I would be very greatful.

Thanks for your time.

Tam.

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


Embedding python: Segmentation Fault

2006-08-19 Thread Shuaib
Hi!

I am trying to embed python into a C programe of mine. When the
execution reaches the following line

pModule = PyImport_Import(pName);

It causes a Segmentation Fault Error. pModule is of type PyObject *, so
is pName.

What could be the possible reasons for the error?

Thanks for your time.

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


Re: install patch on windows

2006-08-19 Thread djoefish

Jorge Godoy wrote:
 djoefish [EMAIL PROTECTED] writes:

  Tim Golden wrote:
  djoefish wrote:
   Does anyone know how to install a patch on Winodws? For example, I want
   to install the patch 'ocmalloc-free-arenas.diff' in Python 2.3.
 
  You can get patch (and quite a lot besides) for win32 from
  the UnxUtils project:
 
  http://sourceforge.net/projects/unxutils
 
  TJG
 
  Thanks, but that project seems to be dead

 The files there didn't work?

 --
 Jorge Godoy  [EMAIL PROTECTED]


not exactly...there are NO files there. Butfrom the forums I found out
about GNUWin32, which has a 'patch' program for windows. I amd trying
it now to see if it works.

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


Re: How to get the ascii code of Chinese characters?

2006-08-19 Thread Peter Maas
Gerhard Fiedler wrote:
 Well, ASCII can represent the Unicode numerically -- if that is what the OP
 wants.

No. ASCII characters range is 0..127 while Unicode characters range is
at least 0..65535.

 For example, U+81EC (all ASCII) is one possible -- not very
 readable though g -- representation of a Hanzi character (see
 http://www.cojak.org/index.php?function=code_lookupterm=81EC).

U+81EC means a Unicode character which is represented by the number
0x81EC. There are some encodings defined which map Unicode sequences
to byte sequences: UTF-8 maps Unicode strings to sequences of bytes in
the range 0..255, UTF-7 maps Unicode strings to sequences of bytes in
the range 0..127. You *could* read the latter as ASCII sequences
but this is not correct.

How to do it in Python? Let chinesePhrase be a Unicode string with
Chinese content. Then

chinesePhrase_7bit = chinesePhrase.encode('utf-7')

will produce a sequences of bytes in the range 0..127 representing
chinesePhrase and *looking like* a (meaningless) ASCII sequence.

chinesePhrase_16bit = chinesePhrase.encode('utf-16be')

will produce a sequence with Unicode numbers packed in a byte
string in big endian order. This is probably closest to what
the OP wants.

Peter Maas, Aachen
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get the ascii code of Chinese characters?

2006-08-19 Thread John Machin

many_years_after wrote:

 John Machin wrote:
  many_years_after wrote:
   Hi,everyone:
  
Have you any ideas?
  
Say whatever you know about this.
  
 
  Perhaps you had better explain what you mean by ascii code of Chinese
  characters. Chinese characters (hanzi) can be represented in many
  ways on a computer, in Unicode as well as many different legacy
  encodings, such as GB, GBK, big5, two different 4-digit telegraph
  codes, etc etc. They can also be spelled out in roman letters with or
  without tone indications (digits or accents) in the pinyin system --
  is that what you mean by ascii code?
 
  Perhaps you might like to tell us what you want to do in Python with
  hanzi and ascii codes, so that we can give you a specific answer.
  With examples, please -- like what are the ascii codes for the two
  characters in the common greeting that comes across in toneless pinyin
  as ni hao?
 
  Cheers,
  John

 hi:

 what I want to do is just to make numbers as people input some Chinese
 character(hanzi,i mean).The same character will create the same
 number.So I think ascii code can do this very well.


*What* characters make *what* numbers? Stop thinking and give us some
*examples*

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


Re: How to get the ascii code of Chinese characters?

2006-08-19 Thread Gerhard Fiedler
On 2006-08-19 16:54:36, Peter Maas wrote:

 Gerhard Fiedler wrote:
 Well, ASCII can represent the Unicode numerically -- if that is what the OP
 wants.
 
 No. ASCII characters range is 0..127 while Unicode characters range is
 at least 0..65535.

Actually, Unicode goes beyond 65535. But right in this sentence, you
represented the number 65535 with ASCII characters, so it doesn't seem to
be impossible. 

 For example, U+81EC (all ASCII) is one possible -- not very
 readable though g -- representation of a Hanzi character (see
 http://www.cojak.org/index.php?function=code_lookupterm=81EC).
 
 U+81EC means a Unicode character which is represented by the number
 0x81EC. 

Exactly. Both versions represented in ASCII right in your message :)

 UTF-8 maps Unicode strings to sequences of bytes in the range 0..255,
 UTF-7 maps Unicode strings to sequences of bytes in the range 0..127.
 You *could* read the latter as ASCII sequences but this is not correct.

Of course not correct. I guess the only correct representation is the
original Chinese character. But the OP doesn't seem to want this... so a
non-correct representation is necessary anyway.

 How to do it in Python? Let chinesePhrase be a Unicode string with
 Chinese content. Then
 
 chinesePhrase_7bit = chinesePhrase.encode('utf-7')
 
 will produce a sequences of bytes in the range 0..127 representing
 chinesePhrase and *looking like* a (meaningless) ASCII sequence.

Actually, no. There are quite a few code positions in the range 0..127 that
don't look like anything (non-printable). And, as you say, this is rather
meaningless.

 chinesePhrase_16bit = chinesePhrase.encode('utf-16be')
 
 will produce a sequence with Unicode numbers packed in a byte
 string in big endian order. This is probably closest to what
 the OP wants.

That's what you think... but it's not really ASCII. If you want this in
ASCII, and readable, I still suggest to transform this sequence of 2-byte
values (for Chinese characters it will be 2 bytes per character) into a
sequence of something like U+81EC (or 0x81EC if you are a C fan or 81EC if
you can imply the rest)... that's where we come back to my original
suggestion :)

Gerhard

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


Re: Documenting a package with Pydoc

2006-08-19 Thread Rob Cowie

Gabriel Genellina wrote:
 At Friday 18/8/2006 11:45, Rob Cowie wrote:

 Pydoc seems to be capable of writing documentation for all modules
 within a package by simply pointing it to the package on the command
 line...
 
 pydoc -w packagename_without_/
 
 Certainly, the method writedocs() appears to descend into a directory
 and create docs for each importable object.
 
 Perhaps I'm doing something wrong but when I do this, pydoc reports
 that no Python documentation can be found for each of the contents of
 the package. Of course, if I point pydoc directly to the modules, it
 succeeds.
 
 Am I doing something wrong?

 That appears to be a bug. In pydoc.writedocs, when iterating over the
 package directory contents, it uses inspect.getmodulename(path). That
 returns the bare filename (without path nor extension) (is it ok???),
 and later the resolve() function can't load the module because it
 lacks package information.

I don't think this is a bug; inspect.getmodulename(path) does indeed
return a bare filename, but this is later augmented with the pkgpath.

I also can't find a resolve() function. Perhaps we have different
versions? I have revision 1.38.

 For simple cases this patch may work: In writedocs, add the following
 line at the beginning:
  if pkgpath=='' and ispackage(dir): pkgpath = os.path.basename(dir) + '.'

 This works for top level packages located at sys.path, but not for
 packages located elsewhere.

 By example, I can generate now the docs for pychart:

 python c:\apps\python\lib\pydoc.py -w c:\apps\python\lib\site-packages\pychart



 Gabriel Genellina
 Softlab SRL


Thanks,

Rob C



 __
 Preguntá. Respondé. Descubrí.
 Todo lo que querías saber, y lo que ni imaginabas,
 está en Yahoo! Respuestas (Beta).
 ¡Probalo ya! 
 http://www.yahoo.com.ar/respuestas

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


Re: How to get the ascii code of Chinese characters?

2006-08-19 Thread John Machin

many_years_after wrote:
 hi:

 what I want to do is just to make numbers as people input some Chinese
 character(hanzi,i mean).The same character will create the same
 number.So I think ascii code can do this very well.


Possibly you have create upside-down. Could you possibly be talking
about an input method, in which people type in ascii letters (and
maybe numbers) and the *result* is a Chinese character? In other words,
what *everybody* uses to input Chinese characters?

Perhaps you could ask on the Chinese Python newsgroup.

*GIVE* *EXAMPLES* of what you want to do.

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


streaming audio with standard modules?

2006-08-19 Thread Marc Shapiro
I am running Python 2.3 on Linux.

I am trying to write a program to simulate a hardware mixer to play 
theatrical sound cues.  I need to be able to play multiple sound 
channels at once, controlling volume by channel as well as globally.  I 
also need to be able to pan a channel through left and right speakers. 
I would prefer if the sound files could be ogg, mp3, or wav, and if they 
could be streamed, instead of having to load each file completely before 
playing it.

I have been using pygame.mixer and pygame.mixer.music, but pygame.mixer 
is not streaming, and pygame.mixer.music has only a single channel.

Is there a way to do any reasonable amount of what I am looking for with 
standard modules?  If not, is there a module(s) that I can download 
somewhere that will do the trick?

Marc
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: timezones and time_t

2006-08-19 Thread MrBlueSky
Thanks for the reply.  Unfortunately, a simple +offset type solution
isn't really accurate enough for the kind of scenario I'm looking at.
I'm often dealing with different timezones with DST changeovers on
different dates or even different times of day!  So I need
industrial-strength timezone handling!

Wrt your naming conventions... sorry, I'm a newbie to Python so not
really qualified to comment.  But what's a PEP?

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


Re: ratfun-2.3 Polynomials and Rational Functions

2006-08-19 Thread Raymond L. Buvel
Bas wrote:
 Are there any differences between this module and the one already
 present in numpy?
 
 http://www.scipy.org/doc/numpy_api_docs/numpy.lib.polynomial.html
 
 Cheers,
 Bas
 

Yes, there are quite a few.  This module uses a multi-precision library
(clnum) to make the calculations more precise.  This makes the root
finder significantly more precise.  There is an example in the user
manual that shows the difference in performance between Numeric
(essentially the same code as in numpy) and the ratfun root finder on an
ill-conditioned polynomial.

If you choose to use exact coefficients (integers and rationals) then
all calculations except for root finding are exact.

Unlike the numpy implementation, arithmetic (+-*/**) uses the standard
Python operators instead of requiring you to call functions.

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


trouble using \ as a string

2006-08-19 Thread OriginalBrownster
Hi there...

I'm still pretty new to turbogears. but i have gotten pretty familiar
with it

i'm just trying to clear something up, i'm having a difficult time
using \ when declaring a string expression

such as tempname=\..it says that the line is single qouted.

i want this because using python I am pulling in filenames from a
mac..thus they are / in the pathways..and i want to .split it at the
/ to obtain the filename at the end...but its proving diffucult with
this obstacle in the way.

Why is this happening??

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


Re: couple more questions about sqlite

2006-08-19 Thread John Salerno
Joel Rosdahl wrote:
 John Salerno [EMAIL PROTECTED] writes:
 
 What is really confusing is that I did a search for 'sqlite' in my
 Ubuntu repositories and it came up with entries like this:

 python2.4-pysqlite1.1   python interface to SQLite 3
 python2.4-pysqlite2 python interface to SQLite 3
 python2.4-pysqlite  python interface to SQLite 2
 
 That's python2.4-sqlite, not python2.4-pysqlite. The reason for both
 having pythonX.Y-foo and python-foo packages is Debian's (and
 therefore Ubuntu's) Python package policy.
 
 python-pysqlite1.1  python interface to SQLite 3
 python-pysqlite2python interface to SQLite 3
 python-sqlite   python interface to SQlite 2

 Needless to say, the numbering had me banging my head against my
 desk.
 
 Sorry to hear that, and I can understand that the names are a bit
 confusing.
 
 Here's the story behind the mess:
 
 In the beginning (well, at least in 2003 when I found out about
 SQLite), SQLite was up to version 2.something and the Python module
 was called sqlite.py. While the Python module *project* was called
 pysqlite 0.something, Debian modules were generally called python-foo
 when providing the module foo; hence the name python-sqlite.
 
 Then, SQLite 3 was released (incompatible with SQLite 2 databases),
 and pysqlite 1.1 was released with the same module name (sqlite.py)
 and API as the old sqlite.py module but linked against SQLite 3. I
 decided not to package that version but instead wait for pysqlite 2, a
 rewritten and improved version linked against SQLite 3 and with a new
 Python API.
 
 pysqlite 2 was released and the Python module was called
 pysqlite2.dbapi2. I didn't think python-sqlite3 would be a good name
 for the Debian package since there were actually two different
 pysqlite versions (both actively maintained) linked against SQLite3,
 so I ended up calling the package python-pysqlite2, following the name
 and version of the pysqlite project instead of the module.
 
 Finally, by request of Debian users, I also packaged the other
 pysqlite version linked against SQLite 3 giving the package
 python-pysqlite1.1.
 
 Oh, and then there's python-apsw too. :-)
 
 Regards,
 Joel (maintainer of Debian's Python-related sqlite packages)
 

Yikes! Well at least it gets simpler when 2.5 is released with the 
module built-in! :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: text editor suggestion?

2006-08-19 Thread John Salerno
Sybren Stuvel wrote:
 John Salerno enlightened us with:
 I'd really like to learn vim, but I spent days just trying to figure
 out how to get the syntax highlighting and indentation working,
 where these settings are and how to edit them
 
 Stop being a man and just ask for directions :)

Oh don't worry, I have no shame. I was asking a ton of questions, yet I 
still couldn't figure it out.

 
 It just feels so insurmountable that I can't even start working with
 it yet because I don't know how to tailor the settings.
 
 vim ~/.vimrc is all you need on any system but Windows. There IIRC
 you need to edit C:\Program Files\VIM\_vimrc.

But what about customizing syntax coloring? Is this also in the same 
file? I've noticed a separate file called python.vim (in Windows, this 
file exists in a 'syntax' folder, and also another file of the same name 
in an 'indent' folder, so I'm *still* confused about which files are 
used for which settings.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: text editor suggestion?

2006-08-19 Thread John Salerno
milosz wrote:
 Did you try gedit?
 It has an options, which you need, I think.
 Regards.
 

Yes, I tried it and it's alright, but it doesn't support smart 
indentation or much customizing of syntax highlighting (i.e. you can 
change the color of functions, but you can't define what a 'function' 
is, or at least I have no idea where this can be done). It seems like 
what most editors do is highlight user-defined functions as they are 
defined, so:

def func()

'func' would be highlighted here, but not when you call it elsewhere in 
your script. Furthermore, there isn't support for built-in Python 
functions and methods.

The thing I liked about UltraEdit is that you can define your own groups 
of words and put whatever words you want in there, so my file had a 
group called '__builtins__' and it listed all the Python built-in 
methods, and those would be highlighted. Most editors I see don't seem 
to allow this...they just figure out what a function or method is on 
their own somehow.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trouble using \ as a string

2006-08-19 Thread Jim
Try using: tempname = \\
Jim


OriginalBrownster wrote:
 Hi there...

 I'm still pretty new to turbogears. but i have gotten pretty familiar
 with it

 i'm just trying to clear something up, i'm having a difficult time
 using \ when declaring a string expression

 such as tempname=\..it says that the line is single qouted.

 i want this because using python I am pulling in filenames from a
 mac..thus they are / in the pathways..and i want to .split it at the
 / to obtain the filename at the end...but its proving diffucult with
 this obstacle in the way.
 
 Why is this happening??

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


Re: How to catch these kind of bugs in Python?

2006-08-19 Thread Ravi Teja
asincero wrote:
 Is there anyway to catch the following type of bug in Python code:

 message = 'This is a message'
 # some code
 # some more code
 if some_obscure_condition:
nessage = 'Some obscure condition occured.'
 # yet more code
 # still more code
 print message


 In the above example, message should be set to 'Some obscure condition
 occured.' if some_obscure_condition is True.  But due to a lack of
 sleep, and possibly even being drunk, the programmer has mistyped
 message.  These types of bugs would easily be caught in languages that
 have a specific keyword or syntax for declaring variables before use.
 I'm still fairly new to using Python on a more than casual basis, so I
 don't know if Python has anyway to help me out here.

The keyword is obscure condition. The solution is to use a coverage
tool and create unit tests that give you 100% code coverage.

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


Re: sum and strings

2006-08-19 Thread Georg Brandl
Bill Pursell wrote:
 Georg Brandl wrote:
 Paul Rubin wrote:
  Sybren Stuvel [EMAIL PROTECTED] writes:
  Because of there should only be one way to do it, and that way should
  be obvious. There are already the str.join and unicode.join methods,
 
  Those are obvious???

 Why would you try to sum up strings? Besides, the ''.join idiom is quite
 common in Python.
 
 One could extend this argument to dissallow the following:
 foo + bar

Fortunately, hypergeneralization is not one of Python's weaknesses.

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


Re: how to use python com server in c++?

2006-08-19 Thread Butternut Squash
Leo Jay wrote:

 dear all,
 i have a python com server like this:
 
 import win32com.server.register
 
 class HelloWorld:
 _reg_clsid_ = {B0EB5AAB-0465-4D54-9CF9-04ADF7F73E4E}
 _reg_desc_  = 'Python test com server'
 _reg_progid_= Leojay.ComServer
 _public_methods_= ['Add', 'Mul']
 
 def Add(self, a, b):
 return a+b
 def Mul(self, a, b):
 return a*b
 
 
 if __name__ == '__main__':
 win32com.server.register.UseCommandLine(HelloWorld)
 
 
 after registering the com server, i can use it in visual basic .net:
 Dim a As Integer = 5
 Dim b As Integer = 8
 Dim h As Object = CreateObject(Leojay.ComServer)
 MsgBox(h.Add(a, b).ToString() +   + h.Mul(a, b).ToString())
 
 but i don't know how to use it in visual c++.
 
 who has any idea about using this com server in viusal c++?
 a detailed sample of early binding would be better, thanks.
 
 
 

too complicated for my brain. Waiting for a good answer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Questions on unittest behaviour

2006-08-19 Thread John Roth

Collin Winter wrote:
 While working on a test suite for unittest these past few weeks, I've
 run across some behaviours that, while not obviously wrong, don't
 strike me as quite right, either. Submitted for your consideration:

 1) TestCase.tearDown() is only run if TestCase.setUp() succeeded. It
 seems to me that tearDown() should always be run, regardless of any
 failures in setUp() or the test method itself.

 I'm undecided if this is a new feature (so it should go in for 2.6) or
 a bug fix; I'm leaning toward the latter.

I strongly disagree. First, this is the documented behavior
for all xUnit ports (see jUnit), second, it's the responsibility
of a routine to clean up for itself.

 2) The TestLoader.testMethodPrefix attribute currently allows anything
 to be assigned to it, including invalid objects and the empty string.
 While the former will cause errors to be raised when one of
 TestLoader's loadTestsFrom*() methods is called, the empty string will
 raise no exception; rather, the loadTestsFrom*() methods will
 interpret every possible attribute as being a test method, e.g.,
 meaning you get things like assertEqual(), failUnlessEqual(), etc,
 when TestLoader.loadTestsFromTestCase() is run.

 I propose protecting testMethodPrefix with a property that validates
 the assigned value, restricting input to non-empty instances of str. I
 see this as a bug fix that should go in before 2.5-final.

Several points. First, since it's been this way since day one and
nobody has complained, it's not a bug. That means it's a feature,
and 2.5 is in a complete, absolute, utter, total and thorough
feature freeze. This is not the place to get Guido's attention. As
far as I'm aware, he doesn't read this newsgroup.

On the other hand, you might be working with the crew on
pythondev; I only read the summaries. If you are, then you
already know what I mentioned above. If you aren't, your
odds of getting a new test suite into 2.5 final are somewhere
on the far side of zero.

 3) TestLoader.loadTestsFromTestCase() accepts objects that are not
 test cases and will happily look for appropriately-named methods on
 any object you give it. This flexibility should be documented, or
 proper input validation should be done (a bug fix for 2.5).

I'm pretty sure I use this. Making it go away would cause
me to have to find another way around the misbegotten
prefix selection mechanism. There's a lot of discussion
around something that's called behavior driven development
which is neither here nor there other than that group of people
considers the whole notion of a name with a fixed element to
be a problem with constructing really meaningful test names.

 4) TestLoader.loadTestsFromName() (and by extension,
 loadTestsFromNames(), too) raises an AttributeError if the name is the
 empty string because -- as it correctly asserts -- the object does not
 contain an attribute named ''. I recommend that this be tested for and
 ValueError be raised (bug fix for 2.5).

Prior point about 2.5 being in a freeze. Take it to the pythondev
mailing list if you really want action. As far as I'm concerned,
this is a so what. There are much deeper issues with unittest
than this.

 This of course leads into the question of how much input validation
 should be done on these names. Should loadTestsFrom{Name,Names}() make
 sure the names are valid attribute names, or is this overkill?

What _I_ want is a method of selecting tests from a class
that doesn't depend on pattern matching the name.
I've got it rigged to not do that, and I feel that my names
are now significantly better.

 5) When TestLoader.loadTestsFrom{Name,Names}() are given a name that
 resolves to a classmethod on a TestCase subclass, the method is not
 invoked. From the docs:

  The specifier name is a ``dotted name'' that may resolve either to a 
  module, a test
  case class, a TestSuite instance, a test method within a test case class, 
  or a
  callable object which returns a TestCase or TestSuite instance.

 It is not documented which of these tests takes priority: is the
 classmethod a test method within a test case class or is it a
 callable? The same issue applies to staticmethods as well.

These are all new since pyUnit (renamed to unittest for inclusion
into the standard library) was written. My viewpoint is that it's a
feature that's looking for a use case.

As I intimated above, my current practice is to not use the supplied
mechanism for locating tests. I don't use it for locating test classes
either.

 Once I get answers to these questions, I can finish off the last few
 bits of the test suite and have it ready for 2.5-final.

Answers? On this list? I'm not even sure you can get
coherent opinions here.

John Roth

 
 Thanks,
 Collin Winter

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


  1   2   >