Hi, SOAP lib for Python 3.0

2009-09-22 Thread Ares
Hi,

Does anyone have a reccommendation on the best soap library for
Python 3.0? The libs I found only support python 2.6 or belove.

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


Re: using python 2.5

2009-09-22 Thread Dave Angel

kunal.k wrote:

I have installed python 2.5 for a particular code. Now i have 2.6
already installed. How do i direct this code to use the 2.5 modules??

  
I can think of two different questions you might be asking.  1) How do I 
get the add-on modules installed with 2.6 to also work in 2.5?  or 2) 
How do I get a particular script to use 2.5, while all other scripts 
should use 2.6 ?


Sean answered #1, but I think you meant to ask #2

First question is what OS you've installed these on.  In Windows, the 
python version is selected by file associations, while in Unix/Linux 
systems, it's selected by the shebang line at the beginning of the script.


A generic answer if you just have one script is to make an OS script 
(bat file, or shell script) that invokes the particular python 
interpreter, passing it the script name as an argument).


But if you want to be able to just run the script as though it were a 
compiled executable, tell us what OS you're on, and maybe the base 
locations of your two installations.


DaveA

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


Re: easy question, how to double a variable

2009-09-22 Thread Hendrik van Rooyen
On Monday, 21 September 2009 22:50:31 daggerdvm wrote:

> carl banks.you are a dork

No mister_do_my_homework, he is not.  
He is actually a respected member
of this little community.

You, however, are beginning to look like one.

Why do you not come clean - tell us what you are doing,
show us what you have tried, and maybe, just maybe, 
some kind soul will help you, instead of mocking you.

Although that is now less likely as you have started calling
people derogatory names.

And if you do not at least do what I have suggested, there is about a 
snowball's hope in hell of anybody helping you, as you come across as a 
parasite who wants other people to do his work.

Prove you are not, or go away.

- Hendrik

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


Re: where is ctrl+newline handled in pywin editor?

2009-09-22 Thread Roger Upole
"C or L Smith" wrote:
>I use the pywin environment on Windows for python code editing and 
>interactive environment.
>
> I've been able to find the place in the editor files where the enter key 
> is handled and where the whitespace is stripped from a line and I've been 
> able to get it to not leave any white space when a double return is 
> entered. But what I would like to be able to do is find the place where 
> ctrl+enter is handled so I could have it strip any trailing space from the 
> current line before going back to the left margin. Is anyone acquainted 
> enough with the pywin editor to be able to help with this?
>
> Thanks,
> Chris
> -- 
> http://mail.python.org/mailman/listinfo/python-list

The key bindings are in \pythonwin\pywin\default.cfg.  The
current definition is

Ctrl+Enter= ProcessEnter

(same as a normal enter).
ProcessEnterEvent in \pythonwin\pywin\framework\interact.py
checks whether the shift or ctrl keys were used.

   Roger



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


Re: passing object between classes

2009-09-22 Thread Duncan Booth
daved170  wrote:

> Is there any existing python Log object that do so?

There is. See Jean-Michel Pichavant's reply.

> I no, I created my
> own Log object that only open file and write a line to it,

> how can I make it be global?

You could assign it to a global name.

> Should I use it as a static object?

If you wish. It depends on exactly what you want. Usually static
objects are fine for logging unless you want to be able to modify the
logging in particular situations (e.g. when running your unit tests). In 
that case you could just assign it to an attribute of your object much as 
you were failing to do in your original post: there is no reason at all why 
that shouldn't work also. 

> will it work?

There is no reason why not.

> (offcurse in the case of the threads I'll use utex)

With the built-in logging module you don't need to worry about that.

-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a pure Python chart drawing module

2009-09-22 Thread Nick Craig-Wood
John Nagle  wrote:
>  I'm looking for something that can draw simple bar and pie charts
>  in Python.  I'm trying to find a Python package, not a wrapper for
>  some C library, as this has to run on both Windows and Linux
>  and version clashes are a problem.
> 
>  Here's the list from the Python wiki at
>  "http://wiki.python.org/moin/NumericAndScientific/Plotting";.
>  Almost all the options are really wrappers for some other
>  package in C/C++.
[snip]
>  So, for pure Python, Pychart is it.  I'll have to try it and see if it still
>  works.

I don't think anyone has mentioned reportlab...  It can plot charts I
think, though last time I used it I plotted stuff by hand as I wanted
exact control over the layout.

I'm not sure of the dependencies though so may not be suitable for
your purposes.

http://www.reportlab.org/rl_toolkit.html

-- 
Nick Craig-Wood  -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-22 Thread Tim Chase

daggerdvm wrote:

what are you retarded?  this is not a test you moron, i can ask all
the questions i want about it.


You seem to have forgotten to CC the list.   Let me help show the 
world your "mad skillz" -- at replying, at programming, at 
orthography, at interpersonal communication...


Sure you can ask all the questions you want...and the newsgroup 
can give all the answers it sees fit.  In all likelihood, your 
professor wanted *you* to solve the problem, not have 
comp.lang.python solve the problem for you.  You got at least two 
answers that "solve" the problem, but were designed to clearly 
indicated to the professor that you didn't author them yourself.


From my experience teaching students to program, that's the sort 
of problem that 4th or 5th graders (who have been paying 
attention in class) should be able to do with no need to ask for 
help.


Given that you made *no* effort (your post had *zero* code to 
show you had even attempted the problem), you got back far more 
than you put in.


-tkc




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


Re: recommendation for webapp testing?

2009-09-22 Thread Ryan Kelly

> >I need to do some basic website testing (log into account, add item to
> >cart, fill out and submit forms, check out, etc.). What modules would
> >be good to use for webapp testing like this?
> 
> Windmill is an option, but I haven't tried it myself

I'll second Windmill as an option, have had good experiences with it.
The current version is a little on the slow side, but I believe there's
a big new release just around the corner that contains significant
performance improvements.

   Ryan

-- 
Ryan Kelly
http://www.rfk.id.au  |  This message is digitally signed. Please visit
[email protected]|  http://www.rfk.id.au/ramblings/gpg/ for details



signature.asc
Description: This is a digitally signed message part
-- 
http://mail.python.org/mailman/listinfo/python-list


difficulty in understanding rsplit(None,1)[1]

2009-09-22 Thread hrishy
Hi

What does rsplit(None,1)[1] accomplish.

Can somebody please decompose that to me.

regards



  

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


Re: easy question, how to double a variable

2009-09-22 Thread daggerdvm
you brain needs error checking!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-22 Thread Andreas Waldenburger
On Mon, 21 Sep 2009 13:46:31 -0700 (PDT) daggerdvm
 wrote:

> u don't want to answerthen why post?...get lost.

You're not doing yourself a favor with this attitude, much less
displaying it. You asked a question that you could have solved with 1
hour's worth of reading at most (much less if you're actually attending
some sort of class for this).

I'm not saying you deserve to be mocked, but it is a fact of life that
you get these responses when it is apparent that you put almost no
effort into this problem.

Here's a tip: post to the group your code that you came up with
yourself and explain what gives you trouble. I assure you, the
responses will be more helpful that way.

/W

-- 
INVALID? DE!

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


problem in encryption

2009-09-22 Thread jayshree
hello ,
The community members,

Using following code  :

fileHandle = open ('jay1key.py','wb')
#fileHandle = open ('jay1key.pem',rb).read()
print fileHandle.write (data) #data variable is contains the key
fileHandle.close()


otp = 'jyshri69'


pub_key = M2Crypto.RSA.load_pub_key('jay1key.py')

encrypted = pub_key.public_encrypt(otp, M2Crypto.RSA.pkcs1_padding)
print "encrypted text is =   "
print "---"
print encrypted

the above code gives me following error :
None
Traceback (most recent call last):
  File "RetEnc.py", line 71, in ?
pub_key = M2Crypto.RSA.load_pub_key('jay1key.py')
  File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 344,
in load_pub_key
return load_pub_key_bio(bio)
  File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 360,
in load_pub_key_bio
rsa_error()
  File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 240,
in rsa_error
raise RSAError, m2.err_reason_error_string(m2.err_get_error())
M2Crypto.RSA.RSAError: no start line


not getting how to resolve it ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem in encryption

2009-09-22 Thread jayshree
On Sep 22, 1:44 pm, jayshree  wrote:
> hello ,
> The community members,
>
> Using following code  :
>
> fileHandle = open ('jay1key.py','wb')
> #fileHandle = open ('jay1key.pem',rb).read()
> print fileHandle.write (data) #data variable is contains the key
> fileHandle.close()
>
> otp = 'jyshri69'
>
> pub_key = M2Crypto.RSA.load_pub_key('jay1key.py')
>
> encrypted = pub_key.public_encrypt(otp, M2Crypto.RSA.pkcs1_padding)
> print "encrypted text is =   "
> print "---"
> print encrypted
>
> the above code gives me following error :
> None
> Traceback (most recent call last):
>   File "RetEnc.py", line 71, in ?
>     pub_key = M2Crypto.RSA.load_pub_key('jay1key.py')
>   File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 344,
> in load_pub_key
>     return load_pub_key_bio(bio)
>   File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 360,
> in load_pub_key_bio
>     rsa_error()
>   File "/usr/lib/python2.4/site-packages/M2Crypto/RSA.py", line 240,
> in rsa_error
>     raise RSAError, m2.err_reason_error_string(m2.err_get_error())
> M2Crypto.RSA.RSAError: no start line
>
> not getting how to resolve it ?

the key looks like this :
-BEGIN RSA PUBLIC KEY-
mQGiBEpz7VIRBADAt9YpYfYHJeGA6d
+G261FHW1uA0YXltCWa7TL6JnIsuxvh9vImUoyMJd6
1xEW4TuROTxGcMMiDemQq6HfV9tLi7ptVBLf/8nUEFoGhxS
+DPJsy46WmlscKHRIEdIkTYhp
uAIMim0q5HWymEqqAfBLwJTOY9sR+nelh0NKepcCqwCgvenJ2R5UgmAh
+sOhIBrh3OahZEED
/2sRGHi4xRWKePFpttXfb2hry2/jURPae/wYfuI6Xw3k5EO593veGS7Zyjnt+7mVY1N5V/
ey
rfXaS3R6GsByG/eRVzRJGU2DSQvmF+q2NC6v2s4KSzr5CVKpn586SGUSg/
aKvXY3EIrpvAGP
rHum1wt6P9m9kr/4X8SdVhj7Jti6A/0TA8C2KYhOn/
hSYAMTmhisHan3g2Cm6yNzKeTiq6/0
ooG/
ffcY81zC6+Kw236VGy2bLrMLkboXPuecvaRfz14gJA9SGyInIGQcd78BrX8KZDUpF1Ek
KxQqL97YRMQevYV89uQADKT1rDBJPNZ+o9f59WT04tClphk/
quvMMuSVILQaamF5c2ggPGph
eXNocmVlQGdtYWlsLmNvbT6IZgQTEQIAJgUCSnPtUgIbAwUJAAFRgAYLCQgHAwIEFQIIAwQW
AgMBAh4BAheAAAoJEFjpOQ2vjFvzS0wAn3vf1A8npIY/DMIFFw0/
eGf0FNekAKCBJnub9GVu
9OUY0nISQf7uZZVyI7kBDQRKc+1SEAQAm7Pink6S5+kfHeUoJVldb
+VAlHdf7BdvKjVeiKAb
dFUa6vR9az+wn8V5asNy/
npEAYnHG2nVFpR8DTlN0eO35p78qXkuWkkpNocLIB3bFwkOCbff
P3yaCZp27Vq+9182bAR2Ah10T1KShjWTS/
wfRpSVECYUGUMSh4bJTnbDA2MAAwUEAIcRhF9N
OxAsOezkiZBm+tG4BgT0+uWchY7fItJdEqrdrROuCFqWkJLY2uTbhtZ5RMceFAW3s
+IYDHLL
PwM1O+ZojhvAkGwLyC4F
+6RCE62mscvDJQsdwS4L25CaG2Aw97HhY7+bG00TWqGLb9JibKie
X1Lk+W8Sde/4UK3Q8tpbiE8EGBECAA8FAkpz7VICGwwFCQABUYAACgkQWOk5Da+MW/
MAAgCg
tfUKLOsrFjmyFu7biv7ZwVfejaMAn1QXEJw6hpvte60WZrL0CpS60A6Q
-END RSA PUBLIC KEY-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: difficulty in understanding rsplit(None,1)[1]

2009-09-22 Thread Martin P. Hellwig

hrishy wrote:

Hi

What does rsplit(None,1)[1] accomplish.

Can somebody please decompose that to me.

regards


Sure:

>>> test = 'This is a test'
>>> help(test.rsplit)
Help on built-in function rsplit:

rsplit(...)
S.rsplit([sep [,maxsplit]]) -> list of strings

Return a list of the words in the string S, using sep as the
delimiter string, starting at the end of the string and working
to the front.  If maxsplit is given, at most maxsplit splits are
done. If sep is not specified or is None, any whitespace string
is a separator.

>>> step_two = test.rsplit(None, 1)
>>> step_two
['This is a', 'test']
>>>
>>> step_two[1]
'test'
>>>

--
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'
--
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-22 Thread Donn
On Monday 21 September 2009 22:49:50 daggerdvm wrote:
> you brain needs error checking!
try:
 return response()
except Troll,e:
 raise dontFeed(anymore=True)

\d
-- 
home: http://otherwise.relics.co.za/
2D vector animation : https://savannah.nongnu.org/projects/things/
Font manager : https://savannah.nongnu.org/projects/fontypython/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: difficulty in understanding rsplit(None,1)[1]

2009-09-22 Thread hrishy
Hi Martin

Many thanks 
And by the way great way to explain that thing

--- On Tue, 22/9/09, Martin P. Hellwig  wrote:

> From: Martin P. Hellwig 
> Subject: Re: difficulty in understanding rsplit(None,1)[1]
> To: [email protected]
> Date: Tuesday, 22 September, 2009, 9:52 AM
> hrishy wrote:
> > Hi
> > 
> > What does rsplit(None,1)[1] accomplish.
> > 
> > Can somebody please decompose that to me.
> > 
> > regards
> > 
> Sure:
> 
> >>> test = 'This is a test'
> >>> help(test.rsplit)
> Help on built-in function rsplit:
> 
> rsplit(...)
>     S.rsplit([sep [,maxsplit]]) -> list of
> strings
> 
>     Return a list of the words in the string S,
> using sep as the
>     delimiter string, starting at the end of the
> string and working
>     to the front.  If maxsplit is given, at
> most maxsplit splits are
>     done. If sep is not specified or is None, any
> whitespace string
>     is a separator.
> 
> >>> step_two = test.rsplit(None, 1)
> >>> step_two
> ['This is a', 'test']
> >>>
> >>> step_two[1]
> 'test'
> >>>
> 
> -- MPH
> http://blog.dcuktec.com
> 'If consumed, best digested with added seasoning to own
> preference.'
> -- http://mail.python.org/mailman/listinfo/python-list
> 


  

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


Re: entry widget won't validate

2009-09-22 Thread Peter Otten
Mike wrote:

> On Sep 21, 12:47 pm, Peter Otten <[email protected]> wrote:
>> Mike wrote:
>> > I'm trying to arrange for an Entry widget to check whether its data
>> > is all digits and whether the number represented is small enough.
>> > The validate function seem to be called once at startup and not
>> > afterwards:
> 
> 
>> > The print statement run 3 times at startup.
>> > Editing an Entry does not cause any printing.
>> > Any ideas?
>>
>> Quotinghttp://www.tcl.tk/man/tcl8.5/TkCmd/entry.htm#M12:
>>
>> """
>> In general, the textVariable and validateCommand can be dangerous to mix.
>> Any problems have been overcome so that using the validateCommand will
>> not interfere with the traditional behavior of the entry widget. Using
>> the textVariable for read-only purposes will never cause problems. The
>> danger comes when you try set the textVariable to something that the
>> validateCommand would not accept, which causes validate to become none
>> (the invalidCommand will not be triggered). The same happens when an
>> error occurs evaluating the validateCommand.
>> """
>>
>> You can verify that this is indeed your problem by changing the
>> Levels.vc() method to always return True for the moment.
> 
> Returning True does seems to cause vc to be called more often.
> I'm still not getting the data I want though.
> The variable always gives me the pre-change string.
> I gather I need to do something with "%P".
> google gave me hints that I should use something called "register",
> but I'm not at all clear on what I should do with them.
> I don't know how to translate from Tcl to python.

I don't know Tcl either; the following is the first thing that seemed to 
work, after some trial and error:

import Tkinter as tk

def validate(before, after):
print before, "-->", after
return after.isdigit()

if __name__ == "__main__":
root = tk.Tk()
name = root.register(validate)
cmd = 'expr {[%(name)s %(parms)s]}' % dict(name=name, parms="%s %P")
var = tk.StringVar()
entry = tk.Entry(root, textvariable=var,
 validate="all", validatecommand=cmd)
entry.pack()
entry.focus_set()
root.mainloop()

Peter

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


Combining sets/dictionaries

2009-09-22 Thread Alfons Nonell-Canals
Hello,
I have different sets/dictionaries/lists (whatever you want because I
can convert them easily) and I would like to combine them. I don't want
a consensus and something like it. I'd need to combine all elements of
the first one with the all elements of the second one and third,... the
numbers of dictionaries/sets/lists is variable as the number of elements
for each one.

For example, i have the following sets and I would like to obtain all
possible combinations...

['I', 'O', 'N', 'P', 'S', 'C']
['I', 'O', 'N', 'P', 'S', 'C']
['I', 'O', 'N', 'P', 'S', 'C']
['I', 'N', 'P', 'S', 'C']
['I', 'N', 'P', 'S', 'C']
['F', 'I', 'L', 'O', 'N', 'P', 'S', 'R', 'C']
['I', 'O', 'N', 'P', 'S', 'C']
['I', 'O', 'N', 'P', 'S', 'C']
['F', 'I', 'L', 'O', 'N', 'P', 'S', 'R', 'C']

And it should be flexible because as I've said, the number of
dictionaries/lists/sets is not always the same, as the number of elements.

I don't like to ask this kid of questions but... today I'm totally lost
and I need it to close one part of a nice project...

Thanks in advance!

Best regards,
Alfons.





-- 

Alfons Nonell-Canals, PhD
Chemogenomics Lab
Research Group on Biomedical Informatics (GRIB) - IMIM/UPF
Barcelona Biomedical Research Park (PRBB)
C/ Doctor Aiguader, 88 - 08003 Barcelona 
[email protected] - http://cgl.imim.es
Tel. +34933160528
 
http://alfons.elmeuportal.cat
http://www.selenocisteina.info

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


Re: Combining sets/dictionaries

2009-09-22 Thread Peter Otten
Alfons Nonell-Canals wrote:

> I have different sets/dictionaries/lists (whatever you want because I
> can convert them easily) and I would like to combine them. I don't want
> a consensus and something like it. I'd need to combine all elements of
> the first one with the all elements of the second one and third,... the
> numbers of dictionaries/sets/lists is variable as the number of elements
> for each one.
> 
> For example, i have the following sets and I would like to obtain all
> possible combinations...
> 
> ['I', 'O', 'N', 'P', 'S', 'C']
> ['I', 'O', 'N', 'P', 'S', 'C']
> ['I', 'O', 'N', 'P', 'S', 'C']
> ['I', 'N', 'P', 'S', 'C']
> ['I', 'N', 'P', 'S', 'C']
> ['F', 'I', 'L', 'O', 'N', 'P', 'S', 'R', 'C']
> ['I', 'O', 'N', 'P', 'S', 'C']
> ['I', 'O', 'N', 'P', 'S', 'C']
> ['F', 'I', 'L', 'O', 'N', 'P', 'S', 'R', 'C']
> 
> And it should be flexible because as I've said, the number of
> dictionaries/lists/sets is not always the same, as the number of elements.
> 
> I don't like to ask this kid of questions but... today I'm totally lost
> and I need it to close one part of a nice project...

Using one common definition of "combinations":

>>> from pprint import pprint
>>> pprint(items)
[['I', 'O', 'N', 'P', 'S', 'C'],
 ['I', 'O', 'N', 'P', 'S', 'C'],
 ['I', 'O', 'N', 'P', 'S', 'C'],
 ['I', 'N', 'P', 'S', 'C'],
 ['I', 'N', 'P', 'S', 'C'],
 ['F', 'I', 'L', 'O', 'N', 'P', 'S', 'R', 'C'],
 ['I', 'O', 'N', 'P', 'S', 'C'],
 ['I', 'O', 'N', 'P', 'S', 'C'],
 ['F', 'I', 'L', 'O', 'N', 'P', 'S', 'R', 'C']]
>>> import itertools
>>> for c in itertools.combinations(items, 2):
... print c
...
(['I', 'O', 'N', 'P', 'S', 'C'], ['I', 'O', 'N', 'P', 'S', 'C'])
(['I', 'O', 'N', 'P', 'S', 'C'], ['I', 'O', 'N', 'P', 'S', 'C'])
(['I', 'O', 'N', 'P', 'S', 'C'], ['I', 'N', 'P', 'S', 'C'])
(['I', 'O', 'N', 'P', 'S', 'C'], ['I', 'N', 'P', 'S', 'C'])


If you mean something else (likely) please give a more detailed description 
or provide some examples with both input and desired output.

Peter

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


Re: easy question, how to double a variable

2009-09-22 Thread koranthala
On Sep 21, 1:27 am, daggerdvm  wrote:
>  Write the definition of a function  twice , that receives an  int
> parameter and returns an  int that is twice the value of the
> parameter.
>
> how can i do this

Please note that most mails here are humorous - as should be expected
for a language named after Monty Python.
So, please do not get angry and do take it the way it was intended.

The main problem that everybody sees is that the code you asked is
extremely simple. This causes others to think that you have not
invested any time in getting a solution yourself. Most of us here are
>30 years old, and we know from experience that if one does not invest
time and energy in solving issues when we are young, it eventually
leads us to a very unrewarding and unhappy life in the end.

So, even though it looks to you that people are mocking you, it is not
exactly the case. If you do try to get a solution and is unable to do
so, then I am 100% sure that many many people would have provided you
the answer or the way to do so.

Also, since you are young (presumably), it would be good to understand
that if you get it into a flamewar (email or in life), it tends to end
bad for you in the end. Esp, MRAB, Carl Banks, Steven D'Aprano, Tim
Chase etc , whom you flamed, are amongst the most respected people in
this group.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter - Text - bullets

2009-09-22 Thread eb303
On Sep 22, 7:45 am, Thomas Lehmann  wrote:
> > This is probably why you had all these alignment problems. But it's
> > weird, because the script I posted is copied and pasted from a really
> > script that I've run, and which doesn't cause any error. What is the
> > version of tcl/tk used by your Tkinter module? And what is your Python
> > version?
>
> Using python 2.5 (with Tcl/Tk 8.4):
>
> Traceback (most recent call last):
>   File "Text1.py", line 10, in 
> txt.tag_configure('bulleted_list', font=('Times', 18),
> lmargin1='10m', lmargin2='15m', tabs=['15m'])
>   File "E:\Python25\lib\lib-tk\Tkinter.py", line 3066, in
> tag_configure
> return self._configure(('tag', 'configure', tagName), cnf, kw)
>   File "E:\Python25\lib\lib-tk\Tkinter.py", line 1188, in _configure
> self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
> _tkinter.TclError: bad screen distance "['15m']"

Try tabs='15m' instead. Seems the list is not handled properly.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: socket send O(N**2) complexity

2009-09-22 Thread Antoine Pitrou
 twistedmatrix.com> writes:
> 
> To the OP, you can get view-like behavior with the "buffer" builtin. 

And, on Python 3 (or even the 2.7 in development), you can use the "memoryview"
builtin for similar effect.

Regards

Antoine.


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


Re: Combining sets/dictionaries

2009-09-22 Thread Adrien
Hi,

Did you try the list.update() builtin function ?

Regards

Peter Otten a écrit :
> Alfons Nonell-Canals wrote:
> 
>> I have different sets/dictionaries/lists (whatever you want because I
>> can convert them easily) and I would like to combine them. I don't want
>> a consensus and something like it. I'd need to combine all elements of
>> the first one with the all elements of the second one and third,... the
>> numbers of dictionaries/sets/lists is variable as the number of elements
>> for each one.
>>
>> For example, i have the following sets and I would like to obtain all
>> possible combinations...
>>
>> ['I', 'O', 'N', 'P', 'S', 'C']
>> ['I', 'O', 'N', 'P', 'S', 'C']
>> ['I', 'O', 'N', 'P', 'S', 'C']
>> ['I', 'N', 'P', 'S', 'C']
>> ['I', 'N', 'P', 'S', 'C']
>> ['F', 'I', 'L', 'O', 'N', 'P', 'S', 'R', 'C']
>> ['I', 'O', 'N', 'P', 'S', 'C']
>> ['I', 'O', 'N', 'P', 'S', 'C']
>> ['F', 'I', 'L', 'O', 'N', 'P', 'S', 'R', 'C']
>>
>> And it should be flexible because as I've said, the number of
>> dictionaries/lists/sets is not always the same, as the number of elements.
>>
>> I don't like to ask this kid of questions but... today I'm totally lost
>> and I need it to close one part of a nice project...
> 
> Using one common definition of "combinations":
> 
 from pprint import pprint
 pprint(items)
> [['I', 'O', 'N', 'P', 'S', 'C'],
>  ['I', 'O', 'N', 'P', 'S', 'C'],
>  ['I', 'O', 'N', 'P', 'S', 'C'],
>  ['I', 'N', 'P', 'S', 'C'],
>  ['I', 'N', 'P', 'S', 'C'],
>  ['F', 'I', 'L', 'O', 'N', 'P', 'S', 'R', 'C'],
>  ['I', 'O', 'N', 'P', 'S', 'C'],
>  ['I', 'O', 'N', 'P', 'S', 'C'],
>  ['F', 'I', 'L', 'O', 'N', 'P', 'S', 'R', 'C']]
 import itertools
 for c in itertools.combinations(items, 2):
> ... print c
> ...
> (['I', 'O', 'N', 'P', 'S', 'C'], ['I', 'O', 'N', 'P', 'S', 'C'])
> (['I', 'O', 'N', 'P', 'S', 'C'], ['I', 'O', 'N', 'P', 'S', 'C'])
> (['I', 'O', 'N', 'P', 'S', 'C'], ['I', 'N', 'P', 'S', 'C'])
> (['I', 'O', 'N', 'P', 'S', 'C'], ['I', 'N', 'P', 'S', 'C'])
> 
> 
> If you mean something else (likely) please give a more detailed description 
> or provide some examples with both input and desired output.
> 
> Peter
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-22 Thread Mel
Tim Roberts wrote:

> daggerdvm  wrote:
>>
>>carl banks.you are a dork
> 
> What are you, eleven years old?
> 
> Look, you asked us to answer for you what is CLEARLY a homework question.
> It is unethical for you to ask that, and it is unethical for us to answer
> it.

Forget ethical.  We can do his homework for him, we can perhaps pass exams 
for him, maybe graduate for him, and then with our luck, he'll get a job in 
our office and we get to do his work for him.

Mel.


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


Re: Combining sets/dictionaries

2009-09-22 Thread Mel
Alfons Nonell-Canals wrote:

> Hello,
> I have different sets/dictionaries/lists (whatever you want because I
> can convert them easily) and I would like to combine them. I don't want
> a consensus and something like it. I'd need to combine all elements of
> the first one with the all elements of the second one and third,... the
> numbers of dictionaries/sets/lists is variable as the number of elements
> for each one.
> 
> For example, i have the following sets and I would like to obtain all
> possible combinations...
> 
> ['I', 'O', 'N', 'P', 'S', 'C']
> ['I', 'O', 'N', 'P', 'S', 'C']
> ['I', 'O', 'N', 'P', 'S', 'C']
> ['I', 'N', 'P', 'S', 'C']
> ['I', 'N', 'P', 'S', 'C']
> ['F', 'I', 'L', 'O', 'N', 'P', 'S', 'R', 'C']
> ['I', 'O', 'N', 'P', 'S', 'C']
> ['I', 'O', 'N', 'P', 'S', 'C']
> ['F', 'I', 'L', 'O', 'N', 'P', 'S', 'R', 'C']
> 
> And it should be flexible because as I've said, the number of
> dictionaries/lists/sets is not always the same, as the number of elements.
> 
> I don't like to ask this kid of questions but... today I'm totally lost
> and I need it to close one part of a nice project...

Maybe a recursive function or generator:

Each item from the first list appended to each of the possible combinations 
from the second through nth lists.

Mel.



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


Re: Not this one the other one, from a dictionary

2009-09-22 Thread Sion Arrowsmith
Vlastimil Brom   wrote:
 other_key = (set(data_dict.iterkeys()) - set([not_wanted_key,])).pop()

other_key = set(data_dict.iterkeys()).difference([not_wanted]).pop()
saves you the construction of an unnecessary set instance. At the
cost of a bit more verbosity, you can get rid of a second set:

key_set = set(data_dict.iterkeys())
key_set.difference_update([not_wanted_key])
other_key = key_set.pop()

although the loss of clarity compared to the one liner can't be
worth the miniscule benefit in this case.

-- 
\S

   under construction

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


Re: easy question, how to double a variable

2009-09-22 Thread Ben Finney
Mel  writes:

> Tim Roberts wrote:
> > Look, you asked us to answer for you what is CLEARLY a homework
> > question. It is unethical for you to ask that, and it is unethical
> > for us to answer it.
>
> Forget ethical. We can do his homework for him, we can perhaps pass
> exams for him, maybe graduate for him, and then with our luck, he'll
> get a job in our office and we get to do his work for him.

+1 QOTW

-- 
 \   “Special today: no ice cream.” —mountain inn, Switzerland |
  `\   |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem in encryption

2009-09-22 Thread Piet van Oostrum
> jayshree  (j) wrote:

>j> hello ,
>j> The community members,

>j> Using following code  :

>j> fileHandle = open ('jay1key.py','wb')
>j> #fileHandle = open ('jay1key.pem',rb).read()
>j> print fileHandle.write (data) #data variable is contains the key
>j> fileHandle.close()


>j> otp = 'jyshri69'


>j> pub_key = M2Crypto.RSA.load_pub_key('jay1key.py')

[Why do you give your key file a .py extension? .pem would be better.]

Your key in the next posting (when the broken lines are reconstructed)
seems to be in PKCS1 format. That's what -BEGIN RSA PUBLIC KEY-
indicates. However,  M2Crypto.RSA.load_pub_key expects the key in X.509
format, which starts with -BEGIN PUBLIC KEY- and also has a
different format inside, so just changing the header and trailer won't
work. 

Anyway, I doubt that the key is correct as it seems to large for just a
public key. How was that key generated?
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: [email protected]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Substitute for KConfig in Qt4

2009-09-22 Thread David Boddie
On Sat Sep 19 12:18:40 CEST 2009, nusch wrote:
> On Sep 19, 3:53 am, David Boddie  wrote:
> > On Thursday 17 September 2009 13:04, nusch wrote:
> > > I want to remove pyKDE dependencies from my app to make it pure PyQt.
> > > What will be the best substitute for KConfig?
> >
> > What exactly do you use KConfig for in your application?
> >
> > David
>
> e.g storing dock window positions, fields choosen in QComboBox etc.
> But I Dont want to use normal config files for it

Then you would use QSettings. Although that may use configuration files
behind the scenes, they should at least be stored in a standard place.

http://www.riverbankcomputing.com/static/Docs/PyQt4/html/qsettings.html

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


Re: Combining sets/dictionaries

2009-09-22 Thread Carl Banks
On Sep 22, 3:08 am, Alfons Nonell-Canals 
wrote:
> Hello,
> I have different sets/dictionaries/lists (whatever you want because I
> can convert them easily) and I would like to combine them. I don't want
> a consensus and something like it. I'd need to combine all elements of
> the first one with the all elements of the second one and third,... the
> numbers of dictionaries/sets/lists is variable as the number of elements
> for each one.
>
> For example, i have the following sets and I would like to obtain all
> possible combinations...
>
> ['I', 'O', 'N', 'P', 'S', 'C']
> ['I', 'O', 'N', 'P', 'S', 'C']
> ['I', 'O', 'N', 'P', 'S', 'C']
> ['I', 'N', 'P', 'S', 'C']
> ['I', 'N', 'P', 'S', 'C']
> ['F', 'I', 'L', 'O', 'N', 'P', 'S', 'R', 'C']
> ['I', 'O', 'N', 'P', 'S', 'C']
> ['I', 'O', 'N', 'P', 'S', 'C']
> ['F', 'I', 'L', 'O', 'N', 'P', 'S', 'R', 'C']

This is the input.  What do you want the output to look like given
this input?

I can't really tell exactly what you mean by "all combinations", there
are different ways to combine sequences, and it doesn't sound like you
mean the formal mathematical definition of "combination".

My best guess is that you want something like this.

def all_union(seqs):
s = set()
for seq in seqs:
s.update(seq)
return s


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


Re: easy question, how to double a variable

2009-09-22 Thread Mahmoud Abdelkader
http://codingforums.com/showthread.php?s=e26b8b0aabc69745ef24a855b1a0fc83&t=177529

It seems that this dude really is looking for how to double a variable...

"""
hi looking for help catching up in a class and overall to get me better than
i am now. I can pay you by the week or per hour.

everything can be done by email i will ask you questions and send you simple
questions like:

how to double a variables value i.e: def double(x):
return (x * 2)

ect. you can post here or send me an email at ***[email protected]
"""

On Tue, Sep 22, 2009 at 9:01 AM, Mel  wrote:

> Tim Roberts wrote:
>
> > daggerdvm  wrote:
> >>
> >>carl banks.you are a dork
> >
> > What are you, eleven years old?
> >
> > Look, you asked us to answer for you what is CLEARLY a homework question.
> > It is unethical for you to ask that, and it is unethical for us to answer
> > it.
>
> Forget ethical.  We can do his homework for him, we can perhaps pass exams
> for him, maybe graduate for him, and then with our luck, he'll get a job in
> our office and we get to do his work for him.
>
>Mel.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-22 Thread Grant Edwards
On 2009-09-22, Mel  wrote:
> Tim Roberts wrote:
>
>> daggerdvm  wrote:
>>>
>>>carl banks.you are a dork
>> 
>> What are you, eleven years old?
>> 
>> Look, you asked us to answer for you what is CLEARLY a homework question.
>> It is unethical for you to ask that, and it is unethical for us to answer
>> it.
>
> Forget ethical.  We can do his homework for him, we can perhaps pass exams 
> for him, maybe graduate for him, and then with our luck, he'll get a job in 
> our office and we get to do his work for him.

No, no, no.  The plan is to do his homework for him so that
he's incompetent when he graduates and won't be competition for
the rest of us who did do our homework.

-- 
Grant Edwards   grante Yow! ... the HIGHWAY is
  at   made out of LIME JELLO and
   visi.commy HONDA is a barbequeued
   OYSTER!  Yum!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Combining sets/dictionaries

2009-09-22 Thread Alfons Nonell-Canals
Hello,
finally I've solved it using a "combinatorics" library which allows to
do this kind of things.

Here, here is an example:

   
http://automatthias.wordpress.com/2007/04/28/cartesian-product-of-multiple-sets/


Thanks for your suggestions.


Regards,
Alfons.

Carl Banks wrote:
> On Sep 22, 3:08 am, Alfons Nonell-Canals 
> wrote:
>   
>> Hello,
>> I have different sets/dictionaries/lists (whatever you want because I
>> can convert them easily) and I would like to combine them. I don't want
>> a consensus and something like it. I'd need to combine all elements of
>> the first one with the all elements of the second one and third,... the
>> numbers of dictionaries/sets/lists is variable as the number of elements
>> for each one.
>>
>> For example, i have the following sets and I would like to obtain all
>> possible combinations...
>>
>> ['I', 'O', 'N', 'P', 'S', 'C']
>> ['I', 'O', 'N', 'P', 'S', 'C']
>> ['I', 'O', 'N', 'P', 'S', 'C']
>> ['I', 'N', 'P', 'S', 'C']
>> ['I', 'N', 'P', 'S', 'C']
>> ['F', 'I', 'L', 'O', 'N', 'P', 'S', 'R', 'C']
>> ['I', 'O', 'N', 'P', 'S', 'C']
>> ['I', 'O', 'N', 'P', 'S', 'C']
>> ['F', 'I', 'L', 'O', 'N', 'P', 'S', 'R', 'C']
>> 
>
> This is the input.  What do you want the output to look like given
> this input?
>
> I can't really tell exactly what you mean by "all combinations", there
> are different ways to combine sequences, and it doesn't sound like you
> mean the formal mathematical definition of "combination".
>
> My best guess is that you want something like this.
>
> def all_union(seqs):
> s = set()
> for seq in seqs:
> s.update(seq)
> return s
>
>
> Carl Banks
>   

-- 

Alfons Nonell-Canals, PhD
Chemogenomics Lab
Research Group on Biomedical Informatics (GRIB) - IMIM/UPF
Barcelona Biomedical Research Park (PRBB)
C/ Doctor Aiguader, 88 - 08003 Barcelona 
[email protected] - http://cgl.imim.es
Tel. +34933160528
 
http://alfons.elmeuportal.cat
http://www.selenocisteina.info

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


Re: Finding application data after install - a solution?

2009-09-22 Thread Aahz
In article ,
Wolodja Wentland   wrote:
>
>I want to:
>
>1. Give administrators the freedom to install the data wherever they
>   want
>2. Adhere to the FHS (installing data within modules breaks it)
>3. Be able to find that data again regardless of the installation
>  scheme used
>
>1 and 2 are easily solved... It was just not possible to find the data
>again. The snippet in the original code solves that.

Given your mention of FHS, it sounds like you are focused on Unix-like
systems, in which case why not rely on the standard mechanisms for config
files?
-- 
Aahz ([email protected])   <*> http://www.pythoncraft.com/

"I won't accept a model of the universe in which free will, omniscient
gods, and atheism are simultaneously true."  --M
-- 
http://mail.python.org/mailman/listinfo/python-list


Dynamic Form

2009-09-22 Thread Victor Subervi
Hi;
I have a dynamic form in which I do the following:
1) Request two fields (company name, number of entries). That is sent back
to the form.
2) If the two fields are not None, the form requests other data. That, too,
is sent back to the form.
3) That new data is then entered into a MySQL table.
The problem is, that when I go back to refresh the form, the data is
re-entered into the table! How do I prevent that?
TIA,
Victor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OK to memoize re objects?

2009-09-22 Thread Hyuga
On Sep 21, 11:02 am, Nobody  wrote:
> On Mon, 21 Sep 2009 07:11:36 -0700, Ethan Furman wrote:
> > Looking in the code for re in 2.5:
> > _MAXCACHE = 100
> > On the other hand, I (a
> > re novice, to be sure) have only used between two to five in any one
> > program... it'll be a while before I hit _MAXCACHE!
>
> Do you know how many REs import-ed modules are using? The cache isn't
> reserved for __main__.

Based on this, I'd say that the best policy would be that if you only
have a handful of simple REs that are used only on occasion, it's
probably not worth using re.compile--even if they fall out of cache,
it shouldn't take a noticeable amount of time to recompile them.

If, however, these are either complex REs, or REs that are being used
very frequently, say in a loop, might as well save the compiled RE
somewhere just to be sure it doesn't have to be recompiled at any
point.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-22 Thread Hyuga
On Sep 22, 9:57 am, Grant Edwards  wrote:
> On 2009-09-22, Mel  wrote:
>
> > Tim Roberts wrote:
>
> >> daggerdvm  wrote:
>
> >>>carl banks.you are a dork
>
> >> What are you, eleven years old?
>
> >> Look, you asked us to answer for you what is CLEARLY a homework question.
> >> It is unethical for you to ask that, and it is unethical for us to answer
> >> it.
>
> > Forget ethical.  We can do his homework for him, we can perhaps pass exams
> > for him, maybe graduate for him, and then with our luck, he'll get a job in
> > our office and we get to do his work for him.
>
> No, no, no.  The plan is to do his homework for him so that
> he's incompetent when he graduates and won't be competition for
> the rest of us who did do our homework.

Well, while they may not be as much competition come promotion time, I
think Mr. Finney had it right that these people *do* still somehow get
hired, and then the rest of us end up having to do enough work for
multiple people.  Sometimes spending more time redoing other peoples'
shoddy work than it would have taken to do ourselves in the first
place.  Annoying for the programmer, but really bad for business.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamic Form

2009-09-22 Thread Simon Forman
On Tue, Sep 22, 2009 at 10:46 AM, Victor Subervi
 wrote:
> Hi;
> I have a dynamic form in which I do the following:
> 1) Request two fields (company name, number of entries). That is sent back
> to the form.
> 2) If the two fields are not None, the form requests other data. That, too,
> is sent back to the form.
> 3) That new data is then entered into a MySQL table.
> The problem is, that when I go back to refresh the form, the data is
> re-entered into the table! How do I prevent that?
> TIA,
> Victor
>

First, this seems like it's not a python question, rather it's seems
to be about some web stuff.

Second, there's not enough information to tell you anything useful.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamic Form--Potential purge cache?

2009-09-22 Thread [email protected]
Personally that sounds like the data needs to be deliberately oveerittren in 
the form. That or the cache has to be cleared by a remote instruction. 
Unfortunately I know how to do neither :[

--Original Message--
From: Simon Forman 
To: 
Date: Tue, 22 Sep 2009 11:34:25 AM -0400
Subject: Re: Dynamic Form

On Tue, Sep 22, 2009 at 10:46 AM, Victor Subervi
 wrote:
> Hi;
> I have a dynamic form in which I do the following:
> 1) Request two fields (company name, number of entries). That is sent back
> to the form.
> 2) If the two fields are not None, the form requests other data. That, too,
> is sent back to the form.
> 3) That new data is then entered into a MySQL table.
> The problem is, that when I go back to refresh the form, the data is
> re-entered into the table! How do I prevent that?
> TIA,
> Victor
>

First, this seems like it's not a python question, rather it's seems
to be about some web stuff.

Second, there's not enough information to tell you anything useful.
-- 
http://mail.python.org/mailman/listinfo/python-list

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


Module inspection by name

2009-09-22 Thread Nadav Chernin
Hi all, a have easy question for python developers.

 

Assume I have list of all objects:

 

obj=dir()

 

Now I want to know which object from "obj" list is module.

 

I searched some method in module inspection, but there is not any method
that get 'string' as parameters

 

Any reply will be greatfull  

 

Nadav

 

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


Re: Module inspection by name

2009-09-22 Thread Jean-Michel Pichavant

Nadav Chernin wrote:


Hi all, a have easy question for python developers.

Assume I have list of all objects:

obj=dir()

Now I want to know which object from “obj” list is module.

I searched some method in module inspection, but there is not any 
method that get ‘string’ as parameters


Any reply will be greatfull

Nadav



import sys
import os
name = 'os'
sys.modules[name]

will return the module itself with the string name. It should allow you 
to use the method you found using the module itself.


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


Re: Finding application data after install - a solution?

2009-09-22 Thread Wolodja Wentland
On Tue, Sep 22, 2009 at 07:42 -0700, Aahz wrote:
> >I want to:
> >
> >1. Give administrators the freedom to install the data wherever they
> >   want
> >2. Adhere to the FHS (installing data within modules breaks it)
> >3. Be able to find that data again regardless of the installation
> >  scheme used
> >
> >1 and 2 are easily solved... It was just not possible to find the data
> >again. The snippet in the original code solves that.
> Given your mention of FHS, it sounds like you are focused on Unix-like
> systems, in which case why not rely on the standard mechanisms for config
> files?

I do not intentionally focus on UNIX type systems, but I have grown up
with *nix and I rather follow one scheme than none at all. But the
proposed way works on Windows as well, although the users might find
previously unseen directories like 'PREFIX/share/foo/doc' and the like
on their system.

How to solve this platform independently? And what standard mechanisms
for config files do you mean? Are there library functions I overlooked?

But the data I am speaking about are not config files. I will explain in
more detail so you can understand the problem.

I have a library that parses markup that has a canonical form and a
localised one. 'Image:' for example is the canonical form and the one
used for English. In German the canonical form *and* a localised one is
used ('Bild:'). This scheme (localised+canonical) holds true for all
(260+) languages this markup is used in.

The library itself works fine with the canonical forms, but loads
language specific markup definitions *if they are available* . I
therefore don't want to install this data along with the library for the
following reasons:

1. The data is not needed if the user just want to work with English
   data

2. The data could change much more frequently than the library that
   works with the data.

   If I couple library and data together I would have to make a new
   release *every time* the data changes, even if the user does not
   care about the other languages.

I therefore opted to provide a seperate (Python) distribution foo-data
which contains the language specific markup definitions and install it
to '$DATA_PREFIX/share/foo/languageinfo' .

As $DATA_PREFIX is only known at build time there was (until now) no
reliable way to find the data if the only information one can get is
$LIB_PREFIX, because these two might be totally unrelated.

I hope that clarifies my point

Wolodja

P.S Which markup format am I speaking about? First one to answer gets a
brand new Internet!


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: entry widget won't validate

2009-09-22 Thread Mike
On Sep 22, 4:29 am, Peter Otten <[email protected]> wrote:
> Mike wrote:
> > On Sep 21, 12:47 pm, Peter Otten <[email protected]> wrote:
> >> Mike wrote:
> >> > I'm trying to arrange for an Entry widget to check whether its data
> >> > is all digits and whether the number represented is small enough.
> >> > The validate function seem to be called once at startup and not
> >> > afterwards:
>
> >> > The print statement run 3 times at startup.
> >> > Editing an Entry does not cause any printing.
> >> > Any ideas?

> I don't know Tcl either; the following is the first thing that seemed to
> work, after some trial and error:
>
> import Tkinter as tk
>
> def validate(before, after):
>     print before, "-->", after
>     return after.isdigit()
>
> if __name__ == "__main__":
>     root = tk.Tk()
>     name = root.register(validate)
>     cmd = 'expr {[%(name)s %(parms)s]}' % dict(name=name, parms="%s %P")
>     var = tk.StringVar()
>     entry = tk.Entry(root, textvariable=var,
>                      validate="all", validatecommand=cmd)
>     entry.pack()
>     entry.focus_set()
>     root.mainloop()

Thanks.
It worked.
I discovered that None is not an acceptable substitute for False.
If validate returns None, it quits being called.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamic Form

2009-09-22 Thread Victor Subervi
Well it's Web stuff, sure, but it's written in python :) The code follows.
The problem is that I haven't figured out how to tell the program that the
user has entered data and to clear the cache of that data so that it's not
re-entered. How do I do that?
TIA,
Victor

#!/usr/bin/python

import cgitb; cgitb.enable()
import cgi
import sys,os
sys.path.append(os.getcwd())
import MySQLdb
import re

def upload(company, num):
  form = cgi.FieldStorage()
  num = form.getfirst('num', 0)
  company = form.getfirst('company', '')
  flag = form.getfirst('flag', '')
  num = int(num)
  print "Content-Type: text/html"
  print
  print """
http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd";>
http://www.w3.org/1999/xhtml";>

.text {  font-family: Arial, Helvetica, sans-serif; font-size: 16px;
text-decoration: none; text-align: justify}

Global Solutions Group




"""
  if flag == 'yes':
host = 'hose'
db = 'db'
user = 'user'
passwd = 'pass'
database = MySQLdb.connect(host, user, passwd, db)
cursor= database.cursor()
pat = '[.,()\[\]\\+=!#$%^&;:"\'*]'
company = re.sub(pat, '', company)
sql = 'Category varchar(100), Item varchar(20), Description
varchar(255), UOM varchar(20), Price float(7,2)'
cursor.execute('create table if not exists %s (%s);' % (company, sql))
i = 0
while i < num:
  print i
  cat = 'cat' + str(i)
  cat = form.getfirst(cat, '')
  item = 'item' + str(i)
  item = form.getfirst(item, '')
  descr = 'descr' + str(i)
  descr = form.getfirst(descr, '')
  uom = 'uom' + str(i)
  uom = form.getfirst(uom, '')
  price = 'price' + str(i)
  price = form.getfirst(price, '')
  sql = 'insert into %s (Category, Item, Description, UOM, Price) values
("%s", "%s", "%s", "%s", "%s");' % (company, cat, item, descr, uom, price)
  cursor.execute(sql)
  i += 1
cursor.close()
print 'Data entered successfully.'
company = ''
num = 0
  print '\n'
  print "Company Name: \n" % (company)
  if num == 0:
  print "How many rows of products shall we include? \n"
  else:
print "\n"
print "\n" % (num)
i = 0
while i < num:
  print '\n'
  print "Category: \n" % (str(i))
  print "Item: \n" % (str(i))
  print "Description: \n" % (str(i))
  print "UOM: \n" % (str(i))
  print "Price: \n" % (str(i))
  i += 1
  print """


  



"""

upload(company='', num=0)


On Tue, Sep 22, 2009 at 11:34 AM, Simon Forman  wrote:

> On Tue, Sep 22, 2009 at 10:46 AM, Victor Subervi
>  wrote:
> > Hi;
> > I have a dynamic form in which I do the following:
> > 1) Request two fields (company name, number of entries). That is sent
> back
> > to the form.
> > 2) If the two fields are not None, the form requests other data. That,
> too,
> > is sent back to the form.
> > 3) That new data is then entered into a MySQL table.
> > The problem is, that when I go back to refresh the form, the data is
> > re-entered into the table! How do I prevent that?
> > TIA,
> > Victor
> >
>
> First, this seems like it's not a python question, rather it's seems
> to be about some web stuff.
>
> Second, there's not enough information to tell you anything useful.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Set literal confusion

2009-09-22 Thread kaoruAngel
I recently decided to implement a small project in python after being
away from the language for a while, so, in learning the language over
again, I experimented.

---
Python 3.1.1 (r311:74483, Aug 17 2009, 16:45:59) [MSC v.1500 64 bit
(AMD64)] on win32

>>> 5 in set(range(10))
True

>>> 15 in set(range(10))
False

>>> 5 in {range(10)}
False

>>> 15 in {range(10)}
False

>>> {range(10)}
{range(0, 10)}

>>> set(range(10))
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
--

After a few days of sitting on what seemed at first to be seemingly
buggy, inconsistent set-creation behaviour, I've finally decided it's
not a bug, but a misunderstanding of mine. However, that does still
leave me with one question: why does Python 3.1.1 allow me to get
caught up in my confusion while Python 3.0 (an EARLIER version) spouts
an error pointing me in the right direction? (see below for Python 3.0
behaviour)


Python 3.0 (r30:67507, Dec  3 2008, 20:14:27) [MSC v.1500 32 bit
(Intel)] on win32

>>> 5 in set(range(10))
True

>>> 15 in set(range(10))
False

>>> 5 in {range(10)}
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unhashable type: 'range'

>>> 15 in {range(10)}
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unhashable type: 'range'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-22 Thread Xavier Ho
On Tue, Sep 22, 2009 at 11:58 PM, Mahmoud Abdelkader
wrote:

> hi looking for help catching up in a class and overall to get me better
> than i am now. I can pay you by the week or per hour.
>

Wow. I'd feel guilty getting paid doing that. Sounds all too easy.

I hope he is actually learning, not just thinking that money will solve all
his problems.

Cheers,
Xav
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Not this one the other one, from a dictionary

2009-09-22 Thread Jean Daniel
Building on the answers of the others, a simple one liner, no side
effect, not the fastest I guess:

>>> d={'a': 'bob', 'b': 'stu'}
>>> set( d.keys() ).difference( [ 'a' ] ).pop()
'b'

Note the square brackets for the parameter of difference(). 'The
string 'a' and the list [ 'a' ] are both iterable but really are
different.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Set literal confusion

2009-09-22 Thread Peter Otten
kaoruAngel wrote:

> I recently decided to implement a small project in python after being
> away from the language for a while, so, in learning the language over
> again, I experimented.
> 
> ---
> Python 3.1.1 (r311:74483, Aug 17 2009, 16:45:59) [MSC v.1500 64 bit
> (AMD64)] on win32
> 
 5 in set(range(10))
> True
> 
 15 in set(range(10))
> False
> 
 5 in {range(10)}
> False
> 
 15 in {range(10)}
> False
> 
 {range(10)}
> {range(0, 10)}
> 
 set(range(10))
> {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
> --
> 
> After a few days of sitting on what seemed at first to be seemingly
> buggy, inconsistent set-creation behaviour, I've finally decided it's
> not a bug, but a misunderstanding of mine. However, that does still
> leave me with one question: why does Python 3.1.1 allow me to get
> caught up in my confusion while Python 3.0 (an EARLIER version) spouts
> an error pointing me in the right direction? (see below for Python 3.0
> behaviour)

That is probably a bug: http://bugs.python.org/issue4701

> 
> Python 3.0 (r30:67507, Dec  3 2008, 20:14:27) [MSC v.1500 32 bit
> (Intel)] on win32
> 
 5 in set(range(10))
> True
> 
 15 in set(range(10))
> False
> 
 5 in {range(10)}
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: unhashable type: 'range'
> 
 15 in {range(10)}
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: unhashable type: 'range'

My younger 3.0.1 doesn't show that behaviour:

Python 3.0.1+ (r301:69556, Apr 15 2009, 17:25:52)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> {range(10)}
{range(0, 10)}

Peter

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


Re: Set literal confusion

2009-09-22 Thread Vlastimil Brom
2009/9/22 kaoruAngel :
> I recently decided to implement a small project in python after being
> away from the language for a while, so, in learning the language over
> again, I experimented.
>
> ---
> Python 3.1.1 (r311:74483, Aug 17 2009, 16:45:59) [MSC v.1500 64 bit
> (AMD64)] on win32
>
 5 in set(range(10))
> True
>
 15 in set(range(10))
> False
>
 5 in {range(10)}
> False
>
 15 in {range(10)}
> False
>
 {range(10)}
> {range(0, 10)}
>
 set(range(10))
> {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
> --
>...
>
You might also try the set comprehension:

Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> {i for i in range(10)}
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
>>> set(range(10))
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
>>>

For these simple cases without conditions, it probably doesn't make
much difference.
The character of the single items is maybe more obvious.

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


Re: Set literal confusion

2009-09-22 Thread Peter Otten
Dennis Lee Bieber wrote:

> range() is what used to be xrange() -- an on-demand generator of
> values. You created a set containing a single generator. Try something
> like:
> 
> 5 in {list(range(10))}

No. {expr} is always a set with a single element. 

>>> {range(10)}
{range(0, 10)}

That element cannot be a list, by the way, because lists aren't hashable.

>>> {list(range(10))}
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unhashable type: 'list'

Peter

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


How can I tell if variable is defined

2009-09-22 Thread Brown, Rodrick
How could I do the following check in Python

In Perl I could do something like if ((defined($a)) { ... }

I tried if var is not None:
However this doesn't seem to work as described.

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


Re: How can I tell if variable is defined

2009-09-22 Thread Sean DiZazzo
On Sep 22, 11:03 am, "Brown, Rodrick "  wrote:
> How could I do the following check in Python
>
> In Perl I could do something like if ((defined($a)) { ... }
>
> I tried if var is not None:
> However this doesn't seem to work as described.
>
> Thanks.

try:
var
except NameError:
handle_it()

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


Re: How can I tell if variable is defined

2009-09-22 Thread Rami Chowdhury
On Tue, 22 Sep 2009 11:03:25 -0700, Brown, Rodrick   
 wrote:



How could I do the following check in Python

In Perl I could do something like if ((defined($a)) { ... }

I tried if var is not None:
However this doesn't seem to work as described.

Thanks.


Could you let us know in what context you're checking to see if a variable  
is defined? If you mean "has the name been used before", then bear in mind  
Python is a lot stricter about this kind of thing than Perl, and if you've  
never used 'var' before the if-statement, you'll probably get a NameError  
being raised.


If you want to check whether the name 'var' is bound to a meaningful  
object, however (e.g. if it's an optional argument to a function, and you  
know it exists, but don't know if it's bound to meaningful data) then your  
construction should work.



--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: How can I tell if variable is defined

2009-09-22 Thread Grant Edwards
On 2009-09-22, Brown, Rodrick  wrote:

> How could I do the following check in Python
>
> In Perl I could do something like if ((defined($a)) { ... }

try:
yourNameHere
except NameError:
print "undefined"
else:
print "defined"

> I tried if var is not None:
> However this doesn't seem to work as described.

As described where?

-- 
Grant Edwards   grante Yow! I feel like a wet
  at   parking meter on Darvon!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Substitute for KConfig in Qt4

2009-09-22 Thread nusch
On Sep 22, 3:43 pm, David Boddie  wrote:
> On Sat Sep 19 12:18:40 CEST 2009, nusch wrote:
>
> > On Sep 19, 3:53 am, David Boddie  wrote:
> > > On Thursday 17 September 2009 13:04, nusch wrote:
> > > > I want to remove pyKDE dependencies from my app to make it pure PyQt.
> > > > What will be the best substitute for KConfig?
>
> > > What exactly do you use KConfig for in your application?
>
> > > David
>
> > e.g storing dock window positions, fields choosen in QComboBox etc.
> > But I Dont want to use normal config files for it
>
> Then you would use QSettings. Although that may use configuration files
> behind the scenes, they should at least be stored in a standard place.
>
> http://www.riverbankcomputing.com/static/Docs/PyQt4/html/qsettings.html
>
> David

Thanks. That's what I'm looking for
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Module inspection by name

2009-09-22 Thread Dave Angel

Jean-Michel Pichavant wrote:
Nadav 
Chernin wrote:


Hi all, a have easy question for python developers.

Assume I have list of all objects:

obj=dir()

Now I want to know which object from “obj” list is module.

I searched some method in module inspection, but there is not any 
method that get ‘string’ as parameters


Any reply will be greatfull

Nadav



import sys
import os
name = 'os'
sys.modules[name]

will return the module itself with the string name. It should allow 
you to use the method you found using the module itself.


JM



The right way to tell if an object is a module is to do isinstance(). 
But your first problem is that the return value of dir() is a list of 
strings, while you want a list of objects. I'd suggest you use globals() 
instead, which produces a dictionary of name/object pairs. Then iterate 
through the values, checking each type with isinstance().


Show us a sample of your code that doesn't work, and we'll try to show 
you how to fix it.


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


custom data warehouse in python vs. out-of-the-box ETL tool

2009-09-22 Thread snfctech
Does anyone have experience building a data warehouse in python?  Any
thoughts on custom vs using an out-of-the-box product like Talend or
Informatica?

I have an integrated system Dashboard project that I was going to
build using cross-vendor joins on existing DBs, but I keep hearing
that a data warehouse is the way to go.  e.g. I want to create orders
and order_items with relations to members (MS Access DB), products
(flat file) and employees (MySQL).

Thanks in advance for any tips.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I tell if variable is defined

2009-09-22 Thread Dave Angel

Brown, Rodrick wrote:

How could I do the following check in Python

In Perl I could do something like if ((defined($a)) { ... }

I tried if var is not None:
However this doesn't seem to work as described.

Thanks.


  

try/except

Or look up the attribute in the appropriate dictionary(ies).


def test():
   newvar = 42
   if "newvar" in locals():
   print "yes"

DaveA

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


Re: How can I tell if variable is defined

2009-09-22 Thread Mel
Grant Edwards wrote:

> On 2009-09-22, Brown, Rodrick  wrote:
> 
>> How could I do the following check in Python
>>
>> In Perl I could do something like if ((defined($a)) { ... }
> 
> try:
> yourNameHere
> except NameError:
> print "undefined"
> else:
> print "defined"

This being Python, however, it can be fooled:

Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class A():
...   def __repr__ (self):
... global b
... return b
... 
>>> a = A()
>>> try:
...   a
... except NameError:
...   print "`a` is not defined"
... 
`a` is not defined




Mel.

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


Read header and data from a binary file

2009-09-22 Thread Jose Rafael Pacheco
Hello,

I want to read from a binary file called myaudio.dat
Then I've tried the next code:

import struct
name = "myaudio.dat"
f = open(name,'rb')
f.seek(0)
chain = "< 4s 4s I 4s I 20s I I i 4s I 67s s 4s I"
s = f.read(4*1+4*1+4*1+4*1+4*1+20*1+4*1+4*1+4*1+4*1+4*1+67*1+1+4*1+4*1)
a = struct.unpack(chain, s)
header = {'identifier' : a[0],
  'cid'  : a[1],
  'clength'   : a[2],
  'hident' : a[3],
  'hcid32' : a[4],
  'hdate'  : a[5],
  'sampling' : a[6],
  'length_B'  : a[7],
  'max_cA'   : a[8],
  'max_cA1' : a[9],
  'identNOTE'  : a[10],
  'c2len'  : a[11],}

It produces:

{'length_B': 150001, 'sampling': 5, 'max_cA1': 'NOTE', 'hident': 'HEDR',
'c2len': "Normal Sustained Vowel 'A', Voice and Speech Lab., MEEI, Boston,
MA", 'hdate': 'Jul 13 11:57:41 1994', 'identNOTE': 68, 'max_cA': -44076,
'cid': 'DS16', 'hcid32': 32, 'identifier': 'FORM', 'clength': 300126}

So far when I run f.tell()
>>f.tell()
136L

The audio data length is 300126, now I need a clue to build an array with
the audio data (The Chunk SDA_), would it possible with struct?, any help ?

Thanks

The file format is:


Offset  |  Length |  Type |Contents
0   4character Identifier: "FORM"
4  4character Chunk identifier: "DS16"
8  4integer Chunk length
12  - -  Chunk data

Header 2

Offset   Length   Type   Contents
0 4 character Identifier: "HEDR" or "HDR8"
4 4 integer Chunk length (32)
8 20 character Date, e.g. "May 26 23:57:43 1995"
28 4 integer Sampling rate
32 4 integer Data length (bytes)
36 2 unsigned integer Maximum absolute value for channel A:
0x if not defined
38 2 unsigned integer Maximum absolute value for channel A:
0x if not defined

NOTE Chunk

Offset   Length   Type   Contents
0 4 character Identifier: "NOTE"
4 4 integer Chunk length
8 - character Comment string

SDA_, SD_A or SDAB Chunk
Offset Length Type Contents
0 4 character Identifier: "SDA_", "SD_B", or "SDAB"
4 4 integer Chunk length
8 - - Data
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I tell if variable is defined

2009-09-22 Thread Peter Otten
Brown, Rodrick  wrote:

> How could I do the following check in Python
> 
> In Perl I could do something like if ((defined($a)) { ... }
> 
> I tried if var is not None:
> However this doesn't seem to work as described.

But in Python this often is the most idiomatic way to check whether a 
variable was set explicitly. Example:

>>> def foo(a=None):
... if a is None:
... print "using default"
... else:
... print "using a =", a
...
>>> foo()
using default
>>> foo(42)
using a = 42

If you tell us what you are actually trying to do we can probably come up 
with a solution that is better than the literal answer

try:
   a
except NameError:
   a_is_defined = False
else:
   a_is_defined = True

Peter

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


set breakpoint in another module/file

2009-09-22 Thread Daniel
Is there a way with pdb to set a breakpoint in another module directly
using a command similar to set_trace() ? For example, I'd like to do
something like this in my source code:

import pdb
pdb.setbreak(42, "/path/to/universe.py", "name == 'hitchhiker'")

Is there a way to do (something like) that with the pdb that ships
with Python? If not, what would people think of adding an additional
function to the pdb module that would do something like the following
code (see below). My use case for this is that often I'd like to set a
breakpoint in some module that does not belong to the project I'm
working in. I rather not edit the module, which is often in site-
packages. The workaround of course is to use set_trace() to drop into
pdb and then set the breakpoint at the pdb prompt, but that's clumsy.
I've found this to be handy:


def setbreak(line=None, file=None, cond=None, temp=0, frame=None,
throw=False):
"""set a breakpoint or a given line in file with conditional

arguments:
line - line number on which to break
file - module or filename where the breakpoint should be set
cond - string with conditional expression, which (if given)
must
evaluate to true to break
temp - if true, create a temporary breakpoint

example usage:

setbreak(42, "/path/to/universe.py", "name == 'hitchhiker'")

"""
if frame is None:
frame = sys._getframe().f_back
if file is None:
file = frame.f_code.co_filename
elif not file.startswith("file:") and os.path.sep not in file:
try:
mod = __import__(file[4:], globals(), locals(),
["__file__"])
except ImportError, err:
if throw:
raise
sys.__stdout__.write("cannot set breakpoint: %s:%s : %s" %
(file, line, err))
return
file = mod.__file__
sys.__stdout__.write("breaking in: %s" % file)
if file.endswith(".pyc"):
file = file[:-1]
pdb = Pdb(stdout=sys.__stdout__) # use sys.__stdout__ to work with
nose tests
pdb.reset()
pdb.curframe = frame
pdb.botframe = object()
pdb.set_continue()
temp = line
while temp < line + 10:
error = pdb.set_break(file, temp, cond=cond, temporary=temp)
if error:
temp += 1
else:
break
if error:
error = pdb.set_break(file, line, cond=cond, temporary=temp)
if throw:
raise Error(error)
sys.__stdout__.write("\n%s\n" % error)
return
sys.__stdout__.write("\n")
pdb.do_break("") # print breakpoints
sys.settrace(pdb.trace_dispatch)


I'm sure there is a better way to implement some of this, especially
the part marked with HACK, but it seems to work for me in most
situations.

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


Re: How can I tell if variable is defined

2009-09-22 Thread Peter Otten
Mel wrote:

> Grant Edwards wrote:
> 
>> On 2009-09-22, Brown, Rodrick  wrote:
>> 
>>> How could I do the following check in Python
>>>
>>> In Perl I could do something like if ((defined($a)) { ... }
>> 
>> try:
>> yourNameHere
>> except NameError:
>> print "undefined"
>> else:
>> print "defined"
> 
> This being Python, however, it can be fooled:
> 
> Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
> [GCC 4.3.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
 class A():
> ...   def __repr__ (self):
> ... global b

Superfluous global statement.

> ... return b
> ...
 a = A()
 try:
> ...   a
> ... except NameError:
> ...   print "`a` is not defined"
> ...
> `a` is not defined

This is an artifact of the interactive interpreter, like the following way 
to print 42:

>>> for i in range(3): 42
...
42
42
42

Peter

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


Re: set breakpoint in another module/file

2009-09-22 Thread Stef Mientki

Daniel wrote:

Is there a way with pdb to set a breakpoint in another module directly
using a command similar to set_trace() ? For example, I'd like to do
something like this in my source code:

import pdb
pdb.setbreak(42, "/path/to/universe.py", "name == 'hitchhiker'")

  

I think winpdb ( nothing todo with windows-OS ) can do that and much more.

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


Re: How can I tell if variable is defined

2009-09-22 Thread Mel
Peter Otten wrote:
> Mel wrote:
>> Grant Edwards wrote: 
>>> On 2009-09-22, Brown, Rodrick  wrote:
>>> 
 How could I do the following check in Python

 In Perl I could do something like if ((defined($a)) { ... }
>>> 
[ ... ]
> This is an artifact of the interactive interpreter,

True.  You can avoid the artifact by wrapping the test in a function:

Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class A():
...   def __repr__ (self):
... return b
... 
>>> def is_defined (obj):
...   try:
... obj
...   except NameError:
... return False
...   return True
... 
>>> a = A()
>>> if is_defined (a):
...   print "`a` is defined"
... else:
...   print "`a` is not defined"
... 
`a` is defined
>>> if is_defined (b):
...   print "`b` is defined"
... else:
...   print "`b` is not defined"
... 
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'b' is not defined
>>> 

At the cost of it not quite working when the function is called with an 
undefined name.  I suppose the print statements could be crafted to make it 
look better.


Mel.



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


DBHandler class for logging?

2009-09-22 Thread kj



I've come across mentions of a mythical class of logging handlers
called DBHandler, but I can't find it anywhere.

Could someone please point me in the right direction?

(FWIW, I'm looking for ways to log messages to PostgreSQL RDBMS.)

TIA!

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


Re: DBHandler class for logging?

2009-09-22 Thread Diez B. Roggisch

kj schrieb:

I've come across mentions of a mythical class of logging handlers
called DBHandler, but I can't find it anywhere.

Could someone please point me in the right direction?

(FWIW, I'm looking for ways to log messages to PostgreSQL RDBMS.)


I'm not aware such a thing is part of the standard logging package. But 
it's trivial to write one, we did so ourselves. Depending on your 
version of python, you need to inject the class into the 
logging.handlers-module to make it loadable by the logfile-format. AFAIK 
since 2.6 that restriction is gone.


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


Re: DBHandler class for logging?

2009-09-22 Thread kj
In <[email protected]> "Diez B. Roggisch"  
writes:

>kj schrieb:
>> I've come across mentions of a mythical class of logging handlers
>> called DBHandler, but I can't find it anywhere.
>> 
>> Could someone please point me in the right direction?
>> 
>> (FWIW, I'm looking for ways to log messages to PostgreSQL RDBMS.)

>I'm not aware such a thing is part of the standard logging package. But 
>it's trivial to write one, we did so ourselves. Depending on your 
>version of python, you need to inject the class into the 
>logging.handlers-module to make it loadable by the logfile-format.

I'm sorry for my ignorance, but what exactly do you mean by
"injecting" the new class into the "logging.handlers-module"?  And
what is "the logfile-format"?

TIA!

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


Searching a large dictionary

2009-09-22 Thread Support Desk
I need help searching a large python dictionary. The dictionary is setup
like so

Key[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]

Key2[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]

Key3[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]



What would be the best way to search for a specific value of item1 and add
all the results to a new dictionary? Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: custom data warehouse in python vs. out-of-the-box ETL tool

2009-09-22 Thread Sean DiZazzo
On Sep 22, 1:00 pm, snfctech  wrote:
> Does anyone have experience building a data warehouse in python?  Any
> thoughts on custom vs using an out-of-the-box product like Talend or
> Informatica?
>
> I have an integrated system Dashboard project that I was going to
> build using cross-vendor joins on existing DBs, but I keep hearing
> that a data warehouse is the way to go.  e.g. I want to create orders
> and order_items with relations to members (MS Access DB), products
> (flat file) and employees (MySQL).
>
> Thanks in advance for any tips.

I have done some small/medium sized stuff using SQLAlchemy,
Turbogears, and Flex.  I have never used a commercial product, but I
imagine getting it set up to work with your data is the hardest part
of the job anyway, and the solution you end up with will most likely
limit you to applying their api to your data.  If you build it
yourself, you have complete control, and know exactly where to go when
you have a problem, or to add a feature.

I'm no expert, but I think I would try to find a way to consolidate
the data into one data source.  We handle the giant amount of data we
are collecting by preprocessing it into another DB anyway, so I
imagine you could do both things at the same time.

This could very probably be handled in a different way if you are a
DBA.  I'm just a MySQL hack.  :)

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


Re: Read header and data from a binary file

2009-09-22 Thread Simon Forman
On Tue, Sep 22, 2009 at 4:30 PM, Jose Rafael Pacheco
 wrote:
> Hello,
>
> I want to read from a binary file called myaudio.dat
> Then I've tried the next code:
>
> import struct
> name = "myaudio.dat"
> f = open(name,'rb')
> f.seek(0)

Don't bother to seek(0) on a file you just opened.

> chain = "< 4s 4s I 4s I 20s I I i 4s I 67s s 4s I"
> s = f.read(4*1+4*1+4*1+4*1+4*1+20*1+4*1+4*1+4*1+4*1+4*1+67*1+1+4*1+4*1)

Instead of calculating the size of the data represented by the format,
instead use the struct.calcsize() function

s = f.read(struct.calcsize(chain))

> a = struct.unpack(chain, s)
> header = {'identifier' : a[0],
>           'cid'  : a[1],
>           'clength'   : a[2],
>   'hident' : a[3],
>   'hcid32' : a[4],
>   'hdate'  : a[5],
>   'sampling' : a[6],
>   'length_B'  : a[7],
>   'max_cA'   : a[8],
>   'max_cA1' : a[9],
>   'identNOTE'  : a[10],
>   'c2len'  : a[11],}
>
> It produces:
>
> {'length_B': 150001, 'sampling': 5, 'max_cA1': 'NOTE', 'hident': 'HEDR',
> 'c2len': "Normal Sustained Vowel 'A', Voice and Speech Lab., MEEI, Boston,
> MA", 'hdate': 'Jul 13 11:57:41 1994', 'identNOTE': 68, 'max_cA': -44076,
> 'cid': 'DS16', 'hcid32': 32, 'identifier': 'FORM', 'clength': 300126}
>
> So far when I run f.tell()
>>>f.tell()
> 136L
>
> The audio data length is 300126, now I need a clue to build an array with
> the audio data (The Chunk SDA_), would it possible with struct?, any help ?

Read the chunk ID and length and then use the length to read the rest
of the chunk data.



> Thanks
>
> The file format is:
>
>
> Offset  |  Length |  Type |    Contents
> 0   4    character     Identifier: "FORM"
> 4      4        character     Chunk identifier: "DS16"
> 8      4        integer         Chunk length
> 12      -         -  Chunk data
>
> Header 2
>
> Offset       Length       Type       Contents
> 0     4     character     Identifier: "HEDR" or "HDR8"
> 4     4     integer     Chunk length (32)
> 8     20     character     Date, e.g. "May 26 23:57:43 1995"
> 28     4     integer     Sampling rate
> 32     4     integer     Data length (bytes)
> 36     2     unsigned integer     Maximum absolute value for channel A:
> 0x if not defined
> 38     2     unsigned integer     Maximum absolute value for channel A:
> 0x if not defined
>
> NOTE Chunk
>
> Offset       Length       Type       Contents
> 0     4     character     Identifier: "NOTE"
> 4     4     integer     Chunk length
> 8     -     character     Comment string
>
> SDA_, SD_A or SDAB Chunk
> Offset     Length     Type     Contents
> 0     4     character     Identifier: "SDA_", "SD_B", or "SDAB"
> 4     4     integer     Chunk length
> 8     -     -     Data
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read header and data from a binary file

2009-09-22 Thread MRAB

Jose Rafael Pacheco wrote:

Hello,

I want to read from a binary file called myaudio.dat
Then I've tried the next code:

import struct
name = "myaudio.dat"
f = open(name,'rb')
f.seek(0)
chain = "< 4s 4s I 4s I 20s I I i 4s I 67s s 4s I"
s = f.read(4*1+4*1+4*1+4*1+4*1+20*1+4*1+4*1+4*1+4*1+4*1+67*1+1+4*1+4*1)

[snip]
FYI, the struct module has a function called 'calcsize', so:

s = f.read(struct.calcsize(chain))
--
http://mail.python.org/mailman/listinfo/python-list


Re: DBHandler class for logging?

2009-09-22 Thread Diez B. Roggisch

kj schrieb:

In <[email protected]> "Diez B. Roggisch"  
writes:


kj schrieb:

I've come across mentions of a mythical class of logging handlers
called DBHandler, but I can't find it anywhere.

Could someone please point me in the right direction?

(FWIW, I'm looking for ways to log messages to PostgreSQL RDBMS.)


I'm not aware such a thing is part of the standard logging package. But 
it's trivial to write one, we did so ourselves. Depending on your 
version of python, you need to inject the class into the 
logging.handlers-module to make it loadable by the logfile-format.


I'm sorry for my ignorance, but what exactly do you mean by
"injecting" the new class into the "logging.handlers-module"?  And
what is "the logfile-format"?


The logfile format as specified in the documentation fo the 
logging-module. And due to some restrictions in the way how this 
instantiates declared logging-handlers, you need to set your own class 
into logging.handlers:


import logging.handlers as h

class MyHandler(...):
...


h.MyHandler = MyHandler


# now you can load the config.

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


Re: Not this one the other one, from a dictionary

2009-09-22 Thread Vlastimil Brom
Thanks for the elaboration;
in retrospect, given the simple requirement, that there are only two
dict keys, one of which is know and the other to be determined, maybe
just the direct dict methods are appropriate, e.g.

d = {'a': 'bob', 'b': 'stu'}
d_copy = dict(d)
d_copy.pop("a")
'bob'
d_copy.popitem()
('b', 'stu')

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


Re: Searching a large dictionary

2009-09-22 Thread Chris Rebert
On Tue, Sep 22, 2009 at 2:50 PM, Support Desk
 wrote:
> I need help searching a large python dictionary. The dictionary is setup
> like so
>
> Key[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]
>
> Key2[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]
>
> Key3[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]

That is not valid syntax. Do you mean you have a dictionary like this?:

{ Key : 
[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}],
Key2 : 
[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}],
Key3 : 
[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]
}

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Searching a large dictionary

2009-09-22 Thread Simon Forman
On Tue, Sep 22, 2009 at 5:50 PM, Support Desk
 wrote:
> I need help searching a large python dictionary. The dictionary is setup
> like so
>
> Key[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]
>
> Key2[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]
>
> Key3[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]
>

These look like you're indexing objects Key, Key2, Key3 by
dictionaries, or possibly these are the result of printing dict-like
objects with custom __repr__() methods.  Could you give more
information about what's actually going on here?

> What would be the best way to search for a specific value of item1 and add
> all the results to a new dictionary? Thanks

"Searching" a dict is accomplished by simply asking for the key:  d['item1']

I'm going to guess you meant something like this:

list_of_dicts = [Key, Key2, Key3]
new_dict = {}

for i, k in enumerate(list_of_dicts):
value = k['item1']
if value == some_specific_value:
new_dict[i] = value


But it's not really clear from your post exactly what you meant to ask.

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


Re: Searching a large dictionary

2009-09-22 Thread Support Desk
Chris,  Yes that is the correct syntax, thanks

On Tue, Sep 22, 2009 at 5:22 PM, Chris Rebert  wrote:

> On Tue, Sep 22, 2009 at 2:50 PM, Support Desk
>  wrote:
> > I need help searching a large python dictionary. The dictionary is setup
> > like so
> >
> >
> Key[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]
> >
> >
> Key2[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]
> >
> >
> Key3[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]
>
> That is not valid syntax. Do you mean you have a dictionary like this?:
>
> { Key :
> [{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}],
> Key2 :
> [{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}],
> Key3 :
> [{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]
> }
>
> Cheers,
> Chris
> --
> http://blog.rebertia.com
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Searching a large dictionary

2009-09-22 Thread Simon Forman
On Tue, Sep 22, 2009 at 6:30 PM, Support Desk
 wrote:
> Chris,  Yes that is the correct syntax, thanks
>

Okay, but correct syntax of what?  Help us help you.


> On Tue, Sep 22, 2009 at 5:22 PM, Chris Rebert  wrote:
>>
>> On Tue, Sep 22, 2009 at 2:50 PM, Support Desk
>>  wrote:
>> > I need help searching a large python dictionary. The dictionary is setup
>> > like so
>> >
>> >
>> > Key[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]
>> >
>> >
>> > Key2[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]
>> >
>> >
>> > Key3[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]
>>
>> That is not valid syntax. Do you mean you have a dictionary like this?:
>>
>> { Key :
>> [{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}],
>> Key2 :
>> [{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}],
>> Key3 :
>> [{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]
>> }
>>
>> Cheers,
>> Chris
>> --
>> http://blog.rebertia.com
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: .h files?

2009-09-22 Thread rogerdpack4
> What python distributions are you referring to? The ones I know don't
> make this distinction; there is only a single set of header files that
> you can choose to install.

Ok good to know.
-r
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Searching a large dictionary

2009-09-22 Thread Chris Rebert
> On Tue, Sep 22, 2009 at 5:22 PM, Chris Rebert  wrote:
>> On Tue, Sep 22, 2009 at 2:50 PM, Support Desk
>>  wrote:
>> > I need help searching a large python dictionary. The dictionary is setup
>> > like so
>> >
>> >
>> > Key[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]
>> >
>> >
>> > Key2[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]
>> >
>> >
>> > Key3[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]
>>
>> That is not valid syntax. Do you mean you have a dictionary like this?:
>>
>> { Key :
>> [{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}],
>> Key2 :
>> [{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}],
>> Key3 :
>> [{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]
>> }
On Tue, Sep 22, 2009 at 3:30 PM, Support Desk
 wrote:
> Chris,  Yes that is the correct syntax, thanks

Ok, so what would the new dictionary you want look like exactly? A
list would seem the natural datatype for the results, but you want a
dict.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Searching a large dictionary

2009-09-22 Thread Chris Rebert
> -Original Message-
> From: Chris Rebert 
> Sent: Tuesday, September 22, 2009 5:35 PM
> To: Support Desk 
> Cc: [email protected]
> Subject: Re: Searching a large dictionary
>> On Tue, Sep 22, 2009 at 5:22 PM, Chris Rebert  wrote:
>>> On Tue, Sep 22, 2009 at 2:50 PM, Support Desk
>>>  wrote:
>>> > I need help searching a large python dictionary. The dictionary is setup
>>> > like so
>>> >
>>> >
>>> > Key[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]
>>> >
>>> >
>>> > Key2[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]
>>> >
>>> >
>>> > Key3[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]
>>>
>>> That is not valid syntax. Do you mean you have a dictionary like this?:
>>>
>>> { Key :
>>> [{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}],
>>> Key2 :
>>> [{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}],
>>> Key3 :
>>> [{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]
>>> }
> On Tue, Sep 22, 2009 at 3:30 PM, Support Desk
>  wrote:
>> Chris,  Yes that is the correct syntax, thanks
>
> Ok, so what would the new dictionary you want look like exactly? A
> list would seem the natural datatype for the results, but you want a
> dict.
On Tue, Sep 22, 2009 at 3:41 PM, Support  wrote:
> Chris, a list would work fine, the results are being rendered to a django 
> template

results = []
for lst in your_dict.values():
d = lst[0]
try:
results.append(d[item1])
except KeyError:
pass
#use results

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Solved - Python: automate input to MySQL query

2009-09-22 Thread Threader Slash
Hi Dennis,
You're right. Putting """ allows indentation. Great!

About putting the name of the table: x.travelerID, etc.. I think it keep the
query more documented, specially when you are dealing with 5 tables in a
same query, like this query.

Cheers.. Threader.

-- Forwarded message --
From: Dennis Lee Bieber 
To: [email protected]
Date: Tue, 22 Sep 2009 10:43:52 -0700
Subject: Re: Solved - Python: automate input to MySQL query
On Tue, 22 Sep 2009 15:58:18 +1000, Threader Slash
 declaimed the following in
gmane.comp.python.general:

>
> self.db = MySQLdb.connect(hostname,username,passwd,dbname)
> self.cursor=self.db.cursor();
>
> name="John"
> runQuery="SELECT traveler.travelerFirstName,vaccine.vaccineName from
> traveler INNER JOIN takenvaccine ON traveler.travelerID =
> takenvaccine.travelerID INNER JOIN vaccine ON
> takenvaccine.vaccineID=vaccine.vaccineID INNER JOIN requiredvaccine ON
> vaccine.vaccineID=requiredvaccine.requiredvaccineID INNER JOIN site ON
> requiredvaccine.siteID = site.siteID WHERE traveler.travelerFirstName
> = %s"
>
   
>
> Note: you need to declare the whole query in the same line to it take
effect
> in the variable "runQuery".

   No, you don't... IF you wrap it in triple-quotes...

runQuery="""select t.travelerFirstName, v.vaccineName
   from traveler as t
   inner join takenvaccine as tv
   on t.travelerID = tv.travelerID
   inner join vaccine as v
   on tv.vaccineID = v.vaccineID
   inner join requiredvaccine as rv
   on v.vaccineID = rv.requiredvaccineID
   inner join site as s
   on rv.siteID = s.siteID
   where t.travelerFirstName = %s"""

Should be perfectly acceptable to Python and the database query
processor.

   I'm not too impressed with the database naming scheme -- if the
TABLE is named "x", why prefix all the fields in the table with the same
"x"
   requiredvaccine.requiredvaccineID
is rather redundant -- same with all the others. The only place where it
might be justified is when it is a foreign key linkage.

   vaccine.ID  ID of the vaccine record

   requiredvaccine.ID  ID of the rv record itself, not of
the
vaccine
   requiredvaccine.vaccineID   foreign key, ID /in/ vaccine
that
this record refers to.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: socket send O(N**2) complexity

2009-09-22 Thread Nobody
On Mon, 21 Sep 2009 16:33:08 -0400, Jack Diederich wrote:

>> AIUI, as a python string is imutable, a slice of a string is a
>> new string which points (C char *) to the start of the slice data
>> and with a length that is the length of the slice, about 8 bytes
>> on 32 bit machine.
> 
> Not in CPython.  While some special strings are re-used (empty string,
> single letters) if you take a slice of an existing string a new buffer
> is allocated and the slice memcpy'd into it.

Er, why?

I can understand doing this for mutable sequences, but it doesn't seem
to make much sense for strings.


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


Re: difficulty in understanding rsplit(None,1)[1]

2009-09-22 Thread Martin P. Hellwig

John Machin wrote:

On Sep 22, 7:10 pm, hrishy  wrote:

Hi Martin

Many thanks
And by the way great way to explain that thing


great way to find out for yourself faster than waiting for a response
from the internet ;-)


I have been called many things in the past but being labeled 'the 
internet' is an honour way to big for me ;-)


--
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'
--
http://mail.python.org/mailman/listinfo/python-list


Re: socket send O(N**2) complexity

2009-09-22 Thread Jack Diederich
On Tue, Sep 22, 2009 at 7:25 PM, Nobody  wrote:
> On Mon, 21 Sep 2009 16:33:08 -0400, Jack Diederich wrote:
>
>>> AIUI, as a python string is imutable, a slice of a string is a
>>> new string which points (C char *) to the start of the slice data
>>> and with a length that is the length of the slice, about 8 bytes
>>> on 32 bit machine.
>>
>> Not in CPython.  While some special strings are re-used (empty string,
>> single letters) if you take a slice of an existing string a new buffer
>> is allocated and the slice memcpy'd into it.
>
> Er, why?
>
> I can understand doing this for mutable sequences, but it doesn't seem
> to make much sense for strings.

Because it adds large amounts of complexity.  If you have a string
that points to 8 bytes in a 1Gig string and the giant string goes out
of scope, what do you do?  You can keep it alive, you can copy out 8
bytes; you can do one of those things now or you can wait until later
when some kind of garbage collection happens.   Once you have that
system why not pile ropes on top of it?  and once you have ropes why
not just make strings mutable ...

If you want much longer mailing list threads about the topic search
the python-dev archives.

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


Re: difficulty in understanding rsplit(None,1)[1]

2009-09-22 Thread nopsidy
lol
-nop nop nop
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I tell if variable is defined

2009-09-22 Thread Dave Angel



Mel wrote:



This is an artifact of the interactive interpreter,



True.  You can avoid the artifact by wrapping the test in a function:

Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) 
[GCC 4.3.3] on linux2

Type "help", "copyright", "credits" or "license" for more information.
  

class A():


...   def __repr__ (self):
... return b
... 
  

def is_defined (obj):


...   try:
... obj
...   except NameError:
... return False
...   return True
... 
  

a = A()
if is_defined (a):


...   print "`a` is defined"
... else:
...   print "`a` is not defined"
... 
`a` is defined
  

if is_defined (b):


...   print "`b` is defined"
... else:
...   print "`b` is not defined"
... 
Traceback (most recent call last):

  File "", line 1, in 
NameError: name 'b' is not defined
  

At the cost of it not quite working when the function is called with an 
undefined name.  I suppose the print statements could be crafted to make it 
look better.



Mel.

  
No clue what you're trying to accomplish here.  The exception inside the 
function is_defined() will never fire;  the method always returns True.


You're getting an exception during the attempt to call such a function, 
and so of course there's no point in putting the if test around that either.


This may be the last time I try to read such complexity in an 
interactive transcript.  It took a couple of tries before I got the 
indentation understood.  I thought that is_defined() was intended to be 
a method inside the class.


DaveA

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


Re: Searching a large dictionary

2009-09-22 Thread Dave Angel

Support Desk wrote:

I need help searching a large python dictionary. The dictionary is setup
like so

Key[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]

Key2[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]

Key3[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}]



What would be the best way to search for a specific value of item1 and add
all the results to a new dictionary? Thanks

  
With all the messages I've seen so far on this thread, all you've 
managed to do is confuse it further.   I suggest you start over (new 
thread) with a legal program defining a single dictionary (with real 
values for Key, Key2, and value, and without extra quote marks which 
make it fail to compile even if we guess what you're doing with the 
three keys).  I suggest that at least some relevant parts of the data 
should not be all identical, so we can tell what's important.


Use copy & paste from working code.

Then given a real dictionary, describe what you really want to search 
for, and what acceptable results would be.


And also specify the programming language, version, and OS environment.

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


Re: set breakpoint in another module/file

2009-09-22 Thread millerdev

> I think winpdb ( nothing todo with windows-OS ) can do that and much more.

The problem with winpdb (which I played with a long time ago) is that
it's much heavier than the built-in pdb--it's a GUI debugger. It
requires the beast called wx, which I do not use for web (or GUI)
development. I'm don't relish the thought of installing wx just for a
debugger. I'm really just looking for a simple function in the pdb
module that sets a breakpoint (which can subsequently be removed).
Nothing more.

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


Re: custom data warehouse in python vs. out-of-the-box ETL tool

2009-09-22 Thread snfctech
Thanks for your replies, Sean and Martin.

I agree that the ETL tools are complex in themselves, and I may as
well spend that learning curve on a lower-level tool-set that has the
added value of greater flexibility.

Can you suggest a good book or tutorial to help me build a data
warehouse in python?  Bill Inmon's "Building the Data Warehouse" is 17
years old, and I've been cautioned against Kimball.

Thanks.


On Sep 22, 3:40 pm, "Martin P. Hellwig" 
wrote:
> snfctech wrote:
> > Does anyone have experience building a data warehouse in python?  Any
> > thoughts on custom vs using an out-of-the-box product like Talend or
> > Informatica?
>
> > I have an integrated system Dashboard project that I was going to
> > build using cross-vendor joins on existing DBs, but I keep hearing
> > that a data warehouse is the way to go.  e.g. I want to create orders
> > and order_items with relations to members (MS Access DB), products
> > (flat file) and employees (MySQL).
>
> > Thanks in advance for any tips.
>
> My experience is that if you enjoy hacking around databases and are
> proficient in Python, than for small scale solutions it is preferable to
> do it yourself. If you need a large scale solutions with advanced
> requirements, building it yourself is mostly the only way.
>
> I have build a rather complex datawarehouse system in the past (well
> actually more like a centralised synchronisation hub, having input and
> reporting databases as satellite clients), shoving data from around 500
> databases (typically 5 Gb in size each) spread over the world.
>
> The only commercial solutions I reviewed was Business Objects Data
> Integrator and Oracle Warehouse Builder.
>
> These tools where quite flexible and if you already have a license deal
> which includes these tools I would definitely recommend to have more
> than just a look at it.
>
> If not and you are comfortably with using python to shovel data from A
> to B and transform it at the same time (moving relational data
> automatically into a EAV model and back again, for example) than
> building your own solution will probably save you money and time (as
> opposed to learn how to use that ETL tool).
>
> This will require you to have at least interest in the following subjects:
> - Authorization, may everybody use all data or should it be limited to a
> subset on the data depending on the data?
> (My solution was one centralised hub which contains all data but is only
> accessible to special 'client' servers strictly maintained by me which
> only sync the data relevant to them).
>
> - Authenticity, if you have different values for the same thing, which
> one should be considered authoritative and if yes may it be pushed back
> to the un-authoritative?
>
> -Synchronisation, you really don't want to push/pull all of the database
> content over every x times, so how can you delta it and is there a way
> to do this only when the data changes (push vs pull)?
>
> -ATOMIC, how long may the data be out of date and is it allowed to
> partially update
>
> -Using and maintaining multiple databases, hopefully spread over
> multiple systems. I had a server for each production DB, a server that
> mirrored that production DB with some added columns per table for
> external synchronization purposes and a master synchronisation server
> (so in essence all data was copied three times, not very efficient but
> good if you like to play it on the safe side).
>
> --
> MPHhttp://blog.dcuktec.com
> 'If consumed, best digested with added seasoning to own preference.'

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


pygui - showing an image

2009-09-22 Thread kyle schalm
hello, i wonder what the chances are that anyone here uses pygui?
it looks pretty good, but i just started using it (version 2.05) and
can't figure out how to just display a window with an image in it. i
tried:

image = Image('foo.png')
window.place(image) -- error message
window.add(image)   -- nothing shows

then i tried getting a canvas involved but that seemed to make things worse.
any hints are appreciated. thanks,
-kyle
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pygui - showing an image

2009-09-22 Thread David Robinow
On Tue, Sep 22, 2009 at 9:26 PM, kyle schalm  wrote:
> hello, i wonder what the chances are that anyone here uses pygui?
> it looks pretty good, but i just started using it (version 2.05) and
> can't figure out how to just display a window with an image in it. i
> tried:
>
> image = Image('foo.png')
> window.place(image) -- error message
> window.add(image)   -- nothing shows
>
> then i tried getting a canvas involved but that seemed to make things worse.
> any hints are appreciated. thanks,
> -kyle
> --
> http://mail.python.org/mailman/listinfo/python-list
>
There's an example in Tests/21-image.py
See if that helps.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Combining sets/dictionaries

2009-09-22 Thread alex23
Alfons Nonell-Canals  wrote:
> finally I've solved it using a "combinatorics" library which allows to
> do this kind of things.

If you're using a version of Python > 2.6 you might find that
itertools.combinations does what you want without requiring the
additional code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Combining sets/dictionaries

2009-09-22 Thread alex23
On Sep 23, 12:44 pm, alex23  wrote:
> Alfons Nonell-Canals  wrote:
> > finally I've solved it using a "combinatorics" library which allows to
> > do this kind of things.
>
> If you're using a version of Python > 2.6 you might find that
> itertools.combinations does what you want without requiring the
> additional code.

Actually, that's probably _not_ what you want, sorry. I don't like the
recursive solution you've found, though, especially as you can get the
same result with a generator expression:

>>> set1 = set(['smart', 'dumb']) # the example on the site is easier to follow 
>>> than your use case, sorry
>>> set2 = set(['hard-working', 'lazy'])
>>> list((a,b) for a in set1 for b in set2)
[('smart', 'lazy'), ('smart', 'hard-working'), ('dumb', 'lazy'),
('dumb', 'hard-working')]

>>> set3 = ['crazy', 'sane', 'boring'] # works with iterators of any size
>>> list((a,b) for a in set1 for b in set3)
[('smart', 'crazy'), ('smart', 'sane'), ('smart', 'boring'), ('dumb',
'crazy'), ('dumb', 'sane'), ('dumb', 'boring')]

Hope this helps.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: socket send O(N**2) complexity

2009-09-22 Thread Steven D'Aprano
On Wed, 23 Sep 2009 00:25:52 +0100, Nobody wrote:

> On Mon, 21 Sep 2009 16:33:08 -0400, Jack Diederich wrote:
> 
>>> AIUI, as a python string is imutable, a slice of a string is a new
>>> string which points (C char *) to the start of the slice data and with
>>> a length that is the length of the slice, about 8 bytes on 32 bit
>>> machine.
>> 
>> Not in CPython.  While some special strings are re-used (empty string,
>> single letters) if you take a slice of an existing string a new buffer
>> is allocated and the slice memcpy'd into it.
> 
> Er, why?
> 
> I can understand doing this for mutable sequences, but it doesn't seem
> to make much sense for strings.

Consider:

huge_string = "abcdef"*1000*1000*1000
tiny_string = huge_string[42:45]
del huge_string

Under the current behaviour, huge_string will be garbage collected. With 
the proposed string-view, it won't be. It would be surprising and 
disturbing if taking a tiny slice of a huge string prohibited the huge 
string from being garbage collected.


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


Re: Dynamic Form

2009-09-22 Thread BJ Swope
If you are trying to avoid the browser caching the pages so that they fetch
a new copy of the page every time, add the following 2 meta tags to the
header of the html page:




Those don't guarantee that the browser won't cache the page but it should
help the situation.

If on the other hand, you only want to populate each company's table with
the data from the form that is currently being submitted, you would run a
delete query on that company's table before you do the insert of the current
form's data.

I have some questions for you.

1. Why create a distinct table for each company?  Why not have a single
table called lets say, "catalog".  Have company be just an additional field
in the catalog table.  This way you can avoid having to create distinct
tables every time somebody submits the form with a distinct company.

2.  Why do you use build your sql statements differently and call
cursor.execute() differently.  In the first sql declaration you are using a
static string then using the string substitution when you make the
cursor.execute() call.  In the second sql declaration you perform the string
substitiution and then make the cursor.execute() call with the resulting
variable.  Why not use the same technique in both places.

3.  And as a way to make the catalog item entry page easier on the eyes, why
not use tables to give a consistent spacing/alignment.

Replace the following:
  print '\n'
  print "Category: \n" % (str(i))
  print "Item: \n" % (str(i))
  print "Description: \n" % (str(i))
  print "UOM: \n" % (str(i))
  print "Price: \n" % (str(i))

With the following:
  print ""
  print ""
  print "Category" % (str(i))
  print "Item" % (str(i))
  print "Description" % (str(i))
  print "UOM" % (str(i))
  print "Price" % (str(i))
  print ""

Makes the web page much easier to read.


-- 
To argue that honorable conduct is only required against an honorable enemy
degrades the Americans who must carry out the orders. -- Charles Krulak,
Former Commandant of the Marine Corps

We are all slave to our own paradigm. -- Joshua Williams

If the letters PhD appear after a person's name, that person will remain
outdoors even after it's started raining. -- Jeff Kay



On Tue, Sep 22, 2009 at 12:50 PM, Victor Subervi wrote:

> Well it's Web stuff, sure, but it's written in python :) The code follows.
> The problem is that I haven't figured out how to tell the program that the
> user has entered data and to clear the cache of that data so that it's not
> re-entered. How do I do that?
> TIA,
> Victor
>
> snip

> sql = 'Category varchar(100), Item varchar(20), Description
> varchar(255), UOM varchar(20), Price float(7,2)'
> cursor.execute('create table if not exists %s (%s);' % (company, sql))
>
> snip

>   sql = 'insert into %s (Category, Item, Description, UOM, Price)
> values ("%s", "%s", "%s", "%s", "%s");' % (company, cat, item, descr, uom,
> price)
>   cursor.execute(sql)
>
> snip

> i = 0
> while i < num:
>   print '\n'
>   print "Category:  maxlength='100' name='cat%s' />\n" % (str(i))
>   print "Item:  name='item%s' />\n" % (str(i))
>   print "Description:  maxlength='255' name='descr%s' />\n" % (str(i))
>   print "UOM:  name='uom%s' />\n" % (str(i))
>   print "Price:  name='price%s' />\n" % (str(i))
>
>
>
> On Tue, Sep 22, 2009 at 11:34 AM, Simon Forman wrote:
>
>> On Tue, Sep 22, 2009 at 10:46 AM, Victor Subervi
>>  wrote:
>> > Hi;
>> > I have a dynamic form in which I do the following:
>> > 1) Request two fields (company name, number of entries). That is sent
>> back
>> > to the form.
>> > 2) If the two fields are not None, the form requests other data. That,
>> too,
>> > is sent back to the form.
>> > 3) That new data is then entered into a MySQL table.
>> > The problem is, that when I go back to refresh the form, the data is
>> > re-entered into the table! How do I prevent that?
>> > TIA,
>> > Victor
>> >
>>
>> First, this seems like it's not a python question, rather it's seems
>> to be about some web stuff.
>>
>> Second, there's not enough information to tell you anything useful.
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Socket Programming through Proxy

2009-09-22 Thread Arnab Chakraborty
I have written client-server programs in python. They seem to be working
fine in the same computer, even on two different computers when directly
connected through a Lan wire, but it wouldn't work in my college LAN. I
think it is due to the proxy server through which all the computers in our
LAN need to connect. I just want to know how to take the proxy server into
consideration.
Looking forward to your replies.
Cheers.
Aki
-- 
http://mail.python.org/mailman/listinfo/python-list


Very simple finite automaton (?)

2009-09-22 Thread kpp9c
Very simple finite automaton (?)

I am not sure if this is and example of Finite Automaton or a Finite
State Machine or perhaps it is related to a transition table or markov
process. I am not a math person so i am not sure what it is called. I
googled around and got lots of super complicated gobbledegoo all with
knotty regex stuff, but what i want to do is much more simple.

I am trying to use a table (called a transition table? i dunno) to
define a bunch of moves like so:

1 --> 2 5
2 --> 1 4
3 --> 3
4 --> 1
5 --> 4 3

so that i can generate a sequence that, given an initial value, will
continue to grow according to these rules.

So starting with 1, we get:

1
2 5
1 4 4 3
2 5 1 1 3
1 4 4 3 2 5 2 5 3


. etc.

Essentially, iterating over the last added items to the list, applying
the table, adding those new items to the list, applying the table
again... etc, until the sequence reaches some predetermined number of
iterations and quits.


[ [1], [2, 5], [1, 4] , [4, 3], [2, 5], [1], [1], [3], [1, 4], [4, 3],
[2, 5], [2, 5], [3] ]


First, I would like to know what, precisely, this kind of process is
called so that i can look it up. Many names are suggested but when
googling more names and acronyms show up, maybe there are many names
used for a variety of related things, but I could be curious to know
exactly what this is an instance of. Second, I am not sure how to get
started with the loop (is this an example of recursion?) and how best
to represent the table (dictionary)? If anyone has an example of how
to do this or a suggestion on where to start poking around, that would
be great.

cheers,

kp

macosx, python2.5 & 2.6

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


Logging question

2009-09-22 Thread Gabor Urban
Hi guys,

I have embarassing problem using the logging module. I would like to
encapsulate the creation and setting up  of the logger in a class, but
it does not seem working.

Here are my relevant parts of the code:

--
import sys
import logging

class LogClass:
def __init__(self, fileName, loggerName = 'classLog'):
self.Logger = logging.getLogger(loggerName)
self.traceName = fileName
handler = logging.FileHandler(self.traceName,'a')
formatter = logging.Formatter("%(name)s %(asctime)s
%(filename)s %(lineno)d %(levelname)s %(message)s")
handler.setFormatter(formatter)
self.Logger.addHandler(handler)
self.Handler = handler

def closeLog(self):
self.Handler.flush()
self.Handler.close()

def fetchLogger(self):
return self.Logger

if __name__ == "__main__":
name = 'testlog.trc'
classLog = LogClass(name)
logger = classLog.fetchLogger()
logger.info("Created")
logger.debug("Test")
logger.info("Created .. ")
logger.debug("Test data")
classLog.closeLog()

--

The trace file is created properly but contains no lines at all. If I
put the code directly in __main__, it works fine.

What did I miss? Any ideas are wellcome.

Gabor
-- 
Linux: Choice of a GNU Generation
-- 
http://mail.python.org/mailman/listinfo/python-list


Twisted 100% event driven or hybrid?

2009-09-22 Thread jacopo
I am diving into Twisted and Perspective Broker (PB) in particular. I
am designing a system  having several models running on different
machines, they need to be recalculated periodically, I have to collect
the results, process them and start again from the beginning.

It is not clear to me if I can blend some event driven programming
with a more traditional one where the flow would be deterministic.
In my case I have to iterate on a list of models and send the request
of recalculation to the specific machine where the model resides. I
don’t want to wait for each single result but I want to sent all the
requests in one go. In this phase I am happy to have an event driven
framework with callbacks. Then I have to stop and wait for all the
results to be ready, I collect and process them. From now on I don’t
need a the system to be event drive any more, the processing should
occur only on the master machine, following a deterministic flow.
As soon as finished I am ready to start again to resubmit the models
for recalculation and so on. This should go on forever.

Is  it possible to have an hybrid system like this? If I call
reactor.spot() at the certain point of the execution where does the
execution continue from? Would this be a good design or in general is
better to keep a 100% event drive system even if I don’t actually need
to handle asynchronicity for big chunks of the code.

I would appreciate any suggestion and for the time being I recommend
this doc, one of the clearest i have read so far.
http://www.artima.com/weblogs/viewpost.jsp?thread=230001
Grazie,
Jacopo
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >