Asynchronous Soappy on AppEngine

2012-09-14 Thread Dennis
Hi,

I've noticed that my Soappy calls get converted to URLFetch calls on Google
AppEngine.  There seems to be documentation that UrlFetch can do
Asynchronous operations [1] but I'm not really sure how to make the soap
operations asynchronous.  Tried looking at the Soapproxy class and see if I
can put in callsbacks with urllib somewhere, but I think I am even more
confused now.  Thoughts suggestions, besides used twisted?



Regards,

Dennis


[1] (
https://developers.google.com/appengine/docs/python/urlfetch/asynchronousrequests
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Please help if you can!

2012-12-26 Thread Dennis
>
> My *very first* thought about this code is that it's really badly spaced.
> Don't put lines together so much! [https://gist.github.com/4383950] shows
> how much nicer things look when they're partitioned more. You may not
> agree, but it took about 10 seconds and I prefer it.
>
>

On another style note, you may want to take a look at this thread:

http://stackoverflow.com/questions/5611776/what-are-the-comprehensive-lint-checkers-for-python

Keeping your code style consistent and readable is a fundamental tenant of
Python development.

That link specifically points out PEP8:
http://www.python.org/dev/peps/pep-0008/
-- 
http://mail.python.org/mailman/listinfo/python-list


urllib2 opendirector versus request object

2011-06-09 Thread Dennis
Hi,

I was wondering what the difference or advantages to using an
opendirector with handlers or using a request object?

I am having an issue where when I use the open director and I try to
add headers it adds them after the connection-close header, but when I
use the request object it does not.

Here is the headers as reported by python:
send: 'POST /xml-api/listaccts HTTP/1.1\r\nAccept-Encoding:
identity\r\nContent-Length: 13\r\nHost:
cpanel01.sea.fibercloud.com:2086\r\nContent-Type:
application/x-www-form-urlencoded\r\nConnection: close\r\nUser-Agent:
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv,1.9.2.13)
Gecko/20101203 Firefox/3.6.13\r\n\r\n'
send: 'domain=anjopa'
reply: 'HTTP/1.1 403 Forbidden\r\n'
header: Connection: close
header: Server: cpsrvd/11.30.0.27
header: Content-type: text/xml

Next two examples one with Request object and the next with the open director,

#!/usr/bin/python
import sys
from xml.dom.minidom import parse, parseString
import urllib
import urllib2
import base64
from cookielib import CookieJar

# Turn on HTTP debugging
http://diveintopython.org/http_web_services/user_agent.html
import httplib



#With Request object:

  req = urllib2.Request(url, {},{'Authorization':'Basic ' +
base64.b64encode( username + ':' + password ) } )
  res = urllib2.urlopen(req)
  print res.read()

With open director:
  # Instantiate and Initialize AuthInfo Handler for use w/ the build_opener

authinfo = urllib2.HTTPBasicAuthHandler()
authinfo.add_password(realm="Web Host Manager",
uri="http://servername:2086/xml-api/listacct";,
user="username",
passwd="password")

# Instantiate Cookie jar Handler for use w/ build_opener

cj = CookieJar()

# Create an opener object from list of handlers above
opener = urllib2.build_opener(authinfo,urllib2.HTTPCookieProcessor(cj),
urllib2.HTTPHandler(debuglevel=1))
urllib2.install_opener(opener)

opener.addheaders = [('User-Agent', 'Mozilla/5.0 (Windows; U;
Windows NT 6.1; en-US; rv,1.9.2.13) Gecko/20101203 Firefox/3.6.13')]
response = opener.open(url, paramaters)





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


Re: Question About Command line arguments

2011-06-10 Thread Dennis
On Fri, Jun 10, 2011 at 11:03 AM, Dennis  wrote:
> On Fri, Jun 10, 2011 at 10:58 AM, Mark Phillips
>  wrote:
>> On Fri, Jun 10, 2011 at 10:41 AM, MRAB  wrote:
>>
>> On 10/06/2011 18:21, Mark Phillips wrote:
>
>>
> How do I write my script so it picks up argument from the output of commands
> that pipe input into my script?

I think if you want to replicate stdin behaviour try looking into
the xargs command, assuming that is available on your platform.

However reading in stdin into argv may be more elegant, but slightly
unexpected to the experienced user.

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


Re: Question About Command line arguments

2011-06-10 Thread Dennis
On Fri, Jun 10, 2011 at 11:58 AM, Mark Phillips
 wrote:
\
>
> Kurt,
>
> How does one write a main method to handle both command line args and stdin
> args?

Here is what I came up with:

The one weird thing, the line from above didn't seem to work so I changed it
if os.isatty(sys.stdin):

to this:

if not os.isatty(sys.stdin.fileno()):

Below 3 tests, with stdin redirection, then with one argument, then
with both stdin redirection and one argument, the results are at the
very bottom.

$ cat ./argvtest.py; echo "fred" | ./argvtest.py ; ./argvtest.py
"alice"; echo "fred" | ./argvtest.py "bob"
#!/usr/bin/python


import os
import sys

def main():
#This checks to see if stdin is a not tty and > 0
if not os.isatty(sys.stdin.fileno()):
arg = sys.stdin.read()
print arg

elif len(sys.argv[1:]) > 0:

# if the length of the first argument is > 0
#[1:] strip the first string beacause it is the name of the script
arg = sys.argv[1:]
print arg

if __name__ == "__main__":
    main()
fred

['alice']
fred





>
> Thanks,
>
> Mark
>

Welcome,

Dennis O.

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


Re: Question About Command line arguments

2011-06-10 Thread Dennis
On Fri, Jun 10, 2011 at 1:33 PM, Dennis  wrote:
> On Fri, Jun 10, 2011 at 11:58 AM, Mark Phillips

> fred
>
> ['alice']
> fred

Just realized the if/else will have to be changed slightly if we want
to output both argv and stdin.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: i want to learn pyqt ,but i have no c++ knowlage. is it ok????

2011-06-10 Thread Dennis
2011/6/10 可乐 :
> On 6月11日, 下午12时03分, Javier  wrote:
>> ??  wrote:
>> > i want to learn pyqt ,but i have no c++ knowlage. is it ok
>>
>> It should be ok.  I would recoomend this book:
>>
>> "Rapid GUI Programming with Python and Qt" (Prentice Hall Open Source 
>> Software
>> Development)
>> Mark Summerfield (Author)
> thanks a lot ,i have got a e-book which is you recomended.

So I don't know anyone Mandarin/Cantonese resources so these are all in English.

 Google has some great Python courses on Youtube and also UW has a
Python series:

http://www.google.com/search?q=youtube+google+python&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

http://www.cs.washington.edu/education/courses/cse142/10au/python.shtml

The python docs you will undoubtedly run into as well.

This was posted to the list recently too in case you missed it:

http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html

I'm sure everyone else has their own list of links.

Thanks,

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


which threading libraries to use?

2011-06-11 Thread Dennis
Hi,

Are there any reasons besides personal preference to use one
particular threading library over the other?  Eventlet, Twisted, and
Python's native Threading class, or are there even others?  Are there
any licensing or redistribution restrictions that I should be worried
about?  Which ones do you consider best documented?  Most thread-safe?
Efficient?

Ultimately this will be used for asynchronous SNMP, HTTP, and WMI.  I
don't think this will need to evolve into a multi-process project,
unless of course that is much easier to do than multi-threading?

Thanks,

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


Re: Security test of embedded Python

2011-06-21 Thread Dennis
Hi,

The Google App Engine product seems to sandbox Python code, however it
comes with a lot of limitations and maybe those can be an inspiration
for how you design your infrastructure.

http://code.google.com/appengine/docs/python/overview.html

http://code.google.com/appengine/kb/commontasks.html

I hope this helps somewhat - I know lacking some specifics.

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


change spacing to two instead of four with pep8 or flake8?

2014-04-07 Thread Dennis
Hi,

In Pylint you can change the spacing multiplier from 4 spaces to two
in its pylintrc, but for the life of me I cannot find a way to do this
with the flake8 / pep8 utilities.

I want to avoid ignoring E111 altogether if at all possible, because
it may catch other spacing problems that are not as obvious.

hacky/non-hacky solutions welcome of course.

If this is too specific and I should go to the pep8/flake8 MLs that is
welcome advice too.

Thanks,

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


python confusion possibly related to pickle

2008-05-18 Thread Dennis


I have a problem that I don't understand at all. I run a python script, 
which uses pickle, and it fails. That alone is, perhaps, no big deal.


The problem that's got me annoyed is that after getting said error I 
close the shell window, open a new one, run the python interpreter and 
type "import pickle" and get the error that the script I'd run earlier 
caused. Why is this ?


To my knowledge, once python stopped running it didn't store anything 
related to the last time it was run.

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


Re: python confusion possibly related to pickle

2008-05-18 Thread Dennis


Never mind. I solved it. I had a file called pickle in the same folder I 
was in when I ran python, and that's the file it was trying to import.


Duh @ me :s


Dennis wrote:


I have a problem that I don't understand at all. I run a python script, 
which uses pickle, and it fails. That alone is, perhaps, no big deal.


The problem that's got me annoyed is that after getting said error I 
close the shell window, open a new one, run the python interpreter and 
type "import pickle" and get the error that the script I'd run earlier 
caused. Why is this ?


To my knowledge, once python stopped running it didn't store anything 
related to the last time it was run.

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


Re: python confusion possibly related to pickle

2008-05-19 Thread Dennis

Derek Martin wrote:

On Sun, May 18, 2008 at 08:28:34PM +0100, Dennis wrote:

The problem that's got me annoyed is that after getting said error I
close the shell window, open a new one, run the python interpreter
and type "import pickle" and get the error that the script I'd run
earlier caused. Why is this ?


Well, what's the error?  Sounds like your system could be b0rked (or
at least your python installation)... but depending on the error,
there could be other explanations.  



Nah, just a case of being in a directory of my home directory that has a 
file called pickle.py in it. That file has a known error. I then ran 
python interactively and typed "import pickle". As a result I end up 
importing the file in my current directory instead of the python module 
I want to import.


I was just being daft :-D
--
http://mail.python.org/mailman/listinfo/python-list


A small and very basic python question

2008-04-27 Thread Dennis

Could anyone tell me how this line of code is working:

filter(lambda x: x in string.letters, text)

I understand that it's filtering the contents of the variable text and I 
know that lambda is a kind of embedded function.


What I'd like to know is how it would be written if it was a normal 
function.

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


Re: A small and very basic python question

2008-04-27 Thread Dennis
I didn't give up after posting and managed to grasp this whole lambda 
thing! No need to respond now :-) I understood it the moment I tried to 
type out, instead of just thinking in my head, what was going on as a 
normal function.



Dennis wrote:

Could anyone tell me how this line of code is working:

filter(lambda x: x in string.letters, text)

I understand that it's filtering the contents of the variable text and I 
know that lambda is a kind of embedded function.


What I'd like to know is how it would be written if it was a normal 
function.

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


Re: twenty years ago Guido created Python

2010-01-01 Thread dennis
On Jan 1, 6:04 am, Krishnakant  wrote:
> On Fri, 2010-01-01 at 03:25 -0800, J Peyret wrote:
> > On Dec 31 2009, 2:06 pm, Steve Howell  wrote:
> > > FYI:
>
> > >http://twitter.com/gvanrossum
>
> > > Python is a truly awesome programming language.  Not only is Guido a
> > > genius language designer, but he is also a great project leader.  What
> > > an accomplishment.  Congratulations to everybody who has contributed
> > > to Python in the last two decades!
>
> > Notwithstanding all of the above, which are all true, having met
> > Guido, I say he is a genuinely nice human being.  Go BSD derivatives.
>
> Indeed,
> python is a great programming language.
> May be it was not marketted as much as languages like java or not as
> much as platforms like rails.
> But who cares?  I must mention here that I am totally blind and the
> talking software (screen reader ) I use on GNU/Linux called Orca is also
> programmed using python.
>
> And I make web applications and off late started to use pylons (  again
> centered around python).
> I see that python is for 2 kind of programmers.
> one which are absolute beginners to programming itself who want to learn
> the scientific art of programming and the second is the extreme experts
> who need the power and performance nicely balanced.
>
> Great work!
>
> happy hfacking.
> Krishnakant.

That's incredible.
-- 
http://mail.python.org/mailman/listinfo/python-list


How to properly implement worker processes

2012-08-22 Thread Dennis Jacobfeuerborn
Hi,
I'm trying to implement a system for periodically checking URLs and I've run 
into problems with some of the implementation details. The URLs are supposed to 
be checked continuously until the config for an URL is explicitly removed.

The plan is to spawn a worker process for each URL that sends the status of the 
last check to its parent which keeps track of the state of all URLs. When a URL 
is no longer supposed to be checked the parent process should shutdown/kill the 
respective worker process.

What I've been going for so far is that the parent process creates a global 
queue that is passed to all children upon creation which they use to send 
status messages to the parent. Then for each process a dedicated queue is 
created that the parent uses to issue commands to the child.

The issue is that since the child processes spent some time in sleep() when a 
command from the parent comes they cannot respond immediately which is rather 
undesirable. What I would rather like to do is have the parent simply kill the 
child instead which is instantaneous and more reliable.

My problem is that according to the multiprocessing docs if I kill the child 
while it uses the queue to send a status to the parent then the queue becomes 
corrupted and since that queue is shared that means the whole thing pretty much 
stops working.

How can I get around this problem and receive status updates from all children 
efficiently without a shared queue and with the ability to simply kill the 
child process when it's no longer needed?

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


Re: How to properly implement worker processes

2012-08-22 Thread Dennis Jacobfeuerborn
On Wednesday, August 22, 2012 7:46:34 PM UTC+2, Ian wrote:
> On Wed, Aug 22, 2012 at 11:29 AM, Dennis Jacobfeuerborn
> 
>  wrote:
> 
> > Hi,
> 
> > I'm trying to implement a system for periodically checking URLs and I've 
> > run into problems with some of the implementation details. The URLs are 
> > supposed to be checked continuously until the config for an URL is 
> > explicitly removed.
> 
> >
> 
> > The plan is to spawn a worker process for each URL that sends the status of 
> > the last check to its parent which keeps track of the state of all URLs. 
> > When a URL is no longer supposed to be checked the parent process should 
> > shutdown/kill the respective worker process.
> 
> >
> 
> > What I've been going for so far is that the parent process creates a global 
> > queue that is passed to all children upon creation which they use to send 
> > status messages to the parent. Then for each process a dedicated queue is 
> > created that the parent uses to issue commands to the child.
> 
> >
> 
> > The issue is that since the child processes spent some time in sleep() when 
> > a command from the parent comes they cannot respond immediately which is 
> > rather undesirable. What I would rather like to do is have the parent 
> > simply kill the child instead which is instantaneous and more reliable.
> 
> >
> 
> > My problem is that according to the multiprocessing docs if I kill the 
> > child while it uses the queue to send a status to the parent then the queue 
> > becomes corrupted and since that queue is shared that means the whole thing 
> > pretty much stops working.
> 
> >
> 
> > How can I get around this problem and receive status updates from all 
> > children efficiently without a shared queue and with the ability to simply 
> > kill the child process when it's no longer needed?
> 
> 
> 
> The usual approach to killing worker processes safely is to send them
> 
> an "exit" command, which they should respond to by terminating
> 
> cleanly.  Instead of using sleep(), have the workers do a blocking
> 
> get() on the queue with a timeout.  This way they'll receive the
> 
> "exit" message immediately as desired, but they'll still wake up at
> 
> the desired intervals in order to do their work.

I was thinking about something like that but the issue is that this really only 
works when you don't do any actual blocking work. I may be able to get around 
the sleep() but then I have to fetch the URL or do some other work that might 
block for a while so the get() trick doesn't work.
Also the child process might not be able to deal with such an exit command at 
all for one reason or another so the only safe way to get rid of it is for the 
parent to kill it.

The better option would be to not use a shared queue for communication and 
instead use only dedicated pipes/queues for each child process but the doesn't 
seem to be a way to wait for a message from multiple queues/pipes. If that were 
the case then I could simply kill the child and get rid of the respective 
pipes/queues without affecting the other processes or communication channels.

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


Re: How to properly implement worker processes

2012-08-22 Thread Dennis Jacobfeuerborn
On Wednesday, August 22, 2012 11:15:10 PM UTC+2, Ian wrote:
> On Wed, Aug 22, 2012 at 1:40 PM, Dennis Jacobfeuerborn
> 
>  wrote:
> 
> > I was thinking about something like that but the issue is that this really 
> > only works when you don't do any actual blocking work. I may be able to get 
> > around the sleep() but then I have to fetch the URL or do some other work 
> > that might block for a while so the get() trick doesn't work.
> 
> 
> 
> At a lower level, it is possible to poll on both the pipe and the
> 
> socket simultaneously.  At this point though you might want to start
> 
> looking at an asynchronous or event-driven framework like twisted or
> 
> gevent.
> 

I was looking at twisted and while the Agent class would allow me to make async 
request it doesn't seem to support setting a timeout or aborting the running 
request. That's really the important part since the http request is really the 
only thing that might block for a while. If I can make the request 
asynchronously and abort it when I receive a QUIT command from the parent then 
this would pretty much solve the issue.

> 
> > Also the child process might not be able to deal with such an exit command 
> > at all for one reason or another so the only safe way to get rid of it is 
> > for the parent to kill it.
> 
> 
> 
> I think you mean that it is the most "reliable" way.  In general, the
> 
> only "safe" way to cause a process to exit is the cooperative
> 
> approach, because it may otherwise leave external resources such as
> 
> file data in an unexpected state that could cause problems later.
> 

True but the child is doing nothing but making http requests and reporting the 
result to the parent so killing the process shouldn't be too much of a deal in 
this case. A segfault in an Apache worker process is very similar in that it's 
an uncontrolled termination of the process and that works out fine.

> 
> > The better option would be to not use a shared queue for communication and 
> > instead use only dedicated pipes/queues for each child process but the 
> > doesn't seem to be a way to wait for a message from multiple queues/pipes. 
> > If that were the case then I could simply kill the child and get rid of the 
> > respective pipes/queues without affecting the other processes or 
> > communication channels.
> 
> 
> 
> Assuming that you're using a Unix system:
> 
> 
> 
> from select import select
> 
> 
> 
> while True:
> 
> ready, _, _ = select(pipes, [], [], timeout)
> 
> if not ready:
> 
> # process timeout
> 
> else:
> 
> for pipe in ready:
> 
> message = pipe.get()
> 
> # process message

That looks like a workable solution. When I decide to kill a worker process I 
can remove the pipe from the pipes list and discard it since it's not shared.

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


Where to set default data - where received, or where used

2012-06-11 Thread Dennis Carachiola
I'm programming a project which will use a file to save parameters
needed by the program.  There are already two previous file formats,
each of which can only be run by the version of the program which
created them.  I'm trying to avoid that problem in the future.  To do
that, I intend to use a dictionary, and default data.  I believe that
most new versions will add parameters.

Each version of the program will have reasonable default values for
each key in the dictionary handled by that version.  If an older file
is used, the data values in that file replace the keys that exist.
The program then can operate on the values supplied by the older data
file and the default values.  Conversely, if a newer file is used, the
data in the file replaces the keys in the dictionary.  The program
then simply doesn't access the newer data values.  I'm hoping that
this will make the file backward and forward compatible.

Here's my question.  I could do this by creating the dictionary with
the default values, then read the file into it.  Or I could use a
'get' with default values at the location in the program where those
values are used.

>From what I can see, creating the dictionary with default values puts
everything in one place.  While, supplying the default values at the
place where they're used places the default values nearest the place
where actually used.

I can't decide on one way over the other.  Can anyone give me some
ideas if one is a preferred method, or other criteria I've overlooked?

Thanks,

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


Re: why no camelCase in PEP 8?

2020-05-31 Thread Dennis Carachiola
>From PEP8--
"The guidelines provided here are intended to improve the readability of code 
and make it consistent across the wide spectrum of Python code. As PEP 20 says, 
"Readability counts".
A style guide is about consistency. Consistency with this style guide is 
important. Consistency within a project is more important. Consistency within 
one module or function is the most important.
However, know when to be inconsistent -- sometimes style guide recommendations 
just aren't applicable. When in doubt, use your best judgment. Look at other 
examples and decide what looks best. And don't hesitate to ask!
In particular: do not break backwards compatibility just to comply with this 
PEP!"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT: ALGOL 60 at 60

2020-05-31 Thread Dennis Carachiola
Ah, but I have used it.  Admittedly it was during a programming languages 
survey course at RPI in 1971-3.
-- 
https://mail.python.org/mailman/listinfo/python-list


Documentation for iteration in mappings

2005-10-25 Thread Dennis Benzinger
Hi!

I must be blind because I didn't find anything in the documentation 
which says iterating over an dictionary iterates over its keys.

For example

a_dictionary = {0: "zero", 1: "one"}
for x in a:
 print x

gives you

0
1

Where is this information hidden? :)

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


Re: Math markup in code documentation?

2005-10-25 Thread Dennis Benzinger
[EMAIL PROTECTED] schrieb:
> Done any one have a way (and examples) of how to do math markups in the
> docstrings of function and class definitions such that the equations
> get typeset in the generated html documentation?  I'll take any markup
> system that'll do the job... MathML or LaTeX possible?
> [...]

Try Doxygen: http://www.doxygen.org

Examples of formulas are here: 
http://www.stack.nl/~dimitri/doxygen/formulas.html

Doxygen has the advantage that you can use it for a variety of 
programming languages.

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


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

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

Yes.

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

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


Re: parse data

2005-11-09 Thread Dennis Benzinger
py schrieb:
> I have some data (in a string) such as
> 
> person number 1
> 
> Name: bob
> Age: 50
> 
> 
> person number 2
> 
> Name: jim
> Age: 39
> 
> ...all that is stored in a string.  I need to pull out the names of the
> different people and put them in a list or something.  Any
> suggestions...besides doing data.index("name")...over and over?
> 
> thanks!
> 

Use the re module:


import re

your_data = """person number 1

Name: bob
Age: 50


person number 2

Name: jim
Age: 39"""


names = []

for match in re.finditer("Name:(.*)", your_data):
 names.append(match.group(1))

print names



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


Re: path module / class

2005-11-16 Thread Dennis Benzinger
[EMAIL PROTECTED] schrieb:
> [...]
> What is the status of the path module/class PEP?  Did somebody start
> writing one, or did it die?  

I didn't find one at the PEP index <http://python.org/peps/>, so I 
assume that nobody wrote or submitted one.

> I would really like to see something like
> Jason Orendorff's path class make its way into the python standard
> library.
> [...]

If you think having such a class in the standard library is that 
important then you should write a PEP by yourself...


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


Re: searching for files on Windows with Python

2005-11-17 Thread Dennis Benzinger
Shane schrieb:
> I've been giving Google a good workout with no luck. I would like to be able 
> to search a Windows filesystem for filenames, returning a list off absolute 
> paths to the found files, something like:
> 
> def findFiles(filename, pathToSearch):
>  ...
>  ...
>  return foundFileNames
> 
> Is the os module where I should start?
> [...]

Yes, especially the os.walk() function should help you.

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


Re: the first element in the list of list

2005-11-22 Thread Dennis Benzinger
Ben Bush schrieb:
> I have a lis:
> [[1,3],[3,4],[5,6],[8,9],[14,0],[15,8]]
> I want a code to test when the difference between the first element in
> the list of list is equal to or larger than 6, then move the previous
> lists to the end of the list. that is:
> [[14,0],[15,8],[1,3],[3,4],[5,6],[8,9]]


your_list = [[1,3],[3,4],[5,6],[8,9],[14,0],[15,8]]


for index, sublist in enumerate(your_list):
 if abs(sublist[1] - sublist[0]) > 6:
 your_list = your_list[index:] + your_list[:index]
 break

print your_list


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


Re: XMLSchema Parsing

2005-11-29 Thread Dennis Benzinger
km schrieb:
> Hi all,
> i'd like to know if there are any good XMLSchema (.xsd files) parsing modules 
> in python.
> regards,
> KM
> 


Try lxml <http://codespeak.net/lxml/> a pythonic binding for the libxml2 
and libxslt libraries.


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


Re: newbie question concerning formatted output

2005-11-29 Thread Dennis Benzinger
Thomas Liesner schrieb:
> [...]
> i am having some hard time to format the output of my small script. I am
> opening a file which containes just a very long string of hexdata
> seperated by spaces. Using split() i can split this string into single
> words and print them on stdout. So far so good. But i want to print always
> three of them in a single line and after that a linebreak.
> [...]


words = ["3905", "3009", "", "4508", "f504", "", "3707", "5a07", 
"", ""]

VALUES_PER_LINE = 3

# Simple version
for index, word in enumerate(words):
 print word,  # Trailing comma to suppress newline
 if (index + 1) % VALUES_PER_LINE == 0:
 print

print
print

# Trickier version
ranges =[]
for i in range(VALUES_PER_LINE):
 ranges.append(words[i::VALUES_PER_LINE])

for triple in map(None, *ranges):
 print " ".join(str(value) for value in triple if value is not None)


Hmm, the second solution seems to be a bit too tricky...

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


Python web publishing framework like Cocoon?

2005-12-07 Thread Dennis Benzinger
Hi!

Is there a Python web publishing framework like Cocoon?

I found Maki <http://maki.sourceforge.net/> but it was last updated in 
2003 and its author says that he doesn't want to make another release...

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


Re: Open Folder in Desktop

2005-01-25 Thread Dennis Benzinger
Kamilche wrote:
> Is there a command you can execute in Python that will open a window on
> the desktop, such as 'My Documents'? Kind of like 'system', but for
> folder names, not just programs. I'm running on Windows 2000.
> 

Here are some commands you can use (tested on WinXP, so YMMV):


1. The os.system function

import os
os.system('explorer "c:\program files"')

This has the disadvantage that a cmd.exe windows is also opened,
because os.system executes the command in a subshell.

But using this approach the explorer starts in front of all other windows.


2. The os.startfile function

import os
os.startfile("C:\program files")

Using startfile doesn't open a cmd.exe window, but the folder window
is not started in front of the other windows


3. The subprocess.Popen function

import subprocess
subprocess.Popen('explorer "C:\program files"')

With subprocess.Popen no cmd.exe window is opened and the explorer
starts in front of the other windows.
But the subprocess module is new in Python 2.4.



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


Re: module for 'po' files

2005-01-25 Thread Dennis Benzinger
Sara Fwd wrote:
>  Hi all
> Is there a module for processing & handling  '.po'
> files in python?
> [...]

I don't know if there is a module for processing them, but
Python comes with msgfmt.py (in Tools/i18n) which creates
.mo files out of your .po files.

So read the source and see if there's something in there
which you can use!


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


Re: string.atoi and string.atol broken?

2005-01-25 Thread Dennis Benzinger
Mike Moum wrote:
> I think there may be a bug in string.atoi and string.atol.  Here's some 
> output from idle.
> 
> 
>>Python 2.3.4 (#2, Jan  5 2005, 08:24:51) 
>>[GCC 3.3.5 (Debian 1:3.3.5-5)] on linux2
>>Type "copyright", "credits" or "license()" for more information.
>>
>>
>>Personal firewall software may warn about the connection IDLE
>>makes to its subprocess using this computer's internal loopback
>>interface.  This connection is not visible on any external
>>interface and no data is sent to or received from the Internet.
>>
>>
>>IDLE 1.0.4  
>>
>>>>>import string as s
>>>>>s.atoi('2',3)
>>
>>2
>>
>>>>>s.atoi('4',3)
>>
>>Traceback (most recent call last):
>>  File "", line 1, in -toplevel-
>>s.atoi('4',3)
>>  File "/usr/lib/python2.3/string.py", line 220, in atoi
>>return _int(s, base)
>>ValueError: invalid literal for int(): 4
>>
>>>>>s.atoi('12',11)
>>
>>13
>>
>>>>>s.atoi('13',4)
>>
>>7
>>
>>>>>s.atoi('12',4)
>>
>>6
>>
>>>>>s.atoi('8',4)
>>
>>Traceback (most recent call last):
>>  File "", line 1, in -toplevel-
>>s.atoi('8',4)
>>  File "/usr/lib/python2.3/string.py", line 220, in atoi
>>return _int(s, base)
>>ValueError: invalid literal for int(): 8
>>
> 
> s.atoi('4',3) should result in 11
> 
> s.atoi('13',4) should result in 31
> 
> s.atoi('12',4) should result in 30
> 
> s.atoi('8',4) is legitimate, but it generates an error.
> 
> Is this a bug, or am I missing something obvious?
> [...]

That's not a bug, you'r missing something obvious.

The second parameter of string.atoi (or the int builtin)
is the base (or radix) in which the number you want to
convert is given.

For example string.atoi("777", 8) results in 511,
because 7 * 8**2 + 7 * 8**1 + 7 * 8**0 = 511.

Just out of curiosty:
What did you think what atoi does?
I don't understand how you came to expect that atoi('4',3)
should result in 11.


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


Re: String Fomat Conversion

2005-01-27 Thread Dennis Benzinger
mcg wrote:
> Investigating python day 1:
> 
> Data in file:
> x   y
> 1   2
> 3   4
> 5   6
> 
> 
> Want to read file into an array of pairs.
> 
> in c: scanf("%d %d",&x,&y)---store x y in array, loop.
> 
> How do I do this in python??
> In the actual application, the pairs are floating pt i.e. -1.003
> 

Either do what the other posters wrote, or if you really like scanf
try the following Python module:

Scanf --- a pure Python scanf-like module
http://hkn.eecs.berkeley.edu/~dyoo/python/scanf/

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


Re: MySQLdb - Tuples

2005-02-01 Thread Dennis Benzinger
Lajos Kuljo wrote:
> Hallo,
> ich bin voll neu im Python-Programming, deshalb ist mein Problem 
> wahrscheinlich trivial:
> 
> Wenn ich die Script
> #33
> #! /usr/bin/env python
> import MySQLdb
> db=MySQLdb.connect(host='localhost', db='photum_0_6_2', user='root', 
> passwd='thkhgfgd')
> c=db.cursor()
> c.execute('select person from persons order by person')
> tup=c.fetchall()
> for a in tup:
>print a
> 
> ausführe, erhalte ich Dinge wie
> ('Dieter',)
> ('Hulda',)
> 
> 
> Ich brauche die Klammern, Apostrphe und Kommas nicht (ich will nur die 
> Inhalte) und kann ich sie nicht loswerden. Versucht habe ich u. a. print 
> a[2:-3] was nur zwei Klammern bringt.
> b=lstrip(a, "(") haut auch nicht hin.
> Weiss jemand Rat?

Hab gerade kein MySQL da, aber änder mal

for a in tup:
print a

in

for a in tup:
print a[0]  # Das erste Element des Tupels


Dann wird statt des ganzen Tupels nur das erste Element ausgegeben.


> P.S. Woher kommen diese Klammern und Apostrophen, vom MySQLdb?

Die Klammern und Apostrophe kommen daher, dass tup ein Tupel
(http://docs.python.org/lib/typesseq.html) mit einem Element
(der Person) ist.


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


Embedded Systems Python?

2005-06-20 Thread Dennis Clark
Hi all,

  I've looked through the threads about embedded Python that are a year
and a half old, and I thought that I'd ask this question now to see if
anything has changed.

  Has anyone, or is anyone working with Python in an embedded Linux 
environment?  Mine is NO where near as constrained as a cell phone since
I've got plenty of memory to work with, I'm just running a Linux 2.4 kernel
on an ARM9 platform.

  Are there success stories for Python on embedded Linux systems today?
The embedded Java JVM's seem to all be propriatary and have quite high
license fees (don't mention Kaffe, it seems pretty fragile to me.)

  I'm a bit of a newb when it comes to Python, is there anyone with experience
compiling it on Linux platforms that can offer me pointers to try this out
myself?

thanks,
DLC
-- 
====
* Dennis Clark [EMAIL PROTECTED]www.techtoystoday.com   
* 
* "Programming and Customizing the OOPic Microcontroller" Mcgraw-Hill 2003 *

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


Re: Embedded Systems Python?

2005-06-21 Thread Dennis Clark
Guys,

  Thanks, that was all information that I wanted to hear.  I have a 
Cirrus Logic Linux port for the ARM9.  I've no idea what the code
base is, I've not figured that out yet.  I should just need to re-
compile on the platform.

thanks,
DLC
-- 
====
* Dennis Clark [EMAIL PROTECTED]www.techtoystoday.com   
* 
* "Programming and Customizing the OOPic Microcontroller" Mcgraw-Hill 2003 *

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


Re: command line argument passing

2005-07-22 Thread Dennis Benzinger
Hayri ERDENER schrieb:
> hi to all,
> is it possible in python to pass arguments by using command prompt in
> windows 2000 and XP ?
> for example:
> sourceCode.py  factorial  4
>  gives me the factorial of 4 namely 24. 
> best regards

import sys

print sys.argv


Or use the optparse module. Docs:
http://www.python.org/doc/2.4.1/lib/module-optparse.html

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


certificate-based authentication

2005-08-18 Thread Dennis . Hoffman
I have been using XML-RPC to get information from one of our remote
servers.  To improve security, the server now has a certificate installed,
and when I try to access it, I get an 'Unauthorized' exception.  Is there
an xmlrpclib module that supports (client-side) certificate-based
authentication?  If so, where can I get it, and what  is involved in doing
the  authentication? If not, what are my options?

thanks

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


Re: certificate-based authentication (Martin v. L?wis)

2005-08-18 Thread Dennis . Hoffman
>> I have been using XML-RPC to get information from one of our remote
>> servers.  To improve security, the server now has a certificate
installed,
>> and when I try to access it, I get an 'Unauthorized' exception.  Is
there
>> an xmlrpclib module that supports (client-side) certificate-based
>> authentication?  If so, where can I get it, and what  is involved in
doing
>> the  authentication? If not, what are my options?

> The standard xmlrpclib should work fine. You need to inherit from the
> SafeTransport class, overriding get_host_info to return the x509_info.
> You then pass an instance of your transport to the ServerProxy.

> HTH,
> Martin

I'm using  Python version 2.2 - the SafeTransport class in it's xmlrpclib
doesn't  have a 'get_host_info' method.  Which version were you referring
to?
thanks
Dennis

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


Re: certificate-based authentication (Martin v. Löwis)

2005-08-19 Thread Dennis . Hoffman
> The standard xmlrpclib should work fine. You need to inherit from the
> SafeTransport class, overriding get_host_info to return the x509_info.
> You then pass an instance of your transport to the ServerProxy.


Ok - I have upgraded to the newer version of xmlrpclib that has the
'get_host_info' method.  I have created a new class (inherited from the
SafeTransport class), and overriden the get_host_info method.  So my
question now is where does the the x509_info come from?  Is that the
key/certificate comming back from the server?  If so, how do I get that?
If not, then where does it come from?  You must excuse my ignorance, as
this is all fairly new to me, and am still in the learning phase.
Thanks
Dennis


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


Downloadable python-dev archive February 2005 contains only one mail?

2005-02-08 Thread Dennis Benzinger
Hi!

I just downloaded the archive of the python-dev mailing list for
February 2005 from

http://mail.python.org/pipermail/python-dev/2005-February.txt.gz

and there is only one mail in it.

Did anyone have this problem, too?

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


Re: pyclbr

2005-02-10 Thread Dennis Benzinger
Fernando San MartÃn Woerner wrote:
> Hi guys!
> 
> i'm using pycblr to implement a class browser for my app, i got some
> issues about it:
> 
> i did:
> 
> dict = pyclbr.readmodule(name, [dir] + sys.path)

Don't use dict (or the name of any other built-in function)
as an identifier! It shadows the built-in function and can be quite
confusing for others reading your code.

It's sufficient to give only [dir] as the second parameter.
sys.path is always searched.
(http://docs.python.org/lib/module-pyclbr.html)

> but  this only works one time, i mean if module "name" is changed and
> some class were added or removed i can't see any changes even if i
> execute readmodule again.
> 
> any idea?, thanks in advance

pyclbr caches modules it has already read. I think there is no method
for clearing that cache, so you have to

reload(pyclbr)

in order to see your changes.


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


Re: Multiple initialization methods?

2005-02-16 Thread Dennis Benzinger
alex wrote:
> Hi,
> 
> it is possible to define multiple initialization methods so that the
> method is used that fits?

No, there is no overloading in Python.

> I am thinking of something like this:
> 
>   def __init__(self, par1, par2):
> self.init(par1, par2);
> 
>   def __init__(self, par1):
> self.init(par1, None)
> 
>   def init(self, par1, par2):
>  ...
>  ...
> 
> So if the call is with one parameter only the second class is executed
> (calling the 'init' method with the second parameter set to 'None' or
> whatever. But this example does not work. 
> 
> How to get it work?
> 
> Alex
> 

Use a default argument for par2 and check for that in your function:

def __init__(self, par1, par2=None):
# do something with par1

if par2 is None:
print "par2 was not given!"
else:
print "par2 is", par2


Read more in the FAQ:
http://www.python.org/doc/faq/programming.html#how-can-i-overload-constructors-or-methods-in-python
or in the tutorial:
http://docs.python.org/tut/node6.html#SECTION00671


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


Re: Whats up with re module vs pre

2005-02-17 Thread Dennis Benzinger
pythonUser_07 wrote:
> This is a very generic observation as I don't have a lot of specifics
> with me right now.  I have noticed over the past two years that the
> python "re" module is somewhat unreliable.  

What do you mean with unreliable?
Can you show an example where re does not work as expected?

> At the suggestion of
> someone quite some time ago, I started to use the deprecated "pre"
> module. "import pre as re". All my problems went away.
> 
> So here I am two years later, writing another script and I had
> forgotten about "pre" and wallah
> 
> $ python proc.py
> Traceback (most recent call last):
>   File "proc.py", line 39, in ?
> c = collect("nohup.out")
>   File "proc.py", line 20, in collect
> m = p.search(cont)
> RuntimeError: maximum recursion limit exceeded
> 
> As soon as I switched "import re" to "import pre as re" my program
> worked as expected.   In the words of Jerry Sienfeld, what's up with
> that?

Try again with Python 2.4. The re module is now non-recursive
(http://www.python.org/2.4/highlights.html), so you shouldn't get any
"maximum recursion limit exceeded" errors.


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


Re: recombination variations

2004-11-30 Thread Dennis Benzinger
David Siedband wrote:
> [...] 
> Is there a better way to do this?
> [...]

Take a look at Biopython: http://biopython.org/

Your problem may be solved there already.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython bug

2004-12-09 Thread Dennis Benzinger
Jive wrote:
> [...]
> What to do?

Ask in comp.soft-sys.wxwindows
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pywhich script - where is that module?

2004-12-17 Thread Dennis Benzinger
Thomas Guettler wrote:
> [...]
> Nice, you could add it to the python cookbook.
> [...]

Just in the case the OP doesn't know where to find the cookbook:
http://aspn.activestate.com/ASPN/Cookbook/Python/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question - default values of a function

2004-12-22 Thread Dennis Benzinger
Bulba! wrote:
> [...]
> But why the following happens?
> 
> 
>>>>def j(a,i=0):
> 
> ...   i=i+1 
> ...   return (a, i)
> ... 
> 
>>>>j(2)
> 
> (2, 1)
> 
>>>>j(3)
> 
> (3, 1)
> 
>>>>j(5)
> 
> (5, 1)
> 
> 
> From Language Reference:
> 
> http://www.python.org/doc/2.3.4/ref/function.html
> 
> "Default parameter values are evaluated when the function definition
> is executed. This means that the expression is evaluated once, when
> the function is defined, and that that same ``pre-computed'' value is
> used for each call. This is especially important to understand when a
> default parameter is a mutable object, such as a list or a dictionary:
> if the function modifies the object (e.g. by appending an item to a
> list), the default value is in effect modified. "
> 
> 
> Surely the variable i is a mutable object?
> [...]

No, i is not mutable!
i is a name for a number object which is _not_ mutable
(http://www.python.org/doc/2.4/ref/types.html).

The line i=i+1 creates a new number object with the value 1 and gives it
the name i.


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


Re: build flow? SCons? AAP? process creation?

2005-04-13 Thread Dennis Benzinger
[EMAIL PROTECTED] schrieb:
[...]
So if I do wind up having to write this thing myself, I've been
checking the docs on process creation, and have a couple questions if
anyone can fill me in.  It looks like the os.spawn* commands can start
nonblocking sub-processes, but there doesn't seem to be a way to get
stdout and stderr.  On the other hand, the popen commands make it easy
to trap stdout and stderr, but I guess I'd have to do the thread setup
and spawning myself.  Is there another alternative that I'm missing
here?  
[...]
Yes, you are missing the subprocess module which was introduced in 
Python 2.4: http://docs.python.org/lib/module-subprocess.html

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


Re: RE Engine error with sub()

2005-04-15 Thread Dennis Benzinger
Maurice LING schrieb:
Hi,
I have the following codes:
from __future__ import nested_scopes
> [...]
Are you still using Python 2.1?
In every later version you don't need the
"from __future__ import nested_scopes" line.
So, if you are using Python 2.1 I strongly recommend
upgrading to Python 2.4.1.
[...]
It all works well for rule count up to 800+ but when my replacement 
rules swells up to 1800+, it gives me a runtime error that says 
"Internal error in regular expression engine"... traceable to "return 
self.regex.sub(self, text)" in substitute() method.
[...]
I didn't read your code, but this sounds like you have a problem with 
the regular expression engine being recursive in Python versions < 2.4.
Try again using Python 2.4 or later (i.e. Python 2.4.1). The new regular 
expression engine is not recursive anymore.

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


Interpretation

2016-03-26 Thread Dennis Ngeno
My programs have never combile, they keep telling me , systax error even
after copy pasting
-- 
https://mail.python.org/mailman/listinfo/python-list


Searching for a usable X509 implementation

2015-07-03 Thread Dennis Jacobfeuerborn
Hi,
I'm trying to implement certificate functionality in a python app but after 
fighting with pyOpenSSL and M2Crypto I'm thinking about writing wrapper 
functions for the OpenSSL command line tool instead or switching the app to 
another language all together.

Apparently PyOpenSSL has no way to save a public key to a file which is 
baffling. M2Crypto has that ability but apparently no usable way to verify a 
certificate?

Is there really no usable module out there to enable straightforward 
certificate handling?

Regards,
  Dennis
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How To Read Excel Files In Python?

2005-12-13 Thread Dennis Benzinger
Anand schrieb:
> Hello,
> 
> Can I get some help on how to read the excel files using python?
> [...]

Besides using the Excel component you could use the pyExcelerator 
<http://sourceforge.net/projects/pyexcelerator> module.
You even don't need Windows for it.


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


Re: Newbie needs help with regex strings

2005-12-14 Thread Dennis Benzinger
Catalina Scott A Contr AFCA/EVEO schrieb:
> I have a file with lines in the following format.
> 
> pie=apple,quantity=1,cooked=yes,ingredients='sugar and cinnamon'
> Pie=peach,quantity=2,ingredients='peaches,powdered sugar'
> Pie=cherry,quantity=3,cooked=no,price=5,ingredients='cherries and sugar'
> 
> I would like to pull out some of the values and write them to a csv
> file.
> 
> For line in filea
>   pie = regex
>   quantity = regex
>   cooked = regex
>   ingredients = regex
>   fileb.write (quantity,pie,cooked,ingredients)
> 
> How can I retreive the values and assign them to a name?
> 
> Thank you
> Scott

Try this:

import re
import StringIO

filea_string = """pie=apple,quantity=1,cooked=yes,ingredients='sugar and 
cinnamon'
pie=peach,quantity=2,ingredients='peaches,powdered sugar'
pie=cherry,quantity=3,cooked=no,price=5,ingredients='cherries and sugar'
"""

FIELDS = ("pie", "quantity", "cooked", "ingredients", "price")

field_regexes = {}

for field in FIELDS:
 field_regexes[field] = re.compile("%s=([^,\n]*)" % field)

for line in StringIO.StringIO(filea_string):

 field_values = {}

 for field in FIELDS:
 match_object = field_regexes[field].search(line)

 if match_object is not None:
 field_values[field] = match_object.group(1)

 print field_values
 #fileb.write (quantity,pie,cooked,ingredients)



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


Re: Newbie needs help with regex strings

2005-12-14 Thread Dennis Benzinger
Christopher Subich schrieb:
> Paul McGuire wrote:
> 
> [...]
> For the example listed, pyparsing is even overkill; the OP should 
> probably use the csv module.

But the OP wants to parse lines with key=value pairs, not simply lines
with comma separated values. Using the csv module will just separate the 
key=value pairs and you would still have to take them apart.

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


Re: to write set of values to a file from python

2005-12-14 Thread Dennis Benzinger
[EMAIL PROTECTED] schrieb:
> hi everybody
> 
> i want to write a set of values to a file from python.
> For ex:: the fields name will "comp name", "ip addr", "mac addr" etc.
> And below all these fields i ll have the values for these fields.
> 
> it should look some what like this.
> 
> comp name ipaddr macaddr
> 
> jdasfhjashd   234.347.23.12
> 334.12.354.43.232
> dfdsfusdaufisa   234.533.45.1289.234.234.2343
> sfdidsfoui  234.45.23.56
> 89.343.23.45.233
> 
> something like thiss.
> 
> so which is the best way to do this.
> I mean which file format would be the best to choose , to dump all
> these values from my python script.
> 
> Will it  be a ".ini" file format? or ".xls" or ".txt" which will be the
> better one.
> so that later it will be easy for me to read this file.
> 
> thanks in advance for the help
> 
> regards
> yogi
> 


I would use a comma separated values (CSV) file.
Have a look at the csv module 
<http://www.python.org/doc/2.4.2/lib/module-csv.html>.

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


Re: Python newbie needs help

2005-12-14 Thread Dennis Benzinger
Ron Hudson schrieb:
> [...]
> I have a .py file with some def scripts(?) in it. 

def is the begining of a function definition.

> [...]
> I am using "Import" to read it after I start an interactive python.  
> What I need
> right now is I seem to have some sort of scoping problems with the  
> world dictionary.
> 
> I can read it and write it and "world" lists it out. but my def  
> look(at): script
> it seems it doesn't see the the "world" dictionary.
> 
>  >>> import lets
>  >>> world = lets.loadworld()
>  >>> world
> {'wizarddescription':'A short guy wearing a robe and a pointy hat'}
>  >>> lets.look('wizard')
>  file "" line ?
>  file lets.py line 14 in look
> print world[at+'description']
> nameError:world
>  >>> at = 'wizard'
>  >>> print world[at+'description']
> A short guy wearing a robe and a pointy hat
>  >>>
> 
> Is there a way to make 'world' global? can I do it in lets.py?
> 
> Am I going about this all wrong?
> [...]

The easiest solution for you would be a world variable in your lets 
module. Then at the interactive prompt you could refer to it with 
lets.world. So the loadworld function in lets.py would look like this:

def loadworld():
 # Your loading code
 global world
 world = ...


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


Re: set & random.choice question

2005-12-14 Thread Dennis Benzinger
[EMAIL PROTECTED] schrieb:
> I want to do something like this:
> 
>   from random import choice
>   x = set(("jenny", "jacqui", "claire", "chris", "tracy"))
>   somebody = random.choice(x)
> 
> but I bet a "TypeError: unindexable object" error. Any suggestions for
> an elegant workaround?
> 
> I'm using set because I want to know that I have a collection of unique
> objects.
> 
> steve
> 

import random

x = set(("jenny", "jacqui", "claire", "chris", "tracy"))


def draw_from_set(a_set):
 random_index = random.randint(0, len(x) - 1)

 for i, name in enumerate(x):
 if i == random_index:
 return name

somebody = draw_from_set(x)

print somebody


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


Re: to write set of values to a file from python

2005-12-14 Thread Dennis Benzinger
[EMAIL PROTECTED] schrieb:
> [...]
> its printing each character in a seperate row where as
> i wanteach string in a seperate column?
> 
> so how can i do that?? Any help for this.
> [...]

Could you post your code here? Or explain what you did exactly.

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


SVG rendering with Python

2005-12-14 Thread Dennis Benzinger
Hi!

Does anybody know of a SVG rendering library for Python?

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


Re: Which package to choose?

2005-12-21 Thread Dennis Benzinger
ankit schrieb:
> Hi pupil, please let me know which package to choose for xml processing
> in python .
> Here are my requirements
> 
> "I want a package which provides me schema support along with minidom
> support.
> According to my findings, "libxml2" provides schema support but it
> needs either libxml2 or libgdome2 for minidom support. But these
> pacakges are not well tested exp libxml2dom.
> Also, libxml2 is not so much pythonic i,e more based and used with C.
> So there is lack of documentation for that and I am new to that. I need
> proper documentation"
> [...]

lxml <http://codespeak.net/lxml/> may be what you are looking for. It's
a pythonic binding for libxml2 and libxslt.


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


Re: How to get the type of an object?

2005-12-21 Thread Dennis Benzinger
Licheng Fang schrieb:
> I wrote a function with a list as its parameter. And the function has
> to perform different operations based on the datatypes of the elements.
> How can I decide whether an object is, say, a list or a string?
> 
> Thanks.
> 

To check if an object is of a particular type use isinstance(), to get 
the type of an object use type(). You can read more about this two 
function in the built-in functions documentation 
<http://www.python.org/doc/2.4.2/lib/built-in-funcs.html>. The types 
module <http://www.python.org/doc/2.4.2/lib/module-types.html> may also 
help you.

Small example:

a_list = [1, "two", [3], (4,), {5: 5}]


for item in a_list:
 if isinstance(item, list):
 print "It's a list"
 else:
 print type(item)


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


psexec and os.popen help

2006-01-06 Thread dennis . scales
I'm trying to wrap a psexec command in a python script so I can capture
the results and generate an exception report. The problem I'm having is
that when I use x = os.popen("command") to do it, it runs, but the
content of x is empty. I know there should be output sent to it,
because when I run the command from the DOS prompt, it shows it.  I
don't have this problem when wrapping other PSTools.  Has anyone else
had this problem, or can someone try it and verify that it works, then
show me there work?  I really appreciate it. Its been a late night.
Thanks

Dennis

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


Re: how to test for a dependency

2006-01-09 Thread Dennis Benzinger
Darren Dale schrieb:
> Hello,
> 
> I would like to test that latex is installed on a windows, mac or linux
> machine. What is the best way to do this? This should work:
> 
> if os.system('latex -v'):
> print 'please install latex'
> 
> but I dont actually want the latex version information to print to screen. I
> tried redirecting sys.stdout to a file, but that doesnt help. Is there a
> better way to do this in a cross-platform friendly way?
> 
> Thanks,
> Darren


I didn't try it, but you could use the subprocess module 
<http://python.org/doc/2.4.2/lib/module-subprocess.html>.
Create a Popen object with stdout = PIPE so that a pipe to the child 
process is created and connected to the client's stdout.


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


Re: Client/Server Question

2006-07-28 Thread Dennis Benzinger
[EMAIL PROTECTED] wrote:
> My server.py looks like this
> 
> -CODE--
> #!/usr/bin/env python
> import socket
> import sys
> import os
> 
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> host = ''
> port = 2000
> 
> s.bind((host,port))
> s.listen(1)
> conn, addr = s.accept()
> print 'client is at', addr
> 
> while True:
>   data = conn.recv(100)
>   if (data == 'MaxSim'):
>   print 'MaxiSim'
>   os.system('notepad')
>   elif (data == 'Driving Sim'):
>   print 'Driving Sim'
>   os.system('explorer')
>   elif (data == 'SHUTDOWN'):
>   print 'Shutting down...'
>   os.system('shutdown -s')
>   conn.close()
>   break
> ---CODE
> END-
> 
> I am running this above program on a windows machine. My client is a
> Linux box. What I want to achieve is that server.py should follows
> instructions till I send a 'SHUTDOWN' command upon which it should shut
> down.
> 
> When I run this program and suppose send 'MaxSim' to it, it launches
> notepad.exe fine, but then after that it doesn't accept subsequent
> command. I want is that it should accept subsequent commands like
> Driving Sim and launch windows explorer etc untill I send a 'SHUTDOWN'
> command.
> 
> Any help on this, it will be greatly appreciated.
> 


os.system() blocks until the called program has finished. Use the 
subprocess module <http://docs.python.org/lib/module-subprocess.html>:



import subprocess

subprocess.Popen("notepad")




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


Re: Client/Server Question

2006-07-29 Thread Dennis Benzinger
[EMAIL PROTECTED] wrote:
> Is os.system() going to be deprecated in future ?.I read somewhere.
> [...]

Sometime in the future it will. But that won't happen soon. Read the 
second paragraph of "Backwards Compatibility" in the subprocess PEP 
<http://www.python.org/dev/peps/pep-0324/>.


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


Re: Newbie help - test for data type

2006-07-31 Thread Dennis Benzinger
Jonathan Bowlas wrote:
> Hi Listers,
> 
> I have a requirement to test for a data type could someone tell me if this
> is possible in python?
> 
> Basically I have a ZPT in Zope that users can select checkboxes in a form
> which pass arguments for a python function, however if there is only one
> checkbox selected it is passed as a string whereas more than one checkbox is
> passed as a list. Therefore if my function is required to perform an action
> based on each argument passed in the list the function works correctly but
> if it is passed as a string nothing happens.

You need the isinstance() function. For example you can use
isinstance(selecteddeptcodes, list) to test if your variable is a list. 
If you want to test the other way round use 
isinstance(selecteddeptcodes, str) if your variable is a string, 
isinstance(selecteddeptcodes, unicode) if it's a unicode string or 
isinstance(selecteddeptcodes, basestring) to test if it's a string or 
unicode string. Read more about this function and the types to test for 
in http://docs.python.org/lib/built-in-funcs.html.

If you already have the code for a list argument I'd check if it's not a 
list and then turn it into a list:


if not isintance(selecteddeptcodes, list):
 selecteddeptcodes = [selecteddeptcodes]



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


strftime replacement which supports Unicode format strings?

2006-08-06 Thread Dennis Benzinger
Is there a library with a strftime replacement which supports Unicode 
format strings?


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


Re: item access time: sets v. lists

2006-10-04 Thread Dennis Benzinger
On Wed, 04 Oct 2006 16:02:56 GMT
"David Isaac" <[EMAIL PROTECTED]> wrote:

> Is it expected for access to set elements to be much
> slower than access to list elements?  Explanation?
> Thanks,
> Alan Isaac
> 
> >>> t1=timeit.Timer("for i in set(xrange(1)):pass","")
> >>> t2=timeit.Timer("for i in list(xrange(1)):pass","")
> [...]

You're measuring the time for creating the xrange and the set/list too.
Create them before you call Timer() and repeat your timing.


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


Re: How to check for instances of a class

2006-11-14 Thread Dennis Benzinger
On 14 Nov 2006 11:00:53 -0800
[EMAIL PROTECTED] wrote:

> Traversing a list of variables, I need to check wheter an element in
> the list is an instance of a (user defined) class. What cind of
> comparison operator can I use? Can't seem to find this in the
> documentation. I anyone have an example it is much appreciated.

Use isinstance() <http://docs.python.org/lib/built-in-funcs.html>.

You need something like 

>> isinstance(list_element, your_class)


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


Re: Using pysqlite2

2006-06-02 Thread Dennis Benzinger
[EMAIL PROTECTED] wrote:
> Is it possible to use this for sending triggers to a sqlite db?Could
> someone provide me with an example of how to do this please?
> Thanks

Do you want to implement a trigger for a SQLite database in Python?

That won't work. Triggers in SQLite can only contain UPDATE, INSERT, 
DELETE and SELECT statements http://sqlite.org/lang_createtrigger.html>.

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


Re: in python , could I accomplish the purpose that "a=Console.read()" used in C?

2006-06-04 Thread Dennis Benzinger
python wrote:
> in python , could I accomplish the purpose that "a=Console.read()" used
> in C?
> when program is running, I wanna add a statement like
> "a=Console.read()" in C language,it will wait for user's input, after
> user's typing a character , and click "enter" key, the program will go
> on running.
> 


Use raw_input() <http://docs.python.org/lib/built-in-funcs.html>:

age = raw_input("Your age: ")
print age


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


Re: How do I automatically redirect stdout and stderr when using os.popen2?

2006-06-07 Thread Dennis Benzinger
[EMAIL PROTECTED] wrote:
> How do I automatically redirect stdout and stderr when using os.popen2
> to start a long running process.  If the process prints a lot of stuff
> to stdout it will eventually stop because it runs out of buffer space.
> Once I start reading the stdout file returned by os.popen2 then the
> process resumes.  I know that I could just specify > /dev/null when
> starting the process but I'd like to know if there is a way to start a
> process using os.popen2 or some other way so that all standard out and
> standard error goes to /dev/null or some other file.
> 
> Thanks,
> Mike
> 


Use the POpen class <http://docs.python.org/lib/node235.html> from the 
subprocess module.


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


Re: creating and naming objects

2006-06-07 Thread Dennis Benzinger
Brian wrote:
> [...]
> For example, lets say that I have a class that creates a student
> object.
> 
> Class Student:
> def setName(self, name)
> self.name = name
> def setId(self, id)
> self.id = id
> 
> Then I instantiate that object in a method:
> 
> def createStudent():
> foo = Student()
> /add stuff
> 
> Now, suppose that I want to create another Student.  Do I need to name
> that Student something other than foo?  What happens to the original
> object?  If I do not supplant the original data of Student (maybe no id
> for this student) does it retain the data of the previous Student
> object that was not altered?  I guess I am asking how do I
> differentiate between objects when I do not know how many I need to
> create and do not want to hard code names like Student1, Student2 etc.
> [...]


Just return your Student object from createStudent() and put it in a 
list. For example:

all_students = []

for i in range(10):
 one_student = createStudent()

 # Do what you want with one_student here

 all_students.append(one_student)

print all_students


BTW: Why don't you use a constructor to create Student objects?

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


Re: tracking dependencies

2006-06-08 Thread Dennis Benzinger
Michele Simionato wrote:
> I have a big framework (not written by me) with lots of internal
> dependencies and I am
> looking for a tool to see the dependency tree. I.e. given a module x,
> it should show me all the modules imported by x, and the modules
> imported
> by them recursively. Standard library modules should be ignored
> and there should be an option to turns off the visualization of certain
> 
> modules, for instance the ones in given subpackages. I guess somebody
> has already written it, maybe even with
> a nice visual backend. Any hint?
> 
>Michele Simionato
> 

I've never tried it, but http://www.tarind.com/depgraph.html looks like 
what you are looking for.

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


Re: Python with Eclipse

2006-06-19 Thread Dennis Benzinger
Stan Cook wrote:
> I've been trying to use Eclipse with Python on Linux for a while and 
> have noticed something odd.  After running the code or debugging a few 
> times, its responsiveness gets really bad.  Upon checking the equivalent 
> of the task manager, I find several instances of Python running.  When I 
> kill these instances, the responsiveness comes back.  I'm not sure if 
> there is a better place to post this, but it is Python related.  Is this 
> just an issue with Eclipse or is there something else I should inspect?
> 
> Any help would be appreciated.
> 
> Regards,
> 
> S Cook

Which Python plugin are you using? PyDev?


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


Re: Python with Eclipse

2006-06-20 Thread Dennis Benzinger
Philippe Martin wrote:
> Dennis Benzinger wrote:
> 
>> Stan Cook wrote:
>>> I've been trying to use Eclipse with Python on Linux for a while and
>>> have noticed something odd.  After running the code or debugging a few
>>> times, its responsiveness gets really bad.  Upon checking the equivalent
>>> of the task manager, I find several instances of Python running.  When I
>>> kill these instances, the responsiveness comes back.  I'm not sure if
>>> there is a better place to post this, but it is Python related.  Is this
>>> just an issue with Eclipse or is there something else I should inspect?
>>>
>>> Any help would be appreciated.
>>>
>>> Regards,
>>>
>>> S Cook
>> Which Python plugin are you using? PyDev?
>>
>>
>> Bye,
>> Dennis
> 
> Hi,
> 
> What other plugins are there ?
> 
> Regards,
> 
> Philippe
> 


In the Python wiki there is a page about Eclipse plugins for Python:

http://wiki.python.org/moin/EclipsePythonIntegration


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


Problem with sets and Unicode strings

2006-06-27 Thread Dennis Benzinger
Hi!

The following program in an UTF-8 encoded file:


# -*- coding: UTF-8 -*-

FIELDS = ("Fächer", )
FROZEN_FIELDS = frozenset(FIELDS)
FIELDS_SET = set(FIELDS)

print u"Fächer" in FROZEN_FIELDS
print u"Fächer" in FIELDS_SET
print u"Fächer" in FIELDS


gives this output


False
False
Traceback (most recent call last):
   File "test.py", line 9, in ?
 print u"FÀcher" in FIELDS
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1: 
ordinal not in range(128)


Why do the first two print statements succeed and the third one fails 
with an exception?

Why does the use of set/frozenset remove the exception?


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


Re: Python UTF-8 and codecs

2006-06-27 Thread Dennis Benzinger
Mike Currie wrote:
> I'm trying to write out files that have utf-8 characters 0x85 and 0x08 in 
> them.  Every configuration I try I get a UnicodeError: ascii codec can't 
> decode byte 0x85 in position 255: oridinal not in range(128)
> 
> I've tried using the codecs.open('foo.txt', 'rU', 'utf-8', errors='strict') 
> and that doesn't work 
 > [...]

You want to write to a file but you used the 'rU' mode. This should be 
'wU'. Don't know if this is the only reason it doesn't work. Could you 
show more of your code?


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


Re: Problem with sets and Unicode strings

2006-06-27 Thread Dennis Benzinger
Serge Orlov wrote:
> On 6/27/06, Dennis Benzinger <[EMAIL PROTECTED]> wrote:
>> Hi!
>>
>> The following program in an UTF-8 encoded file:
>>
>>
>> # -*- coding: UTF-8 -*-
>>
>> FIELDS = ("Fächer", )
>> FROZEN_FIELDS = frozenset(FIELDS)
>> FIELDS_SET = set(FIELDS)
>>
>> print u"Fächer" in FROZEN_FIELDS
>> print u"Fächer" in FIELDS_SET
>> print u"Fächer" in FIELDS
>>
>>
>> gives this output
>>
>>
>> False
>> False
>> Traceback (most recent call last):
>>File "test.py", line 9, in ?
>>  print u"FÀcher" in FIELDS
>> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1:
>> ordinal not in range(128)
>>
>>
>> Why do the first two print statements succeed and the third one fails
>> with an exception?
> 
> Actually all three statements fail to produce correct result.

So this is a bug in Python?

> frozenset remove the exception?
> 
> Because sets use hash algorithm to find matches, whereas the last
> statement directly compares a unicode string with a byte string. Byte
> strings can only contain ascii characters, that's why python raises an
> exception. The problem is very easy to fix: use unicode strings for
> all non-ascii strings.

No, byte strings contain characters which are at least 8-bit wide 
<http://docs.python.org/ref/types.html>. But I don't understand what 
Python is trying to decode and why the exception says something about 
the ASCII codec, because my file is encoded with UTF-8.


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


Re: Problem with sets and Unicode strings

2006-06-28 Thread Dennis Benzinger
Serge Orlov wrote:
> On 6/27/06, Dennis Benzinger <[EMAIL PROTECTED]> wrote:
>> Serge Orlov wrote:
>> > On 6/27/06, Dennis Benzinger <[EMAIL PROTECTED]> wrote:
>> >> Hi!
>> >>
>> >> The following program in an UTF-8 encoded file:
>> >>
>> >>
>> >> # -*- coding: UTF-8 -*-
>> >>
>> >> FIELDS = ("Fächer", )
>> >> FROZEN_FIELDS = frozenset(FIELDS)
>> >> FIELDS_SET = set(FIELDS)
>> >>
>> >> print u"Fächer" in FROZEN_FIELDS
>> >> print u"Fächer" in FIELDS_SET
>> >> print u"Fächer" in FIELDS
>> >>
>> >>
>> >> gives this output
>> >>
>> >>
>> >> False
>> >> False
>> >> Traceback (most recent call last):
>> >>File "test.py", line 9, in ?
>> >>  print u"FÀcher" in FIELDS
>> >> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in 
>> position 1:
>> >> ordinal not in range(128)
>> >>
>> >>
>> >> Why do the first two print statements succeed and the third one fails
>> >> with an exception?
>> >
>> > Actually all three statements fail to produce correct result.
>>
>> So this is a bug in Python?
> 
> No.
> 
>> > frozenset remove the exception?
>> >
>> > Because sets use hash algorithm to find matches, whereas the last
>> > statement directly compares a unicode string with a byte string. Byte
>> > strings can only contain ascii characters, that's why python raises an
>> > exception. The problem is very easy to fix: use unicode strings for
>> > all non-ascii strings.
>>
>> No, byte strings contain characters which are at least 8-bit wide
>> <http://docs.python.org/ref/types.html>.
> 
> Yes, but later it's written that non-ascii characters do not have
> universal meaning assigned to them. In other words if you put byte
> 0xE4 into a bytes string all python knows about it is that it's *some*
> character. If you put character U+00E4 into a unicode string python
> knows it's a "latin small letter a with diaeresis". Trying to compare
> *some* character with a specific character is obviously undefined.
 > [...]

But <http://docs.python.org/ref/comparisons.html> says:

Strings are compared lexicographically using the numeric equivalents 
(the result of the built-in function ord()) of their characters. Unicode 
and 8-bit strings are fully interoperable in this behavior.

Doesn't this mean that Unicode and 8-bit strings can be compared and 
this comparison is well defined? (even if it's is not meaningful)



Thanks for your anwsers,
Dennis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with sets and Unicode strings

2006-06-28 Thread Dennis Benzinger
Robert Kern wrote:
> Dennis Benzinger wrote:
>> Serge Orlov wrote:
>>> On 6/27/06, Dennis Benzinger <[EMAIL PROTECTED]> wrote:
>>>> Hi!
>>>>
>>>> The following program in an UTF-8 encoded file:
>>>>
>>>>
>>>> # -*- coding: UTF-8 -*-
>>>>
>>>> FIELDS = ("Fächer", )
>>>> FROZEN_FIELDS = frozenset(FIELDS)
>>>> FIELDS_SET = set(FIELDS)
>>>>
>>>> print u"Fächer" in FROZEN_FIELDS
>>>> print u"Fächer" in FIELDS_SET
>>>> print u"Fächer" in FIELDS
>>>>
>>>>
>>>> gives this output
>>>>
>>>>
>>>> False
>>>> False
>>>> Traceback (most recent call last):
>>>>File "test.py", line 9, in ?
>>>>  print u"FÀcher" in FIELDS
>>>> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1:
>>>> ordinal not in range(128)
>>>>
>>>>
>>>> Why do the first two print statements succeed and the third one fails
>>>> with an exception?
>>> Actually all three statements fail to produce correct result.
>>
>> So this is a bug in Python?
> 
> No.
> [...]

But I'd say that it's not intuitive that for sets x in y can be false 
(without raising an exception!) while the doing the same with a tuple 
raises an exception. Where is this difference documented?


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

Re: Problem with sets and Unicode strings

2006-06-29 Thread Dennis Benzinger
Diez B. Roggisch wrote:
>> But I'd say that it's not intuitive that for sets x in y can be false
>> (without raising an exception!) while the doing the same with a tuple
>> raises an exception. Where is this difference documented?
> 
> 2.3.7 Set Types -- set, frozenset
> 
> ...
> 
> Set elements are like dictionary keys; they need to define both __hash__ and
> __eq__ methods.
> ...
> 
> And it has to hold that
> 
> a == b => hash(a) == hash(b)
> 
> but NOT
> 
> hash(a) == hash(b) => a == b
> 
> Thus if the hashes vary, the set doesn't bother to actually compare the
> values.
> [...]

Ok, I understand.
But isn't it a (minor) problem that using a set like this:

# -*- coding: UTF-8 -*-

FIELDS_SET = set(("Fächer", ))


print u"Fächer" in FIELDS_SET
print u"Fächer" == "Fächer"


shadows the error of not setting sys.defaultencoding()?


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


Re: Problem with sets and Unicode strings

2006-06-29 Thread Dennis Benzinger
Robert Kern wrote:
> Dennis Benzinger wrote:
>> Ok, I understand.
>> But isn't it a (minor) problem that using a set like this:
>>
>> # -*- coding: UTF-8 -*-
>>
>> FIELDS_SET = set(("Fächer", ))
>>
>> print u"Fächer" in FIELDS_SET
>> print u"Fächer" == "Fächer"
>>
>> shadows the error of not setting sys.defaultencoding()?
> 
> You can't set the default encoding. If you could, then scripts that run 
> on your machine wouldn't run on mine.
> [...]

As Serge Orlov wrote in one of his posts you _can_ set the default 
encoding (at least in site.py). See 
<http://docs.python.org/lib/module-sys.html>


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

Re: change the size of front

2006-07-04 Thread Dennis Benzinger
aliassaf wrote:
> hi, 
> I want to change the size of the front in a legend, i wrote this small
> program and it got to me this message error!!!
> 
> from pylab import *
> plot([1,2,3],'r')
> legend('this',prop = FontProperties('smaller') )

Try

legend('this',prop = matplotlib.font_manager.FontProperties(size = 
'smaller'))

> show()
> 
> NameError: name 'FontProperties' is not defined
> 
> thanks 



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


Re: Finding Return Code From GPG

2006-07-04 Thread Dennis Benzinger
Nomen Nescio wrote:
> I'm running gpg in python to verify a signature. I can see that it is
> working, because gpg is displaying the results.
> 
> But I need a way to let the python script know this. According to the gpg
> manual there is a return code from gpg of 0 if the verify is good and 1 if
> it is bad.
> 
> Can anyone tell me how I can get the python script to 'see' this return
> code?
> 

How do you run GPG? I suggest using the subprocess module 
<http://docs.python.org/lib/module-subprocess.html>. If you just need 
something simple then you can use its call function 
<http://docs.python.org/lib/node236.html>.


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


Re: [Mailman-Developers] Parsing and Rendering rfc8222

2006-07-05 Thread John Dennis
On Tue, 2006-07-04 at 15:44 -0400, emf wrote:
> In order to provide interfaces to archives, I believe I must perform 
> some intermediary manipulation; my goal is to get the information 
> contained within the .mbox files mailman generates into ElementTrees and 
> other objects so as to represent them via HTML/RSS/Atom/etc.

It's not at all clear to me that mailman should be responsible for
archiving. Archiving and MLM (Mailing List Manager) functionality can be
orthogonal to each other. Archiving has a complex feature set if it's
done right, and it's complex to implement. There are many items on
Mailman's UI task list which need attention and can be done
independently of also trying to tackle the 800 pound gorilla known as
archiving.

If we do anything in the near term with archiving I suggest it be only
to clean up and further define an interface between Mailman as a MLM and
an independent mail archiver which would allow installations to install
the mail archiver of their choice along side of Mailman. I seem to
recall this is also Barry's preference who noted the existing pipermail
was only a stop-gap solution so there would be some default archiver,
but it was never the intention Mailman would have any extensive
archiving implementation.

For what its worth I went looking for best of breed in open source
archivers about 6 months ago and what I came up with was a project
called "Lurker" (http://lurker.sourceforge.net)

IMHO let the archiving experts deal with archiving, let the MLM experts
(e.g. Mailman) deal with managing mailing lists.

I recognize that Mailman would benefit from tighter integration with the
archiver such that it is possible to automatically include links in mail
which is being redistributed by the MLM, but rather than bringing any of
this functionality into Mailman lets define the interfaces which are
needed such that Mailman can operate cooperatively with any archiver
which supports a well defined API.

-- 
John Dennis <[EMAIL PROTECTED]>
Red Hat Inc.

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


Re: [Mailman-Developers] Parsing and Rendering rfc2822

2006-07-06 Thread John Dennis
On Thu, 2006-07-06 at 13:45 -0400, Brad Knowles wrote:

> [ snip discussion of fixing pipermail and alternate archivers ]

>  But this is a pretty big undertaking.

I'm 100% with Brad on this, this is a huge chunk of work, probably a
project in its own regard. Would you really finish this during your
summer of code? You've got great ideas, but be realistic about what you
can actually accomplish and don't forget for those folks who dislike
pipermail one can with minimal effort use an external archiver. 
-- 
John Dennis <[EMAIL PROTECTED]>
Red Hat Inc.

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


Re: [Mailman-Developers] Parsing and Rendering rfc2822

2006-07-06 Thread John Dennis
On Thu, 2006-07-06 at 14:17 -0400, John Dennis wrote:
> ... don't forget for those folks who dislike
> pipermail one can with minimal effort use an external archiver. 

Oh, and I should have added that one of the beefs with using an external
archiver is the disjoint UI between mailman and the archiver, the look
and feel and be very different. But since you're adding support for
stylesheets with mailman this issue is minimized, external archivers
become that much more attractive because it's easier to unify the look
and feel.

Speaking of stylesheets and customized UI, are you planning on having
the core mailman code generate xml, which then is transformed with xslt?
This might be more flexible than relying on javascript to control what
is presented to the user. Sites can then replace the xslt if need be.
Javascript still has a very valuable role to play and I'm not suggesting
not using it, but rather introducing an xslt transform means there would
be very little a site could not customize without ever touching mailman
internals.
-- 
John Dennis <[EMAIL PROTECTED]>
Red Hat Inc.

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


BIOS Changes (enable WOL)

2006-09-14 Thread Feiock, Dennis








I was wondering if it is possible to access the BIOS
settings on a system using Python.  I would like to be able to write a script
that would enable WOL on a specified system.  For the most part, it would be
Win32 systems, but could be just about any flavor of UNIX as well.

 

Thanks for any help that can be provided,

 - DF






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

Re: automatically grading small programming assignments

2006-12-14 Thread Dennis Benzinger
Am Thu, 14 Dec 2006 12:27:07 -0500
schrieb Brian Blais <[EMAIL PROTECTED]>:

> Hello,
> 
> I have a couple of classes where I teach introductory programming
> using Python.  What I would love to have is for the students to go
> through a lot of very small programs, to learn the basic programming
> structure.  Things like, return the maximum in a list, making lists
> with certain patterns, very simple string parsing, etc.
> Unfortunately, it takes a lot of time to grade such things by hand,
> so I would like to automate it as much as possible.
> 
> I envision a number of possible solutions.  In one solution, I
> provide a function template with a docstring, and they have to fill
> it in to past a doctest.  Is there a good (and safe) way to do that
> online?  Something like having a student post code, and the doctest
> returns.  I'd love to allow them to submit until they get it, logging
> each attempt.
> 
> Or perhaps there is a better way to do this sort of thing.  How do
> others who teach Python handle this?
> 
> 
>   thanks,
> 
> 
>   Brian Blais
> 


Perhaps the Sphere Online Judge can help you: https://www.spoj.pl/info/


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


Re: sha, PyCrypto, SHA-256

2006-12-16 Thread Dennis Benzinger
Am 16 Dec 2006 11:17:19 -0800
schrieb [EMAIL PROTECTED]:

> Operating system: Win XP
> Vsn of Python: 2.4
> 
> Situation is this: Required to calcluate a message digest.  The
> process for calcluating the digest must use an SHA-256 algorithm.
> 
> Questions:
> 1) Is it correct that the sha module comes with python 2.4?
> 2) Is it correct that the sha module that ships with python 2.4 does
> NOT have the SHA-256 capability as part of the module?
> 3) It looks like PyCrypto is a package that, among other things,
> permits one to calculate a message digest using an SHA-256
> algorithm...is that correct?
> 4) It looks like there are a couple couple possibilities available for
> the download...either download the source code and run the setup which
> (I'm assuming) compiles the various extension modules, or download the
> pycrypto-2.0.1.win32-py2.4.zip which extracts out to a .exe; when one
> runs the just-extracted .exe, it installs the stuff on one's
> workstation.  I'm leaning toward the second option because it seems
> like most of the work has been done for me.  A quick search on this
> site didn't turn up anything that suggested there were problems with
> running the installer.  So, my question is this: are you aware of any
> problems running the installer?
> 5) Besides PyCrypto, are there any other Python packages that permit
> one to calculate a message digest using an SHA-256 algorithm?
> 
> Thank you.
> 


Python 2.5 comes with SHA-256 in the hashlib module.
So you could install Python 2.5 instead of the PyCrypto module.


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


Re: url filtering

2006-12-17 Thread Dennis Benzinger
Am Sun, 17 Dec 2006 20:14:32 +0100
schrieb vertigo <[EMAIL PROTECTED]>:

> Hello
> 
> I want to do some text analysis based on html documents grabbed from  
> internet.
> Is there any library which could allow me easily getting text from
> html documents
> (cutting javascript, html tags and other not nececary data) ?
> 
> Thanx

Try Beautiful Soup: http://www.crummy.com/software/BeautifulSoup/


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


Re: Python and XML Schema

2006-01-25 Thread Dennis Benzinger
Trond wrote:
> I have a need to, given a XML document with XML Schema defined, to get the 
> type of each element in the XML file based on the XML Schema URI given. IE, 
> the  element is of simple datatype string. Is there any existing 
> Python libraries were I can parse the XML file, and for a given node ask for 
> the datatype (which should be taken from XML Schema?)
> [...]

Take a look at lxml. It's a pythonic binding for libxml2 and libxslt.
libxml2 <http://xmlsoft.org/> implements XML Schema Part 2: Datatypes 
and partially XML Schema Part 1: Structures.
I don't know how complete the structures implementation is and if it can 
already do what you want. So you might ask the libxml2 guys how to do 
what you want with libxml2 and then use lxml to do it in Python.

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


Re: Strange behavior with os call in cgi script

2006-02-05 Thread Dennis Benzinger
sophie_newbie schrieb:
> I have written a cgi script that seems to run perfectly from the
> command line when I simulate some cgi input using
> os.environ['QUERY_STRING'].
> 
> The thing is that when I run it from the browser, one of my os.system
> calls, which gets excecuted fine when running the program in the
> interpreter, doesn't seem to get excecuted, or gets excecuted but does
> nothing.
> 
> Does anyone know whats going on or how I could debug this problem?
 > [...]

Probably the environment is different when your program is executed by 
your web server. So either PATH is wrong and your program is not found 
or some other environment variable is wrong and you could debug it by 
printing the environment in your program.


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


Re: Most prominent Tkinter applications?

2006-02-05 Thread Dennis Benzinger
Kevin Walzer schrieb:
> I'm looking for examples of "best practices" in Tkinter/Python
> programming. What are the most prominent Python applications out there
> that use Tkinter as the GUI toolkit? These can be commercial or
> open-source, but are preferably multi-platform.
> 
> I know IDLE is written in Tkinter, so that's one example. Can anyone
> direct me to others?
> 

Leo <http://webpages.charter.net/edreamleo/front.html>, an outlining 
editor, uses Tkinter.

It's at least as prominent as IDLE ;-)


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


Re: apache mod_python problem

2006-02-15 Thread Dennis Benzinger
Ido Yehieli schrieb:
> [...]
> Anyone has any idea as to what went wrong?
> [...]

If you compiled mod_python as a Dynamic Shared Object (DSO) you have to 
tell Apache to load that module. For example like this:

LoadModule python_module libexec/mod_python.so

See the mod_python documentation, especially the Configuring Apache section:

http://modpython.org/live/current/doc-html/inst-apacheconfig.html

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


  1   2   3   4   >