Re: buliding log files

2008-02-26 Thread Thinker
diljeet kaur wrote:
> hi
> im working on pyqt environment
> i want to know how to take log or how to build log files of the output
>
> 
> Looking for last minute shopping deals? Find them fast with Yahoo!
> Search.
> 

Please check module logging.
http://docs.python.org/lib/module-logging.html
It provides facility of system log of UN*X like systems.

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


Re: [Newbie] Is there any method to urlretrieve to a file the html source from a url with "Transfer-encoding": chunked

2008-02-25 Thread Thinker
Aldo Ceccarelli wrote:
> Hello All,
> I apologize for posting a question on this but I could not find a
> complete answer after reading and searching so far:-)
>
> My problem is that I'd like to store the html source of a certain web
> url but when I try via urllib / urllib2 reads or urlretrieve I get
> only a part of the contents (ist type is text/html).
>
> Metainformation associated with the url show that it has a:
>
> Transfer-Encoding: chunked
>
> and this seems the reason why I can get only a part of it.
>   
Please show your code, here.  urllib doesn't always return full content
in one time.  I guess it is the problem.

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


Re: Embedding a literal "\u" in a unicode raw string.

2008-02-25 Thread Thinker
Romano Giannetti wrote:
> Hi,
>
> while writing some LaTeX preprocessing code, I stumbled into this
> problem: (I have a -*- coding: utf-8 -*- line, obviously)
>
> s = ur"añado $\uparrow$"
>
> Which gave an error because the \u escape is interpreted in raw
> unicode strings, too. So I found that the only way to solve this is
>  to write:
>
> s = unicode(r"añado $\uparrow$", "utf-8")
>
> or
>
> s = ur"añado $\u005cuparrow$"
>
> The second one is too ugly to live, while the first is at least
> acceptable; but looking around the Python 3.0 doc, I saw that the
> first one will fail, too.
>
> Am I doing something wrong here or there is another solution for
> this?
>
> Romano
>
The backslash '\' is a meta-char that escapes the string.  You can
escape the char as following string
u"\\u'
insert another '\' before it.


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

Re: AW: Write to a binary file

2007-04-05 Thread Thinker
Grant Edwards wrote:
> On 2007-04-05, Thomi Aurel RUAG A <[EMAIL PROTECTED]> wrote:
>
>   
>> A simplified test programm to compare the function for opening
>> a file i used ("file()") and your suggested "os.open()" showed
>> different behaviour.
>>
>> My simple testprogramm:
>>
>> --- START ---
>> import os
>>
>> msg = chr(0x02) + chr(0x36) + chr(0x00) + chr(0x01) + chr(0x0a) +
>> chr(0xb0) + chr(0x77)
>>
>> f = os.open('/dev/pytest', os.O_RDWR)
>> os.write(f,msg)
>> os.close(f)
>>
>> f = file('/dev/pytest', 'wb')
>> f.write(msg)
>> f.close()
>> --- END ---
>>
>> The "pytest" device is a very simple device-driver which
>> prints out (using "printk()") the buffer delivered to the
>> write function in a hexadecimal format ("Pytest write> [buffer
>> in hex format]").
>>
>> The output was:
>> --- Start ---
>> Pytest write> 02 36 00 01 0a b0 77
>> Pytest write> 02 36 00 01 0a
>> Pytest write> b0 77
>> --- END ---
>> 
>
> I'm surprised that the normal file object's write method does
> that -- especially for a "binary" file.  IMO, it's a bug when a
> binary file object treats 0x0a differently than other byte
> values.  But, using the file object to read/write a device is
> probably not a good idea because of undefined behavior like
> that.  File objects also do their own buffering, which I
> suspect isn't what you want.
>   
Why not try to create a file object with bufsize = 0 ?
for ex:
-
fo = file('/dev/pytest', 'wb', 0)
fo.write()
fo.close()


-- 
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py

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

Re: Make variable global

2007-03-21 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

abcd wrote:
> I have a file, "a.py"
>
> blah = None def go(): global blah blah = 5
>
>> From the python interpreter I try
>
>>>> from a import * blah go() blah
>>>>
>
> ...i was hoping to see "5" get printed out the second time I
> displayed blah, but it doesn't. Now, if I type this same code
> directly into the python interpreter it works as i was hoping.
> what i am missing?
>
> thanks
>
"import" imports bindings between symbols and objects into
the module from another one. When you call a function in another
module, it changes global space of module where it is defined.
The global space of the module, where caller is in, is kept from touched
except accessing through module names.

- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGAZYd1LDUVnWfY8gRAsdNAJ9niVqdGz1aG0NUzN+Ggmk+vnqZSgCfQB9s
SBuV/fWo8lqAytQP/QXQPXE=
=1BiL
-END PGP SIGNATURE-

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

Re: Garbage collection

2007-03-21 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Tom Wright wrote:
> Thinker wrote:
>> How do you know amount of memory used by Python? ps ? top or
>> something?
>
> $ ps up `pidof python2.5` USER PID %CPU %MEM VSZ RSS TTY
> STAT START TIME COMMAND tew24 26275 0.0 11.9 257592 243988
> pts/6 S+ 13:10 0:00 python2.5
>
> "VSZ" is "Virtual Memory Size" (ie. total memory used by the
> application) "RSS" is "Resident Set Size" (ie. non-swapped physical
> memory)
>
>
This is amount of memory allocate by process not Python interpreter.
It is managemed by
malloc() of C library. When you free a block memory by free()
function, it only return
the memory to C library for later use, but C library not always return
the memory to
the kernel.

Since there is a virtual memory for modem OS, inactive memory will be
paged
to pager when more physical memory blocks are need. It don't hurt
much if you have enough
swap space.

What you get from ps command is memory allocated by process, it don't
means
they are used by Python interpreter.

- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGATzJ1LDUVnWfY8gRAjSOAKC3uzoAWBow0VN77srjR5eBF0kXawCcCUYv
0RgdHNHqWMEn2Ap7zQuOFaQ=
=/hWg
-END PGP SIGNATURE-

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

Re: encoding characters

2007-03-21 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Valentina Marotto wrote:
>
>
> The problem is about the insertion data into database.
>
> one of errors is:
>
> exceptions.UnicodeEncodeError: 'ascii' codec can't encode
> characters in position 25-26: ordinal not in range(128)
>
> <http://baghera.crs4.it:8080/sources#tbend> help me! Thanks
More information, please.
For example, what DBMS are used. Snippet run into error!

- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGATYX1LDUVnWfY8gRAtkgAKC9VV4GrraeL9+f3WcHuoUIvZQsLwCg4vPq
qTMx1Rbr5vUGGwmO5hGn/hU=
=zWkT
-END PGP SIGNATURE-

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

Re: Garbage collection

2007-03-21 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Tom Wright wrote:
> Hi all
>
> I suspect I may be missing something vital here, but Python's garbage
> collection doesn't seem to work as I expect it to. Here's a small test
> program which shows the problem on python 2.4 and 2.5:
... skip .
> (at this point, Python is using 252MB)
>
>
> Is there something I've forgotten to do? Why is Python still using such a
> lot of memory?
>
>
> Thanks!
>
How do you know amount of memory used by Python?
ps 、 top or something?

- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGATUI1LDUVnWfY8gRAhy9AKDTA2vZYkF7ZLl9Ufy4i+onVSmWhACfTAOv
PdQn/V1ppnaKAhdrblA3y+0=
=dmnr
-END PGP SIGNATURE-

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

Re: Constructor of object

2007-03-14 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

inline wrote:

> I know it, but i don't want call constructor of parent class - I
> use PyGTK and want to load window from glade file and assign it to
> object, parented gtk.Window:

> #!/usr/bin/env python

> import gtk import gtk.glade

> class HelloWindow (gtk.Window): def __init__(self): xml =
> gtk.glade.XML("hello.glade") xml.signal_autoconnect(self) self =
> xml.get_widget("window")

> window = HelloWindow() window.connect("delete_event",
> gtk.main_quit) window.show_all() gtk.main()

Why don't you just define HelloWindow as a function? It is more simple.
If you want HelloWindow() to return the object from glade, you can
make HelloWindow as a function or
a class with __new__() method, suggested by Sylvain's, that return a
object from glade.

for ex:
def HelloWindow():
..
return xml.get_widget("window")
pass

or
class HelloWindow:
def __init__(self):
pass
def __new__(clz, *args):

return xml.get_widget("window")

- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF+FZH1LDUVnWfY8gRAv/yAKDz6VWmIJkLmQ72UwZLBF/hrHUPPgCePRBq
jSx5PySyDc/pW3SOqZEFM/I=
=T746
-END PGP SIGNATURE-

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

Re: Constructor of object

2007-03-14 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

inline wrote:
> Hello! I want to assign self to object of parent class in
> constructor, like
>
> def my_func(): ... return ParentClass()
>
> class MyClass (ParentClass): def __init__(self): self = my_func()
>
> but it not work, because "object not initialized". What i can do?
>
Do you want to call constructor of super-class to initialize the object?
If it is true, you have following options.

In old style class:
class MyClass(ParentClass):
def __init__(self):
ParentClass.__init__(self)

In new style class:
class MyClass(ParentClass):
def __init__(self):
super(MyClass).__init__(self)

Or
class MyClass(ParentClass):
def __init__(self):
super(MyClass, self).__init__()

- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF+Dls1LDUVnWfY8gRAvDaAKDVmX8LmuWUdJ4eVil7l//rjCQZLQCg8dO8
Y77CL1ikmtdl6S3HD04GWiA=
=mvSe
-END PGP SIGNATURE-

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

Re: getting user id (from an arbitrary sys user)

2007-03-14 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Gerardo Herzig wrote:
> hi all. What i need to know is if there is some function like
> os.getuid(), but taking an argument (the username, off course), so i can
> do getuid('myuser')
>
> Thanks you dudes!
>
> Gerardo
Please refer http://docs.python.org/lib/module-pwd.html for pwd module.

- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF+Dfv1LDUVnWfY8gRAkfkAKDydeZwxvb1tK+Ms5xE9xWfetNtLACg5xi3
yAJvjodjdL20vU32MVZsLDk=
=iRUm
-END PGP SIGNATURE-

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

Re: Starting an external, independent process from a script

2007-03-12 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Henrik Lied wrote:
> Hi there!
>
>
> So - I want to spawn a new system process. I need some good
> pointers on how to do this right.
>
> Any input? :-)
>
> Thanks a lot in advance!
>
You can try os.spawnl().
The url is http://docs.python.org/lib/os-process.html


- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF9jFe1LDUVnWfY8gRArO/AKDaJaHfrAluc0euEqPn/NN2J2tXsgCgye/D
ujNCylOGx3P/yC0UZc5oXHc=
=yRuY
-END PGP SIGNATURE-

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

Re: Starting Python... some questions

2007-03-12 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

[EMAIL PROTECTED] wrote:
> I started using Python a couple of days ago - here are a few
> questions:
>
> * Doesn't the __main__() method automatically execute when I run my
> python program?
> * Only when I do an import of my test.py file within python and then
> run test.__main__() I can see where my bugs are. Is this correct?
> (right now this is my only way of running my python program and see
> where I have problems)
> * Once I've done an import and then I wish to make a change to the
> file I've imported I have to quit Python, restart and import that
> module again in order for the module to be refreshed. Is there no "re-
> import" ?
> * Finally, could someone tell me why I'm having problems with the
> small module below?
> - Python pretends I provide chassis_id() with three parameters, even
> though I clearly only provide it with two - why?
No, Python is executing a module. You should explicit call __main__()
at top scope of
your module. For ex.

if __name__ == '__main__':
__main__()

This snippet calls __main__() when the module is executed directly,
but not imported as a module.

Once a module had been imported, you should invoke reload() function
to reload it from filesystem.


- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF9i/j1LDUVnWfY8gRAgidAKCxHUWf/XTuT8fRQmeL3hnsO4fohQCgt27R
jCNoz4hgp2CxD7H5HPwkfgM=
=4g/m
-END PGP SIGNATURE-

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

Re: Importing binary modules

2007-03-01 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


> Well, unfortunately I don't have access to the binary like that. It
> is given me, I just wanted to use it the way it was compiled. What
> could be done then?
You have better set LD_LIBRARY_PATH environment variable, or use
ldconfig (plz, man ldconfig)
to add the directory, where you shared object is in, to the search
path of dynamic linker.

- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF5uWt1LDUVnWfY8gRAs52AKDLkGkNaPo2NgjdjFelNOx5KWG0KQCfT1RN
l6WqAWcutwPtmJPleSdkrr4=
=Ov/a
-END PGP SIGNATURE-

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

Re: Importing binary modules

2007-03-01 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

[EMAIL PROTECTED] wrote:
cut ..
>
> The problem appears when libMyNewModule.so depends on another
> library, say libfoo.so, which sits also in /my/module/dir. In that
> case, '/my/ module/dir', needs to be preset in the LD_LIBRARY_PATH
> *before* the python interpreter is set.
>
> In this case, the snippet of code above will not work as one would
> expect. It will normally give an ImportError saying it cannot find
> libfoo.so. That happens, apparently, because the dynamic linker
> cannot rescan LD_LIBRARY_PATH after the python interpreter has
> started.
Since you create a new module, you should try to link your module with
- -rpath-link option.
You can specify a path searched by linker when finding shared object
required.



- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF5rcp1LDUVnWfY8gRAmLcAKCobvo06x84L0pj66amTBspTJ9nUwCg5sA+
MP7tLF/i8zqoZHl5Fxw2YsQ=
=BNQy
-END PGP SIGNATURE-

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

Re: spawnl and waitpid

2007-02-27 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

[EMAIL PROTECTED] wrote:
> On 27 f憝, 18:54, Thinker <[EMAIL PROTECTED]> wrote:

> hello

> ha ok...

> i tried this one and the browser don't write the message at once...
> I have alos tried with thread and have the same result... :(

Does child-process terminate it-self in a very short time ?
It can be a race condition, here.
You can try to sleep for a while in child-process to make sure parent
being executed. Parent process may not schedule to run immediately
after spawn. And, you can print some thing before os.spawnl() to make
sure that message can be delivered successfully.


- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF5Hkp1LDUVnWfY8gRAtDdAKCKy8/ap5VJvZV14nhSCWYfLZdyYACffJ+Y
0sHMgyaQBmsOMwq/rxEvm1Q=
=qjTU
-END PGP SIGNATURE-

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

Re: spawnl and waitpid

2007-02-27 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

[EMAIL PROTECTED] wrote:
> i have tried as you said (cf bellow) and same result... is there
> any link which explain how a server Web read script and send the
> answer ?
> -
> pid = os.spawnl(os.P_NOWAIT,"c:\\python25\
> \python.exe","python","Main.py")

print 'please wait...'

> ret = os.waitpid(pid,0)

You have missed my idea.
Since os.waitpid will be blocked, you should print your message before
calling os.waitpid().


- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF5HA61LDUVnWfY8gRAu8sAJ4n1dogsw7RzTxH8Ke3xnNX6gXnRQCeMOKf
/dsGHttcJc/KGpx414I7rxw=
=E3o7
-END PGP SIGNATURE-

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

Re: spawnl and waitpid

2007-02-27 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

[EMAIL PROTECTED] wrote:
> On 27 f憝, 11:28, Thinker <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
>>>> hello, I run a python cgi script under Apache... and while
>>>> the script is running i want to display a "please wait"
>>>> message until the script finish. I have tried to do this but
>>>> the "please wait" message appears at the script end (which is
>>>> useless at this time! )
> You should flush sys.stdout after you print messages, or the
> message will keep in buffer untill buffer is full or process
> terminated.
>

> Hello

> thanks for answering i have flush like this but same result .. the
> server wait until the end...

> pid = os.spawnl(os.P_NOWAIT,"c:\\python25\
> \python.exe","python","Main.py") sys.stdout.flush() ret =
> os.waitpid(pid,0)
Your program will be blocked here until child process being terminated.
You should print your messages before this line.

> if ( ret[1] != 0): print """ wait %i """ %ret[1]
> sys.stdout.flush() else: print """ end %i """ %ret[1]
> sys.stdout.flush()




- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF5BWS1LDUVnWfY8gRAkp8AKCAcTKi/MO6sfkGBBEcMjfpH42O1wCeN14I
0AZ83oVacK0hKik4YC/jfCA=
=3h7d
-END PGP SIGNATURE-

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

Re: spawnl and waitpid

2007-02-27 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

[EMAIL PROTECTED] wrote:
> hello,
>
> I run a python cgi script under Apache...
>
> and while the script is running i want to display a "please wait"
> message until the script finish.
>
> I have tried to do this but the "please wait" message appears at
> the script end (which is useless at this time! )
>
You should flush sys.stdout after you print messages, or
the message will keep in buffer untill buffer is full or process
terminated.


- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF5Afi1LDUVnWfY8gRAgaoAJ9fccAjo00QupE7SRFqgbmOUGZMugCgjvdH
cFoxm+jiZiIpKOfd+fHCt/M=
=9COv
-END PGP SIGNATURE-

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

Re: SystemError: new style getargs format but argument is not a tuple

2007-02-26 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

zefciu wrote:
> Thinker wrote:
>
>> Since PyArg_ParseTuple() is supposed to parse arguments, I
>> recommand you to use PyTuple_GetItem() or PyTuple_GET_ITEM().
>
> Ok. Now I do it this way:
>
> c_real = PyFloat_AsDouble(PyTuple_GetItem(coord,0)); c_imag =
> PyFloat_AsDouble(PyTuple_GetItem(coord,1));
>
> And it worked... once. The problem is really funny - in the
> interactive the function fails every second time.
>
>>>> mandelpixel((1.5, 1.5), 9, 2.2)
> args parsed coord parsed ii3
>>>> mandelpixel((1.5, 1.5), 9, 2.2)
> TypeError: bad argument type for built-in operation
I guess it is caused by ill handling reference count of coord.
You should call Py_INCREF() to get a reference since it is borrowed
from PyArg_ParseTuple().
You can find more information at http://docs.python.org/ext/refcounts.html

- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF4yuP1LDUVnWfY8gRAqOmAJ0SaIwpnRk/GZYm2Z5nnC7xH7EYKwCgjz8o
0Z/S7i5PULQMeAFI7U/Cy5I=
=4C3l
-END PGP SIGNATURE-

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

Re: SystemError: new style getargs format but argument is not a tuple

2007-02-26 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

zefciu wrote:
> Thinker wrote:
>
>> You can add some printf() to throw out messages to make sure
>> where the program stop at. If you can compile the module with
>> debug information and use gdb to backtrace dump file, it would be
>> useful.
>
> Did it. The arguments are parsed, but the coord tuple isn't. But
> can PyArg_ParseTuple be used to tuples other than function
> arguments? If not, what should I use?
Since PyArg_ParseTuple() is supposed to parse arguments, I recommand you
to use PyTuple_GetItem() or PyTuple_GET_ITEM(). You can find more
functions
at http://docs.python.org/api/genindex.html .

- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF4xyq1LDUVnWfY8gRAilNAKDFTKwahXpuxFImhR57Yw5efAGP1wCfR/qU
o774g2YB5gMBLrUa9YltDSQ=
=/tWC
-END PGP SIGNATURE-

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

Re: SystemError: new style getargs format but argument is not a tuple

2007-02-26 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

zefciu wrote:
> Thinker wrote:
>
>> It should be "PyObject *coord;" . Maybe, it is what is wrong with
>> your program!
>>
>>
> Should it? The gcc shows me a warning then:
>
> warning: 'coord' is used uninitialized in this function
>
> and during the execution I get the same error *plus* a segfault.
>
> zefciu
Yes! Please refer http://docs.python.org/api/arg-parsing.html#l2h-210
And your second PyArg_ParseTuple() call, should not make a reference
on coord.
It should be PyArg_ParseTuple(coord, ...) since you declare coord as a
pointer.
You can add some printf() to throw out messages to make sure where the
program stop at.
If you can compile the module with debug information and use gdb to
backtrace dump file,
it would be useful.

- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF4xaG1LDUVnWfY8gRAsW7AKC7D3oZ8p8iWVFcBvkiVwMSrG1oNwCg36ym
e1Fa0AO3KzSD5FcYs0LK7P4=
=kYLW
-END PGP SIGNATURE-

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

Re: SystemError: new style getargs format but argument is not a tuple

2007-02-26 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

zefciu wrote:
> I am trying to embed a c function in my python script for a first
> time. When I try to call it I get an error
>
> SystemError: new style getargs format but argument is not a tuple
>
> Guido said on some mailing list, that it is probably an effect of
> the lack of METH_VARARGS in the functions' array, but it's ok in my
> source code. Here is the full code:
>
> #include 
>
> static PyObject * mandelpixel(PyObject *self, PyObject *args) {
> double z_real = 0, z_imag = 0, z_real2 = 0, z_imag2 = 0, c_real,
> c_imag, bailoutsquare; int iteration_number; register int i;
> PyObject coord;
It should be "PyObject *coord;" .
Maybe, it is what is wrong with your program!

- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF4xDz1LDUVnWfY8gRAmAAAJ9FJPqGyeI0InxrcvdNXHtGMXWK1wCg570r
z3hcYDsjmqRp4BnpEFjbDy0=
=REQM
-END PGP SIGNATURE-

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

Re: Interactive os.environ vs. os.environ in script

2007-02-26 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

[EMAIL PROTECTED] wrote:
>
> OK then I have to reformulate my question. :)
>
> In my script I have a line with
>
> os.environ["LD_LIBRARY_PATH"]='/path/Linux/rh_linux'
>
> but this line didn't work. But when I set this environment variable
> in Linux shell it works. Here is a small example.
>
>> python shrink_bs_070226.py
> Traceback (most recent call last): File "shrink_bs_070226.py", line
> 25, in ? from qt import * File
> "/path/Linux/python/rh_linux/lib/python2.2/site-packages/ qt.py",
> line 46, in ? import libsip ImportError: libadamsqt.so: cannot open
> shared object file: No such file or directory
ld-elf.so reads environment variables when it was loaded.
It never reads environment variables again!
That you setting environment in the process does not make link-editor
to re-read environment variable and take effect.

To resolve the problem, you can try to add the path to sys.path.

- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF4w6H1LDUVnWfY8gRAoI0AKCLikYsFU2N6aaOZFDd1L2KY8DjqACg3QQn
KsEEcrvpw1CktEkVCKe/ojk=
=EQG6
-END PGP SIGNATURE-

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

Re: SystemError: new style getargs format but argument is not a tuple

2007-02-26 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

zefciu wrote:
> I am trying to embed a c function in my python script for a first
> time. When I try to call it I get an error
>
> SystemError: new style getargs format but argument is not a tuple
>
> Guido said on some mailing list, that it is probably an effect of
> the lack of METH_VARARGS in the functions' array, but it's ok in my
> source code. Here is the full code:
>
> #include 
>
> static PyObject * mandelpixel(PyObject *self, PyObject *args) {
> double z_real = 0, z_imag = 0, z_real2 = 0, z_imag2 = 0, c_real,
> c_imag, bailoutsquare; int iteration_number; register int i;
> PyObject coord; if (!PyArg_ParseTuple(args, "Oid", &coord,
> &iteration_number, &bailoutsquare)) return NULL; if
> (!PyArg_ParseTuple(&coord, "dd", &c_real, &c_imag)) return NULL;
Is coord always tuple?

- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF4wQB1LDUVnWfY8gRAtWsAKCavY85KUtoppRSj0uQTeVnmLu5UwCgyfk1
0c5fkRgKaejDja1YWdKkaTg=
=vMjd
-END PGP SIGNATURE-

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

Re: compile python with sqlite3

2007-02-26 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Nader Emami wrote:
> L.S.,
>
> I have to compile (install) locally Python 2.5, because I don't have
> 'root' permission. Besides I would use 'sqlite3' as a database for
> TurboGears/Django. I have installed 'sqlite3' somewhere on my Linux
> (/path/to/sqlite'). What do I have to do if I want to compile 'Python'
> with 'sqlite3'? I would appreciate if somebody tells me to solve this
> problem.
>
> With regards,
> Nader
You need PySQLite ..


- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF4qf21LDUVnWfY8gRArLiAKCfOG3Jh6xcJJA5ASJZ1zM01mv1BACgml19
DIMioieQqKrHqIUk0mp5kvQ=
=a8si
-END PGP SIGNATURE-

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

Re: subprocess stdin encoding

2007-02-05 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

yc wrote:
> I have a encoding problem during using of subprocess. The input is
> a string with UTF-8 encoding.
>
> the code is:
>
> tokenize =
> subprocess.Popen(tok_command,stdin=subprocess.PIPE,stdout=subprocess.PIPE,close_fds=True,shell=True)
>
>
> (tokenized_text,errs) = tokenize.communicate(t)
>
> the error is: File "/usr/local/python/lib/python2.5/subprocess.py",
> line 651, in communicate return self._communicate(input) File
> "/usr/local/python/lib/python2.5/subprocess.py", line 1115, in
> _communicate bytes_written = os.write(self.stdin.fileno(),
> input[:512]) UnicodeEncodeError: 'ascii' codec can't encode
> character u'\xa9' in position 204: ordinal not in range(128)
>
>
> How I change the default encoding from "ascii" to "utf-8"?
>
> Ying Chen
>
find code like

def setencoding():
"""Set the string encoding used by the Unicode implementation. The
default is 'ascii', but if you're willing to experiment, you can
change this."""
encoding = "ascii" # Default value set by _PyUnicode_Init()
if 0:
# Enable to support locale aware default string encodings.
import locale
loc = locale.getdefaultlocale()
if loc[1]:
encoding = loc[1]

in site.py . and change if 0: to if 1: to enable string encoding.
Now, you can execute python interpreter with LC_CTYPE='UTF-8'.


- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFxykX1LDUVnWfY8gRAseRAKCjAksq22bD2YoOt5IEOIcwOB2KiQCbBvvw
lEccSfEaeOhzAUbvulnDoDk=
=y4Jj
-END PGP SIGNATURE-

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

Re: Conversion of string to integer

2007-01-30 Thread Thinker
jupiter wrote:
> Hi guys,
>
> I have a problem. I have a list which contains strings and numeric. 
> What I want is to compare them in loop, ignore string and create 
> another list of numeric values.
>
> I tried int() and decimal() but without success.
>
> eq of problem is
>
> #hs=string.split(hs)
> hs =["popopopopop","254.25","pojdjdkjdhhjdccc","25452.25"]
>   
hs = [.]

import re
reo = re.compile(r'^[0-9]+(\.[0-9]+)?$')
result = [e for e in hs if reo.match(e)]



-- 
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py

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

Re: Watch log

2007-01-15 Thread Thinker
Salvatore Di Fazio wrote:
> Bjoern Schliessmann ha scritto:
>
>   
>> Why not read the file continuously and only do something if a new
>> line is complete (i. e.  a newline char is detected)?
>> 
>
> How can I read the file continuously?
>
>   
What you want is something like 'tail -f' in linux.
If you look into it's source code, you will find it check file periodically.
When a read() reach the end of the file, read() will return a empty string.
You can try to read data from the file periodically after a EOF.
I think it is what you want.

-- 
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py

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

another SQL implement

2007-01-08 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

hello,

I have implement a SQL command generator for Python. It uses features
and syntax of Python to describe SQL schema & query. Following is a
example:

from pysqlite2 import dbapi2 as sqlite
from pysql import *

#
# define data source
# comprises tables and queries
#
class my_data_src(data_src):
def ds_definition():
class t1(pysql.table):
#
# define table 't1'
#
item = pysql.str_f()
count = pysql.int_f()
pass

class t2(pysql.table):
#
# define table 't2'
#
item = pysql.str_f()
money = pysql.float_f()
pass

#
# define a query 'get_count_and_money_of_item'
#
get_count_and_money_of_item = \
lambda: (t1 * t2) \
.fields(t1.item, t1.count * t2.money - 30) \
.where((t1.item == t2.item) & (t1.item != pysql._q))

return ds_define()
pass

cx = sqlite.connect('test
<http://heaven.branda.to/%7Ethinker/GinGin_CGI.py/show_kw_docs/test>.db')

db = my_data_src(cx) # create a instance of data source

db.init_db() # create tables

db.insert(db.t1, item='foo', count=100)
db.insert(db.t2, item='foo', money=3.2)
db.insert(db.t1, item='boo', count=50)
db.insert(db.t2, item='boo', money=3.0)

db.update(db.t1, count=140, where=~(db.t1.item == 'foo'))

cu = db.get_count_and_money_of_item('foo')
rows = cu.fetchall()
print rows

cu = db.get_count_and_money_of_item('cool')
rows = cu.fetchall()
print rows

db.commit()

pass

This is example code to define database schema and query.
get_count_and_money_of_item is initialized by a lambda expression. It
can also be a function. By inherit class data_src and defining method
ds_definition, my_data_src is acting as a wrapper of a database. It
includes two tables, t1 & t2, and a query,
get_count_and_money_of_item. Instantiate a instance of my_data_src
with a DB connection, you can create tables (init_db), insert records,
update records, and perform queries.

get_count_and_money_of_item = \
lambda: (t1 * t2) \
.fields(t1.item, t1.count * t2.money - 30) \
.where((t1.item == t2.item) & (t1.item != pysql._q))

(t1 * t2) means join tables t1 & t2, you can specify fields to be
return by query with *.fields(...). *.where() is just like WHERE
expression in SQL. get_count_and_money_of_item comprises a
free-variable; pysql._q stands as a free-variable waiting for caller
specified as parameter when calling get_count_and_money_of_item.

cu = db.get_count_and_money_of_item('foo')
rows = cu.fetchall()

It calls get_count_and_money_of_item() with 'foo' for free-variable.
A query returns a cursor defined in DBAPI.

Why another SQL ? Why not SQLObject?
RDBMS provides powerful query language, it provides performance by
reducing traffic between database & application and reducing memory
copy. A OR-mapping made RDBMS weak. DBMS is reduced as a indexed
storage. Relational algebra is so powerful & effective. Why don't
integrate it into Python language?

Downloads:
The implementation depend on pythk, so you need two modules, pysql & pythk
http://master.branda.to/downloads/pysql/pysql-20070108.tar.gz
http://master.branda.to/downloads/pythk/pythk-20070108.tar.gz


- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFoflZ1LDUVnWfY8gRAqw9AJ9UQ5OAOIEWo+ovELQvcKohAkWJtwCfcloq
ecOxlrstOZ77Mr9qPxlkBj0=
=U12Y
-END PGP SIGNATURE-

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

Re: Heap Memory

2006-11-16 Thread Thinker
Gregory Pi鎑ro wrote:
> This computer it was running on has 2GB of RAM and 6GB of virtual
> memory so I really doubt I had used up all of that memory.  I didn't
> watch it the whole time so I can't be sure though.  Any ideas what
> could have been going on there?
>
> -Greg
>   
What is your OS? Maybe you should show out the memory usage of your python
process. In FreeBSD, you should set evironment variable
'MALLOC_OPTIONS=P' to
print out usage of malloc()。Maybe you can find a way, in your system,
to print out usage of the
heap.

-- 
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py

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