London Python meetup, Wednesday, December the 5th

2007-11-13 Thread Simon Brunning
Details here: http://tinyurl.com/2cvtlq

-- 
Cheers,
Simon B.
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
GTalk: simon.brunning | MSN: small_values | Yahoo: smallvalues
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: webbrowser.open still gives problem with file://

2007-11-13 Thread Gabriel Genellina
En Mon, 12 Nov 2007 16:18:06 -0300, krishnakant Mane  
[EMAIL PROTECTED] escribió:

 some days bac I posted a problem about webbrowser.open() not opening
 the file on the local machine.
 I get a few responses and I tryed working it out.
 I also refered to the cookbook example posted on that thread.
 I still can't figure out why
 webbrowser.open(file:///home/krishna/documents/tut.html) does not
 open the file.
 as I mentioned earlier the url in the addressbar of mozilla firefox 3
 alpha is file:///home/krishna//home/krishna/documents/tut.html
 which is indeed wrong.

I can think of two alternatives:
1) omit the file: protocol, and just use the absolute file path, like  
webbrowser.open(/home/krishna/documents/tut.html)
2) use this recipe  
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/347810 which  
lets you display content inside a browser window without requiring a  
temporary file.

-- 
Gabriel Genellina

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


Re: How to get a set of keys with largest values?

2007-11-13 Thread DouhetSukd
On Nov 12, 1:07 am, Davy [EMAIL PROTECTED] wrote:
 Hi all,

 I have a dictionary with n elements, and I want to get the m(m=n)
 keys with the largest values.

 For example, I have dic that includes n=4 elements, I want m=2 keys
 have the largest values)
 dic = {0:4,3:1,5:2,7:8}
 So, the the largest values are [8,4], so the keys are [7,0].

 Is there any fast way to implement this algorithm?
 Any suggestions are welcome!

 Best regards,
 Davy

#get a list of tuples, with value in 1st position, key second
li = [(value,key) for key, value in dic.items()]

#sort the list
li.sort()

m = 2
#grab the m highest values, from the end of the list
li_high_keys = [k for v, k in li[-m:]]

p.s. sorry if this ends up appearing multiple times, google groups can
be a bit cranky at times with postings.

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


Re: Define key in nlargest() of heapq?

2007-11-13 Thread Duncan Booth
Davy [EMAIL PROTECTED] wrote:

 Hi all,
 
 I have a dictionary with n elements, and I want to get the m(m=n)
 keys with the largest values.
 
 For example, I have dic that includes n=4 elements, I want m=2 keys
 have the largest values)
 dic = {0:4,3:1,5:2,7:8}
 So, the the largest values are [8,4], so the keys are [7,0].
 
 How to do this by nlargest() of heapq? I have tried
 nlargest(2,dic,key),
 the interpreter give out:
 Traceback (most recent call last):
   File interactive input, line 1, in module
 NameError: name 'key' is not defined
 
 Best regards,
 Davy
 
You could use the code I posted for you yesterday. See message

http://groups.google.co.uk/group/comp.lang.python/browse_frm/thread/83c10e0c67e566d8/a605259c41c78fa0?lnk=gstq=duncan+booth#a605259c41c78fa0

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


Re: Override method name and original method access

2007-11-13 Thread Gabriel Genellina
En Tue, 13 Nov 2007 01:45:31 -0300, Donn Ingle [EMAIL PROTECTED]  
escribió:

 You need to be a new-style class (that is, you must inherit from
 object) for super() to work.
 Problem is that my classes inherit already, from others I wrote. So,  
 should
 I explicitly put (object) into the ones at the top?

Changing from old-style to new-style classes may have some unintended side  
effects. You may prefer keeping your old-style classes and avoid using  
super, if you don't have multiple inheritance. Just call explicitely the  
base class.

 Other than that, you are using it
 correctly here.
 Well, even with One.add(stuff) it seems to be calling to local  
 overridden
 method. In a bit of a hurry, so can't test again right now.

Remember that you must pass `self` explicitely. That is:

class One:
  def __init__(self):
   self.stuff = []
  def add (self, stuff):
   self.stuff.append(stuff)

class Two(One):
  def __init__(self, otherstuff):
   One.__init__(self)
   One.add(self, otherstuff)
   self.unrelated = []
  def add (self, data):
   self.unrelated.append(data)

py x = One()
py x.add(1)
py x.stuff
[1]
py y = Two(2)
py y.add(3)
py y.stuff
[2]
py y.unrelated
[3]

-- 
Gabriel Genellina

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


RE: Populating a dictionary, fast [SOLVED]

2007-11-13 Thread Michael Bacarella
See end for solution.

  (3) Are you sure you need all eight-million-plus items in the cache
  all at once?
 
  Yes.
 
 I remain skeptical, but what do I know, I don't even know what you're
 doing with the data once you have it :-)

It's OK, I'd be skeptical too. ;)

 $ cat /proc/cpuinfo
 processor   : 0
 vendor_id   : AuthenticAMD
 cpu family  : 15
 model   : 107
 model name  : AMD Athlon(tm) 64 X2 Dual Core Processor 4400+
 stepping: 1
 cpu MHz : 1000.000
 cache size  : 512 KB
 ...
 processor   : 1
 vendor_id   : AuthenticAMD
 cpu family  : 15
 model   : 107
 model name  : AMD Athlon(tm) 64 X2 Dual Core Processor 4400+
 stepping: 1
 cpu MHz : 1000.000
 cache size  : 512 KB

# cat /proc/cpuinfo
processor   : 0
vendor_id   : AuthenticAMD
cpu family  : 15
model   : 5
model name  : AMD Opteron(tm) Processor 246
stepping: 10
cpu MHz : 2009.305
cache size  : 1024 KB
fpu : yes
fpu_exception   : yes
cpuid level : 1
wp  : yes
flags   : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca
cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext lm 3dnowext 3dnow
bogomips: 3981.31
TLB size: 1088 4K pages
clflush size: 64
cache_alignment : 64
address sizes   : 40 bits physical, 48 bits virtual
power management: ts fid vid ttp

processor   : 1
vendor_id   : AuthenticAMD
cpu family  : 15
model   : 5
model name  : AMD Opteron(tm) Processor 246
stepping: 10
cpu MHz : 2009.305
cache size  : 1024 KB
fpu : yes
fpu_exception   : yes
cpuid level : 1
wp  : yes
flags   : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca
cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext lm 3dnowext 3dnow
bogomips: 4014.08
TLB size: 1088 4K pages
clflush size: 64
cache_alignment : 64
address sizes   : 40 bits physical, 48 bits virtual
power management: ts fid vid ttp


As for the solution, after trying a half-dozen different integer hashing
functions
and hash table sizes (the brute force approach), on a total whim I switched
to a
model with two dictionary tiers and got whole orders of magnitude
better performance.

The tiering is, for a given key of type long:

id2name[key  40][key  0x100] = name

Much, much better.  A few minutes versus hours this way.

I suspect it could be brought down to seconds with a third level of
tiers but this is no longer posing the biggest bottleneck... ;)

Thanks!


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


Re: Looking for a good Python environment

2007-11-13 Thread Nir
On Nov 11, 11:39 pm, Paul Rubin http://[EMAIL PROTECTED] wrote:
 Russell Warren [EMAIL PROTECTED] writes:
  Wing now has multi-threaded debugging.

 Cool, is it windows-only?  I'm using Linux.

  A quick look at the current state of SPE shows that it now has multi-
  threaded debugging viaWinPDB(what I used to use for debugging thread
  issues).  Interesting.  Worth a look to see if it is integrated well.

 Same issue: this also sounds windows-specific.  Thanks though.

Winpdb may sound to you as windows specific but it actually googles up
as platform independent. Those of you who dare work with a bunch of
separate development tools (oh, the terror, ugh...) instead of an IDE
will find it to be one of the best Python debuggers around.


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


Re: templatetaizing exceptions

2007-11-13 Thread Gabriel Genellina
En Tue, 13 Nov 2007 01:09:12 -0300, alf [EMAIL PROTECTED] escribió:

 I have a few places in the code where I use:

   try:
   code_block
   except A:
   exception_handling


 the code block is different each time while exception_handling the same.

 What would be the best technique to abstract that out?

A function?

try:
code_block
except A:
handle_exception()

-- 
Gabriel Genellina

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


Re: why there is no pythonscript insine web browsers?

2007-11-13 Thread Deli_Llama
One option would be to use jython in conjunction with something like
the google web toolkit(gwt). that way you can write python code, it
will be translated into java by jython (I believe that's how it works)
and then gwt will translate the java into javascript.  I haven't done
this myself (and it seems to be quite a roundabout way of getting it
done) but it *should* work.

Alternatively you might want to try something like microsoft
silverlight which runs on the .Net framework and allows you to use
ironpython without any hacks. But that's only if you don't mind using
propreitry software or installing the silverlight runtime.

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


Re: How to get a set of keys with largest values?

2007-11-13 Thread DouhetSukd
On Nov 12, 1:07 am, Davy [EMAIL PROTECTED] wrote:
 Hi all,

 I have a dictionary with n elements, and I want to get the m(m=n)
 keys with the largest values.

 For example, I have dic that includes n=4 elements, I want m=2 keys
 have the largest values)
 dic = {0:4,3:1,5:2,7:8}
 So, the the largest values are [8,4], so the keys are [7,0].

 Is there any fast way to implement this algorithm?
 Any suggestions are welcome!

 Best regards,
 Davy

#get a list of tuples, with value in 1st position, key second
li = [(value,key) for key, value in dic.items()]

#sort the list
li.sort()

m = 2
#grab the m highest values, from the end of the list
li_high_keys = [k for v, k in li[-m:]]

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


Re: Binary search tree

2007-11-13 Thread Gabriel Genellina
En Mon, 12 Nov 2007 16:21:36 -0300, Scott SA [EMAIL PROTECTED] escribió:

 I decided to test the speeds of the four methods:

(but one should always check for correctness before checking speed)

 def dict_example(urls):
 d = {}
 for url in urls:
 if url in d:
 d[url] = 1

The above does nothing more than iterate over all urls.

 For the simple quest of Find the unique URLs in a list, the 'dict'  
 example is by far the quickest.

After correction, there is no significative difference between  
dict_example and set_example (sometimes one is slightly slower than the  
other, and sometimes it's the other way). But the simpler s = set(urls)  
suggested by Terry Reedy clearly wins (at least on my tests).

 Buuut, if you need the indexes and possibly a 'hit count', then the  
 enumerated example seems about the best (of the possibilities tested)

In this case there is another alternative using defaultict:

def defaultdict_example(urls):
 d = defaultdict(list)
 for idx,url in enumerate(urls):
 d[url].append(idx)

which is faster than setdefault_enum (again, on my tests).

Another point worth menction, I did shuffle(dummy_urls) before testing.  
Having all of them ordered may introduce some bias.

-- 
Gabriel Genellina

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


error :list out of range

2007-11-13 Thread Beema shafreen
hi everybody,
  I have written a code to check which is the lowest value in a
list 
my list:
  ['94', 'A_16_P03647505', '-59', '42', 'A_16_P41573860', '-44', '513',
'A_16_P41573861', '-44', '66', 'A_16_P41573862', '-44', '327',
'A_16_P03647506', '-46', '77', 'A_16_P41573864', '-59', '52',
'A_16_P03647507', '-59', '307', 'A_16_P41573865', '-59', '111',
'A_16_P03647508', '-59', '167', 'A_16_P41573867', '-48', '223',
'A_16_P03647509', '-45', '124', 'A_16_P41573869', '-54', '206',
'A_16_P03647510', '-59', '52', 'A_16_P41573870', '-52', '549',
'A_16_P03647511', '-59', '2976']
mycode:
res_value = []
fh = open('test','r')
for line in fh.readlines():
data = line.strip().split('\t')
current_span = data[3].strip()
probe = data[2].strip()
length = data[4].strip()
res_value.append(current_span)
res_value.append(probe)
res_value.append(length)
#omplete_dataset.append(res_value)
fh.close()
for k in range(0,len(res_value),3):
check = res_value[k:k+4]
if check[0]  check[4]:
print check
error: File app.py, line 16, in module
if check[0]  check[4]:
IndexError: list index out of range
i get an error like this how do i sort the error out to get result
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Arrays

2007-11-13 Thread Simon Brunning
On Nov 13, 2007 6:58 AM, John Machin [EMAIL PROTECTED] wrote:
 Hey Bernard, read Gordon's message carefully; he's asking about
 arrays, not lists.

Chances are a list is exactly what the OP wants.

-- 
Cheers,
Simon B.
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
GTalk: simon.brunning | MSN: small_values | Yahoo: smallvalues
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: templatetaizing exceptions

2007-11-13 Thread david
On Tue, 13 Nov 2007 06:17:26 -0300, Gabriel Genellina wrote:

 
 A function?
 
   try:
   code_block
   except A:
   handle_exception()

maybe

 def handle(f, *args, **kw):
... try:
... return f(*args, **kw)
... except A:
... handle_exception()

 def doSomething():
...code_block
...
 handle(doSomething)

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


Re: 2007.comp.lang.python

2007-11-13 Thread Kay Schluehr
Is this headline a demand for Ruby style DSLs in Python?

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


Re: why there is no pythonscript insine web browsers?

2007-11-13 Thread bramble
On Nov 13, 3:07 am, Dennis Lee Bieber [EMAIL PROTECTED] wrote:
 On Mon, 12 Nov 2007 20:07:38 +0200, Timuçin K?z?lay
 [EMAIL PROTECTED] declaimed the following in comp.lang.python:

  python support? there is even a vbscript support inside MS-IE but there
  is no python support. it would be really nice and easy for me to use
  python instead of javascript to write those ajax scripts.

 Javascript is meant to, basically, control the browser and the
 contents of HTML pages sent to it. [snip] Python can not
 be safely sand-boxed (and the early restricted mode modules have been
 removed for that reason).


Why can't it be safely sandboxed?

That is, why not just have a Python interpreter and some safe subset
of the Python standard library run with the browser? I mean, aside
from the work involved with combing out the unneeded or dangerous
parts of the standard lib, it seems like it would be much nicer to
just use Python syntax and modules rather than having to fool around
with Javascript.

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

Re: Looking for a good Python environment

2007-11-13 Thread bramble
On Nov 10, 4:48 am, Paul Rudin [EMAIL PROTECTED] wrote:
 jwelby [EMAIL PROTECTED] writes:

  The main reason I have used Eclipse for larger, team based, projects
  is for the source control plug-ins. Eclipse has plug-in support for
  cvs and svn. PyScripter may have this too - perhaps I've missed it.
  (I'm away from my Windows box at the moment, otherwise I would check).
  Of course, there are other ways to implement source control without it
  needing to be integrated in the IDE, so even this need not put off
  anyone who wants to use PyScripter with source control.

  [snip]

 I'm not sure if you count emacs as lightweight but it's certainly
 less resource hungry than eclipse/pydev, and does have integrated
 cvs/svn functionality.

I've never understood the desire for using your version control
software via your IDE. Why not just Alt-Tab over to your terminal
window and run the svn/bzr/hg/git/whatever commands yourself right
from there?

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


Re: Binary search tree

2007-11-13 Thread Scott Sandeman-Allen
On 11/13/07, Terry Reedy ([EMAIL PROTECTED]) wrote:


Scott SA [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
| On 11/12/07, Scott SA ([EMAIL PROTECTED]) wrote:
| I decided to test the speeds of the four methods:
|
|set_example
|s = set()
|for url in urls:
|if not url in s:
|s.add(url)

How is that different in result from

As mentioned in my earlier post, I'm fairly new to Python so many options are 
unknown to me (even then, there are often new ideas or approaches even for 
seasoned coders, I'm not looking forward to the days when I stop learning ;-).

set_example2
   s = set(urls)

Well, that's pretty sweet. Thanks for the heads-up on that!

which would be much faster,  faster, I would expect, than

Please see below, it is the 'set2' result

|dict_example
|d = {}
|for url in urls:
|if url in d:
|d[url] = 1

Note: 
There was an erorr in this, it was missing a 'not'
so it should have been:

   dict_example
   d = {}
   for url in urls:
   if not url in d:
   d[url] = 1

|Starting tests with 50 simulated URLs run 3 times.
|
|'set' example
|run time: 0.5505 seconds
|'dict' example
|run time: 0.2521 seconds

Starting tests with 50 simulated URLs run 3 times.

'set' example
run time: 0.8626 seconds
5000 unique URLs
'set2' example
run time: 0.4896 seconds
5000 unique URLs
'dict' example
run time: 0.4296 seconds
5000 unique URLs
'setdefault' example
run time: 0.9723 seconds
5000 unique URLs


Interestingly, the 'dict' method is still the champ for the simulations I 
created. Of course a different ratio of duplication within the source list 
could have an effect on performance, size of list (and I'm sure other 
environmental circumstances) would affect mileage.


Since my earlier posts, I found and re-read the original post:

I have to get list of URLs one by one and to find the
URLs that I have more than one time(can't be more than
twice).

My re-interpretation of his needs were that there could be no more than two 
URL's. This means to me that not only did he require the unique 'set' but also 
needed to _count_ URL hits and subsequently process any overages.

From my testing, the following _seems_ to be the best performer:

def dictcount_example(urls):
d = {}
for url in urls:
if url in d:
d[url] += 1
if d[url]  2:
proc_overage(url) # handle overage
else:
d[url] = 1
return d

Without the 'if' statement (I added it for functional completeness), it 
performed as follows:

Starting tests with 50 simulated URLs run 3 times.

'dictcount' example
run time: 1.1556 seconds
5000 unique URLs



... Curiosity got me going, so I reduced the numbers of redundancies from 100 
to 5 and the unique URLs to 100,000. The results are:

Starting tests with 50 simulated URLs run 3 times.

'set' example
run time: 1.1986 seconds
10 unique URLs
'set2' example
run time: 0.5986 seconds
10 unique URLs
'dict' example
run time: 0.8676 seconds
10 unique URLs
'dictcount' example
run time: 1.3631 seconds
10 unique URLs


So, the set() functionality in Python appears better with smaller amm'ts of 
redundancy. Still, evaluating 1/2 mil. URLs in sub-second timeframes is a 
respectable, in my opinion, pace. Esp. when one considers the call is _one_ 
line!

Scaled to 2,000,000 URLs total and 1,000,000 unique URLs, the timings are 
interesting:

Starting tests with 200 simulated URLs run 3 times.

'set' example
run time: 7.9292 seconds
100 unique URLs
'set2' example
run time: 4.6351 seconds
100 unique URLs
'dict' example
run time: 5.0060 seconds
 

Re: Looking for a good Python environment

2007-11-13 Thread cokofreedom
On Nov 13, 10:56 am, bramble [EMAIL PROTECTED] wrote:
 On Nov 10, 4:48 am, Paul Rudin [EMAIL PROTECTED] wrote:

  jwelby [EMAIL PROTECTED] writes:

   The main reason I have used Eclipse for larger, team based, projects
   is for the source control plug-ins. Eclipse has plug-in support for
   cvs and svn. PyScripter may have this too - perhaps I've missed it.
   (I'm away from my Windows box at the moment, otherwise I would check).
   Of course, there are other ways to implement source control without it
   needing to be integrated in the IDE, so even this need not put off
   anyone who wants to use PyScripter with source control.

   [snip]

  I'm not sure if you count emacs as lightweight but it's certainly
  less resource hungry than eclipse/pydev, and does have integrated
  cvs/svn functionality.

 I've never understood the desire for using your version control
 software via your IDE. Why not just Alt-Tab over to your terminal
 window and run the svn/bzr/hg/git/whatever commands yourself right
 from there?

Because it saves you from having to do this. Some people prefer all
their commands in one place. And GUI wise it is often easier to click
the button showing all previouis versions, or comparing two of them
visually. I use Eclipse with ClearCase and it saves me a great deal of
trouble when dealing with 100+ files...

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


Re: error :list out of range

2007-11-13 Thread Gabriel Genellina
En Tue, 13 Nov 2007 06:23:02 -0300, Beema shafreen  
[EMAIL PROTECTED] escribió:

 for k in range(0,len(res_value),3):
 check = res_value[k:k+4]
 if check[0]  check[4]:
 print check
 error: File app.py, line 16, in module
 if check[0]  check[4]:
 IndexError: list index out of range
 i get an error like this how do i sort the error out to get result

Look at the exception: IndexError: list index out of range. That's pretty  
explicit: some index used as a subscript on some list is out of the  
allowed range. Most of the time, that means that the index is greater than  
or equal to the list length. Now look at the source line: if check[0]   
check[4]. The possible out-of-range indexes are 0 and 4. 0 may be an  
invalid index when the list is empty; but the 4 is much more suspicious.  
We have to determine the length of the check list; that's easy looking  
one line above; res_value[k:k+4] has length 4. Valid indexes include 0, 1,  
2, and 3; 4 is an invalid index.

Now you should have enough info to fix your code. But, why use a flat  
list? Your data has certain structure, and you already read it line by  
line and use different variable names for each field. If you maintain that  
structure instead of flattening it into a list with anonymous elements,  
your code will be easier to write (and read, and understand).
Your file looks like a CSV file, and you could use the cvs module to read  
it. Let's read the file the same way you did, but using an object per row:

class ProbeData: # please choose a better name!
 Holds current_span, probe, and length

 def __init__(self, current_span, probe, length):
 self.current_span = current_span
 self.probe = probe
 self.length = length

 def __str__(self):
 return %d %s %d % (self.current_span, self.probe, self.length)

 __repr__ = __str__

dataset = []
fh = open('test','r')
for line in fh: # note that I've removed readlines()
 data = line.strip().split('\t')
 current_span = int(data[3].strip()) # assuming it's an integer
 probe = data[2].strip()
 length = int(data[4].strip()) # assuming it's an integer too
 probe_data = ProbeData(current_span, probe, length)
 dataset.append(probe_data)
fh.close()

for k in range(len(dataset)-1):
 this_probe = dataset[k]
 next_probe = dataset[k+1]
 if this_probe.current_span  next_probe.current_span:
 # Please check the condition above, it's just an example
 print this_probe

-- 
Gabriel Genellina

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


Re: Arrays

2007-11-13 Thread John Machin
On Nov 13, 8:36 pm, Simon Brunning [EMAIL PROTECTED] wrote:
 On Nov 13, 2007 6:58 AM, John Machin [EMAIL PROTECTED] wrote:

  Hey Bernard, read Gordon's message carefully; he's asking about
  arrays, not lists.

 Chances are a list is exactly what the OP wants.


Chances are a list is what he *needs*. However he explicitly referred
to the array module array, not some generic array concept. Serial
processing of the tutorial should have clued him in on Python lists
way before he  arrived at the mention of the array module.

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


Re: Issue with wxPython GUI

2007-11-13 Thread tarun
Hi Laszlo Nagy,

Thanks a lot.
But the issue over here is that how will the child thread acknowledge the
main thread that it has completed its task. For this I'll have to set some
flag in the child thread and poll for it in the main thread. This will
create a problem. Any alternatives??

Thanks  Regards,
Tarun


On 11/13/07, Laszlo Nagy [EMAIL PROTECTED] wrote:


 
  *New Problem: *I am opening and executing a script from the GUI. The
  script has a many log messages,
  which it posts on some shared memory. The GUI reads the messages from
  the shared memory,
  in the Idle loop. But the script is huge and so the logging is not
  run-time.
  Rather this happens only after the script has executed. Moreover, the
  GUI becomes
  un-responsive till the script has completely executed.
 
 This is (probably) because you are running your script in your main
 thread. While the main thread of the application is running, your
 windowing system cannot process message queues. Since the updating of a
 text control uses window messages, it has no chance to process them. I
 recommend that you run your script in a separate (terminateable?)
 thread, send your messages into a Queue instance, and load messages from
 that queue in your main thread.
 
  Do you have any suggestions for this?
 Well, if you do not want to create more threads, it migth work if you
 call this periodically from your main thread (but I did not try this):


  wxApp::Dispatch

 *virtual void* *Dispatch*()

 Dispatches the next event in the windowing system event queue.

 This can be used for programming event loops, e.g.

 while (app.Pending())
Dispatch();



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

Loop three lists at the same time?

2007-11-13 Thread Davy
Hi all,

I have three lists with the same length. Is there any method to loop
the three lists without a loop counter?

Best regards,
Davy

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


Re: Loop three lists at the same time?

2007-11-13 Thread J. Robertson
Davy wrote:
 Hi all,
 
 I have three lists with the same length. Is there any method to loop
 the three lists without a loop counter?
 
 Best regards,
 Davy
 

Hello,

the zip function?

 list1 = [1,2,3]
 list2 = [4,5,6]
 list3 = [7,8,9]
 for a,b,c in zip(list1,list2,list3):
...print a, b, c
...
1 4 7
2 5 8
3 6 9

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


Re: A JEW hacker in California admits distributing malware that let him steal usernames and passwords for Paypal accounts.

2007-11-13 Thread invalid



You are comparing white collar criminals with Islamic terrorists
who strap on explosive vests and blow themselves up inside the
mosques of those who follow a slightly different version of Islam.

The internet needs licensing so we can revoke yours.

[EMAIL PROTECTED] wrote:

The Jews and Israelis the top notch WHITE COLLAR CRIMINALS, YET, they
are harassing MOSLEMS in CALIFORNIA. Do you know why ? BECAUSE ALL THE
POLITICIANS ARE IN THEIR POCKET.

Los Angeles Police Department Deputy Chief Michael P. Downing, who
heads the bureau, defended the undertaking as a way to help Muslim
communities avoid the influence of those who would radicalize Islamic
residents and advocate violent, ideologically-based extremism.

We are seeking to identify at-risk communities, Downing said in an
interview Thursday evening. We are looking for communities and
enclaves based on risk factors that are likely to become
isolated. . . . We want to know where the Pakistanis, Iranians and
Chechens are so we can reach out to those communities.

911 carried out by evil jews and mossad

Rothschilds financed APARTHEID in South Africa. They corrupted Cecil
Rhodes, the son of an anglican minister, by TEACHING him evil
techniques of apartheid. Apartheid was taught to him by the father
zionists themselves.

Was Hitler's father a bastard son of Rothschilds? Did the Salomon
Mayer von Rothschild perhaps rape  Maria Anna Schicklgruber in dark so
that she could not ever claim with certainty who the real father was?
Look at his facial features, typical central asian khazar. What was
the cause of Hitler's fanatical hatred for the Jews ?


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


Re: Loop three lists at the same time?

2007-11-13 Thread cokofreedom
On Nov 13, 11:46 am, Davy [EMAIL PROTECTED] wrote:
 Hi all,

 I have three lists with the same length. Is there any method to loop
 the three lists without a loop counter?

 Best regards,
 Davy

What exactly do you mean?

Are you trying to loop them together with the same ´count´. for loop
in zip(1,2,3) kind of thing or something else.

Please either post a more descriptive question, or your current code.

Coko

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

Directorio europeo de arte y diseño

2007-11-13 Thread marc

MARC3ART - GUÍA EUROPEA DE ARTE Y DISEÑO
 ofrece de manera ordenada, detallada  y actualizada información sobre
eventos artísticos-culturales y de diseño de interés para personas
relacionadas con el medio.
Ofrece de manera permanente  calendario de exposiciones, concursos de
arte, convocatorias y premios  de diseño, así como cualquier otra
especialidad artística (dibujo, arquitectura, literatura, animación,
cine, ...), cursos, conferencias, ciclos, talleres, sección de becas de
arte y diseño, fotografía, agencias, estudios de diseño, publicidad
etc.

www.marc3art.eu

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


Re: Loop three lists at the same time?

2007-11-13 Thread Gabriel Genellina
En Tue, 13 Nov 2007 07:46:09 -0300, Davy [EMAIL PROTECTED] escribió:

 I have three lists with the same length. Is there any method to loop
 the three lists without a loop counter?

Try zip or itertools.izip:

py L1 = ['a','b','c']
py L2 = [1, 2, 3]
py L3 = ['I', 'II', 'III']
py from itertools import izip
py for x,y,z in izip(L1,L2,L3):
...   print x,y,z
...
a 1 I
b 2 II
c 3 III

-- 
Gabriel Genellina

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


Re: why there is no pythonscript insine web browsers?

2007-11-13 Thread Diez B. Roggisch
bramble wrote:

 On Nov 13, 3:07 am, Dennis Lee Bieber [EMAIL PROTECTED] wrote:
 On Mon, 12 Nov 2007 20:07:38 +0200, Timuçin K?z?lay
 [EMAIL PROTECTED] declaimed the following in comp.lang.python:

  python support? there is even a vbscript support inside MS-IE but there
  is no python support. it would be really nice and easy for me to use
  python instead of javascript to write those ajax scripts.

 Javascript is meant to, basically, control the browser and the
 contents of HTML pages sent to it. [snip] Python can not
 be safely sand-boxed (and the early restricted mode modules have been
 removed for that reason).

 
 Why can't it be safely sandboxed?
 
 That is, why not just have a Python interpreter and some safe subset
 of the Python standard library run with the browser? I mean, aside
 from the work involved with combing out the unneeded or dangerous
 parts of the standard lib, it seems like it would be much nicer to
 just use Python syntax and modules rather than having to fool around
 with Javascript.

The problem is that building such an environment would mean building it up
from scratch instead of trying to secure the existing one - wich quite a
few people tried, and failed.

So it's more than just creating a sandbox, it's keeping track with
CPython's language features and lib-advances as well.

There are two projects I aware of that might help, IronPython  Jython. The
latter had some hard times getting up to python 2.2 (important for the new
style classes support), but now it's finished in that respect so hopefully
we will see more frequent releases of it, with newer python version
support.

And all this still doesn't tackle the fact that at least one, not to say THE
browser vendor won't adopt python just for the fun of it - they even don't
taclke the flaws of the existing product.

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

Re: Issue with wxPython GUI

2007-11-13 Thread Laszlo Nagy
tarun írta:
 Hi Laszlo Nagy,
  
 Thanks a lot.
 But the issue over here is that how will the child thread acknowledge 
 the main thread that it has completed its task. For this I'll have to 
 set some flag in the child thread and poll for it in the main thread. 
 This will create a problem.
What kind of problem, can you explain? Supposing your child (worker) 
thread created the output, I would do it this way (untested):

class Child(threading.Thread):
def __init__(self,output):
   self.stop_requested = threading.Event()
   self.stopped = threading.Event()
   self.output = output
   

def run(self):
   try:
   while not self.stop_requested.isSet():
# put your algorithm here

# but check periodically if you need to abort the job.
if self.stop_requested.isSet():
   break
...
# when you have data, put into the output queue
self.output.put( your_output )
   finally:
  self.stopped.set()


-- And then, from the main thread, create the worker:

self.queue = Queue()
self.child = Child(self.queue)

-- wxApp.OnIdle:

if not self.queue.empty():
data = self.queue.get()
# display your data here, for example add to a text control.

if self.child.stopped.isSet():
add_log(Job compete) # tell the user what is going on  

And finally, you can have a button for stopping the script:

def OnClick(self,event):
self.child.stop_requested.set()
add_log(stopping worker thread)   # tell the user what is going on

 Any alternatives??
First you should tell us what is the problem with using two threads.

Regards,

   Laszlo






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

Re: Issue with wxPython GUI

2007-11-13 Thread tarun
Thanks a lot Laszlo Nagy,

I used the following and it worked.

import time
from threading import *
import wx

# Button definitions
ID_START = wx.NewId()
ID_STOP = wx.NewId()

# Define notification event for thread completion
EVT_RESULT_ID = wx.NewId()

def EVT_RESULT(win, func):
Define Result Event.
win.Connect(-1, -1, EVT_RESULT_ID, func)

class ResultEvent(wx.PyEvent):
Simple event to carry arbitrary result data.
def __init__(self, data):
Init Result Event.
wx.PyEvent.__init__(self)
self.SetEventType(EVT_RESULT_ID)
self.data = data

# Thread class that executes processing
class WorkerThread(Thread):
Worker Thread Class.
def __init__(self, notify_window):
Init Worker Thread Class.
Thread.__init__(self)
self._notify_window = notify_window
self._want_abort = 0
# This starts the thread running on creation, but you could
# also make the GUI thread responsible for calling this
self.start()

def run(self):
Run Worker Thread.
# This is the code executing in the new thread. Simulation of
# a long process (well, 10s here) as a simple loop - you will
# need to structure your processing so that you periodically
# peek at the abort variable
for i in range(10):
time.sleep(1)
if self._want_abort:
# Use a result of None to acknowledge the abort (of
# course you can use whatever you'd like or even
# a separate event type)
wx.PostEvent(self._notify_window, ResultEvent(None))
return
# Here's where the result would be returned (this is an
# example fixed result of the number 10, but it could be
# any Python object)
wx.PostEvent(self._notify_window, ResultEvent(10))

def abort(self):
abort worker thread.
# Method for use by main thread to signal an abort
self._want_abort = 1

# GUI Frame class that spins off the worker thread
class MainFrame(wx.Frame):
Class MainFrame.
def __init__(self, parent, id):
Create the MainFrame.
wx.Frame.__init__(self, parent, id, 'Thread Test')

# Dumb sample frame with two buttons
wx.Button(self, ID_START, 'Start', pos=(0,0))
wx.Button(self, ID_STOP, 'Stop', pos=(0,50))
self.status = wx.StaticText(self, -1, '', pos=(0,100))

self.Bind(wx.EVT_BUTTON, self.OnStart, id=ID_START)
self.Bind(wx.EVT_BUTTON, self.OnStop, id=ID_STOP)

# Set up event handler for any worker thread results
EVT_RESULT(self,self.OnResult)

# And indicate we don't have a worker thread yet
self.worker = None

def OnStart(self, event):
Start Computation.
# Trigger the worker thread unless it's already busy
if not self.worker:
self.status.SetLabel('Starting computation')
self.worker = WorkerThread(self)

def OnStop(self, event):
Stop Computation.
# Flag the worker thread to stop if running
if self.worker:
self.status.SetLabel('Trying to abort computation')
self.worker.abort()

def OnResult(self, event):
Show Result status.
if event.data is None:
# Thread aborted (using our convention of None return)
self.status.SetLabel('Computation aborted')
else:
# Process results here
self.status.SetLabel('Computation Result: %s' % event.data)
# In either event, the worker is done
self.worker = None

class MainApp(wx.App):
Class Main App.
def OnInit(self):
Init Main App.
self.frame = MainFrame(None, -1)
self.frame.Show(True)
self.SetTopWindow(self.frame)
return True

if __name__ == '__main__':
app = MainApp(0)
app.MainLoop()

Thanks  Regards,
Tarun

On 11/13/07, Laszlo Nagy [EMAIL PROTECTED] wrote:

 tarun írta:
  Hi Laszlo Nagy,
 
  Thanks a lot.
  But the issue over here is that how will the child thread acknowledge
  the main thread that it has completed its task. For this I'll have to
  set some flag in the child thread and poll for it in the main thread.
  This will create a problem.
 What kind of problem, can you explain? Supposing your child (worker)
 thread created the output, I would do it this way (untested):

 class Child(threading.Thread):
def __init__(self,output):
   self.stop_requested = threading.Event()
   self.stopped = threading.Event()
   self.output = output
   

def run(self):
   try:
   while not self.stop_requested.isSet():
# put your algorithm here

# but check periodically if you need to abort the job.
if self.stop_requested.isSet():
   break
...
# when you have data, put into the output queue

[OT] The Jew Spam on this list

2007-11-13 Thread Martin Marcher
Hello,

please do not respond to the political spam on this list anymore.
Rather report it as spam to your provider/anti-spam-measures or report
it to the listmasters (if you have the feeling that it helps, I guess
they're already on this issue).

I understand that this might be a heated topic but people please it's
just spam and every message regarding this topic is spam too (funny
enough, so is this message) please just add this stuff to your
killfile or whatever you use.

thanks
martin

PS: if you must discuss this opinion with me answer to me off list as
I guess most people just aren't interested...

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Distributed RVS, Darcs, tech love

2007-11-13 Thread Piet van Oostrum
 Lew [EMAIL PROTECTED] (L) wrote:

L Evidence is that TeX development is dead.  There is not yet firm evidence
L that Tex is a dead end (or even what that means), and there has been none
L (nor, I expect, is there any) that any of that reflects on Knuth's skill as
L a programmer.

According to Knuth's definition the name 'TeX' is reserved for a program
that passes the trip test. Under this assumption TeX is dead by definition.
However in a broader sense TeX is still actively developed, but it may not
be called just 'TeX' because these new versions contain extensions. So
they get new names with 'tex' being part of their name. PdfTeX and LuaTeX
are new versions that are being developed right now.
-- 
Piet van Oostrum [EMAIL PROTECTED]
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A JEW hacker in California admits distributing malware that let him steal usernames and passwords for Paypal accounts.

2007-11-13 Thread Robert J. Kolker
[EMAIL PROTECTED] wrote:

 A Jew hacker in California admits distributing malware that let him
 steal usernames and passwords for Paypal accounts.

Just like all the Goy hackers who have done the same kind of wrongful deed.

Bob Kolker

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


Re: A JEW hacker in California admits distributing malware that let him steal usernames and passwords for Paypal accounts.

2007-11-13 Thread Hendrik Maryns

  ___
  /|  /|  |  |
  ||__||  |  Please do   |
 /   O O\__ NOT  |
/  \ feed the|
   /  \ \ trolls |
  /   _\ \ __|
 /|\\ \ ||
/ | | | |\/ ||
   /   \|_|_|/   \__||
  /  /  \|| ||
 /   |   | /||  --|
 |   |   |// |  --|
  * _|  |_|_|_|  | \-/
   *-- _--\ _ \ //   |
 /  _ \\ _ //   |/
   *  /   \_ /- | - |   |
 *  ___ c_c_c_C/ \C_c_c_c


-- 
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html



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

Re: templatetaizing exceptions

2007-11-13 Thread alf
david wrote:
 On Tue, 13 Nov 2007 06:17:26 -0300, Gabriel Genellina wrote:
 
 A function?

  try:
  code_block
  except A:
  handle_exception()
 
 maybe
 
 def handle(f, *args, **kw):
 ... try:
 ... return f(*args, **kw)
 ... except A:
 ... handle_exception()
 
 def doSomething():
 ...code_block
 ...
 handle(doSomething)
 
 cheers

thx - this might work ...

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


Re: Issue with wxPython GUI

2007-11-13 Thread kyosohma
On Nov 13, 6:18 am, Laszlo Nagy [EMAIL PROTECTED] wrote:
 tarun írta: Hi Laszlo Nagy,

  Thanks a lot.
  But the issue over here is that how will the child thread acknowledge
  the main thread that it has completed its task. For this I'll have to
  set some flag in the child thread and poll for it in the main thread.
  This will create a problem.

 What kind of problem, can you explain? Supposing your child (worker)
 thread created the output, I would do it this way (untested):

 class Child(threading.Thread):
 def __init__(self,output):
self.stop_requested = threading.Event()
self.stopped = threading.Event()
self.output = output


 def run(self):
try:
while not self.stop_requested.isSet():
 # put your algorithm here
 
 # but check periodically if you need to abort the job.
 if self.stop_requested.isSet():
break
 ...
 # when you have data, put into the output queue
 self.output.put( your_output )
finally:
   self.stopped.set()

 -- And then, from the main thread, create the worker:

 self.queue = Queue()
 self.child = Child(self.queue)

 -- wxApp.OnIdle:

 if not self.queue.empty():
 data = self.queue.get()
 # display your data here, for example add to a text control.

 if self.child.stopped.isSet():
 add_log(Job compete) # tell the user what is going on

 And finally, you can have a button for stopping the script:

 def OnClick(self,event):
 self.child.stop_requested.set()
 add_log(stopping worker thread)   # tell the user what is going on

  Any alternatives??

 First you should tell us what is the problem with using two threads.

 Regards,

Laszlo

I run separate tasks in a separate thread. See 
http://wiki.wxpython.org/LongRunningTasks
for more details.

You should also look at the wxPython demo as it has some examples of
using threads in it. One other way to post messages to the main thread
is by using pubsub. This link describes it:

http://wiki.wxpython.org/ModelViewController

as does this: http://www.wxpython.org/docs/api/wx.lib.pubsub-module.html

HTH

Mike

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

Re: Issue with wxPython GUI

2007-11-13 Thread Laszlo Nagy
tarun wrote:
 Thanks a lot Laszlo Nagy,
  
 I used the following and it worked.
I thought this is a producer/consumer scenario, this is why I suggested 
the Queue class. But now I see that you only want to compute one value 
in your thread and stop it afterwards.

In fact using a wx.PyEvent is much more elegant than my solution. :-)

I'm glad that I could help.

   Laszlo

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


Iterator for circulating a list

2007-11-13 Thread BJörn Lindqvist
L = somelist

idx = 0
while True:
item = L[idx]
# Do something with item
idx = (idx + 1) % len(L)

wouldn't it be cool if there was an itertool like this:

def circulate(L, begin = 0, step = 1):
idx = begin
while True:
yield L[idx]
idx = (idx  + step) % len(L)

for x in circulate(range(10)):
print 'at', x,'!'

Or maybe someone knows an even better way of expressing the above code?

-- 
mvh Björn
-- 
http://mail.python.org/mailman/listinfo/python-list


os walk() and threads problems (os.walk are thread safe?)

2007-11-13 Thread Marcus Alves Grando
Hello list,

I have a strange problem with os.walk and threads in python script. I 
have one script that create some threads and consume Queue. For every 
value in Queue this script run os.walk() and printing root dir. But if i 
increase number of threads the result are inconsistent compared with one 
thread.

For example, run this code plus sort with one thread and after run again 
with ten threads and see diff(1).

--code--
#!/usr/local/bin/python

import os, time, glob
import Queue
import threading

EXIT=False
POOL=Queue.Queue(0)
NRO_THREADS=1
#NRO_THREADS=10

class Worker(threading.Thread):
def run(self):
global POOL, EXIT
while True:
try:
mydir=POOL.get(timeout=1)
if mydir == None:
continue

for root, dirs, files in os.walk(mydir):
print root

except Queue.Empty:
if EXIT:
break
else:
continue
except KeyboardInterrupt:
break
except Exception:
raise

for x in xrange(NRO_THREADS):
Worker().start()
try:
for i in glob.glob('/usr/ports/*'):
POOL.put(i)

while not POOL.empty():
time.sleep(1)
EXIT = True

while (threading.activeCount()  1):
time.sleep(1)
except KeyboardInterrupt:
EXIT=True
--code--

If someone can help with this i appreciate.

Regards

-- 
Marcus Alves Grando
marcus(at)sbh.eng.br | Personal
mnag(at)FreeBSD.org  | FreeBSD.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyopenglcontext binaries for 2.5 on win32

2007-11-13 Thread kyosohma
On Nov 13, 12:03 am, gz [EMAIL PROTECTED] wrote:
 no, I don't have them... I need them :)

 I'd like to thank Giovanni Bajo for providing binaries for the various
 package dependencies, and geting me going with pyopengl.

 Unfortunately I only menaged to run a basic example, where there's no
 animation. The glwindow only get's redrawn when it's resized, moved...
 well generally redrawed as a window.

 I would greatly appreciate some hints, about how to process the gui
 events in the gl portion, and how to run a continous animation in wx +
 pyopengl?

 I suspect the whole thing would be way easier with pyopenglcontext,
 but I can't seem to find a binary for python 2.5
 I can't get it to install with mingw and don't have vc currently
 installed. If someone has successfully built it, plesase share.

 Although, I think, an example of a running opengl spinning cube,
 embedded in some wx menu + buttons, capable of handling, say, mouse
 clicks in the glwindow, would work best for me.

 I'm not even that keen on wx. I choose it, purely, on the basis that
 wx is generaly brought up here frequenter than qt.
 (Didn't qt have some licensing change in the last few months that
 could potentially change that?)

I would highly recommend that you post this to the wxPython group. I
think I saw a similar question about using wx and openGL there in the
last couple of weeks. See http://www.wxpython.org/maillist.php

I tried to compile it just now, but it requires the .NET SDK (but
doesn't say which one). I'm downloading the 2.0 SDK and when I've got
it, I'll give it another go.

Mike

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


Re: AOP and pep 246

2007-11-13 Thread Steve
 AOP was a research that gone nowhere - at least not in its orginal
 AspectJ form ...

I think it might be worth pointing out, though, that there is still
significant interest in AOP in the Java community, in the form or
interest in the Spring Framework.  See, for instance:
http://www.onjava.com/pub/a/onjava/2004/07/14/springaop.html

This article was written in 2004.  It has taken some time for
awareness of Spring to penetrate the Java community, but it appears to
be happening in a serious way.

-- Thank-god-I-don't-have-to-learn-all-this-Java-superstructure-stuff-
ly yours,
Steve Ferg

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


Re: Help needed!

2007-11-13 Thread kyosohma
On Nov 12, 5:16 pm, SMALLp [EMAIL PROTECTED] wrote:
 I forgot, I'm using wxPythonSMALLp [EMAIL PROTECTED] wrote in message

 news:[EMAIL PROTECTED]

  I'm new in python and i got lost.

  Ima building an aplication that add's 2 panels and menu bar to the window.
  So i made base class that makes window, menuBarClass that inherits
  mainWindowClass.

  Problem is with PanelClass that would need to inherit MainWindowClass to
  add panels. So if someone has time to write simple example it would be
  realy helpfull.

Please check out the wxPython Wiki: http://wiki.wxpython.org/

There are tutorials there that I think you'll find most helpful.
There's also a user's group mailing list that you can join.

Mike

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


Re: pyopenglcontext binaries for 2.5 on win32

2007-11-13 Thread kyosohma
On Nov 13, 12:03 am, gz [EMAIL PROTECTED] wrote:
 no, I don't have them... I need them :)

 I'd like to thank Giovanni Bajo for providing binaries for the various
 package dependencies, and geting me going with pyopengl.

 Unfortunately I only menaged to run a basic example, where there's no
 animation. The glwindow only get's redrawn when it's resized, moved...
 well generally redrawed as a window.

 I would greatly appreciate some hints, about how to process the gui
 events in the gl portion, and how to run a continous animation in wx +
 pyopengl?

 I suspect the whole thing would be way easier with pyopenglcontext,
 but I can't seem to find a binary for python 2.5
 I can't get it to install with mingw and don't have vc currently
 installed. If someone has successfully built it, plesase share.

 Although, I think, an example of a running opengl spinning cube,
 embedded in some wx menu + buttons, capable of handling, say, mouse
 clicks in the glwindow, would work best for me.

 I'm not even that keen on wx. I choose it, purely, on the basis that
 wx is generaly brought up here frequenter than qt.
 (Didn't qt have some licensing change in the last few months that
 could potentially change that?)

Technically speaking, you could download the zip file, upzip it and
then install it via the command line.

Admittedly, that can be a little difficult when you've never done it
before.

Mike

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


Re: Iterator for circulating a list

2007-11-13 Thread Carsten Haese
On Tue, 2007-11-13 at 15:12 +0100, BJörn Lindqvist wrote:
 L = somelist
 
 idx = 0
 while True:
 item = L[idx]
 # Do something with item
 idx = (idx + 1) % len(L)
 
 wouldn't it be cool if there was an itertool like this:
 
 def circulate(L, begin = 0, step = 1):
 idx = begin
 while True:
 yield L[idx]
 idx = (idx  + step) % len(L)
 
 for x in circulate(range(10)):
 print 'at', x,'!'

For begin=0 and step=1, itertools.cycle does exactly that. For arbitrary
offsets or different steps, you'd have to combine cycle with islice.

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Re: Looking for a good Python environment

2007-11-13 Thread Chris Mellon
On Nov 13, 2007 3:56 AM, bramble [EMAIL PROTECTED] wrote:
 On Nov 10, 4:48 am, Paul Rudin [EMAIL PROTECTED] wrote:
  jwelby [EMAIL PROTECTED] writes:
 
   The main reason I have used Eclipse for larger, team based, projects
   is for the source control plug-ins. Eclipse has plug-in support for
   cvs and svn. PyScripter may have this too - perhaps I've missed it.
   (I'm away from my Windows box at the moment, otherwise I would check).
   Of course, there are other ways to implement source control without it
   needing to be integrated in the IDE, so even this need not put off
   anyone who wants to use PyScripter with source control.
 
   [snip]
 
  I'm not sure if you count emacs as lightweight but it's certainly
  less resource hungry than eclipse/pydev, and does have integrated
  cvs/svn functionality.

 I've never understood the desire for using your version control
 software via your IDE. Why not just Alt-Tab over to your terminal
 window and run the svn/bzr/hg/git/whatever commands yourself right
 from there?


Because I'm already in my IDE and I'm already managing files from
there. The version integration in Eclipse also has some other handy
features, like showing history in the live document (I can do an svn
blame for the line I'm looking at directly in the editor, without
needing to context switch to a different environment).

In the particular case of Eclipse, Eclipse has it's own workspace
and project metaphors, it doesn't work with just any old file it
happens to find. This can be very frustrating at times, but since
that's how Eclipse works it's nice to have source control integrated
into that.


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

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


Re: Iterator for circulating a list

2007-11-13 Thread Hrvoje Niksic
BJörn Lindqvist [EMAIL PROTECTED] writes:

 L = somelist

 idx = 0
 while True:
 item = L[idx]
 # Do something with item
 idx = (idx + 1) % len(L)

 wouldn't it be cool if there was an itertool like this:

 def circulate(L, begin = 0, step = 1):
 idx = begin
 while True:
 yield L[idx]
 idx = (idx  + step) % len(L)

 for x in circulate(range(10)):
 print 'at', x,'!'

How about itertools.cycle?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os walk() and threads problems (os.walk are thread safe?)

2007-11-13 Thread Diez B. Roggisch
Marcus Alves Grando wrote:

 Hello list,
 
 I have a strange problem with os.walk and threads in python script. I
 have one script that create some threads and consume Queue. For every
 value in Queue this script run os.walk() and printing root dir. But if i
 increase number of threads the result are inconsistent compared with one
 thread.
 
 For example, run this code plus sort with one thread and after run again
 with ten threads and see diff(1).

I don't see any difference. I ran it with 1 and 10 workers + sorted the
output. No diff whatsoever.

And I don't know what you mean by diff(1) - was that supposed to be some
output?

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


Re: Iterator for circulating a list

2007-11-13 Thread BJörn Lindqvist
On Nov 13, 2007 3:43 PM, Carsten Haese [EMAIL PROTECTED] wrote:
 On Tue, 2007-11-13 at 15:12 +0100, BJörn Lindqvist wrote:
  L = somelist
 
  idx = 0
  while True:
  item = L[idx]
  # Do something with item
  idx = (idx + 1) % len(L)
 For begin=0 and step=1, itertools.cycle does exactly that. For arbitrary
 offsets or different steps, you'd have to combine cycle with islice.

*slap forehead* Figures.. I actually read the itertools.cycle
documentation but I didn't realize that it was (almost) equivalent to
my code. Thanks for that.


-- 
mvh Björn
-- 
http://mail.python.org/mailman/listinfo/python-list


why no automatic conversion in string concatenation?

2007-11-13 Thread Michael Pelz Sherman
As a Java  PHP developer, I find it kind of annoying that I have to explicitly 
convert non-string variables to strings when concatenating them, especially 
when python is quite capable of doing the conversion automatically.

i.e.:

 myBool = True
 print myBool
True
 print myBool is  + myBool
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: cannot concatenate 'str' and 'bool' objects
 print myBool is  + str(myBool)
myBool is True

Can anyone explain why this is so? Are there any plans to change this in python 
3000?

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

Re: A JEW hacker in California admits distributing malware that let him steal usernames and passwords for Paypal accounts.

2007-11-13 Thread Richard G Riley
Hendrik Maryns [EMAIL PROTECTED] writes:

   ___
   /|  /|  |  |
   ||__||  |  Please do   |
  /   O O\__ NOT  |
 /  \ feed the|
/  \ \ trolls |
   /   _\ \ __|
  /|\\ \ ||
 / | | | |\/ ||
/   \|_|_|/   \__||
   /  /  \|| ||
  /   |   | /||  --|
  |   |   |// |  --|
   * _|  |_|_|_|  | \-/
*-- _--\ _ \ //   |
  /  _ \\ _ //   |/
*  /   \_ /- | - |   |
  *  ___ c_c_c_C/ \C_c_c_c

Just a small pointer here : by you posting that you re-awoke the thread
for many of us. So please, do not tell people not to feed the trolls
since (a) you are doing just that and (b) you re-awake the thread for
some of us who had already filtered it. Thank you.

The best advice is : if you think it's a troll ignore it. It will go
away. It is also better to let other people make up their own minds.
Your ascii art, while pretty, convinces no one ...
-- 
http://mail.python.org/mailman/listinfo/python-list


best open source sample

2007-11-13 Thread Johnny
Hi, I'm new to Python and am looking for a really good/complete open
source project to learn from.   I'd like it to take input from the
browser and query mysql.   Suggestions?

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


Convert some Python code to C++

2007-11-13 Thread meyousikmann
I am working on an implementation of the Longest Common Subsequence
problem (as I understand it, this problem can be used in spell
checking type activities) and have used this site to understand the
problem and its solution:

http://en.wikibooks.org/wiki/Algorithm_implementation/Strings/Longest_common_subsequence


For those that understand algorithms and can talk Python, I want to
convert the Python code in the section Reading out all LCSs into C++
code but I don't understand some of the syntax.  Can anyone give me a
hand?

Here is the code from that section, but is probably of little use
without understanding the entire problem setup given at the site
above:

def backTrackAll(C, X, Y, i, j):
if i == 0 or j == 0:
return set([])
elif X[i-1] == Y[j-1]:
return set([Z + X[i-1] for Z in backTrackAll(C, X, Y, i-1,
j-1)])
else:
R = set()
if C[i][j-1] = C[i-1][j]:
R.update(backTrackAll(C, X, Y, i, j-1))
if C[i-1][j] = C[i][j-1]:
R.update(backTrackAll(C, X, Y, i-1, j))
return R

Thanks!

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


Re: persisting data within a module

2007-11-13 Thread Peter J. Bismuti
I'm not sure how to better state my question than to post my code.  

The question boils down to which namespace to variable in the module (in this 
case A) end up in depending on whether or not the module is simply imported 
by another module which acts as the driver (run.py is __main__), or when the 
module drives itself (test.py __main__).

For example:  my guess is that in the first case A ends up in the namespace of 
test and could be referenced by test.A, in the second case A ends up in the 
global namespace (and therefore must be referred to as simply A by other 
modules).  

Can anyone please shed some light on this for me?

Thanks



  I'm having trouble understanding how namespaces work in modules.  I want
  to execute a module within the interpreter and then have values that are
  calculated persist so that other modules that get executed can retrieve
  them.

 Modules retain state their state across all imports in the same
 interpreter instance.  Module state is not shared among different
 instances of the interpreter.

  For example, consider the two simple modules below.  The first method
  fails and I'm not sure exactly why.  (Note:  assume one instance of an
  interpreter. In my case a 3rd party software tool that starts an
  interpreter when it launches).
 
  Two alternate ways of running it:
 
  1. (FAILS: RESULTS A = 0)  Use the module test itself as the driver
  using the conditional statement if (__name__==__main__):
 
  test.py
  run2.py

 Ok, what do you mean by this?  Do you mean run test.py and then run
 run2.py?  In so, then you will have *two* instances -- one for each
 file being executed.  You can only have one main module per
 interpreter instance.  I suspect this is the source of your confusion.

  or,
 
  2.  (SUCCES: RESULTS A = 10)   Use run.py as the driver.
 
  run.py
 
  _test.py__
 
  import sys,os
 
  A = 0
 
  def getA():
global A
return A
 
  def run():
global A
A = 10
 
  if (__name__==__main__):
run()

 Here, A is only initialized when the module is loaded iff it is the
 main module.  If it's not the main module, then it will have A set to
 0 until some other code calls run().

  _run.py__
 
  import test
 
  test.run()
  print A =  + str(test.getA())

 This code calls test.run(), which is necessary for A to be 10.

  _run2.py__
 
  import test
 
  print A =  + str(test.getA())
 
  --

 This code gets the value of test.A without calling test.run().  Since
 test.run() was not called, A is the value it was initialized when the
 test module was loaded -- namely, 0.

 Hope this helps,

 --Nathan Davis

-- 


Peter Bismuti
Boeing Information Technology
Renton, WA
(425) 234-0873 W
(425) 442-7775 C
-- 
http://mail.python.org/mailman/listinfo/python-list


bsddb : python, index, cursor and get

2007-11-13 Thread Pierre
Hello,

I'm having problems to use the get method on a cursor with an index
(secondary database). I've read Oracle's docs but there are mainly in C,
JAVA and C++. So no python docs!

actually, that's what I'm trying to do :

ret = cursor.get(key='blabla', data='2007-10-30', flags=0, dlen=-1, 
doff=-1)

this does not work.


the code above this line is :

### snip
def getDate(priKey, priData):
date = string.split(priData, ' ')[1]
return date

TheDB = db.DB()
TheDB.open(filename_pri, None, db.DB_BTREE, db.DB_RDONLY)

TheIDX = db.DB()
TheIDX.open(filename_idx2, None, db.DB_BTREE, db.DB_RDONLY)

TheDB.associate(TheIDX, getDate)


# get database cursor and print out database content
cursor = TheIDX.cursor()
### snip

Does anybody have some sample code which performs a lookup in a database
with an index using a cursor in Python?

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


how can I interpret a file within the interactive interpreter

2007-11-13 Thread Peter J. Bismuti
I want to interpret a file (or whatever you call it) and then keep the 
interactive interpreter alive so I can then continue to issue commands.  

How can this be done?  I saw online a -m flag but it does not seem to work. 

Thanks


-- 


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


FALSE FLAG TACTIC TO SCARE CHRISTIANS AND THOSE WHO HAVE LITTLE KNOWLEDGE Re: Concept of God in Islam

2007-11-13 Thread zionist . news2
Here, a jew subterfuge false-flag posing as an Islamic spams the
newsgroup with
CUT AND PASTE job from some Islamic webpage

TO SCARE THE CHRISTIAN FUNDAMENTALISTS and EUROPEANS (like those
French)

in an attempt to destroy 911 truth discussion by making them think
that

911 truth victory = something like islamic victory

and confuse the readership.

911 truthers never get into this kind of thing.
911 truthers never get into this kind of thing.
911 truthers never get into this kind of thing.

We will reply to EXPOSE this tactic coz we know that there are
vulnerable XENOPHOBIC people or just those who dont understand the
nature of these tactics. Such posts have often piggy-backed the posts
by 911 truthers.

It is important to explain the nature of these posts appearing after
911 truth posts which are truly science related and educational and
meant to protect our constitution and democracy from the criminals.

We (911 truthers) must protect our unity.

On Nov 13, 7:45 am, abdo911 [EMAIL PROTECTED] wrote:
 WAMY Series: On Islam No.9.Introduction
 God's Attributes
 The Oneness of God
 The Believer's Attitude
 Introduction
 It is a known fact that every language has one or more terms that are
 used in reference to God and sometimes to lesser deities. This is not
 the case with Allah. Allah is the personal name of the One true God.
 Nothing else can be called Allah. The term has no plural or gender.
 This shows its uniqueness when compared with the word god, which can
 be made plural, as in gods, or made feminine, as in goddess. It is
 interesting to notice that Allah is the personal name of God in
 Aramaic, the language of Jesus and a sister language of Arabic.The One
 true God is a reflection of the unique concept that Islam associates
 with God. To a Muslim, Allah is the Almighty Creator and Sustainer of
 the universe, Who is similar to nothing, and nothing is comparable to
 Him. The Prophet Muhammad was asked by his contemporaries about Allah;
 the answer came directly from God Himself in the form of a short
 chapter of the Qur'an, which is considered to be the essence of the
 unity or the motto of monotheism. This is chapter 112, which reads:
 In the name of Allah, the Merciful, the Compassionate. Say (O
 Muhammad), He is God, the One God, the Everlasting Refuge, who has not
 begotten, nor has been begotten, and equal to Him is not anyone.Some
 non-Muslims allege that God in Islam is a stern and cruel God who
 demands to be obeyed fully and is not loving and kind. Nothing could
 be farther from the truth than this allegation. It is enough to know
 that, with the exception of one, each of the 114 chapters of the
 Qur'an begins with the verse  In the name of God, the Merciful, the
 Compassionate. In one of the sayings of Prophet Muhammad (PBUH), we
 are told that  God is more loving and kind than a mother to her dear
 child.On the other hand, God is also Just. Hence, evildoers and
 sinners must have their share of punishment, and the virtuous must
 have God's bounties and favors. Actually, God's attribute of Mercy has
 full manifestation in His attribute of Justice. People suffering
 throughout their lives for His sake should not receive similar
 treatment from their Lord as people who oppress and exploit others
 their whole lives. Expecting similar treatment for them would amount
 to negating the very belief in the accountability of man in the
 Hereafter and thereby negate all the incentives for a moral and
 virtuous life in this world. The following Qur'anic verses are very
 clear and straightforward in this respect.
 Verily, for the Righteous are gardens of Delight, in the Presence of
 their Lord. Shall We then treat the people of Faith like the people of
 Sin? What is the matter with you? How judge you?
 Islam rejects characterizing God in any human form or depicting Him as
 favoring certain individuals or nations on the basis of wealth, power
 or race. He created the human-beings as equals. They may distinguish
 themselves and get His favor through virtue and piety only.
 The concepts that God rested on the seventh day of creation, that God
 wrestled with one of His soldiers, that God is an envious plotter
 against mankind, and that God is incarnate in any human being are
 considered blasphemy from the Islamic point of view.
 The unique usage of Allah as a personal name of God is a reflection of
 Islam's emphasis on the purity of the belief in God that is the
 essence of the message of all God's messengers. Because of this, Islam
 considers associating any deity or personality with God as a deadly
 sin that God will never forgive, despite the fact that He may forgive
 all other sins.
 The Creator must be of a different nature from the things created
 because if He is of the same nature as they are, He will be temporal
 and will therefore need a maker. It follows that nothing is like Him.
 If the maker is not temporal, then he must be eternal. But if he is
 eternal, he cannot be caused, and if nothing 

Re: how can I interpret a file within the interactive interpreter

2007-11-13 Thread Diez B. Roggisch
Peter J. Bismuti wrote:

 I want to interpret a file (or whatever you call it) and then keep the
 interactive interpreter alive so I can then continue to issue commands.
 
 How can this be done?  I saw online a -m flag but it does not seem to
 work.

Use the -i-flag.

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


referencing a subhash for generalized ngram counting

2007-11-13 Thread braver
Greetings: I wonder how does one uses single-name variables to refer
to nested sunhashes (subdictionaries).  Here's an example:

In [41]: orig = { 'abra':{'foo':7, 'bar':9}, 'ca':{}, 'dabra':{'baz':
4} }

In [42]: orig
Out[42]: {'abra': {'bar': 9, 'foo': 7}, 'ca': {}, 'dabra': {'baz': 4}}

In [43]: h = orig['ca']

In [44]: h = { 'adanac':69 }

In [45]: h
Out[45]: {'adanac': 69}

In [46]: orig
Out[46]: {'abra': {'bar': 9, 'foo': 7}, 'ca': {}, 'dabra': {'baz': 4}}

I want to change orig['ca'], which is determined somewhere else in a
program's logic, where subhashes are referred to as h -- e.g., for x
in orig: ... .  But assigning to h doesn't change orig.

The real-life motivation for this is n-gram counting.  Say you want to
maintain a hash for bigrams.  For each two subsequent words a, b in a
text, you do

bigram_count[a][b] += 1

-- notice you do want to have nested subhashes as it decreases memory
usage dramatically.

In order to generalize this to N-grammity, you want to do something
like,

h = bigram_count
# iterating over i, not word, to notice the last i
for i in range(len(ngram):
  word = ngram[i]
  if word not in h:
if i  N:
  h[word] = {}
else:
  h[word] = 0
  h = h[word]
h += 1

-- doesn't work and is just a sketch; also, if at any level we get an
empty subhash, we can short-circuit vivify all remaining levels and
add 1 in the lowest, count, level.

Yet since names are not exactly references, something else is needed
for generalized ngram multi-level counting hash -- what?

Cheers,
Alexy

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


Re: persisting data within a module

2007-11-13 Thread Peter J. Bismuti
How is that state different depending on whether a module has been simply 
imported (#2.  some other block of code has __name__ == __main__) and the 
script itself being run (#1. and having __name__==__main__)?

Ultimately, what I want is for a module to remember (persist) the value of A, 
regardless of how the module has been loaded into the interpreter.

Thanks

 Modules retain state their state across all imports in the same
 interpreter instance.  Module state is not shared among different
 instances of the interpreter.

  For example, consider the two simple modules below.  The first method
  fails and I'm not sure exactly why.  (Note:  assume one instance of an
  interpreter. In my case a 3rd party software tool that starts an
  interpreter when it launches).
 
  Two alternate ways of running it:
 
  1. (FAILS: RESULTS A = 0)  Use the module test itself as the driver
  using the conditional statement if (__name__==__main__):
 
  test.py
  run2.py

 Ok, what do you mean by this?  Do you mean run test.py and then run
 run2.py?  In so, then you will have *two* instances -- one for each
 file being executed.  You can only have one main module per
 interpreter instance.  I suspect this is the source of your confusion.

  or,
 
  2.  (SUCCES: RESULTS A = 10)   Use run.py as the driver.
 
  run.py
 
  _test.py__
 
  import sys,os
 
  A = 0
 
  def getA():
global A
return A
 
  def run():
global A
A = 10
 
  if (__name__==__main__):
run()

 Here, A is only initialized when the module is loaded iff it is the
 main module.  If it's not the main module, then it will have A set to
 0 until some other code calls run().

  _run.py__
 
  import test
 
  test.run()
  print A =  + str(test.getA())

 This code calls test.run(), which is necessary for A to be 10.

  _run2.py__
 
  import test
 
  print A =  + str(test.getA())
 
  --

 This code gets the value of test.A without calling test.run().  Since
 test.run() was not called, A is the value it was initialized when the
 test module was loaded -- namely, 0.

 Hope this helps,

 --Nathan Davis

-- 


Peter Bismuti
Boeing Information Technology
Renton, WA
(425) 234-0873 W
(425) 442-7775 C
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how can I interpret a file within the interactive interpreter

2007-11-13 Thread Peter Otten
Peter J. Bismuti wrote:

 I want to interpret a file (or whatever you call it) and then keep the 
 interactive interpreter alive so I can then continue to issue commands.  

That's what the -i option is for.

 How can this be done?  I saw online a -m flag but it does not seem to work. 

-m is used to load a module via python's import mechanism.

$ echo 'print Hello from, __name__'  tmp.py

$ python -m tmp
Hello from __main__

$ python -i tmp.py
Hello from __main__
 

You can combine both options:

$ python -i -m tmp
Hello from __main__
 

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


urllib.unquote + unicode

2007-11-13 Thread koara
Hello all,

i am using urllib.unquote_plus to unquote a string. Sometimes i get a
strange string like for example spolu%u017E%E1ci.cz to unquote. Here
the problem is that some application decided to quote a non-ascii
character as %u directly, instead of using an encoding and quoting
byte per byte.

Python (2.4.1) simply returns 'spolu%u017E\xe1ci.cz, which is likely
not what the application meant.

My question is, is this %u quoting a standard (i.e., urllib is in the
wrong), is it not (i.e., the application is in the wrong and urllib
silently ignores the '%u0' - why?), and most importantly, is there a
simple workaround to get it working as expected?

Cheers!

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


Re: best open source sample

2007-11-13 Thread kyosohma
On Nov 13, 9:20 am, Johnny [EMAIL PROTECTED] wrote:
 Hi, I'm new to Python and am looking for a really good/complete open
 source project to learn from.   I'd like it to take input from the
 browser and query mysql.   Suggestions?

Zope / Plone, Django, or Turbogears are all web frameworks that are
Python based. You could check those out. Dabo is created on top of
wxPython and is made for accessing databases.

You might also find these links helpful:

http://wiki.python.org/moin/SummerOfCode
http://freshmeat.net/articles/view/334/
www.python.org

Mike

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


Re: referencing a subhash for generalized ngram counting

2007-11-13 Thread Marc 'BlackJack' Rintsch
On Tue, 13 Nov 2007 08:02:08 -0800, braver wrote:

 Greetings: I wonder how does one uses single-name variables to refer
 to nested sunhashes (subdictionaries).  Here's an example:

That's possible and you do it in your example.

 In [41]: orig = { 'abra':{'foo':7, 'bar':9}, 'ca':{}, 'dabra':{'baz':
 4} }
 
 In [42]: orig
 Out[42]: {'abra': {'bar': 9, 'foo': 7}, 'ca': {}, 'dabra': {'baz': 4}}
 
 In [43]: h = orig['ca']

Here you are getting the reference to the empty dictionary and bind it to
the name `h`.

 In [44]: h = { 'adanac':69 }

 In [45]: h
 Out[45]: {'adanac': 69}
 
 In [46]: orig
 Out[46]: {'abra': {'bar': 9, 'foo': 7}, 'ca': {}, 'dabra': {'baz': 4}}
 
 I want to change orig['ca'], which is determined somewhere else in a
 program's logic, where subhashes are referred to as h -- e.g., for x
 in orig: ... .  But assigning to h doesn't change orig.

Correct.  Changing the dictionary bound to `h` changes it::

  h = orig['ca']
  h['adanac'] = 69
 
 Yet since names are not exactly references, something else is needed
 for generalized ngram multi-level counting hash -- what?

Names *are* implemented as references to objects, but binding the name to
a different object has no effect on the object bound to that name before.

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


Re: os walk() and threads problems (os.walk are thread safe?)

2007-11-13 Thread Marcus Alves Grando
Diez B. Roggisch wrote:
 Marcus Alves Grando wrote:
 
 Hello list,

 I have a strange problem with os.walk and threads in python script. I
 have one script that create some threads and consume Queue. For every
 value in Queue this script run os.walk() and printing root dir. But if i
 increase number of threads the result are inconsistent compared with one
 thread.

 For example, run this code plus sort with one thread and after run again
 with ten threads and see diff(1).
 
 I don't see any difference. I ran it with 1 and 10 workers + sorted the
 output. No diff whatsoever.

Do you test in one dir with many subdirs? like /usr or /usr/ports (in 
freebsd) for example?

 
 And I don't know what you mean by diff(1) - was that supposed to be some
 output?

No. One thread produce one result and ten threads produce another result 
with less lines.

Se example below:

@@ -13774,8 +13782,6 @@
  /usr/compat/linux/proc/44
  /usr/compat/linux/proc/45
  /usr/compat/linux/proc/45318
-/usr/compat/linux/proc/45484
-/usr/compat/linux/proc/45532
  /usr/compat/linux/proc/45857
  /usr/compat/linux/proc/45903
  /usr/compat/linux/proc/46

Regards

-- 
Marcus Alves Grando
marcus(at)sbh.eng.br | Personal
mnag(at)FreeBSD.org  | FreeBSD.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best open source sample

2007-11-13 Thread Johnny
On Nov 13, 9:14 am, [EMAIL PROTECTED] wrote:
 On Nov 13, 9:20 am, Johnny [EMAIL PROTECTED] wrote:

  Hi, I'm new to Python and am looking for a really good/complete open
  source project to learn from.   I'd like it to take input from the
  browser and query mysql.   Suggestions?

 Zope / Plone, Django, or Turbogears are all web frameworks that are
 Python based. You could check those out. Dabo is created on top of
 wxPython and is made for accessing databases.

 You might also find these links helpful:

 http://wiki.python.org/moin/SummerOfCodehttp://freshmeat.net/articles/view/334/www.python.org

 Mike

Thanks Mike - that should get me going.

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


Re: Arrays

2007-11-13 Thread Gordon C
OK, thanks to all. The key statement is from array import array which is 
not exactly intuitive!
Gord

John Machin [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

 Bernard wrote:
 On 12 nov, 20:19, Gordon C [EMAIL PROTECTED] wrote:
  Absolute newbie here. In spite of the Python Software Foundation 
  tutorial's
  (http://www.python.org/doc/current/tut/tut.html) use of the array
  declaration
array(type[,initializer]), the Python interpreter does NOT accept the 
  word
  array! It , presumably, needs to have an import something included. 
  Could
  some show me how to declare arrays with some basic examples?
  Gord.

 hey Gordon,

 here's a good reading for you: http://effbot.org/zone/python-list.htm

 Hey Bernard, read Gordon's message carefully; he's asking about
 arrays, not lists.

 Hey Gordon, You seem a little lost; here's the tutorial reference:
 http://docs.python.org/tut/node13.html#SECTION001370
 which produces:
 
 The array module provides an array() object that is like a list that
 stores only homogenous data and stores it more compactly. The
 following example shows an array of numbers stored as two byte
 unsigned binary numbers (typecode H) rather than the usual 16 bytes
 per entry for regular lists of python int objects:


 from array import array
 a = array('H', [4000, 10, 700, 2])
 sum(a)
26932
 a[1:3]
array('H', [10, 700])
 

 The 2nd word (array) is a link (http://docs.python.org/lib/module-
 array.html) to the docs for the array module.

 Cheers,
 John
 


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


cx_Oracle: Non-ASCII characters handling with different versions

2007-11-13 Thread Benjamin Hell
Hi!

I have a problem with the cx_Oracle module (Oracle database access):

On a computer with cx_Oracle version 4.1 (Python 2.4.3, Oracle 10g)
I can get query results consisting of strings including non-ASCII
characters, e.g. the code example below outputs é 0xe9 (which is
the correct ISO-8859-1 hex code for é). On a newer installation
with cx_Oracle 4.3.3 (Python 2.5.1, connecting to the same Oracle
10g server) these characters are interpreted as ASCII (output e
0x65). The database encoding is the default (and it's the same DB
in both cases anyways); I have no NLS environment environment
variables set on either system (I'm running cygwin). The HISTORY
file of my more recent cx_Oracle names a few changes related to
character sets, but noone strikes me to be relevant for this case.

There is non-ASCII data strings in a database, and I need to find a
way to get it out correctly.


Is anybody able to help me?

Thanks!

Ben



#!/usr/bin/env python
import cx_Oracle
database = cx_Oracle.connect('login/[EMAIL PROTECTED]')
curs = database.cursor()
sql = SELECT CHR(233) FROM DUAL
curs.execute(sql)
result = curs.fetchone()[0]
print result, 0x%x % ord(result)
-- 
http://mail.python.org/mailman/listinfo/python-list


current script path via execfile?

2007-11-13 Thread Adam Pletcher
I have an app with an embedded Python interpreter.  In that interpreter,
I want to use execfile (or something similar) to execute a script from
disk.  The script needs to somehow acquire the full path to itself, but
I can't work out how to do this.

 

Since it's run with execfile in the embedded interpreter, there's no
sys.argv to look at.  Is there another way to get the current script's
full pathname?

 

Thanks in advance.

 

- Adam

 

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

Re: Arrays

2007-11-13 Thread Chris Mellon
On Nov 13, 2007 10:26 AM, Gordon C [EMAIL PROTECTED] wrote:
 OK, thanks to all. The key statement is from array import array which is
 not exactly intuitive!
 Gord


It becomes intuitive when you learn Python, which is what you're
reading the tutorial for, and it's why the tutorial shows you exactly
what to type. If you're progressing through the tutorial step by step
instead of jumping ahead, you should already have been introduced to
the import statement.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os walk() and threads problems (os.walk are thread safe?)

2007-11-13 Thread Diez B. Roggisch
Marcus Alves Grando wrote:

 Diez B. Roggisch wrote:
 Marcus Alves Grando wrote:
 
 Hello list,

 I have a strange problem with os.walk and threads in python script. I
 have one script that create some threads and consume Queue. For every
 value in Queue this script run os.walk() and printing root dir. But if i
 increase number of threads the result are inconsistent compared with one
 thread.

 For example, run this code plus sort with one thread and after run again
 with ten threads and see diff(1).
 
 I don't see any difference. I ran it with 1 and 10 workers + sorted the
 output. No diff whatsoever.
 
 Do you test in one dir with many subdirs? like /usr or /usr/ports (in
 freebsd) for example?

Yes, over 1000 subdirs/files.
 
 
 And I don't know what you mean by diff(1) - was that supposed to be some
 output?
 
 No. One thread produce one result and ten threads produce another result
 with less lines.
 
 Se example below:
 
 @@ -13774,8 +13782,6 @@
   /usr/compat/linux/proc/44
   /usr/compat/linux/proc/45
   /usr/compat/linux/proc/45318
 -/usr/compat/linux/proc/45484
 -/usr/compat/linux/proc/45532
   /usr/compat/linux/proc/45857
   /usr/compat/linux/proc/45903
   /usr/compat/linux/proc/46

I'm not sure what that directory is, but to me that looks like the
linux /proc dir, containing process ids. Which incidentially changes
between the two runs, as more threads will have process id aliases.

Try your script on another directory.

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


Re: Populating a dictionary, fast [SOLVED]

2007-11-13 Thread Francesc Altet
A Monday 12 November 2007, Michael Bacarella escrigué:
 As for the solution, after trying a half-dozen different integer
 hashing functions
 and hash table sizes (the brute force approach), on a total whim I
 switched to a
 model with two dictionary tiers and got whole orders of magnitude
 better performance.

 The tiering is, for a given key of type long:

 id2name[key  40][key  0x100] = name

 Much, much better.  A few minutes versus hours this way.

 I suspect it could be brought down to seconds with a third level of
 tiers but this is no longer posing the biggest bottleneck... ;)

I don't know exactly why do you need a dictionary for keeping the data, 
but in case you want ultra-fast access to values, there is no 
replacement for keeping a sorted list of keys and a list with the 
original indices to values, and the proper list of values.  Then, to 
access a value, you only have to do a binary search on the sorted list, 
another lookup in the original indices list and then go straight to the 
value in the value list.  This should be the faster approach I can 
think of.

Another possibility is using an indexed column in a table in a DB.  
Lookups there should be much faster than using a dictionary as well.

HTH,

-- 
0,0   Francesc Altet     http://www.carabos.com/
V   V   Cárabos Coop. V.   Enjoy Data
 -
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Populating a dictionary, fast [SOLVED]

2007-11-13 Thread Paul McGuire
On Nov 12, 11:32 am, Michael Bacarella [EMAIL PROTECTED] wrote:
 See end for solution.

   (3) Are you sure you need all eight-million-plus items in the cache
   all at once?

   Yes.

  I remain skeptical, but what do I know, I don't even know what you're
  doing with the data once you have it :-)

 It's OK, I'd be skeptical too. ;)





  $ cat /proc/cpuinfo
  processor   : 0
  vendor_id   : AuthenticAMD
  cpu family  : 15
  model   : 107
  model name  : AMD Athlon(tm) 64 X2 Dual Core Processor 4400+
  stepping: 1
  cpu MHz : 1000.000
  cache size  : 512 KB
  ...
  processor   : 1
  vendor_id   : AuthenticAMD
  cpu family  : 15
  model   : 107
  model name  : AMD Athlon(tm) 64 X2 Dual Core Processor 4400+
  stepping: 1
  cpu MHz : 1000.000
  cache size  : 512 KB

 # cat /proc/cpuinfo
 processor   : 0
 vendor_id   : AuthenticAMD
 cpu family  : 15
 model   : 5
 model name  : AMD Opteron(tm) Processor 246
 stepping: 10
 cpu MHz : 2009.305
 cache size  : 1024 KB
 fpu : yes
 fpu_exception   : yes
 cpuid level : 1
 wp  : yes
 flags   : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca
 cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext lm 3dnowext 3dnow
 bogomips: 3981.31
 TLB size: 1088 4K pages
 clflush size: 64
 cache_alignment : 64
 address sizes   : 40 bits physical, 48 bits virtual
 power management: ts fid vid ttp

 processor   : 1
 vendor_id   : AuthenticAMD
 cpu family  : 15
 model   : 5
 model name  : AMD Opteron(tm) Processor 246
 stepping: 10
 cpu MHz : 2009.305
 cache size  : 1024 KB
 fpu : yes
 fpu_exception   : yes
 cpuid level : 1
 wp  : yes
 flags   : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca
 cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext lm 3dnowext 3dnow
 bogomips: 4014.08
 TLB size: 1088 4K pages
 clflush size: 64
 cache_alignment : 64
 address sizes   : 40 bits physical, 48 bits virtual
 power management: ts fid vid ttp

 As for the solution, after trying a half-dozen different integer hashing
 functions
 and hash table sizes (the brute force approach), on a total whim I switched
 to a
 model with two dictionary tiers and got whole orders of magnitude
 better performance.

 The tiering is, for a given key of type long:

 id2name[key  40][key  0x100] = name

 Much, much better.  A few minutes versus hours this way.

 I suspect it could be brought down to seconds with a third level of
 tiers but this is no longer posing the biggest bottleneck... ;)

 Thanks!- Hide quoted text -

 - Show quoted text -

Shouldn't this be:

id2name[key  40][key  0xff] = name

?

-- Paul

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


module data member?

2007-11-13 Thread Peter J. Bismuti
How do you define a module data member (I want to understand out how this 
works before making converting to a Class)?

Right now I'm defining variables in a module that get put into the global 
namespace.  Instead I want to put them in a module global namespace that 
will be the same regardless of whether not this module is imported or run as 
__main__.  

Thanks

PS Sorry for the near redundant posts. I'm simply trying to refine my question 
as I get a better understanding of what I'm confused about. 

Thanks

-- 


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


Re: Convert some Python code to C++

2007-11-13 Thread kyosohma
On Nov 13, 9:28 am, [EMAIL PROTECTED] wrote:
 I am working on an implementation of the Longest Common Subsequence
 problem (as I understand it, this problem can be used in spell
 checking type activities) and have used this site to understand the
 problem and its solution:

 http://en.wikibooks.org/wiki/Algorithm_implementation/Strings/Longest...

 For those that understand algorithms and can talk Python, I want to
 convert the Python code in the section Reading out all LCSs into C++
 code but I don't understand some of the syntax.  Can anyone give me a
 hand?

 Here is the code from that section, but is probably of little use
 without understanding the entire problem setup given at the site
 above:

 def backTrackAll(C, X, Y, i, j):
 if i == 0 or j == 0:
 return set([])
 elif X[i-1] == Y[j-1]:
 return set([Z + X[i-1] for Z in backTrackAll(C, X, Y, i-1,
 j-1)])
 else:
 R = set()
 if C[i][j-1] = C[i-1][j]:
 R.update(backTrackAll(C, X, Y, i, j-1))
 if C[i-1][j] = C[i][j-1]:
 R.update(backTrackAll(C, X, Y, i-1, j))
 return R

 Thanks!

You might try Shed Skin:

http://sourceforge.net/projects/shedskin/

It's been a while since I did C++. I would recommend going through a
basic C++ tutorial. I'm pretty sure the equivalence operators are
almost the same. You'll likely need to declare the types for the
arguments passed into the function as well.

I think lists are called arrays in C++. I don't know what the set
equivalent is though.

Mike

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


Re: how can I interpret a file within the interactive interpreter

2007-11-13 Thread Peter J. Bismuti
Still can't get the -m flat to work.  Perhaps this feature is not in the 
version I am using?  Thanks.


-bash-3.00$ python -m test
Unknown option: -m
usage: python [option] ... [-c cmd | file | -] [arg] ...
Try `python -h' for more information.


-bash-3.00$ python
Python 2.3.4 (#1, Jan  9 2007, 16:40:09)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] on linux2
Type help, copyright, credits or license for more information.
 
 







 Peter J. Bismuti wrote:
  I want to interpret a file (or whatever you call it) and then keep the
  interactive interpreter alive so I can then continue to issue commands.

 That's what the -i option is for.

  How can this be done?  I saw online a -m flag but it does not seem to
  work.

 -m is used to load a module via python's import mechanism.

 $ echo 'print Hello from, __name__'  tmp.py

 $ python -m tmp
 Hello from __main__

 $ python -i tmp.py
 Hello from __main__


 You can combine both options:

 $ python -i -m tmp
 Hello from __main__


 Peter

-- 


Peter Bismuti
Boeing Information Technology
Renton, WA
(425) 234-0873 W
(425) 442-7775 C
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: module data member?

2007-11-13 Thread Diez B. Roggisch
Peter J. Bismuti wrote:

 How do you define a module data member (I want to understand out how
 this works before making converting to a Class)?
 
 Right now I'm defining variables in a module that get put into the global
 namespace.  Instead I want to put them in a module global namespace that
 will be the same regardless of whether not this module is imported or run
 as __main__.

There is no real global namespace, unless you count __builtins__ - which
you shouldn't :)

All your defined top-level (global) module vars are local to that module.

BUT there is of course one tiny probleme here, that arises when using a
module as main script: then the module will be known under two distinct
names, module-name  __main__. The former of course only if someone imports
the module itself.

The common remedy for this is this:


... # lots of code of module myself

def main():
# do mainy stuff here

if __name__ == __main__:
   import myself
   myself.main()

This of course won't prevent __main__ to be existant, nor running possible
initialization code twice. But if the module is supposed to do some work,
it will operate on the one data all the other importing modules see.

You can take this one step further, using an explicit init()-function that
creates global state (remember, it's only module-global).

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


Re: referencing a subhash for generalized ngram counting

2007-11-13 Thread braver
Here's a working version of the ngram counter with nested dict, wonder
how it can be improved!

lines = [abra ca dabra,
abra ca shvabra,
abra movich roman,
abra ca dabra,
a bra cadadra]

ngrams = [x.split() for x in lines]

N = 3
N1 = N-1

orig = {}

for ngram in ngrams:
h = orig
# iterating over i, not word, to notice the last i
for i in range(N):
  word = ngram[i]
  if word not in h:
if i  N1: # (*)
  h[word] = {}
else:
  h[word] = 0
  if i  N1:
h = h[word]
  print i, h

h[word] += 1

print orig


-- e.g., perhaps we could do short-circuit vivification to the end in
(*)?

Cheers,
Alexy

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


RE: Populating a dictionary, fast [SOLVED]

2007-11-13 Thread Michael Bacarella
 Shouldn't this be:
 
 id2name[key  40][key  0xff] = name

Yes, exactly, I had done hex(pow(2,40)) when I meant hex(pow(2,40)-1)

I sent my correction a few minutes afterwards but Mailman
queued it for moderator approval (condition with replying to
myself?)


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


Re: how can I interpret a file within the interactive interpreter

2007-11-13 Thread Diez B. Roggisch
Peter J. Bismuti wrote:

 Still can't get the -m flat to work.  Perhaps this feature is not in the
 version I am using?  Thanks.

-m isn't the option you want. -i it is. And yes, -m appeared in later python
versions - I'm not exactly sure which one grew it, might be 2.3 or even
2.4. But -i is older.

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


Re: Override method name and original method access

2007-11-13 Thread Donn Ingle
 One.add(self, otherstuff)
Ah! Thanks - that makes more sense. Much appreciated.

/d

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


Re: module data member?

2007-11-13 Thread Peter J. Bismuti
This did the trick for the most part, but it still leaves a copy of the 
variable A in the non-module global namespace (see output below).  

I want A declared global to the module (so as not to be local within the 
functions of the module) but not visible outside of the module namespace 
(like B, see below). How can this be done?

Thanks again

python -i test.py
: print test.A
10
: print A
0
: print B
Traceback (most recent call last):
  File stdin, line 1, in ?
NameError: name 'B' is not defined

test.py___

A = 0

def getA():
  global A
  return A

def run():
  global A
  A = 10

if (__name__==__main__):
  import test
  test.run()

__


 def main():
 # do mainy stuff here

 if __name__ == __main__:
import myself
myself.main()

 This of course won't prevent __main__ to be existant, nor running possible
 initialization code twice. But if the module is supposed to do some work,
 it will operate on the one data all the other importing modules see.

 You can take this one step further, using an explicit init()-function that
 creates global state (remember, it's only module-global).

 Diez

-- 


Peter Bismuti
Boeing Information Technology
Renton, WA
(425) 234-0873 W
(425) 442-7775 C
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why there is no pythonscript insine web browsers?

2007-11-13 Thread Shane Geiger
At the last PyCon, Brett Cannon told me that he had already implemented
the security architecture (or security template) for Python within
Firefox.  However, he did not go forward with the project because he
would not be able to get a PhD from doing it.  :-) 




Dennis Lee Bieber wrote:
 On Tue, 13 Nov 2007 09:51:49 -, bramble [EMAIL PROTECTED]
 declaimed the following in comp.lang.python:


   
 Why can't it be safely sandboxed?

 That is, why not just have a Python interpreter and some safe subset
 of the Python standard library run with the browser? I mean, aside
 

   It's not just the library (at a start you'd need to strip out
 modules os, popen, and subprocess), but you'd also need to block out
 exec, eval() (and by extension, input() ) from the interpreter core.
 Might need to do nasty things to the low-level import mechanism so that
 villains can't rig a web site to contain an import module with ability
 to access the local file system.
   


-- 
Shane Geiger
IT Director
National Council on Economic Education
[EMAIL PROTECTED]  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

begin:vcard
fn:Shane Geiger
n:Geiger;Shane
org:National Council on Economic Education (NCEE)
adr:Suite 215;;201 N. 8th Street;Lincoln;NE;68508;United States
email;internet:[EMAIL PROTECTED]
title:IT Director
tel;work:402-438-8958
url:http://www.ncee.net
version:2.1
end:vcard

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

Win32.com

2007-11-13 Thread goldtech
Given WinXP. I remove Pythonwin and it seems I lose  win32.com. I
can't import win32.com  Is win32.com bundled with Pythonwin?

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


New comer

2007-11-13 Thread [EMAIL PROTECTED]
Hi all, I'm new comer here

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


Re: AOP and pep 246

2007-11-13 Thread Kay Schluehr
On 13 Nov., 15:17, Steve [EMAIL PROTECTED] wrote:
  AOP was a research that gone nowhere - at least not in its orginal
  AspectJ form ...

 I think it might be worth pointing out, though, that there is still
 significant interest in AOP in the Java community, in the form or
 interest in the Spring Framework.  See, for 
 instance:http://www.onjava.com/pub/a/onjava/2004/07/14/springaop.html

 This article was written in 2004.  It has taken some time for
 awareness of Spring to penetrate the Java community, but it appears to
 be happening in a serious way.

Yes, I knew about Spring AOP but didn't keep much attention. Is AOP
used a lot in the Spring context or is it just a fancy, experimental
feature which was just cool to implement at some time?

 -- Thank-god-I-don't-have-to-learn-all-this-Java-superstructure-stuff-
 ly yours,

As I understand Spring it was part of a liberation wave from J2EE in
the Java community: return to POJOs and dependency injection as the
main composition technique. Spring is probably not that bad.

 Steve Ferg

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


Re: why no automatic conversion in string concatenation?

2007-11-13 Thread J. Clifford Dyer
On Tue, Nov 13, 2007 at 07:15:06AM -0800, Michael Pelz Sherman wrote regarding 
why no automatic conversion in string concatenation?:
 
As a Java  PHP developer, I find it kind of annoying that I have to
explicitly convert non-string variables to strings when concatenating
them, especially when python is quite capable of doing the conversion
automatically.
i.e.:
 myBool = True
 print myBool
True
 print myBool is  + myBool
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: cannot concatenate 'str' and 'bool' objects
 print myBool is  + str(myBool)
myBool is True
Can anyone explain why this is so? 

Because python doesn't know if '1' + 1 should equal 2 or '11' and would rather 
you mad that decision.  Should it be different than 1 + '1'?  

or to put it more succinctly, because explicit is better than implicit.
In fact, I think it's more often the case that I have string data that I need 
to treat as integers than the other way around (input from stdin and textfiles 
for example).

 Are there any plans to change this
in python 3000?

I hope not, and I don't think so.

Thanks,
- Michael

No problem. 

Cheers,
Cliff

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


Re: Information manager/organizer with tags question.

2007-11-13 Thread Wildemar Wildenburger
[EMAIL PROTECTED] wrote:
 Hello,
 
 [snip outline of an information editor]

Maybe the Literary Machine?
URL:http://sommestad.com/lm.htm

It is a bit weird at first, and Windows only (altough I have had it 
running under wine once). But it is actually really well designed and 
very powerful.


Or, if it ever comes out (I've been waiting for it for YEARS now), 
perhaps Ceryle would fit the bill:

URL:http://www.altheim.com/ceryle/wiki/

There once was some code to download, but I couldnt get it to compile. 
The guy who writes the software is a really approachable, nice guy. 
Maybe if you contact him and politely prod him into finally getting the 
thing out, nobody will ever need to write any information manager anymore.

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


Selamat malem

2007-11-13 Thread [EMAIL PROTECTED]
selamat malem

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


Re: Win32.com

2007-11-13 Thread Matimus
On Nov 13, 9:37 am, goldtech [EMAIL PROTECTED] wrote:
 Given WinXP. I remove Pythonwin and it seems I lose  win32.com. I
 can't import win32.com  Is win32.com bundled with Pythonwin?

They are part of the same package. I'm not sure that there are any
dependencies. It isn't `win32.com' though, it is `win32com' and more
specifically `win32com.client' and `win32com.server' depending on what
you want to do.

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


Re: module data member?

2007-11-13 Thread Diez B. Roggisch
Peter J. Bismuti schrieb:
 This did the trick for the most part, but it still leaves a copy of the 
 variable A in the non-module global namespace (see output below).  
 
 I want A declared global to the module (so as not to be local within the 
 functions of the module) but not visible outside of the module namespace 
 (like B, see below). How can this be done?

It can't, unless you remove the A = 0 from the module and put it into 
some init function.

To quote myself:


This of course won't prevent __main__ to be existant, nor running possible
initialization code twice. But if the module is supposed to do some work,
it will operate on the one data all the other importing modules see.


You could of course delete everything in __main__ as well, but then...
why do you care about the __main__.A living?


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


Re: Win32.com

2007-11-13 Thread Colin J. Williams
goldtech wrote:
 Given WinXP. I remove Pythonwin and it seems I lose  win32.com. I
 can't import win32.com  Is win32.com bundled with Pythonwin?
 
Yes.

Colin W.

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


Re: New comer

2007-11-13 Thread Paul McGuire
On Nov 13, 11:37 am, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 Hi all, I'm new comer here

Welcome to you!  Are you new to programming in Python as well, or just
new to this newsgroup?

If you are new to Python, you will find a wealth of getting started
help at the Python web site, www.python.org, including links to online
books and tutorials.  There is also the Python tutor mailing list,
catering specifically to new Python users - I don't know the link off-
hand but you can find it as well at the python site.

And as you look about the archives of previous posts to acquaint
yourself with the type of discussions you'll find here, let me
apologize on behalf of the group for the recent flurry of racist spam
- it is the unfortunate but familiar story of a few people ruining a
good thing for everybody else.

Cheers,
-- Paul

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


cmp and sorting non-symmetric types

2007-11-13 Thread Adam Olsen
(I've had trouble getting response for collaboration on a PEP.
Perhaps I'm the only interested party?)

Although py3k raises an exception for completely unsortable types, it
continues to silently do the wrong thing for non-symmetric types that
overload comparison operator with special meanings.

 a = set([1])
 b = set([2, 5])
 c = set([1, 2])
 sorted([a, c, b])
[{1}, {1, 2}, {2, 5}]
 sorted([a, b, c])
[{1}, {2, 5}, {1, 2}]

To solve this I propose a revived cmp (as per the previous thread[1]),
which is the preferred path for orderings.  The rich comparison
operators will be simple wrappers for cmp() (ensuring an exception is
raised if they're not merely comparing for equality.)

Thus, set would need 7 methods defined (6 rich comparisons plus
__cmp__, although it could skip __eq__ and __ne__), whereas nearly all
other types (int, list, etc) need only __cmp__.

Code which uses = to compare sets would be assumed to want subset
operations.  Generic containers should use cmp() exclusively.


[1] http://mail.python.org/pipermail/python-3000/2007-October/011072.html

-- 
Adam Olsen, aka Rhamphoryncus
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert some Python code to C++

2007-11-13 Thread Neil Cerutti
On 2007-11-13, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 On Nov 13, 9:28 am, [EMAIL PROTECTED] wrote:
 I am working on an implementation of the Longest Common
 Subsequence problem (as I understand it, this problem can be
 used in spell checking type activities) and have used this
 site to understand the problem and its solution:

 http://en.wikibooks.org/wiki/Algorithm_implementation/Strings/Longest...

 For those that understand algorithms and can talk Python, I
 want to convert the Python code in the section Reading out
 all LCSs into C++ code but I don't understand some of the
 syntax.  Can anyone give me a hand?

 Here is the code from that section, but is probably of little
 use without understanding the entire problem setup given at
 the site above:

 def backTrackAll(C, X, Y, i, j):
 if i == 0 or j == 0:
 return set([])
 elif X[i-1] == Y[j-1]:
 return set([Z + X[i-1] for Z in backTrackAll(C, X, Y, i-1,
 j-1)])
 else:
 R = set()
 if C[i][j-1] = C[i-1][j]:
 R.update(backTrackAll(C, X, Y, i, j-1))
 if C[i-1][j] = C[i][j-1]:
 R.update(backTrackAll(C, X, Y, i-1, j))
 return R

 Thanks!

 You might try Shed Skin:

 http://sourceforge.net/projects/shedskin/

 It's been a while since I did C++. I would recommend going
 through a basic C++ tutorial. I'm pretty sure the equivalence
 operators are almost the same. You'll likely need to declare
 the types for the arguments passed into the function as well.

 I think lists are called arrays in C++. I don't know what the
 set equivalent is though.

It is called set, oddly enough. ;)

There's an overload of the set::insert function that takes a
couple of iterators that will serve for Python's update method.

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


Re: os walk() and threads problems (os.walk are thread safe?)

2007-11-13 Thread Marcus Alves Grando
Diez B. Roggisch wrote:
 Marcus Alves Grando wrote:
 
 Diez B. Roggisch wrote:
 Marcus Alves Grando wrote:

 Hello list,

 I have a strange problem with os.walk and threads in python script. I
 have one script that create some threads and consume Queue. For every
 value in Queue this script run os.walk() and printing root dir. But if i
 increase number of threads the result are inconsistent compared with one
 thread.

 For example, run this code plus sort with one thread and after run again
 with ten threads and see diff(1).
 I don't see any difference. I ran it with 1 and 10 workers + sorted the
 output. No diff whatsoever.
 Do you test in one dir with many subdirs? like /usr or /usr/ports (in
 freebsd) for example?
 
 Yes, over 1000 subdirs/files.

Strange, because to me accurs every time.

  
 And I don't know what you mean by diff(1) - was that supposed to be some
 output?
 No. One thread produce one result and ten threads produce another result
 with less lines.

 Se example below:

 @@ -13774,8 +13782,6 @@
   /usr/compat/linux/proc/44
   /usr/compat/linux/proc/45
   /usr/compat/linux/proc/45318
 -/usr/compat/linux/proc/45484
 -/usr/compat/linux/proc/45532
   /usr/compat/linux/proc/45857
   /usr/compat/linux/proc/45903
   /usr/compat/linux/proc/46
 
 I'm not sure what that directory is, but to me that looks like the
 linux /proc dir, containing process ids. Which incidentially changes
 between the two runs, as more threads will have process id aliases.

My example are not good enough. I run this script in ports directory of 
freebsd and imap folders in my linux server, same thing.

@@ -182,7 +220,6 @@
  /usr/ports/archivers/p5-POE-Filter-Bzip2
  /usr/ports/archivers/p5-POE-Filter-LZF
  /usr/ports/archivers/p5-POE-Filter-LZO
-/usr/ports/archivers/p5-POE-Filter-LZW
  /usr/ports/archivers/p5-POE-Filter-Zlib
  /usr/ports/archivers/p5-PerlIO-gzip
  /usr/ports/archivers/p5-PerlIO-via-Bzip2
@@ -234,7 +271,6 @@
  /usr/ports/archivers/star-devel
  /usr/ports/archivers/star-devel/files
  /usr/ports/archivers/star/files
-/usr/ports/archivers/stuffit
  /usr/ports/archivers/szip
  /usr/ports/archivers/tardy
  /usr/ports/archivers/tardy/files

Regards

-- 
Marcus Alves Grando
marcus(at)sbh.eng.br | Personal
mnag(at)FreeBSD.org  | FreeBSD.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why no automatic conversion in string concatenation?

2007-11-13 Thread Michael Pelz Sherman
Thanks Cliff. Not to belabor this point - clearly it's just something I'll have 
to get used to - but isn't the choice of the + as the concatenation operator 
part of the problem here? A more explicit choice would have been an 
append() function, would it not? Or at least a non-ambiguous character.

Obviously python *does* know that I'm concatenating, not adding, due to the 
type of the LH object, and it would save me a lot of time if I didn't have to 
explicitly convert my objects to strings.

Any rule can be abused...

- Michael

J. Clifford Dyer [EMAIL PROTECTED] wrote: On Tue, Nov 13, 2007 at 
07:15:06AM -0800, Michael Pelz Sherman wrote regarding why no automatic 
conversion in string concatenation?:
 
As a Java  PHP developer, I find it kind of annoying that I have to
explicitly convert non-string variables to strings when concatenating
them, especially when python is quite capable of doing the conversion
automatically.
i.e.:
 myBool = True
 print myBool
True
 print myBool is  + myBool
Traceback (most recent call last):
  File , line 1, in 
TypeError: cannot concatenate 'str' and 'bool' objects
 print myBool is  + str(myBool)
myBool is True
Can anyone explain why this is so? 

Because python doesn't know if '1' + 1 should equal 2 or '11' and would rather 
you mad that decision.  Should it be different than 1 + '1'?  

or to put it more succinctly, because explicit is better than implicit.
In fact, I think it's more often the case that I have string data that I need 
to treat as integers than the other way around (input from stdin and textfiles 
for example).

 Are there any plans to change this
in python 3000?

I hope not, and I don't think so.

Thanks,
- Michael

No problem. 

Cheers,
Cliff


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

Re: Convert some Python code to C++

2007-11-13 Thread kyosohma
On Nov 13, 12:51 pm, Neil Cerutti [EMAIL PROTECTED] wrote:
 On 2007-11-13, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:



  On Nov 13, 9:28 am, [EMAIL PROTECTED] wrote:
  I am working on an implementation of the Longest Common
  Subsequence problem (as I understand it, this problem can be
  used in spell checking type activities) and have used this
  site to understand the problem and its solution:

 http://en.wikibooks.org/wiki/Algorithm_implementation/Strings/Longest...

  For those that understand algorithms and can talk Python, I
  want to convert the Python code in the section Reading out
  all LCSs into C++ code but I don't understand some of the
  syntax.  Can anyone give me a hand?

  Here is the code from that section, but is probably of little
  use without understanding the entire problem setup given at
  the site above:

  def backTrackAll(C, X, Y, i, j):
  if i == 0 or j == 0:
  return set([])
  elif X[i-1] == Y[j-1]:
  return set([Z + X[i-1] for Z in backTrackAll(C, X, Y, i-1,
  j-1)])
  else:
  R = set()
  if C[i][j-1] = C[i-1][j]:
  R.update(backTrackAll(C, X, Y, i, j-1))
  if C[i-1][j] = C[i][j-1]:
  R.update(backTrackAll(C, X, Y, i-1, j))
  return R

  Thanks!

  You might try Shed Skin:

 http://sourceforge.net/projects/shedskin/

  It's been a while since I did C++. I would recommend going
  through a basic C++ tutorial. I'm pretty sure the equivalence
  operators are almost the same. You'll likely need to declare
  the types for the arguments passed into the function as well.

  I think lists are called arrays in C++. I don't know what the
  set equivalent is though.

 It is called set, oddly enough. ;)

 There's an overload of the set::insert function that takes a
 couple of iterators that will serve for Python's update method.

 --
 Neil Cerutti

I suspected as much, but I don't think they ever got that far into C++
in the classes I took. I'll have to file that little nugget for future
reference. Hopefully the OP is getting something out of this as well.

Mike

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


Re: why no automatic conversion in string concatenation?

2007-11-13 Thread Chris Mellon
On Nov 13, 2007 1:09 PM, Michael Pelz Sherman [EMAIL PROTECTED] wrote:
 Thanks Cliff. Not to belabor this point - clearly it's just something I'll
 have to get used to - but isn't the choice of the + as the concatenation
 operator part of the problem here? A more explicit choice would have been
 an append() function, would it not? Or at least a non-ambiguous character.

 Obviously python *does* know that I'm concatenating, not adding, due to the
 type of the LH object, and it would save me a lot of time if I didn't have
 to explicitly convert my objects to strings.


Python doesn't *know* that. It could assume that, and it could
document that assumption (and you could overload + to do that if you
wanted in your own classes), but it chooses not to assume that - you
know best what you want to do. A second operator could be used, but
since there's no ambiguity (and Python won't guess, so incorrect use
is always an error) there doesn't seem to be much gain from doing so.

It's quite rare that this actually involves much extra code - you
probably want to be using string interpolation (which will convert to
str() automatically if you use the %s format character) instead.
-- 
http://mail.python.org/mailman/listinfo/python-list


NumPy Question - numpy.put in multi-dimensional array

2007-11-13 Thread [EMAIL PROTECTED]
from numpy import *

a = zeros((2,40), int)

fields = {}
field = 10
fields[field] = '30A', 5

iy = int(fields[field][1])
ix = int(fields[field][0].rstrip('AB'))

for i in range(2):
  for j in range(iy):
#put(a,[39 - j],[1]) #1d

Can someone help me figure out how I would do it for multiple rows?

I thought,

   put(a,[i][39-j],[1])

but,

Traceback (most recent call last):
  put(a,[i][39 - j],[1])
IndexError: list index out of range

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


  1   2   3   >