Re: Isn't bool __invert__ behaviour strange?

2006-09-22 Thread Carsten Haese
On Fri, 2006-09-22 at 11:25, Saizan wrote:
 Bjoern Schliessmann wrote:
  Saizan wrote:
 
   Why subclassing bool from int either __invert__ or __neg__ haven't
   been overrided to produce a boolean negation?
 
  I wonder what -True or -False should evaluate to.
 Well in boolean notation -True == False and  -False == True, actually
 you may prefer ¬ or a line over the term, but since there's no such
 operator in python [...]

It's called not:

 not True
False
 not False
True

-Carsten


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


Re: Nested Looping SQL Querys

2006-09-21 Thread Carsten Haese
On Thu, 2006-09-21 at 01:12, Dennis Lee Bieber wrote:
 On Wed, 20 Sep 2006 13:21:54 -0400, Steve Holden [EMAIL PROTECTED]
 declaimed the following in comp.lang.python:
 
  .execute() is a cursor method, not a connection method. Some DB API 
  modules do implement it as a connection method, but that makes it 
  impossible for several cursors to share the same connection (which is 
  allowed by some modules).
 
   It struck me that the original wasn't using a cursor just after the
 messages posted.

It doesn't look like the OP is using anything even remotely DB-API
compliant:


import cmi
snip
import hermes
conn = hermes.db()
snip

pubID=cgiForm.getvalue('pubID')
pubName=cgiForm.getvalue('pubName','Unknown Publication')

sqlcheck1 = SELECT pub_type FROM medusa.cmi_publication WHERE pub_id =
'+pubID+'
overseas1 = conn.query(sqlcheck1)
pubType = cmi.fetch_rows(overseas1)


hermes is apparently some wrapper that magically can connect to a
well-known database (via the argumentless db()) call. Who knows what
kind of animal the 'conn' object is that comes out of that db() call.
Apparently it's an object with a query() method that returns something
like a cursor that can be passed into cmi.fetch_rows(). At this point I
wonder why the responsibility of fetching rows is in a module separate
from the responsibility of establishing a database connection.

Legacy code, indeed.

-Carsten


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


Re: Python/MySQL problem on Windows

2006-09-20 Thread Carsten Haese
On Wed, 2006-09-20 at 16:37, Eric Smith wrote:
 I'm trying to use Python 2.4.3 and pywin32-209 to access a MySQL
 database on Windows Server 2003 Standard Edition, and not having much
 luck. It seems like parts of the MySQLdb module are not getting loaded
 correctly, but no error message is given during the import, even if I
 give a -vv on the command line.
 
 I'm trying to do:
 
 import MySQLdb
 db = MySQLdb.connection (db=database, user=user, passwd=password)

What happens if you use connect(...) instead of connection(...)?

-Carsten


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


Re: REQ: Java/J2EE Developer 10 Months

2006-09-15 Thread Carsten Haese
On Fri, 2006-09-15 at 14:41, Steve Holden wrote:
 [EMAIL PROTECTED] wrote:
 [...]
  Skill:
  
  
  *Java, 2 year UNIX - HP / Solaris, 2 yrs OOA+D, Corba, Perl, XML, UML.
  *Java dev experience, Swing, JPS, 2 years of OOA+D.
 
 Clearly not spam, since the guy is so in touch with the readership of 
 this group ... sigh ... is it just me, or is this person an idiot?

Yes, he is an idiot. Good call on CC'ing your assessment to him. :)

-Carsten


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


Re: re.compile() doesn't work under Windows?

2006-08-31 Thread Carsten Haese
On Thu, 2006-08-31 at 17:38, ddtl wrote:
 Hello everybody.
 
 My script uses re.compile() function, and while it rans without errors
 under Linux, when I ran that script under Windows I get the following
 error:
 
 Traceback (most recent call last):
   File C:\a\projects\re.py, line 4, in ?
 import re
   File C:\a\projects\re.py, line 95, in ?
 main()
   File C:\a\projects\re.py, line 37, in main
 s_exp = re.compile(op['-s'])
 AttributeError: 'module' object has no attribute 'compile'
 
 What is the problem here? re module is installed and is on the path - 
 for example, the following code works and doesn't cause any errors:
 
 import re
 re.compile('a')
 
 What else could cause such an error?

Your script is called re, so import re is making the script import
itself instead of the re module from the library.

-Carsten


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


Re: how do you get the name of a dictionary?

2006-08-22 Thread Carsten Haese
On Tue, 2006-08-22 at 12:34, jojoba wrote:
 Hello again,
 
 Fredrick said:
 
  Python's object model.  an object has a value, a type, and an identity,
  but no name.
 
 I say:
 
 Thank you Fredrick for the reply!
 However, although python's object model does not currently support what
 i am asking for, how difficult would it be to assign a string name(s)
 to an object upon creation (and upon referencing)?
 
 please note:
 i don't want to do anything sophisticated with this, i am really only
 looking for a TITLE for my dictionary when i throw it in a tree editor
 that i have built. And i do realize that its not possible now. I am
 just pressing a point here.

At the risk of stating the obvious, why don't you simply add a parameter
for the title in the invocation of the tree editor? I.e. instead of

invoke_tree_editor(somedict)

do

invoke_tree_editor(somedict, somedict)

HTH,

Carsten.


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


Re: Negative division bug?

2006-08-03 Thread Carsten Haese
On Thu, 2006-08-03 at 13:51, Michael Yanowitz wrote:
 Hello:
 
   Just wondering if this is a bug, is this as designed,
 or do I have to import math or something to make it correct:
 
I was just screwing around.
 and found:
  -1/100
 -1
   Shouldn't it be zero?
 1/100  returns 0
 but -1/ANY_POSITIVE_INTEGER_NUMBER
   returns -1
 
  -10/3
 -4
 
It behaves correct for positive numbers, but for negative
 integers it seems to subtract one from the expected result.

It behaves correctly in both cases. Your expectation is incorrect.
http://docs.python.org/ref/binary.html says:

Plain or long integer division yields an integer of the same type; the
result is that of mathematical division with the `floor' function
applied to the result.


The floor of x is the largest integer number that's less than or equal
to x. The floor of -0.01 is -1.

HTH,

Carsten.


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


Re: Can't get LCHARVAR's with InformixDB

2006-08-01 Thread Carsten Haese
On Tue, 2006-08-01 at 09:02, [EMAIL PROTECTED] wrote:
 I'm using the InformixDB package, which has been a real lifesaver, but
 I'm finding I can't get any data from the Informix LCHARVAR types.
 They're coming in as empty strings.
 
 The cursor._description for the field in question is:
 ('msg_text', 'lvarchar', 0, 0, None, None, 1)
 
 Appreciate any help... thanks.

What version are you using? I thought I fixed lvarchars a long time ago.

-Carsten


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


Re: Can't get LCHARVAR's with InformixDB

2006-08-01 Thread Carsten Haese
On Tue, 2006-08-01 at 09:27, [EMAIL PROTECTED] wrote:
 Carsten Haese wrote:
  What version are you using? I thought I fixed lvarchars a long time ago.
 
 2.2, with Python 2.4 on Windows... I installed via
 InformixDB-2.2.win32-py2.4.exe

Hm, this certainly warrants further investigation. I don't use lvarchars
myself, so it's possible that I did something that accidentally broke
the output binding for lvarchars.

Could you possibly send me a minimal test script that shows the problem?
Also, in case it matters, I'd like to know which versions of IDS and
CSDK or Informix Connect you're using.

Thanks,

Carsten.


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


Re: Can't get LCHARVAR's with InformixDB

2006-08-01 Thread Carsten Haese
On Tue, 2006-08-01 at 11:41, [EMAIL PROTECTED] wrote:
 Carsten Haese wrote:
  Could you possibly send me a minimal test script that shows the problem?
  Also, in case it matters, I'd like to know which versions of IDS and
  CSDK or Informix Connect you're using.
 
 
 Here's a sample script:
 
 sql = '''select msg_tx from dev_log'''
 import informixdb
 conn = informixdb.connect('mydb')
 cursor = conn.cursor()
 cursor.execute(sql)
 print 'description is %s' % cursor.description
 print cursor.fetchall()

Thanks, but I can't use this to reproduce the problem. I'll need the
create table statement for dev_log.

 Output is:
 description is ('msg_tx', 'lvarchar', 0, 0, None, None, 1)
 [('',), ('',), ('',), ('',), ('',), ('',)]
 
 But one of them should be:
 '''Something:SomethingElse - going for 221 possibilities [User:
 HOST-NAME\XYZZY]:
 IdOtherData
 5878  C
 5968  X
 6732  V
 [many more lines like this]
 '''
 
 Some hunting around, and I found this:
 
 C:\Program Files\Informix\Client-SDK\binesql
 IBM Informix CSDK Version 2.80, IBM Informix-ESQL Version 9.52.TC1
 
 Not sure what IDS is... the Informix Server version is: 9.3 FC3,
 according to the DBA guy.

IDS = Informix Dynamic Server. The version numbers you gave me are what
I was looking for.

For what it's worth, I've tried a simple test script on my Linux server
that creates a temp table with an lvarchar column, inserts into it, and
reads from it, all without a problem. However, there are many
differences between my test environment and yours, and I'll need to know
your specific circumstances to isolate which difference is causing the
problem.

Thanks,

Carsten.


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


Re: Can't get LCHARVAR's with InformixDB

2006-08-01 Thread Carsten Haese
On Tue, 2006-08-01 at 11:47, [EMAIL PROTECTED] wrote:
 Another thing...
 
  Output is:
  description is ('msg_tx', 'lvarchar', 0, 0, None, None, 1)
 
 The 0's worried me, as I could see where they could be used as parms to
 allocate/trim things as necessary...  just a thought.

That is indeed a problem. For some as of yet undetermined reason, the
client thinks that msg_tx is a column of length zero, so it's no big
surprise that all you get back is empty strings. Once again, I'll need
the create table statement for the table you're selecting from in order
to investigate what's happening.

-Carsten


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


Re: Can't get LCHARVAR's with InformixDB

2006-08-01 Thread Carsten Haese
On Tue, 2006-08-01 at 14:05, [EMAIL PROTECTED] wrote:
 Carsten Haese wrote:
  Once again, I'll need
  the create table statement for the table you're selecting from in order
  to investigate what's happening.
 
 Here it is:
 
 CREATE TABLE DEV_LOG(
  LOG_ID SERIAL,
  LEVEL VARCHAR (10),
  POI_NM VARCHAR (255),
  MSG_TX LVARCHAR(2000),
  MSG2_TX LVARCHAR(5000)
 ) LOCK MODE ROW;

The following test script works fine for me:

-
import informixdb

conn = informixdb.connect(mydb)
cur = conn.cursor()
cur.execute(
CREATE temp TABLE DEV_LOG(
 LOG_ID SERIAL,
 LEVEL VARCHAR (10),
 POI_NM VARCHAR (255),
 MSG_TX LVARCHAR(2000),
 MSG2_TX LVARCHAR(5000)))
str1 = ABCDEFGHIJ*200
str2 = ABCDEFGHIJ*500
cur.execute(insert into dev_log values(?,?,?,?,?),
  (0,'MEDIUM','TESTMAN',str1,str2) )
cur.execute(select * from dev_log)
row = cur.fetchone()
assert row[3]==str1
assert row[4]==str2
print cur.description
-

I have tested this two ways, once directly on the server on Linux, once
with a client-server connection from Windows to Linux. In both cases,
both lvarchars are being read back correctly. One notable difference
between your environment and mine is that I'm using CSDK version
2.90.TC3, which is more recent than the version of CSDK that you're
using. 

I'd suggest upgrading to the newest version of CSDK. Please let me know
what happens after the upgrade.

-Carsten


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


Re: Static Variables in Python?

2006-07-31 Thread Carsten Haese
On Mon, 2006-07-31 at 15:21, Michael Yanowitz wrote:
   Is it possible to have a static variable in Python - 
 a local variable in a function that retains its value.
 
  For example, suppose I have:
 
 def set_bit (bit_index, bit_value):
static bits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
bits [bit_index] = bit_value
 
print \tBit Array:
int i
while (i  len(bits):
   print bits[i],
print '\n'
 
  
I realize this can be implemented by making bits global, but can
 this be done by making it private only internal to set_bit()?  I don't
 want bits to be reinitialized each time. It must retain the set values
 for the next time it is called.

Python does not have static variables in the sense that C does. You can
fake it in various ways, though. If I had to do it, I'd define a
callable object instead of a function, along the lines of this:

class BitSetter(object):
  def __init__(self):
self.bits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  def __call__(self, bit_index, bit_value):
self.bits[bit_index] = bit_value
# do something with self.bits here...
print self.bits

set_bit = BitSetter()

Now you can call set_bit(...) as if it were a function, and it'll behave
the way you want.

Hope this helps,

Carsten.


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


Re: Setting up InformixDb

2006-05-13 Thread Carsten Haese
On Sat, 13 May 2006 14:09:19 -0400, The Shaffer s wrote
 I have an informix database on a unix machine which I want to 
 access. I downloaded InformixDb-2.2 and managed to get it built and 
 installed and it works fine with python.
 
 My problem is I want to access the same database from a PC remotely. 
 Yes, I already have informix setup and configured on the unix 
 machine to accept connections remotely. And, I can connect to it 
 fine from an ODBC interface to Excel and Access.
 
 But, to build the informix module requires the INFORMIXDIR 
 environment variable set to it which I don't believe I can set to a 
 remote machine.
 
 So, how can I get this module built without having an informix 
 installed on my PC?

On the PC, you'll have to install either the Informix Client SDK
(http://www.ibm.com/software/data/informix/tools/csdk/) or Informix Connect
(http://www.ibm.com/software/data/informix/tools/connect/). Both are free
downloads.

If you plan on building InformixDB from source, you'll need CSDK. If you want
to simply use a pre-built binary, such as the one I provide at Sourceforge,
either CSDK or Informix Connect will do.

In either case, INFORMIXDIR on the PC should point to where you installed the
Informix client software, and INFORMIXSERVER points to the server instance
you're connecting to.

Hope this helps,

Carsten.

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


[ANN] InformixDB-2.2 released

2006-03-25 Thread Carsten Haese
I am pleased to announce a new release of InformixDB, the DB-API 2.0 module
for connecting to IBM Informix database engines.

Changes since version 2.1:

- Support for BOOLEAN columns
- DECIMAL and MONEY columns can be fetched as decimal.Decimal instances
  if the decimal module is available
- autocommit mode for connections
- Bug fixes:
  * Output buffer allocation used pointer/int casts that don't work on
most 64 bit platforms.
  * Selecting TEXT/BYTE column from an empty set of rows caused segmentation
fault under certain circumstances.
  * datetime values with trailing double-zeroes were fetched incorrectly.

Downloads and info at http://informixdb.sourceforge.net.

Best regards,

Carsten Haese

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


Re: problem(s) with import from parent dir: from ../brave.py import sir_robin

2006-02-24 Thread Carsten Haese
On Fri, 2006-02-24 at 09:10, per9000 wrote:
 Thanks,
 
 I added an environment variable PYTHONPATH and added the holy folder
 with my script in. Works just perfectly.
 
 But still: is there a way around this? (It is a lot easier to add
 ../../ in my code than make everyone else add this variable).

Yes.

From http://docs.python.org/tut/node8.html#SECTION00811:

Actually, modules are searched in the list of directories given by the
variable sys.path [...]. This allows Python programs that know what
they're doing to modify or replace the module search path.


In other words, your script may simply append other module locations
such as ../.. to sys.path.

-Carsten.


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


Re: Checkbuttons in a Text widget

2006-02-17 Thread Carsten Haese
On Fri, 2006-02-17 at 10:28, Lou G wrote:
 I'm trying to show a number of Checkbuttons (each with associated text
 based on a list of names) inside a y-scrollable Text widget like so:
 
 [ ] Bob
 [ ] Carol
 [ ] Ted
 [ ] Alice
 etc.
 etc.
 
 There may be quite a few (as many as 100 or so). I'm uncertain as to
 the correct way to get these into the Text widget. I've tried
 text.insert and it doesn't seem to do the job. Help?

Does it have to be a text widget? wxWidgets has a wxCheckListBox class
that does precisely what you need, but it's not a text widget.

HTH,

Carsten.


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


Re: kwargs keyword evaluation

2006-02-15 Thread Carsten Haese
On Wed, 2006-02-15 at 11:40, [EMAIL PROTECTED] wrote:
 Ok, so here is my situation:
 
 Let's assume I have a function that makes good use of the kwargs
 parameter. It requires that there is a certain format for the kwargs
 keywords. (I am using Django, btw). The format is like such:
 SOMEVAL__exact, etc., where SOMEVAL is some value that it parses from
 the keyword.
 
 Now, I want to call this function, specifying the kwargs. The problem
 is that I want to dynamically set the kwargs. For example, I don't want
 to hard code in the name like such:
 function_call(name__exact=Tom)
 
 I want to generate the keyword on the fly. So, I want to do this:
 (assume someVar == 'name' for now)
 keyword = someVar + __exact
 
 The problem:
 I need to know how to get it to use the VALUE of the keyword for the
 keyword.
 
 
 My thoughts:
 (1) Maybe I can override the kwargs parameter by doing such:
 function_call(kwargs={keyword:Tom})
 *loud buzzer* Nope. (as expected)
 
 (2) Maybe I can just pass it in:
 function_call(keyword=Tom)
 Nope! (as expected, it tries to use 'keyword' as the keyword)

The correct answer is behind door number 3:

some_dict = {keyword: Tom}
function_call(**some_dict)

HTH,

Carsten.


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


Re: %SystemDrive%

2006-02-15 Thread Carsten Haese
On Wed, 2006-02-15 at 14:07, Todd Whiteman wrote:
 Another hack:
 drive = os.popen(echo %SYSTEMDRIVE%).readline().strip()
 
 rtilley wrote:
  Is there a proper way to get this variable from Windows? I know it's in 
  the registry, but I'd rather not go there. I could not find a CSIDL 
  shell constant for it either. I've been doing this:
 
  os.chdir('/')
  sys_drive = os.getcwd()
  print sys_drive
  C:\
 
  This seems too much of a hack and maybe not 100% right all of the time. 
  How could it be done better?


Is there a reason why os.environ['SYSTEMDRIVE'] shouldn't work?

Hope this helps,

Carsten.


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


Re: Linux application in python

2006-02-15 Thread Carsten Haese
On Wed, 2006-02-15 at 15:02, [EMAIL PROTECTED] wrote:
 Hi all ,
 
 I have a linux application that needs to run on a python interpreter

Why does it need to run on a python interpreter?

 .So what is the best way to have the same functionalities provided by
 C to be implemented in python .

1) Rewrite the functionality in python.
2) Separate the functionality into a library and write a python
extension to call into the library (or use ctypes to call into the
library without writing an extension module)

Better solutions may become apparent once you provide more details about
your needs.

-Carsten


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


Re: using an existing DLL file without having access to the source code?

2006-02-14 Thread Carsten Haese
On Tue, 2006-02-14 at 13:50, Dieter Vanderelst wrote:
 Dear all,
 
 Could anybody tell me whether there are ways to use an existing DLL file 
 in Python without having access to the source code?

That sounds like a job for ctypes:
http://starship.python.net/crew/theller/ctypes/

HTH,

Carsten.


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


Re: cx_Oracle string problems...

2006-02-13 Thread Carsten Haese
On Mon, 2006-02-13 at 13:18, MooMaster wrote:
 Lol, that was a copy paste error into the post on my part...but the
 problem has been fixed. Turns out that there was a string.replace call
 somewhere else in the code that replaced all single quotes with empty
 strings, which thus caused the singe quotes to disappear! Whoops!

Please do yourself a favor and make use of the fact that Python's
database API allows parametrized queries. Here's a sketch of what that
might look like:

sql = 'INSERT INTO prime.utwsLOT VALUES (:kID, etc...)'
curse = self.connection.cursor()
curse.execute(sql, kID=self.kID, etc...)

Of course, etc... would have to be replaced with additional
placeholders and parameter values for all the columns in utwsLOT.

By using parametrized queries, you don't have to worry about any of the
supplied values requiring special treatment due to any quotation marks
or apostrophes that might they might contain.

Hope this helps,

Carsten.

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


Re: cx_Oracle string problems...

2006-02-13 Thread Carsten Haese
On Mon, 2006-02-13 at 13:50, Carsten Haese wrote:
 By using parametrized queries, you don't have to worry about any of the
 supplied values requiring special treatment due to any quotation marks
 or apostrophes that might they might contain.

Add grammar corrections to taste.

-Carsten


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


Re: trapping errors in function call syntax

2006-02-13 Thread Carsten Haese
On Mon, 2006-02-13 at 14:13, Avi Kak wrote:
 Hello:
 
Suppose I write a function that I want to be called
with ONLY keyword argumnts, how do I raise an
   exception should the function get called with 
   what look like position-specfic arguments?
 
   Any help would be appreciated.

Something like this should do the trick:

def f(*args, **kwargs):
  if args: raise TypeError, Please use keyword arguments.
  ...

-Carsten


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


Re: cyclic data structures

2006-02-13 Thread Carsten Haese
On Mon, 2006-02-13 at 16:03, John Salerno wrote:
 Peter Decker wrote:
 
  'L' is a pointer to a list. You are now adding that pointer to the
  very list it points to.
 
 I understand that, but I guess I just don't see how this creates 
 anything other than a list that refers to [1, 2], and then refers again 
 to [1, 2], to create [1, 2, [1, 2]].
 
 L.append(L) basically creates this, I think:
 
 [1, 2, L]
 
 Now, assuming that's correct, and since L points to the list [1, 2], why 
 can't '[1, 2]' be substituted for the 'L' and then the list is closed?

L is [1,2] before the append. After the append, L is [1,2,L], which is
[1,2,[1,2,L]], which is [1,2,[1,2,[1,2,L]]] etc into infinity. L
literally contains itself after the append.

HTH,

Carsten.

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


Re: Create dict from two lists

2006-02-10 Thread Carsten Haese
On Fri, 2006-02-10 at 08:51, py wrote:
 I have two lists which I want to use to create a dictionary.  List x
 would be the keys, and list y is the values.
 
 x = [1,2,3,4,5]
 y = ['a','b','c','d','e']
 
 Any suggestions?  looking for an efficent simple way to do this...maybe
 i am just having a brain fart...i feel like this is quit simple.

d = dict(zip(x,y))

-Carsten


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


Re: email questions

2006-02-09 Thread Carsten Haese
On Thu, 2006-02-09 at 00:50, Dennis Lee Bieber wrote:
 On Wed, 8 Feb 2006 10:49:27 -0800, Scott Frankel [EMAIL PROTECTED]
 declaimed the following in comp.lang.python:
 
 
  
  mail.ispname.net
 
   Not sure why you feel you need to hide it -- I'm presuming it is the
 same ISP in your email address...
 
   However, I'm currently finding a dead access to it...
 
 C:\Documents and Settings\Dennis Lee Biebertracert smtp.pacbell.net
 Unable to resolve target system name smtp.pacbell.net.
 
 C:\Documents and Settings\Dennis Lee Biebertracert mail.pacbell.net
 
 Tracing route to mail.pacbell.net [207.115.57.20]
 over a maximum of 30 hops:
 
   1 1 ms1 ms1 ms  192.168.1.1
   217 ms13 ms14 ms  user-11fa401.dsl.mindspring.com
 [66.245.16.1]
   313 ms13 ms15 ms cor02-vl-10.ca-sanfranc0.ne.earthlink.net
 [209.165.103.65]
   416 ms13 ms16 ms
 bor01-ge-6-1.ca-sanfranc0.ne.earthlink.net [209.165.103.17]
   522 ms22 ms22 ms
 bor02-so-3-1.ca-pasadena0.ne.earthlink.net [209.165.109.154]
   623 ms27 ms31 ms
 bor01-ge-1-1-0.ca-losangel4.ne.earthlink.net [209.165.107.182]
   728 ms21 ms22 ms  ex1-g8-1s1.eqlaca.sbcglobal.net
 [206.223.123.79]
   824 ms22 ms23 ms  ex2-p3-0.eqlaca.sbcglobal.net
 [151.164.191.226]
   925 ms24 ms24 ms  bb1-p6-0.crrvca.sbcglobal.net
 [151.164.41.34]
  1023 ms24 ms27 ms  core2-p4-0.crrvca.sbcglobal.net
 [151.164.41.1]
  1158 ms61 ms59 ms  core2-p3-0.crhstx.sbcglobal.net
 [151.164.241.125]
  1288 ms89 ms81 ms  core1-p9-0.cratga.sbcglobal.net
 [151.164.191.192]
  1383 ms82 ms84 ms  core2-p1-0.cratga.sbcglobal.net
 [151.164.241.82]
  1482 ms82 ms83 ms  core2-p6-0.crhnva.sbcglobal.net
 [151.164.41.206]
  1588 ms89 ms90 ms  core2-p3-0.crnyny.sbcglobal.net
 [151.164.188.197]
  1691 ms88 ms89 ms  bb2-p3-0.nycmny.sbcglobal.net
 [151.164.240.221]
  1788 ms90 ms87 ms  ded2-g8-3-0.nycmny.sbcglobal.net
 [151.164.41.181]
  1893 ms90 ms98 ms  66.10.112.6
  19 *** Request timed out.
  20 *** Request timed out.
  21 *** Request timed out.
  22 *** Request timed out.
  23 *** Request timed out.

This does not necessarily mean that the server is down. Routers can
filter traceroute and ping. Telnet to mail.pacbell.net on port 25 works
just fine. If the server had been down, the OP would not have gotten
connection refused, he would have gotten a connection timeout.

The OP's problem is most likely that he's doing this:

s = smtplib.SMTP(mail.pacbell.net)  # This already connects s
s.connect() # This reconnects s to localhost and is refused

when he should do this:

s = smtplib.SMTP()  # make an unconnected SMTP instance
s.connect(mail.pacbell.net) # and connect it.

or simply this:

s = smtplib.SMTP(mail.pacbell.net)

-Carsten


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


Re: email questions

2006-02-08 Thread Carsten Haese
On Wed, 2006-02-08 at 12:34, Scott Frankel wrote:
 I'm looking for a way to send a simple, plain text email message  
 using Python.  My initial attempts are failing with the following error:
 
   socket.error: (61, 'Connection refused')
 
 Does this imply that I do not have the machine's smtp server  
 running?

Yes.

   (I don't; and I'd like to avoid setting it up.)

You don't have to set up an smtp server to use smtplib. You should be
able to use your ISP's outgoing mail server, as in

s = smtplib.SMTP(ISP's mail server name goes here)

HTH,

Carsten.


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


Re: email questions

2006-02-08 Thread Carsten Haese
On Wed, 2006-02-08 at 13:49, Scott Frankel wrote:
 Seems I'm still having issues with syntax.
 
  From what I can tell from my mail client, my outgoing mail server  
 name is either
   
   mail.ispname.net

This is it.

 or
   mail.ispname.net:myUsername@myDomain.com

Not this.

 The former yields the same socket error on connect() that I reported  
 earlier.

Then you're doing something wrong. The line

s = smtplib.SMTP(mail.ispname.net) instantiates an SMTP instance and
connects it. Are you doing s.connect() afterwards? If yes, don't do
that, it'll try to connect to the local host, which is not an smtp
server.

If you want to separate instantiation and connection, do this:

s = smtplib.SMTP()
s.connect(mail.ispname.net)

-Carsten


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


Re: Replace a module variable with a function call

2006-02-06 Thread Carsten Haese
On Mon, 2006-02-06 at 13:54, [EMAIL PROTECTED] wrote:
 I have a module that defines a variable with a constant value and now I
 need to make that value dynamic, without affecting module clients. In
 other words, I need to call a function witout using parenthesis.
 Example:
 
 mymod.py--
 
 def value():
 return hi
 
 client.py--
 import mymod
 
 print mymod.value
 
 Is there a way to do this ?

If you're not passing any arguments to this function call, what is
this dynamic value supposed to depend on? The phase of the moon?

-Carsten


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


Re: Replace a module variable with a function call

2006-02-06 Thread Carsten Haese
On Mon, 2006-02-06 at 14:19, [EMAIL PROTECTED] wrote:
 I'm not going to waste my time with more
 examples coz probably you won't understand them either.

Fine, I won't waste my time trying to help you.

-Carsten.


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


Re: Replace a module variable with a function call

2006-02-06 Thread Carsten Haese
On Mon, 2006-02-06 at 14:38, [EMAIL PROTECTED] wrote:
 Your post didn't provide any help at all, it was a useless sarcastic
 post and I'm a very sensible person.

Your original question didn't provide enough detail to offer an answer,
which is why I asked the question what the dynamic return value should
depend on. I am sorry if my conjecture that the return value might
depend on the phase of the moon offended you, but my post was not meant
to be useless. It was a necessary follow-up question because you didn't
define your requirements clearly enough.

If the condition upon which the return value is determined can be
evaluated at import time and doesn't change henceforth, a simple if
statement in the module will serve your need.

If the value *really* needs to be re-evaluated every time the name is
looked up, you'll need to follow the advice that Tim Hochberg has
already given on this thread. Note, though, that that won't prevent the
user code from caching the return value and circumventing the
re-evaluation.

-Carsten


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


Re: MySQLdb question... using table name as arg

2006-02-03 Thread Carsten Haese
On Fri, 2006-02-03 at 13:24, Sean Berry wrote:
 I have four tables that all have the same column names (50 in each.)
 
 I have created an admin program to edit, delete and add records to the 
 tables and would like to use the table name as a variable in each query so 
 the code can be used for each of the 4 tables.  Usually I would do something 
 like this by having 1 table with special column to categorize the records as 
 I am doing with each table, but this specific application requires that I do 
 it with 4 tables instead.
 
 To ensure that string are quoted properly without any hassle I use the 
 execute function like so assuming c is my cursor object...
 
 c.execute(update tableName set col1 = %s, col2 = %s, col3 = %s, ..., 
 (val1, val2, val3, ...))
 
 But, not I want to do this with a variable tableName.  If I add it to the 
 tuple of parameters in the second arg before val1 and replace tableName with 
 %s, then the tableName will be quoted in the query, causing an error.
 
 What is the best (easiest) way for me to accomplish this?  I know it may be 
 a stupid question but I just can't figure it out.

As you have discovered, the table name is not allowed to be a parameter.
You have to build the query string for the appropriate table, then hand
it to execute for filling in the actual parameters:

queryString = update +tableName+ set col1=%s, col2=%s,...
c.execute(queryString, (val1, val2,...))

HTH,

Carsten.


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


Re: Dictionary inserts into MySQL (each key in its own field)

2006-01-27 Thread Carsten Haese
On Fri, 2006-01-27 at 05:47, Fredrik Lundh wrote:
 (just curious, but from where do people get the idea that arbitrary data
 just have to be inserted into the the SQL statement text all the time?  is
 this some PHP misfeature?)

Yes, the need to roll queries by inserting parameters directly into the
query string is definitely a PHP misfeature (for versions less than 5),
since the database access modules don't accommodate parametrized
queries. PHP5 finally introduced a standardized database API that allows
parametrized queries. Of course, Python has had this since 1996.

-Carsten


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


Re: replacing \n characters in a hash

2006-01-26 Thread Carsten Haese
On Thu, 2006-01-26 at 09:24, Johhny wrote:
 Hello,
 
 I am currently trying to write some scripts to get information from the
 xmlrpc for redhat network. One of the issues I am having is trying to
 strip off the special characters in the hash that is returned. Here is
 an example of the information returned within the hash :
 
 ===SNIP===
 {'errata_update_date': '2005-12-06', 'errata_topic': 'Updated
 libc-client packages that fix a buffer overflow issue are
 now\navailable.\n\nThis update has been rated as having moderate
 security impact by the Red\nHat Security Response Team.',

 [...]

 What I had attempted to do is use the replace() function but it
 consistantly comes up with the following errors:
 
 Traceback (most recent call last):
   File rhn_errata.py, line 63, in ?
 errata_package = errata_package.strip('\n','')
 AttributeError: 'dict' object has no attribute 'strip'
 
 where errata_package is JUST the errata_topic hash value.

errata_package is obviously not just the errata_topic hash value,
because that would be a string, and python for some reason seems to
believe that errata_package is a dictionary.

Also note that once you correct that problem, python will complain that
strip() doesn't take 2 parameters, since you actually mean replace().

-Carsten


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


Re: replacing \n characters in a hash

2006-01-26 Thread Carsten Haese
On Thu, 2006-01-26 at 09:49, Johhny wrote:
 Hello,
 
 Thankyou for your response,
 If I check that the errara_package value is with a print I get the
 following.
 
 ===SNIP===
 Updated libc-client packages that fix a buffer overflow issue are now
 available.
 
 This update has been rated as having moderate security impact by the
 Red
 Hat Security Response Team.
 ===SNIP===
 
 Notice that it has formatted the output with the \n's.
 
 So i dont understand why its reporting as a dictionary rather than just
 the string.

Posting relevant bits of your code might help.

-Carsten


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


Re: Need Help with Python/C API

2006-01-19 Thread Carsten Haese
On Thu, 2006-01-19 at 00:44, pycraze wrote:
 Hi guys,
 
 I Need to know how do i create a dictionary... eg:
 n = pali_hash
 n={}
 n={1:{ } }   -  i need to know how to make a key of a dictionary, to a
 dictionary using Python/C API's

You can either use Py_BuildValue (See
http://docs.python.org/api/arg-parsing.html#l2h-214) or PyDict_New and
PyDict_SetItem (See http://docs.python.org/api/dictObjects.html) to
construct a dictionary.

Good luck,

Carsten.

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


Re: rational numbers

2006-01-17 Thread Carsten Haese
On Tue, 2006-01-17 at 11:22, Paul Rubin wrote:
 Schüle Daniel [EMAIL PROTECTED] writes:
  does anybody know modules which make rational numbers available?
 
 Try gmpy.mpq (google for gmpy).
 
  and are there considerations to add them to the core, like
  complex numbers (maybe in Python 3)
 
 I don't think it's been discussed much.

Somebody must have discussed it. There is a rejected PEP for adding a
Rational type to python:

http://www.python.org/peps/pep-0239.html

-Carsten


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


Re: Python and location of .so files?

2006-01-10 Thread Carsten Haese
On Tue, 2006-01-10 at 09:42, Efrat Regev wrote:
Hello,
 
On FC4, I've generated an .so file from C++ which I want to use from 
 python. It works when I copy it into /usr/lib/python2.4/site-packages.
 (I.e., say I have hello.so in that directory, then from the python 
 prompt I can 'import hello', and the code works fine). The problem is 
 that the said directory requires su - so I'd rather python load my .so 
 from a different user-privilege directory (when I type 'import hello'). 
 Is there some way to tell python to use a different directory?

Yes. See
http://docs.python.org/tut/node8.html#SECTION00811 for
information on Python's module search path.

Hope this helps,

Carsten.


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


Re: MidiToText : EventDispatcher instance has no attribute 'sysex_events'

2005-12-30 Thread Carsten Haese
On Fri, 2005-12-30 at 09:52, tim wrote:
 Trying to convert midi to text using MidiToText.py.
 I get the following:
 
 midi_port: 0
 Traceback (most recent call last):
   File MidiToText.py, line 176, in ?
 midiIn.read()
   File C:\Python24\Lib\site-packages\midi\MidiInFile.py, line 24, in read
 p.parseMTrkChunks()
   File C:\Python24\Lib\site-packages\midi\MidiFileParser.py, line 167, 
 in parseMTrkChunks
 self.parseMTrkChunk() # this is where it's at!
   File C:\Python24\Lib\site-packages\midi\MidiFileParser.py, line 129, 
 in parseMTrkChunk
 dispatch.sysex_events(sysex_data)
 AttributeError: EventDispatcher instance has no attribute 'sysex_events'

Try changing def sysex_event(self, data): in
...\midi\EventDispatcher.py to def sysex_events(self, data):

Hope this helps,

Carsten.


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


Re: Modifying values in a list

2005-12-29 Thread Carsten Haese
On Thu, 2005-12-29 at 11:43, [EMAIL PROTECTED] wrote:
 The following code:
 
 numbers = [1, 2, 3]
 for value in numbers:
   value *= 2
 print numbers
 
 results in the following output:
 [1, 2, 3]
 
 The intent of the code was to produce this output:
 [2, 4, 6]
 
 What is the reason for the output produced?
 What code should be used to obtain the desired output?

1) Read http://www.effbot.org/zone/python-objects.htm and reread it
until you understand why your code doesn't work.

2) Use a list comprehension:
numbers = [ value*2 for value in numbers ]

-Carsten


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


Re: print UTF-8 file with BOM

2005-12-23 Thread Carsten Haese
 2005/12/23, David Xiao [EMAIL PROTECTED]:
 Hi Kuan:
 
 Thanks a lot! One more question here: How to write if I want
 to
 specify locale other than current locale?
 
 For example, running on Korea locale system, and try read a
 UTF-8 file
 that save chinese. 

Use the encode method to translate the unicode object into whatever
encoding you want.

unicodeStr = ...
print unicodeStr.encode('big5')

Hope this helps,

Carsten.


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


Re: Guido at Google

2005-12-22 Thread Carsten Haese
On Thu, 2005-12-22 at 07:01, Peter Hansen wrote:
 [EMAIL PROTECTED] wrote:
  So exactly how high is python in Google's priority list ? Or in other
  words, if python is in a stand still as it is now, what would be the
  impact to Google ? 
 
 Since when is Python in a standstill?

I believe bonono meant the question in the hypothetical sense of If
Python would stand still in its current state, what would be the impact
to Google? but didn't know how to ask it correctly.

-Carsten


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


Re: Guido at Google

2005-12-22 Thread Carsten Haese
On Thu, 2005-12-22 at 08:18, [EMAIL PROTECTED] wrote:
 Cameron Laird wrote:
  In article [EMAIL PROTECTED],
   [EMAIL PROTECTED] wrote:
  .
  .
  .
  Well, this may be the CPython way of open source but I don't know if
  that is Open source in general. Another way is that if someone(or
  group) don't like the current state of a project, they fork. I don't
  know if that is possible in the context of python, and programming
  language in general. Can it still be called python ?
  .
  .
  .
  While I don't understand the question, it might be pertinent to
  observe that, among open-source development projects, Python is
  unusual for the *large* number of forks or alternative imple-
  mentations it has supported through the years URL:
  http://phaseit.net/claird/comp.lang.python/python_varieties.html .
 The question is, can anyone just fork a new one using the python name,
 as part of the project, without the permission from the foundation ?
 Say for example, anyone want to implement java needs permission from
 Sun(or is it javasoft), if I rememeber correctly. Therefore, the only
 way to make change to java the language is to convince Sun, very
 similar to the model of Python. But many open source project is not
 using this model.

Most of your question can be answered by reading the license. Section 3
of version 2 of the PSF license states:

3. In the event Licensee prepares a derivative work that is based on
or incorporates Python or any part thereof, and wants to make
the derivative work available to others as provided herein, then
Licensee hereby agrees to include in any such work a brief summary of
the changes made to Python.


In other words, you can change Python to your liking and distribute the
changed version, as long as you tell people how it differs from Python.
Since the changed version is different from Python, calling it Python
would be a) boneheaded and b) as Steve Holden points out, a trademark
violation. Note that section 7 states that This License Agreement does
not grant permission to use PSF trademarks or trade name in a trademark
sense to endorse or promote products or services of Licensee, or any
third party and the Python name is a trademark of the PSF.

So, if there is something you don't like about Python, you have two
choices:
1) Seek consensus with the Python community and have your changes
accepted into the official Python version, or
2) Fork Python into something else with a different name. If the
different name contains 'Python', you'll probably have to ask PSF for
permission. In any case, as outlined above, you have have to state that
the fork is based on Python and summarize how it differs from Python.

Hope this clears things up,

Carsten.


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


Re: Easiest way to calculate number of character in string

2005-12-21 Thread Carsten Haese
On Wed, 2005-12-21 at 09:03, P. Schmidt-Volkmar wrote:
 Hi there,
 
 I have a string in which I want to calculate how often the character  ';' 
 occurs. If the character does not occur 42 times, the ; should be added so 
 the 42 are reached.
 
 My solution is slow and wrong:
 for Position in range (0, len(Zeile)):
 if Zeile[Position]==';': AnzahlSemikolon = AnzahlSemikolon +1
 if AnzahlSemikolon  42:
 for Zaehler in range(AnzahlSemikolon, 42):
 Zeile = Zeile + ';'
 Dreckskram = Dreckskram +1
 
 How can this be achieved easily?
 
 Thanks,
 
 Pascal

AnzahlSemikolon = Zeile.count(';')
if AnzahlSemikolon  42:
Zeile += ';'*(42-AnzahlSemikolon)

HTH,

Carsten.


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


Re: Python C/API - *arg,**kwds variable argumnents

2005-12-14 Thread Carsten Haese
On Wed, 2005-12-14 at 12:00, [EMAIL PROTECTED] wrote:
 essentially I already use PyArg_ParseTupleAndKeywords, but that seems
 to emulate fixed arg list definitions like - 
func (x,y,t=0,u=1)

It's unclear what you are actually trying to accomplish. My guess is
that you want to implement a function/method that takes any number of
arbitrarily named keyword arguments. If that is the case, you can simply
use the dictionary that is passed to your C function as the third
argument.

Hope this helps,

Carsten.

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


Re: 0 in [True,False] returns True

2005-12-12 Thread Carsten Haese
On Mon, 2005-12-12 at 16:26, Pierre Quentel wrote:
 Hi all,
 
 In some program I was testing if a variable was a boolean, with this 
 test : if v in [True,False]
 
 My script didn't work in some cases and I eventually found that for v = 
 0 the test returned True
 
 So I changed my test for the obvious if type(v) is bool, but I still 
 find it confusing that 0 in [True,False] returns True
 
 By the way, I searched in the documentation what obj in list meant and 
 couldn't find a precise definition (does it test for equality or 
 identity with one of the values in list ? equality, it seems) ; did I 
 miss something ?

Where/how did you search? http://docs.python.org/lib/typesseq.html
states unambiguously that x in s returns True if an item of s is
equal to x, else False

HTH,

Carsten.


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


Re: i=2; lst=[i**=2 while i1000]

2005-12-06 Thread Carsten Haese
On Tue, 2005-12-06 at 10:44, Steve Holden wrote:
 Daniel Schüle wrote:
 i=2
 lst=[]
 while i1000:
 i**=2
 lst.append(i)
 
 
  
  unless I am missing something obvious, I can not see why the loop should 
  not terminate
 
 In that case, kindly explain how the condition i1000 can become false 
 when it starts at 2 and never changes! [In other words: you *are* 
 missing something obvious].

 Don't you have an interpreter you could run the code in to verify that 
 it does indeed loop interminably? You seem to be assuming that the 
 expression i**2 changes the value of i. It doesn't.

Note that the OP wrote i**=2, not i**2.

-Carsten


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


Re: insert a dictionary into sql data base

2005-12-05 Thread Carsten Haese
On Mon, 05 Dec 2005 18:00:21 -0700, David Bear wrote
 Fredrik Lundh wrote:
  DON'T MANUALLY CONSTRUCT THE SQL INSERT STATEMENT.  Use string
  formatting to insert the field names, but let the database layer deal with
  the values.
  
  If you want to do things in two steps, do the fields formatting first
  
  query = INSERT INTO table (%s) VALUES (%%s); % (,.join(fields))
  
  and pass the query and the values sequence to the database layer:
  
  cursor.execute(query, values)
  
  The database will take care of the rest.
  
  /F
 
 I think I'm missing some important documentation somewhere. Here's 
 what I tried (using both % and $ signs):
 
  sql
 'INSERT INTO nic (addr_code,ip_address,property_control,mac_address) 
 VALUES
 (%s);'
 
  sql2
 'INSERT INTO nic (addr_code,ip_address,property_control,mac_address) 
 VALUES
 ($s);'
  values
 ['p', '129.219.120.134', '6154856', '00:40:50:60:03:02']
 
  cursor.execute(sql1, values)
 Traceback (most recent call last):
   File stdin, line 1, in ?
 NameError: name 'sql1' is not defined
  cursor.execute(sql, values)
 Traceback (most recent call last):
   File stdin, line 1, in ?
   File /usr/lib64/python2.4/site-packages/pgdb.py, line 163, in execute
 self.executemany(operation, (params,))
   File /usr/lib64/python2.4/site-packages/pgdb.py, line 187, in
 executemany
 raise OperationalError, internal error in '%s': %s % (sql,err)
 pg.OperationalError: internal error in 'INIT': not all arguments converted
 during string formatting
 
 I get the same error if using $ sign.
 
 When I look at the pygresql dbapi official site at
 http://www.pygresql.org/pgdb.html
 
 this section needs to be written...
 
 I would really appreciate some more examples on using pgdb (pygresql)

It appears that Fredrik gave you good advice but bad example code. The example
he gave you constructs an insert query with only one parameter placeholder.
You'll need as many placeholders as the number of values that are inserted.

The following example should work better:

def insertDict(curs, tablename, data):
  fields = data.keys()
  values = data.values()
  placeholder = %s
  fieldlist = ,.join(fields)
  placeholderlist = ,.join([placeholder] * len(fields))
  query = insert into %s(%s) values (%s) % (tablename, fieldlist,
  placeholderlist)
  curs.execute(query, values)

The main thing to note here is that we *are* using string formatting to build
a query that's based on a variable table name and a variable column list, but
we *are not* using string formatting to fill in the values.[*]

On a somewhat related note, it's unfortunate that many database modules use %s
 as parameter placeholders, because it makes it too tempting to write bad code
such as

cur.execute(insert into tab1(spam,eggs) values (%s,%s) % (a,b)) # Bad, uses
vulnerable and error-prone string formatting

instead of

cur.execute(insert into tab1(spam,eggs) values (%s,%s), (a,b)) # Good, uses
parameters.

[*] This code blindly trusts that the table name and dictionary keys don't
contain SQL injection attacks. If the source of these is not completely
trustworthy, the code needs to be hardened against such attacks. I'll leave
that as an exercise for the reader.

Hope this helps,

Carsten.

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


Re: Why use #!/usr/bin/env python rather than #!python?

2005-12-02 Thread Carsten Haese
On Fri, 2005-12-02 at 09:12, Adriano Ferreira wrote:
 On 12/2/05, Klaus Alexander Seistrup [EMAIL PROTECTED] wrote:
  #v+
 
  $ ls -l /tmp/hello.py
  -rwxr-xr-x  1 klaus klaus 38 2005-12-02 14:59 /tmp/hello.py
  $ cat /tmp/hello.py
  #! python
  print 'Hello, world!'
  # eof
  $ /tmp/hello.py
  bash: /tmp/hello.py: python: bad interpreter: No such file or directory
  $
 
  #v-
 
 Hey, that's not fair. In your illustration above, does 'python' can be
 found in the PATH? That is,
 
 $ python /tmp/hello.py
 
 works? If it does, probably
 
 #!/usr/bin/python
 #!/usr/bin/env python
 #!python
 
 would also work if
 (1) 'python' is at '/usr/bin/python' (but that's inflexible)
 (2) 'python' can be found in the environment variable path (if 'env'
 is at '/usr/bin/env')
 (3) 'python' can be found in the environment variable path (no need
 for 'env' utility)

(3) assumes that whatever shell the user is running looks up the shebang
executable in the path, which bash, just to name one example, does not
do.

(2) and (1) require that you know where env and python live,
respectively, that's true, but env is likely to be found in an
OS-dependent standard location than python, so (2) is preferable.

HTH,

Carsten.


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


Re: python speed

2005-11-30 Thread Carsten Haese
On Wed, 2005-11-30 at 14:53, Paul Boddie wrote:
 [...] the Java virtual machine
 is suitably designed/specified to permit just-in-time complication.

+1 Freudian slip of the week :)

-Carsten Haese


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


Re: Why are there no ordered dictionaries?

2005-11-23 Thread Carsten Haese
On Tue, 2005-11-22 at 20:44, Tom Anderson wrote:
 On Tue, 22 Nov 2005, Carsten Haese wrote:
 
  On Tue, 2005-11-22 at 14:37, Christoph Zwerschke wrote:
 
  In Foord/Larosa's odict, the keys are exposed as a public member which 
  also seems to be a bad idea (If you alter the sequence list so that it 
  no longer reflects the contents of the dictionary, you have broken your 
  OrderedDict).
 
  That could easily be fixed by making the sequence a managed property 
  whose setter raises a ValueError if you try to set it to something 
  that's not a permutation of what it was.
 
 I'm not a managed property expert (although there's a lovely studio in 
 Bayswater you might be interested in), but how does this stop you doing:
 
 my_odict.sequence[0] = Shrubbery()

It would only break if the getter returns the internal list directly.
The getter should return a copy instead, which is what the keys() method
already does anyway. This would ensure that the only way to alter the
sequence is by replacing it in its entirety.

-Carsten.


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


Re: syntax errors while building pypgsql

2005-11-23 Thread Carsten Haese
On Wed, 2005-11-23 at 08:01, Tin Gherdanarra wrote:
 Hallo,
 
 I'm trying to install pypgsql. However, I get syntax errors
 while compiling the C sources. The following excerpt
 from pgconnection.h looks a little funny to me:
 
 typedef struct {
  PyObject_HEAD /* Here is the syntax error, and rightly so */
  PGconn *conn;
  PyObject *host;
  PyObject *port;
  PyObject *db;
  PyObject *options;
  PyObject *tty;
  PyObject *user;
  PyObject *pass;
  PyObject *bePID;
  PyObject *socket;
  PyObject *version;
  PyObject *notices;
  PyObject *cinfo;
  int showQuery;
 } PgConnection;
 
 
 I don't know what PyObject_HEAD or PGconn is,
 but if they are types, a syntax error is justified here:

PyObject_HEAD is not a type, it is a macro that defines struct members
that all Python objects have in common. The macro definition has a
semicolon at the end, so when the macro is expanded, the result is
syntactically correct, even though the above looks wrong on the surface.

What error messages are you actually getting? If you are getting a long
list of errors, please give us the first few rather than the last few.

-Carsten


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


Re: Why are there no ordered dictionaries?

2005-11-23 Thread Carsten Haese
On Wed, 2005-11-23 at 15:17, Christoph Zwerschke wrote:
 Bengt Richter wrote:
   I think the concept has converged to a replace-or-append-by-key ordering
   of key:value items with methods approximately like a dict. We're now
   into usability aspects such as syntactic sugar vs essential primitives,
   and default behaviour vs selectable modes, ISTM.
 
 Yes, and we would be good if we do not stop the discussion at this point 
 with nothing, but really create such a sophisticated implementation. 
 Whether it will become popular or go to the standard lib some day is a 
 completely different question.
 
   E.g., it might be nice to have a mode that assumes d[key] is 
 d.items()[k][1] when
   key is an integer, and otherwise uses dict lookup, for cases where 
 the use
   case is just string dict keys.
 
 I also thought about that and I think PHP has that feature, but it's 
 probably better to withstand the temptation to do that. It could lead to 
 an awful confusion if the keys are integers.

Thus quoth the Zen of Python:
Explicit is better than implicit.
In the face of ambiguity, refuse the temptation to guess.

With those in mind, since an odict behaves mostly like a dictionary, []
should always refer to keys. An odict implementation that wants to allow
access by numeric index should provide explicitly named methods for that
purpose.

-Carsten


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


Re: Why are there no ordered dictionaries?

2005-11-23 Thread Carsten Haese
On Wed, 23 Nov 2005 23:39:22 +0100, Christoph Zwerschke wrote
 Carsten Haese schrieb:
 
  Thus quoth the Zen of Python:
  Explicit is better than implicit.
  In the face of ambiguity, refuse the temptation to guess.
  
  With those in mind, since an odict behaves mostly like a dictionary, []
  should always refer to keys. An odict implementation that wants to allow
  access by numeric index should provide explicitly named methods for that
  purpose.
 
 Exactly. But I don't think in this case such methods would be 
 needed. You easily get the i-th value in the ordered dict as 
 d.values()[i].
 
 -- Chris

True enough, but unless the odict has its list of values on hand, you're
asking the odict to build a list of all its values just so that you can get
the i'th element. Having a method that does the equivalent of d[d.sequence[i]]
would be cleaner and more efficient.

-Carsten

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


Re: Using Cron to run a python program

2005-11-23 Thread Carsten Haese
On 23 Nov 2005 16:23:11 -0800, vagrantbrad wrote
 I'm using python 2.4 running on Fedora Core 4.  I have written a python
 program called ipscan.py that checks the external ip address of my
 cable internet connection, and on change, will update the dns records
 at my dns provider, zoneedit.  So basically, I've setup dynamic dns
 using python.  Once the ip compare and/or update is complete, I log the
 results to a text file called update.log.  When I run the program in 
 a bash shell with the command python ipscan.py, the program runs fine
 and the results are appended to update.log.  When I run this program 
 as a cron job under the root user with the previously mentioned 
 command, the program runs without errors but does not append an 
 entry to the log.  The permissions on the update.log file should not 
 be an issue since I'm running the cron job as root, but I've given 
 root write permissions just to be safe.  What would cause the 
 logging to work at a command prompt but fail in cron?  I'm not 
 getting any errors in the cron logs or /var/spool/mail/root.

You're not giving us much detail about your script, so we can only guess. My
guess is that your python script is either not invoked at all or it dies
(raises an exception) before appending to the update.log.

You should keep in mind that cron jobs don't run in a normal login shell,
don't have the normal environment variables, and are not attached to a tty.
Any of those factors can conceivably cause a script to fail under cron when it
works fine from a shell.

HTH,

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


Re: Why are there no ordered dictionaries?

2005-11-22 Thread Carsten Haese
On Tue, 2005-11-22 at 13:37, Christoph Zwerschke wrote:
 Would the default semantics below really be that suprising?
 
 An ordered dictionary remembers the order in which keys are first seen 
 [...] Overwriting an entry replaces 
 its value, but does not affect its position in the key order. Removing 
 an entry (using 'del') _does_ remove it from the key order. Accordingly, 
 if the entry is later recreated, it will then occur last in the key 
 order. [...]

 I can't help but I still find it unambiguous and intuitive enough to 
 consider it the one standard implementation for ordered dictionaries.

I don't think it's intuitive if you can't describe it without
contradicting yourself. If the order of the keys really were the order
in which they were first seen by the dictionary, deleting and recreating
a key should maintain its original position.

-Carsten


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


Re: Why are there no ordered dictionaries?

2005-11-22 Thread Carsten Haese
On Tue, 2005-11-22 at 14:37, Christoph Zwerschke wrote:
 In Foord/Larosa's odict, the keys are exposed as a public member which 
 also seems to be a bad idea (If you alter the sequence list so that it 
 no longer reflects the contents of the dictionary, you have broken your 
 OrderedDict).

That could easily be fixed by making the sequence a managed property
whose setter raises a ValueError if you try to set it to something
that's not a permutation of what it was.

 d1[0] + d1[2] == OrderedDict( (1, 11), (3, 13) )

What do you think you're doing here?

-Carsten


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


[ANN] Python API InformixDB-2.1 released

2005-11-20 Thread Carsten Haese
Hi everybody:

I am proud to announce a new release of InformixDB, the IBM Informix
implementation of the Python DB API. This release adds the following new 
features:

* Scroll cursors and cursors with hold
* Support for INTERVAL types
* Support for Smart Large Objects
* Support for User Defined Types

Downloads and more info at http://informixdb.sourceforge.net/

Enjoy,

Carsten Haese.

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


Re: How to avoid f.close (no parens) bug?

2005-11-13 Thread Carsten Haese
On Thu, 2 Nov 2006 23:56:22 +0200, o wrote 
 plez send me 
  

Please tell us what bug you're talking about:

A) Python closed the file but you expected it not to.
B) Python didn't close the file but you expected it to.
C) Python didn't warn you when you wrote f.close instead of f.close().
D) Something else. Please elaborate by giving us a code example, a description
of what you expected to happen, and a description of what happened instead.

Best regards,

Carsten Haese.

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


Re: Python obfuscation

2005-11-10 Thread Carsten Haese
On Thu, 2005-11-10 at 16:53, Steven D'Aprano wrote:
 Dude, a comprehension protection for *any* software can never be built
 because of the fundamental nature of computers. Trying to stop bytes from
 being copyable is like trying to stop water from being wet, and once
 copied, all copies are identical and therefore indistinguishable.

+1 QOTW!

-- 
  Carsten Haese - Software Engineer   |  Phone: (419) 794-2531
Unique Systems, Inc.  |  FAX:   (419) 893-2840
1687 Woodlands Drive  |  Cell:  (419) 343-7045
 Maumee, OH  43537|  Email: [EMAIL PROTECTED]

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


Re: mod_python

2005-11-06 Thread Carsten Haese
On Sun, 06 Nov 2005 23:29:01 -, Jim Segrave wrote
 In article [EMAIL PROTECTED],
 Little [EMAIL PROTECTED] wrote:
 cursor.execute(
 INSERT INTO InventoryList (artist, title, rating) VALUES (%s,
 %s, %s), (z_Name, z_rating, z_price) )
 
 I hate to ask, but what happens when I enter a, b, c);DROP 
 DATABASE; as the entry for z_name? (Or some similar attempt to 
 close the SQL statement and start a new one). I think you want to 
 google for SQL injection and think about sanitising user input a bit.

The OP is using execute() with a parameter tuple. This is the correct method
for executing a parametrized query, and it is immune to SQL injection as long
as the DB module implements parameter substitution in a sane way.

Best regards,

Carsten Haese.

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


Re: Retain reference to a struct

2005-11-02 Thread Carsten Haese
On Wed, 2005-11-02 at 16:23, [EMAIL PROTECTED] wrote:
 Hi All,
 
 A C library I'm using has a number of functions that all require a
 struct as an argument.  The example module shows how to make a new
 Python Object from C code and I've seen other posts that recommend this
 way of doing it.
 
 In this case though, it would seem easier if I could create the object
 in the Python code.  This would require storing a pointer to an
 instance of the struct until a certain function is called.
 
 I can get the pointer into the python code, but whenever I try to use
 it to call another function, the module segfaults.  Can anyone suggest
 why this is?
 
 static PyObject *
 libpyq_PQconnectdb(PyObject *self, PyObject *args)
 {
 PGconn *conn = PyMem_New(PGconn, sizeof(PGconn *));
 conn = (PGconn *)PQconnectdb((const char*)
 PyString_AS_STRING(args));
 
 printf(%p, conn);
 return PyLong_FromVoidPtr(conn) ;
 }
 
 static PyObject *
 libpyq_PQfinish(PyObject *self, PyObject *args)
 {
 printf(%p, args);
 return 1;

What exactly do you think you're returning here? The function
declaration says that you're supposed to return a pointer to a PyObject.
'1' is not likely to be a valid pointer to anything.

 }
 
  import libpyq#works fine
  conn = libpyq.PQconnectdb#conn now a pointer

Are you sure that's the correct example code? As written, that line
doesn't call the PQconnectdb function. It assigns conn to be an
alternate name for the PQconnectdb function.

  libpyq.PQfinish(conn)#segfaults

That's probably due to the fact that the python interpreter wants to
look up your return value for printing it, but you're returning a bogus
pointer.

 I'm new to C but relatively experienced with Python.  I have a sneaky
 suspiscion there's a good reason for not doing it this way but I
 haven't seen a good explanation of why not yet.  If you know one,
 please tell me.

The idea of passing around pointers as numbers is very unpythonic. There
is no guarantee that the number that's passed into PQfinish actually
came from a call to PQconnectdb. The user could pass in any integer and
(probably successfully) attempt to crash the system. You should really
wrap the C struct (or the pointer to the C struct) into a Python object
instead.

By the way, it looks like you're trying to write some sort of database
access module. The 'pq' looks suspiciously like it's for PostgreSQL. If
that's the case, can't you just use an existing module for connecting to
PostgreSQL?

HTH,

Carsten Haese.


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


Re: Function returns none

2005-10-31 Thread Carsten Haese
On Mon, 2005-10-31 at 14:12, [EMAIL PROTECTED] wrote:
 I'm trying to write a website updating script, but when I run the
 script, my function to search the DOM tree returns None instead of what
 it should.
 
 I have this program:
 
 import sys
 from xml.dom.minidom import parse
 
 
 # search the tree for an element with a particular class
 
 def findelement(current, classtofind, topnode = None):
 if topnode == None: topnode = current
 
 
 
 # if it's an xml element...
 if current.nodeType == 1:
 print current.nodeName, ':', current.getAttribute('class')
 if current.getAttribute('class') == classtofind:
 print 'Returning node:', current
 return current
 elif current.hasChildNodes():
 findelement(current.firstChild, classtofind, topnode)
 elif current.nextSibling:
 findelement(current.nextSibling, classtofind, topnode)
 
 elif (current.parentNode != topnode) \
 
  and (current.parentNode.nextSibling != None):
 
 findelement(current.parentNode.nextSibling, classtofind,
 topnode)
 else:
 
 print 'Returning None...'
 
 return None
 
 # others (text, comment, etc)
 
 else:
 
 if current.nextSibling:
 
 findelement(current.nextSibling, classtofind, topnode)
 
 elif (current.parentNode != topnode) \
 
  and (current.parentNode.nextSibling != None):
 
 findelement(current.parentNode.nextSibling, classtofind,
 topnode)
 else:
 
 print 'Returning None...'
 
 return None
 
 
 
 # parse the document
 
 blog = parse('/home/noah/dev/blog/template.html')
 
 
 
 # find a post
 
 postexample = findelement(blog.documentElement, 'post')
 
 
 
 print 'Got node:   ', postexample
 
 -
 
 My output is this:
 
 -
 html :
 head :
 title :
 body :
 h1 :
 ul :
 li :
 h2 :
 ol :
 li : post
 Returning node: DOM Element: li at -0x48599c74
 Got node:None
 -
 
 The function finds the right element fine, and says it will return DOM
 Element: li at -0x48599c74, but the program gets None instead.  What's
 happening here?  Any suggestions?

You have a lot of cases where findelement is called recursively and then
its return value is discarded instead of being turned into a return
value to the caller. In those cases, execution simply falls off the end
of the function and None is returned implicitly (and silently, since you
don't have a print Returning None at the end of the function).

HTH,

Carsten.


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


Re: syntax question - if 1:print 'a';else:print 'b'

2005-10-27 Thread Carsten Haese
On Thu, 2005-10-27 at 14:00, Gregory Piñero wrote:
 Not quite because if something(3) fails, I still want something(4) to
 run.  

def something_ignore_exceptions(x):
  try: something(x)
  except: pass

something_ignore_exceptions(1)
something_ignore_exceptions(2)
# etc...

HTH,

Carsten Haese


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


[ANN] Python API InformixDB-2.0 released

2005-10-24 Thread Carsten Haese
Hi everybody,

Thanks to significant code contributions by Daniel Smertnig, I am proud
to announce release 2.0 of the Informix implementation of the Python
DB-API, a mere 5 weeks after release 1.5.

Downloads and info at http://informixdb.sourceforge.net/

This release features the following improvements over InformixDB-1.5:

* Full compliance with version 2 of the DB-API specification, including
many useful optional features suggested by the specification.

* Improved documentation: Command line help and HTML manual.

* Improved portability: The module now builds painlessly on Windows, and
a binary installer for Python 2.4 is provided.

Note that this release requires Python 2.2 or better, and it breaks
backwards compatibility with version 1 of the DB-API specification. If
either of these are a problem for you, you may still use InformixDB-1.5,
but I strongly recommend upgrading as I won't develop InformixDB-1.5 any
further.

Best regards,

Carsten Haese.


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


Re: Help creating extension for C function

2005-10-11 Thread Carsten Haese
On Tue, 2005-10-11 at 15:14, Java and Swing wrote:
 Anyhow, I need PyBuildValue to work.

Try Py_BuildValue.

HTH,

Carsten Haese.


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


Re: Python interpreter bug

2005-10-07 Thread Carsten Haese
On Fri, 2005-10-07 at 10:33, [EMAIL PROTECTED] wrote:
 In fact, i want to sort the list based on the 'allocated attribute' and
 at the same time, test membership based on the id attribute.
 __cmp__ logically implies an ordering test, not an identity test. These
 two notions seems to be confounded in python which is unfortunate. Two
 objects could have the same rank while still being different.
 Alain

You could use the id in __cmp__ as a tie-breaker if the two objects have
equal allocated values.

By the way, __cmp__ is not an identity test. The in operator doesn't
use object identity, it uses object equality, and __cmp__ does serve to
test object equality (if no __eq__ method is present).

Perhaps the following example will clarify the behavior of in:

 A = [1]
 B = [1]
 A==B
True
 A is B
False
 A in [spam, 42, B]
True

HTH,

Carsten Haese.


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


Re: Dynamical loading of modules

2005-10-04 Thread Carsten Haese
On Mon, 2005-10-03 at 17:37, Steve Holden wrote:
 Carsten Haese wrote:
  On Mon, 2005-10-03 at 16:41, Carsten Haese wrote:
  
 On Mon, 2005-10-03 at 15:52, Jacob Kroon wrote:
 
 Hi, I'm having some problems with implementing dynamical module loading. 
 First let me
 describe the scenario with an example:
 
 modules/
 fruit/
 __init__.py
 apple.py
 banana.py
 
 apple.py defines a class 'Apple', banana defines a class 'Banana'. The 
 problem lies in the
 fact that I want to be able to just drop a new .py-file, for instance 
 peach.py, and not change
 __init__.py, and it should automatically pickup the new file in 
 __init__.py. I've come halfway
 by using some imp module magic in __init__.py, but the problem I have is 
 that the instantiated
 objects class-names becomes fruit.apple.Apple/fruit.banana.Banana, whild 
 I want it to be
 fruit.Apple/fruit.Banana.
 
 Is there a smarter way of accomplishing what I am trying to do ?
 If someone could give me a small example of how to achieve this I would 
 be very grateful.
 
 How about something like this in fruit/__init__.py:
 
 import os
 
 fruit_dir = os.path.dirname(__file__)
 fruit_files = [x for x in os.listdir(fruit_dir) if (x[-3:]=='.py' and 
 x!='__init__.py')]
 for fruit_file in fruit_files:
   module_name = fruit_files[:-3]
  
^^^ This should be fruit_file, of course.
  
  
   exec from %s import * % module_name
 
 
 Wouldn't
 
  __import__(module_name)
 
 be better.

I don't see how a working example that meets the OP's requirements can
be constructed using __import__, but that may easily be due to my lack
of imagination. How would you do it?

Regards,

Carsten Haese.


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


Re: Dynamical loading of modules

2005-10-04 Thread Carsten Haese
On Tue, 2005-10-04 at 08:32, Steve Holden wrote:
 Carsten Haese wrote:
  On Mon, 2005-10-03 at 17:37, Steve Holden wrote:
  
 Carsten Haese wrote:
 
 On Mon, 2005-10-03 at 16:41, Carsten Haese wrote:
 
 
 On Mon, 2005-10-03 at 15:52, Jacob Kroon wrote:
 
 
 Hi, I'm having some problems with implementing dynamical module loading. 
 First let me
 describe the scenario with an example:
 
 modules/
fruit/
__init__.py
apple.py
banana.py
 
 apple.py defines a class 'Apple', banana defines a class 'Banana'. The 
 problem lies in the
 fact that I want to be able to just drop a new .py-file, for instance 
 peach.py, and not change
 __init__.py, and it should automatically pickup the new file in 
 __init__.py. I've come halfway
 by using some imp module magic in __init__.py, but the problem I have is 
 that the instantiated
 objects class-names becomes fruit.apple.Apple/fruit.banana.Banana, whild 
 I want it to be
 fruit.Apple/fruit.Banana.
 
 Is there a smarter way of accomplishing what I am trying to do ?
 If someone could give me a small example of how to achieve this I would 
 be very grateful.
 
 How about something like this in fruit/__init__.py:
 
 import os
 
 fruit_dir = os.path.dirname(__file__)
 fruit_files = [x for x in os.listdir(fruit_dir) if (x[-3:]=='.py' and 
 x!='__init__.py')]
 for fruit_file in fruit_files:
  module_name = fruit_files[:-3]
 
   ^^^ This should be fruit_file, of course.
 
 
 
  exec from %s import * % module_name
 
 
 Wouldn't
 
  __import__(module_name)
 
 be better.
  
  
  I don't see how a working example that meets the OP's requirements can
  be constructed using __import__, but that may easily be due to my lack
  of imagination. How would you do it?
  
 I was simply suggesting that you replace the exec statement with a call 
 to __import__(). Wouldn't that work?

Not the way I tried it by simply replacing my line with your line. (If
it matters, I'm on python 2.2 here.) First of all, the __import__
variant doesn't see the submodules unless I add fruit_dir to sys.path.
Secondly, the OP's requirements are that the classes that the submodules
implement be imported into fruit's namespace, and I don't see how to
make __import__ do that.

Regards,

Carsten Haese.


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


Re: Dynamical loading of modules

2005-10-03 Thread Carsten Haese
On Mon, 2005-10-03 at 15:52, Jacob Kroon wrote:
 Hi, I'm having some problems with implementing dynamical module loading. 
 First let me
 describe the scenario with an example:
 
 modules/
 fruit/
 __init__.py
 apple.py
 banana.py
 
 apple.py defines a class 'Apple', banana defines a class 'Banana'. The 
 problem lies in the
 fact that I want to be able to just drop a new .py-file, for instance 
 peach.py, and not change
 __init__.py, and it should automatically pickup the new file in 
 __init__.py. I've come halfway
 by using some imp module magic in __init__.py, but the problem I have is 
 that the instantiated
 objects class-names becomes fruit.apple.Apple/fruit.banana.Banana, whild 
 I want it to be
 fruit.Apple/fruit.Banana.
 
 Is there a smarter way of accomplishing what I am trying to do ?
 If someone could give me a small example of how to achieve this I would 
 be very grateful.

How about something like this in fruit/__init__.py:

import os

fruit_dir = os.path.dirname(__file__)
fruit_files = [x for x in os.listdir(fruit_dir) if (x[-3:]=='.py' and 
x!='__init__.py')]
for fruit_file in fruit_files:
  module_name = fruit_files[:-3]
  exec from %s import * % module_name

HTH,

Carsten.


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


Re: Dynamical loading of modules

2005-10-03 Thread Carsten Haese
On Mon, 2005-10-03 at 16:41, Carsten Haese wrote:
 On Mon, 2005-10-03 at 15:52, Jacob Kroon wrote:
  Hi, I'm having some problems with implementing dynamical module loading. 
  First let me
  describe the scenario with an example:
  
  modules/
  fruit/
  __init__.py
  apple.py
  banana.py
  
  apple.py defines a class 'Apple', banana defines a class 'Banana'. The 
  problem lies in the
  fact that I want to be able to just drop a new .py-file, for instance 
  peach.py, and not change
  __init__.py, and it should automatically pickup the new file in 
  __init__.py. I've come halfway
  by using some imp module magic in __init__.py, but the problem I have is 
  that the instantiated
  objects class-names becomes fruit.apple.Apple/fruit.banana.Banana, whild 
  I want it to be
  fruit.Apple/fruit.Banana.
  
  Is there a smarter way of accomplishing what I am trying to do ?
  If someone could give me a small example of how to achieve this I would 
  be very grateful.
 
 How about something like this in fruit/__init__.py:
 
 import os
 
 fruit_dir = os.path.dirname(__file__)
 fruit_files = [x for x in os.listdir(fruit_dir) if (x[-3:]=='.py' and 
 x!='__init__.py')]
 for fruit_file in fruit_files:
   module_name = fruit_files[:-3]
  ^^^ This should be fruit_file, of course.

   exec from %s import * % module_name
 
 HTH,
 
 Carsten.


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


InformixDB-1.5 released

2005-09-19 Thread Carsten Haese
Hi Everybody:

I have released a new version, version 1.5, of InformixDB, the DB-API
module for connecting to IBM Informix database engines.

Download at http://sourceforge.net/projects/informixdb .

Notable changes since version 1.4:

* Further steps towards DB-API 2 compliance: added recommended keyword
arguments to connect() method and implemented cursor methods/attributes
.next(), .executemany(), .rowcount, and .arraysize

* informixdb.Error now makes details about the error (such as sqlcode)
available as attributes.

* sqlerrd wasn't initialized properly, and under many circumstances it
didn't correspond to the most recent operation.


Best regards,

Carsten Haese.


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


Re: MySQLdb error - PLEASE SAVE ME!

2005-09-17 Thread Carsten Haese
On Sat, 17 Sep 2005 15:50:29 -0400, Ed Hotchkiss wrote
 Ok. I am trying to read a csv file with three strings separated by commas.
 I am trying to insert them into a MySQL DB online.
 MySQLdb is installed, no problems.
 
 I think that I am having some kind of error with my csv going into 
 the fields and being broken apart correctly. Can someone please 
 help? I attached the code below, it does work with that SQL server 
 also if you want to try and run it. Thanks in advance ..

There are two obvious faults in your code:

1) You're using the % operator to plug your parameters directly into the query
string. Don't do that. Pass the parametrized query as the first argument to
execute(), pass the parameter tuple as the second argument to execute(), and
leave it to execute() to plug in the parameters.

Once 1) is fixed, you'll run into...

2) The ID column is a NOT NULL column. There is no default value for it, nor
is there an AUTO_INCREMENT flag on it. You're not specifying a value for ID in
the insert statement. Either this will fail on the first insert (attempting to
insert a NULL value into a NOT NULL column), or in case MySQL helpfully
defaults the ID to 0, it'll fail on the second row when the primary key
constraint is violated by attempting to insert another 0.

To fix 2), you'll wither want to make the ID column an AUTO_INCREMENT column
or explicitly specify a value for the ID column in the insert statement.
(Using AUTO_INCREMENT is easier.)


Hope this helps,

Carsten.


P.S. You need to learn how to describe your problem accurately. Phrases like
no problems and it does work juxtaposed with some kind of error do
nothing to describe what actually works and what doesn't work. I'm betting
python raised an exception when you ran your code. Instead of guessing
randomly (and incorrectly) that there is some kind of error in your csv
parsing, you could have, for example, included a copy of the exception message.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Find day of week from month and year

2005-09-02 Thread Carsten Haese
On Fri, 2005-09-02 at 16:46, Laguna wrote:
 Paul,
 
 Thanks for the suggestion on calendar module. Here is my solution and
 it works:
 
 def expiration(year, month):
   weekday = calendar.weekday(year, month, 1)
   table = [19, 18, 17, 16, 15, 21, 20]
   return table[weekday]
 
 Cheers,
 Laguna

This, of course, can be optimized into

def expiration(year, month):
return [19,18,17,16,15,21,20][calendar.weekday(year,month,1)]

;)

-Carsten


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


Re: variable hell

2005-08-25 Thread Carsten Haese
On Thu, 2005-08-25 at 10:43, Nx wrote:
 Thanks for the many replies
 
  here is an example for what it will be used for , in this case
  fixed at 31 fieldvalues:
 
  
 inputvalues=(s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16,s17,s18,s19,s20,s21,s22,s23,s24,s25,
 s26,s27,s28,s29,s30,s31)

inputvalues = tuple(mylist)

Hope this helps,

Carsten.


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


Re: variable hell

2005-08-25 Thread Carsten Haese
On Thu, 2005-08-25 at 11:04, I hastily wrote:
 On Thu, 2005-08-25 at 10:43, Nx wrote:
  Thanks for the many replies
  
   here is an example for what it will be used for , in this case
   fixed at 31 fieldvalues:
  
   
  inputvalues=(s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16,s17,s18,s19,s20,s21,s22,s23,s24,s25,
  s26,s27,s28,s29,s30,s31)
 
 inputvalues = tuple(mylist)

And actually, you probably don't have to do that, because the execute
method should be able to handle a list just as well as a tuple.

-Carsten.


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


Re: Spreadsheet with Python scripting and database interface?

2005-08-11 Thread Carsten Haese
On Fri, 2005-07-29 at 04:21, Wolfgang Keller wrote:
 Hello,
 
 I'm looking for a spreadsheet application (MacOS X prefered, but
 Windows, Linux ar available as well) with support for Python scripting
 (third-party plug-ins are ok) and a database interface.
 
 Applications that I know of (that they exist) are:
 
 MS Excel
 Quattro
 Lotus
 OO Calc
 Gnumeric
 Kspread
 
 Which ones have I forgotten?
 
 Which ones have support for Python scripting?
 [snip]
 OO Calc: I know that PyUNO exists, but I know nothing about what it can
 actually do?
 [snip]

See http://udk.openoffice.org/python/python-bridge.html for more than
you'll ever want to know about this. In a nutshell, you can do pretty
much anything.

One thing that's not clear from your question is whether you want to
script the office from within using a macro or from the outside via
remote control. PyUNO allows both, but Python macros are only possible
with the OpenOffice 2 scripting framework.

Hope this helps,

Carsten Haese.


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


Informixdb: New maintainer, new version

2005-04-12 Thread Carsten Haese
Hi Everybody:

Since the current maintainer of the informixdb module appears to have
gone missing, I have decided to take over the project. The new home of
the informixdb module is http://sourceforge.net/projects/informixdb .

Version 1.4 features the following improvements:

* Build uses distutils instead of deprecated Makefile.pre.in mechanism.
* Connect method takes optional username and password parameters for
connecting to a remote database.
* Cursor attribute .sqlerrd exposes Informix's sqlca.sqlerrd resulting
from the cursor's most recent .execute() call.

If you have any questions or comments, please let me know.

Best regards,

-- 
  Carsten Haese - Software Engineer   |Phone:  (419) 861-3331
Unique Systems, Inc.  |  FAX:  (419) 861-3340
 1446 Reynolds Rd, Suite 313  |
 Maumee, OH  43537|  mailto:[EMAIL PROTECTED]

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


Re: Ply(LALR) and Yacc behaving differently

2005-04-08 Thread Carsten Haese
On Thu, 2005-04-07 at 14:51, Åsmund Grammeltvedt wrote:
 Hi.
 
 I am trying to implement a small compiler in python and, trying to use 
 something a bit more pythonic than lex/yacc, ended up with ply 
 (http://systems.cs.uchicago.edu/ply/). The only problem is that whereas 
 yacc accepts the grammar and appears to parse it correctly, ply does not.
 
 Perhaps this belongs on some compiler list, but I couldn't decide if it 
 was a compiler or a python problem, so bear with me.

Maybe this is a PLY bug? LALR(1) support appears to be a relatively
recent addition to PLY. Have you tried contacting PLY's author?

For what it's worth, it appears that you can make your example grammar
work in LALR-mode PLY by eliminating the empty production and making the
Block rule right recursive like this:

def p_Goal(p):
  
  Goal : Block
  

def p_Block(p):
  
  Block : SEMI
| T Block
| S Block
  

Of course, I don't know whether this rewrite is applicable to your
larger grammar.

Hope this helps,

-- 
  Carsten Haese - Software Engineer   |Phone:  (419) 861-3331
Unique Systems, Inc.  |  FAX:  (419) 861-3340
 1446 Reynolds Rd, Suite 313  |
 Maumee, OH  43537|  mailto:[EMAIL PROTECTED]

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


Re: Looking for Stephen Turner, maintainer of informixdb

2005-04-04 Thread Carsten Haese
On Tue, 2005-03-29 at 03:05, Michael Husmann wrote:
 Carsten Haese wrote:
 
  Hello everybody:
  
  I have discovered that the functionality for connecting Python to an
  Informix database is currently in a frustrating state of neglect. The
  link to Kinfxdb is dead, and informixdb doesn't build on Python 2. I
  couldn't find any usable workarounds to the build problem, so I worked
  out successfully how to build informixdb using distutils.
  
  Now I'd like to share the result with the community, but the maintainer
  appears to have gone missing. My emails to [EMAIL PROTECTED] and
  [EMAIL PROTECTED] have bounced back undeliverable, so now I'm
  posting to the lists trying to locate Stephen.
  
  If anybody has any pointers for locating Stephen Turner, please let me
  know. If Stephen can't be located, I'd be willing to take over the
  project, but I'd prefer the torch be given to me rather than me just
  taking it.
 
 Carsten,
 
 haven't heard anything from Stephen either, but there are some extensions to
 the informixdb module. I'll send the sources to you next week. So if you
 like you can bundle everything in one package.

Michael, I'd certainly like to take a look at those extensions. (I tried
to respond to you off-list, but my mail bounced back. Is this project
cursed or am I? :) I hope you're reading this, Michael.)

A week has gone by with no replies as to Stephen's whereabouts, and one
reply telling me that I can, in good faith, go ahead and release a fork.
Unless somebody tells me I should wait longer, I guess I'll do that.
Stay tuned for the announcement on when and where my fork will be
available.

Best regards,

-- 
  Carsten Haese - Software Engineer   |Phone:  (419) 861-3331
Unique Systems, Inc.  |  FAX:  (419) 861-3340
 1446 Reynolds Rd, Suite 313  |
 Maumee, OH  43537|  mailto:[EMAIL PROTECTED]

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


Looking for Stephen Turner, maintainer of informixdb

2005-03-28 Thread Carsten Haese
Hello everybody:

I have discovered that the functionality for connecting Python to an
Informix database is currently in a frustrating state of neglect. The
link to Kinfxdb is dead, and informixdb doesn't build on Python 2. I
couldn't find any usable workarounds to the build problem, so I worked
out successfully how to build informixdb using distutils.

Now I'd like to share the result with the community, but the maintainer
appears to have gone missing. My emails to [EMAIL PROTECTED] and
[EMAIL PROTECTED] have bounced back undeliverable, so now I'm
posting to the lists trying to locate Stephen.

If anybody has any pointers for locating Stephen Turner, please let me
know. If Stephen can't be located, I'd be willing to take over the
project, but I'd prefer the torch be given to me rather than me just
taking it.

Thanks,

-- 
  Carsten Haese - Software Engineer   |Phone:  (419) 861-3331
Unique Systems, Inc.  |  FAX:  (419) 861-3340
 1446 Reynolds Rd, Suite 313  |
 Maumee, OH  43537|  mailto:[EMAIL PROTECTED]

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


<    2   3   4   5   6   7