Re: os.mkdir and mode

2006-12-01 Thread Godson

On 1 Dec 2006 23:17:50 -0800, vj <[EMAIL PROTECTED]> wrote:


How do I do the following unix command:

mkdir -m770 test

with the os.mkdir command. Using os.mkdir(mode=0770) ends with the
incorrect permissions.

Thanks,

VJ

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





using

os.mkdir("/home/godson/test",0770)

Allows me to do that with out any trouble, and also please check whether you
have appropriate permission to the area where you are trying to create the
folder. os.mkdir takes no keyword arguments, if you dont have appropriate
permissions you can try running python as super user, or user with proper
permissions.

Godson Gera
http://godson.auroinfo.com  
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: About alternatives to Matlab

2006-12-01 Thread Jon Harrop

I don't know Python but this benchmark caught my eye.

>>def D4_Transform(x, s1=None, d1=None, d2=None):
>>   """
>>   D4 Wavelet transform in NumPy
>>   (C) Sturla Molden
>>   """
>>   C1 = 1.7320508075688772
>>   C2 = 0.4330127018922193
>>   C3 = -0.066987298107780702
>>   C4 = 0.51763809020504137
>>   C5 = 1.9318516525781364
>>   if d1 == None:
>>  d1 = numpy.zeros(x.size/2)
>>  s1 = numpy.zeros(x.size/2)
>>  d2 = numpy.zeros(x.size/2)

Are these definitions ever used? It looks like s1, d1 and d2 are all
redefined below without reference to these previous values.

>>   odd = x[1::2]
>>   even = x[:-1:2]
>>   d1[:] = odd[:] - C1*even[:]
>>   s1[0] = even[0] + C2*d1[0] + C3*d1[-1]
>>   s1[1:] = even[1:] + C2*d1[1:] + C3*d1[:-1]
>>   d2[0] = d1[0] + s1[-1]
>>   d2[1:] = d1[1:] + s1[:-1]
>>   even[:] = C4 * s1[:]
>>   odd[:] = C5 * d2[:]

Does that line create an array that is never used? If so, is C5 also never
used?

>>   if x.size > 2:
>>
>>D4_Transform(even,s1[0:even.size/2],d1[0:even.size/2],d2[0:even.size/2])

What is the result of this function?

I'm interested in translating this function into other languages, like
OCaml, to see how good Python's performance is (I am amazed it can beat
Matlab, not that I've used Matlab). In particular, I think you are eagerly
allocating arrays when, in a functional language, you could just as easily
compose closures.

For example, this program is 3x faster than the Python on my machine:

let rec d4 s1 d1 d2 x =
  let c1 = 1.7320508075688772 in
  let c2 = 0.4330127018922193 in
  let c3 = -0.066987298107780702 in
  let c4 = 0.51763809020504137 in
  let c5 = 1.9318516525781364 in
  let n = Array.length x in
  let odd i = x.(2*i) and even i = x.(2*i + 1) in
  let d1 i = odd i -. c1 *. even i in
  let f = function -1 -> n/2 - 1 | i -> i in
  let s1 i = even i +. c2 *. d1 i +. c3 *. d1 (f(i-1)) in
  let d2 i = d1 i +. s1 (f(i-1)) in
  let even = Array.init (n/2) (fun i -> c4 *. s1 i) in
  if n > 2 then d4 s1 d1 d2 even else s1, d1, d2

but I'm not sure it is correct!

-- 
Dr Jon D Harrop, Flying Frog Consultancy
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: client/server design and advice

2006-12-01 Thread John Henry
On the subject of passing things around, is there a no brainer way of
sending files back and forth over Pyro?

I am currently using a shared drive to do that.  May be I missed that
feature?

Irmen de Jong wrote:
> bruce wrote:
> > hi irmen...
> >
> > happened to come across this post. haven't looked at pyro. regarding your
> > 'work packets' could these essentially be 'programs/apps' that that are
> > requested by the client apps, and are then granted by the dispatch/server
> > app?
> >
>
> Pyro supports a limited form of "mobile code" i.e. the automatic
> transfering of Python modules to the other side.
> But it has a few important limitations and there's the security
> aspect as well.
>
> It's really better if you can stick to passing data around, not code... ;-)
>
> > i'm considering condor (univ of wisconsin) but am curious as to if pyro
> > might also work.
> 
> Not familiar with this.
> 
> 
> --Irmen

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


Re: Python, PostgreSQL, What next?

2006-12-01 Thread Godson

On 1 Dec 2006 23:04:37 -0800, vbgunz <[EMAIL PROTECTED]> wrote:


Hello all,

I've studied Python and studied PostgreSQL. What is the absolute next
best step to take to merge these two finely together? I've heard of
SQLAlchemy and some others but before I dive in, I would really like
the opinion of those who tried it and other toolkits.

My main concern is, I would like to completely work with a database
from Python. What would you suggest I look into?

Thank you for your time!

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



I am using psycopg 1.1.21 for interacting with postgresql, which proved to
be good for my need i guess django and  zope  also using psycopg for doing
things with postgresql, to get started with that, The following links could
be useful

http://initd.org/pub/software/psycopg/dbapi20programming.pdf


http://www.python.org/dev/peps/pep-0249/

Godson Gera
http://godson.auroinfo.com
-- 
http://mail.python.org/mailman/listinfo/python-list

can't figure out how to create menus in urwid

2006-12-01 Thread krishnakant Mane
hello,
I have been trying out urwid for creating ncurses based applications.
I will like to know if any one has ever tried to create menu bar with
drop down menus using urwid?
any suggestion?
Krishnakant.
-- 
http://mail.python.org/mailman/listinfo/python-list


os.mkdir and mode

2006-12-01 Thread vj
How do I do the following unix command:

mkdir -m770 test

with the os.mkdir command. Using os.mkdir(mode=0770) ends with the
incorrect permissions. 

Thanks,

VJ

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


Python, PostgreSQL, What next?

2006-12-01 Thread vbgunz
Hello all,

I've studied Python and studied PostgreSQL. What is the absolute next
best step to take to merge these two finely together? I've heard of
SQLAlchemy and some others but before I dive in, I would really like
the opinion of those who tried it and other toolkits.

My main concern is, I would like to completely work with a database
from Python. What would you suggest I look into?

Thank you for your time!

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


Printing Barcodes from webapp?

2006-12-01 Thread Burhan
Hello Group:

  I am in the planning stages of an application that will be accessed
over the web, and one of the ideas is to print a barcode that is
generated when the user creates a record.  The application is to track
paperwork/items and uses barcodes to easily identify which paper/item
belongs to which record.

  Is there an easy way to generate barcodes using Python -- considering
the application will be printing to a printer at the client's machine?
I thought of two ways this could be done; one would be to interface
with the printing options of the browser to ensure that margins,
headers, footers are setup properly (I have done this before using
activex and IE, but with mixed results); the other would be to install
some small application at the client machine that would intercept the
print jobs and format them properly (taking the printing function away
from the browser).

  Does anyone have any experience or advice? Any links I could read up
on to help me find out how to program this?  Another way (easier
hopefully) to accomplish this?

Thanks for any advice.

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


Re: python vs java & eclips

2006-12-01 Thread krishnakant Mane
may be emacs can provide code completion (intellicense)
I have not used it so far so can't say.
but the main reason I use eclipse is for the above feature.
and yes indentation happens in eclipse python-mode so that is not a
major feature eclipse offers any way.
syntax highlighting is a very common feature again.
so if there is an editor which will give me auto code completion, I
will happily give up using eclipse.
by the way, there is one problem I am finding with eclipse and py dev.
the following snippad of code is a mesterious problem.
name = raw_input("please identify your self ")
if name == "tom":
   print "hello and welcome"
else:
   print "I don't know you"

just run this script and you will find that you always get "I don't
know you", even if you entered tom.
I then figured out that length of name actually comes to 4 even when I
entered tom.  that's why it always goes in the else claws.
but when I ran the same script from a command promt the length of name
returned 3 when tom was entered and the code worked fine.
I can't understand why is this happening?  why is eclipse putting an
extra character in the name variable?


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


Re: One detail...

2006-12-01 Thread Gabriel G

At Saturday 2/12/2006 00:40, [EMAIL PROTECTED] wrote:

I'm trying to do in Zope, which doesn't allow "_" characters at the 
beginning of identifiers. Even in an external method, it gives me an 
error when I try to reference the o.a. Is there a trick to do it 
some other way?


Better to ask on a Zope group.
But why do you want to do that? As you have noticed, you must provide 
security assertions for your objects so it's not an easy way. And 
dictionaries are fully supported by ZPT and DTML - as it appears to 
be what you want.



--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Possible to assure no "cyclic"/"uncollectible" memory leaks?

2006-12-01 Thread Joe Peterson
I've been doing a lot of searching on the topic of one of Python's more
disturbing issues (at least to me): the fact that if a __del__ finalizer
is defined and a cyclic (circular) reference is made, the garbage
collector cannot clean it up.

First of all, it seems that it's best to avoid using __del__.  So far, I
have never used it in my Python programming.  So I am safe there.  Or am
I?  Also, to my knowledge, I have never created a cyclic reference, but
we do not typically create bugs intentionally either (and there are
certainly times when it is an OK thing to do).

Still, it's not comforting to know that it is possible to create a
situation that would create a memory leak using a language that is
supposed to relieve us of that worry.  I understand the problem, but it
would be nice to know that as a programmer, I could be assured that
Python would always deal with memory management and that memory leaks
were not something I had to think about.

So here's a question: if I write Python software and never use __del__,
can I guarantee that there is no way to create a memory leak?  What
about system libraries - do any of them use __del__, and if so, are they
written in such a way that it is not possible to create a cyclic reference?

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


Re: Is there a reason not to do this?

2006-12-01 Thread Hendrik van Rooyen
"Ron Garret" <[EMAIL PROTECTED]> wrote:

> > I don't want to get into a philosophical debate.
>
> Actually, I changed my mind.  Consider:
>
> def g(): print 'G'
>
> def h(): print 'H'
>
> def f(): g()
>
> class C1:
>   def m1(self): f()
>
> class C2:
>   def m1(self): g()
>
> c1 = C1()
> c2 = C2()
>
> def f(): h()
>
> class C2:
>   def m1(self): h()
>
> c1.m1()  # Prints H
> c2.m1()  # Prints G
>
> On what principled basis can you justify two different outputs in this
> case?  Why should I be able to change the definition of f and not have
> to go back and recompile all references to it, but not m1?

This feels to me as if you are changing the specification of what wood to use
from yellowood to teak after the chair has already been made.

But maybe I am just simple minded...

- Hendrik

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


Re: converting dict to object

2006-12-01 Thread Michel Claveau
Hi!

Yes.

But...

Try:d = {'a': 1, 'b': 2, 'def': 123}

Ok, I go out...

-- 
@-salutations

Michel Claveau


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


[ANN] InformixDB-2.4 released

2006-12-01 Thread Carsten Haese
I am pleased to announce a new release of InformixDB, the DB-API 2.0 module
for connecting to IBM Informix database engines.

The list of changes since version 2.3 is short but sweet:

- Implement 'named' parameter style to optionally bind query parameters by name
- Implement option to retrieve opaque types in their binary representation

Downloads and info at http://informixdb.sourceforge.net

Best regards,

Carsten Haese


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


Re: strange problems with code generation

2006-12-01 Thread [EMAIL PROTECTED]
I never see anything from print(data).  The example I tried to adapt
using readlines may be a little old or something.  I did close all the
files to prevent problems when I figure out what is wrong with what I
have.



John Machin wrote:
> You say "I am sure the readlines code is crashing it." I can't imagine
> how you can be sure of anything, but yes, it is a possibility that
> sys.stdin.readlines() might behave strangely when called from a GUI
> kit. Why from sys.stdin anyway?
>
> You have two *known* definite problems (not closing your output files,
> and no such attribute as "writeline") -- *fix* them, and try again.
>
> Do try to test that function in isolation.
> Put print statements in as I suggested. Comment out the .bat file
> invocation.
> Try calling the function from the interactive interpteter. Check if the
> files are being created, with the right size. If it works, add back the
> .bat file invocation. If that works, try it from your GUI.
>
> IOW, try to attack your problem methodically.
>
> AND try to answer at least some of the questions that helpers might ask
> you, like what does "print(data)" produce -- they're not asked out of
> idle curiosity.
> 
> HTH,
> John

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


Re: Molten Metal Pools in WTC after weeks, only micronuke could have produced so much heat

2006-12-01 Thread Doug

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> W88 warhead design
>
> http://www.thepriceofliberty.org/06/09/25/wardpics-5.htm
>
> http://www.thepriceofliberty.org/06/09/25/wardpics-4.htm


the diagrams are all wrong, they are fiction.




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


Re: strange problems with code generation

2006-12-01 Thread John Machin
You say "I am sure the readlines code is crashing it." I can't imagine
how you can be sure of anything, but yes, it is a possibility that
sys.stdin.readlines() might behave strangely when called from a GUI
kit. Why from sys.stdin anyway?

You have two *known* definite problems (not closing your output files,
and no such attribute as "writeline") -- *fix* them, and try again.

Do try to test that function in isolation.
Put print statements in as I suggested. Comment out the .bat file
invocation.
Try calling the function from the interactive interpteter. Check if the
files are being created, with the right size. If it works, add back the
.bat file invocation. If that works, try it from your GUI.

IOW, try to attack your problem methodically.

AND try to answer at least some of the questions that helpers might ask
you, like what does "print(data)" produce -- they're not asked out of
idle curiosity.

HTH,
John

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


Re: How do I print a numpy array?

2006-12-01 Thread Robert Kern
Grant Edwards wrote:
> On 2006-12-02, Robert Kern <[EMAIL PROTECTED]> wrote:
>> Grant Edwards wrote:
>>> On 2006-12-01, Robert Kern <[EMAIL PROTECTED]> wrote:
 Grant Edwards wrote:
> How do you print a numpy array?
 You might want to ask numpy questions on the numpy list:

   http://www.scipy.org/Mailing_Lists
>>> I tried, but it doesn't seem to be available through gmane.org. 
>> Yes, it is.
>>
>>   http://dir.gmane.org/gmane.comp.python.numeric.general
> 
> I was looking for the "numpy-discussion" mailing list.  It
> didn't occur to me that it was spelled "numeric.general".

Yeah, GMane likes to apply their own naming system. Fortunately, they have a
little search tool that will locate the right newsgroup given 
"numpy-discussion":

  http://gmane.org/find.php

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: strange problems with code generation

2006-12-01 Thread [EMAIL PROTECTED]

John Machin wrote:
> [EMAIL PROTECTED] wrote:
> > I am writing out zero byte files with this (using python 2.5).  I have
> > no idea why I am having that problem
>
> Which output file(s) do you mean, temp.orc or temp.sco or both?
> Two possible causes outlined below.
>
> > I am also looking for an example
> > of readlines where I can choose a number of lines say lines 12 to 14
> > and then write them back to disk.
>
> To the same file? There was a long thread on updating text files very
> recently.
>
> >  any help would be apreaceted.
>
> Have you considered deploying a spelling checker?
>
> >
> > import sys as sys2
> > import os as os2
>
> Why the obfuscation?
>
> >
> > def playscoreinrange(from_file, fromline, toline):
> > "untested way to play a series of lines from a orc, sco combination
> > line 14 may not be correct"
>
> and which is line 14?? According to my count, it is the blank line
> after "outfile2 = open('temp.orc', 'w') "!!
>
> > print(from_file)
> > fromfile = os2.path.basename(from_file)
> > print(fromfile)
> >
> > orcfilename = fromfile[:-4] + '.orc'
> > print(orcfilename)
> > infile2 = open(orcfilename, 'r')
> > outfile2 = open('temp.orc', 'w')
> >
> > for line in infile2:
> > outfile2.write(line)
> >
> >
> > infile = open(fromfile, 'r')
>
> infile is not used
>
> > outfile = open('temp.sco','w')
> >
> > data = sys2.stdin.readlines()
> > print(data)
>
> and how many lines were there in data when you printed it?
>
> > for linenumber in range(fromline, toline):
>
> Consider the possibility that fromline >= toline (which may be caused
> by either or both not being of a numerical type).
>
> Did you mean range(fromline, toline + 1) ?
>
> do this:
> print repr(fromline), type(fromline)
> print repr(toline), type(toline)
>
> BTW, print is a *statement*, not a function!
>
> > outfile.writeline(data[linenumber])
>
> outfile.writeline() ???
>
> | Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
> (Intel)] on win
> 32
> | Type "help", "copyright", "credits" or "license" for more
> information.
> | >>> f = open('fubar.txt', 'w')
> | >>> f.writeline('bt!\n')
> | Traceback (most recent call last):
> |   File "", line 1, in 
> | AttributeError: 'file' object has no attribute 'writeline'
>
> So, the body of your loop wasn't executed (or you overlooked the
> exception, or that wasn't the code that was executed) -- so it looks
> like the range was empty (or the problem occurred further upstream).
>
> > https://sourceforge.net/projects/dex-tracker
> > http://www.dexrow.com
> >
> >
> > os2.startfile('temp.bat')
>
> and what does this do?? Read temp.orc and/or temp.sco before you've
> closed the file(s)?
>
> Where is the code that was used to call this playscoreinrange function?
>
> HTH,
> John

temp bat is

csound temp.orc temp.sco

and it plays the new files I can try closing the other files first.  I
am sure the readlines code is crashing it.  Because I have moved it
befour the code that is reading a line at a time and it would not even
write the second zero byte file.  The comment line is an old line that
I did not update when I made changes.  The code that calls it was
auto-generated but boa-constructer .44  (I haven't updated it yet).


#Boa:Dialog:Dialog2

import wx
import csoundroutines2

def create(parent):
return Dialog2(parent)

[wxID_DIALOG2, wxID_DIALOG2BUTTON1, wxID_DIALOG2STATICTEXT1,
 wxID_DIALOG2STATICTEXT2, wxID_DIALOG2TEXTCTRL1, wxID_DIALOG2TEXTCTRL2,

] = [wx.NewId() for _init_ctrls in range(6)]

class Dialog2(wx.Dialog):
From_File = ''
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Dialog.__init__(self, id=wxID_DIALOG2, name='', parent=prnt,
  pos=wx.Point(759, 203), size=wx.Size(420, 72),
  style=wx.DEFAULT_DIALOG_STYLE, title='play csound lines')
self.SetClientSize(wx.Size(412, 38))
self.Bind(wx.EVT_RIGHT_DCLICK, self.OnDialog2RightDclick)

self.textCtrl1 = wx.TextCtrl(id=wxID_DIALOG2TEXTCTRL1,
name='textCtrl1',
  parent=self, pos=wx.Point(56, 8), size=wx.Size(100, 21),
style=0,
  value='test')

self.textCtrl2 = wx.TextCtrl(id=wxID_DIALOG2TEXTCTRL2,
name='textCtrl2',
  parent=self, pos=wx.Point(216, 8), size=wx.Size(100, 21),
style=0,
  value='')

self.staticText1 = wx.StaticText(id=wxID_DIALOG2STATICTEXT1,
  label='from line', name='staticText1', parent=self,
  pos=wx.Point(8, 8), size=wx.Size(41, 13), style=0)
self.staticText1.SetToolTipString('From Line')
self.staticText1.SetBackgroundStyle(wx.BG_STYLE_SYSTEM)
self.staticText1.SetForegroundColour(wx.Colour(255, 0, 0))

self.staticText2 = wx.StaticText(id=wxID_DIALOG2STATICTEXT2,
  label='To Line', name='staticText2', parent=self,
  pos=wx.Point(168, 8), size=wx.Size(34, 13), style=0)
self.staticText

Molten Metal Pools in WTC after weeks, only micronuke could have produced so much heat

2006-12-01 Thread thermate
W88 warhead design

http://www.thepriceofliberty.org/06/09/25/wardpics-5.htm

http://www.thepriceofliberty.org/06/09/25/wardpics-4.htm

Bali bomb was possibly a micronuke from Dimona Israel - the land of
milk and honey ;)

http://www.vialls.com/nuke/bali_micro_nuke.htm  < Excellent
analysis with photo evidence

You guys in tex/c++/python/physics/math can now analyse the
observations based on your expertise, but the facts are facts, an
acceptable theory must explain them all.

More micronuke analysis:
http://groups.google.com/group/total_truth_sciences/browse_thread/thread/93ea1025953b8064/e1f3b031f5dca83d?lnk=st&q=%22thermate%22+million&rnum=40&hl=en#e1f3b031f5dca83d

The following synopsis comes from a Military Expert in Finland. See all
of this posting Here
http://www.government-propaganda.com/911-why-towers-collasped.html
< EXCELLENT ILLUSTRATIVE PHOTOS

Please, congratulate and send loves and affections to our ZIONIST
brothers in US Government and Israel for giving us such a nice nuclear
gift.

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


Re: strange problems with code generation

2006-12-01 Thread John Machin
[EMAIL PROTECTED] wrote:
> I am writing out zero byte files with this (using python 2.5).  I have
> no idea why I am having that problem

Which output file(s) do you mean, temp.orc or temp.sco or both?
Two possible causes outlined below.

> I am also looking for an example
> of readlines where I can choose a number of lines say lines 12 to 14
> and then write them back to disk.

To the same file? There was a long thread on updating text files very
recently.

>  any help would be apreaceted.

Have you considered deploying a spelling checker?

>
> import sys as sys2
> import os as os2

Why the obfuscation?

>
> def playscoreinrange(from_file, fromline, toline):
> "untested way to play a series of lines from a orc, sco combination
> line 14 may not be correct"

and which is line 14?? According to my count, it is the blank line
after "outfile2 = open('temp.orc', 'w') "!!

> print(from_file)
> fromfile = os2.path.basename(from_file)
> print(fromfile)
>
> orcfilename = fromfile[:-4] + '.orc'
> print(orcfilename)
> infile2 = open(orcfilename, 'r')
> outfile2 = open('temp.orc', 'w')
>
> for line in infile2:
> outfile2.write(line)
>
>
> infile = open(fromfile, 'r')

infile is not used

> outfile = open('temp.sco','w')
>
> data = sys2.stdin.readlines()
> print(data)

and how many lines were there in data when you printed it?

> for linenumber in range(fromline, toline):

Consider the possibility that fromline >= toline (which may be caused
by either or both not being of a numerical type).

Did you mean range(fromline, toline + 1) ?

do this:
print repr(fromline), type(fromline)
print repr(toline), type(toline)

BTW, print is a *statement*, not a function!

> outfile.writeline(data[linenumber])

outfile.writeline() ???

| Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel)] on win
32
| Type "help", "copyright", "credits" or "license" for more
information.
| >>> f = open('fubar.txt', 'w')
| >>> f.writeline('bt!\n')
| Traceback (most recent call last):
|   File "", line 1, in 
| AttributeError: 'file' object has no attribute 'writeline'

So, the body of your loop wasn't executed (or you overlooked the
exception, or that wasn't the code that was executed) -- so it looks
like the range was empty (or the problem occurred further upstream).

> https://sourceforge.net/projects/dex-tracker
> http://www.dexrow.com
>
>
> os2.startfile('temp.bat')

and what does this do?? Read temp.orc and/or temp.sco before you've
closed the file(s)?

Where is the code that was used to call this playscoreinrange function?

HTH,
John

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


Re: How do I print a numpy array?

2006-12-01 Thread Grant Edwards
On 2006-12-02, Robert Kern <[EMAIL PROTECTED]> wrote:
> Grant Edwards wrote:
>> On 2006-12-01, Robert Kern <[EMAIL PROTECTED]> wrote:
>>> Grant Edwards wrote:
 How do you print a numpy array?
>> 
>>> You might want to ask numpy questions on the numpy list:
>>>
>>>   http://www.scipy.org/Mailing_Lists
>> 
>> I tried, but it doesn't seem to be available through gmane.org. 
>
> Yes, it is.
>
>   http://dir.gmane.org/gmane.comp.python.numeric.general

I was looking for the "numpy-discussion" mailing list.  It
didn't occur to me that it was spelled "numeric.general".

-- 
Grant Edwards   grante Yow!  Th' MIND is the Pizza
  at   Palace of th' SOUL
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: converting dict to object

2006-12-01 Thread Gabriel Genellina

At Friday 1/12/2006 22:48, rieh25 wrote:


If I have a dictionary such as:

d = {'a' : 1, 'b' : 2}

is there a way to convert it into an object o, such as:

o.a = 1
o.b = 2


>>> class X(object):
...   def __init__(self, d): self.__dict__.update(d)
...
>>> d = {'a' : 1, 'b' : 2}
>>> o=X(d)
>>> o.a
1
>>> o.b
2
>>>


--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

converting dict to object

2006-12-01 Thread rieh25

If I have a dictionary such as:

d = {'a' : 1, 'b' : 2}

is there a way to convert it into an object o, such as:

o.a = 1
o.b = 2

thanks
-- 
View this message in context: 
http://www.nabble.com/converting-dict-to-object-tf2741429.html#a7649225
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: Thread help

2006-12-01 Thread Gabriel Genellina

At Friday 1/12/2006 17:26, Bjoern Schliessmann wrote:


>> I would make 3 threads for a client application.

> You should use 4.

I vote for just 1.


We all know that the correct answer is, and always has been, 42


--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Take the $million challenge: Prove 911 conspriracy theorists are wrong

2006-12-01 Thread [EMAIL PROTECTED]
The proper edicate would be to write software in python and then link
to your point of view.  It is common practice in music software.  I
tend of think of you like ufo people, if there is a conspiracy of some
sort they use you to discredit it.

https://sourceforge.net/projects/dex-tracker
http://www.dexrow.com



[EMAIL PROTECTED] wrote:
> I found this nice dialog on the internet:
> =
>
> > Well, if you want to convice me, just answer these questions:
>
> If you can prove that the official explanation is correct, what's
> keeping
> you from collecting a MILLION dollars?  Even if you're too wealthy to
> bother, you could donate the proceeds to the Aryan Nation or the John
> Birch
> Society.
>
> > 1. How much explosives were used and what type?
>
> Thermate/thermite have been discovered in chemical tests, and evidence
> of
> its use is plainly visible in photographic an video evidence from the
> WTC
> buildings on 9/11.  Thermate does not cause millions of tones of
> concrete to
> become pulverized into dust in mid-air (as video evidence clearly
> shows), so
> another high-energy explosive must have also been used. Now that we
> have
> positive proof that explosives were used, and once the secondary
> compounds
> have been discovered, the quantities and placement can be estimated
> from
> examinations of the video and photo evidence.
>
> > 2. How many people were needed to prepare the building for demolition?
>
> Irrelevant to the established fact that explosives were used.  Will be
> determined in the new investigation. BTW: It's "buildings," not
> "building."
> Did you realize that *three* WTC towers collapsed on 9/11/01, despite
> only 2
> buildings being hit by jets?  Most Americans don't realize this obvious
> fact.  Why?
>
> > 3. How long did it take to prepare the buildings for demolition?
>
> Irrelevant to the established fact that explosives were used.  Once the
> identities of the conspirators are discovered in a new investigation,
> the
> timeline can be established.  (That's what investigators do.)
>
> > 4. How many people had to be bribed and how much were they bribed to
> > keep silent about the preparations?
>
> Irrelevant to the established fact that explosives were used.  Those
> conspirators (whether bribed or not) that are still alive must be
> discovered
> and convicted for their crimes, which may include conspiracy to commit
> treason. The only way to bring the criminals to justice is to open a
> new
> investigation which will examine *all* relevant evidence, including
> sequestered videos, audio tapes, and classified documents.
>
> Everybody with an IQ above room temperature knows that the 9/11
> Commission
> report was a whitewash, which didn't even attempt to lay blame at the
> feet
> of military and civilian officials who were asleep at the wheel on
> 9/11/01.
> It proves that Bush is not serious about national security.

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


strange problems with code generation

2006-12-01 Thread [EMAIL PROTECTED]
I am writing out zero byte files with this (using python 2.5).  I have
no idea why I am having that problem, I am also looking for an example
of readlines where I can choose a number of lines say lines 12 to 14
and then write them back to disk.  any help would be apreaceted.



import sys as sys2
import os as os2

def playscoreinrange(from_file, fromline, toline):
"untested way to play a series of lines from a orc, sco combination
line 14 may not be correct"
print(from_file)
fromfile = os2.path.basename(from_file)
print(fromfile)

orcfilename = fromfile[:-4] + '.orc'
print(orcfilename)
infile2 = open(orcfilename, 'r')
outfile2 = open('temp.orc', 'w')

for line in infile2:
outfile2.write(line)


infile = open(fromfile, 'r')
outfile = open('temp.sco','w')

data = sys2.stdin.readlines()
print(data)
for linenumber in range(fromline, toline):
outfile.writeline(data[linenumber])

https://sourceforge.net/projects/dex-tracker
http://www.dexrow.com


os2.startfile('temp.bat')

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


Re: python vs java & eclipse

2006-12-01 Thread [EMAIL PROTECTED]
Amir  Michail wrote:
> [EMAIL PROTECTED] wrote:
> > ...
> >
> > Is there anything _useful_ that it'll bring that a good editor doesn't?
> >  e.g. in vim I do get
> > * automatic syntax checking (if I type "if a=1:" and hit enter, it'll
> > immediately highlight the syntax error)
> > * omni-completion (because Intellisense is trademarked)
> > * refactoring (with BicycleRepairMan integration)
> > * folding (which is more important than the above 3 combined, IMO)
> > * online help (typing cmp( gives me the docstring for cmp in the status
> > line, F1 to view the whole thing)
> >
> > As well as all the basics (tags/class browser/good regex support/syntax
> > highlighting/autoindent/source control integration/etc).
> >
> > I'm not trolling here, I'm looking for interesting new features I can
> > steal.
>
> How about we try to find some papers on the subject?

Thanks.  Seems a bit high-level to be very useful, and the plethora of
examples around "self encapsulate field" seem inapplicable, but it
makes me wonder if there's anything to be gained by integrating the vim
refactoring support with the Vim 7 undo branches.

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


Re: client/server design and advice

2006-12-01 Thread Irmen de Jong
bruce wrote:
> hi irmen...
> 
> happened to come across this post. haven't looked at pyro. regarding your
> 'work packets' could these essentially be 'programs/apps' that that are
> requested by the client apps, and are then granted by the dispatch/server
> app?
> 

Pyro supports a limited form of "mobile code" i.e. the automatic 
transfering of Python modules to the other side.
But it has a few important limitations and there's the security
aspect as well.

It's really better if you can stick to passing data around, not code... ;-)

> i'm considering condor (univ of wisconsin) but am curious as to if pyro
> might also work.

Not familiar with this.


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


Re: How do I print a numpy array?

2006-12-01 Thread Robert Kern
Beliavsky wrote:
> When I print an array in any language, I (and I think most programmers)
> expect by default to have all elements displayed. Matlab, R, and
> Fortran 95 have somewhat similar arrays to numpy, and that is what they
> do. I don't remember Numeric summarizing arrays by default. R has a
> "summary" function as well as a "print" function.

There are pretty serious problems with interactive use and large arrays.
Formatting the string for a very large array can take a fair bit of time, often
much more than the computation that generated it. This has been a long-standing
frustration of many Numeric users. At the interactive prompt, if the statement
you just entered is taking a long time to execute and you Ctrl-C, odds are, the
traceback points you right in the middle of array2string(), not anything in the
actual computation itself. Since the interactive prompt prints things out
without the user explicitly asking for it, it's not enough simply to have two
functions available.

numarray set the default to summarize, and numpy kept numarray's choice.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: How do I print a numpy array?

2006-12-01 Thread Robert Kern
Grant Edwards wrote:
> On 2006-12-01, Robert Kern <[EMAIL PROTECTED]> wrote:
>> Grant Edwards wrote:
>>> How do you print a numpy array?
> 
>> You might want to ask numpy questions on the numpy list:
>>
>>   http://www.scipy.org/Mailing_Lists
> 
> I tried, but it doesn't seem to be available through gmane.org. 

Yes, it is.

  http://dir.gmane.org/gmane.comp.python.numeric.general

Did you have a specific problem accessing it? I can access it just fine. I think
you may have to subscribe to the list to post (otherwise we get too much spam).
Of course, you can turn off mail delivery if you only want to go through GMane.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: Take the $million challenge: Prove 911 conspriracy theorists are wrong

2006-12-01 Thread Tonico

[EMAIL PROTECTED] wrote:
> Do you mean to say that the dimension to pursue truth and freedom from
> deception lack for people using TeX? or they must not be informed of
> it?

What kind of "dimension" is needed to pursue truths and freedom from
deception stuff?
Anyway, it is not lack of that: this is a maths group. That's all. Can
you understand that or will there be need to spell it for you?
Tonio

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


Re: Take the $million challenge: Prove 911 conspriracy theorists are wrong

2006-12-01 Thread st911
Do you mean to say that the dimension to pursue truth and freedom from
deception lack for people using TeX? or they must not be informed of
it?

BTW, Mr Siegman from Stanford of Yatches, whats your take on Neturei
Karta ? If I am making a guess based on the sample space I have seen in
"elite" universities, most jews are fervent Zionists even if they are
atheists. I would really like to discuss with some university
professors (especially jewish - almost always zionist) what they think
of Neturei Karta, and the free book that is there, Min Ha Mitzer, (From
the depths) about the role of zionists in abetting the slaughter of the
Jews, nay, in fervently provoking Hitler or someone in that very
direction. Its written by Rabbi Wasserman and unlike your book on
Lasers, is freely available. I assure you, my dialogue with you on this
subject will be civilized. Only, polite language would be used. I only
use the impolite phrases for criminals like those who carried out 911
under the theories of LIHOP/MIHOP and people like Edward Bernays who
maliciously deceived the people or those who masterminded and carried
evil operations like COINTELPRO.

Aandi Inston wrote:
> [EMAIL PROTECTED] wrote:
>
> >I found this nice dialog on the internet:
>
> Doubtless, but why did you choose to share it with a bunch of news
> groups which aren't related to the subject?
> 
> Aandi Inston  [EMAIL PROTECTED] http://www.quite.com
> Please support usenet! Post replies and follow-ups, don't e-mail them.

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


Fun with with

2006-12-01 Thread Klaas
Occasionally I find myself wanting a block that I can break out of at
arbitrary depth--like java's named break statements.  Exceptions can
obviously be used for this, but it doesn't always look nice.

The with statement can be used to whip up something quite usable:

class ExitBlock(object):
""" A context manager that can be broken out of at an arbitrary
depth,
using .exit() """
def __init__(self):
class UniqueException(BaseException):
pass
self.breakExc = UniqueException
def exit(self):
raise self.breakExc()
def __enter__(self):
return self
def __exit__(self, t, v, tb):
return t is self.breakExc

Now the most important thing here is that each exit block creates a
unique exception type.  If you have philosophical issues with creates
unboundedly many type objects, you can use unique instances too.

This allows named break-out-able blocks:

with ExitBlock() as ex1:
with ExitBlock() as ex2:
with ExitBlock() as ex3:
while True:
ex2.exit()
print 'not displayed'
print 'execution proceeds here from ex2.exit()'
while True:
for x in xrange(sys.maxint):
while True:
ex1.exit()
print 'not displayed'
print 'execution proceeds here from ex1.exit()'

The only danger is bare except (or except BaseException) inside the
block.

-Mike

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


Re: How do I print a numpy array?

2006-12-01 Thread Beliavsky

Robert Kern wrote:
> Grant Edwards wrote:
> > How do you print a numpy array?
> >
> > I tried the obvious print a, print `a`, and print str(a), but
> > none of them work on anything other than trivially small
> > arrays.  Most of my real data is elided and replaced with
> > ellipses.
>
> You might want to ask numpy questions on the numpy list:
>
>   http://www.scipy.org/Mailing_Lists
>
> Use numpy.set_printoptions(threshold=sys.maxint) to disable all summarization.

When I print an array in any language, I (and I think most programmers)
expect by default to have all elements displayed. Matlab, R, and
Fortran 95 have somewhat similar arrays to numpy, and that is what they
do. I don't remember Numeric summarizing arrays by default. R has a
"summary" function as well as a "print" function.

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


Re: How do I print a numpy array?

2006-12-01 Thread Grant Edwards
On 2006-12-01, Robert Kern <[EMAIL PROTECTED]> wrote:
> Grant Edwards wrote:
>> How do you print a numpy array?

> You might want to ask numpy questions on the numpy list:
>
>   http://www.scipy.org/Mailing_Lists

I tried, but it doesn't seem to be available through gmane.org. 

> Use numpy.set_printoptions(threshold=sys.maxint) to disable
> all summarization.

Thanks.

-- 
Grant Edwards   grante Yow!  I've got to get
  at   these SNACK CAKES to NEWARK
   visi.comby DAWN!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What are python closures realy like?

2006-12-01 Thread Carl Banks
Karl Kofnarson wrote:
> Hi,
> while writing my last program I came upon the problem
> of accessing a common local variable by a bunch of
> functions.
> I wanted to have a function which would, depending on
> some argument, return other functions all having access to
> the same variable. An OO approach would do but why not
> try out closures...
> So here is a simplified example of the idea:
> def fun_basket(f):
> common_var = [0]
> def f1():
> print common_var[0]
> common_var[0]=1
> def f2():
> print common_var[0]
> common_var[0]=2
> if f == 1:
> return f1
> if f == 2:
> return f2
> If you call f1 and f2 from the inside of fun_basket, they
> behave as expected, so common_var[0] is modified by
> whatever function operates on it.
> However, calling f1=fun_basket(1); f2 = fun_basket(2) and
> then f1(); f2() returns 0 and 0. It is not the way one would
> expect closures to work, knowing e.g. Lisp make-counter.


Lisp works the same way.

* (defun fun_basket (f)
(let ((common_var 0))
(defun f1 ()
(print common_var)
(setf common_var 1))
(defun f2 ()
(print common_var)
(setf common_var 2))
(if (eq f 1)
#'f1
#'f2)))

FUN_BASKET
* (setf (symbol-function 'f1a) (fun_basket 1))

; Converted F1.
; Converted F2.

#
* (setf (symbol-function 'f2a) (fun_basket 2))

#
* (f1a)

0
1
* (f2a)

0
2



> Any ideas what's going on behind the scene?

Every time you call the function, a new closure is created.


Carl Banks

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


Re: Take the $million challenge: Prove 911 conspriracy theorists are wrong

2006-12-01 Thread Aandi Inston
[EMAIL PROTECTED] wrote:

>I found this nice dialog on the internet:

Doubtless, but why did you choose to share it with a bunch of news
groups which aren't related to the subject?

Aandi Inston  [EMAIL PROTECTED] http://www.quite.com
Please support usenet! Post replies and follow-ups, don't e-mail them.

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


Re: What are python closures realy like?

2006-12-01 Thread Paul McGuire
"Karl Kofnarson" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hi,
> while writing my last program I came upon the problem
> of accessing a common local variable by a bunch of
> functions.
> I wanted to have a function which would, depending on
> some argument, return other functions all having access to
> the same variable. An OO approach would do but why not
> try out closures...
> So here is a simplified example of the idea:
> def fun_basket(f):
>common_var = [0]
>def f1():
>print common_var[0]
>common_var[0]=1
>def f2():
>print common_var[0]
>common_var[0]=2
>if f == 1:
>return f1
>if f == 2:
>return f2

Karl,

Usually when using this idiom, fun_basket would return a tuple of all of the 
defined functions, rather than one vs. the other.  So in place of:
>if f == 1:
>return f1
>if f == 2:
>return f2
Just do
>return f1, f2
(For that matter, the argument f is no longer needed either.)

Then your caller will get 2 functions, who share a common var.  You don't 
call fun_basket any more, you've already created your two "closures".  Call 
fun_basket using something like:

z1,z2 = fun_basket(None)

And then call z1() and z2() at your leisure - they should have the desired 
behavior.

-- Paul 


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


Re: type(foo) == function ?

2006-12-01 Thread Mathias Panzenboeck
Chris Mellon wrote:
> On 11/29/06, Tom Plunket <[EMAIL PROTECTED]> wrote:
>> I'd like to figure out if a given parameter is a function or not.
>>
>> E.g.
>>
>> >>> type(1)
>> 
>> >>> type(1) == int
>> True
>>
>> implies:
>>
>> >>> def foo():
>> ...   pass
>> ...
>> >>> type(foo)
>> 
>> >>> type(foo) == function
>> Traceback (most recent call last):
>>   File "", line 1, in ?
>> NameError: name 'function' is not defined
>>
>> Is there a way I can know if 'foo' is a function?
>>
> 
 def foo():
> ... pass
> ...
 from inspect import isfunction
 isfunction(foo)
> True

> 
> 
> But you probably want the callable() builtin instead.
> 

This builtin will be removed in python 3.0!

>> thanks,
>> -tom!
>> -- 
>> http://mail.python.org/mailman/listinfo/python-list
>>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I print a numpy array?

2006-12-01 Thread Robert Kern
Grant Edwards wrote:
> How do you print a numpy array?
> 
> I tried the obvious print a, print `a`, and print str(a), but
> none of them work on anything other than trivially small
> arrays.  Most of my real data is elided and replaced with
> ellipses.

You might want to ask numpy questions on the numpy list:

  http://www.scipy.org/Mailing_Lists

Use numpy.set_printoptions(threshold=sys.maxint) to disable all summarization.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: route planning

2006-12-01 Thread Jon Clements
It's not really what you're after, but I hope it might give some ideas
(useful or not, I don't know).

How about considering a vertex as a point in space (most libraries will
allow you to decorate a vertex with additonal information), then
creating an edge between vertices, which will be your 'path'. You can
then decorate the edge with information such as distance/maximum speed
etc...

Then all you need to do is use an A* path algorithm or shortest path
search to get the shortest / most efficient route You might need a
custom visitor to suit the 'weight'/'score' of how efficient the path
is.

I know this probably isn't of much help, but I hope it comes in useful;
I've only ever used Boost.Graph (which is C++, but I believe it has a
Python binding) and that was for something else -- although I do recall
it had examples involving Kevin Bacon and dependency tracking etc... so
a good old Google might do you some good -- ie, it's not completely
related, but it might give you a few extra things to search on...

All the best with the search.

Jon.

PS. If you do find a library, can you let me know? I'd be interested in
having a play with it...

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


Re: Thread help

2006-12-01 Thread John Henry
Why stop there?


Bjoern Schliessmann wrote:
> Grant Edwards wrote:
> > On 2006-12-01, Salvatore Di Fazio <[EMAIL PROTECTED]>
>
> >> I would make 3 threads for a client application.
>
> > You should use 4.
>
> I vote for just 1.
>
> Regards,
>
>
> Björn
>
> --
> BOFH excuse #236:
>
> Fanout dropping voltage too much, try cutting some of those little
> traces

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


How do I print a numpy array?

2006-12-01 Thread Grant Edwards
How do you print a numpy array?

I tried the obvious print a, print `a`, and print str(a), but
none of them work on anything other than trivially small
arrays.  Most of my real data is elided and replaced with
ellipses.

-- 
Grant Edwards   grante Yow!  I want to kill
  at   everyone here with a cute
   visi.comcolorful Hydrogen Bomb!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Detecting recursion loops

2006-12-01 Thread Fuzzyman

robert wrote:
> My code does recursion loops through a couple of functions. Due to 
> problematic I/O input this leads sometimes to "endless" recursions and after 
> expensive I/O to the Python recursion exception.
> What would be a good method to detect recursion loops and stop it by 
> user-Exception (after N passes or some complex criteria) without passing a 
> recursion counter parameter through all the funcs?
>

Could you not store a set/list of nodes/points already visited and do
an early return if they recur ?

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> Robert

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


Re: v2.3, 2.4, and 2.5's GUI is slow for me

2006-12-01 Thread g4rlik

It is always slow, even when I first start it up and do not enter in any
code.  This is really bugging me, maybe I have OCD >__>  I turned off my
anti-virus and that didn't help.  Oh well.

I'm just glad to know that other people have this problem too.  

Duncan Booth-2 wrote:
> 
> g4rlik <[EMAIL PROTECTED]> wrote:
> 
>> No one can help?  This is seriously bugging me to no end.
> 
>>> My problem is..the GUI for versions 2.3, 2.4, and 2.5 of Python run
>>> very sluggishly.  When I type in them or move them around my desktop,
>>> it's very slow.  I have figured out that this is because of the
>>> subprocesses running.  
> 
> Always slow or just sometimes? Idle can get very slow if you have
> generated 
> a lot of output in the shell window, but usually it performs just fine. If 
> you've accidentally printed "range(10)" then your best best is to kill 
> it and restart.
> 
> Use idle for development and testing: its best if you run actual scripts 
> outside the development environment.
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

-- 
View this message in context: 
http://www.nabble.com/v2.3%2C-2.4%2C-and-2.5%27s-GUI-is-slow-for-me-tf2735011.html#a7647276
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: Is python memory shared between theads?

2006-12-01 Thread Klaas

John Henry wrote:
> Wesley Henwood wrote:

> > Is this normal behavior?  Based on the little documentation I have been
> > able to find on this topic, it is normal behavior.  The only way to use
> > same-named variables in scripts is to have them run in a different
> > process, rather than different threads.
>
> Yes and No.
>
> local variables are local to each threads.   Global variables are
> global to the threads.

That is somewhat misleading.  _All_ variables accessible from two
threads are shared.  This includes globals, but also object attributes
and even local variables (you could create a closure to share a local
among threads).

The only reason locals appear "thread-local" is that locals are
"invokation-local" in that they are different bindings every time a
function is executed, and generally a single invokation of a function
is confined to a single thread.

Another way to share local variables is to create a generator, and call
.next() in two different threads... the local variables are
simulatneously modifiable by both threads.

FWIW, there is also threading.local().

-MIke

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


Re: I/O Multiplexing and non blocking socket

2006-12-01 Thread Paul Boddie
Bjoern Schliessmann wrote:
> Salvatore Di Fazio wrote:
>
> > Thank you guys, but I would like to use the standard libraries
>
> Then I suggest you read a good book about Unix programming,
> especially about the workings of read(), write() and select(). If
> you've understood this doing it with python's read/write/select
> will be easy.
>
> Everyone may choose to reinvent the wheel :)

Or use Python's standard library features:

http://docs.python.org/lib/module-asyncore.html
http://docs.python.org/lib/module-asynchat.html

I have to confess, however, that I did reinvent the wheel recently
rather than use asyncore, although I may adopt that particular wheel
later on in the project concerned.

Paul

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


Re: What are python closures realy like?

2006-12-01 Thread Klaas
Karl Kofnarson wrote:
> Hi,
> while writing my last program I came upon the problem
> of accessing a common local variable by a bunch of
> functions.
> I wanted to have a function which would, depending on
> some argument, return other functions all having access to
> the same variable. An OO approach would do but why not
> try out closures...
> So here is a simplified example of the idea:
> def fun_basket(f):
> common_var = [0]
> def f1():
> print common_var[0]
> common_var[0]=1
> def f2():
> print common_var[0]
> common_var[0]=2
> if f == 1:
> return f1
> if f == 2:
> return f2
> If you call f1 and f2 from the inside of fun_basket, they
> behave as expected, so common_var[0] is modified by
> whatever function operates on it.
> However, calling f1=fun_basket(1); f2 = fun_basket(2) and
> then f1(); f2() returns 0 and 0. It is not the way one would
> expect closures to work, knowing e.g. Lisp make-counter.
> Any ideas what's going on behind the scene?

Python can be read quite literally.  "common_var" is a local variable
to fun_basket, hence it independent among invokations of fun_basket.
"def" is a statement that creates a function when it is executed.  If
you execute the same def statement twice, two different functions are
created.  Running fun_basket twice creates four closures, and the first
two have no relation to the second two.  The two sets close over
different cell variables.

If you want to share data between function invokation, you need an
object which persists between calls. You can use a global variable, or
a default argument.  But since the value is shared everytime the
function is called, I don't see the value in using a closure.  I don't
know lisp very well, but in my mind the whole point of closures is that
you can reference a different unique cell each time.

-MIke

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


Re: What are python closures realy like?

2006-12-01 Thread Felipe Almeida Lessa
On 12/1/06, Karl Kofnarson <[EMAIL PROTECTED]> wrote:
[snip]
> def fun_basket(f):
> common_var = [0]
> def f1():
> print common_var[0]
> common_var[0]=1
> def f2():
> print common_var[0]
> common_var[0]=2
> if f == 1:
> return f1
> if f == 2:
> return f2

Everytime you call fun_basket you create another common_var.

> However, calling f1=fun_basket(1); f2 = fun_basket(2) and
> then f1(); f2() returns 0 and 0.

Two calls to fun_basket, two different common_var's, two f1's and two
f2's. Each f1/f2 pair have access to a different common_var, so it's
working as expected. To work as you expected, fun_basket should be on
the same block common_var is defined.

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


Re: python vs java & eclipse

2006-12-01 Thread Amir Michail
[EMAIL PROTECTED] wrote:
> ...
>
> Is there anything _useful_ that it'll bring that a good editor doesn't?
>  e.g. in vim I do get
> * automatic syntax checking (if I type "if a=1:" and hit enter, it'll
> immediately highlight the syntax error)
> * omni-completion (because Intellisense is trademarked)
> * refactoring (with BicycleRepairMan integration)
> * folding (which is more important than the above 3 combined, IMO)
> * online help (typing cmp( gives me the docstring for cmp in the status
> line, F1 to view the whole thing)
>
> As well as all the basics (tags/class browser/good regex support/syntax
> highlighting/autoindent/source control integration/etc).
>
> I'm not trolling here, I'm looking for interesting new features I can
> steal.

How about we try to find some papers on the subject?

Here's one to start things off:

http://pag.csail.mit.edu/~akiezun/companion.pdf

Amir

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


What are python closures realy like?

2006-12-01 Thread Karl Kofnarson
Hi,
while writing my last program I came upon the problem
of accessing a common local variable by a bunch of 
functions.
I wanted to have a function which would, depending on
some argument, return other functions all having access to
the same variable. An OO approach would do but why not
try out closures...
So here is a simplified example of the idea:
def fun_basket(f):
common_var = [0]
def f1():
print common_var[0]
common_var[0]=1
def f2():
print common_var[0]
common_var[0]=2
if f == 1:
return f1
if f == 2:
return f2
If you call f1 and f2 from the inside of fun_basket, they
behave as expected, so common_var[0] is modified by
whatever function operates on it.
However, calling f1=fun_basket(1); f2 = fun_basket(2) and
then f1(); f2() returns 0 and 0. It is not the way one would
expect closures to work, knowing e.g. Lisp make-counter.
Any ideas what's going on behind the scene?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is python memory shared between theads?

2006-12-01 Thread [EMAIL PROTECTED]
Wesley Henwood wrote:
> So I declare a variable named A in thread1, in script1.py.  I assign
> the value of 2.5 to A.  I then run script2.py in thread2.  Script2.py
> assigns the value of 5.5 to a variable named A.  Now, when thread1
> resums execution, I see that A = 5.5, rather than 2.5 as I expected.
>
> Is this normal behavior?

Yes.  In fact, sharing memory is the whole reason threads exist.  Use
processes in the (more common) case where you don't want memory
sharing, use threads when you do.

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


Re: client/server design and advice

2006-12-01 Thread Peter Decker
On 1 Dec 2006 10:37:39 -0800, John Henry <[EMAIL PROTECTED]> wrote:

> > Now...if only i could master python gui programming and development ;)

> You would short change yourself if you don't check out the other
> packages such as Pythoncard, and Dabo.

FWIW, Dabo has all of the database connectivity stuff built-in. With
PythonCard, you have to roll your own.

-- 

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python vs java & eclipse

2006-12-01 Thread [EMAIL PROTECTED]
hg wrote:
> Thomas Ploch wrote:
> > Yes, thats true, but since eclipse is resource monster (it is still
> > using java), and some people (like me) don't have a super fresh and new
> > computer
>
> If you compare eclipse to VS, it is not that memory hungry

And if you compare Saturn to Jupiter, it's not that big.

> Yet (I believe that) a complete
> IDE can bring functions that an editor, however powerful, cannot

Is there anything _useful_ that it'll bring that a good editor doesn't?
 e.g. in vim I do get
* automatic syntax checking (if I type "if a=1:" and hit enter, it'll
immediately highlight the syntax error)
* omni-completion (because Intellisense is trademarked)
* refactoring (with BicycleRepairMan integration)
* folding (which is more important than the above 3 combined, IMO)
* online help (typing cmp( gives me the docstring for cmp in the status
line, F1 to view the whole thing)

As well as all the basics (tags/class browser/good regex support/syntax
highlighting/autoindent/source control integration/etc).

I'm not trolling here, I'm looking for interesting new features I can
steal.

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


Re: detecting that a SQL db is running

2006-12-01 Thread bill ramsay
thank you paul,  much appreciated
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PythonTidy

2006-12-01 Thread Thomas Heller
Chuck Rhode schrieb:
> Thomas Heller wrote this on Thu, Nov 30, 2006 at 09:50:25PM +0100.  My
> reply is below.
> 
>> The two things that bother me at the moment are how the comments are
>> formatted (dunno if that can be customized or changed easily), and
>> it would be good if the script took command line args instead of
>> working as a filter only.
> 
> Thank you for trying PythonTidy.
> 
> o Command-line args: Please give an example of a standard command that
> I might emulate w.r.t. standard argument use.

Well, at least it would be nice if I could call
'PythonTidy.py mymodule.py' to tidy up the mymodule.py file.

> o Comments: Input is parsed twice: I use *tokenize.generate_tokens* to
> extract the comments and *compiler.parse* to generate the Abstract
> Syntax Tree (AST).  Other applications usually use the AST to generate
> bytecode, so it contains no information about comments.  The tokens
> list identifies keywords (and comments and some whitespace) but
> doesn't group them into statements.  I need both: comments *and*
> functional grouping.  Fortunately both the AST and the tokens list
> carry line numbers to reference the source.  Unfortunately the AST
> line numbers are relative to functional groups and do not necessarily
> apply to the particular keywords that introduce each group.  This
> makes fixing the position of comments relative to reconstructed code a
> bit of a challenge.  For example, when a comment has a line number in
> the beginning/ending range of what would normally be considered one
> command, I have to assume it is an inline comment regardless of how it
> may have appeared in the original code.
> 
> Out-of-line comments should appear pretty much as they did in the
> original code, however.  Can you provide an example where they do not?
> Would you prefer that they be left justified or wrapped?  >-~

Here is part of a diff before and after running PythonTidy on it:


-def comptr_setitem(self, index, value):
-# We override the __setitem__ method of the
-# POINTER(POINTER(interface)) type, so that the COM
-# reference count is managed correctly.
-#
-# This is so that we can implement COM methods that have to
-# return COM pointers more easily and consistent.  Instead of
-# using CopyComPointer in the method implementation, we can
-# simply do:
-#
-# def GetTypeInfo(self, this, ..., pptinfo):
-# if not pptinfo: return E_POINTER
-# pptinfo[0] = a_com_interface_pointer
-# return S_OK
+def comptr_setitem(self, index, value):  # We override the __setitem__ 
method of the
+ # POINTER(POINTER(interface)) 
type, so that the COM
+ # reference count is managed 
correctly.
+ #
+ # This is so that we can 
implement COM methods that have to
+ # return COM pointers more 
easily and consistent.  Instead of
+ # using CopyComPointer in the 
method implementation, we can
+ # simply do:
+ #
+ # def GetTypeInfo(self, this, 
..., pptinfo):
+ # if not pptinfo: return 
E_POINTER
+ # pptinfo[0] = 
a_com_interface_pointer
+ # return S_OK


Can this be customized?

> Doc strings (for modules, class declarations, and functions) are
> another matter.  PythonTidy should not mess with them (unless
> LEFTJUST_DOC_STRINGS is True).  They should appear exactly as
> originally written.
> 
> I was taught that code ought to be self documenting and that comments
> more often than not diminish readability by padding the code beyond
> what can be comprehended on one page (screen).  I use them only
> minimally and am not greatly inconvenienced when they are moved around
> a little.
> 

Thomas

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


Re: Python25.zip

2006-12-01 Thread Colin J. Williams
Dennis Lee Bieber wrote:
> On Thu, 30 Nov 2006 18:14:11 -0500, "Colin J. Williams"
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
> 
>> As part of the Python initialization, C:\Windows\System32\Python25.zip 
>> is set up in the path.
>>
>> I haven't seen any documentation on the use or purpose of the zip file.
>>
>   Well, did you examine the contents of it?
There is no such file in C:\Windows\System32 - Python 2.5 on a Windows XP
> 
>   I believe for some versions now, "import" can pull from a ZIP
> archive -- perhaps they've put the many standard library imports into a
> single file...
Yes, since 2.3 - thanks to Fredrick for the pointer to PEP 273.  That 
gives the helpful warning that the above should follow the home 
directory in the path list.

PEP 302 says "[PYTHONPATH] is directly needed for Zip imports."

The role of Python25.zip is not clear.  Is it required in the path just 
to enable the import X.zip capability?

Colin W.

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


Re: python vs java & eclipse

2006-12-01 Thread Bjoern Schliessmann
Paul Boddie wrote:

> Eclipse may be quite a technical achievement, but I found it
> irritating. Aside from the misuse of screen real-estate, I found
> that typing two characters and having what seemed like half my
> source file underlined in red, with multiple messages telling me
> that I had yet to define or import something or other when what I
> was about to do was to write the declaration, all conspired to
> make me want to scream, "WTF do you think I was going to type in
> about five seconds time? Work it out and autocomplete it if you're
> so damned clever!"

I had exactly the same experience when trying out Eclipse :D I'll
stick with "good ol' vi".

Regards,


Björn

-- 
BOFH excuse #227:

Fatal error right in front of screen

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


Re: detecting that a SQL db is running

2006-12-01 Thread Josh Bloom

I think the main point is that your Python code should be written in such a
way that when you attempt to connect to your local MSDE it will timeout
correctly instead of hanging.

Do you have a loop somewhere that just keeps retrying the connection instead
of giving up at some point?

Here are a couple of links to bits o code, that you can use to see whats
running on your local machine.
http://blog.dowski.com/2003/12/20/getting-at-processes-with-python-and-wmi/
http://mail.python.org/pipermail/python-win32/2001-November/000155.html
Search the resulting lists for whatever name MSDE is supposed to run as.

-Josh

On 12/1/06, bill ramsay <[EMAIL PROTECTED]> wrote:


Dennis

none of this matters,  all i am trying to find out is whether or not
the local MSDE is actually running.

I put all the other bits in there to try and put some background to
it.

kind regards

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

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

Re: detecting that a SQL db is running

2006-12-01 Thread Paul McNett
bill ramsay wrote:
> none of this matters,  all i am trying to find out is whether or not
> the local MSDE is actually running.

If it is a local MSDE then you may be able to rely on the connection
being refused if the server isn't running.

#-- begin
import socket

host = "127.0.0.1"
port = 1433  ## replace with msde_port, if it differs

s = socket.socket(socket.AF_INET)
try:
s.connect((host, port))
print "Server on %s is running" % port
except socket.error, e:
print "Server on %s appears to be down (%s)" % (port, e)

#-- end

Please note that this is untested and not very well thought through. But
try it and see if it gets you on the right track. If this isn't run
locally, you'll probably need to set the timeout low enough for the
connect call not to appear to hang before returning the timeout error.

-- 
pkm ~ http://paulmcnett.com


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


Re: I/O Multiplexing and non blocking socket

2006-12-01 Thread Bjoern Schliessmann
Salvatore Di Fazio wrote:

> Thank you guys, but I would like to use the standard libraries

Then I suggest you read a good book about Unix programming,
especially about the workings of read(), write() and select(). If
you've understood this doing it with python's read/write/select
will be easy.

Everyone may choose to reinvent the wheel :)

Regards,


Björn

-- 
BOFH excuse #180:

ether leak

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


Re: Thread help

2006-12-01 Thread Bjoern Schliessmann
Grant Edwards wrote:
> On 2006-12-01, Salvatore Di Fazio <[EMAIL PROTECTED]>
 
>> I would make 3 threads for a client application.
 
> You should use 4.

I vote for just 1.

Regards,


Björn 

-- 
BOFH excuse #236:

Fanout dropping voltage too much, try cutting some of those little
traces

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


Re: Python popenX() slowness on AIX?

2006-12-01 Thread allenjo5
Stefaan A Eeckels wrote:
> On 24 Nov 2006 09:03:41 -0800
> [EMAIL PROTECTED] wrote:
>
> > Stefaan A Eeckels wrote:
> > > On 21 Nov 2006 13:02:14 -0800
> > > [EMAIL PROTECTED] wrote:
> > >
> > > > The fact that it does this in Python code instead of C is the main
> > > > cause of the slowness.  So, unless Python is changed to do this
> > > > in C, it's always going to be slow on AIX :-(
> > >
> > > I guess that the reason it's slow is that there are many
> > > descriptors to try and close. Reducing them using ulimit -n could
> > > improve the speed.
> > >
> > > AIX has a fcntl command to close all open file descriptors from a
> > > descriptor onwards:
> > >
> > > fcntl(3, F_CLOSEM);
> > >
> > > This of course should be used instead of the loop:
> > >
> > > 10 happens to be the value of F_CLOSEM (from /usr/include/fcntl.h).
> > > I've currently no access to an AIX system with Python, but it could
> > > be worth trying.
> >
> > Yes, very much worth it.  F_CLOSEM is _so_ much better than the loop,
> > even in C.   Using your brilliant suggestion, I now have a simple
> > patch to the python source that implements it for any OS that happens
> > to have the fcntl F_CLOSEM option.
>
> The *BSDs and Solaris have "closefrom(3)" which does the same as
> F_CLOSEM in AIX. As with AIX, the speedup is dramatic when there are a
> lot of file descriptors to try and close.
>
> > It is below in its entirety.  I believe I got the try: stuff correct,
> > but since I'm new to Python, I'd appreciate any comments.
>
> I'm no great Python specialist myself. I'll leave it to those better
> qualified to comment.
>
> > I have another patch to implement my os.rclose(x,y) method, which
> > would improve the speed of popenX() for the OSes that don't have
> > F_CLOSEM, by doing the close() loop in C instead of Python,  but I
> > don't know if it would be as likely to be accepted as this probably
> > would be.
> >
> > Now, where do I send my proposed patch for consideration?
>
> The README file in the Python distribution has the following to say:
>
> Patches and contributions
> -
>
> To submit a patch or other contribution, please use the Python Patch
> Manager at http://sourceforge.net/patch/?group_id=5470.  Guidelines
> for patch submission may be found at http://www.python.org/patches/.

Thanks.  I joined sourceforge, and submitted this patch:

http://sourceforge.net/tracker/index.php?func=detail&aid=1607087&group_id=5470&atid=305470

For some reason, I could not submit it using Firefox 1.5, so I had to
relent and use IE.

John.

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


Re: Thread help

2006-12-01 Thread Salvatore Di Fazio
Grant Edwards ha scritto:

> http://docs.python.org/lib/module-threading.html
> http://linuxgazette.net/107/pai.html
> http://www.wellho.net/solutions/python-python-threads-a-first-example.html
> http://heather.cs.ucdavis.edu/~matloff/Python/PyThreads.pdf

Thank Edward,
I didn't find the linuxgazette tutorial before the post.
Tnx

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


Re: Thread help

2006-12-01 Thread Salvatore Di Fazio
Grant Edwards ha scritto:

> http://docs.python.org/lib/module-threading.html
> http://linuxgazette.net/107/pai.html
> http://www.wellho.net/solutions/python-python-threads-a-first-example.html
> http://heather.cs.ucdavis.edu/~matloff/Python/PyThreads.pdf

Thank Edward,
I didn't find the linuxgazette tutorial.
Tnx

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


Re: Python spam?

2006-12-01 Thread Frederic Rentsch
Hendrik van Rooyen wrote:
> "Aahz" <[EMAIL PROTECTED]> wrote:
>
>   
>> Anyone else getting "Python-related" spam?  So far, I've seen messages
>> "from" Barry Warsaw and Skip Montanaro (although of course header
>> analysis proves they didn't send it).
>> --
>> 
>
> not like that - just the normal crud from people giving me get rich quick tips
> on the stock market that is aimed at mobilising my money to follow theirs to
> help influence the price of a share...
>
> - Hendrik
>
>
>   
...which I noticed works amazingly well in many cases, looking at the 
charts. which, again, means that the trick isn't likely to fizzle out 
soon as others have with victims getting wise to it. Getting feathers 
plucked in this game isn't a turn-off. It's an opportunity to join the 
pluckers by speeding up one's turnover at the expense of the slowpokes. 
Like pyramid sales this it is a self-generating market.
   This game, at least, isn't unethical, other than clogging the 
internet with reckless traffic. I've been asking myself why it seems so 
difficult to backtrace such obtrusive, if not criminal, traffic to the 
source and squash it there. Perhaps some knowledgeable volunteer would 
share his insights. Perhaps stalking con artists could be another 
interest group.

Frederic



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


Re: detecting that a SQL db is running

2006-12-01 Thread bill ramsay
Dennis

none of this matters,  all i am trying to find out is whether or not
the local MSDE is actually running.

I put all the other bits in there to try and put some background to
it.

kind regards

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


Re: Thread help

2006-12-01 Thread Grant Edwards
On 2006-12-01, Salvatore Di Fazio <[EMAIL PROTECTED]> wrote:
> Grant Edwards ha scritto:
>
>> You should use 4.
>
> Yes, but I don't know how can I make a thread :)

Perhaps you should have said that earlier?

Googling for "pythong threads" finds some useful info:

http://docs.python.org/lib/module-threading.html
http://linuxgazette.net/107/pai.html
http://www.wellho.net/solutions/python-python-threads-a-first-example.html
http://heather.cs.ucdavis.edu/~matloff/Python/PyThreads.pdf

-- 
Grant Edwards   grante Yow!  Am I elected yet?
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: good documentation about win32api ??

2006-12-01 Thread Roger Upole
"__schronos__"  wrote:
> Hi all.
>
> Recently I've to developed a project in python that made operation
> under win32 platform and I found a lot of problema to find good
> information. The only one documentation is in ActivePython page
> (http://aspn.activestate.com/ASPN/docs/ASPNTOC-APYTH2.4.0) but it is
> not very good and finally I had to turn to the newsgroups (it was very
> nice).
>
>   And the question is: ¿Anybody knows where can I find good
> documentation about win32api?
>
> Thanks in advanced.

The pywin32 package has a .chm help file that covers the modules,
objects and methods.  Also, there are demos of many of the
functions and interfaces.

  Roger




== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet 
News==
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ 
Newsgroups
= East and West-Coast Server Farms - Total Privacy via Encryption =
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to read the directory which the actively running python file is located in?

2006-12-01 Thread John Machin

anders wrote:
> in os module there is many funktion/methods to extract this information
> to ask the path to the current running pythonprogram you can do likes
> this
>
> - CUT---
> import os
> print os.getcwd()
>
> - CUT --
>
> // Anders
>
>
> Michael Malinowski skrev:
>
> > Is there a way to read the directory that the currently running python file
> > is located in?
> > Cheers
> > Mike.

os.getcwd() provides the "current working directory". This is *not*
necessarily the directory that the "currently running python file"
[whatever that means] is located in.

Try picking what you really want/need out of this:

C:\junk\foo>type ..\where.py
import sys, os
if __name__ == "__main__":
print "running as script"
else:
print "imported module named", __name__
print "code loaded from file", __file__
print "sys.argv[0] is", sys.argv[0]
print "cwd is", os.getcwd()

C:\junk\foo>..\where.py
running as script
code loaded from file C:\junk\where.py
sys.argv[0] is C:\junk\where.py
cwd is C:\junk\foo

C:\junk\foo>type runwhere.py
import sys
sys.path[0:0] = ['c:\\junk']
import where

C:\junk\foo>runwhere.py
imported module named where
code loaded from file c:\junk\where.py
sys.argv[0] is C:\junk\foo\runwhere.py
cwd is C:\junk\foo

C:\junk\foo>cd ..

C:\junk>md bar

C:\junk>cd bar

C:\junk\bar>..\foo\runwhere.py
imported module named where
code loaded from file c:\junk\where.pyc
sys.argv[0] is C:\junk\foo\runwhere.py
cwd is C:\junk\bar

HTH,
John

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


Re: good documentation about win32api ??

2006-12-01 Thread Thomas Heller
krishnakant Mane schrieb:
> On 1 Dec 2006 09:56:09 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> 
>> http://msdn.microsoft.com covers the API itself, although you need to
>> transliterate from the C code to python.
> Exactly! that's where the problem lyes.
> I am pritty well to do with windows API, I am an a good python
> programmer, but I can't find the link between the two.
> there are modules but no good documentation.
> krishnakant.

Maybe then ctypes is the right thing for you?

Thomas

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


RE: v2.3, 2.4, and 2.5's GUI is slow for me

2006-12-01 Thread Duncan Booth
[EMAIL PROTECTED] wrote:

>> I don't use IDLE too much anymore, just for quick tests, but 
> 
> Just curious.  I have tried IDLE, but stopped using it after going
> through a few of the tutorials.  I just type things in at the 'python'
> prompt, regardless of which platform I am working on; Linux, AIX or
> Windows.  But, then again, my code winds up in a batch process or part
> of a web app.  
> 
> Is there something cool I am missing?
> 
The main plus of idle for me is that in interactive mode I can easily pull 
back any single statement (e.g. a complete class definition) edit and then 
re-execute it. The command line only pulls back single lines for editing, 
not complete statements.

Also the ways to pull back a previous command are simpler. As well as 
typing the start of a command then using alt-p to pull it back you can look 
through the buffer, put the cursor on a command and hit return to get an 
editable copy.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Thread help

2006-12-01 Thread Salvatore Di Fazio
Grant Edwards ha scritto:

> You should use 4.

Yes, but I don't know how can I make a thread :)

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


Re: Take the $million challenge: Prove 911 conspriracy theorists are wrong

2006-12-01 Thread st911
I found this nice dialog on the internet:
=

> Well, if you want to convice me, just answer these questions:

If you can prove that the official explanation is correct, what's
keeping
you from collecting a MILLION dollars?  Even if you're too wealthy to
bother, you could donate the proceeds to the Aryan Nation or the John
Birch
Society.

> 1. How much explosives were used and what type?

Thermate/thermite have been discovered in chemical tests, and evidence
of
its use is plainly visible in photographic an video evidence from the
WTC
buildings on 9/11.  Thermate does not cause millions of tones of
concrete to
become pulverized into dust in mid-air (as video evidence clearly
shows), so
another high-energy explosive must have also been used. Now that we
have
positive proof that explosives were used, and once the secondary
compounds
have been discovered, the quantities and placement can be estimated
from
examinations of the video and photo evidence.

> 2. How many people were needed to prepare the building for demolition?

Irrelevant to the established fact that explosives were used.  Will be
determined in the new investigation. BTW: It's "buildings," not
"building."
Did you realize that *three* WTC towers collapsed on 9/11/01, despite
only 2
buildings being hit by jets?  Most Americans don't realize this obvious
fact.  Why?

> 3. How long did it take to prepare the buildings for demolition?

Irrelevant to the established fact that explosives were used.  Once the
identities of the conspirators are discovered in a new investigation,
the
timeline can be established.  (That's what investigators do.)

> 4. How many people had to be bribed and how much were they bribed to
> keep silent about the preparations?

Irrelevant to the established fact that explosives were used.  Those
conspirators (whether bribed or not) that are still alive must be
discovered
and convicted for their crimes, which may include conspiracy to commit
treason. The only way to bring the criminals to justice is to open a
new
investigation which will examine *all* relevant evidence, including
sequestered videos, audio tapes, and classified documents.

Everybody with an IQ above room temperature knows that the 9/11
Commission
report was a whitewash, which didn't even attempt to lay blame at the
feet
of military and civilian officials who were asleep at the wheel on
9/11/01.
It proves that Bush is not serious about national security.

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


Re: Thread help

2006-12-01 Thread Grant Edwards
On 2006-12-01, Salvatore Di Fazio <[EMAIL PROTECTED]> wrote:

> I would make 3 threads for a client application.

You should use 4.

-- 
Grant Edwards   grante Yow!  My TOYOTA is built
  at   like a... BAGEL with CREAM
   visi.comCHEESE!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to read the directory which the actively running python file is located in?

2006-12-01 Thread Gerold Penz
Michael Malinowski schrieb:
> Is there a way to read the directory that the currently running python file
> is located in?

Hi Mike!

To get the started program:

   sys.argv[0]

Don´t use ``os.curdir``.


To get the filename, of the current module:

   __file__


To get the directory:

   os.path.split(sys.argv[0])[0]
   os.path.split(__file__)[0]


Regards,
Gerold
:-)

-- 

Gerold Penz - bcom - Programmierung
 [EMAIL PROTECTED] | http://gerold.bcom.at | http://sw3.at
Ehrliche, herzliche Begeisterung ist einer der
 wirksamsten Erfolgsfaktoren. Dale Carnegie
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ruby/Python/REXX as a MUCK scripting language

2006-12-01 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Laurent Pointal  <[EMAIL PROTECTED]> wrote:
>>  .
>>  .
>>  .
> there's the security issue that really worries me. . .  I have to be
> able to limit what the interpreter can execute.  I can't have my users
.
.
.
>>> I Agree with F.Bayer, when reading OP post, I immediatly think about Lua.
>> 
>> Does Lua have an appropriate security model--a sandbox or such?
>> Fond though I am of Lua, such would be news to me.
>
>I dont think of a security model like in Java, but in the possibility to
>limit the accessible libraries for interpreted code.
>
>   http://www.lua.org/manual/5.1/manual.html#5
>
>If OP just need some computation logic, he could limit external world
>communication libraries (these libraries must be loaded by the C host
>program before being usable by scripts).
>Need to look more precisely to the minimum library set to load and to
>available functions in this set. Maybe it is possible to remove some
>undesired functions from Lua symbol tables just after loading libraries.
>
>
>[note: I have still not used Lua, but I look at it for futur use in a
>current development where an embedded Python would be too heavy and make
>problems relative to the GIL - but I'm still a Python fan in other use
>cases]
.
.
.
I agree that Lua has a nice collection of primitives, and
there certainly is scope for security-related programming.
There isn't a body of work or precedent for polished results
in this area, though, ...

Good luck with the future use you anticipate.
-- 
http://mail.python.org/mailman/listinfo/python-list


Watch Alex Jones' Terror Storm, Bohemian Grove, Arrest Video, on video.google.com and infowars.com

2006-12-01 Thread st911

The one who digs a trap for others falls into it himself. - Moral law
of all religions.

==
Our confidence in 911 controlled demolition is such that we have
invited people to see the truth under the pretext of debunking it. This
letter was sent to professors in many US/Europe/China/India/Brazil
Universities and please do not hesitate to duplicate. Volunteers are
needed. Now please send this to county police stations, fire chiefs,
City governments, police sheriffs, judges, magistrates, doctors,
lawyers, highschools and all institutions of civil govermnents.
==
Dear Professor,

Ever since the crime of the century on 9/11/2001, there have
been many conspiracy theories woven around the incident, and
even 1 Million challenge/reward has been posted:

http://reopen911.org/Contest.htm

Some say that jet fuel cannot melt iron because car accident
fires and plane fires have never melted even the steel body
of the car or the aluminum body of the plane involved in a
traffic accident. Only thermite can melt so much so fast.

The conspiracy theorists have erected an enormous body of
evidence and we APPEAL you to apply your intellectual power
to the known facts and debunk the conspiracy theorists who
are now the university professors and a blot on your occupation.

Much of their theory is based on the hypothesis of CONTROLLED
DEMOLITION based on compositional analysis, finding numerous
pieces of columns with diagonal cuts for ejection, pyroclastic
flow from pulverization of concrete into fluidized dust, and
numerous testimonies of explosions, which they present in videos
on the internet. They object that the pentagon was not hit by
a plane and FBI confiscated all the pentagon videos. Furthermore,
they have shown by producing a side by side video of Osama that
his confession video is a fake, and they call it a synthetic
terror.

Please visit their sites to debunk their spins:

www.scholarsfor911truth.org
www.journalof911studies.org
http://www.journalof911studies.com/JonesAnswersQuestionsWorldTradeCenter.pdf

They are using videos to make a spin in the tradition of Edward L
Bernays (Freud's Nephew, see wikipedia on him, and watch the video on
how he broke the taboo and convinced women to smoke.).

They claim that the government used explosives to bring down the
buildings in controlled demolition, and used thermate to manufacture
molten metal pools to put the blame on smoky jet fuel fire which
is ice cold for melting steel.
Please search google web for thermate using this link:

http://www.google.com/search?as_q=&num=100&as_epq=thermate

In the results you will find these videos that show their argument
on thermate in brief:

http://www.supportthetruth.com/jones.php
http://www.youtube.com/watch?v=_wVLeKwSkXA&mode=related
http://video.google.com/videoplay?docid=-4757274759497686216

They have put popular mechanics in retreat as in this audio debate
with popular mechanics

5MB Audio download:

http://www.911podcasts.com/display.php?vid=158

found via http://911blogger.com/node/2278?page=2

==
They are also calling professor Noam Chomsky as the gate keeper of
the left. Here are the links:

Here's the discovery path:

On st911.org visit this:
Hugo Chavez and the sulfuric odor of "devil" Bush
22 September 2006, onlinejournal.com, Larry Chin
http://onlinejournal.com/artman/publish/article_1234.shtml

There, visit this:
Alternative Media Censorship
http://questionsquestions.net/gatekeepers.html
==

There are a lot of government grants available for research on this
subject intimately linked to terrorism. We ask you as concerned
citizens to exert your intellectual capabilities on this subject and
give an ethical public opinion.

If you can find a general thermodynamic type result that their
conspiracy theory is impossible and that the cars that burn in
accidents can melt their steel body and planes can melt their
aluminum from jet fuel or a plane crash can quickly cause mixing
of the needed reactants to produce a fast thermate reaction with
sulfur from the gypsum wall board, the Administration would have won.

Thank you for your time, fortitude and intellectual honesty.

If you know someone in departments of Mechanical Engineering,
Structural Engineering, Combustion Science and Engineering, Chemistry,
Physics, Materials Science, Metallurgy who would have expertise in the
subject, please pass on the email and just view the videos as a
responsible informed citizen and for its highly entertaining value.
There is also a lot of material to work with for your subject area
of research and study.

Concerned Citizens Appeal to you !!!

We have sent this email to select recipients who will be proud of
the government and know how to propagate the information intelligently.

http://portland.indymedia.org/en/2006/06/341238.shtml

If any of the video links dont work, and censored, just v

Re: String formatters with variable argument length

2006-12-01 Thread John Machin

Peter Otten wrote:
> John Machin wrote:
>
> >> > Fredrik Tolf wrote:
>
> >> > > The thing is, I want to get format strings from the user, and I don't
> >> > > want to require the user to consume all the arguments.
>
> > what's ugly about this:
> > [untested]:
> >
> > def count_format_args(s):
> > pending = False
> > count = 0
> > for c in s:
> > if c == "%":
> > # doubled % chars aren't counted
> > pending = not pending
> > elif pending:
> > count += 1
> > pending = False
> > return count
> >
> > output = format % arglist[:count_format_args(format)]
>
> Keep in mind, though, that it doesn't take '*' into account:
>
> >>> count_format_args("%*.*f")
> 1
> >>> "%*.*f" % (3,2,1)
> '1.00'

A good point. Adding checking for "*" would make it rather ugly, as "*"
is special only inside a conversion specifier.

>
> And just because I don't think I've seen it before:
>
> >>> count_format_args("%42%")
> 1
> >>> "%42%" % ()
> ' %'

Hmmm ... I hadn't seen that before either. I would have said if shown
that input that I could have put in an error check that pending was not
true at the end of the loop, but was relying instead on an exception
from the formatting operator.

Even better: >>> "%-42%" % ()
 '% '

:-)
Before gentle readers consider nominating the Python core dev team to
thedailyWTF.com, they might wish to:
(1) read the Python documentation
(http://docs.python.org/lib/typesseq-strings.html)
[it is not a simple escape mechanism; the second % is a "conversion
type"]
(2) compare those docs carefully with K&R v2 section B1.2 Formatted
Output (pp 243-245)
(3) note that not everything that emanated from Murray Hill NJ obeyed
the Law of Least Astonishment
:-)

Cheers,
John

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


Thread help

2006-12-01 Thread Salvatore Di Fazio
Hi guys,
I would make 3 threads for a client application.

Tnx

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


Security Descriptor and CoInitializeSecurity

2006-12-01 Thread Huayang Xia
I'd like to call pythoncom.CoInitializeSecurity with a
PySecurityDescriptor object to set the process-wide security values.
But I'm not able to find a way to let the code go through.

I have read MSDN and searched web, I've not been able to find answer. I
cooked a security descriptor like this (assume aces is a tuple of tuple
(access, sid) :



sd = win32security.SECURITY_DESCRIPTOR()
sd.Initialize()
sd.SetSecurityDescriptorOwner(sid_owner, False)
sd.SetSecurityDescriptorGroup(sid_group, False)


# create DACL
dacl = win32security.ACL()
dacl.Initialize()
for (access, acc_sid) in aces:
# Add ACE which is access and SID
dacl.AddAccessAllowedAce(win32security.ACL_REVISION, access,
isinstance(acc_sid, (unicode, str)) and
win32security.ConvertStringSidToSid(acc_sid) or acc_sid)

sd.SetDacl(True, dacl, False)   # SetSecurityDescriptorDacl
print sd.IsSelfRelative()# result is 1

The sd is a self relative one.

>From MSDN, after calling InitializeSecurityDescriptor, the sd is
absolute sd, and CoInitializeSecurity needs absolute sd. Pythonwin has
not wrapped function like 'MakeAbsoluteSD'.

Has someone ever had same problem. Could you give a hint for solving
the problem. Thanks.

Regards

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


Re: good documentation about win32api ??

2006-12-01 Thread krishnakant Mane
On 1 Dec 2006 09:56:09 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> http://msdn.microsoft.com covers the API itself, although you need to
> transliterate from the C code to python.
Exactly! that's where the problem lyes.
I am pritty well to do with windows API, I am an a good python
programmer, but I can't find the link between the two.
there are modules but no good documentation.
krishnakant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: client/server design and advice

2006-12-01 Thread John Henry
TonyM wrote:


> > Pyro rocks for that.
>
> Awesome, ill look into it in greater detail and will most likely use
> it.  Given what ive seen so far it looks like it will make the
> client/server interface fairly easy to write.
>

Correction:  not "fairly easy" - make that "incredibly easy".  Even
Micky likes it.  :=)

> Now...if only i could master python gui programming and development ;)
> I'm not entirely sure which gui lib im going to end up using, but as of
> now im leaning more towards tkinter as i know it will work where i need
> and it seems to be one of the more documented.  Ive looked at used
> wxpython a little but had trouble figure out a few minor things while
> playing around with it initially.  I've also thought about pygtk
> although I haven't taken the time to play with it quite yet as i
> assumed it was primarily for linux (id be running the majority of these
> on windows pcs).
>

You would short change yourself if you don't check out the other
packages such as Pythoncard, and Dabo.

The other thing I recommend for large scale applications:

http://www-128.ibm.com/developerworks/library/l-pythrd.html


> Thanks for the suggestions :)
> Tony

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


Re: Python spam?

2006-12-01 Thread skip

aahz> Anyone else getting "Python-related" spam?  So far, I've seen
aahz> messages "from" Barry Warsaw and Skip Montanaro (although of
aahz> course header analysis proves they didn't send it).

I blacklisted Barry long ago.  He's probably sending out spam in my name in
retaliation.  ;-)

Skip

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


RE: v2.3, 2.4, and 2.5's GUI is slow for me

2006-12-01 Thread Michael . Coll-Barth


> -Original Message-
> From: John Salerno

> 
> I don't use IDLE too much anymore, just for quick tests, but 

Just curious.  I have tried IDLE, but stopped using it after going through a 
few of the tutorials.  I just type things in at the 'python' prompt, regardless 
of which platform I am working on; Linux, AIX or Windows.  But, then again, my 
code winds up in a batch process or part of a web app.  

Is there something cool I am missing?
















The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.

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


RE: client/server design and advice

2006-12-01 Thread bruce
hi irmen...

happened to come across this post. haven't looked at pyro. regarding your
'work packets' could these essentially be 'programs/apps' that that are
requested by the client apps, and are then granted by the dispatch/server
app?

i'm considering condor (univ of wisconsin) but am curious as to if pyro
might also work.

i'm looking to create a small distributed crawling app for crawling/scraping
of targeted websites

thanks


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf
Of Irmen de Jong
Sent: Friday, December 01, 2006 10:05 AM
To: python-list@python.org
Subject: Re: client/server design and advice


TonyM wrote:

> Lastly, as far as the networking goes, i have seen posts and such about
> something called Pyro (http://pyro.sourceforge.net) and wondered if
> that was worth looking into for the client/server interaction.

I'm currently busy with a new version of Pyro (3.6) and it already
includes a new 'distributed computing' example, where there is
a single dispatcher service and one or more 'worker' clients.
The clients request work 'packets' from the dispatcher and
process them in parallel.
Maybe this is a good starting point of your system?
Current code is available from Pyro's CVS repository.

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

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


Re: v2.3, 2.4, and 2.5's GUI is slow for me

2006-12-01 Thread John Salerno
g4rlik wrote:
> I've been asking all over the place, namely different forums.  I even
> e-mailed [EMAIL PROTECTED] about my problem, but they couldn't assist me too
> much.
> 
> My problem is..the GUI for versions 2.3, 2.4, and 2.5 of Python run very
> sluggishly.  When I type in them or move them around my desktop, it's very
> slow.  I have figured out that this is because of the subprocesses running.  

I don't use IDLE too much anymore, just for quick tests, but I noticed 
this from the beginning as well. It's sluggish when you drag it around 
the screen. Not sure why.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python vs java & eclipse

2006-12-01 Thread Paul Boddie
Stephen Eilert wrote:
>
> The support for Java is light-years ahead. Sometimes I feel that
> Eclipse is coding for me (quickfix, for instance).

Eclipse may be quite a technical achievement, but I found it
irritating. Aside from the misuse of screen real-estate, I found that
typing two characters and having what seemed like half my source file
underlined in red, with multiple messages telling me that I had yet to
define or import something or other when what I was about to do was to
write the declaration, all conspired to make me want to scream, "WTF do
you think I was going to type in about five seconds time? Work it out
and autocomplete it if you're so damned clever!"

So, Eclipse certainly has its share of detractors, too. ;-)

[...]

> That said, the code completion for Python is still in its early stages.
> There is a lot of room for improvement, even for a dynamic language.

Agreed. I don't believe in endless refactoring, and I think that's
frequently a symptom of using an overly inflexible statically typed
language (where it's more like "Refactoring" - the big R symbolising
the seriousness and heavy lifting involved), but there are often times
when I've wondered whether something could alert me to obvious
breakage, especially after fairly big changes, acting possibly within
the editing environment. I suppose pylint and similar tools have been
working towards that goal, but I often wonder about producing something
more subtle: something which is more clever than looking at modules and
globals, and yet doesn't nag you continously about things which you'll
discover almost immediately anyway.

Paul

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


Re: client/server design and advice

2006-12-01 Thread Irmen de Jong
TonyM wrote:

> Lastly, as far as the networking goes, i have seen posts and such about
> something called Pyro (http://pyro.sourceforge.net) and wondered if
> that was worth looking into for the client/server interaction.

I'm currently busy with a new version of Pyro (3.6) and it already
includes a new 'distributed computing' example, where there is
a single dispatcher service and one or more 'worker' clients.
The clients request work 'packets' from the dispatcher and
process them in parallel.
Maybe this is a good starting point of your system?
Current code is available from Pyro's CVS repository.

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


Re: good documentation about win32api ??

2006-12-01 Thread olsongt

__schronos__ wrote:
> Hi all.
>
>   Recently I've to developed a project in python that made operation
> under win32 platform and I found a lot of problema to find good
> information. The only one documentation is in ActivePython page
> (http://aspn.activestate.com/ASPN/docs/ASPNTOC-APYTH2.4.0) but it is
> not very good and finally I had to turn to the newsgroups (it was very
> nice).
>
>   And the question is: ¿Anybody knows where can I find good
> documentation about win32api?
>
> Thanks in advanced.
>
>   ScnS.

http://msdn.microsoft.com covers the API itself, although you need to
transliterate from the C code to python.

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


Re: Is there a reason not to do this?

2006-12-01 Thread Ron Garret
In article <[EMAIL PROTECTED]>,
 "Michele Simionato" <[EMAIL PROTECTED]> wrote:

> Ron Garret wrote:
> > One of the things I find annoying about Python is that when you make a
> > change to a method definition that change is not reflected in existing
> > instances of a class (because you're really defining a new class when
> > you reload a class definition, not actually redefining it).  So I came
> > up with this programming style:
> >
> > def defmethod(cls):
> >   return lambda (func): type.__setattr__(cls, func.func_name, func)
> 
> Why not just ``return lambda func: setattr(cls, func.func_name, func)``
> ?

Because I'm an idiot.  (i.e. yes, that is obviously the right way to do 
it.)

> The only thing I don't like is that all your
> functions/methods will end up begin 'None'.
>
> I'd rather to be able to use
> the help, so I would write
> 
> def defmethod(cls):
> def decorator(func):
> setattr(cls, func.func_name, func)
> return func
> return decorator
> 
> @defmethod(C)
> def m1(self, x):pass
> 
> help(m1)
> 
> 
> BTW, for people with a Lisp background I recommend using IPython with
> emacs  and the
> ipython.el mode. It is pretty good, even if not comparable to Slime.
> 
>  Michele Simionato

Good tips.  Thanks!

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


Re: Is there a reason not to do this?

2006-12-01 Thread Ron Garret
In article <[EMAIL PROTECTED]>,
 "Carl Banks" <[EMAIL PROTECTED]> wrote:

> The principle behind this is pretty much "it was just a language design
> decision".

Yes, and I'm not taking issue with the decision, just pointing out that 
the desire to do things differently is not necessarily perverse.

> P.S. If you want to be truly evil, you could use a class hook to get
> the modifying in-place behavior:
> 
> def modify_in_place(name,bases,clsdict):
> cls = globals()[name]
> for attr,val in clsdict.iteritems():
> setattr(cls,attr,val)
> return cls
> 
> # Replace second C2 class above with this
> class C2:
> __metaclass__ = modify_in_place
> def m1(self): h()

Doesn't work for me:

>>> c2  
<__main__.C2 instance at 0x51e850>
>>> c2.m1()
G
>>> class C2:
...   __metaclass__ = modify_in_place
...   def m1(self): print 'Q'
... 
>>> c2.m1()
G
>>> C2().m1()
Q

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


[no subject]

2006-12-01 Thread Thomas Ploch
Amir Michail schrieb:
> krishnakant Mane wrote:
>> just used the py dev plugin for eclipse.
>> it is great.
> 
> But isn't support for java better because the eclipse ide can take
> advantage of explicit type declarations (e.g.,  for intellisense,
> refactoring, etc.)?
> 
> Amir

Obviously, since eclipse _is_ a full blown Java application, so support
for Java is excellent. It was actually developed for being a Java IDE
but (as far as I know) people were liking it so much, so they decided to
make it expandable (and PyDev is actually a good thing, it supports
PyLint and PyChecker, manages the python path when new modules are
added, but can be improved (as can everything :-) )). But as I said, often my 
system hangs when having quite a few
files opened, so that brought me off using it too often.

Thomas


-- 
"Ein Herz für Kinder" - Ihre Spende hilft! Aktion: www.deutschlandsegelt.de
Unser Dankeschön: Ihr Name auf dem Segel der 1. deutschen America's Cup-Yacht!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Functions, callable objects, and bound/unbound methods

2006-12-01 Thread Ron Garret
In article <[EMAIL PROTECTED]>,
 "Michele Simionato" <[EMAIL PROTECTED]> wrote:

> Duncan Booth wrote:
> > Ron Garret <[EMAIL PROTECTED]> wrote:
> >
> > > I want to say:
> > >
> > > trace(c1.m1)
> > >
> > > and have c1.m1 be replaced with a wrapper that prints debugging info
> > > before actually calling the old value of m1.  The reason I want that
> > > to be an instance of a callable class instead of a function is that I
> > > need a place to store the old value of the method so I can restore it,
> > > and I don't want to start building a global data structure because
> > > that gets horribly ugly, and a callable class is the Right Thing -- if
> > > there's a way to actually make it work.
> > >
> > > Is there?  I tried the obvious things (like making callable inherit
> > > from function, and adding im_func and im_self attribuetes) but they
> > > didn't work.
> >
> > Read "Functions and Methods" in
> > http://users.rcn.com/python/download/Descriptor.htm
> >
> > You need to implement a __get__ method on your class.
> 
> See also
> 
> http://groups.google.com/group/comp.lang.python/browse_frm/thread/d691240a5cfe
> bcdf/93503c5b9c66226e?lnk=gst&q=simionato+subclassing+FunctionType&rnum=1&hl=e
> n#93503c5b9c66226e
> 
> for an example and some discussion.
> 
>  Michele Simionato

Thanks!

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


Re: client/server design and advice

2006-12-01 Thread TonyM
> Don't use sqlite, use a "real" RDBMS.  sqlite is cool, but not really suited
> for large amounts of data, and the concurrent access aspects that are dealt
> with with an RDBMS for free are not to be underestimated.

Would PostgreSQL be suitable in this situation?  I hadn't even thought
about the possible problems that could arise with concurrency but i do
recall it being an issue the last time i worked with sqlite.  I have
also looked into mysql given my extensive experience with it...however
postgresql seems to be faster from what ive read.  Either way i'll work
on writing something to convert and insert the data so that it can
process while im working on the gui and client/server apps.

> Pyro rocks for that.

Awesome, ill look into it in greater detail and will most likely use
it.  Given what ive seen so far it looks like it will make the
client/server interface fairly easy to write.

Now...if only i could master python gui programming and development ;)
I'm not entirely sure which gui lib im going to end up using, but as of
now im leaning more towards tkinter as i know it will work where i need
and it seems to be one of the more documented.  Ive looked at used
wxpython a little but had trouble figure out a few minor things while
playing around with it initially.  I've also thought about pygtk
although I haven't taken the time to play with it quite yet as i
assumed it was primarily for linux (id be running the majority of these
on windows pcs).

Thanks for the suggestions :)
Tony

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


Re: Functions, callable objects, and bound/unbound methods

2006-12-01 Thread Ron Garret
In article <[EMAIL PROTECTED]>,
 Kent Johnson <[EMAIL PROTECTED]> wrote:

> Ron Garret wrote:
> > The reason I want to do this is that I want to implement a trace 
> > facility that traces only specific class methods.  I want to say:
> > 
> > trace(c1.m1)
> > 
> > and have c1.m1 be replaced with a wrapper that prints debugging info 
> > before actually calling the old value of m1.  The reason I want that to 
> > be an instance of a callable class instead of a function is that I need 
> > a place to store the old value of the method so I can restore it, and I 
> > don't want to start building a global data structure because that gets 
> > horribly ugly, and a callable class is the Right Thing -- if there's a 
> > way to actually make it work.
> 
> If the only reason for a callable class is to save a single value (the 
> original function), you could instead store it as an attribute of the 
> wrapper function.

I considered that, and I may yet fall back on it, but 1) I wanted to 
understand how these things worked and 2) I need a way to tell when a 
method has been traced, and isinstance(method, tracer) seems less 
hackish to me than hasattr(method, 'saved_function').

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


Re: Is python memory shared between theads?

2006-12-01 Thread Daniel Dittmar
Wesley Henwood wrote:
> So I declare a variable named A in thread1, in script1.py.  I assign
> the value of 2.5 to A.  I then run script2.py in thread2.  Script2.py
> assigns the value of 5.5 to a variable named A.  Now, when thread1
> resums execution, I see that A = 5.5, rather than 2.5 as I expected.
> 
> Is this normal behavior?  

Not if this is all you are doing. A variable A in script1.py and a 
variable A in script2.py are completely different, even when running in 
the same thread.

But if you're running script1.py and script2.py by calling execfile or 
exec and you pass the same dictionary as the globals argument to 
execfile, then the two scripts would share the global namespace. 
Variables of the same name would really be the same variable.

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


Re: Functions, callable objects, and bound/unbound methods

2006-12-01 Thread Kent Johnson
Ron Garret wrote:
> The reason I want to do this is that I want to implement a trace 
> facility that traces only specific class methods.  I want to say:
> 
> trace(c1.m1)
> 
> and have c1.m1 be replaced with a wrapper that prints debugging info 
> before actually calling the old value of m1.  The reason I want that to 
> be an instance of a callable class instead of a function is that I need 
> a place to store the old value of the method so I can restore it, and I 
> don't want to start building a global data structure because that gets 
> horribly ugly, and a callable class is the Right Thing -- if there's a 
> way to actually make it work.

If the only reason for a callable class is to save a single value (the 
original function), you could instead store it as an attribute of the 
wrapper function.

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


Re: Functions, callable objects, and bound/unbound methods

2006-12-01 Thread Kent Johnson
Ron Garret wrote:
> The reason I want to do this is that I want to implement a trace 
> facility that traces only specific class methods.  I want to say:
> 
> trace(c1.m1)
> 
> and have c1.m1 be replaced with a wrapper that prints debugging info 
> before actually calling the old value of m1.  The reason I want that to 
> be an instance of a callable class instead of a function is that I need 
> a place to store the old value of the method so I can restore it, and I 
> don't want to start building a global data structure because that gets 
> horribly ugly, and a callable class is the Right Thing -- if there's a 
> way to actually make it work.

If the only reason for a callable class is to save a single value (the 
original function), you could instead store it as an attribute of the 
wrapper function.

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


  1   2   >