Re: Python Magazine

2013-05-25 Thread Daniel
All of the above, plus:

- Best Pythonic tools for GUI

- notorious projects (in science, education, NGOs, etc) using python

Please keep us informed, and best wishes

Daniel

El 25/05/2013, a las 07:29, Michael Poeltl  
escribió:

> * DRJ Reddy  [2013-05-25 05:26]:
>> Planning to start a python online chronicle.What you want to see in it. :)
> - idiomatic python (common mistakes; do it 'pythonically')
> - interviews
> - challenge of the week (how would you solve that?)
> - python for kids
> - scientific python news
> - new python-books
> 
> - 
> 
> 
>> -- 
>> http://mail.python.org/mailman/listinfo/python-list
> 
> -- 
>  Michael Poeltl 
>  Computational Materials Physics at University
>  Wien, Sensengasse 8/12, A-1090 Wien, AUSTRIA
>  http://cmp.univie.ac.at/
>  http://homepage.univie.ac.at/michael.poeltl/
>  using elinks-0.12, mutt-1.5.21, and vim-7.3,
>  with python-3.2.3, on slackware-13.37   :-)
>  fon: +43-1-4277-51409
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: For loop

2012-05-01 Thread Daniel
You could also try http://docs.python.org/library/stdtypes.html#str.join 
like this:

for i in range(5):
print "".join(str(i) for j in range(i))
--
http://mail.python.org/mailman/listinfo/python-list


fun with nested loops

2011-08-31 Thread Daniel
Dear All,

I have some complicated loops of the following form

for c in configurations: # loop 1
while nothing_bad_happened: # loop 2
while step1_did_not_work: # loop 3
for substeps in step1 # loop 4a
# at this point, we may have to
-leave loop 1
-restart loop 4
-skip a step in loop 4
-continue on to loop 4b

while step2_did_not_work: # loop 4b
for substeps in step2:
# at this point, we may have to
-leave loop 1
-restart loop 2
-restart loop 4b
...
...many more loops...


I don't see any way to reduce these nested loops logically, they
describe pretty well what the software has to do.
This is a data acquisition application, so on ever line there is
a lot of IO that might fail or make subsequent steps useless or
require a
retry.

Now every step could need to break out of any of the enclosing loops.
So basically I have to transform every loop to be of the following
horror:

# general transformation of
# "for c in configurations..."
# to provide restart, break and continue
# callable from any nesting level inside of the loop

class loop1_restart(Exception): pass
class loop1_break(Exception): pass
class loop1_continue(Exception): pass

while True:
try:
for c in configurations:
while True:
try:
# inner loops go here, of course, they would have
to get
# all the boilerplate added, too
while nothing_bad_happened:
while step1_did_not_work:
   if cond1:
   raise loop1_restart()
   elif cond3:
   raise loop1_break()
   elif cond3:
   raise loop1_continue()

break

except loop1_continue:
pass
break
except loop1_restart:
pass
except loop1_break:
break

Of course this is extremely tedious and error prone.
If Python had named loops (PEP 3136, unfortunately rejected), this
would be trivial:
In Fortran I can continue (cycle), break (exit) and redo (goto label)
arbitrary
loops, which results in neat code:

10 loop1: do I=1,3
loop2: do J=1,4
print *,I,J
goto 10
cycle loop1
exit loop1
enddo loop2
enddo loop1


My question is, how do I obtain something that implements the
following logic:

@named_loop(fred) # I wish this would be possible
for i in range(10):
for j in range(10):
break fred # breaks out of outer loop
continue fred # continues outer loop
redo fred # resets outer loop and restarts with i=0


The best solution would be something along the Proposal D - Explicit
iterators
in PEP 3136, in this case it would even be possible to peek at the
next i or
advance/reverse the iterator a few steps.

Has anyone an idea on a nice way to write breaks/continues/redos for
deeply
nested loops?


Dan


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


Re: fun with nested loops

2011-08-31 Thread Daniel

> one more idea, a kind of named loop:
interesting idea, thanks.


>
> When it become too complicate, I use state 
> machine:http://en.wikipedia.org/wiki/Finite-state_machine
I unsuccessfully played a bit with a FSM, but there is a lot of data
that is passed around between the states and a lot of counting (like
trying a certain step n times), so the FSM turned out to be even more
complex. And I have to keep the code simple for non CS people to run
the actual experiment. The loops are kind of self-explanatory, this is
exactly how you would specify the experiment, even though I am really
hitting a wall at the moment.

Maybe I am really missing an obvious solution, because breaking out of
nested loops really doesn't seem like anything fancy. Fortran/c/c++/
Ruby/Perl all have that facility, even Java has named loops.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: fun with nested loops

2011-08-31 Thread Daniel

> Do you only ever have one top-level loop that you would be naming? If
no, unfortunately not. The rough structure is several loops deep, and
I need to break/continue/restart many of them.
Continue is used more than break, because most of the time that I find
some strange value, I'd just _continue_ a few levels up
to restart the current measurements.


for some configurations
while not enough data collected
while not in the right state
for steps  in steps to bring the system to the right state
if the system is bad, break out of all loops
if it just need to be reset, just redo the steps
if it is ok, go to the next while loop
while in the right state
steps to do some measurements
...



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


Re: fun with nested loops

2011-09-01 Thread Daniel
Hi Steve,

Thanks for your comments, I appreciate any input.
> Do you think the software in the Apple iPod is "simple"? Or Microsoft
No, that's much more complicated that what I am doing.
But the iPod probably (?) doesn't get new algorithms based on a
specification discussed with non-programmers once a month.

I didn't explain enough of what I am doing. This is a fairly complex
application that has been running for a few years now,
I am just trying to improve it. The code runs a big
test machine, that runs >10 individual tests in one run on
something like semiconductor chips.

The specification of these tests is already very complex, it has the
form of the nested loops,
for all these configurations try these steps, if they fail try them
again n times, if it still doesn't work give up
this configuration, if it works continue on to the next steps etc.
That's the form the specification is in, and it makes sense and is
very readable.
In pseudocode it looks like this, I am using @ to give loops a name:

@loop1
for c in configurations:
@loop2
while not_done:
@loop3
while step1_did_not_work:
@loop4
for substeps in step1 # loop 4a
if hopeless(): continue loop1 # run next configuration
if substepsFailed(): restart loop4 # try again
if substepsWorked(): break loop3 # go on to next
steps, like loop4

That format is fine, everyone involved can understand it, even the
people in charge. I'd like to make this executable without
changing too much of the form. It would be possible to do this as a
FSM, but then you'd loose the line to line correspondence with the
specification, and of course some errors always creep in.

> non-CS people to be hacking the source code, they only interact with the
This is a research setting, so the person running the machine will
have to change the source from time to time if
he gets a new specification. The specifications are far to complex to
be entered into a user interface because of all the loops.

> the code by splitting it into functions appropriately, instead of the
> spaghetti code you have (apparently) written with jumps all over the place.
I wouldn't call the example above spaghetti code in the sense of old
Fortran or Basic full of gotos.
In a language that can break out of nested loops this is highly
structured code.
I am not jumping forward to labels, not jumping into functions, not
using jumps to replace loops etc.

It is like the Fortran example (just to show the syntax, has an
infinite loop), everyone can understand that right away, even
non Fortran people:

10 loop1: do I=1,3
loop2: do J=1,4
print *,I,J
goto 10 ! redo loop1
cycle loop1
exit loop1
enddo loop2
enddo loop1

There is no wild jumping her. The only problem is that Fortran does
not allow to restart a loop, so instead of restart loop1 you have to
do a goto 10. Otherwise you could do entirely without gotos (like in
Ruby with the redo, which is of course much much better)

> To take the most obvious, simple example: any time you have a loop that you
> might want to redo, the right solution is to put the loop inside a
> function, and then "redo the loop" becomes "call the function again".
Doesn't work, because it can only redo one level, to break out of the
next loop, I'd need exceptions anyway.
And having all of these exceptions as gotos doesn't make it more
readable.
Replacing loop4 by a function makes it possible to replace the restart
loop4 by a return, but then I still need an exception to
continue loop1 and one to break out of loop4 to indicate that we can
go on to the next step.

> I suppose that, just possibly, your application really would benefit from
> named labels to jump to. But if so, you've stumbled across something rarer
> than iridium.

Don't think so. I am doing that all of the time in other languages,
and I am convinced the named loops (not raw labels+gotos, which are
just a necessary evil) are beautiful and clean things.
They have a lot of symmetry, break is always break, not sometimes
break, sometimes return and sometimes raise breakSomeLoopExcept().
Rewriting the simple Fortran example above in Python would be much,
much uglier and more difficult to comprehend.
You always call break and continue with a label, searching for that
label will tell you right away which loop the break breaks.
I am always doing that, even if there is only one loop. break and
continue (without label) are IMO (please no flame war about that)
worse than goto, at least the goto tells you where it goes, with break/
continue you always have to scan the surroundings to find the right
loop.

I know I am not the only one who is trying to solve that problem, I
was hoping someone has come up with a hack to solve it, like this goto
Chis has come up with. I have to play with that a bit.



Dan

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


Re: fun with nested loops

2011-09-01 Thread Daniel
I thought a bit about Carl's and Thomas' proposals, and it gave me an
idea how this problem could be approached:
Break is relatively easy to implement with a context manager that
returns an iterable that throws an exception specific to that context
manager:

with named_loop(i for i in range(10)) as loop1:
for i in loop1:
with named_loop(i for i in range(10)) as loop2a:
for j in loop2a:
loop1._break() # this is easy
loop1._continue() # this is difficult
# if we _continue here, we need to do a continue right
after the with loop2a:
if loop1.cont: continue # context manager does not create new
scope

with named_loop(i for i in range(10)) as loop2b:
for j in loop2b:
loop1._break()

this throws an exception that propagates through all the context
managers till it hits the one that made loop1
at that point the exception is caught.

Now using the idea of break_levels, something like loop1._continue()
should work.
It is more difficult, because it should be caught in the last loop
before the one that is targeted,
loop1._continue throws an exception that is caught in loop2. Then
loop1 just continues with the next value.

I don't know how loop2 can learn that it is enclosed in loop1. Maybe
loop1 could add itself to a global stack on enter
and delete itself on exit, or maybe inspect could help?

The big problem is that loop1._continue breaks out of loop2a, but then
starts to execute loop2b, which we don't want.
If loop1 is _continued inside of loop2a, a continue needs to directly
follow the loop2a with block.

An alternative would be to wrap each sequence of statements in another
with statement, I think this is better:

for i in loop1:
with sequenced_stuff():
with named_loop(i for i in range(10)) as loop2a:
for j in loop2a:
loop1._continue() # this is caught in
sequenced_stuff()

with named_loop(i for i in range(10)) as loop2b:
for j in loop2b:
loop1._break()


Loops can even be restarted with a small modification:
In a loop like "for i in loop1:" the __iter__ method of loop1 is
called. If __iter__ returns a smart iterator that keeps a reference to
loop1, then it can be restarted, advanced etc.
loop1.restart() would throw an exception that __exits__ all the inner
loops and gets caught in the loop just before loop1. Then it resets
the iterable that the iterator returned by __iter__ links to, i.e.
loop1 restarts.
Nice side benefit: loops can have a method peek(n) to look ahead.

Thanks for all your input,

Dan



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


Tkinter Progress Bar

2019-08-22 Thread Daniel
If i have a figure like 13247347347437x23828328382  how to make a 
progress bar in tkinter that shows the time the pc takes to give the result?


---
Este email foi escaneado pelo Avast antivírus.
https://www.avast.com/antivirus

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


Print to Paper

2019-10-04 Thread Daniel
How to do a code to print to paper?  please post here a "Hello World" 
code to be printed on paper with an inkjet.

Thanks
Daniel

---
Este email foi escaneado pelo Avast antivírus.
https://www.avast.com/antivirus

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


Python 3.8 install

2019-11-07 Thread Daniel

How to install Python 3.8 on top of Python 3.6?

--
Este email foi escaneado pelo Avast antivírus.
https://www.avast.com/antivirus

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


Re: Regular Expression for the special character "|" pipe

2014-05-27 Thread Daniel

What about skipping the re and try this:

'start=|ID=ter54rt543d|SID=ter54rt543d|end=|'.split('|')[1][3:]

On 27.05.2014 14:09, Vlastimil Brom wrote:

2014-05-27 12:59 GMT+02:00 Aman Kashyap :

I would like to create a regular expression in which i can match the "|" 
special character too.

e.g.

start=|ID=ter54rt543d|SID=ter54rt543d|end=|

I want to only |ID=ter54rt543d| from the above string but i am unable to write the  
pattern match containing "|" pipe too.

By default python treat "|" as an OR operator.

But in my case I want to use to as a part of search string.
--

Hi,
you can just escpape the pipe with backlash like any other metacharacter:

r"start=\|ID=ter54rt543d"

be sure to use the raw string notation r"...", or you can double all
backslashes in the string.

hth,
vbr


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


Mock return_value

2015-03-09 Thread Daniel
I have a dao.py module with a dao class declared and I want to use mock to set 
a return value for a dao function, dao.execute_ldap_search().

import mock
import unittest
import model, dao

class TestPeopleDAO(unittest.TestCase):

ldap_person_response = SOME_DICT

@mock.patch('dao.dao')
def test_find_by_last_first_comma(self, mock_dao):
# setup the mock
mock_dao.execute_ldap_search.return_value = self.ldap_person_response

persondao = dao.person_dao()
persondao.find_by_last_first_comma('name', '', '')
self.assertEqual(len(persondao),1,"Wrong number of objects returned.")
self.assertEqual(persondao[0].givenName, "FirstName", "Failed to parse 
response.")

if __name__ == '__main__':
unittest.main()

When I run this, it fails when calling execute_ldap_search because it really 
calls it. I was expecting it to just return the value I specified. What am I 
doing wrong?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Mock return_value

2015-03-09 Thread Daniel
I found that the following change worked:

@mock.patch('dao.dao.execute_ldap_search')
def test_find_by_last_first_comma(self, mock_dao):
# setup the mock
mock_dao.return_value = self.ldap_person_response

Daniel

On Monday, March 9, 2015 at 10:28:20 AM UTC-5, Daniel wrote:
> I have a dao.py module with a dao class declared and I want to use mock to 
> set a return value for a dao function, dao.execute_ldap_search().
> 
> import mock
> import unittest
> import model, dao
> 
> class TestPeopleDAO(unittest.TestCase):
> 
> ldap_person_response = SOME_DICT
> 
> @mock.patch('dao.dao')
> def test_find_by_last_first_comma(self, mock_dao):
> # setup the mock
> mock_dao.execute_ldap_search.return_value = self.ldap_person_response
> 
> persondao = dao.person_dao()
> persondao.find_by_last_first_comma('name', '', '')
> self.assertEqual(len(persondao),1,"Wrong number of objects returned.")
> self.assertEqual(persondao[0].givenName, "FirstName", "Failed to 
> parse response.")
> 
> if __name__ == '__main__':
> unittest.main()
> 
> When I run this, it fails when calling execute_ldap_search because it really 
> calls it. I was expecting it to just return the value I specified. What am I 
> doing wrong?

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


Re: Mock return_value

2015-03-09 Thread Daniel
On Monday, March 9, 2015 at 10:28:20 AM UTC-5, Daniel wrote:
> I have a dao.py module with a dao class declared and I want to use mock to 
> set a return value for a dao function, dao.execute_ldap_search().
> 
> import mock
> import unittest
> import model, dao
> 
> class TestPeopleDAO(unittest.TestCase):
> 
> ldap_person_response = SOME_DICT
> 
> @mock.patch('dao.dao')
> def test_find_by_last_first_comma(self, mock_dao):
> # setup the mock
> mock_dao.execute_ldap_search.return_value = self.ldap_person_response
> 
> persondao = dao.person_dao()
> persondao.find_by_last_first_comma('name', '', '')
> self.assertEqual(len(persondao),1,"Wrong number of objects returned.")
> self.assertEqual(persondao[0].givenName, "FirstName", "Failed to 
> parse response.")
> 
> if __name__ == '__main__':
> unittest.main()
> 
> When I run this, it fails when calling execute_ldap_search because it really 
> calls it. I was expecting it to just return the value I specified. What am I 
> doing wrong?

I ended up refactoring to setup patching once for a test class.

https://docs.python.org/3.5/library/unittest.mock-examples.html#applying-the-same-patch-to-every-test-method
-- 
https://mail.python.org/mailman/listinfo/python-list


issue with pexpect

2011-10-05 Thread Daniel
Hello,
For about week i am experiencing a problem with pexpect that's why i
hope you can help me :).
Following is my code which tries to remove some files from the root dir
and the code works on linux debian and freebsd but with no success on
linux fedora .. any idea why this happen only in fedora ?

#!/usr/bin/env python
from __future__ import print_function
import sys
import pexpect
import time

spa=pexpect.spawn('su root')
spa.expect('.*')
print(spa.after)
spa.sendline('abc')
spa.expect('.*')
print(spa.after)
spa.sendline('rm -rf /root/py/pe*')
spa.expect('.*')
print(spa.after)
spa.close()


this is the output in Fedora linux  it looks that the script can't
authenticate as root

python]$ ./sk64.py 
Password: 


rm -rf /root/py/pe*


i appreciate any help thanks in advance

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


issue with pexpect

2011-10-05 Thread Daniel
Hello,
For about week i am experiencing a problem with pexpect that's why i
hope you can help me :).
Following is my code which tries to remove some files from the root dir
and the code works on linux debian and freebsd but with no success on
linux fedora .. any idea why this happen only in fedora ?

#!/usr/bin/env python
from __future__ import print_function
import sys
import pexpect
import time

spa=pexpect.spawn('su root')
spa.expect('.*')
print(spa.after)
spa.sendline('abc')
spa.expect('.*')
print(spa.after)
spa.sendline('rm -rf /root/py/pe*')
spa.expect('.*')
print(spa.after)
spa.close()


this is the output in Fedora linux  it looks that the script can't
authenticate as root

python]$ ./sk64.py 
Password: 


rm -rf /root/py/pe*


i appreciate any help thanks in advance 

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


Re: issue with pexpect

2011-10-05 Thread Daniel
there is no such implementation in fedora you can su as a root .. i can
su from regular user to root with no problems 
the problem come when i use the pexpect module

On Wed, 2011-10-05 at 14:47 +0200, Nizamov Shawkat wrote:
> 2011/10/5 Daniel <5960...@gmail.com>:
> > Hello,
> > For about week i am experiencing a problem with pexpect that's why i
> > hope you can help me :).
> > Following is my code which tries to remove some files from the root dir
> > and the code works on linux debian and freebsd but with no success on
> > linux fedora .. any idea why this happen only in fedora ?
> >
> > #!/usr/bin/env python
> > from __future__ import print_function
> > import sys
> > import pexpect
> > import time
> >
> > spa=pexpect.spawn('su root')
> > spa.expect('.*')
> > print(spa.after)
> > spa.sendline('abc')
> > spa.expect('.*')
> > print(spa.after)
> > spa.sendline('rm -rf /root/py/pe*')
> > spa.expect('.*')
> > print(spa.after)
> > spa.close()
> >
> >
> > this is the output in Fedora linux  it looks that the script can't
> > authenticate as root
> >
> 
> Hi!
> 
> The problem may be that root user is disabled. This was introduced in
> Ubuntu long ago and I believe that later this was also accepted in
> Fedora. That means that you simply can not "su" to root, no matter
> what password you supply. This is the way how your OS operates and is
> not connected in any way to python or pexpect. Therefore, either use
> sudo (generally recommended) or enable root user (insecure!).
> 
> Hope it helps,
> S.Nizamov


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


Re: issue with pexpect

2011-10-05 Thread Daniel
Okey i figure it out how to do the job in fedora
i added slight delay before sending each command
either by the delaybeforesend attribute or by the time module
;)


cheers

On Wed, 2011-10-05 at 14:47 +0200, Nizamov Shawkat wrote:
> 2011/10/5 Daniel <5960...@gmail.com>:
> > Hello,
> > For about week i am experiencing a problem with pexpect that's why i
> > hope you can help me :).
> > Following is my code which tries to remove some files from the root dir
> > and the code works on linux debian and freebsd but with no success on
> > linux fedora .. any idea why this happen only in fedora ?
> >
> > #!/usr/bin/env python
> > from __future__ import print_function
> > import sys
> > import pexpect
> > import time
> >
> > spa=pexpect.spawn('su root')
> > spa.expect('.*')
> > print(spa.after)
> > spa.sendline('abc')
> > spa.expect('.*')
> > print(spa.after)
> > spa.sendline('rm -rf /root/py/pe*')
> > spa.expect('.*')
> > print(spa.after)
> > spa.close()
> >
> >
> > this is the output in Fedora linux  it looks that the script can't
> > authenticate as root
> >
> 
> Hi!
> 
> The problem may be that root user is disabled. This was introduced in
> Ubuntu long ago and I believe that later this was also accepted in
> Fedora. That means that you simply can not "su" to root, no matter
> what password you supply. This is the way how your OS operates and is
> not connected in any way to python or pexpect. Therefore, either use
> sudo (generally recommended) or enable root user (insecure!).
> 
> Hope it helps,
> S.Nizamov


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


what is the keyword "is" for?

2006-08-15 Thread daniel
I'm so confused by the keyword "is" and "==" equal sign, it seems they
could be exchanged in some contexts, but not in others, what's the
difference between them in terms of comparation?

thanks...

daniel

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


Re: what is the keyword "is" for?

2006-08-15 Thread daniel
many thanks to Sybren and Kirk for your helpful explanation.

when I tried to check the stuff out, found sth interesting that if you
define variables in a style like this:
a = b = ['a', 'b']
changing one list affects the other, and they still refer to same
object. in fact, seems all compound types (dictionary for instance)
behave in this way.

however, when list is replaced with other built-in  types like integers
:
a = b = 3
changing one of them cause the two objects differ...


best regards.

daniel

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


Re: what is the keyword "is" for?

2006-08-15 Thread daniel

Martin v. Löwis wrote:
> daniel wrote:
> > when I tried to check the stuff out, found sth interesting that if you
> > define variables in a style like this:
> > a = b = ['a', 'b']
> > changing one list affects the other, and they still refer to same
> > object. in fact, seems all compound types (dictionary for instance)
> > behave in this way.
> >
> > however, when list is replaced with other built-in  types like integers
> > :
> > a = b = 3
> > changing one of them cause the two objects differ...
>
> Ah, but make a difference between "change a variable", and "change an
> object".
>
> py> a = b = [1,2,3]
> py> a[0] = 6   # don't change the variable a, just change the object
> py> a
> [6, 2, 3]
> py> b
> [6, 2, 3]
> py> a=[7,8,9]  # change the variable a;
># it's now a different object than b
mm, python runtime might allocate a new chunk of memory for this... but
might not for the previous operation..
> py> a
> [7, 8, 9]
> py> b
> [6, 2, 3]
>
> For some objects, "change the object" is impossible. If you have
>
> a = b = 3
>
> then there is no way to change the object 3 to become 4 (say);
> integer objects are "immutable". So for these, to make a change,
> you really have to change the variable, not the value.
>
sounds reasonable, I tried tuple which is also immutable, it behaves
the same as integers. 

> Regards,
> Martin

tks Martin...

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


always raise syntax error!

2006-10-12 Thread daniel
I'm not quite new to this language, but such error has never happened
so frequently before. I have no idea what to do about it, because
there's actually no syntax error at all !!

I'm using python 2.4.3 on windows, with gvim..
I realize this might because of the tab and space, so I use listchars
in vim to all my tabs and trailing spaces visible, make sure they are
used consistently, but python still raise syntax error, no further
description, and just make no sense to me.

anyone heard of such issue or the like before?
many thanks

daniel

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


Re: always raise syntax error!

2006-10-13 Thread daniel
thank you so much for the reply.

I finally re-type all the codes where python would raise syntax error,
then fixed. I did not examine every single word of my old codes though,
 there might be some parenthesis not matching somewhere, I guess.

well, I would say, the reason why I could not position the error code
may partly due to the ambiguous message that python provides. the lines
that python pointed to contains no error,  I think the error codes must
be too far away from there. anyway, I hope python would make more
detailed error messages, like c++ compilers do. such as: "missing ;" or
"(" not matching...etc.

tks again..

daniel

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


is it possible to send raw data through ftp?

2006-10-19 Thread daniel
well, I'm trying to use ftplib to upload data that received from
socket, and the application is required to  restart the transfer at a
specific interval so as to generate a different target file on the
server to store subsequent data.

the problem is 'storbinary' accepts only file-like object, I have to
use socketobj.makefile() to do that, how can I stop and resume that
transfer then? the abort() generates lots of wierd and unexpected
behavior, I guess if there is a way to upload raw data buffer, the
restart action should be implemented more easily. 

thanks.

daniel

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


Re: is it possible to send raw data through ftp?

2006-10-19 Thread daniel


On Oct 20, 1:10 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> daniel wrote:
> > well, I'm trying to use ftplib to upload data that received from
> > socket, and the application is required to  restart the transfer at a
> > specific interval so as to generate a different target file on the
> > server to store subsequent data.
> > the problem is 'storbinary' accepts only file-like object"storbinary" works 
> > with anything that has a "read" method that takes a
> buffer size, so you can wrap the source stream in something like:
>
> ##
> # File wrapper that reads no more than 'bytes' data from a stream. Sets
> # the 'eof' attribute to true if the stream ends.
>
> class FileWrapper:
>  def __init__(self, fp, bytes):
> self.fp = fp
> self.bytes = bytes
>  self.eof = False
>  def read(self, bufsize):
> if self.bytes <= 0:
> return ""
> data = self.fp.read(min(bufsize, self.bytes))
>  if not data:
>  self.eof = True
> self.bytes -= len(data)
> return data
>
> source = open(...)
>
> while 1:
>  cmd = "STOR " + generate_file_name()
>  f = FileWrapper(source, 100)
>  ftp.storbinary(cmd, f)
>  if f.eof:
>  break
>
> 
I'm trying to understand your code, thank you so much for the help.

daniel

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


Network Simulator in Python

2006-10-23 Thread Daniel
Hi,

I was wondering if anybody can give me pointers on an existing network
simulator in Python somthing like ns2 which would model all the real
world internet dynamics including TCP stacks, congestion, flow control
etc.

Every help is appreciated,

Thanks

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


Re: Network Simulator in Python

2006-10-24 Thread Daniel
Any help ?


Daniel wrote:
> Hi,
>
> I was wondering if anybody can give me pointers on an existing network
> simulator in Python somthing like ns2 which would model all the real
> world internet dynamics including TCP stacks, congestion, flow control
> etc.
> 
> Every help is appreciated,
> 
> Thanks

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


Help on writing P2P Streaming client

2006-11-02 Thread Daniel
I want to write a P2P streaming client where ine user broadcasts and
many users receive the streaming content and forward like BitTorrent.

Can anybody provide pointers for starting in Python. I have done couple
of small projects in Python but I need to get this done.

Every help is appreciated.

Thanks

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


decimal by default

2006-06-28 Thread Daniel
I'm writing an application that (among other things) evaluates
mathematical expressions. The user enters strings containing literals
and names that later get evaluated using the Python interpreter. Here's
a short (very simplified) example:

>>> from decimal import Decimal
>>> names = dict(a=Decimal('3.625'), b=Decimal(2))
>>> expr = '(a + 2.625) / b' # expression entered by end-user
>>> eval(expr, names)
Traceback (most recent call last):
  ...
TypeError: You can interact Decimal only with int, long or Decimal data
types.

I understand why I got the error, so there's no need to explain that.
It is a requirement that the 'names' dict contains Decimal values. And
of course it's unacceptable to expect my users to enter Decimal('...')
every time they enter a non-integer number. My initial solutioin is to
use a regular expression to wrap each float value with Decimal('...')
before the expression is evaluated. But I don't like that solution for
two reasons:

1. It seems error prone and inelegant. Paraphrase: if you've got a
problem and you think "Ahh, I'll use regular expressions..." now you've
got two problems.

2. Error reporting is not as intuitive (I'm using the Python
interpreter and therefore my users see Python exceptions when their
expressions don't evaluate). After the expressions have been shot up
with all the extra Decimal junk to make them evaluate correctly they
are not nearly as recognizable (or easy to read) and the user is likely
to think "but I didn't even write that expression...where is that
Decimal('...') stuff coming from?"

Ideally I'd like to have a way to tell the interpreter to use Decimal
by default instead of float (but only in the eval() calls). I
understand the performance implications and they are of no concern. I'm
also willing to define a single global Decimal context for the
expressions (not sure if that matters or not). Is there a way to do
what I want without rolling my own parser and/or interpreter? Is there
some other alternative that would solve my problem?

Thanks,
~ Daniel

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


Re: decimal by default

2006-06-29 Thread Daniel
Alex Martelli wrote:
> What about:
>
> c = compile(thestring, thestring, '')
>
> cc = new.code( ...all args from c's attributes, except the 5th
>   one, constants, which should instead be:
>   decimalize(c.co_consts)...)

Wow, what an elegant solution! I had no hope that it would be this
simple. I always wondered what compile() was useful for and now I know
at least one thing. I'll try it out tomorrow. Thanks a lot Alex!

~ Daniel

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


Re: Libraries in python

2006-09-02 Thread Daniel
[EMAIL PROTECTED] wrote:
> Hy people, I'm new in python and comming from JAVA.
>
> Something I really like in java is the easy way to add a library to the
> project. Just put the jar file in the folder ( WEB-INF/lib ) and
> doesn't need to restart the server ( tomcat ).
>
> Can I do some like using python - I'm using apache mod_python?

I know exactly what you mean because I had the same question when I
came to Python from Java. What you're looking for is Python "eggs".
Unfortunately, they're a fairly new addition to the Python ecosystem
and they're not as nice/simple to use as jars. Here are a few of their
shortcomings:

1. not nearly all of the libraries that you may want to use are
distributed as eggs, so you may need to package them yourself, which
can be a pain. To be fair, this is not a shortcoming of eggs directly,
but rather a disadvantage of new technology--it's not ubiquitous yet.

2. you have to put them in the source root directory of the project so
they can be imported in all packages in the project. This seems to
clutter things up for me, and I'd rather have a project-local lib
directory in which to put them (I know that's possible with sys.path
hacks, but that's a hack, this should be standardized).

3. eggs only work well for python-only packages. In other words if the
library includes platform-specific binaries or other non-python-code
files then the egg must be unpacked for it to work. I really hate this
one because it means all those unpackaged files must be checked into
source control rather than just a single library archive file.

4. the seemingly "standard" place to deploy eggs is in the global
site-packages directory of your Python installation. That's terrible
because it makes it a pain to use different versions of a given package
in different projects. Yes, you can use the "setuptools.requires()"
function, but I want to deploy my apps without requiring those who
install it to download lots of dependencies to get it running (not to
mention I just want to use Python's standard "import", not some
non-standard "requires()" function). And yes, I know "requires()" is
supposed to automatically handle the dependencies too, but that just
seems too error prone because it makes too many assumptions about
resource availablitiy... all I want to do is bundle the library when I
deploy (preferably in the form of a single file).

That's my $0.02 on Python packaging and library dependencies. In my
opinion it's one of the few things that Java got right that Python
didn't.

~ Daniel

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


python threading

2006-09-13 Thread daniel
can someone give me a good threading tutorial
thx

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


ImportError: Don't know how to import XYZ (type code 3)

2006-09-19 Thread daniel
Trying to load a C++ module that is wrapped with boost_python and get
the error

ImportError: Don't know how to import XYZ (type code 3)

I think type code 3 is means that it is a C++ wrapped .pyd.

I have know idea what that means or how to fix it.

Any ideas?

D.

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


Python Threading

2006-09-20 Thread daniel
Hello,
Can anyone explain the main points in working with threads in Python.
Why use threading and not Thread.I have read an article that i have to
subclass the Thread class and override some function.

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


anybody using python 2.5 that raises error while importing?

2006-09-22 Thread daniel
there's a dll extension used to be imported with no error under version
2.4.3, but the new python complains that the name of the module can't
be found. seems not mentioned in the official documentation, any work
around to fix the issue without switching back to the old version?

tks..
daniel

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


Re: anybody using python 2.5 that raises error while importing?

2006-09-23 Thread daniel

John Machin wrote:
> daniel wrote:
> > there's a dll extension used to be imported with no error under version
> > 2.4.3, but the new python complains that the name of the module can't
> > be found. seems not mentioned in the official documentation, any work
> > around to fix the issue without switching back to the old version?
>
thank you for your reply..

> Did/does its name end in .dll or in .pyd?
It ends in .dll

> Have you procured a new one (necessary when there's a change of minor
> version number) and installed it in the right place?
My output of "python -V" shows 2.5c2

> Can you tell us the name of the module, and the path to the DLL/PYD
The dll is distributed with a third party library, it claimed to be
compatible with 2.4, It was installed at "d:\" on my box, and the path
had been added to my PYTHONPATH variable.

> that is/was imported by Python 2.4?
yep, it works very well with python 2.4, so, I'm just wondering if
there is a fix for using with 2.5

> Have you contacted the author(s) of the module?
uh.. not yet, because they clearly mentioned that in the doc.

> Have you installed Python 2.5 in its own directory e.g. c:\python25
> (the default)? Python 2.4, same question? Have you uninstalled 2.4?
I already uninstalled the version 2.4. and put python25 in drive "d:".
there's probably no problem with my environment variables, maybe I
should check for a updated version of python.

thanks again.

daniel 
> 
> Regards,
> John

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


Re: anybody using python 2.5 that raises error while importing?

2006-09-23 Thread daniel
thank you so much for your help..
I've got no idea about pyd or dll stuff, started to learn python just
several weeks ago.
so the implementation rules of python extension module must have been
changed, for now, I have to wait for the new release of that module and
switch back to python 2.4 to get my work done.

thanks again..

daniel

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


where the hell is the run command of PyPe editor?

2006-09-24 Thread daniel
I'm trying to use PyPe, but I just got so frustrated when attempting to
run a script, this is the very first feature I would use for an editor,
OMG. I browsed through every single menu item and gave up...

any help would be appreciated,  (the most silly question ever, sounds
like a new computer user. ;--()

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


where the hell is the run command of PyPe editor?

2006-09-24 Thread daniel
I'm trying to use PyPe, but I just got so frustrated when attempting to
run a script, this is the very first feature I would use for an editor,
OMG. I browsed through every single menu item and gave up...

any help would be appreciated,  (the most silly question ever, sounds
like a new computer user. ;--()

tks
daniel

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


why logging re-raise my exception and can't be caught?

2006-09-30 Thread daniel
I use a simple program to illustrate the problem:

import logging

def foo() :
raise ValueError("foo")

if __name__ == "__main__" :
try :
foo()
except ValueError :
logging.exception("caught here")  -- seems re-raise the
exception and can't be caught
print "caught here" --- just works.

I'm expecting the exception to be caught silently, and print the msg to
some place, if I comment out the logging statement, it just works, but
now, the stack trace is printed as if the except statement was not
there!!

how could this happen, just weird.. can I make the logging module
behave as I expected?

tks in advance.

daniel

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


Re: why logging re-raise my exception and can't be caught?

2006-09-30 Thread daniel
thank your so much firstly.

I feel really ashamed...

I think I did read through all examples and docs, but I just took for
granted that all the  info(), warning(), debug() like functions behaves
much alike except the level name.. so the description you listed really
was ignored,, 

tks again for your help.. I do appreciate it.

daniel

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


import cx_Oracle fails!

2005-05-18 Thread Daniel
Hello from Brazil :-)

I'm trying to bring cx_Oracle alive on my Python 2.4.1 @ HP-UX 11
(suckz) and Oracle 10.1.0 64bits without success

I've already tryied the suggestions from Bernard Delmée and Martin v.
Löwis (topic "Python 2.3b1 + cx_oracle 3.0 on HP-UX"), but it didn't
work, even when I recompiled Python with the "-lc -lpthread" options.
The result was:

>>> import cx_Oracle
/usr/lib/dld.sl: Can't shl_load() a library containing Thread Local
Storage: /usr/lib/libcl.2
/usr/lib/dld.sl: Exec format error
Traceback (most recent call last):
  File "", line 1, in ?
ImportError: Failed to load
/usr/local/lib/python2.4/site-packages/cx_Oracle.sl
>>>

Any other suggestion?

Thank you all in advance!

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


Re: import cx_Oracle fails!

2005-05-19 Thread Daniel
Yes dude, it worked! :-)

Thank you very much (Muito obrigado!!!)

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


Re: import cx_Oracle fails!

2005-05-19 Thread Daniel

And, completing my answer, I'm sending you all how I finally got the
Python 2.4.1 and cx_Oracle-4.1 running on my HP-UX (sukz) box:

Box: HP-UX B.11.11

Compiling Python 2.4.1 with gcc 3.4.3
=

./configure --with-libs='-lcl'

Added Makefile options:
CC= gcc -lc -lpthread

Changes on pyconfig.h:
Turn "#define _POSIX_THREADS" on


Compiling cx_Oracle-4.1:
===

Make sure to setup Oracle variables:

setenv ORACLE_HOME /oracle10/product/10.1.0
setenv ORACLE_BASE /oracle10
setenv TMPDIR /var/tmp
setenv PATH ${PATH}:$ORACLE_HOME/bin
setenv LD_LIBRARY_PATH $ORACLE_HOME/lib32
setenv SHLIB_PATH $ORACLE_HOME/lib32
setenv TNS_ADMIN $ORACLE_HOME/network/admin

Changes on setup.py:
from: libPath = os.path.join(oracleHome, "lib")
to:   libPath = os.path.join(oracleHome, "lib32")


And finally:

$ python
Python 2.4.1 (#20, May 18 2005, 20:33:21)
[GCC 3.4.3] on hp-ux11
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>> dir(cx_Oracle)
['BINARY', 'BLOB', 'CLOB', 'CURSOR', 'Connection', 'Cursor',
'DATETIME', 'DataError', 'DatabaseError', 'Date', 'DateFromTicks',
'Error', 'FIXED_CHAR', 'FNCODE_BINDBYNAME', 'FNCODE_BINDBYPOS',
'FNCODE_DEFINEBYPOS', 'FNCODE_STMTEXECUTE', 'FNCODE_STMTFETCH',
'FNCODE_STMTPREPARE', 'IntegrityError', 'InterfaceError',
'InternalError', 'LOB', 'LONG_BINARY', 'LONG_STRING', 'NUMBER',
'NotSupportedError', 'OperationalError', 'ProgrammingError', 'ROWID',
'STRING', 'SYSDBA', 'SYSOPER', 'SessionPool', 'TIMESTAMP', 'Time',
'TimeFromTicks', 'Timestamp', 'TimestampFromTicks', 'UCBTYPE_ENTRY',
'UCBTYPE_EXIT', 'UCBTYPE_REPLACE', 'Warning', '__doc__', '__file__',
'__name__', 'apilevel', 'buildtime', 'connect', 'makedsn',
'paramstyle', 'threadsafety', 'version']
>>>

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


Re: import cx_Oracle fails!

2005-05-25 Thread Daniel
Hi Bernard

My system is a PA 8K series with 4096 MB and 2 processors, running 64
bit mode OS.

I only created the recipe above after 1 week of mistakes :-), but I
don't know if it will work with your branch of patches @ 11.23 version.


I really hate HP-UX >-(, god bless BSD!!! :-D

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


Changing entities

2005-06-08 Thread Daniel
Hello all

I need to build a program that check the sintax in a line:

SIZE (1 BYTE)

and change the correct number of bytes to the following format:

SIZE(1)

without the "BYTE" word. But, the number of bytes can be over 3 digits,
and the entitie can't have spaces but the correct number of bytes in
parentheses, like "SIZE (1024 BYTE)" to "SIZE(1024)".

Does anyone already done this or similar sintax using re?

Thank you

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


Re: Changing entities

2005-06-09 Thread Daniel
Hi Kent

Thanks for your help, it worked sucessfully. I have another question, I
think it is a stupid and simple but...

I need match a regular expression, change it erasing the other strings
after this. Just like:

a = "I'm going send to out of space, find another race"

And I want to match "space" instance, and erase the other.

Thank you

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


Re: Changing entities

2005-06-10 Thread Daniel
Hi Kent

This isn't work with the following line:
FieldGraphic56::=   GraphicString EBCDIC BC= " " SIZE (56
BYTES)

>>> byter = re.compile(r'SIZE \((\d+) BYTE\)')
>>> s = 'SIZE (1 BYTE)'
>>> byter.sub(r'SIZE(\1)', s)
'SIZE(1)'
>>> byter.sub(r'SIZE(\1)', line)
'FieldGraphic56::=   GraphicString EBCDIC BC= " " SIZE (56
BYTES)'
>>> line
'FieldGraphic56::=   GraphicString EBCDIC BC= " " SIZE (56
BYTES)'
>>>

Any idea? :-p

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


Re: Changing entities

2005-06-10 Thread Daniel
Hi Kent

This isn't work with the following line:
FieldGraphic56::=   GraphicString EBCDIC BC= " " SIZE (56
BYTES)

>>> byter = re.compile(r'SIZE \((\d+) BYTE\)')
>>> s = 'SIZE (1 BYTE)'
>>> byter.sub(r'SIZE(\1)', s)
'SIZE(1)'
>>> byter.sub(r'SIZE(\1)', line)
'FieldGraphic56::=   GraphicString EBCDIC BC= " " SIZE (56
BYTES)'
>>> line
'FieldGraphic56::=   GraphicString EBCDIC BC= " " SIZE (56
BYTES)'
>>>

Any idea? :-p

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


using Mac OS X CoreGraphics via ctypes

2007-06-14 Thread Daniel
I'm trying to implement a routine that converts a PDF document to
image files using ctypes and the Apple CoreGraphics library as per the
'Splitting a PDF File' example on Apple's web site [0]. Unfortunately
I cannot use the CoreGraphics module used in that example because I'm
using Python 2.5 (AFAIK that module is only available in the system
default Python 2.3.5). There are three questions in the code snippet
below. Each problem area has been commented out in the example so it
runs through to the end. The code is obviously not complete, but it's
enough do demonstrate my problems so far.

BTW, this is the only way I have found to convert a PDF (generated by
ReportLab) to an image that can be fed into a PyQt (v3) QPrinter
object. If anyone knows another way to gain access to the system print
services on Mac OS X using Python please do tell. Oh yes, I'd rather
not include PyObjC because I'm already packaging PyQt, and that would
make the resulting app a lot bigger.

# BEGIN CODE
from ctypes import cdll, c_void_p
from ctypes.util import find_library

cglib = cdll.LoadLibrary(find_library('ApplicationServices'))

# the next line causes a segfault - what's the right way to do this?
#GCS_RGB = cglib.kCGColorSpaceGenericRGB()
#cs = cglib.CGColorSpaceCreateWithName(GCS_RGB)

# the next line causes the following error:
#CGPDFDocumentRef = cglib.CGPDFDocumentRef
# AttributeError: dlsym(0x1018c0, CGPDFDocumentRef): symbol not found

CGPDFDocumentCreateWithProvider =
cglib.CGPDFDocumentCreateWithProvider
CGPDFDocumentCreateWithProvider.restype = c_void_p #CGPDFDocumentRef

provider = cglib.CGDataProviderCreateWithFilename("sample.pdf")
pdf = CGPDFDocumentCreateWithProvider(provider)

#for page in xrange(1, pdf.getNumberOfPages() + 1):
#print page
# pdf.getNumberOfPages caues the following error:
# AttributeError: 'int' object has no attribute 'getNumberOfPages'
# I presume the 'pdf' object is a pointer. How do I get a real
# CGPDFDocuemnt instance that has a getNumberOfPages method?

cglib.CGPDFDocumentRelease(pdf)
# END CODE

[0] Splitting a PDF File <http://developer.apple.com/graphicsimaging/
pythonandquartz.html>

Thanks in advance for any hints you can provide.

~ Daniel

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


Re: using Mac OS X CoreGraphics via ctypes

2007-06-15 Thread Daniel
> > # the next line causes a segfault - what's the right way to do this?
> > #GCS_RGB = cglib.kCGColorSpaceGenericRGB()
>
> Usually, things in the OSX lib that start with k* are a constant - not a
> function. As is this.
>
> Diez

That's what I thought too. But when I try passing it directly as if it
were a constant:

GCS_RGB = cglib.kCGColorSpaceGenericRGB
cs = cglib.CGColorSpaceCreateWithName(GCS_RGB)

I get a segfault too. ctypes said kCGColorSpaceGenericRGB was a
function pointer, so I thought maybe I needed to call it to get the
value (not very good reasoning, I know).

~ Daniel

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


Re: using Mac OS X CoreGraphics via ctypes

2007-06-18 Thread Daniel
On Jun 18, 6:07 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Daniel wrote:
> >> > # the next line causes a segfault - what's the right way to do this?
> >> > #GCS_RGB = cglib.kCGColorSpaceGenericRGB()
>
> >> Usually, things in the OSX lib that start with k* are a constant - not a
> >> function. As is this.
>
> >> Diez
>
> > That's what I thought too. But when I try passing it directly as if it
> > were a constant:
>
> > GCS_RGB = cglib.kCGColorSpaceGenericRGB
> > cs = cglib.CGColorSpaceCreateWithName(GCS_RGB)
>
> > I get a segfault too. ctypes said kCGColorSpaceGenericRGB was a
> > function pointer, so I thought maybe I needed to call it to get the
> > value (not very good reasoning, I know).
>
> I'm not sure what that constant exported is - but how about looking the
> constant up in the ref docs and pass it as value? Usually these thingies
> are some 4-byte-string, or a normal zero-terminated one.
>

Thanks Diez. I'll try that if I decide to keep going with ctypes. I
got a bit further but had some problems with memory management (i.e.
retaining and releasing object references). It seemed like Python/
ctypes was accessing referenced objects after I had released them,
which caused segfaults. I may resort to writing an extension in C that
will handle the entire print process for me rather than fiddling
around with something that gets me half way there. For anyone
interested, here is the code I ended up with:


from ctypes import cdll, cast, c_void_p
from ctypes.util import find_library
cglib = cdll.LoadLibrary(find_library("ApplicationServices"))

CFStringRef = c_void_p

CGColorSpaceCreateWithName = cglib.CGColorSpaceCreateWithName
CGColorSpaceCreateWithName.restype = c_void_p
CGColorSpaceCreateWithName.argtypes = [CFStringRef]

CGPDFDocumentCreateWithProvider =
cglib.CGPDFDocumentCreateWithProvider
CGPDFDocumentCreateWithProvider.restype = c_void_p

provider = cglib.CGDataProviderCreateWithFilename("sample.pdf")
if provider:
BMP_INFO = cglib.kCGBitmapByteOrderDefault
CS_RGB = cast(cglib.kCGColorSpaceGenericRGB, CFStringRef)

#cs = CGColorSpaceCreateWithName(CS_RGB) # segfault
pdf = CGPDFDocumentCreateWithProvider(provider)
npages = cglib.CGPDFDocumentGetNumberOfPages(pdf)

for pnum in xrange(1, npages + 1):
print "processing page", pnum
page = cglib.CGPDFDocumentGetPage(pdf, pnum)
rect = cglib.CGPDFPageGetBoxRect(page, 0) # kCGPDFMediaBox = 0
page_w = cglib.CGRectGetWidth(rect)
page_h = cglib.CGRectGetHeight(rect)

# incorrect constructor for bitmap
#bitmap = cglib.CGBitmapContextCreate(None, page_w, page_h,
cs, BMP_INFO)
    #cglib.CGContextDrawPDFDocument(bitmap, rect, pdf, pnum)

#cglib.CGPDFDocumentRelease(pdf) # segfault
#cglib.CGColorSpaceRelease(cs)
cglib.CGDataProviderRelease(provider)

~ Daniel

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


Re: Pretty Printing Like Tidy for HTML

2007-07-07 Thread Daniel
On Sat, 07 Jul 2007 21:35:40 +0300, David <[EMAIL PROTECTED]>  
wrote:

>
> All,
>
> Is there a pretty printing utility for Python, something like Tidy for
> HTML?
>
> That will change:
>
> xp=self.uleft[0]+percentx*(self.xwidth)
>
> To:
>
> xp = self.uleft[0] + percentx * (self.xwidth)
>
> And other formatting issues.
>

Why not just write python as it should be written?

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is the most efficient way to test for False in a list?

2007-07-08 Thread Daniel
On Mon, 09 Jul 2007 06:21:31 +0300, Simon Forman <[EMAIL PROTECTED]>  
wrote:

>
> On Jul 8, 7:43 pm, lex <[EMAIL PROTECTED]> wrote:
>> Of course there is the always the iteration method:
>>
>> list = [1, True, True, False, False, True]
>> status = True
>> for each in list:
>> status = status and each
>>
>> but what is your best way to test for for False in a list?
>
>
> False in list
>
>

all() is slightly faster


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: bool behavior in Python 3000?

2007-07-10 Thread Daniel
>>  > Do you care to explain what is broken?
>>  My preference would be for the arithmetic operations *,+,-
>> to be given the standard interpretation for a two element
>> boolean algebra:
>> http://en.wikipedia.org/wiki/Two-element_Boolean_algebra
>
> If I understand this right, the biggest difference from the current  
> implementation would be that::
>
>  True + True == True
>
> instead of:
>
>  True + True == 2
>
> What's the advantage of that? Could you give some use cases where that  
> would be more useful than the current behavior?
>

I prefer the use of 'and' and 'or', and they feel more pythonic than & and  
+

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting values out of a CSV

2007-07-12 Thread Daniel
On Fri, 13 Jul 2007 05:59:53 +0300, <[EMAIL PROTECTED]> wrote:

>
> How do I access the value in the second row in the first position of a
> CSV? Or the 3rd row, in the fifth position?
>
> a,b,c,d,e,f,g,h,i
> j,k,l,m,n,o,p,q,r
> r,s,t,v,w,x,y,z
>
> I'd want to get at "j" and "w". I know I can do
>
> import csv
> reader = csv.reader(open("some.csv", "rb"))
> for row in reader:
> print row[0]
>
> to get the first value in EVERY row, but I don't want that. Thanks for
> the help.
>

data = [row for row in csv.reader(open('some.csv', 'rb'))

then you can access like so:

>>> data[1][4]
'n'
>>> data[0][0]
'a'
>>> data[2][0]
'r'

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting values out of a CSV

2007-07-12 Thread Daniel
On Fri, 13 Jul 2007 08:51:25 +0300, Gabriel Genellina  
<[EMAIL PROTECTED]> wrote:
>> data = [row for row in csv.reader(open('some.csv', 'rb'))
>
> Note that every time you see [x for x in ...] with no condition, you can  
> write list(...) instead - more clear, and faster.
>
> data = list(csv.reader(open('some.csv', 'rb')))

Clearer? Maybe, but list comprehensions are clearer (at least for me)

Faster? No. List Comprehensions are faster.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting values out of a CSV

2007-07-13 Thread Daniel
>> > Note that every time you see [x for x in ...] with no condition, you  
>> can
>> > write list(...) instead - more clear, and faster.
>> >
>> > data = list(csv.reader(open('some.csv', 'rb')))
>>
>> Faster? No. List Comprehensions are faster.
>
> [EMAIL PROTECTED] pdfps $ python -m timeit -c 'data = list(open("make.ps"))'
> 100 loops, best of 3: 7.5 msec per loop
> [EMAIL PROTECTED] pdfps $ python -m timeit -c 'data = [line for line in
> open("make.ps")]'
> 100 loops, best of 3: 9.2 msec per loop
>
> On my system just putting into a list is faster.  I think this is
> because you don't need to assign each line to the variable 'line' each
> time in the former case.
>
> I, too, think it's faster to just use list() instead of 'line for line
> in iterable', as it seems kind of redundant.
>

$ python -m timeit -c 'import csv; data = list(csv.reader(open("some.csv",  
"rb")))'
1 loops, best of 3: 44 usec per loop
$ python -m timeit -c 'import csv; data = [row for row in  
csv.reader(open("some.csv", "rb"))]'
1 loops, best of 3: 37 usec per loop

I don't know why there seems to be a differece, but I know that list comps  
are python are very heavily optimised.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting values out of a CSV

2007-07-13 Thread Daniel
On Fri, 13 Jul 2007 16:18:38 +0300, Marc 'BlackJack' Rintsch  
<[EMAIL PROTECTED]> wrote:
>> $ python -m timeit -c 'import csv; data =  
>> list(csv.reader(open("some.csv",
>> "rb")))'
>> 1 loops, best of 3: 44 usec per loop
>> $ python -m timeit -c 'import csv; data = [row for row in
>> csv.reader(open("some.csv", "rb"))]'
>> 1 loops, best of 3: 37 usec per loop
>>
>> I don't know why there seems to be a differece, but I know that list  
>> comps
>> are python are very heavily optimised.
>
> Does the machine use power saving features like SpeedStep or
> something similar, i.e. runs the processor always with 100% speed or is  
> it
> dynamically stepped if there's load on the processor?  Do both tests read
> the data always from cache or has the very first loop had to fetch the  
> CSV
> file from disk?
>
> $ python -m timeit -n 1000 -c 'import csv; data = [row for row in
> csv.reader(open("test.csv", "rb"))]' 1000 loops, best of 3: 1.27 msec per
> loop
>
> $ python -m timeit -n 1000 -c 'import csv; data =
> list(csv.reader(open("test.csv", "rb")))' 1000 loops, best of 3: 1.25  
> msec
> per loop

No SpeedStep - tried a few repeats just in case files were cached,  
consistent 35usec for comp 40usec for list

Python 2.5.1 on Linux 1.2ghz

Even replacing the csv lookup with a straight variable declaration:  
[range(10)*3], same results

Weird.

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


Re: NoneType object not iterable

2007-07-13 Thread Daniel
On Fri, 13 Jul 2007 20:44:13 +0300, <[EMAIL PROTECTED]> wrote:

>
> Hi!
> My code is
>
>  > db = {}
>  >
>> def display():
>> keyList = db.keys()
>> sortedList = keyList.sort()
>> for name in sortedList:
>> line = 'Name: %s, Number: %s' % (name, db[name])
>> print line.replace('\r', '')
>
> And it gives following error:
>
>> for name in sortedList:
>> TypeError: 'NoneType' object is not iterable
>
> How can sortedList variable turn into NoneType? I just don't get it...

db is out of scope, you have to pass it to the function:
>> def display(db):
>> keyList = db.keys()
>> sortedList = keyList.sort()
>> for name in sortedList:
>> line = 'Name: %s, Number: %s' % (name, db[name])
>> print line.replace('\r', '')


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NoneType object not iterable

2007-07-13 Thread Daniel
On Fri, 13 Jul 2007 21:13:20 +0300, Bjoern Schliessmann  
<[EMAIL PROTECTED]> wrote:

>
> Daniel wrote:
>
>> db is out of scope, you have to pass it to the function:
>
> What's wrong about module attributes?
>

I made a mistake
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamic method

2007-07-16 Thread Daniel
Bruno Desthuilliers wrote:
>
> > Another way is to use the 'types' module:
>
> True - and that's somewhat cleaner since it doesn't expose the internals
> of the descriptor protocol. OTHO, it can lead to strange results with
> callables not implementing the descriptor protocol:



Actually, the result is not "strange" at all if you understand what's
going. The reason you got an exception is because your __call__()
method only takes a single argument (the implicit self argument, which
is the instance of MyCallable). However, if you define it with two
arguments it works just fine:

>>> class MyCallable(object):
... def __call__(self, inst):
... print self, inst
...
>>> class Foo(object):
... pass
...
>>> fun = MyCallable()
>>> f = Foo()
>>> f.fun = types.MethodType(fun, f, Foo)
>>> f.fun()
<__main__.MyCallable object at 0x648d0> <__main__.Foo object at
0x64810>
>>>

~ Daniel

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


Re: a=0100; print a ; 64 how to reverse this?

2007-07-17 Thread Daniel
On Tue, 17 Jul 2007 14:09:35 +0300, mosi <[EMAIL PROTECTED]> wrote:

>
> Problem:
> how to get binary from integer and vice versa?
> The simplest way I know is:
> a = 0100
> a
> 64
>
> but:
> a = 100 (I want binary number)
> does not work that way.
>
> a.__hex__   exists
> a.__oct__ exists
>
> but where is a.__bin__ ???
>
>
> What`s the simplest way to do this?
> Thank you very much.
>
Write your own?

something like:

def bin(x):
  from math import log
  bits = (8 if x == 0 else 8*(int(log(x)/log(2))/8+1))
  return ''.join([str((x >> i) & 1) for i in range(bits)[::-1]])

though that's probably slow :/


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a=0100; print a ; 64 how to reverse this?

2007-07-17 Thread Daniel
On Tue, 17 Jul 2007 14:09:35 +0300, mosi <[EMAIL PROTECTED]> wrote:

>
> Problem:
> how to get binary from integer and vice versa?
> The simplest way I know is:
> a = 0100
> a
> 64


Also that is not binary - that is octal, binary would be: '0100'  
(denoted as a string, since 0100 in octal is actually 262144 in  
decimal.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a=0100; print a ; 64 how to reverse this?

2007-07-17 Thread Daniel
On Tue, 17 Jul 2007 21:22:03 +0300, Wildemar Wildenburger  
<[EMAIL PROTECTED]> wrote:

>
> Bruno Desthuilliers wrote:
>> mosi a écrit :
>>
>>> Problem:
>>> how to get binary from integer and vice versa?
>>> [snip]
>>> What`s the simplest way to do this?
>>>
>>
>> [EMAIL PROTECTED]:~$ python
>> Python 2.5.1 (r251:54863, May  2 2007, 16:56:35)
>> [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>>  >>> help(int)
>> Help on class int in module __builtin__:
>>
>> class int(object)
>>   |  int(x[, base]) -> integer
>>
>
> :D
>
> After reading the other two replies, this one made me burst with  
> laughter. Thanks for that.

Why exactly?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: accessing javascript variables within psp code

2007-07-17 Thread Daniel
On Wed, 18 Jul 2007 04:29:27 +0300, BAnderton <[EMAIL PROTECTED]>  
wrote:

>
> Hello all,
>
> Question:  Is there any way to access a javascript variable from
> within psp code?
>
>
> I'm aware of how to do the reverse of this (js_var='<%=psp_var%>').
>
>
> Here's a non-working example of what I'm trying to do:
>
>
> - - - (begin example) - - -
>
>
> function Test(txt)
> {
> a = confirm('Are you sure you want to delete '+txt+'?')
> if (a)
> {
> //The problem is getting the value of js variable 'txt' recognized in
> "psp space".
> <%
> os.remove(  os.path.join(os.path.dirname(req.filename), '../notes/'+
> %>txt<%)  )
> %>
>
>
> }
> }
>
>
> - - - (end example) - - -
>
> FYI, I've already found a workaround for the above example (by placing
> a "get" variable in the URL, reloading the page, and having psp check
> for the existence of that variable before proceeding with deleting the
> appropriate file) but I'd still like this general capability for
> future projects.  I've searched several forums, websites, etc. and
> the
> answer has aluded me for two days now.  I'm new to apache, mod_python,
> and javascript, so this may be ridiculously simple.
>
> Since this is my first post on google groups, I'd also appreciate any
> helpful suggestions on how to best go about getting answers quickly
> (so let me know if there's a more appropriate forum/method/etc.)
>
> Thanks for any help you can provide.
>
>
>
> (This is copied from a message I originally posted to the mod_python
> group.)
>

Only with ajax.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sort lines in a text file

2007-07-22 Thread Daniel
On Sun, 22 Jul 2007 06:03:17 +0300, leegold <[EMAIL PROTECTED]> wrote:
> say I have a text file:
>
> zz3 uaa4a ss 7 uu
>   zz 3 66 ppazz9
> a0zz0
>
> I want to sort the text file. I want the key to be the number after
> the two "zz".  Or I guess a string of two zz then a numberSo
> that's 3, 9, 0
>
> I'm trying to say that I want to sort lines in a file based on a
> regular expression. How could I do that in Python? I'm limited to
> Python 2.1, I can't add any 2nd party newer tools.

Do your own homework.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sort lines in a text file

2007-07-22 Thread Daniel
On Sun, 22 Jul 2007 06:03:17 +0300, leegold <[EMAIL PROTECTED]> wrote:
> say I have a text file:
>
> zz3 uaa4a ss 7 uu
>   zz 3 66 ppazz9
> a0zz0
>
> I want to sort the text file. I want the key to be the number after
> the two "zz".  Or I guess a string of two zz then a numberSo
> that's 3, 9, 0
>
> I'm trying to say that I want to sort lines in a file based on a
> regular expression. How could I do that in Python? I'm limited to
> Python 2.1, I can't add any 2nd party newer tools.
>
> Thanks
> Lee G.
>

Shouldn't it be 3, 6, 9, 0
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why PHP is so much more popular for web-development

2007-07-25 Thread Daniel
On Wed, 25 Jul 2007 20:42:54 +0300, walterbyrd <[EMAIL PROTECTED]>  
wrote:

> I'm fairly new to web-development, and I'm trying out different
> technologies. Some people wonder why PHP is so popular, when the
> language is flawed in so many ways. To me, it's obvious: it's because
> it's much easier to get started with PHP, and once somebody gets
> started with a particular language, that person is likely to stay with
> that language.

I think Python is the computer scientist based language, whereas PHP is  
for weekend hobbyists. Not to say you can't produce serious code with PHP  
(or quick and dirty code with Python).

Having used both, I can tell you that Python will take 10 times the  
initial effort to produce the same functionality as a PHP implementation -  
since Python programmers will not opt for quick hacks and workarounds like  
PHP coders will. The trade off however is that Python code is much more  
readable and 100 times more maintainable in the long run, which I consider  
more important.

However this is the problem: Web Development is not about being perfect,  
it's about getting your application to production as quick as possible,  
worrying about bugs and added functionality later on. No good putting your  
idea on the web 6 months after your competitor has taken all the market  
share. PHP lets you do this very quickly, Python does not. I find myself  
trying to 'finish' the Python app whereas in PHP I would have already gone  
live.

Today I've found the best approach for me is a hybrid solution. Since  
database models are quite definitive - it doesn't matter if I use PHP or  
Python, the underlying datastructure for my app won't change. Therefore,  
using a library of custom helpers and framework-like tools for PHP, I can  
create a working site in less than a couple days in PHP. This is made live.

Then I have the time to rewrite the app in Python, which will take me a  
couple weeks, but due to the much better language properties of Python,  
will mean that I can also maintain it a year after writing it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: defaultdict of arbitrary depth

2007-08-21 Thread Daniel
Any reason why this wouldn't work?

>>> from collections import defaultdict
>>> def rdict(*args, **kw):
... return defaultdict(rdict, *args, **kw)
...
>>> d = rdict()
>>> d[1][2][3][4][5] # ...
defaultdict(, {})


~ Daniel

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


Re: IEC - cannot find button

2007-10-29 Thread daniel
On Oct 29, 6:04 am, [EMAIL PROTECTED] wrote:
> On Oct 29, 12:58 am, [EMAIL PROTECTED] wrote:
>
>
>
> > I'm brand new to Python--and programming in general. I'm trying to use
> > IEC to control Internet Explorer. I've navigated to a page, and now
> > I'm trying to click a button. The button appears to be called 'PDF
> > Preview' but I honestly do not know whether that's the name or the
> > caption. Here is my code:
>
> >  from win32com.client import Dispatch
> >  import IEC
>
> >  .
> >  .
> >  .
>
> >  ie = IEC.IEController(window_num = 1)
> >  ie.Navigate(URL_part_1 + x + URL_part_2)
> >  ie.ClickButton(name='PDF Preview')
>
> > (I've also tried replacing name w/ caption but I get a similar error
> > message.) I get this error message:
>
> > Traceback (most recent call last):
> >   File "C:\Program Files\Python25\experiment", line 14, in 
> > ie.ClickButton(name='PDF Preview')
> >   File "C:\Program Files\Python25\lib\IEC.py", line 126, in
> > ClickButton
> > elem = elemcoll.item(i)
> >   File ">", line 3, in item
> > com_error: (-2147024891, 'Access is denied.', None, None)
>
> > I really have no idea how to interpret this. I'm pasting the button
> > tag below:
>
> > 
> >   > onclick="javascript:performPdfPreview(2);"/>
> > 
>
> You might want to look at PAMIE instead. It sounds like a Python
> project that's aimed at automating Internet 
> Explorer:http://sourceforge.net/projects/pamie/
>
> But if you really like COM, I found this tutorial:
>
> http://www.evilbitz.com/2006/10/22/python-ie-automation-thorough-tuto...
>
> I'm not very good with COM, but I would recommend that you do some
> research on it. From the traceback, I would guess that you don't have
> administrator privileges (of some sort) on the machine you're running
> the script on.
>
> Mike

Thanks for the input, Mike. Since I don't have much experience w/
either, I don't have a strong preference for COM over PAMIE. I'm just
frustrated my script isn't working. I guess it could have to do w/
privileges. I'm using a VPN connection. I tried turning off my
antivirus software before running the module. I can click on the
button I want manually, and get the page I need, so I wonder if I can
adjust some settings to allow Python to take control of certain
things? That or I thought it might have to do w/ a javascript error.
By looking at the tag, does 'PDF Preview' look like the name of the
button or the button caption? Let me know what you think.

Daniel

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


trouble with PAMIE

2007-10-29 Thread daniel
I'm using PAMIE to automate some web browsing. My problem is with the
buttonClick() method. It seems to work unless the button is supposed
to open a new window, in which case nothing happens. There is no error
message. Any ideas?

Daniel

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


trouble with PAMIE

2007-10-29 Thread daniel
I'm trying to use PAMIE to automate some web browsing. My problem is
with the buttonClick() method; it seems to work unless the button is
supposed to open a new window. Specifically, the button is supposed to
open a PDF Preview in a new window. Any ideas?

Daniel

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


trouble with PAMIE

2007-10-29 Thread daniel
I'm trying to use PAMIE to automate some web browsing. My problem is
with the buttonClick() method; it doesn't seem to work when the button
is supposed to open a new window. For example, I can use it to submit
a username and password and advance to the next page but it fails on a
button that opens a PDF Preview in a new window. There is no error
message. Any ideas?

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


Re: My python programs need a GUI, wxPython or PyQt4?

2007-01-23 Thread Daniel
I've downloaded both the wxPython and the PyQt4 package, and by the 
first impression I must say that the PyQt4 system had a very 
compelling presentation. From what I can understand from the feedback 
I've gotten so far is that the wxPython is a better choice when it 
comes to compability (with linux), and it's free even if I want to 
create applications and sell them.
So, from what I understand I will have to go with PyQt4 since (from 
my understanding):
1. I will not sell the applications I'm working with since they will 
only be used by the internal QA at a computer game company. 
2. There seems to be a lot of documentation available for PyQt4. 
3. PyQt4 seems to be easier to learn.
4. My programs does not need to support Linux or Unix. 
Or am I wrong? Flame people, for the love of God, flame!! :)

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


Re: While loop with "or"? Please help!

2007-01-25 Thread Daniel
2007-01-25 11:26:09
[EMAIL PROTECTED] wrote in message
<[EMAIL PROTECTED]>

> Hmm, my while loop with "or" doesn't seem to work as I want it to...

> How do I tell the while loop to only accept "Y" or "y" or "N" or 
"n"
> input from the str(raw_input)?
> 
> Thank's in advance!
> 
> Snippet of code:
> 
> import os
> 
> def buildfinder():
> os.system("CLS")
> GameRoot = os.getenv("GAME_ROOT") + "\\"
> 
> print "Do you want to use " + GameRoot + " as your source
> directory?"
> usr = str(raw_input('Y/N: '))
> return usr
> 
> #Runs the buildfinder function
> usrinp = buildfinder()
> 
> def buildwhiler():
> 
> while usrinp != "y" or "Y" or "N" or "n": PROBLEM
> print "Enter Y or N!"
> usr = str(raw_input('Y/N: '))
> else:
> code continues

Thanks for the help everyone! :)
This forum rules!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: running applications in python

2007-01-25 Thread Daniel
2007-01-25 18:28:44
lee <[EMAIL PROTECTED]> wrote in message
<[EMAIL PROTECTED]>

> how can i run or open a windows application from the python 
prompt?for
> e.g.mediaplayer opening,folder acess etc

Here's another way of doing it:
import os 
TheCommandIwantTorun = '"C:\Program\Windows Media Player\wmplayer.
exe"' #saves the command to a string 
os.system(TheCommandIwantTorun) #runs TheCommandIwantTorun in the 
command prompt (windows)
-- 
http://mail.python.org/mailman/listinfo/python-list


boolean flag vs threading.Event

2007-02-27 Thread Daniel
I have a class similar to this:


class MyThread(threading.Thread):

def __init__(self):
self.terminated = False

def run(self):
while not self.terminated:
pass # do stuff here

def join(self):
self.terminated = True
threading.Thread.join(self)


Recently I was reading in the Python Cookbook (9.2 Terminating a
Thread) about how to do this sort of thing. That recipe uses a
threading.Event object to signal the thread termination. Here's my
class recoded to use an event:


class MyThread(threading.Thread):

def __init__(self):
self.event = threading.Event()

def run(self):
while not self.event.isSet():
pass # do stuff here

def join(self):
self.event.set()
threading.Thread.join(self)


If I understand the GIL correctly, it synchronizes all access to
Python data structures (such as my boolean 'terminated' flag). If that
is the case, why bother using threading.Event for this purpose?

Thanks,
~ Daniel

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


Re: boolean flag vs threading.Event

2007-02-27 Thread Daniel
> But what are you gaining, really [by using a boolean flag instead of an 
> Event]?

I agree Chris, the Event is better and it certainly does not add much
if any overhead. Thanks for the response.

~ Daniel

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


what is the difference between tuple and list?

2006-05-16 Thread daniel
is there any typical usage that shows their difference? 

thanks

daniel

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


Re: what is the difference between tuple and list?

2006-05-16 Thread daniel
thank you all for replying, I'm new to python, and just reading the
python tutorial now. I did not expect the FAQ to contain any relevant
topics, so thanks Simon...

your comments did make sense, I should have read the tutorial more
thoroughly, It's not a good question, I admit. ;-)

English is not my mother language, so sorry if there is any mistakes or
improper expression.

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


logging multiple messages

2009-01-15 Thread Daniel
I was fighting with a problem all day that was producing multiple
messages in my logging output.  The problem was related to the fact
that I was defining logging handlers multiple times.  I found the
following posting from a few years ago that related to my problem:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/8a707c289642c668/44f16cf5ba68721f?lnk=gst&q=logging#44f16cf5ba68721f

What I did was the following:

def initLogging(loggingArea):
# create/get logger
logger = logging.getLogger("mylogger")
logger.setLevel(logging.DEBUG)

# setup Handlers
if len(logger.handlers) == 0:
# create handlers only if there are none
sh = logging.StreamHandler()
# now add the handlers
logger.addHandler(sh)

If the logger already has handlers nothing happens, otherwise they're
created and added to the logger.  Now I can call initLogging
('mylogarea') whereever I need to without getting multiple messages.

If you know of a better way to do this let me know...
--
http://mail.python.org/mailman/listinfo/python-list


where is handle_timeout in SocketServer

2009-02-11 Thread Daniel
I've just been reading the docs to help me with a SocketServer issue.
I found in the docs (http://docs.python.org/library/socketserver.html)
a reference to a member attribute timeout and a member function
handle_timeout() is made.  I am using python 2.5 and there's no
indication that these were added in 2.6 or later.  I've also searched
Google and found that it may have been committed as long ago as
January of last year (http://mail.python.org/pipermail/python-checkins/
2008-January/064877.html).

Why isn't it available in my version of python?  Is there another
place to find it?  Please help me figure out what I'm missing so that
I can use the timeout functionality in my SocketServers.

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


Re: where is handle_timeout in SocketServer

2009-02-11 Thread Daniel
On Feb 11, 4:01 pm, Daniel  wrote:
> I've just been reading the docs to help me with a SocketServer issue.
> I found in the docs (http://docs.python.org/library/socketserver.html)
> a reference to a member attribute timeout and a member function
> handle_timeout() is made.  I am using python 2.5 and there's no
> indication that these were added in 2.6 or later.  I've also searched
> Google and found that it may have been committed as long ago as
> January of last year (http://mail.python.org/pipermail/python-checkins/
> 2008-January/064877.html).
>
> Why isn't it available in my version of python?  Is there another
> place to find it?  Please help me figure out what I'm missing so that
> I can use the timeout functionality in my SocketServers.
>
> Thanks.

I've just looked at the subversion repository and it does appear that
the timeout functionality was introduced in python 2.6 (or after 2.5.2
anyway).
http://svn.python.org/projects/python/trunk/Lib/SocketServer.py
http://svn.python.org/projects/python/tags/r252/Lib/SocketServer.py

I guess I'll see what I can do to adapt since porting my entire
project isn't realistic at this point.
--
http://mail.python.org/mailman/listinfo/python-list


Python syntax question

2008-10-08 Thread Daniel
I hope this question is OK for this list.  I've downloaded Rpyc and
placed it in my site packages dir.  On some machines it works fine, on
others not so much.

Here is one error I get when I try to import it:

>>> import Rpyc
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Python25\lib\site-packages\Rpyc\__init__.py", line 7, in

from Rpyc.Lib import rpyc_excepthook
  File "C:\Python25\lib\site-packages\Rpyc\Lib.py", line 65
print("=== Remote traceback ===", file=stderr)
  ^
SyntaxError: invalid syntax

The little carrot points to the equal sign ('=') in 'file=stderr'

What's the syntax problem?

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


Re: Python syntax question

2008-10-08 Thread Daniel
On Oct 8, 12:07 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> On Wed, 08 Oct 2008 11:02:49 -0700, Daniel wrote:
> > Here is one error I get when I try to import it:
>
> >>>> import Rpyc
> > Traceback (most recent call last):
> >   File "", line 1, in 
> >   File "C:\Python25\lib\site-packages\Rpyc\__init__.py", line 7, in
> > 
> >     from Rpyc.Lib import rpyc_excepthook
> >   File "C:\Python25\lib\site-packages\Rpyc\Lib.py", line 65
> >     print("=== Remote traceback ===", file=stderr)
> >                                                   ^
> > SyntaxError: invalid syntax
>
> > The little carrot points to the equal sign ('=') in 'file=stderr'
>
> > What's the syntax problem?
>
> That's Python 3.0 syntax where ``print`` is not a keyword anymore but a
> function.  Won't work with Python 2.5.
>
> Ciao,
>         Marc 'BlackJack' Rintsch

Thanks!  With that I was able to find a solution.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python syntax question

2008-10-13 Thread Daniel
On Oct 8, 1:19 pm, "Blubaugh, David A." <[EMAIL PROTECTED]> wrote:
> Sir,
>
> I was just wondering that the module that you are utilizing (Rpyc) is a 
> remote process call module for python?  Is this what you are developing with 
> at this time?
>
> Thanks,
>
> David Blubaugh
>
> -Original Message-
> From: Daniel [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, October 08, 2008 3:11 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Python syntax question
>
> On Oct 8, 12:07 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> > On Wed, 08 Oct 2008 11:02:49 -0700, Daniel wrote:
> > > Here is one error I get when I try to import it:
>
> > >>>> import Rpyc
> > > Traceback (most recent call last):
> > >   File "", line 1, in 
> > >   File "C:\Python25\lib\site-packages\Rpyc\__init__.py", line 7, in
> > > 
> > >     from Rpyc.Lib import rpyc_excepthook
> > >   File "C:\Python25\lib\site-packages\Rpyc\Lib.py", line 65
> > >     print("=== Remote traceback ===", file=stderr)
> > >                                                   ^
> > > SyntaxError: invalid syntax
>
> > > The little carrot points to the equal sign ('=') in 'file=stderr'
>
> > > What's the syntax problem?
>
> > That's Python 3.0 syntax where ``print`` is not a keyword anymore but
> > a function.  Won't work with Python 2.5.
>
> > Ciao,
> >         Marc 'BlackJack' Rintsch
>
> Thanks!  With that I was able to find a solution.
>
> This e-mail transmission contains information that is confidential and may be
> privileged. It is intended only for the addressee(s) named above. If you 
> receive
> this e-mail in error, please do not read, copy or disseminate it in any 
> manner.
> If you are not the intended recipient, any disclosure, copying, distribution 
> or
> use of the contents of this information is prohibited. Please reply to the
> message immediately by informing the sender that the message was misdirected.
> After replying, please erase it from your computer system. Your assistance in
> correcting this error is appreciated.
>
>

RPyC is use in pyscripter to provide remote debugging.  I was having
trouble getting the RPyC module working, and the reason is that the
RPyC site only provides a download for Python 3 (not sure why, since I
suspect that a lot of people are still in the 2.x releases).  Anyway,
I found an old version of RPyC and it worked out great.  I'm not
actually developing it.
--
http://mail.python.org/mailman/listinfo/python-list


Python logging and ThreadingTCPServer

2008-10-17 Thread Daniel
Hello,

I building an application that consists of several sockets
components.  I would like to use logging in them, but I've noticed
some issues with the logs getting mangled.  This mangling seems to
happen when different threads attempt to access the same log file.

For example, if a client and a server component are running on the
same box and both try to write to the same physical log file, the
first will write fine, but when the second thread (or process) writes
to the log file it mangles the first part of the log file including
deleting some of the information and adding various strange characters
and space.  Sometimes it seems that the first process never is able to
write to the log file after the second process starts writing.

Is this a known issue/bug?  Are there any known workarounds?

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


Re: Interface to Matlab

2008-10-17 Thread Daniel
On Oct 17, 8:48 am, Claire Mouton <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I would like to call Python functions from Matalab.
> How could I find an interface from Matlab to Python?
>
> Cheers,
> Claire

Hey,

Have you looked at
http://www.scipy.org/
and http://matplotlib.sourceforge.net/

They do an awful lot of what matlab does.

Also, I think that Matlab's perferred language is Java.  Anyway,
googling brings up these:
http://j-integra.intrinsyc.com/support/com/doc/other_examples/Matlab.htm
http://claymore.engineer.gvsu.edu/~steriana/Python/pymat.html

I just googled "python matlab" and "java matlab"

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


Re: Interface to Matlab

2008-10-22 Thread Daniel
On Oct 17, 2:26 pm, Lawrence D'Oliveiro <[EMAIL PROTECTED]
central.gen.new_zealand> wrote:
> In message
> <[EMAIL PROTECTED]>, Daniel
> wrote:
>
> > Have you looked at
> >http://www.scipy.org/
> > andhttp://matplotlib.sourceforge.net/
>
> > They do an awful lot of what matlab does.
>
> This one <http://www.sagemath.org/> I think rolls them all up into a package
> that does even more.
>
> > Also, I think that Matlab's perferred language is Java.
>
> It has its own built-in language (good for some things, crappy for others),
> though no doubt it's been making more use of Java over the years.

The Matlab interpreter is written in Java:
http://www.cs.princeton.edu/introcs/11matlab/

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


Sync paramstyle between sqlite and mysql

2008-11-10 Thread Daniel
Hello,

I'm developing an application that accesses both a MySQL and an SQLite
database.  I would like to have named parameters in my SQL and have
found the following:

For MySQL my named parameters need to look like this: %(paramname)s
For SQLite my named parameters need to look like this: :paramname

I have read in PEP249 (http://www.python.org/dev/peps/pep-0249/) that
there are five paramstyles, though it wasn't clear if I should expect
these to be implemented in all DBAPI2 compliant modules.  I have found
that I can set the paramstyle, but it doesn't seem to apply:

>>> import sqlite3 as dbapi2
>>> dbapi2.paramstyle
'qmark'
>>> dbapi2.paramstyle = 'format'
>>> dbapi2.paramstyle
'pyformat'

My sqlite access still requires the 'named' format and not
'pyformat'.

Can someone tell me if it's possible to configure a connection or
cursor to use a particular paramstyle?

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


Re: Remote control of firefox (mozilla) from a python program

2008-11-10 Thread Daniel
On Nov 10, 9:23 am, Scott <[EMAIL PROTECTED]> wrote:
> I have a requirement to control a firefox web browser from an external
> python program.  The python program running under linux from a command
> shell needs to first find all open firefox web browser windows read
> the URL currently displayed in each web browser and if the URL matches
> a particular regular expression it needs to get/set form fields
> displayed in the web browser.  Basically I need something like Windows
> COM and Internet Explorer where you can use COM to get/set form
> elements in the web page as well as post the web page.  Does xpcom
> provide this?  Is there some other method?  Mozilla has an xpcom
> interface but I am not sure it is available to a python program
> running in a different process as my scenario describes.  At some
> point I will need this python program to run under Mac OS X but for
> now I need something running under Linux.

I'm not sure I understand all your requirements, but my first approach
would be to build a firefox plugin that exposed the information you
need.  The firefox plugin could provide some mechanism for the
external program to communicate with it and would have access to all
the browser specific items that you described.

http://roachfiend.com/archives/2004/12/08/how-to-create-firefox-extensions/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Sync paramstyle between sqlite and mysql

2008-11-11 Thread Daniel
On Nov 10, 11:00 am, Daniel <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I'm developing an application that accesses both a MySQL and an SQLite
> database.  I would like to have named parameters in my SQL and have
> found the following:
>
> For MySQL my named parameters need to look like this: %(paramname)s
> For SQLite my named parameters need to look like this: :paramname
>
> I have read in PEP249 (http://www.python.org/dev/peps/pep-0249/) that
> there are five paramstyles, though it wasn't clear if I should expect
> these to be implemented in all DBAPI2 compliant modules.  I have found
> that I can set the paramstyle, but it doesn't seem to apply:
>
> >>> import sqlite3 as dbapi2
> >>> dbapi2.paramstyle
> 'qmark'
> >>> dbapi2.paramstyle = 'format'
> >>> dbapi2.paramstyle
>
> 'pyformat'
>
> My sqlite access still requires the 'named' format and not
> 'pyformat'.
>
> Can someone tell me if it's possible to configure a connection or
> cursor to use a particular paramstyle?
>
> Thanks.

If no one has any input, can someone tell me where I should post?

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


how to acces the block inside of a context manager as sourcecode

2008-11-18 Thread Daniel
Hello,

I need to access the code inside of a context manager, i.e. the call to

with myManager(v=5) as x:
a=b
c=sin(x)


should cause the following output (minus the first line, if that's easier):


with myManager(v=5) as x: # I could live without this line
a=b
c=sin(x)


I can get the line number from the traceback (see below), and try to
find the block in the source, but that seems ugly to me.



class MyManager(object):
def __init__(self,name='name'):
# how to access the source code inside of the with block ?
f = traceback.extract_stack()
print f[0]

def __enter__(self):
pass

def __exit__(self,type,value,traceback):
if type is not None:
print 'exception'
    pass



Any ideas?

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


Re: how to acces the block inside of a context manager as sourcecode

2008-11-19 Thread Daniel
Hi Aaron,

let me give you the reason for the context manager:
I am driving handware with a python script, basically a data acquisition
program which looks like this:


with dataStore('measurement1.dat') as d:
magnet.setField(0)
r1=doExperiment(voltage=0.345, current=0.346, temperature=33)
magnet.setField(1)
r2=doExperiment(voltage=0.32423, current=0.3654, temperature=45)
d.append(r2-r1)

the script does the measuring and the context manager stores the result
(r1 and r2), at the end the result is printed.

The source code serves as the documentation (it contains many parameters
that need to be well documented), so I print the source code, cut it out
and glue it into my lab notebook.
Now I want to automate this process, i.e. the dataStore should print the
sourcecode.

Daniel

> There isn't a solution in the general case, because strings can be
> executed.  However, 'inspect.currentframe()' and
> 'inspect.getsourcelines(object)' can handle some cases, and your idea
> is (I believe) how getsourcelines works itself.  You can probably do
> it without a context manager, e.g. 'print_next_lines( 5 )' or
> 'print_prior_lines( 2 )', dedenting as needed.
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to acces the block inside of a context manager as sourcecode

2008-11-20 Thread Daniel
Hi Aaron,

the dataStore combines both the printing and analysis (it will create a
report).
Unfortunately the end of the block already needs to be known in
__enter__, as the report starts to print during the measurement.
I decided to do it the following way:

__enter__ gets the start line number using the idea you proposed.
then the program reads the number of lines that are indented with
respect to the with block. This could cause problems for strange
indenting, but this should not happen in my application. Unfortunately I
could not use the ast module, because the comments are an important part
of the report.

Thank you for your ideas

Daniel




class CM( object ):
def __enter__(self):
self.startline= inspect.stack( )[ 1 ][ 0 ].f_lineno
print 'startline',self.startline
filename = inspect.stack( )[-1][1]

def getIndentation(line):
# TODO: handle comments and docstrings correctly
return len(line) - len(line.lstrip())

with open(filename,'r') as f:
lines=f.readlines()[self.startline-1:]
indent0=getIndentation(lines[0])
indent =[getIndentation(i)-indent0 for i in lines[1:]]
nlines = [n for l,n in zip(indent,xrange(1,100)) if l >
0][0]
self.callingCode = lines[:self.startline+nlines]

print self.callingCode


def __exit__(self, exc_type, exc_value, traceback):
   pass

if __name__ == '__main__':
with CM():
print 'in first'
a= 0
b= 1
c= 2
print 'end of first'

with CM():
d= 3
e= 4
--
http://mail.python.org/mailman/listinfo/python-list


Re: starting a Python 2.5 executable without the DOS window

2009-02-27 Thread Daniel
On Feb 27, 8:19 am, Vlastimil Brom  wrote:
> >> 2009/2/27 Greg Miller :
> >> > I am working on a program that controls a piece of equipment.  The GUI/
> >> > control software is written with Python2.5/wxPython.  I would like to
> >> > know if there is a way of starting the GUI without the DOS window
> >> > having to launch?  I would like only the application itself to appear,
> >> > no DOS window.  Thanks for any information.
> >> > Greg Miller
> >> > --
>
> 2009/2/27 Greg Miller :
>
> > Sorry, I should have been a bit more specific, it is an executable, .exe,
> > application created with PytoExe.
>
> Ok, then you can adjust your setup script for py2exe to contain
>
> setup(windows=["sourcefile.py"] ... )
>
> instead of
>
> setup(console=["sourcefile.py"] ...) which you probably have now.
>
> hth,
>   vbr

Just giving it the .pyw extension also seems to work (as I remember)
--
http://mail.python.org/mailman/listinfo/python-list


package questions

2009-05-22 Thread Daniel
Hello,

I've posted about this before, but after reading the docs, I have a
few more questions
here are the docs: http://docs.python.org/tutorial/modules.html#packages
here is my previous post:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/3a352159f6828eb9/cda8395d36827d20

I've setup some directories for the sound package, exactly as shown in
the examples in the docs.  In the surround file I put the lines

from . import echo
from .. import formats
from ..filters import equalizer

again, exactly as in the docs.  When I run surround.py, I get the
following result:
C:\sound\effects>python surround.py
Traceback (most recent call last):
  File "surround.py", line 1, in 
from . import echo
ValueError: Attempted relative import in non-package

C:\sound\effects>

Why doesn't this work as suggested in the docs.  The only way that I
found to get around this is to add directories to the path, but I
can't help but think that it shouldn't be necessary to modify the path
for packages to work.

Just to be sure, here are directory listings showing the I have the
__init__.py files in place

C:\sound\effects>dir
 Volume in drive C is Default
 Volume Serial Number is 8CD7-71F6

 Directory of C:\sound\effects

05/22/2009  10:07 AM  .
05/22/2009  10:07 AM  ..
05/22/2009  10:06 AM 0 echo.py
05/22/2009  10:16 AM   189 surround.py
05/22/2009  10:04 AM 0 __init__.py
   3 File(s)189 bytes
   2 Dir(s)  50,860,060,672 bytes free

C:\POP\sound\effects>dir ..\
 Volume in drive C is Default
 Volume Serial Number is 8CD7-71F6

 Directory of C:\sound

05/22/2009  10:04 AM  .
05/22/2009  10:04 AM  ..
05/22/2009  10:07 AM  effects
05/22/2009  10:06 AM  filters
05/22/2009  10:04 AM  formats
05/22/2009  10:04 AM 0 __init__.py
   1 File(s)  0 bytes
   5 Dir(s)  50,859,077,632 bytes free

C:\sound\effects>dir ..\filters
 Volume in drive C is Default
 Volume Serial Number is 8CD7-71F6

 Directory of C:\sound\filters

05/22/2009  10:06 AM  .
05/22/2009  10:06 AM  ..
05/22/2009  10:06 AM 0 equalizer.py
05/22/2009  10:04 AM 0 __init__.py
   2 File(s)  0 bytes
   2 Dir(s)  50,859,077,632 bytes free

Please share any feedback.  Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: package questions

2009-05-22 Thread Daniel
On May 22, 11:29 am, Scott David Daniels 
wrote:
> Daniel wrote:
> > Hello,
>
> > I've posted about this before, but after reading the docs, I have a
> > few more questions
> > here are the docs:http://docs.python.org/tutorial/modules.html#packages
> > here is my previous post:
> >http://groups.google.com/group/comp.lang.python/browse_thread/thread/...
>
> > I've setup some directories for the sound package, exactly as shown in
> > the examples in the docs.  In the surround file I put the lines
>
> > from . import echo
> > from .. import formats
> > from ..filters import equalizer
>
> > again, exactly as in the docs.  When I run surround.py, I get the
> > following result:
> > C:\sound\effects>python surround.py
> > Traceback (most recent call last):
> >   File "surround.py", line 1, in 
> >     from . import echo
> > ...
>
> (1) You really should identify your OS and Python version.  I am fairly
> certain it is some form of Windows, but 
> Try something like:
>      C:\sound\effects> cd C:\
>      C:\> python -m sound.effects.surround
>
> (2) you can run
>      python -v surround.py
> or
>      python -vv surround.py
> To see files opened (or attempted and opened for -vv) in order to
> discover what exactly is tried and in what order on imports.
> Warning: the output is huge.
>
> --Scott David Daniels
> scott.dani...@acm.org

I'm on WinXP using Python 2.5  Sorry I didn't mention that at first.

C:\sound\effects>cd ..\..\

C:\>python -m sound.effects.surround
Traceback (most recent call last):
  File "C:\Python25\lib\runpy.py", line 95, in run_module
filename, loader, alter_sys)
  File "C:\Python25\lib\runpy.py", line 52, in _run_module_code
mod_name, mod_fname, mod_loader)
  File "C:\Python25\lib\runpy.py", line 32, in _run_code
exec code in run_globals
  File "C:\POP\sound\effects\surround.py", line 5, in 
from . import echo
ValueError: Attempted relative import in non-package

Do you want me to post the output from the -vv.  I couldn't see that
it actually tried to load it.  Here's a relevant portion (I think):
# C:\Python25\lib\linecache.pyc matches C:\Python25\lib\linecache.py
import linecache # precompiled from C:\Python25\lib\linecache.pyc
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
  File "surround.py", line 1, in 
from . import echo
ValueError: Attempted relative import in non-package
# clear __builtin__._

It appears to finish loading everything for python and then
immediately fails due to the import call.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: package questions

2009-05-22 Thread Daniel
On May 22, 3:37 pm, Scott David Daniels  wrote:
> Daniel wrote:
> > I'm on WinXP using Python 2.5  Sorry I didn't mention that at first.
>
> Generally, you want the full version number (my 2.5 is 2.5.4).
> However, I set up your demo setup, and found that 2.6.2 worked, and
> 2.5.4 failed in the same way you see.  I also see that even inside
> the effects directory (with 2.6), I can use the syntax to work.
> However, 2.5 is nearing "security fixes only" status, so I'd try
> moving to 2.6. In the following, "C:\...\Py" is in my standard path.
>
>      C:\...\Py\sound\effects> \python26\python -m sound.effects.surround
>      effects package imported
>      surround started
>      echo imported
>      echo in
>      formats package imported
>      formats in
>      filters package imported
>      equalizer imported
>      filters in
>
> But if I make a file:
>      C:\...\Py\> type demo_sound.py
>      import sound.effects.surround
>      print('all loaded')
> I can then:
>      C:\...\Py> \python25\python demo_sound.py
>      effects package imported
>      surround started
>      echo imported
>      echo in
>      formats package imported
>      formats in
>      filters package imported
>      equalizer imported
>      filters in
>      all loaded
> or even:
>      C:\...\Py\sound\effects> \python25\python demo_sound.py
>      effects package imported
>      surround started
>      echo imported
>      echo in
>      formats package imported
>      formats in
>      filters package imported
>      equalizer imported
>      filters in
>      all loaded
>
> So, not what you want to hear, but at least identified.  I expect
> nobody wants to crawl into that code to make your case work,
> especially since you can switch to 2.6 and have it work.  The
> import code is said to be quite nasty and being rewritten/redocumented.
>
> --Scott David Daniels
> scott.dani...@acm.org

Thanks for doing the experiment.  I'll begin to consider testing with
python 2.6 for a possible upgrade.

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


  1   2   3   4   5   6   7   8   9   10   >