Bangalore Python February Meetup

2007-04-18 Thread Ajay S
Hi Swaroop,

I do business development for a technology start up based in Hyderabad. 
We use Python and related technologies extensively, which means we are 
constantly on the lookout for partners and high quality talent. We are 
currently focussed on developing a series of ideas for Web 2.0 based 
services and we are very excited about the future.

I am based in Bangalore and would love to attend one of meetings to try 
and connect with the community that you have created here.

Do let me know where and when you have your meetings.

Regards
Ajay
Business Development
Azri Solutions Pvt Ltd

+91-98867-18452
+91-40-2354-3940
Skype: ajay_s_1407
www.azri.biz

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

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


First Texas Unconference

2007-04-18 Thread Robin Friedrich
I'm pleased to announce we in Houston have started planning the 1st
Annual Texas Unconference for Python users. This is a FREE weekend
event scheduled for Sept. 15-16, 2007. We've arranged use of the Texas
Learning  Computing Center on the campus of the University of
Houston. Python users in the region are invited to attend and make
this first event memorable!

Visit our Wiki site and help shape the event over the next five
months.
http://pycamp.python.org/Texas/HomePage

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

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


How to communicate via USB port

2007-04-18 Thread [EMAIL PROTECTED]
Can someone explain how I would read the data from the USB port? I
don't know if it matters, but I am trying to read the data from a GPS
plugged in to the USB port.

Thank you,
Robin

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


Re: Future Python Gui?

2007-04-18 Thread Richard Jones
kirkjobsluder wrote:
 I'd say that the best bet is to learn swig and similar
 bridging, expanding, and embedding mechanisms.

For GUI programming this would seem overkill. Pick a GUI toolkit and it's
almost guaranteed to be wrapped for use in Python already.


Richard

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


Re: What makes an iterator an iterator?

2007-04-18 Thread I V
On Wed, 18 Apr 2007 15:39:22 +1000, Steven D'Aprano wrote:
 I thought that an iterator was any object that follows the iterator
 protocol, that is, it has a next() method and an __iter__() method.
...
 class Parrot(object):
...
 def __init__(self):
 self.next = self._next()

self.next isn't a method here, it's a generator. You could do:

def __init__(self):
  self.next = self._next().next

But, having tested, that doesn't appear to work either - I think
this is because, again, self.next is not strictly a method, it's an
attribute that happens to be callable.

The python manual gives you a possible solution:

---QUOTE http://docs.python.org/lib/typeiter.html ---
Python's generators provide a convenient way to implement the iterator
protocol. If a container object's __iter__() method is implemented as a
generator, it will automatically return an iterator object (technically, a
generator object) supplying the __iter__() and next() methods.
---END QUOTE---

i.e., just rename your _next function to __iter__ . Your class won't
itself be an iterator, but it will be usable in for statements and so one,
and convertable to an iterator with the iter builtin.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Binary file output using python

2007-04-18 Thread Peter Otten
Chi Yin Cheung wrote:

 Is there a way in python to output binary files? I need to python to
 write out a stream of 5 million floating point numbers, separated by
 some separator, but it seems that all python supports natively is string
 information output, which is extremely space inefficient.
 
 I'd tried using the pickle module, but it crashed whenever I tried using
 it due to the large amount of data involved.

A minimalistic alternative is array.tofile()/fromfile(), but pickle should
handle a list, say, of 5 million floating point numbers just fine. What
exactly are you doing to provoke a crash, and what does it look like?
Please give minimal code and the traceback.

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


Re: is laziness a programer's virtue?

2007-04-18 Thread Ken Tilton


Xah Lee wrote:
 Dear Ken,
 
 I want to thank you for your spirit in supporting and leading the lisp
 community, in spreading lisp the language both in what you have done
 technically as well as evangelization, as well as the love and
 knowledge attitude towards newsgroup communities in general, in part
 thru your numerous replies to my posts in the past years.

Hey, thx, but to me recommending Lisp is like recommending water to a 
life form.

Meanwhile, the last thing anyone can doubt is that you say what you mean 
and mean what you say, so all we can say about your detractors is...

 (as opposed
 to, the motherfucking pack of driveling and fuckface ignoramuses that
 are predominate personalities in newsgroups,

...OK, but we know this from long Usenet experience. Reaching 
Enlightenment means smiling on these noisemakers and having compassion 
for them, for they live in mean, narrow worlds and in attacking you are 
only reaching for the sunlight you enjoy, in however their ignorant way.

The nice thing about this compassionate view is that it leaves you 
feeling positive and at peace within yourself, whereas the driveling 
and fuckface thing leaves you feeling negative and attacked. less good, 
for my money.

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


Re: What makes an iterator an iterator?

2007-04-18 Thread Ben Finney
Steven D'Aprano [EMAIL PROTECTED] writes:

 class Parrot(object):
 def __iter__(self):
 return self
 def __init__(self):
 self.next = self._next()
 def _next(self):
 for word in Norwegian Blue's have beautiful plumage!.split():
 yield word

Clearly the problem is you've misused an apostrophe. Python doesn't
like the plural getting an apostrophe.

URL:http://www.angryflower.com/bobsqu.gif

-- 
 \  Speech is conveniently located midway between thought and |
  `\ action, where it often substitutes for both.  -- John Andrew |
_o__)  Holmes, _Wisdom in Small Doses_ |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Strange terminal behavior after quitting Tkinter application

2007-04-18 Thread Chris
Hi,

I'm puzzled by some strange behavior when my Python/Tkinter
application quits (on linux): the terminal from which I started Python
is messed up.

If start up python, then import the code below, then start the program
with Application(), then click the Quit button, my terminal never
prints anything again (such as commands I type).

code

import Tkinter
import sys

class Application(Tkinter.Tk):

def __init__(self,**config):
Tkinter.Tk.__init__(self,**config)
 
Tkinter.Button(self,text=Quit,command=self.quit_application).pack()

def quit_application(self):
sys.exit()

/code


Can anyone tell me what I'm doing wrong?

Thanks for your help.

Chris

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


Re: Strange terminal behavior after quitting Tkinter application

2007-04-18 Thread Chris
(I'm not sure what happened to the formatting in my post: the
Tkinter.Button line should be at the same level of indentation as
the Tkinter.Tk.__init__ line.)

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


Win32com, and Excel issues.

2007-04-18 Thread Ant
Hi all,

I'm doing some Excel automation work for a friend, and am developing
on a machine running Office 2000. My friends machine is running Excel
2003. The code I've written works like a charm on my machine (in fact
all three of my machines), but falls over early on on Excel 2003.

The code snippet it falls over on is code to copy one worksheet after
another:

app = wincl.Dispatch(Excel.Application)
app.Visible = True
app.Workbooks.Open(self.filename)
sheet = app.Worksheets(1)
sheet.Copy(None, sheet)

and this last line throws the following exception:

pywintypes.com_error: (-2147417851, 'the server threw an exception.'
, None, None)

which isn't too helpful.

I'm wondering if something has changed in the Excel API that doesn't
allow a null parameter to Copy or some similar issue. I tried using
the keyword argument format, but that simply refused to work.

Other relevant information:

* The program is packaged using py2exe, so I know that the same
version of Python, and the same libraries are on each machine.
* One of the test machines running Excel 2000 does not have Python
installed.
* The machines are all of a similar spec.

Any ideas are welcome!

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


Re: ??? POLICE AND CITY/UNIVERSITY OFFICIALS INCOMPETENCE LEADS TO 33 KILLED BY KOREAN-ALQAEDA TERRORIST ???

2007-04-18 Thread Muhammad
On Apr 17, 12:18 pm, utabintarbo [EMAIL PROTECTED] wrote:
 On Apr 17, 10:32 am, Muhammad [EMAIL PROTECTED] wrote:

  On Apr 17, 7:56 am, [EMAIL PROTECTED] wrote:
  - snipped rant
  You mentioned Korean Al-Qaeda Terrorist in the title! Honesty
  demands that you establish it as a fact that the person was connected
  to Al-Qaeda and that he was a terrorist and not some mentally sick
  fellow.
  Muhammad

 Just do it in a more appropriate forum, mmmkay?

Sorry about that. But I only post when I feel it necessary. And I
thought that if I let this person be, it might get to: But Al-Qaeda is
a Muslim terrorist organization, let us go get Muslims. Precisely like
Wafa Sultan and Co. who want to eradicate Radical Islam for a start,
but end up saying There is no moderate Muslim. In other words, Get
all the Muslims. Not that it frightens me, I have seen much worse,
but it is a bother.
Muhammad

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


Signals

2007-04-18 Thread Robert Rawlins - Think Blue
Hello Chaps,

 

I posted about this the other day but I'm still struggling to get any form
of result from it. Basically I have the following piece of code, and
according to its API is produces singals when particular events occur, but i
have no idea how to list for events, I've tried all sorts of combinations
using the signal module but haven't been able to get it working.

 

#!/usr/bin/python

 

import dbus, signal

 

bus = dbus.SystemBus()

obj = bus.get_object('org.bluez', '/org/bluez')

obj = bus.get_object('org.bluez', '/org/bluez/hci0')

adapter = dbus.Interface(obj, 'org.bluez.Adapter')

 

adapter.DiscoverDevices()

 

Now here is a copy of the API documentation that lists the signals thrown by
the API, this is the one I'm trying to listen for.

 

void RemoteDeviceFound(string address, uint32 class, int16 rssi)

 

   This signal will be send every time an inquiry result

   has been found by the service daemon. In general they

   only appear during a device discovery.

 

Basically I'm just looking to run a function that will print those details
to screen. Can anyone help with working out how to listen for this signal?
I'd also like to know how i can keep the application running until I decided
to stop it manually, as the DiscoverDevices() can take a while to complete
and send out several RemoteDeviceFound() signals in that period.

 

Thanks guys

 

Rob

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

Re: Queue enhancement suggestion

2007-04-18 Thread Antoon Pardon
On 2007-04-17, Jean-Paul Calderone [EMAIL PROTECTED] wrote:
 On 17 Apr 2007 14:32:01 GMT, Antoon Pardon [EMAIL PROTECTED] wrote:
On 2007-04-17, Jean-Paul Calderone [EMAIL PROTECTED] wrote:
 On 17 Apr 2007 13:32:52 GMT, Antoon Pardon [EMAIL PROTECTED] wrote:
On 2007-04-17, Hendrik van Rooyen [EMAIL PROTECTED] wrote:
 [snip]

 Not sure I understand this -  it sounds vaguely incestous to me.
 I normally use a GUI with two queues,  one for input, one for
 output, to two threads that front end two named pipes to
 the next process - I try to avoid more than one thing reading or
 writing to one end of a queue or a pipe, so the dataflow diagram
 for my stuff always looks like a TinkerToy...

The problem is that sometimes the gui thread has something to show
too. With the added problem that the code wanting to show something
doesn't know when it is executing the gui thread or an other. So
it is very difficult to avoid the gui thread putting things on the
queue. But since the gui thread is the single reader, it will dead
lock if the queue happens to be full at the moment the gui thread
want to add another item.


 This is pretty easily solved:

 def sendToGUI(event):
 if isInGUIThread():
 gui.scheduleCall(event)
 else:
 guiQueue.put(event)

No that is not a solution for the simple reason that now things
can be shown out of order. Suppose I have a thread that shows
the value of a certain variable. Now I have a button that can
stop this thread and zero the variable. If I go for your
solution a value may still be in the queue and my window
ends up showing this last value instead of zero.


 Addressing that is up to the application code.  Threading is tough,
 there are no magic bullets.  The above is a very standard tool for
 addressing the concern raised earlier in this thread.  It's only
 *part* of a solution though, the rest of the application has to play
 along.

My solution is a more complete implementation of Queues, which allow
a thread to register as reader, writer or reader-writer. Reader-writers
are always allowed to put an element in the queue even if it is full.

Since the Reader-writer will typically only put things on the queue
as a result of user interaction, the queue wont grow too large
anyway.

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


Re: Queue enhancement suggestion

2007-04-18 Thread Antoon Pardon
On 2007-04-18, Hendrik van Rooyen [EMAIL PROTECTED] wrote:
  Antoon Pardon [EMAIL PROTECTED] wrote:


 The problem is that sometimes the gui thread has something to show
 too. With the added problem that the code wanting to show something
 doesn't know when it is executing the gui thread or an other. So
 it is very difficult to avoid the gui thread putting things on the
 queue. But since the gui thread is the single reader, it will dead
 lock if the queue happens to be full at the moment the gui thread
 want to add another item.

 This can happen - I suppose the cure is to have the GUI use a non blocking
 put in a try except checking for the full condition - its bad to block the GUI
 anyway because then the mouse and kbd become unresponsive.  So even
 the reads (get) have to be non blocking, or the thing will behave like a 
 disobedient dog, that knows what to do, but just refuses.

My queue module has a register call. So you can register it to GTK the
same way you can register a pipe or network connection. So the gui will
only try to get things from the queue if there is something in it.

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


Re: What makes an iterator an iterator?

2007-04-18 Thread Stefan Rank
on 18.04.2007 07:39 Steven D'Aprano said the following:
 I thought that an iterator was any object that follows the iterator

replace object with instance of a class, i.e. the relevant methods are 
looked up in the __class__ not in the instance (I think).
I had the same troubles trying to dynamically reassign a __call__ method...

 protocol, that is, it has a next() method and an __iter__() method.
 
 But I'm having problems writing a class that acts as an iterator. I have:
 
 class Parrot(object):
 def __iter__(self):
 return self
 def __init__(self):
 self.next = self._next()
 def _next(self):
 for word in Norwegian Blue's have beautiful plumage!.split():
 yield word

Try this::

  class Parrot(object):
  def __iter__(self):
  return self
  def __init__(self):
  self.__class__.next = self._next().next # see post by I V
  def _next(self):
  for word in Norwegian Blue's have beautiful plumage!.split():
  yield word

This works but practically forces the class to be used as a singleton... 
not very helpful :)

Better:

* use the '__iter__ returns/is a generator' way,
* or if you need the object to be the iterator, implement the next 
method directly on the class::

  class Parrot(object):
  def _next(self):
  for word in Norwegian Blue's have beautiful plumage!.split():
  yield word
  def __iter__(self):
  self.generator = self._next()
  return self
  def next(self):
  return self.generator.next()

cheers,
stefan

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


Re: The smallest and largest values of numeric types

2007-04-18 Thread Hendrik van Rooyen

 Michael Hoffman [EMAIL PROTECTED] wrote:


20859248300531693115643211913059311997417115606882000504639505780471641693377296
50765802242049L

 Of course performance decreases for longer longs.

I once made a thing that tried to find the limit of longs and stopped
when I had two or three screenfulls of numbers.

I came to the conclusion that for integer arithmetic like this,
the limit is either your memory size, or some other number
that is so big that in practice you don't have to worry about it..

- Hendrik

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


Re: Screen Control in WinXP and Linux

2007-04-18 Thread Tim Golden
peter wrote:
 I've been wrestling on and off with this problem for over a year now,
 without success.  Basically, I am looking for a simple set of screen
 and keyboard manipulation commands that will run identically under
 Linux and Windows.  Nothing fancy - just clear the screen, print a
 string at an arbitrary xy position and detect a keystroke.  I've
 googled around this newsgroup and elsewhere, and come across various
 suggestions (and even posted my own partial solutions), but still
 haven't come up with an elegant solution.

OK, a bit of info from the Windows side of
things. Here are several existing modules
which offer the kind of thing you're after
in different ways. Don't bother with the
ANSI thing; it's a dead end under Windows.

   http://newcenturycomputers.net/projects/wconio.html
   http://effbot.org/zone/console-index.htm
   http://adamv.com/dev/python/curses/

I've used the first two for relatively trivial
things, the third not at all. The third is
interesting, obviously, because curses is
readily available on Linux (indeed comes as
part of Python, I think). So that might be
a quick win.

Alternatively, and depending on your needs,
there are a few UI addons for pygame:

   http://www.pygame.org/projects/9

Might not be what you're after from your
original description, but better too much
information than too little.

Obviously, unless the curses stuff fits your
needs, you might need to write a wrapper module
doing a bit of conditional importing or
platform-sniffing, but that's not beyond the wit
of man.

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


Re: The smallest and largest values of numeric types

2007-04-18 Thread Steven D'Aprano
On Wed, 18 Apr 2007 07:15:11 +0200, Hendrik van Rooyen wrote:

 I once made a thing that tried to find the limit of longs and stopped
 when I had two or three screenfulls of numbers.

You should find that converting longs to strings (say, for printing them)
is *very* slow. E.g. the following code

big = 10L**100 # one google, a big number
while True:
print big # so we can see the last value before it fails
big *= 10

will run terribly slow and should be written as:

big = 10L**100 # one google, a big number
try:
while True:
big *= 10
except: # don't know what exception will be raised, so catch ANYTHING
print len(str(big))-1 # the number of digits

only does the slow conversion to string once, instead of every time around
the loop. However, once your machine starts paging, it will still slow
down a lot.



 
 I came to the conclusion that for integer arithmetic like this, the
 limit is either your memory size, or some other number that is so big
 that in practice you don't have to worry about it..

Yes, longs are limited only by the amount of memory accessible. 


-- 
Steven D'Aprano 

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


Re: What makes an iterator an iterator?

2007-04-18 Thread Steven D'Aprano
On Wed, 18 Apr 2007 16:58:23 +1000, Ben Finney wrote:

 Steven D'Aprano [EMAIL PROTECTED] writes:
 
 class Parrot(object):
 def __iter__(self):
 return self
 def __init__(self):
 self.next = self._next()
 def _next(self):
 for word in Norwegian Blue's have beautiful plumage!.split():
 yield word
 
 Clearly the problem is you've misused an apostrophe. Python doesn't
 like the plural getting an apostrophe.
 
 URL:http://www.angryflower.com/bobsqu.gif

I thought the rule wa's that any time you 'see an 'S, you put an
apo'strophe before it. If that's wrong, 'shouldn't it rai'se an exception?




-- 
'Steven D'Aprano 


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


Re: What makes an iterator an iterator?

2007-04-18 Thread Steven D'Aprano
On Wed, 18 Apr 2007 06:13:39 +, I V wrote:

 On Wed, 18 Apr 2007 15:39:22 +1000, Steven D'Aprano wrote:
 I thought that an iterator was any object that follows the iterator
 protocol, that is, it has a next() method and an __iter__() method.

[snip]

 i.e., just rename your _next function to __iter__ . Your class won't
 itself be an iterator, but it will be usable in for statements and so one,
 and convertable to an iterator with the iter builtin.


Thanks to all those who helped, this fixed my problem.

For the record, this is what I actually wanted: a four-line self-sorting
dictionary:

class SortedDict(dict):
def __iter__(self):
for key in sorted(self.keys()):
yield key

Note that using sorted(self) does not work.

Iterating over a SortedDictionary returns the keys in sorted order. This
minimalist implementation doesn't sort the values, items or string
representation of the dict, but they should be easy to implement.



-- 
Steven D'Aprano 

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


Re: Strange terminal behavior after quitting Tkinter application

2007-04-18 Thread Michael Bentley

On Apr 18, 2007, at 2:33 AM, Chris wrote:


 I'm puzzled by some strange behavior when my Python/Tkinter
 application quits (on linux): the terminal from which I started Python
 is messed up.

 If start up python, then import the code below, then start the program
 with Application(), then click the Quit button, my terminal never
 prints anything again (such as commands I type).

 code

 import Tkinter
 import sys

 class Application(Tkinter.Tk):

 def __init__(self,**config):
 Tkinter.Tk.__init__(self,**config)

 Tkinter.Button(self,text=Quit,command=self.quit_application).pack()

 def quit_application(self):
 sys.exit()

 /code


 Can anyone tell me what I'm doing wrong?

What happens if you type 'stty sane' (and of course, a carriage  
return) afterwards?


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


Re: Getting started with python

2007-04-18 Thread [EMAIL PROTECTED]
On Apr 17, 11:00 pm, Basilisk96 [EMAIL PROTECTED] wrote:
 On Apr 14, 8:46 pm, Eric [EMAIL PROTECTED] wrote:

  Hello, after reading some of the book Programming Python it seems that
  python is something I would like to delve deeper into. The only thing
  is, I have no idea what I should try and write. So I was hoping that
  someone here could help point me to a group/project that would be a
  good starting place for a person with limited python knowledge, but
  that is willing to learn whatever is necessary. I'm hoping that with a
  goal I can start to learn python instead of just playing around with
  it. Thanks.

 Eric,

 You will certainly appreciate how concise and easy Python is.
 I am also relatively new to Python (started about a year ago), and I'd
 rather not go back to any other language! Why would I want to torment
 my not-so-quick typing fingers?? :)  I'm a self-learner. I learn by
 reading, by example, and by doing.

 Here is a list of suggestions. Start with simple things, grow
 confident, and move on to more interesting stuff as you progress:

 At the Python command line, type import this to see the basic ideas
 behind Python development. It begins with Beautiful is better than
 ugly. - a nice thought.

 1. First of all, read the publication How to Think Like a Computer
 Scientist: Learning with Python by Allen B. Downey et al.  I have
 found this little gem to be very, very useful when I first got
 interested in Python and thought to myself, how do I go about
 learning this, where do I start??.  Highly recommended. I read it
 from start to finish in a couple of days and started making useful
 scripts right after that.  The author actually implements a simple
 card game toward the end of the book, using all the knowledge from the
 previous chapters.  The text is available 
 at:http://www.ibiblio.org/obp/thinkCSpy/

 2. Play with Python from the command line first, using PyShell,
 PyCrust, or any of its other siblings that come with the wxPython
 package (a GUI toolkit - see #8 below).  You will find the code
 completion feature and the syntax helper quite useful.

 3. Tinker around with the builtin modules.  There's a lot of built-in
 functionality in Python right out of the box. Try the os and sys
 modules to experiment with filesystem handling. Try reading and
 writing text files, as this is quite a common task with a variety of
 applications. Try the struct module for binary file processing.  Try
 the urllib and urllib2 modules for loading and processing Web
 pages... I could go on, but you get the idea.

 4. If you have a text processing background, dip your hand in regular
 expressions with the re module. Maybe you have a need for extracting
 some statistical data from a financial report, and this might be one
 way to do it.

 5. If you have a mathematical background, download and install the
 NumPy or SciPy package and do some wild matrix math!

 6. I have recently tinkered with the Pymedia package, perhaps you want
 to try it later on.  It is a nice tool for dealing with audio - for
 recording, encoding, decoding, spectrum analysis, etc.  In just a few
 hours, I came up with a nice voice-activated MP3 sound recorder
 application.

 7. If you feel brave and want to work with Windows COM client/server
 stuff (assuming Windows is your platform), get the PythonWin package,
 also known as win32com and try to read/write Excel, Word files,
 etc., or whatever

 8. Last but certainly not least, once you feel comfortable with basic
 Python, try GUI development.  Several gui toolkits are out there.
 wxPython is a good one to start with, though you may find some others
 to your liking.

 9. If you have previous programming experience, try taking an
 application you've developed before and port it to Python.  See how
 much your code base shrinks compared to its C++ or Java counterpart :)
 But really, do it just to understand Python on a deeper level. Instead
 of thinking in the old way, try to think in the Pythonic way.  A nice
 example of this is iteration.  Where an iteration counter variable is
 required in most other languages, Python inherently supports iteration
 in sequence objects like lists, strings, and dictionary keys; so the
 syntax is simpler in most cases.

 -Basilisk96

 I choose python with a goal in mind the language was not
important..  Python is fantastic for input and output..  Once in a
while I get stuck and to be honest if I had a little more cash I would
be putting a small project on rent a coder that said tracker software
where the notes are defined in collums are great for practicing input
output, I can always do that myself but if there is a interest (or if
a intresting idea presents itself because small projects can be
linked) then I am game...  good luck to all of you and happy learning

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


Re: What makes an iterator an iterator?

2007-04-18 Thread Paul McGuire
On Apr 18, 3:32 am, Steven D'Aprano [EMAIL PROTECTED]
wrote:
 On Wed, 18 Apr 2007 06:13:39 +, I V wrote:
  On Wed, 18 Apr 2007 15:39:22 +1000, Steven D'Aprano wrote:
  I thought that an iterator was any object that follows the iterator
  protocol, that is, it has a next() method and an __iter__() method.

 [snip]

  i.e., just rename your _next function to __iter__ . Your class won't
  itself be an iterator, but it will be usable in for statements and so one,
  and convertable to an iterator with the iter builtin.

 Thanks to all those who helped, this fixed my problem.

 For the record, this is what I actually wanted: a four-line self-sorting
 dictionary:

 class SortedDict(dict):
 def __iter__(self):
 for key in sorted(self.keys()):
 yield key

 Note that using sorted(self) does not work.

 Iterating over a SortedDictionary returns the keys in sorted order. This
 minimalist implementation doesn't sort the values, items or string
 representation of the dict, but they should be easy to implement.

 --
 Steven D'Aprano

Very neat.  Why not this?

class SortedDict(dict):
def __iter__(self):
return iter(sorted(self.keys()))

-- Paul

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


Re: Strange terminal behavior after quitting Tkinter application

2007-04-18 Thread Chris

 What happens if you type 'stty sane' (and of course, a carriage
 return) afterwards?

The terminal returns to normal, thanks!

But does anyone know why the Tkinter program is doing this to the
terminal in the first place? I don't want to have to tell users of my
program that they must recover their terminal's sanity each time after
running my program.

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


exception just to avoid output error (newbie)

2007-04-18 Thread Flyzone
Hi
I'm trying to delete some files, but i get an exception error if the
file don't exist.
I can use an {if fileexist(file) then delete}, but it will get cpu
time.
So i catch the exception with:
   try: os.remove(filename)
   except EnvironmentError: error=1
If i just want to avoid the output error, is this the right way to
write the code?
I don't care of get if is in error, but an except EvironmetError
without the : will give me a sytax error.
Am I too much complicated? :-)

Thanks in advance

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


Re: is laziness a programer's virtue?

2007-04-18 Thread Ingo Menger
On 18 Apr., 01:54, Lew [EMAIL PROTECTED] wrote:
 Markus E Leypold

  Trying to correct Xah's behaviour is probably impossible.
 Ingo Menger wrote:
  Perhaps somebody could ask the chinese government to put him in jail
  for hurting international society :)

 Y'know, even in jest, calling for an oppressive regime to suppress even
 wrong-headed and self-serving garbage self-expression is immoral and horrible.

You're right. I confess this joke was going too far.

 Free speech, free press and free expression of ideas is not something to take
 so lightly.

I'm with you on this point.
But, since the biggest crime in Xah Lee's opinion apparently is
harming and damaging society through expression of ideas, it must
be possible to judge him by his own standards.


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


Re: How to communicate via USB port

2007-04-18 Thread Paul McGuire
On Apr 18, 12:54 am, [EMAIL PROTECTED] [EMAIL PROTECTED]
wrote:
 Can someone explain how I would read the data from the USB port? I
 don't know if it matters, but I am trying to read the data from a GPS
 plugged in to the USB port.

 Thank you,
 Robin

Just a guess, but can you use pyserial to talk to USB001?

-- Paul

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


Re: exception just to avoid output error (newbie)

2007-04-18 Thread James Stroud
Flyzone wrote:
 Hi
 I'm trying to delete some files, but i get an exception error if the
 file don't exist.
 I can use an {if fileexist(file) then delete}, but it will get cpu
 time.
 So i catch the exception with:
try: os.remove(filename)
except EnvironmentError: error=1
 If i just want to avoid the output error, is this the right way to
 write the code?
 I don't care of get if is in error, but an except EvironmetError
 without the : will give me a sytax error.
 Am I too much complicated? :-)
 
 Thanks in advance
 

You got it! Not to complicated--just right. I would make the tiniest of 
changes for style and speed:

try:
   os.remove(filename)
except EnvironmentError:
   pass

But what you have already is fine.

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


How? Movable yet? Click here to join!

2007-04-18 Thread blackjay
How? Movable yet? Click here to join!
AsiaFriendFinder
http://www.9fy.cn/love/friends/

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

unicode data - accessing codepoints FFFF on narrow python builts

2007-04-18 Thread vbr
Hi all,
I'd like to ask about the usage of unicode data on a narrow python build.
Unicode string literals \N{name} work even without the (explicit) import of 
unicodedata and it correctly handles also the  wider unicodes planes - over 


  u\N{LATIN SMALL LETTER E}
u'e'
  u\N{GOTHIC LETTER AHSA}
u'\U00010330'

The unicode data functions works analogous in the basic plane, but behave 
differently otherwise:

  unicodedata.lookup(LATIN SMALL LETTER E)
u'e'
 unicodedata.lookup(GOTHIC LETTER AHSA)
u'\u0330'

(0001 gets trimmed)

Is it a bug in unicodedata, or is this the expected behaviour on a narrow build?

Another problem I have is to access the characters and their properties by 
the respective codepoints:
under  it is possible, to use unichr(), which isn't valid for higher 
valules on a narrow build
It is possible to derive the codepoint from the surrogate pair, which would be 
usable also for wider codepoints.

Currently, I'm using a kind of parallel database for some unicode ranges above 
, but I don't think, this is the most effective way.
I actually found something similar at http: / / 
inamidst.com/phenny/modules/codepoint.py  using directly the UnicodeData.txt;

but I was wondering, If there is a simpler way for doing that; it seems 
obvious, that the data are present, if it could be used for constucting unicode 
literals.

Any hints are welcome,   thanks.

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


Re: Python Feature Request: Allow changing base of member indices to 1

2007-04-18 Thread Bjoern Schliessmann
Dustan wrote:

 For newbies, it's easier to count starting with 1. It's rather
 unintuitive to start at 0.

Cool. So Python will become a newbie language, and everyone
that jumps from Python to a different language will have to
relearn 0-based indices? ;)
 
Regards,


Björn

-- 
BOFH excuse #418:

Sysadmins busy fighting SPAM.

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


2.5 from source install problem with extensions

2007-04-18 Thread Florian Demmer
Hi!

I am doing a from source installation of Python 2.5 on some old Debian
machine. As the target directoy I want /opt/somename so i added it to
the configure like so:

./configure --prefix=/opt/somedir

The following make works fine as far as I can see. Then the make
install also actually works and installs python in /opt/somedir with
all its subdirectoris (bin, lib, man, include).
The extensions (*.so) however get put in /usr/local/lib/... and there
also in the wrong python directoy: 2.4

This is a c/p of the make install output:
[...]
running build_scripts
running install_lib
changing mode of /usr/local/lib/python2.4/site-packages/_struct.so to
755
changing mode of /usr/local/lib/python2.4/site-packages/_ctypes.so to
755
[...]

(How) can I change the install_dir for the extensions?
Why does it use python2.4 anyway?! What env var or else is set here
that I cannot find?

thanks!

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


array{uint32}

2007-04-18 Thread Robert Rawlins - Think Blue
Guys,

 

I have a function that returns a array{uint32}, is there any way to output
that to screen in a more user friendly format? At the moment when I print it
by itself it appears as [65541L], which isn't much used to anyone.

 

I know this is probably a REALLY dumb question but I'm a little lost with
this API, its driving me nuts.

 

Thanks again guys,

 

Rob

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

Re: What makes an iterator an iterator?

2007-04-18 Thread Peter Otten
Steven D'Aprano wrote:

 class SortedDict(dict):
 def __iter__(self):
 for key in sorted(self.keys()):
 yield key
 
 Note that using sorted(self) does not work.

That's because sorted() invokes __iter__() if present. To prevent the
recursion you can explicitly invoke dict.__iter__():

 class SortedDict(dict):
... def __iter__(self):
... return iter(sorted(super(SortedDict, self).__iter__()))
...
 sd = SortedDict(a=1, b=2, c=3)
 list(sd)
['a', 'b', 'c']

Note that a list of keys is still built before the first key is yielded,
and, unlike dict, you can modify your SortedDict while iterating over it:

 for k in sd:
... if k == b: sd[x] = 42
...
 sd
{'a': 1, 'x': 42, 'c': 3, 'b': 2}

whereas:

 d = dict(a=1, b=2, c=3)
 for k in d:
... if k == b: d[x] = 42
...
Traceback (most recent call last):
  File stdin, line 1, in module
RuntimeError: dictionary changed size during iteration

By the way, I think it would be worthwile to change super() to allow
e. g. super(SomeClass, self)[...] as an alternate spelling for
super(SomeClass, self).__getitem__(...) etc. With such an enhancement
SortedDict would become

class SortedDict(dict): 
def __iter__(self):
# doesn't work in current Python
iter(sorted(super(SortedDict, self))) 


Peter

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


Re: What makes an iterator an iterator?

2007-04-18 Thread Georg Brandl
Stefan Rank schrieb:
 on 18.04.2007 07:39 Steven D'Aprano said the following:
 I thought that an iterator was any object that follows the iterator
 
 replace object with instance of a class, i.e. the relevant methods are 
 looked up in the __class__ not in the instance (I think).
 I had the same troubles trying to dynamically reassign a __call__ method...

This is correct.

It's not properly documented though, and not applied consistently, e.g.
__enter__ and __exit__ are looked up in the instance itself.

Georg

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


Re: Python Feature Request: Allow changing base of member indices to 1

2007-04-18 Thread Antoon Pardon
On 2007-04-14, Paddy [EMAIL PROTECTED] wrote:
 On Apr 14, 11:27 am, [EMAIL PROTECTED] wrote:
 This is like the previous one. Please check for sanity and approve for
 posting at python-dev.

 I would like to have something like option base in Visual Basic.
 IIRC it used to allow me to choose whether 0 or 1 should be used as
 the base of member indices of arrays. In Python, the same can be used
 with strings, lists, tuples etc.

 This would mean:
 foo = foo
 = foo[1] == 'f'

 foo = ['foo', 'bar', 'spam' ]
 = foo[1] == 'foo'

 foo = ('spam', 'eggs')
 = foo[1] == 'spam'

 For convenience it should also affect the range function so that:

 range(3) = [1, 2, 3]

 because this is often used where arrays would be used in VB.

 Finally, when the programmer does not specify his choice of base at
 the beginning of the program, the current behaviour of using 0 as base
 should continue so that there is no problem with backward
 compatibility.

 Here is a document giving good reasons for indexing to start at
 zero, as in Python.

I find he just picks the reasons he agrees with.

If you pick your values as a = i = b it has the advantage that
the bounds are explicit. No need to add or substract 1 from
one of the values to get the exact boundis. Now how much weight
you want to give this characteristic is open for debate but
the fact that it isn't even mentioned doesn't give me much
confidence in the author's ability to weight all the pro's
and con's.

 http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html
 The author has done a bit:
 http://en.wikipedia.org/wiki/Dijkstra

 Having more than one index start point would be a maintenance
 nightmare best avoided. (It can be done in Perl).

It was never a problem when I still programmed in Pascal.

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


Re: multiremberco

2007-04-18 Thread Anton Vredegoor
[EMAIL PROTECTED] wrote:

 I have modified, simplified and (hopefully) improved Steven's code
 like this (but it may be a bit slower, because the class It is inside
 the function?):

Here is a yet more simple version, I wonder if it still does the same 
thing, whatever it is you are looking for :-)

def xsplitter(iseq, pred):

 class It(object):
 def __init__(self, fun, parity):
 self.divert = fun
 self.parity = parity
 self.queue = collections.deque()

 def append(self, item):
 self.queue.append(item)

 def __iter__(self):
 while self.queue:
 yield self.queue.popleft()
 for item in iseq:
 if pred(item) == self.parity:
 yield item
 else:
 self.divert(item)
 for x in self:
 yield x

 it1 = It(lambda y: it2.append(y), True)
 it2 = It(lambda y: it1.append(y), False)
 return it1, it2

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


no trace of PyRun_SimpleString() ???

2007-04-18 Thread iwl
Hi,

it seems like I can't trace scripts run by PyRun_SimpleString():

a=0
def test(frame, event, arg):
 global a
 a+=1

import sys
sys.settrace(test)
print a
print a
print a

-
0
0
0

Does anybody know how I can get something similar with the
C-Funcs for Tracing??

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


Re: Future Python Gui?

2007-04-18 Thread kirkjobsluder
On Apr 18, 2:07 am, Richard Jones [EMAIL PROTECTED]
wrote:
 kirkjobsluder wrote:
  I'd say that the best bet is to learn swig and similar
  bridging, expanding, and embedding mechanisms.

 For GUI programming this would seem overkill. Pick a GUI toolkit and it's
 almost guaranteed to be wrapped for use in Python already.

Perhaps a bit.  I'm not saying that everyone should wrap their own
code,
but many of the currently existing wrappers are quite thin, and
understanding
how to use and debug wrapped GUI code might put one in a better
position
over knowing a particular toolkit.



 Richard


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


Re: 2.5 from source install problem with extensions

2007-04-18 Thread Florian Demmer
On Apr 18, 12:36 pm, Florian  Demmer [EMAIL PROTECTED] wrote:
 Hi!

 I am doing a from source installation of Python 2.5 on some old Debian
 machine. As the target directoy I want /opt/somename so i added it to
 the configure like so:

 ./configure --prefix=/opt/somedir

 The following make works fine as far as I can see. Then the make
 install also actually works and installs python in /opt/somedir with
 all its subdirectoris (bin, lib, man, include).
 The extensions (*.so) however get put in /usr/local/lib/... and there
 also in the wrong python directoy: 2.4

...and the current /usr/bin/python symlink points to the 2.4
installation (from .deb)

 This is a c/p of the make install output:
 [...]
 running build_scripts
 running install_lib
 changing mode of /usr/local/lib/python2.4/site-packages/_struct.so to
 755
 changing mode of /usr/local/lib/python2.4/site-packages/_ctypes.so to
 755
 [...]

 (How) can I change the install_dir for the extensions?
 Why does it use python2.4 anyway?! What env var or else is set here
 that I cannot find?

 thanks!


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


X root Operator help

2007-04-18 Thread lucidparadox
I'm currently new to Python and I haven't been able to find the
operator/math function to find the square root or even the x root of a
number.  I'm rewriting a program that I wrote in BASIC that does the
math of a quadratic equation (user puts in a, b, and c values) and
tells the user whether it has 1 root, 2 roots, or no real roots and
displays the roots if it has real roots.

Thanks in advance,
Dan

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


Re: X root Operator help

2007-04-18 Thread Tim Golden
lucidparadox wrote:
 I'm currently new to Python and I haven't been able to find the
 operator/math function to find the square root or even the x root of a
 number.  

Without ever having used it, I would guess
it's the sqrt function in the math module.

(Possibly also of interest: the pow function
in that same module)


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


Re: Signals

2007-04-18 Thread Carsten Haese
On Wed, 2007-04-18 at 08:39 +0100, Robert Rawlins - Think Blue wrote:
 Hello Chaps,
 
  
 
 I posted about this the other day but I’m still struggling to get any
 form of result from it. Basically I have the following piece of code,
 and according to its API is produces singals when particular events
 occur, but i have no idea how to list for events, I’ve tried all sorts
 of combinations using the signal module but haven’t been able to get
 it working.
 [...]
 import dbus, signal
 [...]

 Now here is a copy of the API documentation that lists the signals
 thrown by the API, this is the one I’m trying to listen for.
 
  
 
 void RemoteDeviceFound(string address, uint32 class, int16
 rssi)
 
  
 
This signal will be send every time an inquiry result
 
has been found by the service daemon. In general they
 
only appear during a device discovery.
 
  
 
 Basically I’m just looking to run a function that will print those
 details to screen. Can anyone help with working out how to listen for
 this signal?

The signal module is for handling process signals the operating system
sends to your python process. The API you're using (dbus, a crucial
detail you neglected to mention before) doesn't send this kind of
signal.

Googling for 'python dbus documentation' brings up
http://dbus.freedesktop.org/doc/dbus-python/api/ , which seems to
explain everything you need. You need to get an instance of
dbus.Interface, which you seem to have done, and call its
connect_to_signal() method, which you don't seem to have done.

  I’d also like to know how i can keep the application running until I
 decided to stop it manually, as the DiscoverDevices() can take a while
 to complete and send out several RemoteDeviceFound() signals in that
 period.

The very first section of the above mentioned documentation talks about
needing a main loop for receiving signals, and it provides example
boilerplate code for how to set up a main loop.

Hope this helps,

Carsten.


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

Python crash after using weave inline

2007-04-18 Thread Soren
Hi,

I have a strange and very annoying problem when using weave in scipy..
when I run the code below.. the first time it needs to compile.. it
says compiling and then python.exe crashes! and no result is shown..
the second time i run it, it does not compile but gives the completely
wrong answer.. prints a matrix of all zeros except for point 1,1 in
the matrix which seems to have some random high number like
-5.39403959e+08.  !!??

Basicly I run through a 10 by 10 matrix do some calculations with
respect to some center values x_c and y_c and insert the result into
the empty numpy matrix array res.

Any help is appreciated!

Thanks,
Sroren


from numpy import *
from scipy import weave
from scipy.weave import converters

def cartPolFast(xlen, ylen, x_c, y_c):

res = zeros((xlen,ylen))

code = 
{
int xlen, ylen, x_c, y_c;
double rel_x, rel_y;
int x, y;

for( x = 0; x == xlen; x++)
   for( y = 0; y == ylen; y++)
rel_x = x-x_c;
rel_y = y_c-y;

res(x,y) = rel_y*rel_y;
}


weave.inline(code,['xlen','ylen','x_c','y_c','res'],
type_converters=converters.blitz, compiler=gcc)

return res


if __name__ == __main__:

tst = cartPolFast(10,10,5,5)
print tst

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


Re: X root Operator help

2007-04-18 Thread Michael Hoffman
lucidparadox wrote:
 I'm currently new to Python and I haven't been able to find the
 operator/math function to find the square root or even the x root of a
 number.

For square root, use math.sqrt(y)

For x root use y**(1/x)

  I'm rewriting a program that I wrote in BASIC that does the
  math of a quadratic equation (user puts in a, b, and c values) and
  tells the user whether it has 1 root, 2 roots, or no real roots and
  displays the roots if it has real roots.

In floating point arithmetic, the naive way of calculating both roots 
always using the formula (-b +/- sqrt(b**2 - 4*a*c))/2*a will give you 
inaccurate results sometimes. See 
http://www.cse.uiuc.edu/eot/modules/floating_point/quadratic_formula/.

For a better formula, see how r_1 and r_2 are defined in 
http://en.wikipedia.org/wiki/Quadratic_equation#Alternative_formula.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: please sort this out

2007-04-18 Thread piyali biswas

hi all,
I solved the problem with the help of python cookbook+matplotlib
I was getting the main error as *
raise RuntimeError('%s' is not a writable dir; you must set
environment variable HOME to be
*
* a writable dir %h)*
Matplotlib needs the environment variable HOME to point to a writable
directory.Thats why i did
os.environ[ 'HOME' ] = 'C:/temp'
and the cgi-script worked.
For further questions about cgi+matplotlib/networkx please see
http://www.scipy.org/Cookbook. Its very useful

Thanks,
Piyali Biswas

On 4/16/07, piyali biswas [EMAIL PROTECTED] wrote:


 Hi,
I am using networkx and pylab for creating a graph using a python script
abc.py.
I have saved the networkx folder in C:/Python24/Lib/site-packages.
When I run the script from command prompt, it creates the graph and saves
it to the place I want to but when I write a python-cgi script and run it as

os.system('python abc.py')
it doesn't gives me any result.

I have included the path of my system using
os.environ['PATH'] = ..

I also appended the path of networkx directory using
sys.path.append('C:/Python24/Lib/site-packages') as it seems to me that it
is a path related problem and the cgi result page shows error
(1) networkx *undefined*
(2)* *drawing undefined
(3) nx_pylab *undefined*
(4) matplotlib *undefined*
*(5)
raise RuntimeError('%s' is not a writable dir; you must set environment 
variable HOME to be
*
* a writable dir %h)*
Can you please tell me how to enable cgi to run this program on runtime. I
have kept both the cgi script as well as python script in Apache/cgi-bin
folder.

Thanks,
Piyali

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

Wanted: Email Client with GUI

2007-04-18 Thread Franz Steinhaeusler
Hi, although I have googled, I didn't find a Python 
email client program fitting to my needs.

What I want is a program (it doesn't have to be so sophisticated
as thunderbird) written totally in python and using a gui 
toolkit like pyqt, pygtk, wxpyhton or tkinter.

Who knows such a program? ;)

best regards, 

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


Re: Win32com, and Excel issues.

2007-04-18 Thread kyosohma
On Apr 18, 2:38 am, Ant [EMAIL PROTECTED] wrote:
 Hi all,

 I'm doing some Excel automation work for a friend, and am developing
 on a machine running Office 2000. My friends machine is running Excel
 2003. The code I've written works like a charm on my machine (in fact
 all three of my machines), but falls over early on on Excel 2003.

 The code snippet it falls over on is code to copy one worksheet after
 another:

 app = wincl.Dispatch(Excel.Application)
 app.Visible = True
 app.Workbooks.Open(self.filename)
 sheet = app.Worksheets(1)
 sheet.Copy(None, sheet)

 and this last line throws the following exception:

 pywintypes.com_error: (-2147417851, 'the server threw an exception.'
 , None, None)

 which isn't too helpful.

 I'm wondering if something has changed in the Excel API that doesn't
 allow a null parameter to Copy or some similar issue. I tried using
 the keyword argument format, but that simply refused to work.

 Other relevant information:

 * The program is packaged using py2exe, so I know that the same
 version of Python, and the same libraries are on each machine.
 * One of the test machines running Excel 2000 does not have Python
 installed.
 * The machines are all of a similar spec.

 Any ideas are welcome!

I can't find anything about copying a worksheet, but I found a some
fairly detailed information about COM objects and getting more
information about Python's bindings to them here:
http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html or here:
http://mathieu.fenniak.net/plotting-in-excel-through-pythoncom/

Hopefully this will give you some pointers.

Mike


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


Re: Help on Shelve....

2007-04-18 Thread Clement
On Apr 17, 5:52 pm, Michael Bentley [EMAIL PROTECTED] wrote:
 On Apr 17, 2007, at 6:52 AM, Clement wrote:

  Can i useShelvefor storing large amount of data around 6GB.. Is it
  stable...? if any problems come, can i retrive the document..

 Do you know for sure your filesystem handles files that big?

I am using NTFS that can hold more that 500GB of data

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


Re: python - dll access (ctypes or swig)

2007-04-18 Thread Larry Bates
Alex Martelli wrote:
 Larry Bates [EMAIL PROTECTED] wrote:
 
  recently learned that you can ship COM as either an .EXE or a .DLL (nobody
 has yet let me know why).
 
 The why is pretty obvious -- you may want to be able to instantiate a
 COM object either in-process, or in its own separate process, depending
 on that object's nature.  For example, a complete application that when
 running exposes COM objects to let other processes drive/script it will
 be an EXE file since it can also run independently.
 
 In general I'm no big fan of MS's design, but COM, despite its
 imperfections, was in fact seriously good (Don Box's Essential COM, an
 excellent book, went just into enough depth to let a developer really
 appreciate that, IMHO).  I'm using the past tense because MS has been
 trying to kill COM for a while now (but I notice that Essential COM,
 while 10 years-old, is _still_ in stock at Amazon -- so, I guess that so
 far MS's attempts haven't _quite_ succeeded yet:-).
 
 
 Alex

I guess I was the only one it wasn't obvious to grin.  I've always
written my COM servers as .EXE files even though they cannot be run
independently.  What I find is odd is that I can create a .DLL or an
.EXE of my COM server and after I register it, my application doesn't
appear to know the difference.  The difference seems to be hidden from
the actual application and doesn't affect it (at least that I can
determine).

I also think COM works quite well and I've found it much easier to use
than C-style DLLs that many vendors ship as their API.  Most of what
I've learned came from Mark/Andy's Python Programming on Win32 and
trial-and-error so my knowledge is quite limited.

Thanks for the info.

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


Re: How to Passs NULL as a IDispatch Pointer to method?

2007-04-18 Thread Larry Bates
Yingpu Zhao wrote:
 Thanks to Larry.
 I want to pass the IDispatch pointer of other COM object to
 AddShapeInfo or pass null to tell x do nothing.
 for example.
 
 Rect= Dispatch(Rect.Document)
 ShapeSet = Dispatch(xxx.Document)
 ShapeSet.AddShapeInfo(Rect, 0, Shape)
 
 or
 
 ShapeSet.AddShapeInfo(EmptyShape, 0, None)
 
I think you will need to pass a basically empty class that
is wrapped in an IDispatch object.  See my earlier example.

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


Re: Calling private base methods

2007-04-18 Thread Isaac Rodriguez

 C++'s and Java's approaches are vitiated by an unspoken assumption that
 the library's designer is some kind of demigod, while the writer of code
 that uses the library is presumably still struggling with the challenge
 of opposable thumbs.  

That might be  your point of view. To me, the library designer is the
one that has done the homework and should know better how to simplify
things for others not a God. No one uses a high level library if
implementing the low-level your self is easier. Libraries provide
functionality that allow the application programmer to concentrate in
what he is being paid for, making the application. An application
programmer will have to define what the correct interface for the
application is (for example, what UI to provide). There will be users
that will say, I wish this application had a way of doing this, but
unless they were technically savy and wanted to spend the necessary
time to understand how the application works, they would not write the
feature themselves; they will request that feature to the programmer.



 In real life, the skills of the two people in
 question are likely to be much closer, and since designing libraries for
 use in all kinds of applications is a really hard task, it's likelier
 than the library designer will make an error in designing his or her
 library, rather than the application programmer in using that library.

Those are called defects or bugs. When I find a bug in a library or
an application, I submit a bug report. I might have to work around it
for a little bit, but I don't just work around it and call it goods.
Library designers are normal programmers that work under a set of
requirements like any other programmer (application programmers
included), but when I find a bug in an application, I report it and
try to work around it until it gets fixed; I don't hack the
application or re-write my own just because a found a bug.


 Purely-advisory encapsulation approaches, like Python's, even the odds.
 Actually, I'd argue that even double-leading-underscores are overkill
 more often than not (and single-leading-underscores the compromise that
 is generally prefereable).

You see it as an intelligence challenge, where I see it as making
things easier for everybody.

Thanks,

- Isaac.


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


Re: Help on Shelve....

2007-04-18 Thread Clement
On Apr 17, 5:52 pm, Michael Bentley [EMAIL PROTECTED] wrote:
 On Apr 17, 2007, at 6:52 AM, Clement wrote:

  Can i useShelvefor storing large amount of data around 6GB.. Is it
  stable...? if any problems come, can i retrive the document..

 Do you know for sure your filesystem handles files that big?

I am using NTFS filesystem that can handle more than 500GB files

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


Re: What makes an iterator an iterator?

2007-04-18 Thread Isaac Rodriguez

 class Parrot(object):
 def __iter__(self):
 return self
 def __init__(self):


Typo right here

 self.next = self._next()

write:
self.next = self._next

no parenthesis.

 def _next(self):
 for word in Norwegian Blue's have beautiful plumage!.split():
 yield word



See previous explanation.

thanks,

- Isaac.

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


Re: looking for library to read ppt files

2007-04-18 Thread Aljosa Mohorovic
  Not really a Python question but Google turned up:
it is a python question. i'm not looking for a program, i'm looking
for a library.
my goal is to convert ppt to jpegs but later i wish to convert to swf
and maybe implement animations

 I suppose you could also use the win32 module and the COM object to
 grab the info from the slide and then use the PIL module to create a
 jpeg. Sounds like a lot of head banging to me, but it might be an
 interesting project.
i can't use win32 because it should work on linux since it will be
used as server-side application.

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


Re: What makes an iterator an iterator?

2007-04-18 Thread Isaac Rodriguez

Sorry, my previous post was incomplete. I didn't realized that you
implemented _next() as a generator funcition. Besides changing
__init__() from

self.next = self._next()

to
self.next = self._next

you need to implement __iter__() as:

return self.next()


 class Parrot(object):
 def __iter__(self):
 return self
 def __init__(self):
 self.next = self._next()
 def _next(self):
 for word in Norwegian Blue's have beautiful plumage!.split():
 yield word


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


Re: Calling private base methods

2007-04-18 Thread Isaac Rodriguez

 After all, that's what duck-typing is about. There is no official
 interface declaration, just an implicit protocol. And private methods
 or members are part of that protocol as well.


I don't think so. Duck-typing is about implementing the expected
public interface, and has nothing to do with accessing private members
of a class, nor overriding those members.

- Isaac.

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


solved

2007-04-18 Thread piyali biswas

hi all,
I solved the problem with the help of python cookbook+matplotlib
I was getting the main error as *
raise RuntimeError('%s' is not a writable dir; you must set
environment variable HOME to be
*
* a writable dir %h)*
Matplotlib needs the environment variable HOME to point to a writable
directory.Thats why i did
os.environ[ 'HOME' ] = 'C:/temp'
and the cgi-script worked.
For further questions about cgi+matplotlib/networkx please see
http://www.scipy.org/Cookbook. Its very useful

Thanks,
Piyali Biswas
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Help on Shelve....

2007-04-18 Thread Clement
On Apr 17, 5:52 pm, Michael Bentley [EMAIL PROTECTED] wrote:
 On Apr 17, 2007, at 6:52 AM, Clement wrote:

  Can i useShelvefor storing large amount of data around 6GB.. Is it
  stable...? if any problems come, can i retrive the document..

 Do you know for sure your filesystem handles files that big?

I am using NTFS that can hold more that 500GB of data

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


Re: looking for library to read ppt files

2007-04-18 Thread Carsten Haese
On Wed, 2007-04-18 at 06:30 -0700, Aljosa Mohorovic wrote:
   Not really a Python question but Google turned up:
 it is a python question. i'm not looking for a program, i'm looking
 for a library.
 my goal is to convert ppt to jpegs but later i wish to convert to swf
 and maybe implement animations
 
  I suppose you could also use the win32 module and the COM object to
  grab the info from the slide and then use the PIL module to create a
  jpeg. Sounds like a lot of head banging to me, but it might be an
  interesting project.
 i can't use win32 because it should work on linux since it will be
 used as server-side application.

How about running a headless OpenOffice instance and remote-controlling
it with pyuno:

http://udk.openoffice.org/python/python-bridge.html

-Carsten


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


Re: How to communicate via USB port

2007-04-18 Thread Grant Edwards
On 2007-04-18, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 Can someone explain how I would read the data from the USB port?

You can't.  There's no such thing from a SW point of view. ;)

 I don't know if it matters, but I am trying to read the data
 from a GPS plugged in to the USB port.

It's probably a serial device.  Try using pyserial to talk to
/dev/ttyUSB0.

-- 
Grant Edwards   grante Yow! Used staples are good
  at   with SOY SAUCE!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Wanted: Email Client with GUI

2007-04-18 Thread kyosohma
On Apr 18, 8:07 am, Franz Steinhaeusler [EMAIL PROTECTED]
wrote:
 Hi, although I have googled, I didn't find a Python
 email client program fitting to my needs.

 What I want is a program (it doesn't have to be so sophisticated
 as thunderbird) written totally in python and using a gui
 toolkit like pyqt, pygtk, wxpyhton or tkinter.

 Who knows such a program? ;)

 best regards,

I'm not finding much either. There is this: 
http://sourceforge.net/projects/usablemail/

This also looked promising: http://wiki.laptop.org/go/Email

It looks like their might be some kind of tkinter email client in the
Programming Python book by Lutz. ( See
http://proquest.safaribooksonline.com/0596000855/python2-CHP-11-SECT-4
)

Hope that helps.

Mike

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


Re: How to better pickle an extension type

2007-04-18 Thread dgdev
Thanks for your replies.

The code I showed above was pyrex code, not python code. You are
correct that python objects do not require .__reduce__() to be
picklable, but apparently c extension types do (makes sense, they must
be more opaque to the python machinery).

I'll try the .__newobj__(), see if I can get it to do what I want...

On Apr 17, 2:50 am, Ziga Seilnacht [EMAIL PROTECTED] wrote:
 dgdev wrote:
  I would like topicklean extension type (written inpyrex).  I have
  it working thus far by defining three methods:

  class C:
  # for pickling
  __getstate__(self):
  ... # make 'state_obj'
  return state_obj

  __reduce__(self):
  return C,(args,to,__init__),me.__getstate__()

  # for unpickling
  __setstate__(self,state_obj):
  self.x=state_obj.x
  ...

  This gets the class pickling and unpickling.

  However, I'd like to not specify arguments for __init__ (as I do now
  in __reduce__), and so not have __init__ invoked during unpickling.

  I would like to have the pickling machinery somehow create an
  uninitialized object, and then call its __setstate__, where I can re-
  create it from 'state_obj'.

  Is there a kosher way to do so, that is without me having to have a
  special mode in the constructor for when the object is being created
  by the unpickler?

 Why are you overwriting the __reduce__() method?  The default
 object.__reduce__() method, inherited by all new style classes,
 already does what you want.  If you really must overwrite it, and
 you don't want __init__() to get called, then you should return a
 reconstructor named __newobj__() as the first item of reduce
 tuple.  Something like this:

  def __newobj__(cls, *args):

 ... return cls.__new__(cls, *args)
 ... class C(object):

 ... def __init__(self):
 ... print I shouldn't be called at reconstruction
 ... def __reduce__(self):
 ... try:
 ... getnewargs = self.__getnewargs__
 ... except AttributeError:
 ... newargs = (self.__class__,)
 ... else:
 ... newargs = (self.__class__,) + getnewargs()
 ... try:
 ... getstate = self.__getstate__
 ... except AttributeError:
 ... # this ignores __slots__ complications
 ... state = self.__dict__
 ... else:
 ... state = getstate()
 ... # this ignores list and dict subclasses
 ... return __newobj__, newargs, state
 ... c = C()

 I shouldn't be called at reconstruction importpickle
  for proto in range(3):

 ... assert isinstance(pickle.loads(pickle.dumps(c, proto)), C)
 ...



 Ziga


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


Re: array{uint32}

2007-04-18 Thread Daniel Nogradi
 I have a function that returns a array{uint32}, is there any way to output
 that to screen in a more user friendly format? At the moment when I print it
 by itself it appears as [65541L], which isn't much used to anyone.

I'm not sure I understand your question precisely but this might help:

 mylist = [65541L]
 mylist
[65541L]
 mylist[0]
65541L
 int(mylist[0])
65541

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


Re: Wanted: Email Client with GUI

2007-04-18 Thread Franz Steinhaeusler
On 18 Apr 2007 07:09:29 -0700, [EMAIL PROTECTED] wrote:

On Apr 18, 8:07 am, Franz Steinhaeusler [EMAIL PROTECTED]
wrote:
 Hi, although I have googled, I didn't find a Python
 email client program fitting to my needs.

 What I want is a program (it doesn't have to be so sophisticated
 as thunderbird) written totally in python and using a gui
 toolkit like pyqt, pygtk, wxpyhton or tkinter.

 Who knows such a program? ;)

 best regards,

I'm not finding much either. There is this: 
http://sourceforge.net/projects/usablemail/

This also looked promising: http://wiki.laptop.org/go/Email

It looks like their might be some kind of tkinter email client in the
Programming Python book by Lutz. ( See
http://proquest.safaribooksonline.com/0596000855/python2-CHP-11-SECT-4
)

Hope that helps.

Mike

Thanks, that I also found already.

I know XPN, which has also some email functionality.

I only wonder, why there doesn't exist a nice one.

Oh, I here, why do you not write such a thing yourself?

It fails on lack of time. ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: X root Operator help

2007-04-18 Thread lucidparadox
On Apr 18, 8:52 am, Michael Hoffman [EMAIL PROTECTED] wrote:
 lucidparadox wrote:
  I'm currently new to Python and I haven't been able to find the
  operator/math function to find the square root or even the x root of a
  number.

 For square root, use math.sqrt(y)

 For x root use y**(1/x)

   I'm rewriting a program that I wrote in BASIC that does the
   math of a quadratic equation (user puts in a, b, and c values) and
   tells the user whether it has 1 root, 2 roots, or no real roots and
   displays the roots if it has real roots.

 In floating point arithmetic, the naive way of calculating both roots
 always using the formula (-b +/- sqrt(b**2 - 4*a*c))/2*a will give you
 inaccurate results sometimes. See
 http://www.cse.uiuc.edu/eot/modules/floating_point/quadratic_formula/.

 For a better formula, see how r_1 and r_2 are defined in
 http://en.wikipedia.org/wiki/Quadratic_equation#Alternative_formula.
 --
 Michael Hoffman

Thanks.  As of right now I'm just trying to familiarize myself with
the syntax of Python.  Actually I should have thought of y**(1/x).
I'm currently a freshman in college so the alternative formula hasn't
been introduced to me yet.  Thanks for the pointers though.

Dan Collins

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


Re: Calling private base methods

2007-04-18 Thread Duncan Booth
Isaac Rodriguez [EMAIL PROTECTED] wrote:

 In real life, the skills of the two people in
 question are likely to be much closer, and since designing libraries for
 use in all kinds of applications is a really hard task, it's likelier
 than the library designer will make an error in designing his or her
 library, rather than the application programmer in using that library.
 
 Those are called defects or bugs. When I find a bug in a library or
 an application, I submit a bug report. I might have to work around it
 for a little bit, but I don't just work around it and call it goods.
 Library designers are normal programmers that work under a set of
 requirements like any other programmer (application programmers
 included), but when I find a bug in an application, I report it and
 try to work around it until it gets fixed; I don't hack the
 application or re-write my own just because a found a bug.
 
You appear to have led a very sheltered life if the only libraries you ever 
use are ones where you can always get a change to the library api in a 
timely manner.

In the particular case where I hacked around a private variable, the 
library in question was burned into ROM on thousands of consumer devices. 
Getting the library to change simply wasn't an option.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Signals

2007-04-18 Thread Robert Rawlins - Think Blue
Thanks Carsten,

Sorry for not mentioning the dbus before, I thought that the signals were a 
general python thing, I didn’t realize it was a specific dbus thing.

I've now modified the code so it looks like this.

#!/usr/bin/python

import dbus
from gobject import MainLoop, idle_add
from dbus.mainloop.glib import DBusGMainLoop

def main_function():
bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object('org.bluez', 
'/org/bluez'),'org.bluez.Manager')
adapter = dbus.Interface(bus.get_object('org.bluez', 
manager.DefaultAdapter()),'org.bluez.Adapter')

def remote_device_found(addr, class_, rssi):
print 'Found:', addr

adapter.connect_to_signal('RemoteDeviceFound', remote_device_found)

adapter.DiscoverDevices()

if __name__ == '__main__':
idle_add(main_function)
dbus_mainloop_wrapper = DBusGMainLoop(set_as_default=True)
mainloop = MainLoop()
mainloop.run()

Which should implement the main loop and keep the application alive, however 
when running the program I get the following error thrown at me.

File ./scan4.py, line 5, in ?
from dbus.mainloop.glib import DBusGMainLoop
ImportError: No module named mainloop.glib

Any ideas what might be causing this? My guess is that I don’t have one of the 
dependency installed properly, but I have no idea which ones I need.

Thanks for any more help you can offer, its greatly appreciated.

Rob 
-Original Message-
From: Carsten Haese [mailto:[EMAIL PROTECTED] 
Sent: 18 April 2007 13:43
To: Robert Rawlins - Think Blue
Cc: python-list@python.org
Subject: Re: Signals

On Wed, 2007-04-18 at 08:39 +0100, Robert Rawlins - Think Blue wrote:
 Hello Chaps,
 
  
 
 I posted about this the other day but I’m still struggling to get any
 form of result from it. Basically I have the following piece of code,
 and according to its API is produces singals when particular events
 occur, but i have no idea how to list for events, I’ve tried all sorts
 of combinations using the signal module but haven’t been able to get
 it working.
 [...]
 import dbus, signal
 [...]

 Now here is a copy of the API documentation that lists the signals
 thrown by the API, this is the one I’m trying to listen for.
 
  
 
 void RemoteDeviceFound(string address, uint32 class, int16
 rssi)
 
  
 
This signal will be send every time an inquiry result
 
has been found by the service daemon. In general they
 
only appear during a device discovery.
 
  
 
 Basically I’m just looking to run a function that will print those
 details to screen. Can anyone help with working out how to listen for
 this signal?

The signal module is for handling process signals the operating system
sends to your python process. The API you're using (dbus, a crucial
detail you neglected to mention before) doesn't send this kind of
signal.

Googling for 'python dbus documentation' brings up
http://dbus.freedesktop.org/doc/dbus-python/api/ , which seems to
explain everything you need. You need to get an instance of
dbus.Interface, which you seem to have done, and call its
connect_to_signal() method, which you don't seem to have done.

  I’d also like to know how i can keep the application running until I
 decided to stop it manually, as the DiscoverDevices() can take a while
 to complete and send out several RemoteDeviceFound() signals in that
 period.

The very first section of the above mentioned documentation talks about
needing a main loop for receiving signals, and it provides example
boilerplate code for how to set up a main loop.

Hope this helps,

Carsten.



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

Re: python - dll access (ctypes or swig)

2007-04-18 Thread Daniel Watrous
thank you for the responses and the links.  I will give these ideas a
try this week and post again if I have more questions.  Thanks again
for being so helpful!

Daniel

On 4/17/07, Cameron Laird [EMAIL PROTECTED] wrote:
 In article [EMAIL PROTECTED],
 Larry Bates  [EMAIL PROTECTED] wrote:
 Daniel Watrous wrote:
  Hello,
 
  I am interested in using python to script access to some hardware for
  which there are existing drivers in the form of DLLs.  The DLLs each
  have four exported functions and a host of COM Properties and COM
  Methods.  The four exported functions are as follows:
  DllCanUnloadNow
  DllGetClassObject
  DllRegisterServer
  DllUnregisterServer
 
  The COM methods and properties all begin with I, followed by a unique name.
 
  I am able to load the DLL using ctypes and it can access the exported
  functions, but I'm not sure how to access the COM methods and
  properties.  I have read that ctypes once had support for COM but that
  it has since been separated into its own project.  I couldn't find any
  information about how these work together.
 
  All help is appreciated.  THANKS in advance...
 
  Daniel
 
 I recently learned that you can ship COM as either an .EXE or a .DLL (nobody
 has yet let me know why).  You don't have a traditional .DLL that you would
 use ctypes to call methods in, you have a COM .DLL.  COM methods need to be
 access with Win32com
 
 obj=win32com.client.Dispatch(typelib name).
 
 You need to find out the COM dispatch typelib name and make sure the DLL is
 registered (regsvr32 your.dll).
 
 -Larry

 Is this--adroit use of Win32com with special-purpose DLLs--written
 up anywhere?  Doing this with unusual hardware that turns up in the
 real world is ENTIRELY more satisfying than trying to wrangle the
 Visual C bindings that vendors usually push, but, apart from Mark
 and Andy's book, now over seven years old, I know of no appropri-
 ately ambitious tutorial in the subject.

 Daniel, do you have what you need to make progress?  Have you seen
 URL: http://www.oreilly.com/catalog/pythonwin32/ ?
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: The smallest and largest values of numeric types

2007-04-18 Thread [EMAIL PROTECTED]
On Apr 18, 3:09�am, Steven D'Aprano [EMAIL PROTECTED]
wrote:
 On Wed, 18 Apr 2007 07:15:11 +0200, Hendrik van Rooyen wrote:
  I once made a thing that tried to find the limit of longs and stopped
  when I had two or three screenfulls of numbers.

 You should find that converting longs to strings (say, for printing them)
 is *very* slow. E.g. the following code

 big = 10L**100 # one google, a big number
 while True:
 � � print big # so we can see the last value before it fails
 � � big *= 10

 will run terribly slow and should be written as:

 big = 10L**100 # one google, a big number
 try:
 � � while True:
 � � � � big *= 10
 except: # don't know what exception will be raised, so catch ANYTHING
 � � print len(str(big))-1 # the number of digits

 only does the slow conversion to string once, instead of every time around
 the loop. However, once your machine starts paging, it will still slow
 down a lot.

  I came to the conclusion that for integer arithmetic like this, the
  limit is either your memory size, or some other number that is so big
  that in practice you don't have to worry about it..

 Yes, longs are limited only by the amount of memory accessible.

But there may be other limitations even if you have the memory.

For example, this test is limited to generation 10
because tne 11th generation produces outrageous
exponent error. Here, every 9th 1st generation,
starting from the fifth is a second generation, every
9th sencond, starting from the fifth, is a 3rd generation,
every 9th 3rd gen, starting from the 5th is a 4th gen, etc.

Closed form: Type12MH(k,i)
Find ith, kth Generation Type [1,2] Mersenne Hailstone
using the closed form equation

2**(6*((i-1)*9**(k-1)+(9**(k-1)-1)/2+1)-1)-1

2**5-1  generation: 1
   2**29-1  generation: 2
  2**245-1  generation: 3
 2**2189-1  generation: 4
2**19685-1  generation: 5
   2**177149-1  generation: 6
  2**1594325-1  generation: 7
 2**14348909-1  generation: 8
2**129140165-1  generation: 9
   2**1162261469-1  generation:10

1.797 seconds

There is never a number too large to worry about.


 --
 Steven D'Aprano


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

Re: Help on Shelve....

2007-04-18 Thread Michael Bentley

On Apr 18, 2007, at 8:19 AM, Clement wrote:

 On Apr 17, 5:52 pm, Michael Bentley [EMAIL PROTECTED] wrote:
 On Apr 17, 2007, at 6:52 AM, Clement wrote:

 Can i useShelvefor storing large amount of data around 6GB.. Is it
 stable...? if any problems come, can i retrive the document..

 Do you know for sure your filesystem handles files that big?

 I am using NTFS filesystem that can handle more than 500GB files

Ye looks like your filesystem can theoretically handle 16tb files.   
I'm afraid I don't know the answer to your question -- seems like it  
should work ;-)  How about trying it out and reporting back?


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


Re: python - dll access (ctypes or swig)

2007-04-18 Thread Alex Martelli
Larry Bates [EMAIL PROTECTED] wrote:
   ...
 I guess I was the only one it wasn't obvious to grin.  I've always
 written my COM servers as .EXE files even though they cannot be run
 independently.  What I find is odd is that I can create a .DLL or an
 .EXE of my COM server and after I register it, my application doesn't
 appear to know the difference.  The difference seems to be hidden from
 the actual application and doesn't affect it (at least that I can
 determine).

Yes, except for performance (a DLL affords within-process communication
without the overhead of IPC, so it can be much faster when appropriate)
and some technical issues such as threading (if COM client and server
are in separate processes, their threading models are independent from
each other; if they are in the same process, they'd better have
compatible threading approaches -- a thread-unsafe DLL server can make a
single-threaded client happy but would cause problems and crashes if a
freely-threaded client tried using it).


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


pycurl problem

2007-04-18 Thread pabloski
Hi to all, I have a problem with a snippet of code that creates a Curl
object

the code is

c = pycurl.Curl()

c.key = keyCurrent
c.proxy = proxyCurrent
c.url = http://www.google.; + lg + /search?hl= + lg + q= + c.key +
meta=lr%3Dlang_ + lg + num=30

c.setopt(pycurl.URL, c.url)
c.setopt(pycurl.PROXY, c.proxy)

the last two lines raise a TypeError

obviously proxyCurrent, lg and keyCurrent are parameters

I noted that if I define c.proxy and c.url as costants e.g. c.url =
http://www.google.com/search?blah blah and c.proxy =
127.0.0.1:8080 it works

However if I define them as described before pycurl raises the TypeError
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What makes an iterator an iterator?

2007-04-18 Thread Alex Martelli
Steven D'Aprano [EMAIL PROTECTED] wrote:

 I thought that an iterator was any object that follows the iterator
 protocol, that is, it has a next() method and an __iter__() method.

The special methods need to be on the type -- having attributes of those
names on the instance doesn't help (applies to all special methods in
the normal, aka newstyle, object model; legacy, aka classic, classes,
work by slightly different and not entirely self-consistent semantics).


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


Re: Future Python Gui?

2007-04-18 Thread Kevin Walzer
[EMAIL PROTECTED] wrote:
 I've been trying to find out what the future of Python is with regard
 to Tk.  It seems there are several interfaces that make use of new
 functionality, including Tile and Ttk.
 
 If I want to write a program that will run under the standard Python
 distribution of the future, what extension module should I work with
 today?
 
 Thanks!
 
 -- Brian
 

Tile is available right now in Tk as an extension package, and a Tkinter 
wrapper for it can be found here:

http://tkinter.unpythonic.net/wiki/TileWrapper

Tile will be integrated into Tk's core when 8.5 is released. It's 
supposed to enter beta testing Real Soon Now. However, I imagine that 
Python/Tkinter will depend on Tk 8.4 for the foreseeable 
future--certainly 8.5 won't be supported officially before a full, 
stable release is made. Perhaps in Python 2.6?


-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: X root Operator help

2007-04-18 Thread Michael Hoffman
[Michael Hoffman]
 In floating point arithmetic, the naive way of calculating both roots
 always using the formula (-b +/- sqrt(b**2 - 4*a*c))/2*a will give you
 inaccurate results sometimes. See
 http://www.cse.uiuc.edu/eot/modules/floating_point/quadratic_formula/.

[lucidparadox]
 Thanks.  As of right now I'm just trying to familiarize myself with
 the syntax of Python.  Actually I should have thought of y**(1/x).

math.sqrt(y) might be faster or even more accurate (depending on 
platform) than y**0.5.

 I'm currently a freshman in college so the alternative formula hasn't
 been introduced to me yet.

It probably won't be unless you take a class in numerical analysis. Many 
a person has been burned by not thinking about these sorts of things 
until it is too late (myself included).
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Combinate 2 lists to a dict ?

2007-04-18 Thread Jia Lu
Hi all.

 I have 2 lists,
 a = [1,2,3]
 b = [ooo,aaa,ppp]

 What is the fastest way to make a dict like {1:ooo,2:aaa,
3:ppp} ?

Thanx

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


Re: Wanted: Email Client with GUI

2007-04-18 Thread BartlebyScrivener
On Apr 18, 9:25 am, Franz Steinhaeusler [EMAIL PROTECTED]
wrote:

  What I want is a program (it doesn't have to be so sophisticated
  as thunderbird) written totally in python and using a gui
  toolkit like pyqt, pygtk, wxpyhton or tkinter.

Why reinvent the wheel? Why not use Mutt and then call any Python
script you want from within Mutt. Or use Python modules written for
Mutt.

See, e.g., http://pyropus.ca/software/

rd


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


Re: Combinate 2 lists to a dict ?

2007-04-18 Thread vbr

 Hi all.
 
  I have 2 lists,
  a = [1,2,3]
  b = [ooo,aaa,ppp]
 
  What is the fastest way to make a dict like {1:ooo,2:aaa,
 3:ppp} ?
 
 Thanx

 dict(zip(a,b))
{1: 'ooo', 2: 'aaa', 3: 'ppp'}

works for me, but not sure, if it is the fastest way; a, b have to be of the 
same length, otherwise the shorter is used.

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


Combinate 2 lists to a dict ?

2007-04-18 Thread Jia Lu
Hi all.

 I have 2 lists,
 a = [1,2,3]
 b = [ooo,aaa,ppp]

 What is the fastest way to make a dict like {1:ooo,2:aaa,
3:ppp} ?

Thanx

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


subprocess handle is invalid error

2007-04-18 Thread Grant Edwards
I'm trying to use the py-gnuplot module on windows, and have
been unable to get it to work reliably under Win2K and WinXP.

By default, it uses popen(gnuplotcmd,'w'), but in some
situations that consistently gets an invalid operand IOError
when write() is called on the pipe.

So I switched to subprocess.  It works fine when executed
normally (e.g.  python progname.py), but when bundled by
py2exe, it always does this:

  Traceback (most recent call last):
File surfedit.py, line 28, in ?
File Gnuplot\_Gnuplot.pyc, line 178, in __init__
File Gnuplot\gp_win32.pyc, line 117, in __init__
File subprocess.pyc, line 533, in __init__
File subprocess.pyc, line 607, in _get_handles
File subprocess.pyc, line 634, in _make_inheritable
  WindowsError: [Errno 6] The handle is invalid

How does one troubleshoot errors that happen three layers deep
in the subprocess module?

-- 
Grant Edwards   grante Yow! I'm a fuschia bowling
  at   ball somewhere in Brittany
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Future Python Gui?

2007-04-18 Thread [EMAIL PROTECTED]
 I'd say that the best bet is to learn swig and similar
 bridging, expanding, and embedding mechanisms.
 Python GUI programming is likely to involve either
 python hooking into frameworks like Cocoa, Qt, or
 wxWidgets, python embedded in frameworks
 like Java or .NET, or flavors of python used
 as domain-specific languages in applications such as
 emacs, vim, and OpenOffice.org.

If this were just a tool for me, it wouldn't matter.  My concern is
distribution.  If anybody who wants to run my software then they also
have to go through all the trouble to install these extensions, none
of which seem to have decent instructions.  I'm an old-time hack and I
have trouble getting them to work.  A simple user won't have a chance!

If Python doesn't declare an official Gui system, then it'll be
fragmented, inconsistent, and unsupportable.

I wouldn't mind using just Tkinter, despite it's primative look,
except that it doesn't support more advanced widgets like notebook.

-- Brian

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


Re: looking for library to read ppt files

2007-04-18 Thread Aljosa Mohorovic
On Apr 18, 4:02 pm, Carsten Haese [EMAIL PROTECTED] wrote:
 How about running a headless OpenOffice instance and remote-controlling
 it with pyuno:

 http://udk.openoffice.org/python/python-bridge.html

 -Carsten

i'll try oo, thanks for link.

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


Re: Combinate 2 lists to a dict ?

2007-04-18 Thread Bart Willems
Jia Lu wrote:
  I have 2 lists,
  a = [1,2,3]
  b = [ooo,aaa,ppp]

reading the documentation might help.

If that doesn't work, try d = dict(zip(a, b))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python - dll access (ctypes or swig)

2007-04-18 Thread Thomas Heller
Alex Martelli schrieb:
 Larry Bates [EMAIL PROTECTED] wrote:
...
 I guess I was the only one it wasn't obvious to grin.  I've always
 written my COM servers as .EXE files even though they cannot be run
 independently.  What I find is odd is that I can create a .DLL or an
 .EXE of my COM server and after I register it, my application doesn't
 appear to know the difference.  The difference seems to be hidden from
 the actual application and doesn't affect it (at least that I can
 determine).
 
 Yes, except for performance (a DLL affords within-process communication
 without the overhead of IPC, so it can be much faster when appropriate)
 and some technical issues such as threading (if COM client and server
 are in separate processes, their threading models are independent from
 each other; if they are in the same process, they'd better have
 compatible threading approaches -- a thread-unsafe DLL server can make a
 single-threaded client happy but would cause problems and crashes if a
 freely-threaded client tried using it).

I think that the latter problem (incompatible threading models in the same
process) are solved by COM apartments - aren't they?

Thomas

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


Re: Future Python Gui?

2007-04-18 Thread Kevin Walzer
[EMAIL PROTECTED] wrote:
 I'd say that the best bet is to learn swig and similar
 bridging, expanding, and embedding mechanisms.
 Python GUI programming is likely to involve either
 python hooking into frameworks like Cocoa, Qt, or
 wxWidgets, python embedded in frameworks
 like Java or .NET, or flavors of python used
 as domain-specific languages in applications such as
 emacs, vim, and OpenOffice.org.
 
 If this were just a tool for me, it wouldn't matter.  My concern is
 distribution.  If anybody who wants to run my software then they also
 have to go through all the trouble to install these extensions, none
 of which seem to have decent instructions.  I'm an old-time hack and I
 have trouble getting them to work.  A simple user won't have a chance!
 

This is what deployment tools such as py2app or py2exe are for--to wrap 
all the bits up into a simple package that the end user just installs, 
without worrying about dependencies.

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What makes an iterator an iterator?

2007-04-18 Thread boggom

 I find myself perplexed as to this behaviour.

You can not iterate over a dead object!

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


Compiling python from soruce vs RPM ?

2007-04-18 Thread howa
I have compiled python 2.5 from source

i.e.

./configure
make
make install


but when i try to install another package require python, seems it
can't regonize python...

e.g..


/usr/bin/python is needed by xyz

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

Re: subprocess handle is invalid error

2007-04-18 Thread Erik Johnson

Grant Edwards [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

snip stuff about gnu-plot and py2exe problems
 How does one troubleshoot errors that happen three layers deep
 in the subprocess module?

I think the problem is more likely in how your py2exe is getting
bundled, rather than any real problem with the subprocess module. I have
been on the py2exe email list but not really paying much attention... If I
recall correctly, there are some special considerations when using gnuplot
with py2exe?  I would suggest digging through the py2exe email archives to
see if you can locate emails on that subject (one copy of which I believe
can be found at:
http://sourceforge.net/mailarchive/forum.php?forum_name=py2exe-users), and
if that doesn't work, to direct your question to the py2exe users list at:
[EMAIL PROTECTED]

(I believe the current home page of the py2exe project is at:
http://sourceforge.net/projects/py2exe/)

Hope that helps,
-ej


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


Re: X root Operator help

2007-04-18 Thread Steve Holden
Michael Hoffman wrote:
 lucidparadox wrote:
 I'm currently new to Python and I haven't been able to find the
 operator/math function to find the square root or even the x root of a
 number.
 
 For square root, use math.sqrt(y)
 
 For x root use y**(1/x)
 
[...]

   1/3
0
   3.14159 ** (1/3)
1.0
  

So the cube root of pi is 1? I don't think so.

For generic roots use y ** (1.0 / x)

until future versions of Python produce floating point results from all 
divisions as necessary.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings   http://holdenweb.blogspot.com

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


Newbie: import

2007-04-18 Thread genkuro
I thought import used relative paths from either the python executable
or the script being executed.  I have a script pulling in code from an
arbitrary directory.  How is this happening?

It's a RHEL 4 environment by the way.  I couldn't find any relevant
environment variables.

Thanks from a newbie for any insight.

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


Re: array{uint32}

2007-04-18 Thread Erik Johnson

Daniel Nogradi [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
  I have a function that returns a array{uint32}, is there any way to
output
  that to screen in a more user friendly format? At the moment when I
print it
  by itself it appears as [65541L], which isn't much used to anyone.

 I'm not sure I understand your question precisely but this might help:

  mylist = [65541L]
  mylist
 [65541L]
  mylist[0]
 65541L
  int(mylist[0])
 65541
 

Right, so getting rid of the 'L' is one improvement.  You might also check
out the pprint module:

 l = range(30)
 l
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 2
2, 23, 24, 25, 26, 27, 28, 29]
 from pprint import pprint
 pprint(l)
[0,
 1,
 2,
 3,
snip
 28,
 29]


You can use C-like print formatting statements:

 l = [-3, 0, 101320, 67]
 pprint(l)
[-3, 0, 101320, 67]
 for i in l:
...   print i
...
-3
0
101320
67
 for i in l:
...   print '%6i' % i
...
-3
 0
101320
67

# the above probably doesn't disply correctly unless you are viewing with a
monospaced font)

You could sort the list, then split it up into N separate lists so that
you can format multiple columns of sorted integers...

You haven't given any real information about your idea of a user friendly
format, but maybe this will help also.

-ej


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


Re: What makes an iterator an iterator?

2007-04-18 Thread [EMAIL PROTECTED]
On Apr 18, 10:36 am, [EMAIL PROTECTED] wrote:
  I find myself perplexed as to this behaviour.

 You can not iterate over a dead object!

It's not dead, it's restin'. All shagged out over a long squak.

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


Re: Newbie: import

2007-04-18 Thread Larry Bates
[EMAIL PROTECTED] wrote:
 I thought import used relative paths from either the python executable
 or the script being executed.  I have a script pulling in code from an
 arbitrary directory.  How is this happening?
 
 It's a RHEL 4 environment by the way.  I couldn't find any relevant
 environment variables.
 
 Thanks from a newbie for any insight.
 

PYTHONPATH environment variable is next in line to be searched.

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


Re: Newbie: import

2007-04-18 Thread Steven Howe

[EMAIL PROTECTED] wrote:

I thought import used relative paths from either the python executable
or the script being executed.  I have a script pulling in code from an
arbitrary directory.  How is this happening?

It's a RHEL 4 environment by the way.  I couldn't find any relevant
environment variables.

Thanks from a newbie for any insight.

  

See 

   http://docs.python.org/tut/node8.html#SECTION00811


   6.1.1 The Module Search Path

   When a module named spam is imported, the interpreter searches for a
   file named spam.py in the current directory, and then in the list of
   directories specified by the environment variable PYTHONPATH. This
   has the same syntax as the shell variable PATH, that is, a list of
   directory names. When PYTHONPATH is not set, or when the file is not
   found there, the search continues in an installation-dependent
   default path; on Unix, this is usually .:/usr/local/lib/python.

   Actually, modules are searched in the list of directories given by
   the variable |sys.path| which is initialized from the directory
   containing the input script (or the current directory), PYTHONPATH
   and the installation-dependent default. This allows Python programs
   that know what they're doing to modify or replace the module search
   path. Note that because the directory containing the script being
   run is on the search path, it is important that the script not have
   the same name as a standard module, or Python will attempt to load
   the script as a module when that module is imported. This will
   generally be an error. See section 6.2
   http://docs.python.org/tut/node8.html#standardModules, ``Standard
   Modules,'' for more information.

Then try

   import sys
   sys.path


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

Re: subprocess handle is invalid error

2007-04-18 Thread Grant Edwards
On 2007-04-18, Erik Johnson [EMAIL PROTECTED] wrote:

 Grant Edwards [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]

snip stuff about gnu-plot and py2exe problems
 How does one troubleshoot errors that happen three layers deep
 in the subprocess module?

 I think the problem is more likely in how your py2exe is
 getting bundled, rather than any real problem with the
 subprocess module.

I've switched back to os.popen() since I seem to get the same
problems with either.  The odd thing is that it only seems to
fail when the current directory is mounted via the network
_and_ when it's being started by clicking on a file whose
filetype is associated with the application.

Running the program from the command line (cmd.exe or bash)
always works for any current directory. Running the program by
cliking on a shortcut icon on the desktop always works for any 
'start in' directory.

The one case that doesn't work is when its run by clicking on
an associated file on a network drive.

-- 
Grant Edwards   grante Yow! Now I'm concentrating
  at   on a specific tank battle
   visi.comtoward the end of World
   War II!
-- 
http://mail.python.org/mailman/listinfo/python-list


Martel Package from Biopython

2007-04-18 Thread elventear
Hello,

I know this is not the best place to ask this but I haven't had luck
in the Biopython forums with my questions, so I'll just try here.

I want to use the Martel package to do some parsing. I've found it to
be very powerful and convenient. Yet the documentation avaialble is
less than complete. I have a few questions on how to use it, if you
know the answers to my questions:

- How does Bio.Std.record  affect the parsing of a Martel expression.
- How does Bio.RecordReader work? How does it interact with
Martel.HeaderFooter?
- Many of the matching objects (ie. Martel.Digits) have an attrs
argument. How does it work?

Thanks!

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


Re: X root Operator help

2007-04-18 Thread Michael Hoffman
[Michael Hoffman]
 For x root use y**(1/x)

[Steve Holden]
   3.14159 ** (1/3)
 1.0
  
 
 So the cube root of pi is 1? I don't think so.
 
 For generic roots use y ** (1.0 / x)

Yes, good point. :)
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


image sequence to Quicktime movie

2007-04-18 Thread Simon Cassels
did u ever find anything out about this ?

if so can you help me with some leads i am trying to figure an action  
that can convert image files to quicktime automatically.

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


  1   2   3   >