a regex question

2019-10-25 Thread Maggie Q Roth
Hello

There are two primary types of lines in the log:

60.191.38.xx/
42.120.161.xx   /archives/1005

I know how to write regex to match each line, but don't get the good result
with one regex to match both lines.

Can you help?

Thanks,
Maggie
-- 
https://mail.python.org/mailman/listinfo/python-list


graphics with python

2019-10-24 Thread Maggie Q Roth
Hello

Can you show me the correct way to programming with graphics?

I want to take some action detection, for instance, recognize dancing etc.

Thanks,
Maggie
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Goto (Posting On Python-List Prohibited)

2018-01-01 Thread John Q Hacker
Sorry, delete string "n't".  I mean that you would strcuture your code
with that architecture.

Hate that.

marxos

On 1/1/18, John Q Hacker <zonderv...@gmail.com> wrote:
>>> I don’t use gotos in C code. Why should it be “harder” in a higher-level
>>> language?
>>
>> Good for you.
>>
>> Looking at 14 million lines of Linux kernel sources, which are in C,
>> over 100,000 of them use 'goto'. About one every 120 lines.
>
> Most use of goto's implies a lack of understanding of the unseen
> architecture of the problem domain itself (otherwise, you wouldn't
> have structured your program with that architecture).  The only
> remaining use is optimization, and most of that is probably premature,
> as use of gotos *can* make things hard to understand, but using labels
> is a pretty happy medium.
>
> Marxos
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Goto (Posting On Python-List Prohibited)

2018-01-01 Thread John Q Hacker
>> I don’t use gotos in C code. Why should it be “harder” in a higher-level
>> language?
>
> Good for you.
>
> Looking at 14 million lines of Linux kernel sources, which are in C,
> over 100,000 of them use 'goto'. About one every 120 lines.

Most use of goto's implies a lack of understanding of the unseen
architecture of the problem domain itself (otherwise, you wouldn't
have structured your program with that architecture).  The only
remaining use is optimization, and most of that is probably premature,
as use of gotos *can* make things hard to understand, but using labels
is a pretty happy medium.

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


[issue29675] SysLogHandler does not seem to always expand %(loglevel)s properly

2017-02-28 Thread Q

Q added the comment:

PS. I'm not sure if that is a systemd/journald issue, or indeed a Python bug.

However, it would be nice to clear one possibility. 

For a StreamHandler, it all works as it should.

--

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



[issue29675] SysLogHandler does not seem to always expand %(loglevel)s properly

2017-02-28 Thread Q

Q added the comment:

Attaching the other file mentioned.

--
Added file: http://bugs.python.org/file46680/good.py

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



[issue29675] SysLogHandler does not seem to always expand %(loglevel)s properly

2017-02-28 Thread Q

New submission from Q:

On Ubuntu LTS 16.04, SysLogHandler with a custom formatter does not seem to 
expand loglevel/levelno fields properly, when there are square brackets ( see 
the attached examples ). Instead, it seems to replace '[%(loglevel)s]' with a 
'[pid]', and '%(loglevel)s' with 'LOGLEVEL[pid]' .

To test, run 'journalctl -f | grep test_test_test' on one console, and the 
attached files on another. The output for 'bad.py' looks as follows:
===
Feb 28 21:30:05 hostname [7117]: logging was configured for 
process <7117>
===

And should have looked like:
===
Feb 28 21:30:05 hostname [INFO]: logging was configured for 
process <7117>
===

For 'good.py', the output is as follows:
===
Feb 28 21:30:04 hostname INFO[7114]: logging was configured for 
process <7114>
===

and should have probably been: 
===
Feb 28 21:30:04 hostname INFO: logging was configured for 
process <7114>
===

Kind regards, /t13

--
files: bad.py
messages: 288702
nosy: thread13
priority: normal
severity: normal
status: open
title: SysLogHandler does not seem to always expand %(loglevel)s properly
versions: Python 2.7
Added file: http://bugs.python.org/file46679/bad.py

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



Re: mix-in classes

2015-06-16 Thread Dr. John Q. Hacker
On Sun, May 24, 2015 at 6:11 AM, Steven D'Aprano st...@pearwood.info
wrote:

 On Sun, 24 May 2015 11:53 am, Dr. John Q. Hacker wrote:
 But, frankly, what you describe is more likely to be a weakness of multiple
 inheritance and mixins, one which should be avoided. One attempt to avoid
 this problem is with traits, an alternative to mixins which explicitly
 deals with the problem of mixin conflicts.

 http://www.artima.com/weblogs/viewpost.jsp?thread=246488


Interesting.  This brings up an issue another poster brought up:  In my
usage of the term parent, I use it to mean the class that is a product of
object composition:

class Parent(child1, child2):  pass

I figure that it is this Parent class which must manage the methods that
it is inheriting with child1 and child2 -- mixins or otherwise.  In this
usage, super() should be called delegate as whatever I don't accomplish
in my specialized Parent class, I will get the child classes to do.  Python
automagically delegates any methods that I don't define in Parent to
methods found in child1 and child2.

It seems the issues that everyone encounters with multiple inheritance,
mixins, and such has more to do with terminology (and proper
implementation) than in actuality.

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


mix-in classes

2015-05-23 Thread Dr. John Q. Hacker
The post on different types of inheritence... brought up a thought.

Let's say, I'm adding flexibility to a module by letting users change class
behaviors by adding different mix-in classes.

What should happen when there's a name collision on method names between
mix-ins?  Since they're mix-ins, it's not presumed that there is any parent
class to decide.  The proper thing would seem to call each method in the
order that they are written within the parent class definition.

I suppose one can create a method in the parent class, that runs the mixin
methods in the same order as in the inheritance list, but would there be a
better way for Python to enforce such a practice so as not to create class
anarchy?  (A problem for another topic.)

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


code blocks

2015-05-03 Thread Dr. John Q. Hacker
Hello,

I'm thinking how interesting it would be to add code blocks to Python, so
that arbitrary strings of code can be passed around.   It would open up
some interesting possibilities for self-modifying code and generic
programming.

Since Python has already a plethora of ambiguous string designations, one
of them could be set aside specificially for code blocks:

for i in n: print i

For any variables, like n, it would access the scope in which it was
running.  When you tried to print a triple-double-quoted code block,
perhaps it could invoke the code.

My suggestion would be to use triple double-quoted strings.

You probably already know that Ruby has code blocks.

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


[issue14823] Simplify threading.Lock.acquire() description

2012-05-18 Thread Q

Q abon...@gmail.com added the comment:

My bad. That's indeed what I did. Won't repeat the mistake, sorry.

--

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



[issue14823] Simplify threading.Lock.acquire() description

2012-05-16 Thread Q

Q abon...@gmail.com added the comment:

Well, as threading is a Python wrapper, this could easily be fixed. (I am not 
certain whether it *should* be fixed or not -- perhaps things are fine just as 
they are, at least with that particular detail. ) 

But this is good to know, thank you.

--

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



[issue14823] Simplify threading.Lock.acquire() description

2012-05-15 Thread Q

New submission from Q abon...@gmail.com:

Hi there,

I suggest to improve the description of Lock.acquire()
[ http://docs.python.org/library/threading.html#threading.Lock.acquire ]
in the following way:

 current version 
Lock.acquire([blocking])

   Acquire a lock, blocking or non-blocking.

   When invoked without arguments, block until the lock is unlocked,
   then set it to locked, and return true.

   When invoked with the *blocking* argument set to true, do the same
   thing as when called without arguments, and return true.

   When invoked with the *blocking* argument set to false, do not
   block.  If a call without an argument would block, return false
   immediately; otherwise, do the same thing as when called without
   arguments, and return true.

 current version 


 suggested version 
Lock.acquire([blocking])

   Acquire a lock, blocking or non-blocking.

   When invoked with the *blocking* argument set to true 
   (the default), block until the lock is unlocked, 
   then set it to locked, and return true.

   When invoked with the *blocking* argument set to false, do not
   block.  If a call without an argument would block, return false
   immediately; otherwise, set the lock to locked, and return true.

 suggested version 

The idea is to simplify the structure of the explanation: get rid of an 
unnecessary goto -- do the same thing as as well as the extra branching 
(when invoked without arguments ... when invoked with *blocking* argument 
set to true) .

The suggested patch for the text version of the documentation ( 
http://docs.python.org/download.html - 
http://docs.python.org/archives/python-2.7.3-docs-text.tar.bz2 ) is attached. 

PS. I did not dare to capitalize the boolean variables (true - True) to 
adhere to the general style of the document (obviously inherited from Java). 
For the same reason I didn't either change the argument signature from 
[blocking] to [blocking=True].

--
assignee: docs@python
components: Documentation
files: threading.txt.patch
keywords: patch
messages: 160786
nosy: docs@python, thread13
priority: normal
severity: normal
status: open
title: Simplify threading.Lock.acquire() description
versions: Python 2.6, Python 2.7
Added file: http://bugs.python.org/file25604/threading.txt.patch

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



[issue14671] isinstance(obj, object) returns True for _old style_ class instances

2012-04-29 Thread Q

Q abon...@gmail.com added the comment:

thanks, that's rather convenient

--

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



[issue14671] isinstance(obj, object) returns True for _old style_ class instances

2012-04-26 Thread Q

Q abon...@gmail.com added the comment:

I do not mean to reopen the bug (there are supposedly much more important 
things to work on in Python). 

But just for the record, let me state that I feel like there is some misleading 
inconsistency here:

- by definition, a new style class is Any class which inherits from object ( 
see http://docs.python.org/glossary.html#term-new-style-class ) ;

- to support this statement, new classes are indeed explicitly defined in the 
form NewClass(object) ;

- now isinstance(), that is supposed to return whether an object is an 
instance of a class or of a subclass thereof (see help(isinstance)), returns 
True for old-style objects.

It also seems reasonable if the descendants of a class will inherit its powers, 
which -- in the case of the old-style classes -- they obviously don't.

Furthermore, I personally see no /point/ in returning True for 
isinstance(Old(), object): as it is quite misleading, one could easily have 
made it returning e.g. None as well.

As I completely accept the fact it's a feature -- ( may be slightly confusing, 
and probably also useless -- but ... hey, nobody's perfect ) -- should I take 
then calling

issubclass(obj.__class__, object) 

to be the official way to distinguish between the new-style and the old-style 
classes?

--

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



[issue14671] isinstance(obj, object) returns True for _old style_ classes

2012-04-25 Thread Q

New submission from Q abon...@gmail.com:

$python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) 
[GCC 4.4.3] on linux2
 class Old: pass
 class New(object): pass
 o = Old()
 n = New()
 isinstance(o, object)
True

This is it, basically. Is it a bug or a feature?

More tests :

 isinstance(o, Old)
True
 isinstance(o, New)
False
 isinstance(n, Old)
False
 isinstance(o, int)
False

Please note that some unimportant output was deleted from above.

PS. If this is a feature, how do I detect an old-style class then ?

--
components: Interpreter Core
messages: 159351
nosy: thread13
priority: normal
severity: normal
status: open
title: isinstance(obj, object) returns True for _old style_ classes
type: behavior
versions: Python 2.6

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



[issue14671] isinstance(obj, object) returns True for _old style_ class instances

2012-04-25 Thread Q

Changes by Q abon...@gmail.com:


--
title: isinstance(obj, object) returns True for _old style_ classes - 
isinstance(obj, object) returns True for _old style_ class instances

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



[issue14671] isinstance(obj, object) returns True for _old style_ class instances

2012-04-25 Thread Q

Q abon...@gmail.com added the comment:

In addition:

 issubclass(Old, object)
False

--

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



[issue14671] isinstance(obj, object) returns True for _old style_ class instances

2012-04-25 Thread Q

Q abon...@gmail.com added the comment:

 help(isinstance)

isinstance(...)
isinstance(object, class-or-type-or-tuple) - bool

Return whether an object is an instance of a class or of a subclass thereof.
(...)

So are the old-style class instances descendants of the object?

I feel like I am missing something (except for the fact that you have closed 
the bug).

--
resolution: invalid - 
status: closed - open

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



Help: how to protect the module 'sys' and 'os'

2012-03-07 Thread q q
Hi~ alls,
I have to limit somebody modify the attr of 'sys''os'? e.g. you can't
append sys.path. Someone has a good method?
now my way: modified the source code of python
,_PyObject_GenericSetAttrWithDict, because if you want to reset the
value,
you need to invoke this function.


---
best regards
pytom
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Locale bug?

2012-01-03 Thread =?ISO-8859-1?Q?Trond_Endrest=F8l?=
Marko Rauhamaa ma...@pacujo.net writes:

 Mysterious 8-bit characters appear in the string returned by strftime.

 $ python
 Python 2.7.2 (default, Oct 27 2011, 01:36:46) 
 [GCC 4.6.1 20111003 (Red Hat 4.6.1-10)] on linux2
 Type help, copyright, credits or license for more information.
  import time, locale
  locale.setlocale(locale.LC_TIME, ('fi_FI', 'UTF-8'))
 'fi_FI.UTF-8'
  time.strftime(%a, %d %b %Y %H:%M:%S %z (%Z))
 'ti, 03 tammi\xc2\xa0 2012 14:52:47 +0200 (EET)'
  
 $ python3
 Python 3.2.1 (default, Jul 11 2011, 18:55:33) 
 [GCC 4.6.1 20110627 (Red Hat 4.6.1-1)] on linux2
 Type help, copyright, credits or license for more information.
  import time, locale
  locale.setlocale(locale.LC_TIME, ('fi_FI', 'UTF-8'))
 'fi_FI.UTF-8'
  time.strftime(%a, %d %b %Y %H:%M:%S %z (%Z))
 'ti, 03 tammi\xa0 2012 14:51:57 +0200 (EET)'
  

It may be OS-specific. Your sample code runs fine on FreeBSD/i386
8.2-STABLE. The OS and Python 2.7.2  3.2.2 were recently compiled and
installed on my system.

trond@enterprise:~uname -sr
FreeBSD 8.2-STABLE
trond@enterprise:~python
Python 2.7.2 (default, Dec 20 2011, 08:49:23)
[GCC 4.2.2 20070831 prerelease [FreeBSD]] on freebsd8
Type help, copyright, credits or license for more information.
 import time, locale
 locale.setlocale(locale.LC_TIME, ('fi_FI', 'UTF-8'))
'fi_FI.UTF-8'
 time.strftime(%a, %d %b %Y %H:%M:%S %z (%Z))
'Ti, 03 Tam 2012 15:02:32 +0100 (CET)'

trond@enterprise:~python3.2
Python 3.2.2 (default, Dec 21 2011, 14:42:29)
[GCC 4.2.2 20070831 prerelease [FreeBSD]] on freebsd8
Type help, copyright, credits or license for more information.
 import time, locale
 locale.setlocale(locale.LC_TIME, ('fi_FI', 'UTF-8'))
'fi_FI.UTF-8'
 time.strftime(%a, %d %b %Y %H:%M:%S %z (%Z))
'Ti, 03 Tam 2012 15:03:15 +0100 (CET)'

trond@enterprise:~

-- 
--
Trond Endrestøl
ACM, NAS, NUUG, SAGE, USENIX
-- 
http://mail.python.org/mailman/listinfo/python-list


access to base class __init__

2008-03-05 Thread sambo q
I got myself in jam trying to be too fancy with  threading.Thread
Docs say / remind to call the base __init__
but I can't fighure out how.

---
def main()
.
ls.listen(5)
key = ' '
#while key != EXITCHARCTER:
while stop_serving == False:
cs, raddr = ls.accept()
print Main_Thread: ,cs, raddr
nt = client_socket_handler( cs, raddr )
print threading.enumerate()
key = getkey()

#ls.close()
time.sleep(4)
print Server Exiting.

class client_socket_handler(threading.Thread):
def __init__(self, cs, remote_address):
???
self.threading.Thread.__init__(self,self.socket_handler,None,None)
self.socket = cs
self.rhost_addr = remote_address
print client_socket_handler.__init__(): , self.socket, 
self.rhost_addr
#t1 = threading.Thread( None,self.socket_handler, None, (5,78) )
#t1.start()
self.start()
print client_socket_handler.__init__(): , self.socket, 
self.rhost_addr
print client_socket_handler.__init__(): enumerate(), 
threading.enumerate()

def socket_handler( self, invar, indict ):
threadname = self.getName()
print \%s started\ % threadname
print client_socket_handler.socket_handler() invar: , invar
instr = self.socket.recv( 500 )
#print instr
req_lines = string.split( instr, \r )
for line in req_lines:
line.strip( \n)
print req_lines
print len( instr )

--

self.threading.Thread.__init__()
self.Thread.__init__()
??
-- 
http://mail.python.org/mailman/listinfo/python-list


Embedding Python

2005-06-17 Thread =?iso-8859-1?q?S=E9bastien_Boisg=E9rault?=
Hi,

Imagine that you have a PyObject pointer 'object'
pointing to a Python integer ... let's say 42.

How would do you attach the variable answer to
it so that the code

PyRun_SimpleString(print answer);

works as expected ?

My current solution is:

__main__ = PyImport_ImportModule(__main__);
PyObject_SetAttrString(__main__, answer, object);

Anything better ?

SB

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


Re: FAQ: __str__ vs __repr__

2005-06-15 Thread =?iso-8859-1?q?S=E9bastien_Boisg=E9rault?=
Jan Danielsson a écrit :
 Sorry, but I Just Don't Get It. I did search the 'net, I did read the
 FAQ, but I'm too dumb to understand.

As far as I can gather, __str__ is just a representation of the
 object.

... yep, and this representation is built for human eyes. Don't
worry too much if it does not display every bit of information
contained in your object. Pretty printing rules ...

 str(0.1)
0.1
 str(it's a bad idea)
it's a bad idea

However, I don't understand what __repr__ should be.

It is an *exact* (if possible) description of the object's content,
nicely packaged into a string.

 repr(0.1)
0.10001
 repr(it's a bad idea)
   'it\'s a bad idea'


 There's a phrase
 in the documentation which makes it highly confusing for a beginner like
 me: If at all possible, this should look like a valid Python expression
 that could be used to recreate an object with the same value (given an
 appropriate environment)..

It means that the equality eval(repr(x)) == x should hold.

Cheers,

SB

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


Re: FAQ: __str__ vs __repr__

2005-06-15 Thread =?iso-8859-1?q?S=E9bastien_Boisg=E9rault?=

Errata:

 str(0.1)
'0.1'
 str(it's a bad idea)
it's a bad idea

 repr(0.1)
   ' 0.10001'
 repr(it's a bad idea)
   'it\'s a bad idea' 


SB

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


Re: dynamic

2005-06-15 Thread =?iso-8859-1?Q?Fran=E7ois?= Pinard
[Michele Simionato]

 Having a class that returns instances of some other class is horrible,
 [...] don't do it!

Unusual, granted.  Horrible, why?

I found useful, sometimes, (ab)using Python syntax for representing data
having more or less complex structure.  More than once, it spared me the
trouble of inventing a syntax, and then writing a lexer and a parser.
Letting class constructors returning arbitrary objects has often been
useful in such circumstances.

-- 
François Pinard   http://pinard.progiciels-bpi.ca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Controlling assignation

2005-06-14 Thread =?ISO-8859-1?Q?Xavier_D=E9coret?=
Bruno Desthuilliers a écrit :
 Xavier Décoret a écrit :
 (snip)
 
 What I wanted to do is something like this:

 def change(x,v):
 x = v

 class A(object):
 def __init__(self,v):
 self.x = v

 a = A(3)
 print a.x  # displays 3
 change(a.x,4)
 print a.x  # still displays 3


 It may seem weird, 
 
 
 It does
 
 but I ensure there is a reason for doing this. 
 
 
 I really wonder what it can be ???

It's the ability to develop the equivalent of GeoNext (and much more) in 
  Python with a very nice syntax.

 
 You could achieve the same effect with:
 
 class A( object):
   def __init__(self, value):
 self.value = value
 
 a = A(3)
 a.value = 4
 a.value
 = 4
 

Of course, and even simpler ;-)
print 4

More seriously, try to do this with your simpler approach.

a = A(4)
b = A(lambda : a.x+5)
a.x = 2

print b.x # I want this to be 7, not 9


 And it's *much* more simple/readable/efficient.
 
 Ever googled for evolution of a programmer ?-)
 
 
Not to brag, but I think I know what programming is.  Google for my 
name. C'est bien un commentaire de francais ca ;-)

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


Re: MySQLDBAPI

2005-06-14 Thread =?ISO-8859-1?Q?Gregory_Pi=F1ero?=
see below

On 6/10/05, Daniel Dittmar [EMAIL PROTECTED] wrote:
 Gregory Piñero wrote:
  Is that something I can install all to my home directory?
 
 If you have a similar Linux distribution at home, simply build the mysql
 extension on that machine and then copy it to the web server.

I have Ubuntu running at home and Redhat is running on the server. 
Would this still work for me?  Do I need to install the same old
version of MySql on my home computer?

 
 Otherwise:
 
 You don't have to actually install it. Just make sure that Setup.py
 finds the headers and libs
 
 1a) get the rpm and extract the files

Are you referring to the rpm for Mysql?  I would just get the same
version as the server has?
 
 or 1b) compile (but don't install) mysql from sources
 
 2) specify the locations of the header files and the libs to Setup.py or
 patch the module such that the defaults point to your directories. From
 your error message, the current default for the includes seems to be
 /usr/local/mysql/include/mysql

So the new location will be where I extracted the RPM to?

 
 3) You can then delete the directories created in 1a or 1b

So the new python module, the dpapi will be installed in my home
directory?  So when I import it from another script I would just
append my home directory to the sys.path first to use it?
 
 Daniel
 --
 http://mail.python.org/mailman/listinfo/python-list 

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


Re: MySQLDBAPI

2005-06-14 Thread =?ISO-8859-1?Q?Gregory_Pi=F1ero?=
While waiting for answers to the above questions, I went ahead and
tried the following:

1. Downloaded the RPM for the server's version of MySql:
http://downloads.mysql.com/archives/mysql-3.23/MySQL-devel-3.23.57-1.i386.rpm

2. Copy file to server, and extract to a new folder i made called rpmmysql:
[EMAIL PROTECTED] gpinero]$ cd rpmmysql/
[EMAIL PROTECTED] rpmmysql]$ rpm2cpio
/home/gpinero/MySQL-devel-3.23.56-1.i386.rpm | cpio -d -i
3936 blocks
[EMAIL PROTECTED] rpmmysql]$ ls
usr
[EMAIL PROTECTED] rpmmysql]$ cd usr
[EMAIL PROTECTED] usr]$ ls
bin  include  lib
[EMAIL PROTECTED] usr]$ cd include/
[EMAIL PROTECTED] include]$ ls
mysql
[EMAIL PROTECTED] include]$ cd mysql
[EMAIL PROTECTED] mysql]$ ls
chardefs.h  m_ctype.hmy_net.h mysql.h  sslopt-case.h
dbug.h  m_string.h   my_no_pthread.h  mysql_version.h  sslopt-longopts.h
errmsg.hmy_config.h  my_pthread.h my_sys.h sslopt-usage.h
history.h   my_global.h  mysql_com.h  raid.h   sslopt-vars.h
keymaps.h   my_list.hmysqld_error.h   readline.h   tilde.h
[EMAIL PROTECTED] mysql]$

3. Edited setup.py to include the new directory.  Here's my whole file
just in case you need it:

#!/usr/bin/env python

\
=
Python interface to MySQL
=

MySQLdb is an interface to the popular MySQL_ database server for
Python.  The design goals are:

- Compliance with Python database API version 2.0 [PEP-0249]_

- Thread-safety

- Thread-friendliness (threads will not block each other) 

MySQL-3.22 through 4.1 and Python-2.3 through 2.4 are currently
supported.

MySQLdb is `Free Software`_.

.. _MySQL: http://www.mysql.com/
.. _`Free Software`: http://www.gnu.org/
.. [PEP-0249] http://www.python.org/peps/pep-0249.html



import os
import sys
from distutils.core import setup
from distutils.extension import Extension

mysqlclient = os.getenv('mysqlclient', 'mysqlclient_r')
mysqlstatic = eval(os.getenv('mysqlstatic', 'False'))
embedded_server = (mysqlclient == 'mysqld')

name = MySQL-%s % os.path.basename(sys.executable)
if embedded_server:
name = name + -embedded
version = 1.2.1c3

extra_objects = []

if sys.platform == win32:
mysqlroot = os.getenv('mysqlroot', None)
if mysqlroot is None:
print You need to set the environment variable mysqlroot!
print This should be the path to your MySQL installation.
print Probably C:\Program Files\MySQL 4.1\ or something like that.
sys.exit(1)

include_dirs = [os.path.join(mysqlroot, include)]
library_dirs = [os.path.join(mysqlroot, libs)]
libraries = ['zlib', 'msvcrt', 'libcmt', 'wsock32', 'advapi32']
if mysqlstatic:
extra_objects.append(os.path.join(
library_dirs[0], mysqlclient+'.lib'))
else:
libraries.append(mysqlclient)

else:

def config(what):
from os import popen
f = popen(mysql_config --%s % what)
data = f.read().strip().split()
if f.close(): data = []
return data

# This dequote() business is required for some older versions
# of mysql_config

def dequote(s):
if (s[0] == ' or s[0] == '') and (s[0] == s[-1]):
s = s[1:-1]
return s

include_dirs = [ dequote(i[2:]) for i in config('include') if
i.startswith('-i') ]
#include_dirs.append('/usr/local/mysql/include/mysql')
#include_dirs=['/usr/local/mysql/include/mysql']

if mysqlclient == mysqlclient:
libs = config(libs)
elif mysqlclient == mysqlclient_r:
libs = config(libs_r)
elif mysqlclient == mysqld:
libs = config(embedded)
library_dirs = [ dequote(i[2:]) for i in libs if i.startswith(-L) ]
libraries = [ dequote(i[2:]) for i in libs if i.startswith(-l) ]

# Workaround for a pre-4.1.9 bug
if z not in libraries:
libraries.append(z)

extra_compile_args = config(cflags)

if mysqlstatic:
extra_objects.append(os.path.join(
library_dirs[0],'lib%s.a' % mysqlclient))
else:
libraries.append(mysqlclient)


classifiers = 
Development Status :: 5 - Production/Stable
Environment :: Other Environment
License :: OSI Approved :: GNU General Public License (GPL)
Operating System :: MacOS :: MacOS X
Operating System :: Microsoft :: Windows :: Windows NT/2000
Operating System :: OS Independent
Operating System :: POSIX
Operating System :: POSIX :: Linux
Operating System :: Unix
Programming Language :: C
Programming Language :: Python
Topic :: Database
Topic :: Database :: Database Engines/Servers


metadata = {
'name': name,
'version': version,
'description': Python interface to MySQL,
'long_description': __doc__,
'author': Andy Dustman,
'author_email': [EMAIL PROTECTED],
'license': GPL,
'platforms': ALL,
'url': http://sourceforge.net/projects/mysql-python;,
'download_url': http://prdownloads.sourceforge.net/mysql-python/; \
MySQL-python-%s.tar.gz % 

Re: MySQLDBAPI

2005-06-14 Thread =?ISO-8859-1?Q?Gregory_Pi=F1ero?=
The closest thing I found was libmysqlclient.a in
/home/gpinero/rpmmysql/usr/lib/mysql/

I added that path to my library_dir in setup.py but I still get the
same error message when I do python2.4 setup.py build

I really appriciate your help.  I really want to start web development
in python.

Thanks,

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


Re: MySQLDBAPI

2005-06-14 Thread =?ISO-8859-1?Q?Gregory_Pi=F1ero?=
Here's a list of all the files from the RPM extraction, maybe that helps too?


[EMAIL PROTECTED] rpmmysql]$ dir -R
.:
usr

./usr:
bin  include  lib

./usr/bin:
comp_err  mysql_config

./usr/include:
mysql

./usr/include/mysql:
chardefs.h  m_ctype.hmy_net.h mysql.h  sslopt-case.h
dbug.h  m_string.h   my_no_pthread.h  mysql_version.h  sslopt-longopts.h
errmsg.hmy_config.h  my_pthread.h my_sys.h sslopt-usage.h
history.h   my_global.h  mysql_com.h  raid.h   sslopt-vars.h
keymaps.h   my_list.hmysqld_error.h   readline.h   tilde.h

./usr/lib:
mysql

./usr/lib/mysql:
libdbug.a  libmerge.a   libmyisammrg.alibmystrings.a  libnisam.a
libheap.a  libmyisam.a  libmysqlclient.a  libmysys.a
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MySQLDBAPI

2005-06-14 Thread =?ISO-8859-1?Q?Gregory_Pi=F1ero?=
One other note, the few searches I've made that seem somewhat relevant
talk about turning off something thread-safe?  Is this something I can
try even though I have very limited permissions on the server?


On 6/14/05, Gregory Piñero [EMAIL PROTECTED] wrote:
 Here's a list of all the files from the RPM extraction, maybe that helps too?
 
 
 [EMAIL PROTECTED] rpmmysql]$ dir -R
 .:
 usr
 
 ./usr:
 bin  include  lib
 
 ./usr/bin:
 comp_err  mysql_config
 
 ./usr/include:
 mysql
 
 ./usr/include/mysql:
 chardefs.h  m_ctype.hmy_net.h mysql.h  sslopt-case.h
 dbug.h  m_string.h   my_no_pthread.h  mysql_version.h  sslopt-longopts.h
 errmsg.hmy_config.h  my_pthread.h my_sys.h sslopt-usage.h
 history.h   my_global.h  mysql_com.h  raid.h   sslopt-vars.h
 keymaps.h   my_list.hmysqld_error.h   readline.h   tilde.h
 
 ./usr/lib:
 mysql
 
 ./usr/lib/mysql:
 libdbug.a  libmerge.a   libmyisammrg.alibmystrings.a  libnisam.a
 libheap.a  libmyisam.a  libmysqlclient.a  libmysys.a

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


Controlling assignation

2005-06-13 Thread =?ISO-8859-1?Q?Xavier_D=E9coret?=
I would like to know if there is for python's classes an equivalent of 
the operator= that can be overidden.

Let's say I have
  a=A()
and I want to write
  a=5
and I want this to change some internal value of a instead of making a 
point to a new object (an int 5)

In other word, I would like to be able to use a=5 instead of a.set(5)

Is that possible?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Controlling assignation

2005-06-13 Thread =?ISO-8859-1?Q?Xavier_D=E9coret?=
Xavier Décoret a écrit :
 I would like to know if there is for python's classes an equivalent of 
 the operator= that can be overidden.
 
 Let's say I have
   a=A()
 and I want to write
   a=5
 and I want this to change some internal value of a instead of making a 
 point to a new object (an int 5)
 
 In other word, I would like to be able to use a=5 instead of a.set(5)
 
 Is that possible?

Thanks anybody for the answers. It confirms what I understood of Python.
What I wanted to do is something like this:

def change(x,v):
x = v

class A(object):
def __init__(self,v):
self.x = v

a = A(3)
print a.x  # displays 3
change(a.x,4)
print a.x  # still displays 3


It may seem weird, but I ensure there is a reason for doing this. In C++ 
(the language I am mot familiar with), I could define f to take a 
pointer to member function of a class, a pointer and a value and achieve 
what I want. In python, I cannot that way becauswe when change(a.x,4) is 
executed, a.x is replaced by ist value (returned by __getattribute__).

Finally, here is how I hold the situation:


class Handle:
 def __init__(self,v):
 self.__v = v
 def __call__(self):
 x = self.__v
 while callable(x): x=x()
 return x
 def set(self,v):
 self.__v = v

class HandledProperty(object):
 def __init__(self,name=):
 self.name = name
 def __get__(self,o,t):
 return o.__dict__[self]
 def __set__(self,o,v):
 o.__dict__[self] = Handle(v)

class A(object):
x = HandledProperty(x)
def __init__(self,v):
self.x = v

def change(x,v):
x.set(v)


a = A(3)
print a.x()  # displays 3 (notice the () in the call)
change(a.x,4)
print a.x()  # still displays 4
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Custom type: PyObject_IS_GC access violation

2005-06-12 Thread =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
Bue Krogh Vedel-Larsen wrote:

 But if I call
 
 SA_PyVector_Type.tp_new = PyType_GenericNew;
 PyType_Ready( SA_PyVector_Type );
 
 then, when Py_Finalize is called, PyObject_IS_GC(op) in visit_decref() in 
 gcmodule.c causes an access violation. If I don't call PyType_Ready, then 
 the access violation doesn't occure, but then the type can't be used...
 
 So, the question is, does anyone have any idea about what could be 
 causing this?

Most likely some code that you haven't shown. Here is the expansion
of PyObject_IS_GC(op)

#define PyObject_IS_GC(o) (PyType_IS_GC((o)-ob_type)  \
((o)-ob_type-tp_is_gc == NULL || (o)-ob_type-tp_is_gc(o)))

so it becomes

PyType_IS_GC(op-type)  (op-ob_type-tp_is_gc==NULL ||
op-ob_type-tp_is_gc(op))

Then, PyType_IS_GC(op-type) becomes

PyType_HasFeature((op-type), Py_TPFLAGS_HAVE_GC)

which in turn becomes

(op-tp_flags  Py_TPFLAGS_HAVE_GC) != 0

So typically, PyObject_IS_GC goes to the type of the object,
which should never crash, and then looks into the flags of
the type, which cannot crash - unless somebody messed with
ob_type of the object, and unless this isn't a Python
object in the first place.

You did not say what kind of object op was in the crash - this
is something you should investigate further. Does it point to
a Python object? If so, what is the type of the Python object?

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


Re: How to use 8bit character sets?

2005-06-12 Thread =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
copx wrote:
 For some reason Python (on Windows) doesn't use the system's default 
 character set and that's a serious problem for me.

I very much doubt this statement: Python does use the system's default
character set on Windows. What makes you think it doesn't?

 Is it possible to tell Python to use an 8bit charset (latin-1 in my case) 
 for textfile and string processing by default?

That is the default.

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


Re: identifying 64-bit Windows from 2.3.5?

2005-06-11 Thread =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
Steven Knight wrote:
 Can some Windows-savvy Pythonista point me to some way to distinguish
 between these two?

I would look at the environment variable PROCESSOR_ARCHITECTURE. On
the Win64 machine I use, its value is IA64.

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


Re: What is different with Python ?

2005-06-11 Thread =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
Philippe C. Martin wrote:
 I apologize in advance for launching this post but I might get enlightment
 somehow (PS: I am _very_ agnostic ;-).
 
 - 1) I do not consider my intelligence/education above average
 - 2) I am very pragmatic
 - 3) I usually move forward when I get the gut feeling I am correct
 - 4) Most likely because of 1), I usually do not manage to fully explain 3)
 when it comes true.
 - 5) I have developed for many years (18) in many different environments,
 languages, and O/S's (including realtime kernels) .
 
 
 Yet for the first time I get (most) of my questions answered by a language I
 did not know 1 year ago.
 
 As I do try to understand concepts when I'm able to, I wish to try and find
 out why Python seems different. 

Unfortunately, you didn't give many examples of what you did for the
last 18 years (except that that also included RT kernels).

So let me guess two aspects:

1. In these 18 years, you got acquainted to a variety of concepts
   in various languages. When dealing with Python, you could easily
   correlate between Python concepts and the ones you are familiar
   with. This is one of Python's strenghts: it tries not to be
   surprising, but builds on what most people consider standard.
   Try import this some time; you may be experiencing the Zen:

   Readability counts.
   ...
   Special cases aren't special enough to break the rules.
   Although practicality beats purity.
   ...
   In the face of ambiguity, refuse the temptation to guess.

2. You may not have dealt with a weakly-typed language before. If
   that is the case, your feeling of something being different
   most likely comes from that difference.

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


Re: Generating HTML from python

2005-06-10 Thread =?ISO-8859-1?Q?Walter_D=F6rwald?=
Cappy2112 wrote:
 I looked at HTMLGen a while ago- I didn't see what the advantage was.
 I wrote soem code similar to the example above, to generate a page..
 It worked out fine.
 
 However, I want to add HTML ouput to many of my other python programs,
 and I don't want to re-write this for each program. So some higher
 level of abastraction is needed, but I don't know how just yet.
 
 HTMLGen is no longer maintained, so I don't know what the best choice
 is.

If you want an alternative to HTMLGen that is still maintained, you 
might want to try XIST (http://www.livinglogic.de/Python/xist)

A few simple examples can be found here:
http://www.livinglogic.de/Python/xist/Examples.html

Bye,
Walter Dörwald
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IMAP Proxy

2005-06-10 Thread =?ISO-8859-1?Q?Tarek_Ziad=E9?=
Alex Verstraeten wrote:

 Tarek Ziadé wrote:

 Hi,

 I want to write a small TCP Server in Python to make an IMAP Proxy for
 post-processing client requests.

 It is not long either complicated but needs to be very robust so...
 maybe someone here has already done such a thing I can use or know where
 i can get it ?

 Cheers,

 Tarek
  

 I wrote one with twisted.. it's quite easy and minimal..
 you can start hooking stuff to it, I only use dataReceived
 as I only need to watch what cmds are imap client sending.

 from twisted.protocols.portforward import ProxyFactory
 from twisted.protocols.portforward import ProxyClientFactory
 from twisted.protocols.portforward import ProxyClient
 from twisted.protocols.portforward import ProxyServer
 from twisted.internet import reactor

 class PS(ProxyServer):
def dataReceived(self, data):
print PS-dataReceived(%s) %repr(data)
ProxyServer.dataReceived(self, data)
 pfactory = ProxyFactory('192.168.1.1',143)
 pfactory.protocol = PS

 reactor.listenTCP(143, pfactory)
 reactor.run()

 this will bind to port 143 and proxy all requests to the real imap
 server at 192.168.1.1, while printing the commands being sent to stdout.
 Here, my proxy runs on different box than imap server... if you need
 to put both of them on same box you'll need to change the port number
 of , either imap server, or imap proxy.

 well..
 hope it helps

Great thank you, it will help me for sure.

Tarek



 Alex


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


XML + SOAP + Webservices

2005-06-09 Thread Johan =?iso-8859-1?Q?Segern=E4s?=
I'm put on building a system in Python and I haven't used either webservices,
SOAP or Python so I'm a bit lost.

This system will require callback functions, should I use Python thru Apache
for this or build my own listening daemon? Use module for Apache or do I make
some kind of CGI script in Python? 

Where do I start? What lib do I use for XML? SOAP? Webservices?

Is there any nice project/tutorial for this so I can give it a taste and try
to estimate how much time I need and stuff.

Help needed. =)

Thanks.


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

Re: XML + SOAP + Webservices

2005-06-09 Thread Johan =?iso-8859-1?Q?Segern=E4s?=
On 2005-06-09 13:21 +0200 or thereabouts, Johan Segernäs wrote:
 I'm put on building a system in Python and I haven't used either webservices,
 SOAP or Python so I'm a bit lost.

Addon:
I will speak to .NET-stuff in the other end, does this create problems?



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

Re: XML + SOAP + Webservices

2005-06-09 Thread Johan =?iso-8859-1?Q?Segern=E4s?=
On 2005-06-09 14:20 +0200 or thereabouts, Diez B. Roggisch wrote:
 a way to pass a server the necessary callback information. It basically 
 consists of the url to talk to. That by the way is no limitation of 

But of course, a little slip in my thoughts.

 Sooo - concluding remarks could be:
   - soap and python - not so good
   - if you can, use some other RPC to interface .NET - like IPython, or 
 win32, or even corba if you can.

Basically, don't write the implementation to talk to the SOAP/WDSL-services
in Python, find something else and this 'something else' produces an XML file
which I then parse with Python?

win32 isn't an option, we only have *nix-boxes around and we plan to stay
that way.

Very good answer btw, thanks alot.



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

Re: MySQLDBAPI

2005-06-09 Thread =?ISO-8859-1?Q?Gregory_Pi=F1ero?=
I didn't see anything about mysql-devel package in the release notes. 
Is that something I can install all to my home directory?

On 6/9/05, deelan [EMAIL PROTECTED] wrote:
 Gregory Piñero wrote:
  Hey guys,
 (...)
 
  My first question is if there is anything built into python as far as
  a Database API that will work with MySQL.  It seems like there should
  be because Python without it is kinda useless for web development.  If
  there is then I'd probably prefer to use that instead.
 
 there is not. mysqldb module is the answer.
 
 (...)
 cd MySQL-python-1.2.0
 python2.4 setup.py install --home=~
 
  running install
  running build
  running build_py
  running build_ext
  building '_mysql' extension
  gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall
  -Wstrict-prototypes -fPIC -I/usr/local/include/python2.4 -c _mysql.c
  -o build/temp.linux-i686-2.4/_mysql.o
  -I'/usr/local/mysql/include/mysql'
  _mysql.c:41:19: mysql.h: No such file or directory
  _mysql.c:42:26: mysqld_error.h: No such file or directory
  _mysql.c:43:20: errmsg.h: No such file or directory
  error: command 'gcc' failed with exit status 1
 
 you need mysql-devel package installed to compile the _mysql extension.
 
 just look a the release notes:
 https://sourceforge.net/project/shownotes.php?group_id=22307release_id=303257
 
 HTH.
 
 --
 deelan, #1 fan of adriana lima!
 http://www.deelan.com/
 
 
 
 
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Knowing the signature of a function

2005-06-08 Thread =?ISO-8859-1?Q?Xavier_D=E9coret?=
Hello,

I have the following code:

def foo(x,y):
pass

How can I query the function object foo to know the number of parameters 
it expects.  I can find it is a function using callable(f), I can find 
some information (listed by dir(foo)) such as the name of the 
function,etc.. but nowhere I can find the number of arguments.

I would like to know wether the function expects one or zero arguments.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Knowing the signature of a function

2005-06-08 Thread =?ISO-8859-1?Q?Xavier_D=E9coret?=
Kent Johnson a écrit :
 Xavier Décoret wrote:
 
 Hello,

 I have the following code:

 def foo(x,y):
 pass

 How can I query the function object foo to know the number of 
 parameters it expects.  I can find it is a function using callable(f), 
 I can find some information (listed by dir(foo)) such as the name of 
 the function,etc.. but nowhere I can find the number of arguments.

 I would like to know wether the function expects one or zero arguments.
 
 
 foo.func_code.co_argcount gives the count of named args. 
 len(foo.func_code.co_varnames) gives the total number of arguments 
 including *args and **kwds args. inspect.getargspec() might also be 
 helpful.
 
 Kent

Thanks.

Now I have the following issue: what if foo is not a function but a 
callable? inspect.getargspec raises an exception.

I have to do something like:


import inspect

def countargs(f):
 if callable(f):
 if inspect.isfunction(f): return len(inspect.getargspec(f)[0])
 return len(inspect.getargspec(f.__call__)[0])-1
 raise ValueError

class foo:
 def __call__(self,a,b):
 pass

def bar(x):
 pass


print countargs(foo)
print countargs(bar)



Is there any better way?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: maybe a bug in python

2005-06-05 Thread =?ISO-8859-1?Q?Tiago_St=FCrmer_Daitx?=
Just as everyone said, use ('a',) instead of ('a'). As Steve said there
are lots of documentation about it. Check the Library Reference at
http://www.python.org/doc/current/lib/typesseq.html#l2h-155 or to make
things more clear you could read the tuples section in the tutorial at
http://docs.python.org/tut/node7.html#SECTION00730

my 2 cents
Regards,
Tiago S Daitx
On 6/5/05, flyaflya [EMAIL PROTECTED] wrote:
  a = {1: (a)}  a[1]'a'why not ('a')? when  a = {1: (((a)))}  a[1]'a'the result is 'a' too,not (((a))).but when use[a] or (a,b),the
tuple is longer than 1, it's no problem.--[http://www.flyaflya.com/]--
http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: any macro-like construct/technique/trick?

2005-06-04 Thread =?iso-8859-1?Q?Fran=E7ois?= Pinard
[Georges JEGO]
 Mac a écrit :
  #  do some stuff
  if debug:
  emit_dbg_obj(DbgObjFoo(a,b,c))

 Assuming your debug functions always return true, you could use:

  assert emit_dbg_obj(DbgObjFoo(a,b,c))

 and have this code executed -or not- depending on the use of -O

Dirty, dirty trick :-).

`assert' is quite useful in its real and genuine purpose.  There is
something heretic in allowing side effects in `assert' statements.  A
few centuries ago, Python programmers doing this were burnt in public,
and this is how Python got forgotten for so long.  (Guido rediscovered
it a dozen years ago, the wise guy attributed all the merit to himself!)

-- 
François Pinard   http://pinard.progiciels-bpi.ca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: any macro-like construct/technique/trick?

2005-06-04 Thread =?iso-8859-1?Q?Fran=E7ois?= Pinard
[Paddy]

 If you still must have something like the c preprocessor
 then unix has m4 (and it seems there is a windows version
 http://gnuwin32.sourceforge.net/packages/m4.htm).

The difficulty of `m4' for Python source is that macro expansions should
be accompanied with proper adjustment of indentation, for adapting to
the context where macros are getting expanded.

René Seindal's `m4' is surprisingly powerful, so maybe that with enough
trickery (I really mean: a _lot_ of trickery), adjustment of indentation
could be possible.  And maybe that a simpler `m4' approach to Python
macro-expansion could be made available through the later pluggin
features which René added to `m4'.  (Yet I do not know if the pluggin
features have been integrated in the `m4' distribution mainstream.)

It would be much easier using `m4' for Python, if there was a way
to invoke it after Python lexer and before further parsing, because
indent and dedent tokens would already been identified.  If this was
possible, `m4' would be a breeze to use as a pre-processor for Python.

Still in this dreaming mode, there would also be one necessary detail
missing for full comfort: that is, the recognition of `#line' like
directives as generated by `m4' so Python tracebacks, for example, would
correctly refer to the Python source lines before macro-expansion.

-- 
François Pinard   http://pinard.progiciels-bpi.ca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: executing a command

2005-06-04 Thread =?ISO-8859-1?Q?Tiago_St=FCrmer_Daitx?=
Hello,When you use one of the os.exec*p fnnctions python looks
for the specified file in the directories refered by
os.environ['PATH']. If and _only_ if your os.enviroment['PATH'] isn't
set then it looks in os.defpath - you can check this at
http://www.python.org/doc/current/lib/os-path.html#l2h-1557So, my advice is that you first try printing your os.environ['PATH']to
check wheter it includes the program that you are calling or not (and
then you will have to include it). In the case that it isn't set, then
check os.defpath.Also, when you use one of the functions
os.exec that requires a path variable to be passed (ie. the ones that
doesn't have 'p' in their names) the path can be relative or absolute,
but it must include the file name (and not only the dir where the file
is).And for each one of these os.exec* functions the first
argument will always be used as the program name (argv[0]), so unless
you a reason to do otherwise, pass the same name as the file that you
are calling.Regards,Tiago S DaitxOn 6/4/05, andrea valle [EMAIL PROTECTED] wrote: Hi to all, I need to run a program from inside python (substantially, algorithmic
 batch processing). I'm on mac osx 10.3.8 with python 2.3 framework and macpython.  Trying to use exec*, I checked references, Brueck  Tanner, and then grab this code from effbot:
  program = python def run(program, *args): os.execvp(program, (program,) +args) print ok  run(python, /Users/apple/Desktop/prova.py)
  Traceback (most recent call last):File pyshell#50, line 1, in -toplevel-run(python, /Users/apple/Desktop/prova.py)File pyshell#49, line 2, in run
os.execvp(program, (program,) +args)File /System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/os.py, line 336, in execvp_execvpe(file, args)
File /System/Library/Frameworks/Python.framework/Versions/2.3/lib/ python2.3/os.py, line 374, in _execvpefunc(fullname, *argrest) OSError: [Errno 45] Operation not supported
  This OSError seems to be consistend with all exec family. What does it mean and how to use exec?  I also tried with. os.system. It works if I invoke python, but it fails (in a way I don't know) when I invoke other programs.
  For example: command = python /Users/apple/Desktop/test.py os.system(command) 0 (test.py write a string in a file. It works)  But with lilypond or with latex I have no output (and in fact it
 doesn't give 0 as result):  command = lilypond /Users/apple/Desktop/test.ly os.system(command) 32512 command = latex /Users/apple/Desktop/test.tex
 os.system(command) 32512  Any help is much appreciated  Thanks a lot  -a-  -- 
http://mail.python.org/mailman/listinfo/python-list 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re:

2005-06-04 Thread =?ISO-8859-1?Q?Tiago_St=FCrmer_Daitx?=
That depends on what using a file means. You could check the thread executing a command (
http://mail.python.org/pipermail/python-list/2005-June/283963.html)
and see if there's something related there, otherwise it would help if
you could post what exactly you are trying to do (execute a file, open
a file, write into a file, etc).

Regards,
Tiago S DaitxOn 6/4/05, Jatinder Singh [EMAIL PROTECTED] wrote:
Hi guysI am working in a complex directory structure. I want to use a file (not .py)which is in some other directory. I couldn't do it.but if I copy the file inthe same directory then it is working fine. Can anybody guide me how and where
to add the path of the file. I have tried it with sys.path but it is not forthat.--Regards,Jatinder Singh" Everyone needs to be loved... especially when they do not deserve it."--
http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Looking for help with a python-mode/pdbtrack/gdb patch

2005-06-04 Thread =?ISO-8859-1?Q?Tiago_St=FCrmer_Daitx?=
Unfortunatly the only tip I can give you is that there's a list for
mode-python in http://mail.python.org/mailman/listinfo/python-mode, but
you probably already know about it.

Regards,
Tiago S DaitxOn 6/4/05, Skip Montanaro [EMAIL PROTECTED] wrote:
Can someone who uses Emacs's python-mode, pdbtrack and gdb take a look atthis simple but ancient patch:
http://sourceforge.net/tracker/index.php?func=detailaid=785816group_id=86916atid=581351As you'll see from the discussion, Barry had problems with it from XEmacsand was thinking of rejecting it way back when.I'd like to resolve it one
way or the other, but I've never used pdb, let alone pdbtrack.Thanks,Skip--http://mail.python.org/mailman/listinfo/python-list

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

Re: Sorted List (binary tree) why no built-in/module?

2005-06-04 Thread =?iso-8859-1?Q?Fran=E7ois?= Pinard
[Alex Stapleton]

 Unless I've totally missed it, there isn't a binary tree/sorted list
 type arrangement in Python.  Sometimes it might be preferable over
 using a list and calling list.sort() all the time ;)

Well, after `some_list.sort()', `some_list' is indeed a sorted list. :-)
You can use the `bisect' module after that for sorted insertion.

Lists can also be used for representing binary trees, and with a bit of
imagination, the `heapq' module might help you at keeping a binary tree
half-sorted.  This is sometimes sufficient for some applications.  Or
else, you have to resort to avl tree modules, available separately!

 On a somewhat unrelated note, does anyone know how python searches
 lists when you do things list list.index(n), is it a binary search, or
 does it just scan the list?

As Python does not know if a list is sorted or not, it cannot binary
search them by default.  But you, as a programmer, know.  Then, the
`bisect' module might be helpful for binary searches.

-- 
François Pinard   http://pinard.progiciels-bpi.ca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Importing and source structure troubles

2005-06-03 Thread =?ISO-8859-1?Q?Tiago_St=FCrmer_Daitx?=
The best way depends on how you have structured your program. From
what you've told I believe that setting the directories like
 dir1
dir2
dir3
 
is a good approach.
 
As for the import errors you're getting, check this section from the tutorial:
http://docs.python.org/tut/node8.html#SECTION00840

It describes how to setup packages in Python - and that's exactly what
you need. You'll see that in order to import dir3 from dir2 you must
import the full name of the package (ie. import dir1.dir3). See the
intra-packages reference
http://docs.python.org/tut/node8.html#SECTION00842 
 

Regards,
Tiago S Daitx
On 6/3/05, Echo [EMAIL PROTECTED] wrote:
  Hello,
  
  I am having trouble with putting the source for a program I am working on in 
 different directories.
  I have the directories set up like this:
  
  dir1
dir2
dir3
  
  I want the source in dir2 to be able to import from the source in dir3(is 
 this possible). I get import errors when I tried doing this.
  
  A less preferred structure that I tried was like this:
  dir1
dir3
  dir2
  
  I thought that this way would work. but this way I get even more import 
 errors. two files in dir2 have a 'from dir3.dir2 import bla' however, in one 
 of the files, I get an import error. any idea why this is??
  
  What is the best way to structure the program I am working on? I have 3 
 groups of source files. One has the files that start the program and some 
 tools. Another group has all the main files. And the last group is just some 
 misc stuff. How would the best way to accomplish this be?
  
 -- 
 -Echo  
 --
 http://mail.python.org/mailman/listinfo/python-list
 

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


Re: compile python in release...

2005-06-03 Thread =?iso-8859-1?Q?Fran=E7ois?= Pinard
[mg]

 My problem is here : all the source files are compiled with the -g
 flag which might be the debug flag. (On the other hand, the option
 -DNDEBUG is defined : it's normal !) Then my question is : Is exist
 a flag/option to run the shell script named 'configure' allowing to
 remove the '-g' flag located in the generated makefile ?

There is no relation between `-g' and `-DNDEBUG', they control different
things.  What people usually do is leaving `-g' for compilation and
linking, but stripping the resulting binary or library at installation
time.

See the documentation of `strip' and the `-s' option of `install'.

-- 
François Pinard   http://pinard.progiciels-bpi.ca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: thread vs GC

2005-06-03 Thread =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
Paul Rubin wrote:
 Any suggestions for the cleanest way to get rid of the thread?

As Jeff explains, it is rather unlikely that GC will collect
primegen objects, since the generating thread holds self as
a local variable.

You should make background_generator have explicit q and
event arguments, and you should signal the event in __del__.
However, this won't terminate the thread, since it still
hangs in .put. So it might be easiest to .read() in __del__
first.

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


Re: Newbie question: Allocation vs references

2005-06-02 Thread Stian =?iso-8859-1?Q?S=F8iland?=
On 2005-06-02 14:43:40, Jan Danielsson wrote:

 a = [ 'Foo', 'Bar' ]
 b = [ 'Boo', 'Far' ]
 q = [ a, b ]

Or, better yet, how do I store a and b in q, and then tell Python
 that I want a and b to point to new lists, without touching the contents
 in q?

There are several ways to create a copy of a list:

a1 = a[:]  # new copy, sliced from 0 to end
a2 = list(a)   # create a new list object out of any sequence
import copy
a3 = copy.copy(a)  # use the copy module


So you could do for example:

q1 = [ list(a), list(b) ]
q2 = [ a[:], b[:] ]
q3 = [ list(x) for x in (a,b)]


Note that the copy module also has a function deepcopy that will make
copies at all levels. So if you had:

q = [a,b]
q1 = copy.deepcopy(q2)


every list in q1, even the inner a and b will be new copies. Note
that non-mutables such as Foo and Bar are NOT copied, but as they
cannot be changed, that doesn't matter.

-- 
Stian Søiland   Work toward win-win situation. Win-lose
Trondheim, Norway   is where you win and the other lose.
http://soiland.no/  Lose-lose and lose-win are left as an
exercise to the reader.  [Limoncelli/Hogan]
Og dette er en ekstra linje 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python 2.4: tarfile tell() and seek() seem to be broeken

2005-06-02 Thread =?iso-8859-1?q?Lars_Gust=E4bel?=
On Wed, 01 Jun 2005 14:58:23 +0200, N. Volbers wrote:

 - subsequent calls of fd.readline() and fd.tell() will yield the correct
 lines but always the same value from fd.tell().  
 
 Is there a mistake on my side or does this need fixing?

This is a bug. Although the pseudo file object's readline() method returns
the file data line-wise, the data is processed block-wise (100 chars)
internally. Therefore, the output of tell() will always return the
position right after the current block if it is used in conjunction with
readline().

Thank you for pointing that out. I'll take care of this getting fixed.

-- 
Lars Gustäbel
[EMAIL PROTECTED]

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


Re: avl tree

2005-06-01 Thread =?utf-8?q?Berthold_H=C3=B6llmann?=
Zunbeltz Izaola [EMAIL PROTECTED] writes:

 On Tue, 31 May 2005 22:40:19 +0200, Berthold Hllmann wrote:

 You can grab it from 
 
   http://starship.python.net/~bhoel/avl-2.1.0.tar.gz
 

 Thanks i will play with it. But i have realize that what i need was
 exactly a binary tree. I haven't used tree yet and i don't know if i 
 can use the avl instaead an ordinary binary tree.
 I have to construct a tree like this

  A

 B  C

  A C A B

 B C   A B   B C   A C


 but i think i can construct a avl using left/right. Am I correct?

The point with AVL trees is, that they are self balancing, If you want
to 'define' the structure of the tree, you have to find another
solution.

Berthold
-- 
[EMAIL PROTECTED] / http://hllmanns.de/
[EMAIL PROTECTED] / http://starship.python.net/crew/bhoel/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: avl tree

2005-05-31 Thread =?utf-8?q?Berthold_H=C3=B6llmann?=
Zunbeltz Izaola [EMAIL PROTECTED] writes:

 On Mon, 30 May 2005 21:13:57 +0200, Berthold Hllmann wrote:

 
 I'm afraid you won't be happy with the code. It's very old and likely
 won't compile. We have an inhouse version of this module which
 compiles and run on Sparc solaris (32 Bit) and linux x86 with Python
 up to 2.4. I fixed some warnigs just today for compilation on Linux
 x86_64, it also seems to work on this platform now. Installation is
 setup.py based. I'm quite sure we once sent patches to Sam Rushing,
 but they never made it into his release. I'll try to publish our
 version the next days. 

 Thanks. I will be looking forward to the release.

You can grab it from 

  http://starship.python.net/~bhoel/avl-2.1.0.tar.gz

Please report any problems to me. I'll do my best to solve them.

Regards,
Berthold
-- 
[EMAIL PROTECTED] / http://hllmanns.de/
[EMAIL PROTECTED] / http://starship.python.net/crew/bhoel/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python 2.5 CVS broken for HP-UX platform?

2005-05-31 Thread =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
mg wrote:
 While trying to compile Python 2.5 from the nighlty CVS image, it raises
 the following errors on HP-UX. This disables me the use of HP-UX for
 some projects:

Please submit patches to sf.net/projects/python.

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


ANN: Version 0.9 of RUR-PLE

2005-05-31 Thread =?ISO-8859-1?Q?Andr=E9_Roberge?=
Version 0.9 of RUR: a Python Learning Environment has been released.
Information about RUR-PLE can be obtained at
http://rur-ple.sourceforge.net

Note that the project website is slightly out of date.

Among the changes in this new version:

***Spanish translation added.*

Changed image for language selection to reflect addition.

Changed directory structure of lessons.

Fixed non-existent file problem when changing language
with unstranslated lesson file open in browser; the
browser will open the default file in the chosen language
instead.

Changed dialogs (beepers to robot and resize world)
to use GridBagSizer for layout as opposed to specific
coordinates.

Added parameter  wx.BUFFER_VIRTUAL_AREA in
dc = wx.BufferedPaintDC(self, self.buffer, wx.BUFFER_VIRTUAL_AREA)
in world_display.py; this is required to get proper scrolling
since wxPython 2.5.4.1.

Added SetFocus() when positioning sizer on Robot: code and learn
page.  This gets rid of the unwanted grey background.

Changed list of beepers that can be placed at an intersection from
0 ... 15, 16, 17, 18, 19, 20  to
0 ... 15, 20, 40, 60, 80, 99.

Removed the from __future__ import division command to the interpreter.
Since this is not likely to be the default version for a *long* time, it 
seems
a better idea to revert to the default behaviour for the interpreter.
TODO: The lesson needs to be updated to reflect this change.

World redrawn immediately after selecting a new language, so that
the words streets and avenues are updated right away.

Corrected tooltip language setting on speed selection slider.

Added possibility to change background colour of robot world
through user program.  This is to be used in the random maze escape lesson.

Changed the 20 robot images so that their background
is transparent.

Removed obsolete self-testing code in various files as well as
redundant import statements.

Fixed problem with seemingly random
invalid world file error.  This occured when
a robot was removed from the world, and an
attempt was made at resetting the world.

Added SetFocus() to WorldGui.OnLeftDown().  Somehow,
the WorldGUI (i.e. robot world) would no longer get focus
as a matter of course when left-clicked.  This meant that it
was no longer possible to position the robot using the cursor keys.
This problem has appeared since I made the switch to
wxPython 2.6.

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