[issue4966] Improving Lib Doc Sequence Types Section

2009-06-05 Thread Dennis Benzinger

Changes by Dennis Benzinger dennis.benzin...@gmx.net:


--
nosy: +dcbbcd

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4966
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3292] Position index limit; s.insert(i,x) not same as s[i:i]=[x]

2009-06-05 Thread Dennis Benzinger

Changes by Dennis Benzinger dennis.benzin...@gmx.net:


--
nosy: +dcbbcd

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue3292
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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: 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: 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: 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: 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


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: 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


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: 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:

untested_code

import subprocess

subprocess.Popen(notepad)

/untested_code


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: 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 uFächer in FIELDS_SET
print uFä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 uFächer in FIELDS_SET
 print uFä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: 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 uFächer in FROZEN_FIELDS
  print uFächer in FIELDS_SET
  print uFächer in FIELDS
 
 
  gives this output
 
 
  False
  False
  Traceback (most recent call last):
 File test.py, line 9, in ?
   print uFÀ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 uFächer in FROZEN_FIELDS
 print uFächer in FIELDS_SET
 print uFächer in FIELDS


 gives this output


 False
 False
 Traceback (most recent call last):
File test.py, line 9, in ?
  print uFÀ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

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 uFächer in FROZEN_FIELDS
print uFächer in FIELDS_SET
print uFächer in FIELDS


gives this output


False
False
Traceback (most recent call last):
   File test.py, line 9, in ?
 print uFÀ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 uFächer in FROZEN_FIELDS
 print uFächer in FIELDS_SET
 print uFächer in FIELDS


 gives this output


 False
 False
 Traceback (most recent call last):
File test.py, line 9, in ?
  print uFÀ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: 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


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: 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: 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: 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: 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: Class probkem - getting msg that self not defined

2006-05-22 Thread Dennis Benzinger
wes weston schrieb:
 Andrew Robert wrote:
 
 wes weston wrote:

 Andrew Robert wrote:

 Hi Everyone,

 I am having a problem with a class and hope you can help.

 When I try to use the class listed below, I get the statement that self
 is not defined.
test=TriggerMessage(data)

 self is not known here; only inside the class.

 var = test.decode(self.qname)

 snip

 I guess I was barking up the wrong tree on that one.

 How would I go about getting the required values out of the class?

 Return self?
 
 
 You can refer to the variables inside the class as test.version;
 for example - as they are not protected. Or, you could add access
 methods in the class like def GetVersion(self): return self.version
 If you want to protect version, call it self.__version which mangles
 the name from outside.
 wes

Or use the property function to define properties 
http://docs.python.org/lib/built-in-funcs.html.

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


Re: File encoding strategy question

2006-05-21 Thread Dennis Benzinger
Andrew Robert schrieb:
 Hi everyone,
 
 I am in the process of creating a file transmit/receiver program using
 MQSeries.
 
 The way it works is through creation of an XML message.
 
 Elements within the XML message contain things such as file name, size,
 and the file contents.
 
 The file contents are encoded, currently using Base64, for support of
 both binary and text data.
 
 This works great but there is a small rub to the problem.
 
 I would like to be able to view the contents of the file if it is text
 while still maintaining the ability to transmit binary data.
 
 Does anyone know of an encoding format that would make this possible?
 [...]

Yes. You could use the Quoted-Printable encoding. See RFC 2045
Multipurpose Internet Mail Extensions (MIME) Part One: Format of
Internet Message Bodies ftp://ftp.rfc-editor.org/in-notes/rfc2045.txt


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


Re: escapes in regular expressions

2006-05-21 Thread Dennis Benzinger
James Thiele schrieb:
 I was helping a guy at work with regular expressions and found
 something I didn't expect:
 
 
re.match('\d', '7').group()
 
 '7'

'\d' is not recognized as a escape sequence by Python and therefore it
is left unchanged http://docs.python.org/ref/strings.html in the
string which is passed to re.match.

 
re.match('\\d', '7').group()
 
 '7'
 [...]

This is the correct version. The first backslash escapes the second one
and this version will work even if a future version of Python recognizes
   \d as an escape sequence.


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


Update Demo/ and Tools/ directories

2006-04-24 Thread Dennis Benzinger
Hi!

I'd like to help with updating the Demo/ and Tools/ directories as it is 
suggested in the Python Wiki http://wiki.python.org/moin/SimpleTodo.

How exactly should the directories be updated? Should it just be made 
sure that the demos and examples are working or should they be updated 
to use the newest applicable Python features (e.g. the new any/all 
functions)?


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


Outdated Python Info on www.unicode.org

2006-03-03 Thread Dennis Benzinger
The Unicode Consortium has a page about Unicode Enabled Products 
http://www.unicode.org/onlinedat/products.html. This page contains 
some really outdated information about Python (like Python 2.3 will come 
out in a few months).

Could someone who knows the current state of Unicode support in Python 
update this information?


Thanks,
Dennis Benzinger
-- 
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


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: 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 title 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: 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: 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


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 worldcr 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 stdin 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: 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


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: 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


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: 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: 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: 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


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: 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


Re: Self-modifying Code

2005-05-19 Thread Dennis Benzinger
[EMAIL PROTECTED] schrieb:
 [...]
 Also Python can (writing and running a module, in-line):
 
 fNew =open(newModule.py,'w')
 lNew=['print 123\n','print 454\n','print 789\n']
 fNew.writelines(lNew)
 fNew.close()
 from newModule import *
  [...]

You don't even need a file for this.
Try: exec(print 123; print 456; print 789)

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


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: 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: 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: pyclbr

2005-02-10 Thread Dennis Benzinger
Fernando San Martn 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: 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


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: 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 pyshell#2, 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 pyshell#6, 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: 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: 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: 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