DFW Pythoneer Meetings This Week

2005-11-08 Thread Jeff Rush
The Dallas-Ft. Worth Pythoneers are having three meetings this week.

[1] Thursday, November 10th (i.e. Every Second Thursday) 

From 7 pm until 10 pm at Snuffer's Restaurant and Bar
in Addison on Midway, we have a *social get-together*.  Sure
to be on the agenda is discussion about our recent experiences
with learning Zope 3 and establishing a club IRC channel.

Snuffer's Restaurant and Bar
14910 Midway Rd. 
Addison, TX 75244
972-991-8811 

We meet in the glassed-in patio and try to have Python-related
books and signs scattered about so people can find us.

[2] Friday, November 11th (Kickoff of Ft. Worth Chapter)

The first meeting of the Fort Worth chapter, we're trying to
build up a group for those who find it difficult to drive all
the way to Dallas/Addison.  If you want local meetings, please
make your presence known.

We're meeting from 6 pm until 8 pm at:

Artistic Blends
5298 Trail Lake Drive 
Fort Worth, TX 76133
(817) 292.4744 

Look for the Kylixitis shirt wearing individual.

[3] Saturday, November 12th (i.e. Second Saturday Hands-On Sessions)

We start gathering at 1 pm and formally start at 2 pm.  This is
*hands-on programming* so bring your laptops.  The site has both
wired and wireless Internet, and we have a projector for talks.

We run until 5 pm and then break for a group dinner.  We're at
the tables in the big middle of the bookstore, with laptops,
hubs and cables everywhere.  Easy to find.

NerdBooks.com
1681 Firman Drive 
Richardson, TX 75081
(972) 470-9600 

The topics this time will be Zope 3 and more Extreme Programming,
applied to the web-based talks scheduler we're constructing as a
group project for the PyCon conference.

Next time, the Fourth Saturday, we hope to have a demo/talk of
the Django web framework.


Locations, times and *maps* for all events are maintained at:

http://python.meetup.com/10/events/

The DFW Pythoneers maintain a club wiki/mailing list at:

   http://www.python.org/dfw

Hope to see you there, and especially some new faces!

Jeff Rush, DFW Pythoneers Coordinator
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Chicago Python Users Group, Thurs Nov 10

2005-11-08 Thread Ian Bicking
November topics are Remote, Generic and Random, just like us.

We'll have presentations on PyRO (Python Remote Objects) by Fawad
Halim, generic functions (as implemented in RuleDispatch) by Ian
Bicking, and the standard library random module by Robert Ramsdell.

There will also be time to chat, and many opportunities to ask
questions. We encourage people at all levels to attend.

We'll be meeting at 7 PM, Thursday November 10, in downtown Chicago at
Performics 180 N. Lasalle 12th floor.  RSVP is necessary for building
security, email [EMAIL PROTECTED] with a subject of RSVP for
ChiPy to be added to the list.  If you aren't sure if you can come,
email just in case.

About ChiPy (http://chipy.org):

ChiPy meets on the second Thursday of each month, at different
locations around Chicagoland.  If you are interested in goings-on,
please subscribe to our mailing list:
http://mail.python.org/mailman/listinfo/chicago

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

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


Re: how to stop a loop with ESC key? [newbie]

2005-11-08 Thread Fredrik Lundh
mo [EMAIL PROTECTED] wrote:
 Can somebody explain how to stop a WHILE loop in running program by pressing
 ESC key?

depends on the platform.

on windows, you can use the mscvrt module:

import msvcrt

while ...:
...
if msvcrt.kbhit() and msvcrt.getch() == chr(27):
break
...

also see the second example on this page:

http://effbot.org/tag/python.msvcrt

/F



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


Pywin32: How to import data into Excel?

2005-11-08 Thread Dmytro Lesnyak



Hello,


I need to import some big 
data into Excel from my Python 
script. I have TXT file (~7,5 Mb). Im using Pywin32 library for that, but if I 
first try to read the TXT file and then save the values one by one 
like

 
xlBook.Sheets(sheet_name).Cells(i,j).Value = 
value_from_TXT_file

it takes about 10 hours to process 
wholedata (and it's not acceptable in my 
case).
I just wonder if its possible to speed up the process. F.e. by using 


 
xlApp.Workbooks.OpenText() function

I was trying to do that, but I dont have any documentation for the function and it doesnt work.

BR,
Dima
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: how to stop a loop with ESC key? [newbie]

2005-11-08 Thread Leif K-Brooks
mo wrote:
 Can somebody explain how to stop a WHILE loop in running program by pressing
 ESC key?

On Unix-like systems try:

import termios, fcntl, sys, os
fd = sys.stdin.fileno()

oldterm = termios.tcgetattr(fd)
newattr = termios.tcgetattr(fd)
newattr[3] = newattr[3]  ~termios.ICANON  ~termios.ECHO
termios.tcsetattr(fd, termios.TCSANOW, newattr)

oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)

i = 0
try:
while 1:
print i
i += 1
try:
char = sys.stdin.read(1)
if char == '\x1b':
print Bye!
break
except IOError:
pass
finally:
termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
-- 
http://mail.python.org/mailman/listinfo/python-list


image

2005-11-08 Thread Shi Mu
why the following code report the error:
Traceback (most recent call last):
 File C:\Python23\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py,
line 310, in RunScript
   exec codeObject in __main__.__dict__
 File C:\Python23\Examples\AppB\text.py, line 24, in ?
   text.image_create(END, image=photo)
 File C:\Python23\lib\lib-tk\Tkinter.py, line 2882, in image_create
   return self.tk.call(
TclError: image pyimage4 doesn't exist

from Tkinter import *

root = Tk()
root.option_readfile('optionDB')
root.title('Text')
text = Text(root, height=26, width=50)
scroll = Scrollbar(root, command=text.yview)
text.configure(yscrollcommand=scroll.set)
text.tag_configure('bold_italics', font=('Verdana', 12, 'bold', 'italic'))
text.tag_configure('big', font=('Verdana', 24, 'bold'))
text.tag_configure('color', foreground='blue', font=('Tempus Sans ITC', 14))
text.tag_configure('groove', relief=GROOVE, borderwidth=2)
text.tag_bind('bite', '1',
 lambda e, t=text: t.insert(END, I'll bite your legs off!))

text.insert(END, 'Something up with my banter, chaps?\n')
text.insert(END, 'Four hours to bury a cat?\n', 'bold_italics')
text.insert(END, 'Can I call you Frank?\n', 'big')
text.insert(END, What's happening Thursday then?\n, 'color')
text.insert(END, 'Did you write this symphony in the shed?\n', 'groove')
button = Button(text, text='I do live at 46 Horton terrace')
text.window_create(END, window=button)
photo=PhotoImage(file='img52.gif')
text.image_create(END, image=photo)
text.insert(END, 'I dare you to click on this\n', 'bite')
text.pack(side=LEFT)
scroll.pack(side=RIGHT, fill=Y)

root.mainloop()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: overloading *something

2005-11-08 Thread Bengt Richter
On Mon, 7 Nov 2005 20:39:46 -0800, James Stroud [EMAIL PROTECTED] wrote:

On Monday 07 November 2005 20:21, Robert Kern wrote:
 James Stroud wrote:
  Hello All,
 
  How does one make an arbitrary class (e.g. class myclass(object)) behave
  like a list in method calls with the *something operator? What I mean
  is:
 
  myobj = myclass()
 
  doit(*myobj)
 
  I've looked at getitem, getslice, and iter. What is it if not one of
  these?
 
  And, how about the **something operator?

 Avoiding magic at the expense of terseness, I would do something like
 the following:

   class myclass(object):
 def totuple(self):
   ...
 def todict(self):
   ...

   myargs = myclass()
   mykwds = myclass()

   doit(*myargs.totuple(), **mykwds.todict())

Actually, I retried __iter__ and it worked. I'm not sure how I screwed it up 
before. So I'm happy to report a little magic:

py def doit(*args):
...   print args
...
py class bob:
...   def __init__(self, length):
... self.length = length
...   def __iter__(self):
... return iter(xrange(self.length))
...
py b = bob(8)
py list(b)
[0, 1, 2, 3, 4, 5, 6, 7]
py doit(*b)
(0, 1, 2, 3, 4, 5, 6, 7)

I think you can also just define __getitem__ if that's handier. E.g.,

  class MyClass(object):
 ... def __init__(self, limit=1): self.limit=limit
 ... def __getitem__(self, i):
 ...  if i  self.limit: return i**3
 ...  raise StopIteration
 ...
  myobj = MyClass(5)
  list(myobj)
 [0, 1, 8, 27, 64]
  list(MyClass(10))
 [0, 1, 8, 27, 64, 125, 216, 343, 512, 729]

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


Re: Distributed Cache Server?

2005-11-08 Thread [EMAIL PROTECTED]
har nah, think I'll give BT a miss for this purpose.

Yeah, know it was a loaded question (no specifics), but was really only
thinking out aloud.

The plans are:

- Multiple copies of data on different machines (just thinking 2 copies
of the data)
- Load spread over multiple machines... anything between 2-lots
(again, not being specific).
- Data itself I'm expecting to be low a few Gb at tops (but
ofcourse, as this extends I might want to increase the size)
- Haven't thought a LOT about automatic handling of errors.. yet.
- and its assumed to be on a trusted network.

Apart from memcached, I haven't seen anything similar to what I'm after
(plus to be perfectly honest. I wouldn't mind coding it up anyway)
;)

Was just feeling about to see if anything else is out there.

KenF

ps. btw, only part of it is theoretical, a lot of this I've already
coded, but not targetted towards large scale (100's machines etc)... So
am thinking what I'd need to consider to increase this to a larger
scale.




Roger Binns wrote:
 [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]
  Does anyone know if a distributed caching system has been developed
  for use with Python?

 BitTorrent :-)

  Yes, distributed caching system is a bit of a general term, but am
  really just talking about something as simple as key + value (arbitrary
  class) which can be split over a number of machines in an efficient
  manner.

 You'll need to define what the sweet spot is that you are aiming for.
 Are we talking tens of thousands of keys or billions?  How big is the
 data (megabytes, gigabytes, terabytes?)  Do you need transactional
 integrity (eg when are updates seen by other readers)?  Do you want
 redundancy (data duplicated on multiple machines)?  How many machines
 are we talking about?  Should failure be automatically detected?  Is
 there a need for security or treating the machines as untrusted?
 
 Roger

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


Re: overloading *something

2005-11-08 Thread Peter Otten
James Stroud wrote:

 I was attempting to re-define iter of a subclassed list, to find the
 magic method, but it didn't work. 

 class List(list):
... def __iter__(self): return iter(abc)
...
 a = List([1,2,3])
 list(a)
['a', 'b', 'c']
 tuple(a)
(1, 2, 3)

list-to-tuple conversion is optimized for performance -- basically a
memcopy() of the internal data. As with a similar peculiarity with
file.write() and the print statement, the problem could be shunned if
python would check for the exact class instead of a test that is equivalent
to isinstance().

Peter

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


Re: socket receive file does not match sent file

2005-11-08 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

 while True:
data = f.read(8192)
if not data: break
else:
s.send(data)

 What is the cause of the problem, can anyone tell me?

using sendall instead of send should fix this.  see the library reference for
details:

send( string[, flags])
  Send data to the socket. The socket must be connected to a remote
  socket. The optional flags argument has the same meaning as for recv()
  above. Returns the number of bytes sent. Applications are responsible
  for checking that all data has been sent; if only some of the data was
  transmitted, the application needs to attempt delivery of the
  remaining data.

  sendall( string[, flags])

  Send data to the socket. The socket must be connected to a remote
  socket. The optional flags argument has the same meaning as for recv()
  above. Unlike send(), this method continues to send data from string
  until either all data has been sent or an error occurs. None is
  returned on success. On error, an exception is raised, and there is no
  way to determine how much data, if any, was successfully sent.

  /F



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


Re: image

2005-11-08 Thread Fredrik Lundh
Shi Mu wrote:

 why the following code report the error:
 Traceback (most recent call last):
  File 
 C:\Python23\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py,
 line 310, in RunScript
exec codeObject in __main__.__dict__
  File C:\Python23\Examples\AppB\text.py, line 24, in ?
text.image_create(END, image=photo)
  File C:\Python23\lib\lib-tk\Tkinter.py, line 2882, in image_create
return self.tk.call(
 TclError: image pyimage4 doesn't exist

works for me, when running it from a stock CPython interpreter.

have you tried running the script outside the pywin environment?

/F



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


Addressing the last element of a list

2005-11-08 Thread [EMAIL PROTECTED]
Isn't there an easier way than

lst[len(lst) - 1] = ...

?

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


Re: Class Variable Access and Assignment

2005-11-08 Thread Magnus Lycka
Antoon Pardon wrote:
 Fine that goes both ways. I don't mind not being taken serious by people
 I have trouble taking serious my self. No doubt that goes for you too.

You know Antoon, these internet communities aren't really like
Speaker Corner in Hyde Park. You earn respect based on your merits,
not from the stubborn persistence in you arguments.

Steve has written a very good book on Python, he's worked a lot
with Python conferences, and helped people on comp.lang.python
for years etc. He has earned his respect.

You are fighting wind mills, bickering about things that you
don't have any solutions for. It's possible that you have just
not realized how Python handles objects, names and classes, but I
can't understand what you are trying to accomplish. What can you
possibly try to convey that you haven't already stated? It's
as if you've got stuck in this thread. In the real world, I
haven't heard of anyone ever having had problems with this.

Isn't it better to let it go and to spend your time on something
constructive?

I recently heard a priest say, that the difference between the
saint and the fanatic is that the fanatic tries to remove the
evil in the world, while the saint tries to remove the evil in
himself.

Just as introspection is useful both in fighting evil and in
Python programming, I think it's useful when we get into heated
discussions. I've always loved heated discussions, but over time,
I've come to realize that the best thing that can happen in such
a discussion is to realize that I was wrong. Then I've learnt
something! If I don't change my mind, I'm just standing still.
In that case, it might be useful for someone else, if she or he
learnt something from it, but the best thing is if I learn
something.

This thread is all to infected to lead to good things. Hopefully
you'll learn something about communication from it, but the price
has been higher than you might be aware of right now.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Addressing the last element of a list

2005-11-08 Thread [EMAIL PROTECTED]
Or alternatively:

Is there a way to make reference to the last element of a list, to use
as a shorthand:

ref := lst[len(lst) - 1] # I know syntax is wrong, but you get the
idea

and then using the last element of the list by (assuming the element is
a dict):

ref[foo] = 42
ref[bar] = Ni!

etc.

/David

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


Re: image

2005-11-08 Thread Shi Mu
yes. I use both cmd and pythonwin to run it. why both of them can not work?

On 11/8/05, Fredrik Lundh [EMAIL PROTECTED] wrote:
 Shi Mu wrote:

  why the following code report the error:
  Traceback (most recent call last):
   File 
  C:\Python23\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py,
  line 310, in RunScript
 exec codeObject in __main__.__dict__
   File C:\Python23\Examples\AppB\text.py, line 24, in ?
 text.image_create(END, image=photo)
   File C:\Python23\lib\lib-tk\Tkinter.py, line 2882, in image_create
 return self.tk.call(
  TclError: image pyimage4 doesn't exist

 works for me, when running it from a stock CPython interpreter.

 have you tried running the script outside the pywin environment?

 /F



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

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


Re: Addressing the last element of a list

2005-11-08 Thread [EMAIL PROTECTED]
I knew there was an easy way :)

Just to satisfy my curiousity: Is there a way to do something like the
reference solution I suggest above?

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


DFW Pythoneer Meetings This Week

2005-11-08 Thread Jeff Rush
The Dallas-Ft. Worth Pythoneers are having three meetings this week.

[1] Thursday, November 10th (i.e. Every Second Thursday) 

From 7 pm until 10 pm at Snuffer's Restaurant and Bar
in Addison on Midway, we have a *social get-together*.  Sure
to be on the agenda is discussion about our recent experiences
with learning Zope 3 and establishing a club IRC channel.

Snuffer's Restaurant and Bar
14910 Midway Rd. 
Addison, TX 75244
972-991-8811 

We meet in the glassed-in patio and try to have Python-related
books and signs scattered about so people can find us.

[2] Friday, November 11th (Kickoff of Ft. Worth Chapter)

The first meeting of the Fort Worth chapter, we're trying to
build up a group for those who find it difficult to drive all
the way to Dallas/Addison.  If you want local meetings, please
make your presence known.

We're meeting from 6 pm until 8 pm at:

Artistic Blends
5298 Trail Lake Drive 
Fort Worth, TX 76133
(817) 292.4744 

Look for the Kylixitis shirt wearing individual.

[3] Saturday, November 12th (i.e. Second Saturday Hands-On Sessions)

We start gathering at 1 pm and formally start at 2 pm.  This is
*hands-on programming* so bring your laptops.  The site has both
wired and wireless Internet, and we have a projector for talks.

We run until 5 pm and then break for a group dinner.  We're at
the tables in the big middle of the bookstore, with laptops,
hubs and cables everywhere.  Easy to find.

NerdBooks.com
1681 Firman Drive 
Richardson, TX 75081
(972) 470-9600 

The topics this time will be Zope 3 and more Extreme Programming,
applied to the web-based talks scheduler we're constructing as a
group project for the PyCon conference.

Next time, the Fourth Saturday, we hope to have a demo/talk of
the Django web framework.


Locations, times and *maps* for all events are maintained at:

http://python.meetup.com/10/events/

The DFW Pythoneers maintain a club wiki/mailing list at:

   http://www.python.org/dfw

Hope to see you there, and especially some new faces!

Jeff Rush, DFW Pythoneers Coordinator
-- 
http://mail.python.org/mailman/listinfo/python-list


[OTAnn] Groups:New Developments at Roomity

2005-11-08 Thread shenanigans
I was interested in getting feedback from current communities of Roomity.com and let you know the recent improvements we are working on for better interface.Roomity.com v 1.5 is a web 2.01/RiA poster child community webapp. This new version adds broadcast video, social networking such as favorite authors and html editor.Its likely already you have groups and content you are already using but aggregated and safer, including technology, Java, etc., but it only works on broadband.S.*This is not spam! I work for Roomity and are trying to find better ways to enhance our members' experience.Broadband interface (RIA) + mail box saftey = Python_General_Discussion_List.roomity.com*Your* clubs, no sign up to read, ad supported; try broadband internet. ~~1131142545482~~-- 
http://mail.python.org/mailman/listinfo/python-list

what the %?....

2005-11-08 Thread john boy
Hey can somebody tell me what the "%" function does...I am not math illiterate...its just a new symbol for meis it a divisor? remainder something another??

thanks -xray-
		 Yahoo! FareChase - Search multiple travel sites in one click.

 

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

Re: python server

2005-11-08 Thread Magnus Lycka
linuxpld wrote:
 I`m writing a program (server in future) in python.
 I would like to write it in such a way that I will be able to write gui
 in any language and connect to my python program and use functionality
 included with it.
 are there any libraries that I could use?

Thee are many solutions. An XML-RPC server springs to mind as a
solution. There are several Python XML-RPC servers, and clients
for a wide range of languages, see:
http://xmlrpc.scripting.com/directory/1568/implementations

Plain sockets can work of course, but that's fairly low
level: You'll need to device a protocol etc.

For more possible solutions, see
http://www.thinkware.se/cgi-bin/thinki.cgi/UsingPythonWithOtherLanguages
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Addressing the last element of a list

2005-11-08 Thread Andreas Lobinger
Aloha,

[EMAIL PROTECTED] wrote:
 Isn't there an easier way than
 lst[len(lst) - 1] = ...
lst[-1] = ...

Wishing a happy day
LOBI
-- 
http://mail.python.org/mailman/listinfo/python-list


[OTAnn] Feedback

2005-11-08 Thread shenanigans
I was interested in getting feedback from current mail group users.We have mirrored your mail list in a new application that provides a more aggregated and safe environment which utilizes the power of broadband.Roomity.com v 1.5 is a web 2.01 community webapp. Our newest version adds broadcast video and social networking such as favorite authors and an html editor.It?s free to join and any feedback would be appreciated.S.Broadband interface (RIA) + mail box saftey = Python_General_Discussion_List.roomity.com*Your* clubs, no sign up to read, ad supported; try broadband internet. ~~1131397871462~~-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Addressing the last element of a list

2005-11-08 Thread Peter Otten
[EMAIL PROTECTED] wrote:

 Just to satisfy my curiousity: Is there a way to do something like the
 reference solution I suggest above?

No. You cannot overload assignment. 
Of course, for mutable objects you can use the object as the reference to
itself.

Peter

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


How to convert a number to hex number?

2005-11-08 Thread Hako
I try this command:
 import string
 string.atoi('78',16)
120
this is 120 not 4E.

Someone can tell me how to convert a decimal number to hex number? Can
print A, B, C,DEF.
Thank you.

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


Re: os.path.getmtime on winXP

2005-11-08 Thread Bengt Richter
On Tue, 08 Nov 2005 07:57:44 +0100, =?ISO-8859-1?Q?Jorg_R=F8dsj=F8?= [EMAIL 
PROTECTED] wrote:

[sorry to those reading twice, but I just realised that I had posted 
this after mucking about with the date on my machine to try to figure 
this out -- so the message probably went into last months messages for 
most people including me.]

Hi

I'm trying to use os.path.getmtime to check if a file has been modified. 
  My OS is WinXP. The problem is, that when the os changes from/to 
daylight savings time, the result is suddenly off by 3600 seconds ie. 
one hour, even if the file remains the same.

Well, if the file hasn't been modified, the file time should be wrt
a constant epoch, so you must be observing a DST-corrected conversion
of that number, but you don't show what you are using.
E.g. you can convert with time.localtime or time.gmtime, and format the
result any way you want with time.strftime(...)

  time.strftime('%Y-%m-%d %H:%M:%S', 
  time.localtime(os.path.getmtime('wc.py')))
 '2003-09-10 14:38:57'
  time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(os.path.getmtime('wc.py')))
 '2003-09-10 21:38:57'

Which comes from
  os.path.getmtime('wc.py')
 1063229937

And default localtime formatting is
  time.ctime(os.path.getmtime('wc.py'))
 'Wed Sep 10 14:38:57 2003'

which is
  time.asctime(time.localtime(os.path.getmtime('wc.py')))
 'Wed Sep 10 14:38:57 2003'

the GMT version of which is
  time.asctime(time.gmtime(os.path.getmtime('wc.py')))
 'Wed Sep 10 21:38:57 2003'

reflecting
  os.system('dir wc.py')
  Volume in drive C is System
  Volume Serial Number is 14CF-C4B9

  Directory of c:\pywk\clp

 03-09-10  14:38595 wc.py



I've tried using win32file.GetFileTime, and it reports a consistent 
number, regardless of DST.

What is happening here? My first thought is that getmtime should measure 
'raw' time, and not be concerned with DST, and thus give me the same 
result no matter the date on the machine I call it. Is the module broken 
in some way, or am I just missing something here?

How did you format the number you got from os.path.getmtime?
You might want to try some of the above.

If you actually created/modified files just before and after the DST change
and saw an extra hour difference instead of the time between the two actions,
then maybe I'd look into whether the OS has some perverse option to use local 
DST
time to record in the file stat info, but that's hard to believe. More likely 
someone
is messing with with raw file time setting, like touch. Don't have it handy to 
see
what DST assumptions it makes if any.

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


Re: Lie Hetland book: Beginning Python..

2005-11-08 Thread Vittorio
Steve Holden [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 No, you actually did quite a creditable piece of debugging. The DB-API
 specifications allow database modules to substitute parameters into
 SQL commands in a number of different ways, and they are supposed to 
 indicate the technique they use by setting a module variable 
 paramstyle to one of five possible values.
 
 Magnus' original code was written to use a different (but valid) 
 paramstyle, so I'm guessing that his sqlite module and your sqlite2 
 simply use different paramstyles. Whether that's because a change was 
 made in developing the pysqlite code or because pysqlite and pysqlite2
 come from different developers I couldn't say, but you have nailed the
 problem. Well done!

Thanks Steve for your encouragement.

Actually, subsequently to my posting, I had realised that the point was 
in the different version of the Pysqlite interface: in fact I found many 
other pieces of code which were affected the same way, and each of them 
made use of import pysqlite.

Nonetheless, I was unable to find any documentation about such a 
different behaviour between Pysqlite and Pysqlite2; from my beginner 
point of view the Pysqlite (Magnus' version) paramstyle looks a better 
and more pythonic choice and I don't grasp the Pysqlite2 developers' 
intentions deviating from that way.

I would be very grateful if someone would cast a light over 
Pysqlite/Pysqlite2 discrepancies.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Addressing the last element of a list

2005-11-08 Thread [EMAIL PROTECTED]
what do you mean by alias ?

a = b

now both a and b refers to the same object.

[EMAIL PROTECTED] wrote:
 So there is no way in Python to make an alias for an object?
 
 /David

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


Re: Addressing the last element of a list

2005-11-08 Thread [EMAIL PROTECTED]
I just want an alias. Ideally, I don't want to deal with pointers or
special reference types etc. After all, this is not C++ :)

I just want to be able to make a reference to any old thing in Python.
A list, an integer variable, a function etc. so that I, in complicated
cases, can make a shorthand. If myRef could somehow point at
something long an complicated like a[42][pos][-4], that might be
useful.

/David

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


Re: image

2005-11-08 Thread Fredrik Lundh
   File C:\Python23\lib\lib-tk\Tkinter.py, line 2882, in image_create
 return self.tk.call(
  TclError: image pyimage4 doesn't exist

 works for me, when running it from a stock CPython interpreter.

 have you tried running the script outside the pywin environment?

btw, the error message indicates that the problem is that PythonWin
doesn't clean things up between runs, so you end up creating new Tk
objects every time you try the script.  but when you call PhotoImage,
it uses the default root window (which was created the first time you
called Tk), so you get back an image that's associated with another
Tk instance.

it's really an issue with PythonWin, but if you cannot switch to an IDE
that runs your scripts in a separate process, you can work around the
problem by passing in an explicit master to the PhotoImage factory:

photo=PhotoImage(file='...', master=root)

/F



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


Re: How to convert a number to hex number?

2005-11-08 Thread Daniel Evers
Hi!

Try hex:
 hex(120)
'0x78'

Consider converting string - int using the int()-function:
 print int.__doc__
int(x[, base]) - integer

Convert a string or number to an integer, if possible.  A floating point
argument will be truncated towards zero (this does not include a string
representation of a floating point number!)  When converting a string, use
the optional base.  It is an error to supply a base when converting a
non-string. If the argument is outside the integer range a long object
will be returned instead.

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


Re: how to stop a loop with ESC key? [newbie]

2005-11-08 Thread mo
Thanks,
I tryed your example:

import msvcrt
while 1:
print '.'
if msvcrt.kbhit() and msvcrt.getch() == chr(27):
 break

but it doesn't work. It is running (Win2000), there is no messages about
errors but there is no effect when pressing ESC key. What I am doing wrong?
mo


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


Re: Addressing the last element of a list

2005-11-08 Thread [EMAIL PROTECTED]
But if lst[42][pos] happens to hold an integer value, then

a = lst[42][pos]

will _copy_ that integer value into 'a', right? Changing 'a' will not
change the value at lst[42][pos]

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


RAW_INPUT-----NEVERMIND I FIGURED IT OUT

2005-11-08 Thread john boy
i had posted a previous question but I figured it out...thanks
		 Yahoo! FareChase - Search multiple travel sites in one click.

 

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

Re: os.path.getmtime on winXP

2005-11-08 Thread Jorg Rødsjø
Bengt Richter wrote:
 How did you format the number you got from os.path.getmtime?

I'm not doing any formating at all. I am just looking at the numbers of 
seconds since epoch. Which is what makes it so strange.

 You might want to try some of the above.

I'll do that. At the moment I'm looking at the difference between 
localtime and gmtime to see if my computer is in dst. If it is not, I 
just add 3600 seconds to the result from os.path.getmtime -- which then 
should give consistent results.

 If you actually created/modified files just before and after the DST change
 and saw an extra hour difference instead of the time between the two actions,
 then maybe I'd look into whether the OS has some perverse option to use local 
 DST
 time to record in the file stat info, but that's hard to believe. More likely 
 someone
 is messing with with raw file time setting, like touch. Don't have it handy 
 to see
 what DST assumptions it makes if any.

The files I am testing with have not been modified for a long time. 
Windows reports the modified date as being the same, no matter what I do 
(both through the gui, and through win32file). And they all show the 
same strange 3600 sec difference with/without dst when I call getmtime 
on them.

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


Re: Addressing the last element of a list

2005-11-08 Thread Bengt Richter
On 8 Nov 2005 01:12:07 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

I knew there was an easy way :)

Just to satisfy my curiousity: Is there a way to do something like the
reference solution I suggest above?


If the last element in the list was a dict, then you could do something like

  lst = ['the', 'last', 'element of this list is a dict', {'key':key's 
  value}]
  ref = lst[-1]
  ref
 {'key': key's value}
  ref[foo] =42
  ref['bar'] = 'Ni!'
  ref
 {'foo': 42, 'bar': 'Ni!', 'key': key's value}
  ref['key']
 key's value
  ref['bar']
 'Ni!'
  del ref['key']
  ref
 {'foo': 42, 'bar': 'Ni!'}

FWIW ;-)

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


Re: Addressing the last element of a list

2005-11-08 Thread Jerzy Karczmarczuk
Peter Otten wrote:
 [EMAIL PROTECTED] wrote:
 
 
Just to satisfy my curiousity: Is there a way to do something like the
reference solution I suggest above?
 
 
 No. You cannot overload assignment. 

I have the impression that this is not an issue, to overload assignments,
which btw. *can* be overloaded, but the absence of *aliasing* (undiscriminate
handling of pointers) in Python. Am I wrong?

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


Re: Sending email in utf-8?

2005-11-08 Thread Max M
morphex wrote:
 That works, kinda.  I get strange characters now like this
 
 
 Date: Mon, 7 Nov 2005 11:38:29 -0700 (MST)
 Message-Id: [EMAIL PROTECTED]
 To: [EMAIL PROTECTED], [EMAIL PROTECTED]
 From: [EMAIL PROTECTED]
 Subject:  Order confirmation
 Content-Type: text/plain; charset=utf-8
 X-Bogosity: No, tests=bogofilter, spamicity=0.00, version=0.92.8
 
 Thank you for your order, it is copied here for your convenience, and
 we will process it shortly.
 
 Name:  ø
 Phone: ø
 Email:  [EMAIL PROTECTED]
 Comments:  asdf
 
 
 but at least it doesn't raise any errors.
 

This is a method I have clipped from one of my projects. It should 
pretty much cover everything you would want to do while sending mails.


 def Workgroup_mailFormAction(self, to=None, cc=None, bcc=None, 
inReplyTo=None,
  subject=None, body='', 
attachments=None, mfrom=None,
  REQUEST=None):
 
 Sends a message. Many of the input parameters are not currently 
used,
 but can be used for skinning the functionlity.
 
 site_encoding = self._site_encoding()
 ##
 # Create the message
 msg = Message()
 msg.set_payload(body, site_encoding)
 #
 # if attachment, convert to multipart
 # file fields are posted even if empty, so we need to remove 
those :-s
 if attachments is None:
 attachments = []
 attachments = [a for a in attachments if a]
 if attachments:
 mimeMsg = MIMEMultipart()
 mimeMsg.attach(msg)
 for attachment in attachments:
 # Add the attachment
 tmp = email.message_from_string(str(attachment.headers))
 filename = tmp.get_param('filename', 'Attachment', 
'Content-Disposition')
 # clean up IE paths
 filename = filename[max(filename.rfind('/'),
 filename.rfind('\\'),
 filename.rfind(':')
)+1:]
 contentType = tmp['Content-Type']
 attach_part = Message()
 attach_part.add_header('Content-Type', contentType, 
name=filename)
 attach_part.add_header('Content-Disposition', 
'attachment', filename=filename)
 attach_part.set_payload(attachment.read())
 Encoders.encode_base64(attach_part)
 mimeMsg.attach(attach_part)
 msg = mimeMsg
 
 # set headers on message
 
 if to is None:
 to = []
 if mfrom:
 to.append(mfrom)
 msg['From'] = mfrom
 msg['Reply-To'] = mfrom
 to = ','.join(to)
 if to: msg['To'] = to
 
 if cc is None:
 cc = []
 cc = ','.join(cc)
 if cc: msg['Cc'] = cc
 
 if bcc is None:
 bcc = []
 bcc = ','.join(bcc)
 if bcc: msg['Bcc'] = bcc
 
 msg['Date'] = self.ZopeTime().rfc822() # needed by some servers
 if inReplyTo:
 msg['In-Reply-To'] = inReplyTo
 msg['Subject'] = Header(subject, site_encoding)
 ##
 # Send the message
 SMTPserver = self._mailhost()
 success = 0
 try:
 cleaner = lambda adresses: [adress.strip() for adress in 
adresses.split(',') if adress.strip()]
 all_receivers = cleaner(to) + cleaner(cc) + cleaner(bcc)
 all_receivers = list(set(all_receivers))
 if all_receivers: # only send if any recipients
 self._mailhost().send(str(msg), mto=all_receivers, 
mfrom=mfrom)
 success = 1
 except:
 pass


-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Addressing the last element of a list

2005-11-08 Thread Bengt Richter
On 8 Nov 2005 01:43:43 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

But if lst[42][pos] happens to hold an integer value, then

a = lst[42][pos]

will _copy_ that integer value into 'a', right? Changing 'a' will not
change the value at lst[42][pos]

Right, but try an example:

  lst = range(42)+[{'pos':123}]+range(43,50)
  lst
 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 
22, 23, 24, 25, 2
 6, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, {'pos': 123}, 
43, 44, 45, 46, 47,
  48, 49]
  lst[41:44]
 [41, {'pos': 123}, 43]
  lst[42]
 {'pos': 123}
  lst[42]['pos']
 123
  a = lst[42]['pos']
  a
 123
  lst[42]['pos']
 123
  id(lst[42]['pos'])
 49421860
  id(a)
 49421860

IOW, a is now an alias for the same 123 immutable integer object as is referred 
to by the 'pos' key
in the dict which is the 43rd element (index 42) of lst.

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


Re: Addressing the last element of a list

2005-11-08 Thread Peter Otten
Jerzy Karczmarczuk wrote:

 Peter Otten wrote:
 [EMAIL PROTECTED] wrote:
 
 
Just to satisfy my curiousity: Is there a way to do something like the
reference solution I suggest above?
 
 
 No. You cannot overload assignment.
 
 I have the impression that this is not an issue, to overload assignments,
 which btw. *can* be overloaded, but the absence of *aliasing*
 (undiscriminate handling of pointers) in Python. Am I wrong?

I think so. 

a = b

will always make a a reference to (the same object as) b. What can be
overloaded is attribute assignment:

x.a = b

can do anything from creating an attribute that references b to wiping your
hard disk.

I don't understand what you mean by absence of aliasing, but conceptually
every python variable is a -- well-behaved -- pointer.

Peter

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


Re: how to stop a loop with ESC key? [newbie]

2005-11-08 Thread Fredrik Lundh
mo [EMAIL PROTECTED] wrote:

 I tryed your example:

 import msvcrt
 while 1:
print '.'
if msvcrt.kbhit() and msvcrt.getch() == chr(27):
 break

 but it doesn't work. It is running (Win2000), there is no messages about
 errors but there is no effect when pressing ESC key. What I am doing wrong?

works for me, when running it from a stock CPython interpreter in a windows
console window, with focus set to that window.

what environment are you using?

/F 



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


recursive function call

2005-11-08 Thread Nicolas Vigier
Hello,

I have in my python script a function that look like this :

def my_function(arg1, arg2, opt1=0, opt2=1, opt3=42):
if type(arg1) is ListType:
for a in arg1:
my_function(a, arg2, opt1=opt1, opt2=opt2, opt3=opt3)
return
if type(arg2) is ListType:
for a in arg2:
my_function(arg1, a, opt1=opt1, opt2=opt2, opt3=opt3)
return
 ... then here the real function code

I'm new to python, so I was wondering if there is a better way to do that.
The reason for a recursive function here is to be able to give lists for
the first 2 args (I could as well use only a simple 'for' without a
recursive call). The problem I have here, is that as I'm working on this
script, I often change the prototype of the function, and each time I
have to think about changing the recursive call too. Is there a way that
I can do a recursive call and say something like keep all the same
arguments except this one ?

Thanks

Nicolas

-- 
http://n0x.org/ - [EMAIL PROTECTED]


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


Re: Addressing the last element of a list

2005-11-08 Thread [EMAIL PROTECTED]
If you want to do what you want(though I don't know why without a
concrete example), just store a mutable object at lst[42][pos], like
this :

lst[42][pos] = [1]

a = lst[42][pos]
a[0] = 2
assert(lst[42][pos][0] == 2)

[EMAIL PROTECTED] wrote:
 But if lst[42][pos] happens to hold an integer value, then

 a = lst[42][pos]

 will _copy_ that integer value into 'a', right? Changing 'a' will not
 change the value at lst[42][pos]

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


Re: Addressing the last element of a list

2005-11-08 Thread Simon Brunning
On 8 Nov 2005 01:43:43 -0800, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 But if lst[42][pos] happens to hold an integer value, then

 a = lst[42][pos]

 will _copy_ that integer value into 'a', right?

Nope. It will bind the name 'a' to the integer object.

 Changing 'a' will not
 change the value at lst[42][pos]

Integers are immutable - they can't be modified. So, Changing 'a'
means binding the name 'a' to a different object. This will have no
effect on other references to the original object.

Reset your brain - http://effbot.org/zone/python-objects.htm.

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


Re: Class Variable Access and Assignment

2005-11-08 Thread Antoon Pardon
Op 2005-11-08, Magnus Lycka schreef [EMAIL PROTECTED]:
 Antoon Pardon wrote:
 Fine that goes both ways. I don't mind not being taken serious by people
 I have trouble taking serious my self. No doubt that goes for you too.

 You know Antoon, these internet communities aren't really like
 Speaker Corner in Hyde Park. You earn respect based on your merits,
 not from the stubborn persistence in you arguments.

 Steve has written a very good book on Python, he's worked a lot
 with Python conferences, and helped people on comp.lang.python
 for years etc. He has earned his respect.

So? Steve can be very good at explaining what python is and
how it behaves and at the same time have poor arguments why
this would be good langauge design.

So although he may have earned his respect in the first,
that doesn't mean I have to take him seriously in the
other.

 You are fighting wind mills, bickering about things that you
 don't have any solutions for.

People should know what they want. If one dares to propose
an alternative here, chances are that you get told to
search a language that behaves as you want, if you don't
you get blamed you don't have a solution.

The only acceptable behaviour, seems to keep quiet about
things where one thinks python could be improved.

 It's possible that you have just
 not realized how Python handles objects, names and classes, but I
 can't understand what you are trying to accomplish. What can you
 possibly try to convey that you haven't already stated? It's
 as if you've got stuck in this thread. In the real world, I
 haven't heard of anyone ever having had problems with this.

Well in the real world nobody seemed to have problems with
the lack of a condtional expression either. Each time someone
brought it up, they were told it wasn't necessary anyway and
how you could simulate it, with some caveat, by using 'and'
and 'or'.

Until it seems one of the developers got bitten by an elusive
bug caused by such a caveat and suddenly there will be a
condional expression in the next version.

So, that we haven't heard of anyone ever having a problem
with it doesn't contradict, that it may one day be the
cause of a very elusive bug.

 This thread is all to infected to lead to good things. Hopefully
 you'll learn something about communication from it, but the price
 has been higher than you might be aware of right now.

Shrug, this is usenet, not my social life.

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


Re: PyFLTK - an underrated gem for GUI projects

2005-11-08 Thread Jeremy Sanders
aum wrote:

 But for smaller gui programs not needing the power of wx, I find I get
 the job done much more quickly and effortlessly with PyFLTK.

Interesting. I've found PyQt very easy to use too. I wonder how they compare
(providing you can GPL your app, of course).

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Addressing the last element of a list

2005-11-08 Thread Peter Otten
[EMAIL PROTECTED] wrote:

 I just want an alias. Ideally, I don't want to deal with pointers or
 special reference types etc. After all, this is not C++ :)
 
 I just want to be able to make a reference to any old thing in Python.
 A list, an integer variable, a function etc. so that I, in complicated
 cases, can make a shorthand. If myRef could somehow point at
 something long an complicated like a[42][pos][-4], that might be
 useful.

You can do

shorthand = a[42][pos]

...

print shorthand[-4]
shorthand[0] = 42 # if a[42][pos] is mutable

But the last indirection must always be given explicitly.

Peter

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


Re: Addressing the last element of a list

2005-11-08 Thread Jerzy Karczmarczuk
Peter Otten wrote cites me:
I have the impression that this is not an issue, to overload assignments,
which btw. *can* be overloaded, but the absence of *aliasing*
(undiscriminate handling of pointers) in Python. Am I wrong?
 
 
 I think so. 
 
 a = b
 
 will always make a a reference to (the same object as) b. What can be
 overloaded is attribute assignment:
 
 x.a = b
 
 can do anything from creating an attribute that references b to wiping your
 hard disk.
 
 I don't understand what you mean by absence of aliasing, but conceptually
 every python variable is a -- well-behaved -- pointer.

Would you please concentrate on - what I underlined - the sense of C aliasing,
where you can make a pointer to point to anything, say, the 176th byte of a
function code?

*This* is impossible in Python. What you wrote is OK, but I still don't know
where I have been wrong, unless you over-interpret my words. Sure, I didn't
want to claim that the assignment a=anything can be plainly overloaded. But
getitem, setitem, getattr, setattr - yes. And they (set-) are also assignments.

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


Re: Sorting Documentation

2005-11-08 Thread [EMAIL PROTECTED]
For example, where can I find the official documentation on the
list.sort() method?

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


Re: recursive function call

2005-11-08 Thread Peter Otten
Nicolas Vigier wrote:

 Hello,
 
 I have in my python script a function that look like this :
 
 def my_function(arg1, arg2, opt1=0, opt2=1, opt3=42):
 if type(arg1) is ListType:
 for a in arg1:
 my_function(a, arg2, opt1=opt1, opt2=opt2,
 opt3=opt3)
 return
 if type(arg2) is ListType:
 for a in arg2:
 my_function(arg1, a, opt1=opt1, opt2=opt2,
 opt3=opt3)
 return
  ... then here the real function code
 
 I'm new to python, so I was wondering if there is a better way to do that.
 The reason for a recursive function here is to be able to give lists for
 the first 2 args (I could as well use only a simple 'for' without a
 recursive call). The problem I have here, is that as I'm working on this
 script, I often change the prototype of the function, and each time I
 have to think about changing the recursive call too. Is there a way that
 I can do a recursive call and say something like keep all the same
 arguments except this one ?

Here is a non-recursive approach: 

def tolist(arg):
if isinstance(arg, list): 
return arg
return [arg]

def f(arg1, arg2, more_args):
for arg1 in tolist(arg1):
for arg2 in tolist(arg2):
# real code

If it were my code I would omit the tolist() stuff and instead always pass
lists (or iterables) as the function's first two arguments.

Peter

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


Re: recursive function call

2005-11-08 Thread Duncan Booth
Nicolas Vigier wrote:

 I have in my python script a function that look like this :
 
 def my_function(arg1, arg2, opt1=0, opt2=1, opt3=42):
 if type(arg1) is ListType:
 for a in arg1:
 my_function(a, arg2, opt1=opt1, opt2=opt2,
 opt3=opt3) 
 return
 if type(arg2) is ListType:
 for a in arg2:
 my_function(arg1, a, opt1=opt1, opt2=opt2,
 opt3=opt3) 
 return
  ... then here the real function code
 
 I'm new to python, so I was wondering if there is a better way to do
 that. The reason for a recursive function here is to be able to give
 lists for the first 2 args (I could as well use only a simple 'for'
 without a recursive call). The problem I have here, is that as I'm
 working on this script, I often change the prototype of the function,
 and each time I have to think about changing the recursive call too.
 Is there a way that I can do a recursive call and say something like
 keep all the same arguments except this one ?
 

This gets messy if the actual first two arguments could also be lists, do 
you really want it to recurse again? I would handle this by having two 
functions, one which takes simple arguments:

def my_function(a, b, opt1=0, opt2=1, opt3=42):
   ... the real function code ...

and one which takes your list arguments:

def my_function_for_sequences(seqA, seqB, *args, **kw):
for a in seqA:
for b in seqB:
my_function(a, b, *args, **kw)

That way you avoid any confusion over the argument types. It won't handle 
the case where only one of a or b is a sequence, but you can handle that 
easily enough by creating a list in the call.

It will also handle the case where you pass an iterable which isn't a list, 
so you have more flexibility there. (Once you are used to Python you should 
get a big red warning light going on in your head any time you see an 
explicit test for a type: not all such cases are bad, but they often 
indicate a code smell.)
-- 
http://mail.python.org/mailman/listinfo/python-list


any python module to calculate sin, cos, arctan?

2005-11-08 Thread Shi Mu
any python module to calculate sin, cos, arctan?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting Documentation

2005-11-08 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote_

I want to read a little bit about sorting in Python (sorted() and
 method sort()). But I can't seem to find anything in the documentation
 at the homepage?

sorted() is a function that works on arbitrary sequences, and is
described in the built-in functions chapter:

http://www.python.org/doc/current/lib/built-in-funcs.html

sort() is a list method, and is documented under sequences:

http://www.python.org/doc/current/lib/typesseq-mutable.html

/F 



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


RE: Pywin32: How to import data into Excel?

2005-11-08 Thread Tim Golden
[Dmytro Lesnyak]
 I need to import some big data into Excel from my 
 Python script. I have TXT file (~7,5 Mb). I'm using 
 Pywin32 library for that, but if I first try to read 
 the TXT file and then save the values one by one like
   xlBook.Sheets(sheet_name).Cells(i,j).Value = value_from_TXT_file
 it takes about 10 hours to process whole data

A few suggestions:

+ When trying to automate anything in Excel, it's
  usually illuminating to record a macro which does
  what you want, and then to translate that VBA code
  into Python.

+ To find documentation on the Microsoft object models,
  MSDN is usually a good bet. Googling for:

  site:msdn.microsoft.com excel object model

  gives some hopeful-looking hits

+ I fiddled around for a few moments, and found that
  the following code at least worked:

code
import win32com.client
xl = win32com.client.gencache.EnsureDispatch (Excel.Application)
xl.Visible = 1
xl.Workbooks.OpenText (c:/temp/temp.txt)
/code

+ If you needed more control, bear in mind that you
  can put lists and lists of lists directly into an
  Excel range. So, something like this:

code
import win32com.client

a = [1, 2, 3]
b = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']]

xl = win32com.client.gencache.EnsureDispatch (Excel.Application)
xl.Visible = 1
wb = xl.Workbooks.Add ()
ws = wb.ActiveSheet
ws.Range (ws.Cells (1, 1), ws.Cells (1, 3)).Value = a
ws.Range (ws.Cells (2, 1), ws.Cells (4, 3)).Value = b

/code

+ Finally, you might look at PyExcelerator. I've toyed with
  it only a little, but it seems to do the business, and
  doesn't need Excel installed (so you can even run it on 
  Linux, if that takes your fancy). It's had a very recent
  release, so it's definitely being maintained:

  http://sourceforge.net/projects/pyexcelerator/

TJG


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

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


Re: what the %?....

2005-11-08 Thread Simon Brunning
On 07/11/05, john boy [EMAIL PROTECTED] wrote:
 Hey can somebody tell me what the % function does...I am not math
 illiterate...its just a new symbol for meis it a divisor? remainder
 something another??

For numeric values, it's the modulo operator - see
http://docs.python.org/ref/binary.html and
http://en.wikipedia.org/wiki/Modular_arithmetic.

Over strings, '%' performs string formatting. See
http://docs.python.org/lib/typesseq-strings.html.

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


Re: Addressing the last element of a list

2005-11-08 Thread [EMAIL PROTECTED]
So there is no way in Python to make an alias for an object?

/David

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


Re: Pylab and pyserial plot in real time

2005-11-08 Thread Juho Schultz
[EMAIL PROTECTED] wrote:
 Hiya,
 
 I've got a PIC microcontroller reading me humidity data via rs232, this
 is in ASCII format. I can view this data easily using hyperterminal or
 pyserial and convert it to its value (relative humidty with ord(input))
 
 But what im trying to do is plot the data in real time, ideally with
 pylab - as it looks simple to use and simple is the way i want to go!
 
This might be close to what you are trying to do:

import time
import pylab
# interactive mode on
pylab.ion()
timefig = pylab.figure(1)
timesub = pylab.subplot(111)
dt = 0.1
t = pylab.arange(0.0, 2.0, dt)
h = 1.2*pylab.sin(t)
lines = pylab.plot(t,h)
for i in range(8):
 t = t + dt
 h = 1.2*pylab.sin(t)
 lines[0].set_data(t,h)
 timesub.set_xlim((t[0],t[-1]))
 pylab.draw()
 time.sleep(1.0)

It shows a piece of sine curve, and updates the x-axis with time.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: any python module to calculate sin, cos, arctan?

2005-11-08 Thread Dennis Benzinger
Shi Mu schrieb:
 any python module to calculate sin, cos, arctan?

Yes.

Use the math module or the cmath module if you need
mathematical functions for complex numbers.

Bye,
Dennis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pywin32: How to import data into Excel?

2005-11-08 Thread Simon Brunning
On 08/11/05, Dmytro Lesnyak [EMAIL PROTECTED] wrote:
 I need to import some big data into Excel from my Python script. I have TXT
 file (~7,5 Mb).

Have you considered converting your text data to CSV format? Excel
opens CSV files happily enough, and you could always automate
save-as-workbook and any formatting you need afterwards.

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


Re: any python module to calculate sin, cos, arctan?

2005-11-08 Thread Simon Brunning
On 08/11/05, Shi Mu [EMAIL PROTECTED] wrote:
 any python module to calculate sin, cos, arctan?

http://docs.python.org/lib/module-math.html

I seem to be posting loads of links to the docs today...

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


Re: any python module to calculate sin, cos, arctan?

2005-11-08 Thread Juho Schultz
Shi Mu wrote:
 any python module to calculate sin, cos, arctan?

math

There are two versions of arctan: atan and atan2.
atan2(y,x) does the quadrant selection
you do not get from atan(y/x)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting Documentation

2005-11-08 Thread Simon Brunning
On 8 Nov 2005 02:27:29 -0800, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 I want to read a little bit about sorting in Python (sorted() and
 method sort()). But I can't seem to find anything in the documentation
 at the homepage?

Sorted() is documented here -
http://docs.python.org/lib/built-in-funcs.html#l2h-66.

(All found from  here, BTW - http://docs.python.org/lib/genindex.html.)

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


Re: Addressing the last element of a list

2005-11-08 Thread Matt Hammond
On Tue, 08 Nov 2005 10:25:21 -, Jerzy Karczmarczuk  
[EMAIL PROTECTED] wrote:

 Would you please concentrate on - what I underlined - the sense of C  
 aliasing,
 where you can make a pointer to point to anything, say, the 176th byte  
 of a
 function code?

Pretty much everything is referred to by reference in python. The big  
difference is that most
primitive data types (integer, string) etc... aren't mutable - you can't  
change them in place - instead you replace them with a new instance  
containing the new/modified value.

But your own object and lists are mutable - you can change their  
attributes. So encapsulate data within a list or as an attribute of an  
object and you've got the effect you're after.

For example:

 a = 5; b = a
 a = 6
 a,b
(6, 5)

Whereas:

 a = [5]; b = a
 a[0] = 6
 a,b
([6], [6])

Note that reassigning a:
 a = [6]
causes a to point to a new list, containing the value 6, whereas the 2nd  
example above modified the list by replacing an element of it.


Hope this helps


Matt

-- 

| Matt Hammond
| RD Engineer, BBC Research  Development, Tadworth, Surrey, UK.
| http://kamaelia.sf.net/
| http://www.bbc.co.uk/rd/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to stop a loop with ESC key? [newbie]

2005-11-08 Thread Mikael Olofsson
Fredrik Lundh wrote:
 works for me, when running it from a stock CPython interpreter in a windows
 console window, with focus set to that window.
 
 what environment are you using?

Could be IDLE. The code Fredrik proposed works well for me in the Python 
console window, but not in IDLE (thats under XP). I guess that IDLE 
makes use of msvcrt itself. Let's remember that the OP describes himself 
as a newbie in the subject, so he might not know the difference between 
those two interactive environments.

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


Re: any python module to calculate sin, cos, arctan?

2005-11-08 Thread Mikael Olofsson
Shi Mu wrote:
 any python module to calculate sin, cos, arctan?

Try module math. Or cmath if you want the functions to be aware of 
complex numbers.

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


Re: Addressing the last element of a list

2005-11-08 Thread Giovanni Bajo
[EMAIL PROTECTED] wrote:

 I just want an alias.

What you want is impossible. But there are many workarounds.

 I just want to be able to make a reference to any old thing in Python.
 A list, an integer variable, a function etc. so that I, in complicated
 cases, can make a shorthand. If myRef could somehow point at
 something long an complicated like a[42][pos][-4], that might be
 useful.


One simple workaround:

def createAlias(L, idx1, idx2, idx3):
 def setval(n):
 L[idx1][idx2][idx3] = n
 return setval

k = createAlias(a, 42, pos, -4)

[...]

n = computeValue(...)
k(n)   # store it!


You will also find out that your case is actually very unlikely in
well-designed code. You don't usually work with stuff with three level of
nesting like a[][][], since it gets totally confusing and unmaintanable. You
will end up always with objects with better semantic, and methods to modify
them. So in the end you will always have a reference to the moral equivalent of
a[42][pos], and that would be a well defined object with a method setThis()
which will modify the moral equivalent of [-4].
-- 
Giovanni Bajo


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


Re: Sorting Documentation

2005-11-08 Thread Simon Brunning
On 8 Nov 2005 02:32:44 -0800, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 For example, where can I find the official documentation on the
 list.sort() method?

http://docs.python.org/lib/typesseq-mutable.html

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


parabola

2005-11-08 Thread Shi Mu
Is there any sample code to draw parabola using Tkinter?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.getmtime on winXP

2005-11-08 Thread Bengt Richter
On Tue, 08 Nov 2005 10:49:56 +0100, =?ISO-8859-1?Q?Jorg_R=F8dsj=F8?= [EMAIL 
PROTECTED] wrote:

Bengt Richter wrote:
 How did you format the number you got from os.path.getmtime?

I'm not doing any formating at all. I am just looking at the numbers of 
seconds since epoch. Which is what makes it so strange.

 You might want to try some of the above.

I'll do that. At the moment I'm looking at the difference between 
localtime and gmtime to see if my computer is in dst. If it is not, I 
just add 3600 seconds to the result from os.path.getmtime -- which then 
should give consistent results.
the time module should know how to do that for you, unless something is fubar.

see time.timz
import time
help(time)


 If you actually created/modified files just before and after the DST change
 and saw an extra hour difference instead of the time between the two actions,
 then maybe I'd look into whether the OS has some perverse option to use 
 local DST
 time to record in the file stat info, but that's hard to believe. More 
 likely someone
 is messing with with raw file time setting, like touch. Don't have it handy 
 to see
 what DST assumptions it makes if any.

The files I am testing with have not been modified for a long time. 
Windows reports the modified date as being the same, no matter what I do 
(both through the gui, and through win32file). And they all show the 
same strange 3600 sec difference with/without dst when I call getmtime 
on them.
By 'getmtime' you mean os.path.getmtime(fer_shure_or_absolute_path_to_file) 
right?
Doesn't that get you an integer number of seconds? What GUI or win32file is 
showing you
that integer so you see a 3600 sec difference? Or how are you seeing it?

Could you paste an example of this difference from an example on your screen?
I don't think I am understanding ;-) ... urk, it's late ;-/

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


RE: Pywin32: How to import data into Excel?

2005-11-08 Thread Dmytro Lesnyak
Thanks a lot. It really works! 
Now, I can solve my problem and make my script faster!

 A few suggestions:
 
 + When trying to automate anything in Excel, it's
  usually illuminating to record a macro which does
  what you want, and then to translate that VBA code
  into Python.

Yes, I also doing VBA macros first, but sometimes it is difficult for me
to translate it into Python.

 + To find documentation on the Microsoft object models,
  MSDN is usually a good bet. Googling for:

  site:msdn.microsoft.com excel object model

Thanks. I got very good links

 I fiddled around for a few moments, and found that
  the following code at least worked:

 code
 import win32com.client
 xl = win32com.client.gencache.EnsureDispatch (Excel.Application)
xl.Visible = 1 xl.Workbooks.OpenText 
 (c:/temp/temp.txt) /code

Yes. It works. I wonder why I did not in my case. 
It's strange, but if you put 

xl.Visible = 1

after  xl.Workbooks.OpenText(c:/temp/temp.txt)
It doesn't display the result. Probably, it is some Excel's feature :)


+ If you needed more control, bear in mind that you
  can put lists and lists of lists directly into an
  Excel range. So, something like this:

 code
 import win32com.client

 a = [1, 2, 3]
 b = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']]
 
 xl = win32com.client.gencache.EnsureDispatch (Excel.Application)
xl.Visible = 1 wb = xl.Workbooks.Add () ws =  wb.ActiveSheet ws.Range
(ws.Cells (1, 1), ws.Cells (1, 3)).Value = a ws.Range (ws.Cells (2, 1),
ws.Cells (4, 3)).Value = b

 /code

I didn't know that. Probably, It would be faster.

 + Finally, you might look at PyExcelerator. I've toyed with
  it only a little, but it seems to do the business, and
  doesn't need Excel installed (so you can even run it on
  Linux, if that takes your fancy). It's had a very recent
  release, so it's definitely being maintained:

  http://sourceforge.net/projects/pyexcelerator/

Good option. Thanks :)

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


Re: Addressing the last element of a list

2005-11-08 Thread Peter Otten
Jerzy Karczmarczuk wrote:

 Sure, I didn't want to claim that the assignment a=anything can be plainly
 overloaded. 

I interpreted your previous post as such a claim. No disagreement here then.

 Would you please concentrate on - what I underlined - the sense of C
 aliasing, where you can make a pointer to point to anything, say, the
 176th byte of a function code? 

I've never heard the expression aliasing for that, sorry.

 This is impossible in Python.

Of course, but I don't think this is what the OP wanted. 

Peter

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


Re: PYTHON LOOSING FOR JAVA???????

2005-11-08 Thread Jarek Zgoda
Fcamattti napisał(a):

  So I have a doubt. I'd like to know what do you think about the joint
 of efforts of Sun Microsystems and the Google to create a office web
 based. I sincerely enjoy the idea althoug I'd like to know what will be
 the future of this wonderful language called Python??

Sun and Google do not cover 100% of possible uses of Python. From my POV
i.e., they have nothing that could help in writing ETL tasks helpers on
iSeries. Python is unstoppable here. ;)

Computing is large area. Much larger than aunt Tilly's laptop.

-- 
Jarek Zgoda
http://jpa.berlios.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Sorting Documentation

2005-11-08 Thread [EMAIL PROTECTED]
I want to read a little bit about sorting in Python (sorted() and
method sort()). But I can't seem to find anything in the documentation
at the homepage?

/David

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


Writing Win32 shell extensions in python?

2005-11-08 Thread Thomas W
Well, is it possible to write Win32 shell extension in python? I want
to create a virtual folder ( like gmailfs ) to serve files from a
http-server ( and no, I cannot use webdav ) so that users can access
them like normal files in Windows Explorer.

Any hints or info about this would be highly appreciated.

Regards,
Thomas

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


Re: Pywin32: How to import data into Excel?

2005-11-08 Thread BJ Swope
On 11/8/05, Dmytro Lesnyak [EMAIL PROTECTED] wrote:





Hello,


I need to import some big 
data into Excel from my Python 
script. I have TXT file (~7,5 Mb). I'm using Pywin32 library for that, but if I 
first try to read the TXT file and then save the values one by one 
like


I have to question the reasoning behind using Excel. That much
data seems like it would be troublesome to manage in Excel. How
good is Excel at working with that much data?
-- 
http://mail.python.org/mailman/listinfo/python-list

RE: Pywin32: How to import data into Excel?

2005-11-08 Thread Dmytro Lesnyak



 
I have to question the reasoning behind using 
Excel. That much data seems like it would be troublesome to manage in 
Excel. How good is Excel at working with that much data?

Well,It's not that big data. As result, It willbe 52 X 25000 
table and it works fine in Excel 
(f.e. I need to make several Pivot tables from that data and it is really 
fast).
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Pylab and pyserial plot in real time

2005-11-08 Thread Jeremy Sanders
[EMAIL PROTECTED] wrote:

 Does anyone know of a module designed for ploting real time data thats
 more appropriate for the above mentioned task than pylab??

You could have a look at my plotting package, Veusz, which can be embedded
in other apps. You can update the data in real time, as the windowing runs
in a separate thread.

The main problem is that I have only really tested it on Unix, but I have
reports that it mostly works in Windows (I'm looking into supporting this
soon).

http://home.gna.org/veusz/

Alternatively matplotlib may be another solution.

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to stop a loop with ESC key? [newbie]

2005-11-08 Thread mo
Fredrik Lundh  wrote:
 works for me, when running it from a stock CPython interpreter in a
windows
 console window, with focus set to that window.
 what environment are you using?

I use IDLE 1.0.3, Python 2.3.4
The same problem is when running in a win console.
mo


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


Re: Sorting Documentation

2005-11-08 Thread Xah Lee

[EMAIL PROTECTED] wrote:
«I want to read a little bit about sorting in Python (sorted() and
method sort()). But I can't seem to find anything in the documentation
at the homepage?»

if you want some detailed account on the sort method, see:
http://www.xahlee.org/perl-python/sort_list.html

 Xah
 [EMAIL PROTECTED]
∑ http://xahlee.org/

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

Re: parabola

2005-11-08 Thread Salvatore
Here is an old piece of code I wrote when begining Python ;-)

from Tkinter import *

import string
import Numeric
from Canvas import Line
import math

class Tableau(Canvas):
def
__init__(self,master=None,size=400,col='black',colrep='red',colgrid='grey'):

Canvas.__init__(self,master,width=size,height=size,bg=col,highlightthickness=0)
self.pack(expand=1,fill=BOTH)
self.width_table = 0; self.height_table = 0
self.nl = 20.0
self.bind(Configure,self.Redraw)
self.colrep = colrep
self.colgrid = colgrid

def GetSize(self,event):
self.width_table = event.width
self.height_table = event.height

def SetBgColor(self,color):
self['bg'] = color

def ChangeColGrid(self,col):
self.colgrid = col
self.itemconfig('grid',fill=col)

def ChangeColAxe(self,col):
self.colrep = col
self.itemconfig('repere',fill=col)

def Redraw(self,event):
self.delete('all')
self.TraceAxe()
self.UpdateGraphe()
self.update()

def Redessine(self):
self.delete('all')
self.TraceAxe()
#self.UpdateGraphe()
self.update()

def TraceAxe(self):
self.delete('all')
w , h = self.winfo_width(),self.winfo_height()

#Trace Grille
posx=0;posy=0
intervallex = w/self.nl
intervalley = h/self.nl
posx=intervallex;posy=intervalley
for i in range(0,self.nl):

self.create_line(posx,0,posx,h,fill=self.colgrid,tag=('repere','grid'))

self.create_line(0,posy,w,posy,fill=self.colgrid,tag=('repere','grid'))
posy += intervalley
posx += intervallex
#Trace des axes
posx = w/2.0; posy = h/2.0

self.create_line(posx,0,posx,h,fill=self.colrep,tag=('repere','axe'))

self.create_line(0,posy,w,posy,fill=self.colrep,tag=('repere','axe'))


def UpdateGraphe(self):
for f in F.keys():
try:
name,color = F[f]
Function(f,nom=name,col=color)
except:
Function(f)

class Function:
def __init__(self,fonction = '',nom='affine',col='yellow',epaiss =
1):
w , h = t.winfo_width(),t.winfo_height()
self.valeur = eval('lambda x: '+fonction)
self.x = Numeric.arange(-200.0,200.0)
self.y = 20*self.valeur(self.x/20.0)
res = Numeric.arange(0.0,800.0)
res.shape = (400,2)
res[:,0] = self.x*w/400.0 + w/2.0
res[:,1] = -self.y*h/400.0 + h/2.0
Line(t,res.tolist(),fill=col,tag=nom,width=epaiss)

def expression(exp):
return eval('lambda x: '+exp)


if __name__ == '__main__':
print test
sin = Numeric.sin
F =
{'x*x':('carre','green'),'2*sin(x)':('sin','blue'),'x*x*x':('cube','yellow')}
t = Tableau()
t.delete('grid')
t.mainloop()
from Tkinter import *

import string
import Numeric
from Canvas import Line
import math

class Tableau(Canvas):
def
__init__(self,master=None,size=400,col='black',colrep='red',colgrid='grey'):

Canvas.__init__(self,master,width=size,height=size,bg=col,highlightthickness=0)
self.pack(expand=1,fill=BOTH)
self.width_table = 0; self.height_table = 0
self.nl = 20.0
self.bind(Configure,self.Redraw)
self.colrep = colrep
self.colgrid = colgrid

def GetSize(self,event):
self.width_table = event.width
self.height_table = event.height

def SetBgColor(self,color):
self['bg'] = color

def ChangeColGrid(self,col):
self.colgrid = col
self.itemconfig('grid',fill=col)

def ChangeColAxe(self,col):
self.colrep = col
self.itemconfig('repere',fill=col)

def Redraw(self,event):
self.delete('all')
self.TraceAxe()
self.UpdateGraphe()
self.update()

def Redessine(self):
self.delete('all')
self.TraceAxe()
#self.UpdateGraphe()
self.update()

def TraceAxe(self):
self.delete('all')
w , h = self.winfo_width(),self.winfo_height()

#Trace Grille
posx=0;posy=0
intervallex = w/self.nl
intervalley = h/self.nl
posx=intervallex;posy=intervalley
for i in range(0,self.nl):

self.create_line(posx,0,posx,h,fill=self.colgrid,tag=('repere','grid'))

self.create_line(0,posy,w,posy,fill=self.colgrid,tag=('repere','grid'))
posy += intervalley
posx += intervallex
#Trace des axes
posx = w/2.0; posy = h/2.0

self.create_line(posx,0,posx,h,fill=self.colrep,tag=('repere','axe'))

self.create_line(0,posy,w,posy,fill=self.colrep,tag=('repere','axe'))


def UpdateGraphe(self):
for f in F.keys():
try:
name,color = F[f]
Function(f,nom=name,col=color)
except:
Function(f)

class Function:
def __init__(self,fonction = '',nom='affine',col='yellow',epaiss =
1):
w , h = 

Re: parabola

2005-11-08 Thread Salvatore
Here is an old piece of code I wrote to test Tkinter

from Tkinter import *

import string
import Numeric
from Canvas import Line
import math

class Tableau(Canvas):
def
__init__(self,master=None,size=400,col='black',colrep='red',colgrid='grey'):

Canvas.__init__(self,master,width=size,height=size,bg=col,highlightthickness=0)
self.pack(expand=1,fill=BOTH)
self.width_table = 0; self.height_table = 0
self.nl = 20.0
self.bind(Configure,self.Redraw)
self.colrep = colrep
self.colgrid = colgrid

def GetSize(self,event):
self.width_table = event.width
self.height_table = event.height

def SetBgColor(self,color):
self['bg'] = color

def ChangeColGrid(self,col):
self.colgrid = col
self.itemconfig('grid',fill=col)

def ChangeColAxe(self,col):
self.colrep = col
self.itemconfig('repere',fill=col)

def Redraw(self,event):
self.delete('all')
self.TraceAxe()
self.UpdateGraphe()
self.update()

def Redessine(self):
self.delete('all')
self.TraceAxe()
#self.UpdateGraphe()
self.update()

def TraceAxe(self):
self.delete('all')
w , h = self.winfo_width(),self.winfo_height()

#Trace Grille
posx=0;posy=0
intervallex = w/self.nl
intervalley = h/self.nl
posx=intervallex;posy=intervalley
for i in range(0,self.nl):

self.create_line(posx,0,posx,h,fill=self.colgrid,tag=('repere','grid'))

self.create_line(0,posy,w,posy,fill=self.colgrid,tag=('repere','grid'))
posy += intervalley
posx += intervallex
#Trace des axes
posx = w/2.0; posy = h/2.0

self.create_line(posx,0,posx,h,fill=self.colrep,tag=('repere','axe'))

self.create_line(0,posy,w,posy,fill=self.colrep,tag=('repere','axe'))


def UpdateGraphe(self):
for f in F.keys():
try:
name,color = F[f]
Function(f,nom=name,col=color)
except:
Function(f)

class Function:
def __init__(self,fonction = '',nom='affine',col='yellow',epaiss =
1):
w , h = t.winfo_width(),t.winfo_height()
self.valeur = eval('lambda x: '+fonction)
self.x = Numeric.arange(-200.0,200.0)
self.y = 20*self.valeur(self.x/20.0)
res = Numeric.arange(0.0,800.0)
res.shape = (400,2)
res[:,0] = self.x*w/400.0 + w/2.0
res[:,1] = -self.y*h/400.0 + h/2.0
Line(t,res.tolist(),fill=col,tag=nom,width=epaiss)

def expression(exp):
return eval('lambda x: '+exp)


if __name__ == '__main__':
print test
sin = Numeric.sin
F =
{'x*x':('carre','green'),'2*sin(x)':('sin','blue'),'x*x*x':('cube','yellow')}
t = Tableau()
t.delete('grid')
t.mainloop()

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


Re: socket receive file does not match sent file

2005-11-08 Thread [EMAIL PROTECTED]
Thanks Fredrik Lundh,
 This is great!

I've rewrote the code and it works!
Thanks a lot.

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


which feature of python do you like most?

2005-11-08 Thread [EMAIL PROTECTED]
which feature of python do you like most?

I've heard from people that python is very useful.
Many people switch from perl to python because they like it more.

I am quite familiar with perl, I've don't lots of code in perl.
Now, I was curious and interested in the python people.
They certainly made their best choice from perl to python.

but i have no interesting python experence before, thought i've read a
few chapters
of a python tutorial book. The things are much like the perl one.

I have no idea why people are so facinating with python.
So I post this question:  What do you use in your dairy work with
python?
what is the thing that python makes you happy?


I certainly don't want to miss a language if it's so great!
can anyone share your happy experence with python?

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


Re: Writing Win32 shell extensions in python?

2005-11-08 Thread Fredrik Lundh
Thomas W [EMAIL PROTECTED] wrote:

 Well, is it possible to write Win32 shell extension in python? I want
 to create a virtual folder ( like gmailfs ) to serve files from a
 http-server ( and no, I cannot use webdav ) so that users can access
 them like normal files in Windows Explorer.

 Any hints or info about this would be highly appreciated.

typing your subject into a google search box brings up plenty of hits,
including

http://mail.python.org/pipermail/python-list/2005-March/271141.html

From: Roger Upole
Date: Tue Mar 15 12:39:43 CET 2005

There's an example shell extension in the Pywin32 demos
that creates a pseudo-folder whose contents are determined by
python code.  Take a look at
\win32comext\shell\demos\servers\shell_view.py.
However, I don't think it qualifies as 'simple' ;)

(alright, that one was two clicks away from the search result, not one, but
that's close enough)

here's a direct pointer to an on-line copy of that script, btw:

http://tinyurl.com/babct

(that copy may be outdated; you may want to get the latest version from the
pywin package before you start hacking on this)

/F 



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


Re: any python module to calculate sin, cos, arctan?

2005-11-08 Thread Raymond L. Buvel
Shi Mu wrote:
 any python module to calculate sin, cos, arctan?

The other answers in this thread point you to the standard modules.  If
you need arbitrary precision floating point versions of these functions
check out:

http://calcrpnpy.sourceforge.net/clnumManual.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.getmtime on winXP

2005-11-08 Thread Jorg Rødsjø
Bengt Richter wrote:
 By 'getmtime' you mean os.path.getmtime(fer_shure_or_absolute_path_to_file) 
 right?
 Doesn't that get you an integer number of seconds? What GUI or win32file is 
 showing you
 that integer so you see a 3600 sec difference? Or how are you seeing it?
 
 Could you paste an example of this difference from an example on your screen?
 I don't think I am understanding ;-) ... urk, it's late ;-/

(Btw: thanks for the interest.)

Step by step example:
[I do of cource not modify the foo.py-file at any time during the testing.]

With the system-date set to the 8th of november(no dst) I run the following
os.path.getmtime('spam.py'), and get 1045578240 as the result.

With the system-date set to the 8th of october(dst) I run the following
os.path.getmtime('spam.py'), and get 1045581840 as the result.

This is what boggles my mind. These numbers should be the same -- right? 
Not offsett by 3600.

On both dates, calling Windows win32file.GetFileTime (from the Python 
Win32 Extensions) gives me the time 02/18/03 14:24:00 -- i.e. the same 
both before and after setting the time.

I have not looked at the source to either win32file.GetFileTime or 
os.path.getmtime, but I should think that they should both call the same 
underlying Windows-function.

I hope this makes it more clear. Any idea why this happens?

regards
Jorg Rødsjø
-- 
http://mail.python.org/mailman/listinfo/python-list


Exposing a COM interface to embedded scripts via PythonCOM

2005-11-08 Thread cookie__raver
I have a host process that exposes a COM object to embedded Python
scripts, and want it to appear to the Python scripts as a smart COM
object, in the same way that Python COM provides. The Python scripts
would then be able to use expected methods and properties, in the same
way that one does with Python COM.

I am hoping to find some function along the lines of
PyCOM_WrapRawIUnknown(), but have no idea whether such a thing exists,
and where I might obtain it.

If no such thing exists, I imagine I'll have to write a full extension
for the COM interfaces, which would be a mighty big pain. ;-)

Many thanks in advance

The Cookie

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


Re: Is mod_python 3.1 good for commercial blogging/CMS?

2005-11-08 Thread Ben Sizer
Anthony L. wrote:
 1. I want to use CGI through Publisher handler, instead of CGI handler
 or PSP. Despite the speed increase mod_python gives me, there is a
 problem of persistence that can be a problem when dealing with a site
 that will hosts potentially hundreds of simultaneous users.

What problem? Could you elaborate further?

 3. I am not very attracted to PSP because I want to separate the logic
 from the presentation as completely as possible, and PHP and other
 template languages including PSP seem difficult to do that in.

In theory, people use these templates to /improve/ the separation
between logic and presentation. When you just use req.write() you're
inevitably mixing logic and presentation. At least with the template
systems, you do the presentation once and the logic fills in the gaps.
It's even possible to edit the presentation in many WYSIWYG web editors
without affecting the code.

 Why can't I just use req.write() to
 output my markup, relying completely on external CSS after the fact?

You can, and in fact this is largely what I do. But the HTML/CSS divide
is not exactly in the same place as the template/CGI-style divide. You
can still delegate most of the presentation work to CSS no matter how
you emit your HTML.

It as not easy to work with the CGI-style code in a WYSIWYG web editor
as it is to edit a template, which is probably the main reason for
their use. Also, coding everything with req.write() means that each
page is very idiosyncratic, making for poor code-reuse. In theory.

 My
 thought is that HTML templates provide a minimum set of static code that
 doesn't require extra processing, thus keeping performance up. However,
 if I minimize my use of req.write() will it make a difference?

I don't think performance is a factor, really. HTML templates tend to
exist so that you can structure the page without worrying about the
Python code. They work well for fairly uniform pages that largely
require the same sort of data on each page. I am more of a programmer
than a designer so I prefer to think in terms of code and emit HTML as
it suits me.

 I'd appreciate some practical advise on this. I am funding this myself
 on a small budget with no hard deadline, so it is critical to me that I
 choose a language that will minimize my costs. Are my assumptions
 correct, or am I falling prey to FUD?

Python is a good language for rapid development and hence testing. So
you could probably create a quick mock-up of your system and then write
some scripts to place it under heavy stress to see how well it holds
up.

-- 
Ben Sizer

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


Re: recursive function call

2005-11-08 Thread Nicolas Vigier
Peter Otten said:
 Here is a non-recursive approach:

 def tolist(arg):
if isinstance(arg, list):
return arg
return [arg]

 def f(arg1, arg2, more_args):
for arg1 in tolist(arg1):
for arg2 in tolist(arg2):
# real code

 If it were my code I would omit the tolist() stuff and instead always
 pass lists (or iterables) as the function's first two arguments.

Hmm, that's right. After all it's not very useful to be able to give
a single element, passing a list all the time is more simple. That's
what I'll do. I got the idea of passing a list or a singe element
because that's what they do in SCons, but in my case it's not really
usefull.

Thanks

-- 
http://n0x.org/ - [EMAIL PROTECTED]


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


Re: Web automation

2005-11-08 Thread Paul Boddie
Mike Meyer wrote:
 Paul Boddie [EMAIL PROTECTED] writes:
  The problem on non-Windows systems is the lack of a common (or
  enforced) technology for exposing application object models

 OS X has AppleScript. VM/CMS has Rexx. The Amiga had ARexx when MS was
 still peddling DOS. Plan 9 has files.

I knew I should have written UNIX systems or non-Windows but still
mainstream systems. ;-)

 I don't think any of them are enforced - then again, I don't think anything 
 enforces
 exporting objects from Windows applications, either.

No, but COM is the obvious choice for doing so on Windows. Combine that
with the component developer mindset and it's likely that some kind of
object model will be exposed by an application.

Still, I wouldn't say that automation is necessarily ass-backwards:
sometimes you want the additional baggage that the browser can give you
- witness the occasional comp.lang.python thread about working with
JavaScript-laden pages - and it's not necessarily automation involving
the activation of coincidental user interface components (find the
Register Later button in the Register Now? pop-up dialogue and
click on it) that's involved here either.

Yes, the very architecture of the Web should have made automation tasks
a lot more open and convenient, but sometimes there's a need for a
complete browser to get at the data.

Paul

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


Diff. between Class types and classic classes

2005-11-08 Thread venk
Hi,
  can some one properly explain the differences between class types and
classic classes? ... Still face problems in identifying what is what.

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


Re: Python doc problem example: gzip module (reprise)

2005-11-08 Thread Xah Lee
Newsgroups: comp.lang.perl.misc
From: Veli-Pekka Tätilä
Date: Sat, 5 Nov 2005 17:25:35 +0200
Subject: Re: Python doc problem example: gzip module (reprise)

Xah Lee wrote:
 Today i need to use Python to compress/decompress gzip files. snip
 However, scanning the doc after 20 seconds there's no single example
 showing how it is used.
 jargons of Class, Constructor, Object etc are thrown together with
 presumption of reader's expertise of IO programing in Python snip

I se the problem now. Perl usually doesn't have that kind of trouble as

there are plenty of example snippets and the synopsis part even before
the
description.

But if you want to bash the Python docs, I'd like to mention that they
are
pretty inaccessible and unmanagable with speech. Here's my post about
it in
comp.langh.python:

URL:

http://tinyurl.com/dfrb7

(or search Google Groups with vtatila python)

Though I've carefully explain the problems and provided a number of
solutions, no-one has replied yet. I reckon that, ether people don't
know
what I'm talking about accessibility being such a nieche topic still,
or
else my explanation is all too elaborate or just heavy to read through.

Well, I've tried. Yet another reason to stay with Perl. Whose docs are,
by
the way, very accessible in general.

PS: I won't cross-post as I'm not subscribed to the Python group.
---

Thank you Veli-Pekka Tätilä for your thoughtful reply.

I have cross posted it for you.

 Xah
 [EMAIL PROTECTED]
∑ http://xahlee.org/

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

Re: Sending email in utf-8?

2005-11-08 Thread Fredrik Lundh
morphex [EMAIL PROTECTED] wrote:

 
 Date: Mon, 7 Nov 2005 11:38:29 -0700 (MST)
 Message-Id: [EMAIL PROTECTED]
 To: [EMAIL PROTECTED], [EMAIL PROTECTED]
 From: [EMAIL PROTECTED]
 Subject:  Order confirmation
 Content-Type: text/plain; charset=utf-8
 X-Bogosity: No, tests=bogofilter, spamicity=0.00, version=0.92.8

 Thank you for your order, it is copied here for your convenience, and
 we will process it shortly.

 Name:  ø
 Phone: ø
 Email:  [EMAIL PROTECTED]
 Comments:  asdf
 

that's 0xC3 0xB8 (at least according to my mail reader), which, translated
back from UTF-8, looks like a typically norsk character to me...

 name = \xc3\xb8.decode(utf-8)

 print name
ø

 import unicodedata
 unicodedata.name(name)
'LATIN SMALL LETTER O WITH STROKE'

try adding a Mime-Version: 1.0 header to your mail.

a Content-Transfer-Encoding: 8bit might not hurt either (or run the body 
through
quopri.encodestring() after you've encoded it, and use 
Content-Transfer-Encoding:
quoted-printable).

(also check the email package: http://docs.python.org/lib/module-email.html )

/F 



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

RE: Pywin32: How to import data into Excel?

2005-11-08 Thread Duncan Booth
Tim Golden wrote:

 [Dmytro Lesnyak]
 I need to import some big data into Excel from my 
 Python script. I have TXT file (~7,5 Mb). I'm using 
 Pywin32 library for that, but if I first try to read 
 the TXT file and then save the values one by one like
 xlBook.Sheets(sheet_name).Cells(i,j).Value = value_from_TXT_file
 it takes about 10 hours to process whole data
 
 A few suggestions:
 
 + When trying to automate anything in Excel, it's
   usually illuminating to record a macro which does
   what you want, and then to translate that VBA code
   into Python.
 

Another suggestion: when automating Excel, turn off the automatic 
recalculation (set Application.Calculation=xlManual) and then turn it back 
on again when you have finished.

If you don't do this, Excel will attempt to recalculate the sheet after 
every update to a cell. Even if you don't have any formulae referencing the 
cells you change it still makes a big difference.

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


RE: Pywin32: How to import data into Excel?

2005-11-08 Thread Tim Golden
[Tim Golden]
 + When trying to automate anything in Excel, it's
   usually illuminating to record a macro which does
   what you want, and then to translate that VBA code
   into Python.
 

[Duncan Booth]
 Another suggestion: when automating Excel, turn off the automatic 
 recalculation (set Application.Calculation=xlManual) and then turn it
back 
 on again when you have finished.

 If you don't do this, Excel will attempt to recalculate the sheet
after 
 every update to a cell. Even if you don't have any formulae
referencing the 
 cells you change it still makes a big difference.

Thanks. Didn't know that.

TJG


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

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


SPE IDE for Python

2005-11-08 Thread py
Anyone here use SPE (http://www.stani.be/python/spe/blog/). ...the IDE?

Also, anyone know if it supports CVS or has a plugin for CVS?  If not,
what do you use to get your code into CVS (via an IDE preferably)?

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


XML GUI

2005-11-08 Thread py
Looking for information on creating a GUI using a configuration file
(like an XML file or something).  Also, how do you map actions (button
clicks, menu selections, etc) to the XML?

Any other suggestions for building GUI's for Python projects...even
Jython.

Thanks

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


Re: which feature of python do you like most?

2005-11-08 Thread Benji York
[EMAIL PROTECTED] wrote:
 I have no idea why people are so facinating with python.
 So I post this question:  What do you use in your dairy work with
 python?

I can't imagine why you're confused.
--
Benji York
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: any python module to calculate sin, cos, arctan?

2005-11-08 Thread Matt Feinstein
On Tue, 08 Nov 2005 12:30:35 GMT, Raymond L. Buvel
[EMAIL PROTECTED] wrote:

Shi Mu wrote:
 any python module to calculate sin, cos, arctan?

The other answers in this thread point you to the standard modules.  If
you need arbitrary precision floating point versions of these functions
check out:

http://calcrpnpy.sourceforge.net/clnumManual.html

Unless you're using Windows.

Matt Feinstein

--
There is no virtue in believing something that can be proved to be true.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Addressing the last element of a list

2005-11-08 Thread Steven D'Aprano
On Tue, 08 Nov 2005 01:31:31 -0800, [EMAIL PROTECTED] wrote:

 So there is no way in Python to make an alias for an object?

Yes, sort of. Bind two names to the same mutable object:

py x = [Something mutable]
py y = x
py y.append(this way comes.)
py print x
['Something mutable', 'this way comes.']

Note that this only works with mutable objects like lists and dicts, and
is a side effect of mutability, rather than a deliberate alias.

In general, you can bind multiple names to the same object. The one liner

x = y = 1

is the same as the two liner

x = 1
y = x

Both create two names, x and y, and sets them both to the same int 1.

Because ints are immutable, if you rebind one name, the other one will
NOT change:

py x += 1
py print x, y
2, 1


-- 
Steven.

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


Re: Addressing the last element of a list

2005-11-08 Thread Steven D'Aprano
On Tue, 08 Nov 2005 01:04:13 -0800, [EMAIL PROTECTED] wrote:

 Or alternatively:
 
 Is there a way to make reference to the last element of a list, to use
 as a shorthand:
 
 ref := lst[len(lst) - 1] # I know syntax is wrong, but you get the
 idea
 
 and then using the last element of the list by (assuming the element is
 a dict):
 
 ref[foo] = 42
 ref[bar] = Ni!

py lst = [Now is the time, 4, all good men, {foo: bar}]
py lst[-1]  # refers to the last item of lst
{'foo': 'bar'}
py obj = lst[-1]  # the name obj is now bound to the same dict
py obj[foo] = 42
py print lst
['Now is the time', 4, 'all good men', {'foo': 42}]

This only works with mutable objects. See:

py obj = lst[-3]
py obj
4
py obj = obj + 1  # rebinds the name obj, doesn't change the underlying
object the name points to
py print lst
['Now is the time', 4, 'all good men', {'foo': 42}]

You will quickly learn what are mutable and what are immutable. Ints,
floats, longs, strs and tuples are immutable. Lists and dicts are mutable.
Custom classes could be either, in principle, but are generally mutable.



-- 
Steven.

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


  1   2   3   >