[Linux] Detect a key press

2006-10-05 Thread Jia,Lu
Hi all
  I write a program to detect key press,but , why there is a *space*
before the character I typed.??

#!/usr/bin/env python

import sys
import tty
import termios

i = sys.stdin.fileno()
o = sys.stdout.fileno()

backup = termios.tcgetattr(i)

def loop():
while 1:
ch = sys.stdin.read(1)
print "->%s"%ch
if ch == 'q':break

try:
tty.setraw(i)
loop()
finally:
termios.tcsetattr(i, termios.TCSADRAIN, backup)

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


[curses] Instead of window.refresh() or window.redrawwin() ?

2006-10-09 Thread Jia,Lu
Hi all.
 I wrote a program to get key press and echo to the screen at once. But
I found I must use refresh() to let it show in the screen.
 Is there a method which can show charactors at once without refresh()
??

 Thanks

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


Re: A curses-game I need help with.

2006-10-10 Thread Jia Lu

> try:
> import curses
> except ImportError:
> print "Missing the Curses-library."
> print "Please install the curses-library correctly."
> SystemExit
   ~
 Does this work ? Maybe *raise SystemExit* ??

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


Cannot import a module from a variable

2006-10-15 Thread Jia Lu
Hi all:

I try to do things below:
>>>import sys
>>> for i in sys.modules.keys():
import i
Traceback (most recent call last):
  File "", line 2, in 
import i
ImportError: No module named i

But it seems that import donot know what is i ? why?

Thanks/

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


How to convert this list to string?

2006-10-18 Thread Jia Lu
Hi all

 I have a list like:

>>> list
[1, 2, 3]
>>> list[1:]
[2, 3]

I want to get a string "2 3"

>>> str(list[1:])
'[2, 3]'

How can I do that ?

thanks

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


Re: How to convert this list to string?

2006-10-18 Thread Jia Lu
Thank you very much. I memoed all you views.

:)

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


Why I cannot Exit python shell ??

2006-10-22 Thread Jia Lu
Hi all.

  After using python shell (IDLE) for a while, I typed commands below
to exit . But error ocurred.

>>> raise SystemExit

Traceback (most recent call last):
  File "", line 1, in 
raise SystemExit
SystemExit
>>> sys.exit(0)

Traceback (most recent call last):
  File "", line 1, in 
sys.exit(0)
SystemExit: 0
>>> dir()
['__builtins__', '__doc__', '__name__', 'os', 'sys', 'time']

Why??

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


wxPython changed ??

2006-10-29 Thread Jia Lu
Hi all.
 I'm using wxPython 2.6.3.2-2 on FC 6.
 I wrote a demo used 'self.Bind(xx)' but I got an error says:
   " MyFrame instance has no attribute 'Bind' "

 I did that when I used FC 5 and it worked.

 Is new wxPy changed about the Bind method??

thanx

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


Re: How to access file last modified dates on each file in a directory

2006-10-29 Thread Jia Lu

[EMAIL PROTECTED] wrote:
> Greetings,
>
> I am attempting to view all files in a directory and if those files
> have not been modified within the last couple days I will remove them.
> In order to do this I need to look at the file date modied and check
> the date. I know how to look at each file name and I know how to remove
> the file. I just can't figure out how to get access to the date last
> modifed filed.

For this you have some solutions.

1,
import os
import time
time.ctime(os.stat(r"L:\MyDoc\EBook\Python").st_mtime)

2,
os.path.getmtime()

3, in Win32
win32file.GetFileTime
int = GetFileTime(handle, creationTime , accessTime , writeTime )

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


[wxPython] wxFrame don't have Bind attribute ??

2006-10-29 Thread Jia Lu
Hi all
 I am using wxPy 2.6.3.2-2, But when run an application with self.Bind
, I got an error that there is no Bind.

 How can I fix it. thanx

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


Re: wxFrame don't have Bind attribute ??

2006-10-30 Thread Jia Lu

Steve Holden のメッセージ:
> Perhaps you could show us the code that's failing,

the code is :


#!/usr/bin/python -tt

__author__ = "Jia Lu <[EMAIL PROTECTED]>"
__verstion__ = "1.0.0"

import wx

class MyFrame(wx.Frame):
  def __init__(self):
wx.Frame.__init__(self, None, -1, "MyFrame", size=(300,300))
panel = wx.Panel(self, -1)
panel.Bind(wx.EVT_MOTION, self.OnMove)
wx.StaticText(panel, -1, "Pos:", pos=(100,105))
self.posCtrl = wx.TextCtrl(panel, -1, "", pos=(130,100))

  def OnMove(self, event):
pos = event.GetPosition()
self.posCtrl.SetValue("%s, %s" % (pos.x, pos.y))

if __name__ == "__main__":
  app = wx.PySimpleApp()
  frame = MyFrame()
  frame.Show(True)
  app.MainLoop()

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

Re: wxFrame don't have Bind attribute ??

2006-10-30 Thread Jia Lu

Frank Millman のメッセージ:
> This works perfectly for me, using wxPython 2.6.3.2, on both Linux and
> Windows.
>
> What platform are you using?
Yes this works OK for me too on my FedoraCore 5, but cannot work on my
FedoraCore 6...

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

Re: __init__ function problem

2006-11-07 Thread Jia Lu

> In Python, the real constructor is called __new__, >
> Carl Banks

But the code below won't invoke __new__:

[CODE]
class Test:
def __new__(self, value):
print "__new__",value
def __init__(self,value):
print "__init__",value

x = Test("testing")
[/CODE]

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


Re: ANN: wxPython 2.7.2.0

2006-11-08 Thread Jia Lu

Robin Dunn wrote:
> Announcing
> --

Thanx.

But I found wxPy's release speed is too fast that we nearly cannot
catch up with it :)

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


Re: wxFrame don't have Bind attribute ??

2006-11-17 Thread Jia Lu

Franz Steinhaeusler wrote:
> Is it really an instance of wx.Frame?
> What do you get, if you make a "print self" statement?
sovled it
I think it is an installation problem.
I used yum on FC6 to install wxPython 2.6
But after that I got that error.

Now I uninstalled them and did an installation of wxPy 2.7 manully.
It is ok now..

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


[Q]An error with my module in C

2006-10-02 Thread Jia,Lu
hello,all.

  I wrote a module in C as below, BUT msg() method cannot work
allright.

#include 
#include 

static PyObject *Roka_msg(PyObject *self,PyObject *args)
{
printf("Roka Python lib. Version 1.0\n");
}

static PyObject *Roka_func(PyObject *self,PyObject *args)
{
long arg;
if(!PyArg_ParseTuple(args,"l",&arg)){
return NULL;
}
return Py_BuildValue("l",arg*2);
}

//--

static struct PyMethodDef functions[]=
{
{"msg",Roka_msg,METH_VARARGS},
{"func",Roka_func,METH_VARARGS},
{NULL,NULL,0},
};


void initRoka(void)
{
(void)Py_InitModule("Roka",functions);
}
-
python result:
>>>import Roka
>>>Roka.msg()
Roka Python lib. Version 1.0
Segmentation fault

I throw out a Segmentation fault after display my message.
Can anyone tell me why?

thanks.

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


How to get keyboard event in Linux console?

2006-10-03 Thread Jia,Lu
Hi all,
  I want to deal keyboard event in Linux console.
  Example: I Create a deamon at background and when I press F1 key then
print Hello at Console.

  Can python do it? with which module?

  Thanks.

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


How to turn AUTOCOMMIT ON with cx_Oracle

2006-12-01 Thread Jia Lu
Hi all.
 I use cx_Oracle to connect to an Oracle9i DB. And I want to turn on
AUTOCOMMIT function.
 I see that cur.execute("SET AUTOCOMMIT ON") cannot work. Is there any
method to do that ??

 Thanks a lot!

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


Re: How to turn AUTOCOMMIT ON with cx_Oracle

2006-12-01 Thread Jia Lu

Paul McGuire のメッセージ:

> AUTOCOMMIT is a dangerous crutch, beware.  Ok for single record updates, but
> if you need to update 2 records in synch, AUTOCOMMIT leaves you open to
> hard-to-debug bugs (will work ok in development under light load, then fail
> intermittently with concurrent users).

Thanx.
But I am doing an exception test to Servers. So I have to work without
commit, but I need a autocommit environment of DB.

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


How to use MySQL without MySQLdb module

2006-12-06 Thread Jia Lu
Hi all.
 I am using a hosting space with python cgi.
 But this host haven't got MySQLdb installed.

 Is there any methods to connect to Mysql without MySQLdb.
 Or any other DB methods with original python release?

 Thanx

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


Is there any python-twisted tutorial or texts?

2006-12-18 Thread Jia Lu
Hi all
 I want to study twisted of python . But I donot know how to start.
 Any suggistions?

 Thank you

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


Flat DB seeking speed

2007-04-21 Thread Jia Lu
Hello all

 I see there are lots of flat db or db-like modules in the standard
python modules.
 What about the keywords seeking speed of them ?

 (I want to put about 1 articles with 1 IDs, and I can do
searching keywords with them)

 The db-like modules are :
 dbm, gdbm, dbhash,anydbm,
 pickle(cPickle), shelve, marshal

 Any advice? Thank you.

Jia Lu

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


Why canNOT import from a local directory ?

2007-05-18 Thread Jia Lu
Hi all

 I created a folder named *lib* and put a py file *lib.py* in it.
 In the upper folder I created a py file as:


import lib.lib

def main():
"""
__doc__
"""
lib.lib.test()


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


But I got an error :
#.:python main.py
Traceback (most recent call last):
  File "main.py", line 6, in ?
import lib.lib
ImportError: No module named lib.lib

Why ?

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


Re: Why canNOT import from a local directory ?

2007-05-18 Thread Jia Lu

>
> You need to define a file __init__.py in your newly created lib directory.
>
Thank you very much :)


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


Many-to-many pattern possiable?

2007-05-19 Thread Jia Lu
Hi all

 I see dict type can do 1-to-1 pattern, But is there any method to do
1-to-many, many-to-1 and many-to-many pattern ? What about using some
Serialized objects?

Thanks.

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


How to do this in python with regular expressions

2007-05-25 Thread Jia Lu
Hi all

 I'm trying to parsing html with re module.

 html = """
 


DATA1DATA2DATA3DATA4


DATA5DATA6DATA7DATA8


"""

I want to get DATA1-8 from that string.(DATA maybe not english words.)
Can anyone tell me how to do it with regular expression in python?

Thank you very much.

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


Can string be callable as a method ?

2007-05-28 Thread Jia Lu
Hi all
 I tried to scan a directory and __import__ all modules ,

imported module: help
imported module: __init__
imported module: hi
imported module: thanks

and I scaned all methods in them, and put them to a list like:

[['f_chelp', 'f_help'], [], ['f_exclaim', 'f_hi', 'random'],
['f_thanks', 'random']]

But how can I call them from that list??

Thank you.

Jia Lu

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


How to write GUI and event separately in wxPython??

2007-07-29 Thread Jia Lu
HI all

 I am making an application with wxpython.
 But I got a problem when I want to change the display string
according to process status.

 I passed the frame to the processing function and use the
frame.txtobj to change displaying strings.

 I found it is a bad method to do that.
 Can any one tell me how to do that usually?
( How to separate GUI and Control code? )

Thank you.

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


Problem with algorithm

2007-04-12 Thread Jia Lu
Hi all.
 I want to create a large list like:

 ~ 

Is there any good algorithm to do this?

Thanx

Jia Lu

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


Re: Problem with algorithm

2007-04-13 Thread Jia Lu

> for m in test:
> for n in test:
> for o in test:
> for p in test:
> print m+n+o+p

Thanx for your anwser.
But if I consider about a combination of over 26 letter's list just
like:
"abcdefssdzxcvzxcvzcv"
"asllxcvxcbbedfgdfgdg"
.

Need I write 26 for loops to do this?

Thanx

Jia LU

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


Re: Problem with algorithm

2007-04-13 Thread Jia Lu

> If you just expand the length to five million* or so, one of those
> strings will contain all the works of Shakespeare.
Oops, you have this formula in math?

Actually I want to scan a range of network for some certain files.

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


File DB instead of real database?

2007-04-13 Thread Jia Lu
Hello all

 I donot want to use a real DB like MySQL ... But I need something to
save about more than 1000 articles.
 Is there any good ways?

 Thanx

Jia Lu

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


Combinate 2 lists to a dict ?

2007-04-18 Thread Jia Lu
Hi all.

 I have 2 lists,
 a = [1,2,3]
 b = ["ooo","aaa","ppp"]

 What is the fastest way to make a dict like {1:"ooo",2:"aaa",
3:"ppp"} ?

Thanx

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


Combinate 2 lists to a dict ?

2007-04-18 Thread Jia Lu
Hi all.

 I have 2 lists,
 a = [1,2,3]
 b = ["ooo","aaa","ppp"]

 What is the fastest way to make a dict like {1:"ooo",2:"aaa",
3:"ppp"} ?

Thanx

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


Re: Q: Why Python is bad for web from the point of URLs?

2007-01-24 Thread Jia Lu

But you can do capsulation to them.


On 1月24日, 午後7:50, "techtonik" <[EMAIL PROTECTED]> wrote:
> A: Because you need three modules to parse, edit and reassemble query
> string. urlparse, cgi and urllib

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


Can I import a file without file extension .py?

2007-01-31 Thread Jia Lu
Hi all
 I wonder if I can import a file with other file extensions ?

 Can I do that only with python?

 Thank you

Jia Lu

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


Re: Can I import a file without file extension .py?

2007-01-31 Thread Jia Lu
>
> def make_module_from_file(module_name, file_name):
> """ Make a new module object from the code in specified file """
>
> from types import ModuleType
> module = ModuleType(module_name)
>
> module_file = open(file_name, 'r')
> exec module_file in module.__dict__

Thank you very much.
And can you tell me what does " exec module_file in module.__dict__ "
mean?

Thanx

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


Can anyone explain a part of a telnet client code to me..

2007-02-10 Thread Jia Lu
Hello
 I have a program that can telnet to a host.
 But I cannot understand from [for c in data] part, can anyone explain
it to me?
 Thank you very much.

[CODE]


import sys, posix, time
from socket import *

BUFSIZE = 1024

# Telnet protocol characters

IAC  = chr(255) # Interpret as command
DONT = chr(254)
DO   = chr(253)
WONT = chr(252)
WILL = chr(251)

def main():
# Get hostname from param
host = sys.argv[1]
try:
# Get ip from hostname
hostaddr = gethostbyname(host)
except error:
sys.stderr.write(sys.argv[1] + ': bad host name\n')
sys.exit(2)
# Check param[2] as type of protocol
if len(sys.argv) > 2:
servname = sys.argv[2]
else:
# default use telnet
servname = 'telnet'
# If got servname as port num
if '0' <= servname[:1] <= '9':
# cast port num from str to int
port = eval(servname)
else:
try:
# Get port num by service name
port = getservbyname(servname, 'tcp')
except error:
sys.stderr.write(servname + ': bad tcp service name\n')
sys.exit(2)
# Create a tcp socket
s = socket(AF_INET, SOCK_STREAM)
# Connect to server
try:
s.connect((host, port))
except error, msg:
sys.stderr.write('connect failed: ' + repr(msg) + '\n')
sys.exit(1)
# Fork a proccess
pid = posix.fork()
#
if pid == 0:
# child -- read stdin, write socket
while 1:
line = sys.stdin.readline()
s.send(line)
else:
# parent -- read socket, write stdout
iac = 0 # Interpret next char as command
opt = ''# Interpret next char as option
while 1:
data = s.recv(BUFSIZE)
# if recv nothing then Exit program
if not data:
# EOF; kill child and exit
sys.stderr.write( '(Closed by remote host)\n')
# Call posix function kill and send signal 9 to child
posix.kill(pid, 9)
sys.exit(1)
cleandata = ''
for c in data:
if opt:
print ord(c)
s.send(opt + c)
opt = ''
elif iac:
iac = 0
if c == IAC:
cleandata = cleandata + c
elif c in (DO, DONT):
if c == DO: print '(DO)',
else: print '(DONT)',
opt = IAC + WONT
elif c in (WILL, WONT):
if c == WILL: print '(WILL)',
else: print '(WONT)',
opt = IAC + DONT
else:
print '(command)', ord(c)
elif c == IAC:
iac = 1
print '(IAC)',
else:
cleandata = cleandata + c
sys.stdout.write(cleandata)
sys.stdout.flush()


try:
main()
except KeyboardInterrupt:
pass

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