read function in python serial

2005-08-11 Thread sinan .
hi i`m developing a program that reads the serial device. i like the
readline() function, but readline() depends on \n character, i want a
similar function that waits for a specific character or string that i
gave like [ETX] (hex03) how can i do this ?
thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


simpli int/str problem

2005-08-12 Thread sinan .
hi all,
i have a string and int values in same dictionary like this
dict = {'str_name': 'etc' , 'int_name' : 112 }
the error occures when do this
SQL = "INSERT INTO (`AH`, `BH` ) VALUES ('" + dict['str_name'] + "',
'" + dict['int_name'] + "')"
cursor.execute(SQL)
python does not accep dict['int_name'] in SQL variable but when i
convert this variable to the str , python accepts but i cannot insert
that into database because database only accept int in `BH `
thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: simpli int/str problem

2005-08-13 Thread sinan .
i thank you all, first of al ill change my dictinary variable name :)
then ill use %s and %d . and thanks for other examples,these examples
enchance my python-way thinking. :)

On 8/12/05, Scott David Daniels <[EMAIL PROTECTED]> wrote:
> Paolino wrote:
> > sinan . wrote:
> >
> >> hi all,
> >> i have a string and int values in same dictionary like this
> >> dict = {'str_name': 'etc' , 'int_name' : 112 }
> Bad idea to call this "dict" -- that is a system-defined name
> for the dictionary type. I'll use "holder" below.
> 
> >> the error occures when do this
> >> SQL = "INSERT INTO (`AH`, `BH` ) VALUES ('" + dict['str_name'] + "',
> >> '" + dict['int_name'] + "')"
> ^^ I suspect this should be:
> SQL = "INSERT INTO TABLENAME(AH, BH) VALUES (...
> >> cursor.execute(SQL)
> >> python does not accep dict['int_name'] in SQL variable but when i
> >> convert this variable to the str , python accepts but i cannot insert
> >> that into database because database only accept int in `BH `
> >> thanks.
> 
> > Try use:
> > SQL = "INSERT INTO (`AH`, `BH` ) VALUES
> > ('%s,%d)"%(dict['str_name'],dict['int_name'])
> This will work, but the DB interface allows you to leave the
> variable formatting to it.  Depending on the parameter style
> your DB interface supports, you may use at least one of:
> 
> cursor.execute("INSERT INTO TABLENAME(AH, BH) VALUES(?, ?)",
>[(holder['str_name'], holder['int_name'])])
> or
> cursor.execute("INSERT INTO TABLENAME(AH, BH) VALUES(:1, :2)",
>[(holder['str_name'], holder['int_name'])])
> ### I think, it _might_ be ...(0, :1)",
> or
> cursor.execute("INSERT INTO TABLENAME(AH, BH) "
>"VALUES(:str_name, :int_name)",
>holder)
> 
> --Scott David Daniels
> [EMAIL PROTECTED]
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


question about threading

2005-08-17 Thread sinan .
hi i have a program that listens socket connection and serial device.
in main program i am creating a socket then calling a class to listen
socket under while 1: ,
class soket(Thread):
def __init__(self):
Thread.__init__(self)
self.host = '127.0.0.1'
self.port = 4500
self.data = ''
try:
self.s = 
socket.socket(socket.AF_INET,socket.SOCK_STREAM)
self.s.bind((self.host,self.port))
self.s.listen(1)
except:
print 'error creating a socket !?!'
def run(self):
Thread.__init__(self)
self.conn, self.addr = self.s.accept()
self.data +=  self.conn.recv(1024)
if not self.data:
pass
else:
return trim(self.data)
self.conn.close()


in main after doing this , 


try:
s = AboutSocket.soket()
s.setDaemon(1)
s.start()
except:
print 'Error occured while using Threaded Socket !?!'

after creating a socket i put bot soket and serial listeners in same while 1:

  while 1:
skcgelen = s.run()
print '\n\nreceived data from socket : ' + skcgelen.__str__()
okunan = serial_readline(ser,'[ETX]')
print '\n\nreceived data : ' + okunan.__str__()
#   ser.write('[ACK]')
#   database_relation(db,okunan)  

this works but when i send message to serial, the program waits for
socket to receive message, if i send a message to a socket it prints
both socket message and serial device message, how can i work them
separetly. i want to see the message from the serial if received
immediately and socket if socket receives immediately. i`ll put these
incoming message to the list dynamically.
note: serial device listener is not threaded.
thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


about accessing mysql

2005-06-10 Thread sinan ,
hi everybody, i have a small mysql connection code

>>> import MySQLdb
>>> db=MySQLdb.Connection(host="localhost",user="root",db="nux")
Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib/python2.3/site-packages/MySQLdb/__init__.py", line
66, in Connect
return Connection(*args, **kwargs)
  File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line
156, in __init__
self.autocommit(0)
_mysql_exceptions.OperationalError: (1193, "Unknown system variable
'AUTOCOMMIT'")
>>>

these command works at my computer but when i want to do in my server,
i get these messages as you seen, my both computer and server have
same python, same MySQLdb module and same database with same
priviliges.also how can i connect to remote database? is that work ?
db=MySQLdb.Connection(host="192.168.0.120",user="root",db="nux")
thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: about accessing mysql

2005-06-10 Thread sinan ,
hi,
my table types are MyISAM both local and server, my code can reach to
my locals mysql but cannot reach when running on server.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: about accessing mysql

2005-06-10 Thread sinan ,
oh my system is debian - sarge with python 2.3
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: about accessing mysql

2005-06-10 Thread sinan ,
i checked innodb support via show variable. they have both same support. 
mysql version is 4.0.24_Debian-5-log
MySQLdb module version is  1.2.1g2
they are same packets in debian.
thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


ncurses programming

2005-09-26 Thread Sinan Nalkaya
hi, i want to use ncurses library in python i`ve found proper library 
for that, PyNcurses.
then i searched for some documentation about ncurses programming, i only 
found that web site ;
http://www.tldp.org/HOWTO/NCURSES-Programming-HOWTO/
this howto is nice but seems to me, this is for experienced ncurses 
programmers who have just migrated to python so i dont understand 
anything from examples and howto. what should i do ? firstly should i 
learn ncurses programmin on C then migrate to python?
thanks.


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


Re: ncurses programming

2005-09-27 Thread Sinan Nalkaya
thank you very much for your suggestions and links, also slang got my 
attention.
thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


button design in curses library

2005-10-12 Thread Sinan Nalkaya
hi,
im using curses library in my program, i need a button. but i cannot 
find anything about it. should i do the button via newwin function with 
bold characters ?
any help will be appreciated
thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


taking x-window screen shot

2005-10-31 Thread Sinan Nalkaya
hi i have some python practice and want to develop tiny prgramme that 
takes screen shots from command line, im using gnome now but my 
programme should support the others especially pure X - window. also i 
want to learn some more about inside when taking screen shots.
thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


get just one character

2005-11-17 Thread Sinan Nalkaya
hello everybody,
how can i just get 1 character ? i`ve done a search but just found 
getch() for windows, i need same for unix and raw_input has any option 
that is not documented ?
thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: get just one character

2005-11-17 Thread Sinan Nalkaya
Paul Watson wrote:

>Sinan Nalkaya wrote:
>  
>
>>hello everybody,
>>how can i just get 1 character ? i`ve done a search but just found 
>>getch() for windows, i need same for unix and raw_input has any option 
>>that is not documented ?
>>thanks.
>>
>>
>
>Please use Google.
>
>http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/134892
>  
>
thanks , i found something in 
http://the.taoofmac.com/static/grimoire.html  also works but i thought 
that there is short way for doing it.
-- 
http://mail.python.org/mailman/listinfo/python-list


need help about time.sleep, timer

2005-11-18 Thread Sinan Nalkaya
hello,
i need a function like that,
wait 5 seconds:
(during wait) do the function
but function waits for keyboard input so if you dont enter any it waits 
forever.
i tried time.sleep() but when i used time.sleep in while, the function 
in while never executed.
then i found something about Timer but couldnt realize any algorithm in 
my mind.
i`ll use the function like remote controller. as you know in remote 
controllers, tv waits you for second number input. if you dont press 
any, executes the first number that you have entered.
thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need help about time.sleep, timer

2005-11-21 Thread Sinan Nalkaya
Dennis Lee Bieber wrote:

>On Fri, 18 Nov 2005 22:45:37 -0500, Peter Hansen <[EMAIL PROTECTED]>
>declaimed the following in comp.lang.python:
>
>  
>
>>It's quite unclear whether the last part, above, is one of your 
>>*requirements*, or a description of a problem you are having with your 
>>current approach.  Do you *want* it to wait forever if you don't enter 
>>anthing?
>>
>>
>>
>   As I understand it, he (?) wants to accumulate characters to be
>passed to a certain function -- but the function is not to be invoked
>until after a time period has expired; the time period resetting on each
>character entered.
>
>   Something I'd do with threads, queues, and sleep...
>
>PSEUDOCODE
>
>thread1:
>   while not Shutdown:
>   ch = getChar()
>   q.put(ch)
>
>
>thread2: #or main
>   while not Shutdown:
>   chars = []
>   while True:
>   sleep(max_interval)
>   if q.empty(): break #no input since start of sleep
>   while not q.empty():#collect all input from sleep
>   chars.append(q.get())
>   inp = "".join(chars)
>   function(inp)
>
>
>
>  
>
i appreciate your comments and ideas. Dennis told exactly what i tried 
to say :), code seems to be fine but during sleep action i think the 
above code does not execute

if q.empty(): break #no input since start of sleep
while not q.empty():
chars.append(q.get())

i need something, while sleeping, executes the function that waits for 
input from keyboard.
i imagined something like that, i have a queu, it both stores the keys 
that pressed and pressing times of these keys, then i`ll proccess these 
times. here is scenario
input : 5
after 10 seconds later input 5 is being proccessed
return back to main function
input : 1
after 5 seconds , other input 5
after 5 more seconds , 15 is being proccessed
Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: termios.tcgetattr(fd) error: (22, 'Invalid argument')

2005-11-21 Thread Sinan Nalkaya
Petr Jakes wrote:

>To provide  some feedback:
>As Grant Edwards  posted in this list, I was running my code inside of
>IDE that replaces sys.stdin with some other. While running the program
>from a shell prompt, everything goes fine. 
>Petr Jakes
>
>  
>
have you tried it with root account ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need help about time.sleep, timer

2005-11-22 Thread Sinan Nalkaya
Bengt Richter wrote:

>On Mon, 21 Nov 2005 10:35:20 +0200, Sinan Nalkaya <[EMAIL PROTECTED]> wrote:
>
>  
>
>>Dennis Lee Bieber wrote:
>>
>>
>>
>>>On Fri, 18 Nov 2005 22:45:37 -0500, Peter Hansen <[EMAIL PROTECTED]>
>>>declaimed the following in comp.lang.python:
>>>
>>> 
>>>
>>>  
>>>
>>>>It's quite unclear whether the last part, above, is one of your 
>>>>*requirements*, or a description of a problem you are having with your 
>>>>current approach.  Do you *want* it to wait forever if you don't enter 
>>>>anthing?
>>>>
>>>>   
>>>>
>>>>
>>>>
>>> As I understand it, he (?) wants to accumulate characters to be
>>>passed to a certain function -- but the function is not to be invoked
>>>until after a time period has expired; the time period resetting on each
>>>character entered.
>>>
>>> Something I'd do with threads, queues, and sleep...
>>>
>>>PSEUDOCODE
>>>
>>>thread1:
>>> while not Shutdown:
>>> ch = getChar()
>>> q.put(ch)
>>>
>>>
>>>thread2: #or main
>>> while not Shutdown:
>>> chars = []
>>> while True:
>>> sleep(max_interval)
>>> if q.empty(): break #no input since start of sleep
>>> while not q.empty():#collect all input from sleep
>>> chars.append(q.get())
>>> inp = "".join(chars)
>>> function(inp)
>>>
>>>
>>>
>>> 
>>>
>>>  
>>>
>>i appreciate your comments and ideas. Dennis told exactly what i tried 
>>to say :), code seems to be fine but during sleep action i think the 
>>above code does not execute
>>
>>if q.empty(): break #no input since start of sleep
>>  while not q.empty():
>>  chars.append(q.get())
>>
>>i need something, while sleeping, executes the function that waits for 
>>input from keyboard.
>>i imagined something like that, i have a queu, it both stores the keys 
>>that pressed and pressing times of these keys, then i`ll proccess these 
>>times. here is scenario
>>input : 5
>>after 10 seconds later input 5 is being proccessed
>>return back to main function
>>input : 1
>>after 5 seconds , other input 5
>>after 5 more seconds , 15 is being proccessed
>>Thanks.
>>
>>
>
>If I understand, you really don't want to sleep, you want to wait a max time 
>of 5 seconds
>for a character. You can get that from a queue.get(True,5) hence, you could 
>try the
>following as a start (untested, and I don't have much experience with python 
>threading,
>so will wait for bug reports ;-)
>
>Note that it uses getch for input, which doesn't echo. (Change to getche if 
>you want echo)
>You can run this from the command line with one arg: the number of seconds you 
>want to
>have the test continue. At the end of that time it will set the Shutdown 
>event, and
>thread2 should empty the queue and wait 5 seconds and then do its last 
>function call and
>see the shutdown event.
>
>< tqinp.py 
>>---
># tqinp.py -- test queued input of unechoed character input until a 5-second 
>delay
>import threading
>import Queue
>import msvcrt
>queue = Queue.Queue(10) # 2 is prob enough for this thing
>Shutdown = threading.Event()
>
>def getChar(): return msvcrt.getch() # blocks
>def function(s): print 'function(%r)'%s
>
>def thread1(q):
>while not Shutdown.isSet():
>ch = getChar()
>q.put(ch)
>
>def thread2(q): #or main
>while not Shutdown.isSet():
>chars = ''
>try:
>while True: chars += q.get(True, 5)
>except Queue.Empty, e:
>print 'No input for 5 seconds. Using %r'%chars
>function(chars)
>
>import time
>def test(trial_time):
>thr1 = threading.Thread(target=thread1, args=(queue,))
>thr1.start()
>thr2 = threading.Thread(target=thread2, args=(queue,))
>thr2.start()
>t0 = time.clock()
>time.sleep(trial_time)
>print 'Ending trial after %s seconds' % (time.clock()-t0)
>Shutdown.set()
>
>if __name__ == '__main__':

re and escape character

2005-09-15 Thread Sinan Nalkaya
i re-format incoming messages like this,
command = re.findall("^\002(.{2})\|.*\003$", response)[0]
it works well but when response comes with escape characters , my 
command variable crashes,
i cannot parse if response variable is like ,
response = '\002AB|TIasdasdasd
asdasdasd
xzczxc
qwewer
werwer|\003'

ps:there must be \002 at the start and \003 at the end.
thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: re and escape character

2005-09-16 Thread Sinan Nalkaya
Thomas Guettler wrote:

>Am Thu, 15 Sep 2005 14:36:38 +0300 schrieb Sinan Nalkaya:
>
>  
>
>>i re-format incoming messages like this,
>>command = re.findall("^\002(.{2})\|.*\003$", response)[0]
>>it works well but when response comes with escape characters , my 
>>command variable crashes,
>>i cannot parse if response variable is like ,
>>response = '\002AB|TIasdasdasd
>>asdasdasd
>>xzczxc
>>qwewer
>>werwer|\003'
>>
>>ps:there must be \002 at the start and \003 at the end.
>>thanks.
>>
>>
>
>Hi,
>
>I don't know what you mean with "escape characters".
>The dot does not match a newline. You  have to use the
>re.DOTALL option if you want this.
>
> HTH,
>   Thomas
>
>  
>
thats exactly what i want, how can i use DOTALL, by doing re.compile ?
thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


make a video from xwd output

2005-12-12 Thread Sinan Nalkaya
hi i want to write a program that makes a video of my desktop, i think that 
can be via return or output xwd functions in X11 lib then through to the mpeg  
video encoding codes, hmm is there an easier solution to this via python?
thanks for your attention.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: make a video from xwd output

2005-12-12 Thread Sinan Nalkaya
On Monday 12 December 2005 03:34 pm, Fredrik Lundh wrote:
> Sinan Nalkaya wrote:
> > hi i want to write a program that makes a video of my desktop, i think
> > that can be via return or output xwd functions in X11 lib then through to
> > the mpeg video encoding codes, hmm is there an easier solution to this
> > via python?
>
> http://www.unixuser.org/~euske/vnc2swf/
>
> ?
>
> 

i didnt try that but it seems ,just makes swf to me.
thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


popen and password entry

2006-06-14 Thread sinan nalkaya
hello, 
i want to use rsync for remote file transfer via popen, but couldnt pass the 
Password yet. 
here`s what i did
cmd = 'rsync -av config [EMAIL PROTECTED]:/tmp/.'
f = os.popen(cmd,'w')
f.write('1234')
#not worked
f.write('1234\n')
#not worked

every time i see "Password:" line, then i tried popen2
st_out, st_in = popen2.popen2(cmd)
st_in.write('1234')
#not worked
st_in.write('1234\n')
#not worked again
i got bored to see "Password:" line every time and did st_out.close() to not 
to see stdout messages from rsync, but even this did not work.
also i tried popen3() function same way.
what should i do?
Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


popen and password entry

2006-06-14 Thread sinan nalkaya
hello, 
i want to use rsync for remote file transfer via popen, but couldnt pass the 
Password yet. 
here`s what i did
cmd = 'rsync -av config [EMAIL PROTECTED]:/tmp/.'
f = os.popen(cmd,'w')
f.write('1234')
#not worked
f.write('1234\n')
#not worked

every time i see "Password:" line, then i tried popen2
st_out, st_in = popen2.popen2(cmd)
st_in.write('1234')
#not worked
st_in.write('1234\n')
#not worked again
i got bored to see "Password:" line every time and did st_out.close() to not 
to see stdout messages from rsync, but even this did not work.
also i tried popen3() function same way.
what should i do?
Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: popen and password entry

2006-06-14 Thread Sinan Nalkaya
hi,i have found expect method for this purpose. i`m trying to use pexpect but following code gives me an something strange as a result.# The CODEimport pexpectcmd = '/usr/bin/rsync config [EMAIL PROTECTED]:/tmp/.'
#cmd = 'ssh [EMAIL PROTECTED]'child = pexpect.spawn(cmd)passwd = 'qwe123'try:    i = child.expect(['Password:','Password: ',pexpect.EOF,pexpect.TIMEOUT])    if i == 0:  
child.sendline(passwd)    elif i == 1:    print 1    elif i == 2:    print 2    elif i == 3:    print 3except EOF: print 'EOF'except TIMEOUT: print 'TIMEOUT'print 'finished'
# The resultfinishedException pexpect.ExceptionPexpect:  in > ignored
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: popen and password entry

2006-06-15 Thread sinan nalkaya
thanks for reply, i add the line you suggested, thats what i get

[EMAIL PROTECTED]:~/tmp/multi_server$ python deneme.py
Password: qwe123
finished
Exception pexpect.ExceptionPexpect:  in > ignored

does rsync may cause a problem while trying to fork-exec ssh ?

> Add "child.logfile = sys.stdout" here and check what's going on.
>
> Ganesan
>
> --
> Ganesan Rajagopal
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: popen and password entry

2006-06-15 Thread sinan nalkaya
i put while True: before top of line, i=child.expect() . it worked, the file 
has gone but also it goes into loop with many EOF result, i tried the 
os.waitpid() function with child.pid but didnt help me. still couldn`t get 
the problem.
thanks for help


On Thursday 15 June 2006 12:04, Ganesan Rajagopal wrote:
> Ah, got it. You didn't wait for the rsync process to complete. Put the body
> of the "try:" in a while loop.
>
> Ganesan
>
> --
> Ganesan Rajagopal
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: popen and password entry

2006-06-15 Thread sinan nalkaya
finally following code works,

import pexpect, sys
cmd = '/usr/bin/rsync config [EMAIL PROTECTED]:/tmp/.'
#cmd = 'ssh [EMAIL PROTECTED]'
child = pexpect.spawn(cmd)
child.logfile = sys.stdout
passwd = 'qwe123'
i = 0
try:
while i == 0:
i = 
child.expect(['Password:','Password: ',pexpect.EOF,pexpect.TIMEOUT])
if i == 0:  child.sendline(passwd)
elif i == 1:print 1
elif i == 2:print 2
elif i == 3:print 3
except EOF: print 'EOF'
except TIMEOUT: print 'TIMEOUT'
-- 
http://mail.python.org/mailman/listinfo/python-list


about spawn flag

2006-01-30 Thread Sinan Nalkaya
hi, i am using os.spawn function, it works well but i need a flag that
allows function return the process id with exit/error code, is there
any or how can i do it, i can replace spawn with fork/exec if
necessary.
thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: about spawn flag

2006-01-31 Thread Sinan Nalkaya
thank you but also i need a pid.also react like an os.P_NOWAIT.
if i summarize,
child proccess immediately returns the pid, if child exits also
returns the exit/error code :)
-- 
http://mail.python.org/mailman/listinfo/python-list


pop line from file

2006-02-15 Thread Sinan Nalkaya
hello all,
i searched and google long long time but couldnt find any result, i
want pop the first line from file, i dont want to read all file
contents because file is being updated from another proccess. even i
couldnt realize its algorithm, thanks for any suggestion
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pop line from file

2006-02-16 Thread Sinan Nalkaya
i am unix platform, now searching for the mkfifo topics.
thank you all.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Go "help" the perl list instead Fredrik Lundh

2006-05-25 Thread A. Sinan Unur
D H <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]:

> You obviously ignored that and invented some argument that he
> posted with malicious intentions.  That better describes most of
> your thousands of annoying posts.

I don't know what describes what you did. What is the point of bringing 
clpmisc into this argument.

Anyway, *PLONK*

Sinan

-- 
A. Sinan Unur <[EMAIL PROTECTED]>
(remove .invalid and reverse each component for email address)
-- 
http://mail.python.org/mailman/listinfo/python-list