Re: [Tutor] nutshell review

2006-02-10 Thread nephish
yeah, one of the guys that posted earlier mentioned late feb as a
release of the new one. i think i am going to go ahead and get the
cookbook now, and then pick up the new nutshell later.
sk

On Fri, 2006-02-10 at 09:56 -0600, [EMAIL PROTECTED] wrote:
 Isn't there supposed to be a new edition of the Nutshell book coming
 out?  I was kinda hanging back for that one...
 Carl Badgley
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] nutshell review

2006-02-09 Thread nephish
lo there, 
i know this comes up from time to time. i am considering buying 'python
in a nutshell'. All the reviews i have read for it are very good. But it
only covers up to python 2.2. i use 2.3 at work, and tinker with 2.4 at
home. As good a reference as it is, is it too dated to be that good
still ? i have 'Learning Python' and 'Programming Python'. Learning is
awesome for me, Programming is a bit over my head. 
any suggestions?

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] nutshell review

2006-02-09 Thread nephish
thanks man, ill check out cookbook  see what its all about, too.

sk


On Thu, 2006-02-09 at 22:22 -0400, Andre Roberge wrote:
 On 2/9/06, nephish [EMAIL PROTECTED] wrote:
  lo there,
  i know this comes up from time to time. i am considering buying 'python
  in a nutshell'. All the reviews i have read for it are very good. But it
  only covers up to python 2.2. i use 2.3 at work, and tinker with 2.4 at
  home. As good a reference as it is, is it too dated to be that good
  still ? i have 'Learning Python' and 'Programming Python'. Learning is
  awesome for me, Programming is a bit over my head.
  any suggestions?
 
 I own about 10 Python books including Learning Python, Programming
 Python and Python in a Nutshell.  Of these three, Python in a Nutshell
 is the one I find the most useful.  The Python Cookbook (2nd ed) is my
 other favourite.  Your mileage may vary...
 
 André

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] nutshell review

2006-02-09 Thread nephish
Sounds like its worth the wait. thanks all. 

shawn

On Thu, 2006-02-09 at 19:02 -0800, Terry Carroll wrote:
 On Fri, 10 Feb 2006, nephish wrote:
 
  i know this comes up from time to time. i am considering buying 'python
  in a nutshell'. All the reviews i have read for it are very good. But it
  only covers up to python 2.2. i use 2.3 at work, and tinker with 2.4 at
  home. As good a reference as it is, is it too dated to be that good
  still ? 
 
 No, it's not too dated.  I still use it constantly as my main reference.  
 When I know a facility is post-2.2, I use the online docs instead.  But my 
 preference is definitely for the Nutshell.  Alex explains things 
 extraordinarily well, in my opinion.  The book is well-organized 
 and well-indexed, so you can find things pretty easily.
 
 Two thumbs up, from here.
 
  i have 'Learning Python' and 'Programming Python'. Learning is
  awesome for me, Programming is a bit over my head. 
 
 That tracks my feelings.  I don't find Programming Python to be very 
 useful.  It's not the sort of reference book that, say, Programming Perl 
 occupies on the Perl world.  My own take on PP is that you can't open it 
 up to a discussion of a particular feature and understand that feature 
 without understanding a lot of other things having nothing to do with the 
 feature, but that are implicit in the explanations and examples.  (But I 
 hasten to add, I've seen enough people swear how much they love that book, 
 that this may just be idiosyncratic to me.)
 
 I think a good Python *reference* book is invaluable to any Python 
 programmer.  And to me, that book is Python in a Nutshell.
 
 There are a couple others that are good, too: 
 
   The Python 2.1 Bible - 2.1, obviously; I don't know if there's a later 
 version;
 
 
   The Complete Python Reference  - published 2001, so bound to be a bit 
 dated)
 
   Python Essential Reference - When I first started playing with Python, a
 library copy of this was my reference.  I liked it, but I like the
 Nutshell just a little better, but that may be a matter of familiarity.  
 If you're going for this one, I'd suggest waiting another couple of weeks.  
 The Third Edition is coming out February 24, which means it will be the
 most current Python reference book, when published.  I would be surprised
 if it didn't cover through 2.4.
  
 
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] stuck again - socket connection

2006-02-07 Thread nephish

ok, i am stuck again. 


from the docs, the byte stream is supposed to look like this: 


'S' 'T' 'X'   [length indicator] [message type] [message] 'E' 'N' 'X' 


the length indicator it says is a four byte integer number of a value N 
 ( N would be how long the message body is ) 


the message type comes from a table in the docs. In my case, the 
message type is 200. This is also supposed to be sent as  a 4 byte 
value. 


so. how do i make 200 occupy 4 bytes ? 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] stuck again - socket connection

2006-02-07 Thread nephish
Yeah, looking over it right now as a point of fact.
thanks. Looks like exactly what i need.

cheers 
shawn

On Tue, 2006-02-07 at 10:43 -0800, Danny Yoo wrote:
 
  from the docs, the byte stream is supposed to look like this:
 
 [problem cut]
 
  so. how do i make 200 occupy 4 bytes ?
 
 
 Hi Nephish,
 
 Have you had a chance to look at the 'struct' module yet?
 
 http://www.python.org/doc/lib/module-struct.html
 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] question about ascii and bytes

2006-02-06 Thread nephish
ok, so i have sparce documentation from a server that i need to make a
socket connection with. 

the server wants to get info a certain way. Each message has to start
with an ascii STX (literally the three letters, not the standart ascii
'STX') then it has to have another four bytes that give the length of
the message, then the message itself, then end with an ascii ENX 
(again,the three letters, not the ascii character ETX ).

So here is where the biggest gap in my understanding is... how do i send
ascii characters ? 

the docs say that if the password is not 24 bytes long, the other bytes
must be filled with null values. How do i do that ? What is a null
value?

python strings are ascii already , right ? would this be as simple as
simply passing the string to the socket.send('pythonAsciiString') ?

thanks for any tips or links for documentation . 

sk

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] quick question about threads

2006-01-17 Thread nephish
Hey there, i have a program written in python that uses four threads
that run all at the same time. Now i want to add a new thread with the
same basic structure (threading.thread) that will run only when needed.
This one will not run in a loop, it will just run once and quit.
So, i may need this to be running several times at once because it will
have a 15 second delay written into it.
My question is, after the script is done, will it be safe ? i mean, over
the course of a few days, it may run this thing a few hundred times. if
it is simple like this

threading.thread
print 'here is something to say'
time.sleep(15)
print 'here is something else'

do i need to include a special command to kill the thread, or will it
just finish and everything will be ok then ?

thanks for any tips.
shawn

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] quick question about threads

2006-01-17 Thread nephish
all i needed to know, thanks very much 
shawn


On Tue, 2006-01-17 at 21:53 -0500, Kent Johnson wrote:
 nephish wrote:
  Hey there, i have a program written in python that uses four threads
  that run all at the same time. Now i want to add a new thread with the
  same basic structure (threading.thread) that will run only when needed.
  This one will not run in a loop, it will just run once and quit.
  So, i may need this to be running several times at once because it will
  have a 15 second delay written into it.
  My question is, after the script is done, will it be safe ? i mean, over
  the course of a few days, it may run this thing a few hundred times. if
  it is simple like this
  
  threading.thread
  print 'here is something to say'
  time.sleep(15)
  print 'here is something else'
  
  do i need to include a special command to kill the thread, or will it
  just finish and everything will be ok then ?
 
 Assuming you are showing the run() method of your thread above, it 
 should be fine. If the run() method exits the thread terminates and you 
 don't have to worry about it any more. Make sure you don't keep any 
 references to the threads so they can be garbage-collected.
 
 Kent
 
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to call mysqlcommand in Python , mysqldump for backup

2005-12-28 Thread nephish
Glad to help, glad you got it working too.!

shawn


On Wed, 2005-12-28 at 09:03 +, John Joseph wrote:
 --- nephish [EMAIL PROTECTED] wrote:
 
  ooh ooh, i know this one, i have python do this for
  me every day !
  
  target_dir = '/path/to/where/you/want/to/dump'
  
  os.system(mysqldump --add-drop-table -c -u user
  -ppassword database
  table  +target_dir+/table.bak.sql)
  
  dont forget the p in front of your password !
  
  hope this helps
  
  
 
   Hi it  helped me a lot ,
   I did my script like this  for backing my zabbix
 database 
 
 import os, time
 # difine the target directory
 target_dir = '/home/john/backup/z-b-weekly/zabbix'
 
 # in the formar year-month-day-hours-minute-secound
 # uses  time module
 today =  time.strftime('%Y-%m-%d-%H-%M-%S')
 
 # For testing purpose only I had kept %M %S , we can
 remove it later
 now = target_dir + today
 
 os.system(mysqldump  -u root -pjohn zabbix   
 +now+   )
   Thanks  A LOT 
   Joseph 
 
  
 
 
 
   
 ___ 
 To help you stay safe and secure online, we've developed the all new Yahoo! 
 Security Centre. http://uk.security.yahoo.com
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to call mysqlcommand in Python , mysqldump for backup

2005-12-27 Thread nephish
ooh ooh, i know this one, i have python do this for me every day !

target_dir = '/path/to/where/you/want/to/dump'

os.system(mysqldump --add-drop-table -c -u user -ppassword database
table  +target_dir+/table.bak.sql)

dont forget the p in front of your password !

hope this helps


On Tue, 2005-12-27 at 13:07 +, John Joseph wrote:
 Hi 
 I am trying to execute some MySQL commands using
 some python scripts 
   I want to do a “mysqldump” of my database “john” to
 a file backup.date.sql
 the normal command  to take a dump is 
  mysqldump  john backup.sql
 
   I tried python , by importing 
  “import os”
 but  I am stuck in  how to call “mysqldump” in
 python and execute it 
   Help and guidance requested
Thanks 
 Joseph 
 
 
 
   
 ___ 
 NEW Yahoo! Cars - sell your car and browse thousands of new and used cars 
 online! http://uk.cars.yahoo.com/
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Learning books

2005-12-20 Thread nephish
Learning Python by O'Reilly,
got me started after realizing that Programming Python by O'Reilly was a
tad over me head.

i am new here too.

On Tue, 2005-12-20 at 14:46 -0600, Richard wrote:
 Afternoon all, My son asked me what books I would like for Christmas 
 this year. So what would you recommend?
 
 I am a beginner here.
 
 
 Thanks
 
 
 Richard
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] dont understand this error MySQLdb

2005-12-14 Thread nephish
hey there,
i am using the MySQLdb module and i keep getting this error, it doesnt
offer much in the way of explanation

_mysql_exceptions.InterfaceError: (0, '')

does anyone know what this means ?

thanks

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] whats the best command to end a program

2005-12-06 Thread nephish
Hey there,
what would be the best command to end a program with.
i have an app that i want to start every day at 6am from cron
but i want it to shutdown at 4pm

i was going to check by time on every loop

if int(time.strftime(%H))  4:
some end the program command
else:
continue

what would be best used here ?

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] whats the best command to end a program

2005-12-06 Thread nephish
right, greater  16 was what i ment.

he he

it is not a gui.
is raise SystemExit built in ?

thanks gents

sk

On Tue, 2005-12-06 at 21:49 +, Alan Gauld wrote:
  what would be the best command to end a program with.
 
 If its Tkinter (or another GuI) there will be a quit command 
 somewhere. Call that to ensure that the GUI framework gets 
 tidied up properly.
 
 For normal programs
 
 import sys; sys.exit()
 
 You can pass an exit code to the outdside world as 
 a parameter to exit too.
 
 or just
 
 raise SystemExit
 
 will work.
 
  i have an app that i want to start every day at 6am from cron
  but i want it to shutdown at 4pm
 
 OK, here you probably want system.exit(n) with a proper error 
 code so that cron can tell if it worked or not...
 
 BTW strftime('%H') returns the hour in 24 hour format so you 
 will want to check for 16 not 4...
 
 Alan G
 Author of the learn to program web tutor
 http://www.freenetpages.co.uk/hp/alan.gauld
 
 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] question about ord

2005-11-15 Thread nephish
Thanks for all your help and the link,
looking at the docs right now.
slaute`
shawn


On Wed, 2005-11-16 at 10:05 +1300, Liam Clarke-Hutchinson wrote:
 Hmm, 
 
 Never thought of doing it that way.
 
 try - 
 
 import struct
 
 a = theByte
 value = ord(a)
 theByteReloaded = struct.pack(i,value)
 
 You nmay want to check the docs for the struct module at python.org on that
 pattern.
 
 
 Liam Clarke-Hutchinson
 
 
 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
 Of nephish
 Sent: Wednesday, 16 November 2005 9:46 a.m.
 To: tutor
 Subject: [Tutor] question about ord
 
 
 Hey there,
   i am using a script to change a byte into an integer
 like this:
   a = the byte
   value = ord(a)
 
 but i cant find the operation that can change it back to a byte. i am sure
 its easy, but i am missing how to do it.
 
 thanks for any tips
 
 sk
 
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor
 
 A new monthly electronic newsletter covering all aspects of MED's work is now 
 available.  Subscribers can choose to receive news from any or all of seven 
 categories, free of charge: Growth and Innovation, Strategic Directions, 
 Energy and Resources, Business News, ICT, Consumer Issues and Tourism.  See 
 http://news.business.govt.nz for more details.
 
 
 
 
 http://www.govt.nz - connecting you to New Zealand central  local government 
 services
 
 Any opinions expressed in this message are not necessarily those of the 
 Ministry of Economic Development. This message and any files transmitted with 
 it are confidential and solely for the use of the intended recipient. If you 
 are not the intended recipient or the person responsible for delivery to the 
 intended recipient, be advised that you have received this message in error 
 and that any use is strictly prohibited. Please contact the sender and delete 
 the message and any attachment from your computer.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] question about serial coms

2005-11-14 Thread nephish
Hey there,
i am developing on a linux computer with the serial module. Now, i
already am able to recieve info from a serial RS232 device and process
everything ok. What i need to do now is write to the serial device, but
i also need to be able to not interrupt the script that is reading from
it. 
I guess my question is, do i have to interrupt the reading script to
write to the same RS232 device ?
and if so, how do i do that?

thanks,
shawn

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] question about serial coms

2005-11-14 Thread nephish
Yeah, i am using pyserial, i think, in debian its called python serial
and i use import serial to get things going. 
Really easy, just wanted to know about this stuff before i start
scrambling this like so many eggs.

i will not be using two different scripts, but likely two threads in the
same script. not sure i really get what select() is all about

great link by the way, thanks.
shawn


On Mon, 2005-11-14 at 12:35 -0600, Hugo González Monteverde wrote:
 Hi Nephish,
 
 Are you using pyserial or rolling your own? Normally you can write and 
 read to the /dev/ttySXX file at the same time; since they're special 
 files, not ordinary files, the driver handles that.
 
 Handling both writing and reading in your program's flow control is a 
 wholly different matter, though. You might  need to use select()  to 
 avoid blocking.
 
 Are you using two completely different scripts for reding and writing?
 
 There is some valuable info, if not about python, in the Serial 
 Programming howto, at:
 
 http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/
 
 
 Hugo
 
 nephish wrote:
  Hey there,
  i am developing on a linux computer with the serial module. Now, i
  already am able to recieve info from a serial RS232 device and process
  everything ok. What i need to do now is write to the serial device, but
  i also need to be able to not interrupt the script that is reading from
  it. 
  I guess my question is, do i have to interrupt the reading script to
  write to the same RS232 device ?
  and if so, how do i do that?
  
  thanks,
  shawn
  
  ___
  Tutor maillist  -  Tutor@python.org
  http://mail.python.org/mailman/listinfo/tutor
  

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] question about serial coms

2005-11-14 Thread nephish
well thats encouraging, did you have to do anything special to prevent
an error when trying to read or write at the same time
?

thanks
sk


On Tue, 2005-11-15 at 09:29 +1300, Hans Dushanthakumar wrote:
 Ive worked on a similar application. I used one thread to read from the 
 serial port and another one to handle the writes. 
 
 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hugo González 
 Monteverde
 Sent: Tuesday, 15 November 2005 7:36 a.m.
 To: nephish
 Cc: tutor
 Subject: Re: [Tutor] question about serial coms
 
 Hi Nephish,
 
 Are you using pyserial or rolling your own? Normally you can write and read 
 to the /dev/ttySXX file at the same time; since they're special files, not 
 ordinary files, the driver handles that.
 
 Handling both writing and reading in your program's flow control is a wholly 
 different matter, though. You might  need to use select()  to avoid blocking.
 
 Are you using two completely different scripts for reding and writing?
 
 There is some valuable info, if not about python, in the Serial Programming 
 howto, at:
 
 http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/
 
 
 Hugo
 
 nephish wrote:
  Hey there,
  i am developing on a linux computer with the serial module. Now, i 
  already am able to recieve info from a serial RS232 device and process 
  everything ok. What i need to do now is write to the serial device, 
  but i also need to be able to not interrupt the script that is reading 
  from it.
  I guess my question is, do i have to interrupt the reading script to 
  write to the same RS232 device ?
  and if so, how do i do that?
  
  thanks,
  shawn
  
  ___
  Tutor maillist  -  Tutor@python.org
  http://mail.python.org/mailman/listinfo/tutor
  
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] question about serial coms

2005-11-14 Thread nephish
ok, i think i got it. Thanks so much. 
let you know how it turns out.
shawn


On Tue, 2005-11-15 at 11:27 +1300, Hans Dushanthakumar wrote:
 Lock() is provided by the threading module.
 see
 http://docs.python.org/lib/module-threading.html 
 
 http://docs.python.org/lib/lock-objects.html
 
 Cheers
 Hans
 
 
 -Original Message-
 From: nephish [mailto:[EMAIL PROTECTED] 
 Sent: Tuesday, 15 November 2005 11:23 a.m.
 To: Hans Dushanthakumar
 Cc: Hugo González Monteverde; tutor
 Subject: RE: [Tutor] question about serial coms
 
 ok, lock is something you wrote yourself ?
 i can't find it in the docs. However, i think i can essentially build the 
 same thing. 
 the serial module i use is pyserial. pyserial.sourceforge.net.
 the docs are a wee bit on the sparce side. But i think i can pull it off. 
 Thanks for your help. 
 
 shawn
 
 
 On Tue, 2005-11-15 at 10:58 +1300, Hans Dushanthakumar wrote:
  I believe that the drivers take care of that, however, I did use locks to 
  make sure that there were no conflicts.
  
  In the listener thread I had something along the lines of:
  
   Acquire lock
   readline() from the ser port
   Release lock
  
  And in the sender thread,
  
   Acquire lock
   send msg over ser port
   Release lock
  
  Cheers
  Hans
  
  -Original Message-
  From: nephish [mailto:[EMAIL PROTECTED]
  Sent: Tuesday, 15 November 2005 10:47 a.m.
  To: Hans Dushanthakumar
  Cc: Hugo González Monteverde; tutor
  Subject: RE: [Tutor] question about serial coms
  
  well thats encouraging, did you have to do anything special to prevent an 
  error when trying to read or write at the same time ?
  
  thanks
  sk
  
  
  On Tue, 2005-11-15 at 09:29 +1300, Hans Dushanthakumar wrote:
   Ive worked on a similar application. I used one thread to read from the 
   serial port and another one to handle the writes. 
   
   -Original Message-
   From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On 
   Behalf Of Hugo González Monteverde
   Sent: Tuesday, 15 November 2005 7:36 a.m.
   To: nephish
   Cc: tutor
   Subject: Re: [Tutor] question about serial coms
   
   Hi Nephish,
   
   Are you using pyserial or rolling your own? Normally you can write and 
   read to the /dev/ttySXX file at the same time; since they're special 
   files, not ordinary files, the driver handles that.
   
   Handling both writing and reading in your program's flow control is a 
   wholly different matter, though. You might  need to use select()  to 
   avoid blocking.
   
   Are you using two completely different scripts for reding and writing?
   
   There is some valuable info, if not about python, in the Serial 
   Programming howto, at:
   
   http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/
   
   
   Hugo
   
   nephish wrote:
Hey there,
i am developing on a linux computer with the serial module. 
Now, 
i already am able to recieve info from a serial RS232 device and 
process everything ok. What i need to do now is write to the 
serial device, but i also need to be able to not interrupt the 
script that is reading from it.
I guess my question is, do i have to interrupt the reading 
script 
to write to the same RS232 device ?
and if so, how do i do that?

thanks,
shawn

___
Tutor maillist  -  Tutor@python.org 
http://mail.python.org/mailman/listinfo/tutor

   ___
   Tutor maillist  -  Tutor@python.org
   http://mail.python.org/mailman/listinfo/tutor
  
 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] question about serial coms

2005-11-14 Thread nephish
oh yeah, i will need this too!
sk


On Mon, 2005-11-14 at 17:04 -0800, Bennett, Joe wrote:
 I have been working with pyserial. One question I have
 is this. I have a loop that writes to the serial port
 and then waits about 500ms and then reads from the
 serial port. The first thing read from the serial port
 is ALWAYS the data written to the serial port... I
 must be missing something obvious, but I thuoght the
 two buffers were separate...
 
 Here is the code I'm using if that helps:
 
 while i == 0:
   line = parmfile.readline()
   line = string.rstrip(line)
   #print line
   if line == :
 i = 1
 break
   
   else:
 
 ser.write(line + \r)
 #ser.write(\r\n)
 print Sending:  + line
 
 

 time.sleep(1)
 data_in = ser.read(100)
 print Response:  + data_in
 time.sleep(.2)
 
 
 print Closing Serial Port\n
 ser.close()
 
 
 
 -Joe
 
 
 --- nephish [EMAIL PROTECTED] wrote:
 
  ok, i think i got it. Thanks so much. 
  let you know how it turns out.
  shawn
  
  
  On Tue, 2005-11-15 at 11:27 +1300, Hans
  Dushanthakumar wrote:
   Lock() is provided by the threading module.
   see
   http://docs.python.org/lib/module-threading.html 
   
   http://docs.python.org/lib/lock-objects.html
   
   Cheers
   Hans
   
   
   -Original Message-
   From: nephish [mailto:[EMAIL PROTECTED] 
   Sent: Tuesday, 15 November 2005 11:23 a.m.
   To: Hans Dushanthakumar
   Cc: Hugo González Monteverde; tutor
   Subject: RE: [Tutor] question about serial coms
   
   ok, lock is something you wrote yourself ?
   i can't find it in the docs. However, i think i
  can essentially build the same thing. 
   the serial module i use is pyserial.
  pyserial.sourceforge.net.
   the docs are a wee bit on the sparce side. But i
  think i can pull it off. Thanks for your help. 
   
   shawn
   
   
   On Tue, 2005-11-15 at 10:58 +1300, Hans
  Dushanthakumar wrote:
I believe that the drivers take care of that,
  however, I did use locks to make sure that there
  were no conflicts.

In the listener thread I had something along the
  lines of:

 Acquire lock
 readline() from the ser port
 Release lock

And in the sender thread,

 Acquire lock
 send msg over ser port
 Release lock

Cheers
Hans

-Original Message-
From: nephish [mailto:[EMAIL PROTECTED]
Sent: Tuesday, 15 November 2005 10:47 a.m.
To: Hans Dushanthakumar
Cc: Hugo González Monteverde; tutor
Subject: RE: [Tutor] question about serial coms

well thats encouraging, did you have to do
  anything special to prevent an error when trying to
  read or write at the same time ?

thanks
sk


On Tue, 2005-11-15 at 09:29 +1300, Hans
  Dushanthakumar wrote:
 Ive worked on a similar application. I used
  one thread to read from the serial port and another
  one to handle the writes. 
 
 -Original Message-
 From: [EMAIL PROTECTED]
  [mailto:[EMAIL PROTECTED] On 
 Behalf Of Hugo González Monteverde
 Sent: Tuesday, 15 November 2005 7:36 a.m.
 To: nephish
 Cc: tutor
 Subject: Re: [Tutor] question about serial
  coms
 
 Hi Nephish,
 
 Are you using pyserial or rolling your own?
  Normally you can write and read to the /dev/ttySXX
  file at the same time; since they're special files,
  not ordinary files, the driver handles that.
 
 Handling both writing and reading in your
  program's flow control is a wholly different matter,
  though. You might  need to use select()  to avoid
  blocking.
 
 Are you using two completely different scripts
  for reding and writing?
 
 There is some valuable info, if not about
  python, in the Serial Programming howto, at:
 

  http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/
 
 
 Hugo
 
 nephish wrote:
  Hey there,
  i am developing on a linux computer with
  the serial module. Now, 
  i already am able to recieve info from a
  serial RS232 device and 
  process everything ok. What i need to do now
  is write to the 
  serial device, but i also need to be able to
  not interrupt the 
  script that is reading from it.
  I guess my question is, do i have to
  interrupt the reading script 
  to write to the same RS232 device ?
  and if so, how do i do that?
  
  thanks,
  shawn
  
 
  ___
  Tutor maillist  -  Tutor@python.org 
 
  http://mail.python.org/mailman/listinfo/tutor
  

  ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

   
  
  ___
  Tutor maillist  -  Tutor@python.org
  http://mail.python.org/mailman/listinfo/tutor
  
 

___
Tutor maillist

[Tutor] question about try except

2005-10-26 Thread nephish
Hey there,
i am writing some (for me) pretty complicated stuff for work that
really needs to work. 
i have looked at exception handling in the Learning Python book.
and i am using some try / except statements. 
the problem is, that even though my script does not crash, i dont know
the exact error. 
is there a parameter that will allow me to use try and except but that
will also pring out the traceback statements that python usually does to
the terminal?

thanks

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] question about try except

2005-10-26 Thread nephish
Thanks Hugo,
Now that i know where to look
appreciate your help.
-sk


On Wed, 2005-10-26 at 21:27 -0600, Hugo González Monteverde wrote:
 Yes,
 
 You can catch an error object along with the exception, as in:
 
 try:
  fileo = open(nofile)
 except IOError, e:
  print Alas..., e
 
 As you see, the error object has a string representation equal wo what 
 normally the python interpreter prints...
 
  
 Alas... [Errno 2] No such file or directory: 'nofile'
  
 
 
 Hope it helps. It took me originally a long time to know this trick, as 
 it's kinda buried in the docs.
 
 Hugo
 
 
 nephish wrote:
  Hey there,
  i am writing some (for me) pretty complicated stuff for work that
  really needs to work. 
  i have looked at exception handling in the Learning Python book.
  and i am using some try / except statements. 
  the problem is, that even though my script does not crash, i dont know
  the exact error. 
  is there a parameter that will allow me to use try and except but that
  will also pring out the traceback statements that python usually does to
  the terminal?
  
  thanks
  
  ___
  Tutor maillist  -  Tutor@python.org
  http://mail.python.org/mailman/listinfo/tutor
  

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] question about try except

2005-10-26 Thread nephish
Yeah, cool. i am just starting this part.
i am glad i started with python.
thanks for the help
sk


On Wed, 2005-10-26 at 21:32 -0700, w chun wrote:
  i am writing some (for me) pretty complicated stuff for work that
  really needs to work.
  i have looked at exception handling...
  and i am using some try / except statements.
  the problem is, that even though my script does not crash, i dont 
  know
  the exact error.
  is there a parameter that will allow me to use try and except but 
  that
  will also pring out the traceback statements that python usually does to
  the terminal?
 
 
 exception handling is one of the greatest strengths of Python and
 other high-level languages with this feature.  it allows the
 programmer to anticipate potential problems and perhaps be able to
 accept and process them at runtime.
 
 let's say you have a code block called BLOCK.  newbies to Python would
 typically do something like this to ensure that errors don't happen:
 
 try:
 BLOCK
 except:
 pass
 
 however, this is not the case.  if errors *do* happen, they are thrown
 away, thus serves no one any good, not the programmer nor the user.
 
 the best solution is to catch specific exceptions and handle each
 case.  (sure, and having just one handler for multiple exceptions is
 also okay.).  one example is hugo's where he catches an IOError
 exception and uses the exception instance 'e' to get more info out of
 it.
 
 now if you *don't* know what exceptions may happen, you can do
 something similar.  it's almost a combination of the above two
 handlers:
 
 try:
 BLOCK
 except Exception, e:
 print 'Caught exception without a specific handler:, e
 
 this will at least tell you what exception happens in BLOCK, so that
 you can modify it to be something like:
 
 try:
 BLOCK
 except YourSpecificException, e:
 # handle YourSpecificException code
 except Exception, e:
 print 'Caught exception without a specfic handler:', e
 
 once you know the range of exceptions that may happen in BLOCK and
 have written handlers for them, you can dispense with the general
 catch-all.
 
 hope this helps!
 -- wesley
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 Core Python Programming, Prentice Hall, (c)2006,2001
 http://corepython.com
 
 wesley.j.chun :: wescpy-at-gmail.com
 cyberweb.consulting : silicon valley, ca
 http://cyberwebconsulting.com

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python myspace module?

2005-10-25 Thread nephish
Hey there Ed, 
if you pull this off, let us know. i have wanted to do this very
thing, but just don't have the time.
sk


On Tue, 2005-10-25 at 14:24 -0700, Danny Yoo wrote:
 
 On Tue, 25 Oct 2005, Ed Hotchkiss wrote:
 
  looking to write a myspace wrapper/module. what is the best way
  (hopefully using the stdlib not an outside module) to connect to a
  website and (if possible, otherwise ill have to code it?) access forms
  with GET POST blah blah blah ...
 
 Hi Ed,
 
 We do have some rudimentary access by using libraries like urllib and
 urllib2.  Let's look at urllib for the moment:
 
 http://www.python.org/doc/lib/module-urllib.html
 
 By default, it send GET queries, but if we pass in a data argument to its
 open() function, it can perform a POST.  So for really quick-and-dirty
 stuff, urllib can do the trick.
 
 
 For anything more sophisticated, we may want to look at some tools like
 mechanize:
 
 http://wwwsearch.sourceforge.net/mechanize/
 
 which can help provide the illusion of a stateful session with a web
 server.
 
 
 Best of wishes!
 
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] advice on how to start with urllib

2005-10-23 Thread nephish
Thanks a lot, this stuff is pretty easy.
i got a couple of things working here.
thanks for your help
sk 

On Sun, 2005-10-23 at 13:46 +0100, Christopher Arndt wrote:
 nephish schrieb:
  hey there gents,
  i am looking for a good place to start learning how to read a web page
  with python and pull out bits of information for an app i am doing for
  work. i have googled and looked at the docs. i looked at urllib and
  httplib so i think this a place to kinda start. Does anyone know of a
  good site with some examples or tutorials for this kind of thing ? 
 
 The online book Diving into Python by Mark Pilgrim has an excellent chapter
 on how to download webpages and process them:
 
 http://diveintopython.org/http_web_services/index.html
 
 HTH, Chris
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] advice on how to start with urllib

2005-10-22 Thread nephish
hey there gents,
i am looking for a good place to start learning how to read a web page
with python and pull out bits of information for an app i am doing for
work. i have googled and looked at the docs. i looked at urllib and
httplib so i think this a place to kinda start. Does anyone know of a
good site with some examples or tutorials for this kind of thing ? 
thanks

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] question about pychart

2005-10-14 Thread nephish
Hey there,
i have a simple app that plots some numbers sent by a field sensor with
respect to time. i am trying to do this in pychart, but the problem is,
when the numbers come in, they do so at almost random times.
y shows the value sent by the sensor
x plots the time that the value came in.

what happens is that the plots are spaced evenly throughout the x axis.
so it always looks like an even amount of time when most often, it isn't
i need a way to make it plot out the x so that when a lot of values come
in at close to the same time, it looks more like that on the graph. i
looked at the docs where the examples show that this can be done, the
example uses a log style to the plot.
it looks like this.
http://home.gna.org/pychart/examples/scattertest.png

mostly the graph on the right

my chart shows just a plot of x=datetime y=value,
someone have an idea about how i can get more realistic looking values?

thanks 
shawn


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] time challange

2005-09-22 Thread nephish
Hey there,

i use mx.DateTime.RelativeDateTimeDiff to get the difference between 
date_x and date_y.
what i need to do divide this amount of time into 20 different times 
that spaced out between the date_x and the date_y.

so if the difference between date_x and date_y is 20 hours, i need 20 
DateTimes that are one hour apart from each other. If the difference is 
40 minutes, i need the 20 DateTimes to be spaced out 2 minutes from each 
other..

what would be a way to pull this off? i have looked at the docs for 
mxDateTime
http://www.egenix.com/files/python/mxDateTime.html
and there seems to be a divide operation, but i dont quite know what it 
is talking about
with the deltas.

anyone have a good start point?

thanks
shawn
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] time challange

2005-09-22 Thread nephish
paul brian wrote:

You are fairly close

  

t1 = today()
t1


DateTime object for '2005-09-22 00:00:00.00' at 11656e0
  

t2 = today() + RelativeDateTime(hours=20)
t2


DateTime object for '2005-09-22 20:00:00.00' at 1165760
  

t3 = t2 - t1
t3.hours


20.0
  

slice = t3/20
slice


DateTimeDelta object for '01:00:00.00' at 116cc50

t3 is a Delta - that is an abstract representation
of time - it is not the 20 hours since midnight, just 20 hours
at any time in the universe.
slice is just 1/20th of that same abstract time. But because of the munificence
of Marc we can add that abstract hour to a real fixed time (ignoring
Einstein of course)

  

t1 + slice


DateTime object for '2005-09-22 01:00:00.00' at 11655e0

And so that is a real datetime 1/20th of the way forward from t1

so a simple loop will get you your 20 evenly spaced time periods,
which is what i think you were asking for.

cheers



On 9/22/05, nephish [EMAIL PROTECTED] wrote:
  

Hey there,

i use mx.DateTime.RelativeDateTimeDiff to get the difference between
date_x and date_y.
what i need to do divide this amount of time into 20 different times
that spaced out between the date_x and the date_y.

so if the difference between date_x and date_y is 20 hours, i need 20
DateTimes that are one hour apart from each other. If the difference is
40 minutes, i need the 20 DateTimes to be spaced out 2 minutes from each
other..

what would be a way to pull this off? i have looked at the docs for
mxDateTime
http://www.egenix.com/files/python/mxDateTime.html
and there seems to be a divide operation, but i dont quite know what it
is talking about
with the deltas.

anyone have a good start point?

thanks
shawn
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor





--
--
Paul Brian
m. 07875 074 534
t. 0208 352 1741

  

YES !
that is what i needed. This is great.
i think i understand your steps ok, but you lost me with the munificence
of Marc. i never got to take physics. All the same, thanks so much

shawn
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] problem with matplot

2005-09-20 Thread nephish
hey there,
anyone have any luck getting up and running with matplot-lib on debian?
from the website, i followed the instructions to get it with apt. but 
something is messed up in the dependencies.

i get this
import pylab

Traceback (most recent call last):
  File pyshell#0, line 1, in -toplevel-
import pylab
  File /usr/lib/python2.3/site-packages/pylab.py, line 1, in -toplevel-
from matplotlib.pylab import *
  File /usr/lib/python2.3/site-packages/matplotlib/pylab.py, line 198, 
in -toplevel-
from axes import Axes, PolarAxes
  File /usr/lib/python2.3/site-packages/matplotlib/axes.py, line 13, 
in -toplevel-
from artist import Artist, setp
  File /usr/lib/python2.3/site-packages/matplotlib/artist.py, line 4, 
in -toplevel-
from transforms import identity_transform
  File /usr/lib/python2.3/site-packages/matplotlib/transforms.py, line 
189, in -toplevel-
from _transforms import Value, Point, Interval, Bbox, Affine
  File /usr/lib/python2.3/site-packages/matplotlib/_transforms.py, 
line 11, in -toplevel-
from matplotlib._nc_transforms import *
ImportError: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.4' not found 
(required by /usr/lib/python2.3/site-packages/matplotlib/_nc_transforms.so)

i have already installed libstdc++6, and i dont really know what version 
GLIBCXX_3.4.4 means.

anyone have an idea?

thanks
shawn
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem with matplot

2005-09-20 Thread nephish
Danny Yoo wrote:

  

anyone have any luck getting up and running with matplot-lib on debian?
from the website, i followed the instructions to get it with apt. but
something is messed up in the dependencies.



Check with the Debian folks about this one; the problem you're running
into looks really specific to the way Debian has packaged libstdc++6.
This topic isn't really one that folks on Tutor will necessarily have
competence in.  Instead, try the debian-python mailing list:

http://lists.debian.org/debian-python/

I did try to Google what was going on, and there's a thread in:

http://lists.badopi.org/pipermail/comandob/Week-of-Mon-20050801/011594.html

Unfortunately, I'm not quite sure what they're saying, given that it's not
English.  *grin* But I suspect that someone intimate with the Debian
packaging system would know what was going on here.


  

thanks for the links, i will dig some more, i know this isnt really a 
python issue, but i thought that since debian is popular, matplot is 
most peoples recommendation for graphing, and it is for python...
figgured i may not be the only one to run into this brick wall.
anyway, thanks for your time, maybe an upgrade to 'testing' will help 
for this package.
ok, thanks much.
shawn
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem with matplot

2005-09-20 Thread nephish
Danny Yoo wrote:

Check with the Debian folks about this one; the problem you're running
into looks really specific to the way Debian has packaged libstdc++6.
This topic isn't really one that folks on Tutor will necessarily have
competence in.  Instead, try the debian-python mailing list:

   http://lists.debian.org/debian-python/

  

thanks for the links, i will dig some more, i know this isnt really a
python issue, but i thought that since debian is popular, matplot is
most peoples recommendation for graphing, and it is for python...




True, but let's try to maintain the topical Learn to program  nature of
the mailing list.  I really want to try to avoid turning Tutor into the
Help with installing package X on system Y mailing list.  We'll try to
help out as best we can on such questions, of course, but this is probably
not the best place to ask this.

I guess I'm really trying to say: let's try to keep Tutor from turning
into comp.lang.python.  *grin*

From the Google searches I've done so far, this problem really doesn't
look specific to Python, but basically to anything that links up with the
libstdc++ library on both Debian and Red Hat systems.  It's not exclusive
to Python, and since it's so far reaching, I have to assume that it's the
particular Linux distribution's faul... er, responsibility.


  

he he he. yeah, i admit, i have been breezing over distrowatch.
sorry about the clutter. wont happen again. i don't know where i would
be without this list.
cheers,
sk
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] pychart and debian

2005-09-18 Thread nephish
Hey there,
anyone have luck getting pychart installed on debian ?
there is no debian package for it (that i have found thus far)
and i need something that will allow me to place some
simple x, y plots on a chart in pygtk.

if any of you have a better solution, i am not completely sold out to
pychart. i know that there are others out there.

thanks
sk

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pychart and debian

2005-09-18 Thread nephish
Danny Yoo wrote:

On Sun, 18 Sep 2005, nephish wrote:

  

anyone have luck getting pychart installed on debian ? there is no
debian package for it (that i have found thus far) and i need something
that will allow me to place some simple x, y plots on a chart in pygtk.



Hi sk,

Ah, found it.  It's in the 'testing' and 'unstable' branches in Debian:

http://packages.qa.debian.org/p/python-pychart.html
http://packages.debian.org/unstable/python/python2.3-pychart

If you're running 'stable', you may want to ask the Debian folks how easy
it is to grab it from 'testing' and install it.

If you install pychart from source, doing 'python setup.py install' should
be sufficient, as long as you have ghostscript installed on your system.


Best of wishes to you!


  

ok, got the package installed, but it seems to not be working, or the 
examples are messed up.
here is the source

from pychart import *
theme.get_options()
data = [[Jan, 10], [Feb, 22], [Mar, 30]]

ar = area.T(x_coord = category_coord.T(data, 0),
y_range = (0, None),
x_axis = axis.X(label=Month),
y_axis = axis.Y(label=Value))
ar.add_plot(bar_plot.T(data = data, label = Something))
ar.draw()

and here is what i get when i run it.

from: can't read /var/mail/pychart
./categbar.py: line 16: syntax error near unexpected token `data'
./categbar.py: line 16: `data = [[Jan, 10], [Feb, 22], [Mar, 30]]'
[EMAIL PROTECTED]:~$

what do you think may be wrong?
thanks for your help with the package by the way

-sk
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pychart and debian

2005-09-18 Thread nephish
Danny Yoo wrote:

ok, got the package installed, but it seems to not be working, or the
examples are messed up.
here is the source

from pychart import *
theme.get_options()
data = [[Jan, 10], [Feb, 22], [Mar, 30]]

ar = area.T(x_coord = category_coord.T(data, 0),
y_range = (0, None),
x_axis = axis.X(label=Month),
y_axis = axis.Y(label=Value))
ar.add_plot(bar_plot.T(data = data, label = Something))
ar.draw()

and here is what i get when i run it.

from: can't read /var/mail/pychart


  ^^

Ah!  You're running into an issue with your Unix environment, not Python.

Unix doesn't care about file names: without any hints, it'll think that
your program is a mere shell script.  The error message above means that
'/bin/sh' is trying to interpret your program.  That is, it's trying to
run the Unix 'from' command!

http://www.freebsd.org/cgi/man.cgi?query=fromapropos=0sektion=0manpath=FreeBSD+5.4-RELEASE+and+Portsformat=html

And the subsequent error messages are pretty much '/bin/sh' error
messages.


To avoid this problem, try:

$ python categbar.py

Alternatively, make sure the first line in your Python program contains
the magic line:

#!/usr/bin/env python

to tell the Unix (or Linux) kernel that the program you're running is
meant to be run through Python.


  

yup, the examples did not have the #!/usr/bin/python line.
i have been at python for about 5 months now. How did i miss this?

thanks
sk
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] IDEs

2005-09-14 Thread nephish
Matt Williams wrote:

I've used both PyDev and Wing IDE.

PyDev seems good, and is getting better. 
Wing is pay-for (although only $40 or so), but can be trialled. I thought
it was good, but had a huge problem trying to get it to play with a C library
I was using...

I've never managed to get Boa-Constructor to run...

As regards using wxPython - I thought it was ok, but frankly Glade was s
much easier..

(all IMHO)

Matt

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

  

Yup, exactly why i use glade!
sk
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Boa-Constructor

2005-09-12 Thread nephish
Terry Kemmerer wrote:

 Hey Guys,

 I am trying to pick an IDE, and it seems to me that Boa-Constructor 
 has great potential. However, in searching google looking to see what 
 others have said, I am reading that the latest version of 
 Boa-Constructor is unstable at best and crashes a lot.being said, 
 at least, by those promoting non-free IDE's. Yet, Boa-Constructor 
 looks from the outside to me, like a really great IDE.

 Does anyone who is using this latest version or who has tried this 
 latest version have any comments concerning its actual usability?

 Thanks,

 Terry



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
  

if you don't mind KDE, eric is really cool. I run gnome, but i use eric 
because of things like syntax error checking, etc.. i really dig it
sk
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [tutor] threading problem in GUI

2005-09-08 Thread nephish
Pierre Barbier de Reuille wrote:

Great :)

Just to be clear about that: you can see the connect line as a dynamic
registration process (with the symetric disconnect operation available
via ... disconnect). The only thing you need is to connect (at
runtime) the even before it's called (obvious isn't it ? ;) ), but you
have no other constraint. You can even choose to connect/disconnect
events when they are used/unused ... You can also connect a single event
many times (to different functions) or you can connect many events to
the same function. This is the power of this system :) Like now if you
want to log your strings on a file, you just define the function writing
in the file and connect the event to this function: you'll have both the
GUI and the log-file outputs !

This is, AFAIK, the best existing implementation for user interfaces !

Pierre

nephish a écrit :
  

Pierre Barbier de Reuille wrote:



nephish a écrit :
 

  

one more thing.
if i uncomment the lines
gtk.threads_enter()
and
gtk.threads_leave()
the whole thing locks up when the function is called.
the gui, and the thread both lock up.
  


Well, that's just normal. However, what you should do is to send a
signal from your thread with the text to append in your textbuffer.
Then, you catch the signal in your main widget to show it !

To emit a signal use :

   gtk.gdk.threads_enter()
   self.emit(writing, str)
   gtk.gdk.threads_leave()

To catch it:


   emitting_object.connect(writing, self.method_handling_to_signal)

Well, I used that and it just work ! Using the signal does not solve any
threading problem but allow you to separate between the event and the
answer to the event, which is a good habit to take !

Pierre


 

  

I finally got it working !!
thanks so much for all your help
i would not have gotten it working without you,
(or this mailing list)

God bless
shawn




  

indeed. i really want to get into this stuff more.
i think a whole lot of what i have been doing could really be
done easier and cleaner.
thanks for everything,
shawn
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [tutor] threading problem in GUI

2005-09-07 Thread nephish


Serial1() just call the function ... it will be evaluated and then the
result will be sent to Thread.start ...

So try:

Thread.start(Serial)


ok,
so far the thread runs fine in the background, but just does not send the 
output to the 
textbuffer, and hangs up the rest of the show.

i think i am off in how i have the gtk.main() set up
and how the main class is set up

class SimpleGladeApp:
def __init__(self, path, root=None, domain=None, **kwargs):
if os.path.isfile(path):
self.glade_path = path
else:
glade_dir = os.path.dirname( sys.argv[0] )
self.glade_path = os.path.join(glade_dir, path)
for key, value in kwargs.items():
try:
setattr(self, key, weakref.proxy(value) )
except TypeError:
setattr(self, key, value)
self.glade = None
self.install_custom_handler(self.custom_handler)
self.glade = self.create_glade(self.glade_path, root, domain)
if root:
self.main_widget = self.get_widget(root)
else:
self.main_widget = None
self.normalize_names()
self.add_callbacks(self)
self.new()

def main(self):
gtk.gdk.threads_enter()
gtk.main()
gtk.gdk.threads_leave() 

class Main(SimpleGladeApp):
def __init__(self, path=pivcontrolcenter.glade,
 root=Main,
 domain=app_name, **kwargs):
path = os.path.join(glade_dir, path)
SimpleGladeApp.__init__(self, path, root, domain, **kwargs)

def on_StartEnginesButton_clicked(self, widget, *args):
print on_StartEnginesButton_clicked called with self.%s % 
widget.get_name()
Input1Iter = self.Input1Buffer.get_end_iter()
Input2Iter = self.Input2Buffer.get_end_iter()
Input1Data = 'Reading Serial device ttyS14 \n'
Input2Data = 'Reading Serial device ttys15 \n'
self.Input1Buffer.insert(Input1Iter, Input1Data)
self.Input2Buffer.insert(Input2Iter, Input2Data)
time.sleep(1)
def Serial1():
print 'running serial 1'
ser = serial.Serial('/dev/ttyS15', 2400, timeout=None)
loopy = 1
i = 1
while loopy  5:
for x in range(5):
i = i + 1
a = ser.read(1)#read one byte
a = ord(a) # change byte to integer
if (a  64 )or (a  127):
break
b = ser.read(1)
b = ord(b)
if (b  64 )or (b  127):
break
c = ser.read(1)
c = ord(c)
if c  92:
break
d = ser.read(1)
d = ord(d)
if d  128:
break
Sensor_ID = (a  63) + (b  63) * 64 + (c  1) * 4096
Status = (c  62) / 2 + (d  63) * 32
c = int(c)
d = int(d)
x_Now = strftime('%Y-%m-%d %H:%M:%S')   
#gtk.threads_enter()
Input1Data = 
str(Sensor_ID)+'\t'+str(Status)+'\t-\t'+x_Now+'\n'
Input1Iter = self.Input1Buffer.get_end_iter()
self.Input1Buffer.insert(Input1Iter, Input1Data)
#gtk.threads_leave()
f = open('/home/piv/PivData/tmp/Serial/'+str(i), 'w')

f.write(str(Sensor_ID)+'\n'+str(c)+'\n'+str(d)+'\n'+str(Status)+'\n'+x_Now) 
  
f.close()
Thread.start(Serial1())

def main():
main = Main()
#gtk.threads_enter()
main.run()
#gtk.threads_leave()

if __name__ == __main__: 
#gtk.threads_enter()   
main()
#gtk.threads_leave() 

lots of comments, been trying this several ways.

cheers
shawn 





___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [tutor] threading problem in GUI

2005-09-07 Thread nephish
Pierre Barbier de Reuille wrote:

nephish a écrit :
  

one more thing.
if i uncomment the lines
gtk.threads_enter()
and
gtk.threads_leave()
the whole thing locks up when the function is called.
the gui, and the thread both lock up.



Well, that's just normal. However, what you should do is to send a
signal from your thread with the text to append in your textbuffer.
Then, you catch the signal in your main widget to show it !

To emit a signal use :

gtk.gdk.threads_enter()
self.emit(writing, str)
gtk.gdk.threads_leave()

To catch it:


emitting_object.connect(writing, self.method_handling_to_signal)

Well, I used that and it just work ! Using the signal does not solve any
threading problem but allow you to separate between the event and the
answer to the event, which is a good habit to take !

Pierre


  

cool, will try.
where exactly do i put this line? Just right in the main loop?

emitting_object.connect(writing, self.method_handling_to_signal)


thanks !
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [tutor] threading problem in GUI

2005-09-07 Thread nephish
Pierre Barbier de Reuille wrote:

nephish a écrit :
  

one more thing.
if i uncomment the lines
gtk.threads_enter()
and
gtk.threads_leave()
the whole thing locks up when the function is called.
the gui, and the thread both lock up.



Well, that's just normal. However, what you should do is to send a
signal from your thread with the text to append in your textbuffer.
Then, you catch the signal in your main widget to show it !

To emit a signal use :

gtk.gdk.threads_enter()
self.emit(writing, str)
gtk.gdk.threads_leave()

To catch it:


emitting_object.connect(writing, self.method_handling_to_signal)

Well, I used that and it just work ! Using the signal does not solve any
threading problem but allow you to separate between the event and the
answer to the event, which is a good habit to take !

Pierre


  

I finally got it working !!
thanks so much for all your help
i would not have gotten it working without you,
(or this mailing list)

God bless
shawn
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] threading problem in GUI

2005-09-06 Thread nephish
Hello there !
i am having a problem with threading.
OK, i have this GUI app that i am building with pygtk.
there is a process (four actually, just working on getting one right now)
that needs to run in the background.
there is a button that starts the background function. But, it locks up 
the gui. it doesn't run in the background, it locks everything up. It 
still runs though.
one of the things this background process is to do is updata a viewable
area on the GUI. Now when run from a terminal, when i hit CTRL+C
it stops the thread, but doesnt kill the GUI, and the TextView gets 
updated right then with everything it should have gotten before.


def Serial1():
print 'running serial 1'
ser = serial.Serial('/dev/ttyS15', 2400, timeout=None)
loopy = 1
i = 1
while loopy  5:   
x_Now = strftime('%Y-%m-%d %H:%M:%S')
i = i + 1   
a = ser.read(1)#read one byte   
a = ord(a) # change byte to integer
if (a  64 )or (a  127):
continue   
b = ser.read(1)
b = ord(b)
if (b  64 )or (b  127):
continue
c = ser.read(1)
c = ord(c)
if c  92:
continue
d = ser.read(1)
d = ord(d)
if d  128:
continue
Sensor_ID = (a  63) + (b  63) * 64 + (c  1) * 4096
Status = (c  62) / 2 + (d  63) * 32
c = int(c)
d = int(d)
x_Now = strftime('%Y-%m-%d %H:%M:%S')
f = open('/home/piv/PivData/tmp/Serial/'+str(i), 'w')
Input1Data = 
str(Sensor_ID)+'\t'+str(Status)+'\t-\t'+x_Now+'\n'
Input1Iter = self.Input1Buffer.get_end_iter()
self.Input1Buffer.insert(Input1Iter, 
Input1Data)   

f.write(str(Sensor_ID)+'\n'+str(c)+'\n'+str(d)+'\n'+str(Status)+'\n'+x_Now) 
  

f.close()
thread.start_new(Serial1())

the code may not be best form, i am still fairly new at this. so i am 
also open to
any constructive critisism.

thanks
shawn
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] threading problem in GUI

2005-09-06 Thread nephish
Pierre Barbier de Reuille wrote:

nephish a écrit :
  

Hello there !



Hello,

  

i am having a problem with threading.
OK, i have this GUI app that i am building with pygtk.
there is a process (four actually, just working on getting one right now)
that needs to run in the background.



Please, do not mix process and threads ... there very different ...
you're talking about threads here, so you want Threads to run in the
background ...

  

there is a button that starts the background function. But, it locks up 
the gui. it doesn't run in the background, it locks everything up. It 
still runs though.



That's just normal ... if you read PyGtk documentation, you'll see you
need to initialise PyGtk to handle threads :

http://www.async.com.br/faq/pygtk/index.py?req=index - 20. The GTK
Mainloop and Threading

http://www.async.com.br/faq/pygtk/index.py?req=showfile=faq20.006.htp
- This is exactly your problem !

http://www.pygtk.org/pygtk2reference/gdk-functions.html#function-gdk--threads-init

This is done like this :

# First call to PyGtk function ever
gtk.gdk.threads_init()
# Here initialize what you want
[...]
# Launch the Gtk loop
gtk.gdk.threads_enter() # Unneeded if you don't want to call GUI
# functions from other threads
gtk.main()
gtk.gdk.threads_leave() # Needed only with threads_enter

  

one of the things this background process is to do is updata a viewable
area on the GUI. Now when run from a terminal, when i hit CTRL+C
it stops the thread, but doesnt kill the GUI, and the TextView gets 
updated right then with everything it should have gotten before.


def Serial1():
print 'running serial 1'
ser = serial.Serial('/dev/ttyS15', 2400, timeout=None)
loopy = 1
i = 1
while loopy  5:   
x_Now = strftime('%Y-%m-%d %H:%M:%S')
i = i + 1   
a = ser.read(1)#read one byte   
a = ord(a) # change byte to integer
if (a  64 )or (a  127):
continue   
b = ser.read(1)
b = ord(b)
if (b  64 )or (b  127):
continue
c = ser.read(1)
c = ord(c)
if c  92:
continue
d = ser.read(1)
d = ord(d)
if d  128:
continue
Sensor_ID = (a  63) + (b  63) * 64 + (c  1) * 4096
Status = (c  62) / 2 + (d  63) * 32
c = int(c)
d = int(d)
x_Now = strftime('%Y-%m-%d %H:%M:%S')
f = open('/home/piv/PivData/tmp/Serial/'+str(i), 'w')
Input1Data = 
str(Sensor_ID)+'\t'+str(Status)+'\t-\t'+x_Now+'\n'
Input1Iter = self.Input1Buffer.get_end_iter()
self.Input1Buffer.insert(Input1Iter, 
Input1Data)   

f.write(str(Sensor_ID)+'\n'+str(c)+'\n'+str(d)+'\n'+str(Status)+'\n'+x_Now)   


f.close()
thread.start_new(Serial1())

the code may not be best form, i am still fairly new at this. so i am 
also open to
any constructive critisism.

thanks
shawn
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor




  

ok, i am still having a little problem understanding.
tried it but i don't know if i have things set in the right order.

 
gtk.gdk.threads_init()
# Here initialize what you want
[...]
# Launch the Gtk loop
gtk.gdk.threads_enter() # Unneeded if you don't want to call GUI
# functions from other threads
gtk.main()
gtk.gdk.threads_leave() # Needed only with threads_enter

at the part where you wrote 
# Here initialize what you want
[...]
is that where i define the function that will run the thread?

i get the part about having the enter and leave
i just seem to have a hang up (so to speak) with where the function gets 
defined.
do i need to build it as a class like the example in the link you sent?

thanks for your help on this


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] threading problem in GUI

2005-09-06 Thread nephish
Pierre Barbier de Reuille wrote:

nephish a écrit :
  

Pierre Barbier de Reuille wrote:

[...]
ok, i am still having a little problem understanding.
tried it but i don't know if i have things set in the right order.


gtk.gdk.threads_init()
# Here initialize what you want
[...]
# Launch the Gtk loop
gtk.gdk.threads_enter() # Unneeded if you don't want to call GUI
   # functions from other threads
gtk.main()
gtk.gdk.threads_leave() # Needed only with threads_enter

at the part where you wrote # Here initialize what you want
[...]
is that where i define the function that will run the thread?

i get the part about having the enter and leave
i just seem to have a hang up (so to speak) with where the function gets
defined.
do i need to build it as a class like the example in the link you sent?



Well, no you don't need to create a class.

As for the place where to put your function, it's not a problem, [...]
is the place where you will *execute* some initialization code (if
needed) before you launch your interface. That's all (typically that's
where you will instanciate your widgets).

  

thanks for your help on this



Your welcome,

Pierre

  

ok, i am still kinda stuck.
im posting what i think is necessary, because the whole thing is rather 
long.
so here goes.

#!/usr/bin/python

import os
import time
from time import strftime

import sys
import gtk
import pygtk
import serial
import threading
from threading import Thread
import tokenize
import gtk.glade
import weakref
import inspect
import re


gtk.gdk.threads_init()

def main(self):
gtk.gdk.threads_enter()
gtk.main()
gtk.gdk.threads_leave()

def on_StartEnginesButton_clicked(self, widget, *args):
print on_StartEnginesButton_clicked called with self.%s % 
widget.get_name()
Input1Iter = self.Input1Buffer.get_end_iter()
Input2Iter = self.Input2Buffer.get_end_iter()
Input1Data = 'Reading Serial device ttyS14 \n'
Input2Data = 'Reading Serial device ttys15 \n'
self.Input1Buffer.insert(Input1Iter, Input1Data)
self.Input2Buffer.insert(Input2Iter, Input2Data)   
time.sleep(2)
def Serial1():   
print 'running serial 1'
ser = serial.Serial('/dev/ttyS15', 2400, timeout=None)
loopy = 1
i = 1
while loopy  5:   
for x in range(5):
i = i + 1   
a = ser.read(1)#read one byte   
a = ord(a) # change byte to integer
if (a  64 )or (a  127):
break 
b = ser.read(1)
b = ord(b)
if (b  64 )or (b  127):
break
c = ser.read(1)
c = ord(c)
if c  92:
break
d = ser.read(1)
d = ord(d)
if d  128:
break
Sensor_ID = (a  63) + (b  63) * 64 + (c  1) * 4096
Status = (c  62) / 2 + (d  63) * 32
c = int(c)
d = int(d)
x_Now = strftime('%Y-%m-%d %H:%M:%S')  
gtk.threads_enter()
Input1Data = 
str(Sensor_ID)+'\t'+str(Status)+'\t-\t'+x_Now+'\n'
Input1Iter = self.Input1Buffer.get_end_iter()
self.Input1Buffer.insert(Input1Iter, Input1Data)
gtk.threads_leave()
f = open('/home/piv/PivData/tmp/Serial/'+str(i), 'w')

f.write(str(Sensor_ID)+'\n'+str(c)+'\n'+str(d)+'\n'+str(Status)+'\n'+x_Now) 
  

f.close()
Thread.start(Serial1())

thanks, i am learning from several sources. two books from O'Reilly, and 
a dozen or so websites,
not everybody does everything the same way . if something here looks 
alarming, please let me know.

thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to make a script do two things at once.

2005-08-22 Thread nephish
Michael Lange wrote:

On Sun, 21 Aug 2005 16:23:20 -0500
nephish [EMAIL PROTECTED] wrote:

  

Hey there,
i have a simple question about getting a script to do
two things at once.
like this.


for i in range(100):
print i
time.sleep(.2)
if i == 15:
os.system('python /home/me/ipupdate.py')
   
print 'done'

when i run this, it stops at 15 and runs the script called out in the 
os.system line. i know it is supposed to do that. But, how could i get a 
script to do this without stopping the count (or delaying it unill the 
script called exits) I don' t have to run it this way, i can import it 
if necessary as a module. or whatever will work so i can execute two 
things at once.




If you just need to call a unix system command you can simply add  to the 
command string to
make it run in the background.

Regards

Michael

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

  

Well Cool , yeah, i run linux. this would work out great.
thanks!
shawn
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how to make a script do two things at once.

2005-08-21 Thread nephish
Hey there,
i have a simple question about getting a script to do
two things at once.
like this.


for i in range(100):
print i
time.sleep(.2)
if i == 15:
os.system('python /home/me/ipupdate.py')
   
print 'done'

when i run this, it stops at 15 and runs the script called out in the 
os.system line. i know it is supposed to do that. But, how could i get a 
script to do this without stopping the count (or delaying it unill the 
script called exits) I don' t have to run it this way, i can import it 
if necessary as a module. or whatever will work so i can execute two 
things at once.

thanks
shawn


___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to make a script do two things at once.

2005-08-21 Thread nephish
Kent Johnson wrote:

nephish wrote:
  

Hey there,
i have a simple question about getting a script to do
two things at once.
like this.


for i in range(100):
print i
time.sleep(.2)
if i == 15:
os.system('python /home/me/ipupdate.py')
   
print 'done'

when i run this, it stops at 15 and runs the script called out in the 
os.system line. i know it is supposed to do that. But, how could i get a 
script to do this without stopping the count (or delaying it unill the 
script called exits) 



One way to get a script to do two things 'at once' is to use threads. Threads 
are also a good way to introduce strange bugs into your program so you should 
do some reading about them. I can't find a good introduction - anyone else 
have a suggestion? Here is a brief one:
http://www.wellho.net/solutions/python-python-threads-a-first-example.html

Here are a couple of articles, not really introductory:
http://linuxgazette.net/107/pai.html
http://www.devshed.com/c/a/Python/Basic-Threading-in-Python/

Anyway here is something to get you started, this version of your program 
starts a new thread to do the os.system call, that way the main thread doesn't 
block.

import os, threading, time

def doSomething():
''' This function will be called from the second thread '''
os.system('''python -c from time import sleep;sleep(2);print 'hello)

for i in range(30):
print i
time.sleep(.2)
if i == 10:
print 'Starting thread'
threading.Thread(target=doSomething).start()
   
print 'done'

Kent

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor

  

thanks for all of the responses, yep, looks like threads is what i want 
to go with. got the docs you guys linked me to bookmarked. this is going 
to take a bit of research.
thanks again for showing me where to start.
shawn
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Need help with serial input

2005-08-18 Thread nephish
Hey there,
i am using the serial module and trying to get some info over an RS232 
port. Seems to be comming in ok, but when i print it out, its in ASCII 
instead of hex. is there a way to have python read serial in hex bytes 
instead of ASCII ?
thanks.
shawn
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] need some help with ascii hex

2005-08-18 Thread nephish
Hey there,
i am using the serial module and trying to get some info over an RS232 
port. Seems to be comming in ok, but when i print it out, its in ASCII 
instead of hex. is there a way to have python read serial in hex bytes 
instead of ASCII ?
thanks.
shawn
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] i know this should be easy

2005-08-17 Thread nephish
Hey there,
i have a simple question.
if something returns a true or false, how do i test for it with an if 
statement?
i am using pygtk with a toggle button that returns TRUE if checked and 
FALSE if not.
do i need quotes around the TRUE / FALSE or should i use 1 and 0?

Auto_Tog = self.AutoCheckRaw.get_active()
if str(AddDay_Tog)== '1':
do so and so.

is this right?

thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor



Re: [Tutor] i know this should be easy

2005-08-17 Thread nephish
Jeremy Jones wrote:

 nephish wrote:

 Hey there,
 i have a simple question.
 if something returns a true or false, how do i test for it with an if 
 statement?
 i am using pygtk with a toggle button that returns TRUE if checked 
 and FALSE if not.
 do i need quotes around the TRUE / FALSE or should i use 1 and 0?

 Auto_Tog = self.AutoCheckRaw.get_active()
 if str(AddDay_Tog)== '1':
do so and so.
  

 If ``get_active()`` returns True or False (or 1 or 0), you could just 
 do::

if self.AutoCheckRaw.get_active():
   do_your_True_stuff_here()
else:
   do_your_False_stuff_here()


 is this right?

 thanks
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

  

 Jeremy

i knew this would be an easy one.
thanks very much
shawn
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] i know this should be easy

2005-08-17 Thread nephish
Kent Johnson wrote:

nephish wrote:
  

Hey there,
i have a simple question.
if something returns a true or false, how do i test for it with an if 
statement?
i am using pygtk with a toggle button that returns TRUE if checked and 
FALSE if not.
do i need quotes around the TRUE / FALSE or should i use 1 and 0?

Auto_Tog = self.AutoCheckRaw.get_active()
if str(AddDay_Tog)== '1':
do so and so.



I'm not sure what you mean by TRUE and FALSE but you can most likely just test 
it directly:

Auto_Tog = self.AutoCheckRaw.get_active()
if AddDay_Tog:
do so and so.

From http://docs.python.org/ref/Booleans.html#Booleans

In the context of Boolean operations, and also when expressions are used by 
control flow statements, the following values are interpreted as false: None, 
numeric zero of all types, empty sequences (strings, tuples and lists), and 
empty mappings (dictionaries). All other values are interpreted as true.

So any reasonable values for TRUE and FALSE will work fine.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

  

cool. thanks much !
shawn
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how to write a line

2005-07-25 Thread nephish
Hey there,
kinda newbie question here.
i know how to read the lines of a txt file.
i know how to write a txt file.

but how do i overwrite a line value with another value ?

i mean, how do go to, say, line 3 of a text file and replace
what is written on line 3 with something else?

thanks


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to write a line

2005-07-25 Thread nephish
i get it. manipulate everything while it is read.
make my changes and use writelines(list from readlines earlier)
so i kinda just hold everything in the list until i overwrite the
original. thats great. my file is only 8 lines long. no problem
thanks a lot ! Seems easy now.
-shawn
On 07/25/2005 04:18:08 PM, Danny Yoo wrote:
 
 
 On Mon, 25 Jul 2005, nephish wrote:
 
  i know how to read the lines of a txt file.
  i know how to write a txt file.
 
  but how do i overwrite a line value with another value ?
 
  i mean, how do go to, say, line 3 of a text file and replace what is
  written on line 3 with something else?
 
 Hi Nephish,
 
 It's slightly difficult to replace a single line of a file if all of
 the
 lines are different lengths.
 
 But if you can hold the whole file in memory at once, then the
 following
 should work:
 
 readlines() the file's contents into a list.
 
 Do changes on that list of lines.
 
 writelines() all the lines back out.
 
 So the idea is that we use an intermediate list and do all our work on
 that list first.  We treat the files just as storage.
 
 Does this make sense?  Please feel free to ask more questions about
 this.
 
 
 
 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] confusing smtp problem

2005-07-21 Thread nephish
ok this is what i get when i use host = '10.10.10.04 25'
resourse unavailable
  line = self.sock.recv(size,socket.MSG_PEEK)

now if i use host = '10.10.10.04:25' it has all the appearences of
having worked, but the email never gets to its destination.

h.

i tried it the first way because that is what let me connect and
do the helo thing via telnet.


On 07/21/2005 09:21:14 AM, Reed L. O'Brien wrote:
 nephish wrote:
  Sorry about the delay getting back on this one guys,
  yeah, i am running a linux machine.
  no firewall between here and there (both behind a firewall router)
  yeah, sylpheed does send on port 25
  the windows machine has the Merek email server on board.
  i would like my scripts to be able to send to it,
  as a backup, but the debian linux MTA (Exim i think) is working.
  So it isn't too big a deal if it does not.
  telnet and helo does work, it lets me in from the command line
  from the linux machine (where my python scripts are) to the win
  machine (where the other mail server is)
 
  we dont need POP for this at all, we are sending only.
 
  incidentally, i appreciate you guys time and attention to this.
 
  all the best,
  shawn
 
 
 
 Does it still give the same error
 
  ib.py, line 347, in getreply
  raise SMTPServerDisconnected(Connection unexpectedly closed)
  SMTPServerDisconnected: Connection unexpectedly closed
 
  or is it different??
 
  ~reed
 
 --
 4.6692916090
 'cmVlZG9icmllbkBnbWFpbC5jb20=\n'.decode('base64')
 http://www.spreadfirefox.com/?q=affiliatesamp;id=16474amp;t=1
 keyID: 0x0FA09FCE
 
 
 
 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] confusing smtp problem

2005-07-21 Thread nephish
sorry i am late on this one didnt get a chance to look at
it today, perhaps in the morning i will crack this open

thanks guys!



On Thu, 2005-07-21 at 15:17 +, nephish wrote:
 ok this is what i get when i use host = '10.10.10.04 25'
 resourse unavailable
   line = self.sock.recv(size,socket.MSG_PEEK)
 
 now if i use host = '10.10.10.04:25' it has all the appearences of
 having worked, but the email never gets to its destination.
 
 h.
 
 i tried it the first way because that is what let me connect and
 do the helo thing via telnet.
 
 
 On 07/21/2005 09:21:14 AM, Reed L. O'Brien wrote:
  nephish wrote:
   Sorry about the delay getting back on this one guys,
   yeah, i am running a linux machine.
   no firewall between here and there (both behind a firewall router)
   yeah, sylpheed does send on port 25
   the windows machine has the Merek email server on board.
   i would like my scripts to be able to send to it,
   as a backup, but the debian linux MTA (Exim i think) is working.
   So it isn't too big a deal if it does not.
   telnet and helo does work, it lets me in from the command line
   from the linux machine (where my python scripts are) to the win
   machine (where the other mail server is)
  
   we dont need POP for this at all, we are sending only.
  
   incidentally, i appreciate you guys time and attention to this.
  
   all the best,
   shawn
  
  
  
  Does it still give the same error
  
   ib.py, line 347, in getreply
   raise SMTPServerDisconnected(Connection unexpectedly closed)
   SMTPServerDisconnected: Connection unexpectedly closed
  
   or is it different??
  
   ~reed
  
  --
  4.6692916090
  'cmVlZG9icmllbkBnbWFpbC5jb20=\n'.decode('base64')
  http://www.spreadfirefox.com/?q=affiliatesid=16474t=1
  keyID: 0x0FA09FCE
  
  
  
  
 
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] confusing smtp problem

2005-07-20 Thread nephish
Hey there, i am trying to get an email through an SMTP server on a  
windows computer from a linux machine on the same network.

 import smtplib
 import MySQLdb
 Server = smtplib.SMTP('10.10.10.32')
 ToAddress = '[EMAIL PROTECTED]'
 FromAddress = '[EMAIL PROTECTED]'
 Message = 'Some text message'
 Server.sendmail(FromAddress, ToAddress, Message)
{}

but nothing goes through,
now if i do this...
 Server.connect()

i get this

Traceback (innermost last):
   File stdin, line 1, in ?
   File /usr/lib/python2.3/smtplib.py, line 303, in connect
 (code, msg) = self.getreply()
   File /usr/lib/python2.3/smtplib.py, line 347, in getreply
 raise SMTPServerDisconnected(Connection unexpectedly closed)
SMTPServerDisconnected: Connection unexpectedly closed

now if i use the server on this computer ('localhost')
everything works ok.

any ideas?
thanks,


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] confusing smtp problem

2005-07-20 Thread nephish
Sorry about the delay getting back on this one guys,
yeah, i am running a linux machine.
no firewall between here and there (both behind a firewall router)
yeah, sylpheed does send on port 25
the windows machine has the Merek email server on board.
i would like my scripts to be able to send to it,
as a backup, but the debian linux MTA (Exim i think) is working.
So it isn't too big a deal if it does not.
telnet and helo does work, it lets me in from the command line 
from the linux machine (where my python scripts are) to the win
machine (where the other mail server is)

we dont need POP for this at all, we are sending only.

incidentally, i appreciate you guys time and attention to this.

all the best,
shawn



On Wed, 2005-07-20 at 19:38 -0400, Reed L. O'Brien wrote:
 nephish wrote:
  ok, my fault. the router assigned the smtp server a different address
  no longer 10.10.10.32, now 10.10.10.04
  tried the telnet thing and it worked, so i still dont know
  why the script isnt working
 
  thanks
 Does it still give the same error
 
 ib.py, line 347, in getreply
 raise SMTPServerDisconnected(Connection unexpectedly closed)
 SMTPServerDisconnected: Connection unexpectedly closed
 
 or is it different??
 
 ~reed
 
 
 
 
  On 07/20/2005 03:32:10 PM, Reed L. O'Brien wrote:
  nephish wrote:
   On 07/20/2005 12:24:04 PM, Reed L. O'Brien wrote:
   nephish wrote:
Hey there, i am trying to get an email through an SMTP server on
  a
windows computer from a linux machine on the same network.
   
   
import smtplib
import MySQLdb
Server = smtplib.SMTP('10.10.10.32')
ToAddress = '[EMAIL PROTECTED]'
FromAddress = '[EMAIL PROTECTED]'
Message = 'Some text message'
Server.sendmail(FromAddress, ToAddress, Message)
   
{}
   
but nothing goes through,
now if i do this...
   
Server.connect()
   
   
i get this
   
Traceback (innermost last):
   File stdin, line 1, in ?
   File /usr/lib/python2.3/smtplib.py, line 303, in connect
 (code, msg) = self.getreply()
   File /usr/lib/python2.3/smtplib.py, line 347, in getreply
 raise SMTPServerDisconnected(Connection unexpectedly
  closed)
SMTPServerDisconnected: Connection unexpectedly closed
   
now if i use the server on this computer ('localhost')
everything works ok.
   
any ideas?
thanks,

   
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
   
   Can you telnet to port 25  on the other server?
   What does it respond to an EHLO command?
   HELO?
   can you get it to deliver there?
  
   ~r
  
   --
   4.6692916090
   'cmVlZG9icmllbkBnbWFpbC5jb20=\n'.decode('base64')
   http://www.spreadfirefox.com/?q=affiliatesid=16474t=1
   keyID: 0x0FA09FCE
  
  
  
  
   i did this
   telnet 10.10.10.32
   it responded with unable to connect to remote host, connection
  refused
  
   hmmm, perhaps there is something i am missing here.
   this computer sits at 10.10.10.24
   the mail server is at 10.10.10.32
   and the other computer on the lan that can use it effectivly is at
   10.10.10.5 maybe the program it is using is passing some sort of
   parameter that i am missing here.
  
   will check it all out again.
  
   thanks
  
  That would be
  use the IP you choose in lieu of localhost
  The 25 tels  it to connect to the smtp port
  telnet localhost 25
  Trying 127.0.0.1...
  Connected to localhost.localdomain (127.0.0.1).
  Escape character is '^]'.
  220 my.dom.com ESMTP
  EHLO any.com
  250-my.dom.com
  250-AUTH LOGIN CRAM-MD5 PLAIN
  250-AUTH=LOGIN CRAM-MD5 PLAIN
  250-STARTTLS
  250-PIPELINING
  250 8BITMIME
 
  Try HELO if EHLO doesn't work.  If you can't connect at all, no smtp
  server is running; or it is running on a non-standard port.
 
  best,
  ~r
 
 
  -- 
  4.6692916090
  'cmVlZG9icmllbkBnbWFpbC5jb20=\n'.decode('base64')
  http://www.spreadfirefox.com/?q=affiliatesid=16474t=1
  keyID: 0x0FA09FCE
 
 
 
 
 
 
 
 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] This should be easy

2005-07-18 Thread nephish
Hey there,

i have a script that i am trying to use to add a record to a MySQL
database.

i keep getting a syntax error.

this works
cursor.execute(INSERT INTO Table ( numberone ) VALUES ( 'one');)

but this does not
cursor.execute(INSERT INTO Table ( numberone, numbertwo ) VALUES
( 'one','two');)

what is getting scrambled here?

the error i get is syntax error in MySQL query, check the documentation,
blah blah blah

thanks


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] This should be easy

2005-07-18 Thread nephish
ok here is the error i am getting.
You have an error in your SQL syntax. Check the manual that corrosponds  
to your MySQL version for the right syntax near Name ) values ('one',  
'two')

thanks

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] This should be easy

2005-07-18 Thread nephish
Hey! looks like that is what the problem was.
i used the MySQL Migration toolkit to transfer all the records
over from Access to MySQL.
man, you really saved me a lot of time and frustration.
should have written in about 6 hours ago
thank you very much.


On 07/18/2005 03:41:59 PM, Alberto Troiano wrote:
 Hey
 
 Your problem is in the database
 I'm surprised how MySQL let you put a space in a field
 In MySQL you can't have spaces, as far as I know
 Try renaming the field by enteriig to the console and making the  
 alter table sentence and put Site_Name instead of Site Name. Then  
 make the query again and see what happens
 
 mysql create table d(autoinc int(4) primary key,Site Name  
 varchar(30));
 ERROR 1064: You have an error in your SQL syntax.  Check the manual  
 that corresponds to your MySQL server version for the right syntax to  
 use near 'Name varchar(30))'
 
 This is the error I get from MySQL Server when I try to create a  
 field with a space and check the solution:
 mysql create table d(autoinc int(4) primary key,Site_Name  
 varchar(30));
 Query OK, 0 rows affected (0.14 sec)
 
 This should fix your problem.
 
 Best Regards to you
 
 Alberto
 
 From: nephish [EMAIL PROTECTED]
 To: Alberto Troiano [EMAIL PROTECTED]
 CC: tutor@python.org
 Subject: Re: [Tutor] This should be easy
 Date: Mon, 18 Jul 2005 20:32:55 +
 
 ok here is what i have,
 cursor.execute(INSERT INTO History (autoinc, Site Name) VALUES
 (12, 'Test');)
 
 gives me this
 ''' _mysql_exceptions.ProgrammingError : (1064, You have an error in
 your SQL syntax.  Check the manual that corresponds to your MySQL
 server version for the right syntax to use near 'Name) VALUES  
 (12,
 'Test')' at line 1) '''
 
 the autoinc field isn't really an auto-increment field, its an int.
 That is left over from the migration from Access.
 
 there are other fields in the table but all can be null.
 
 this line works fine though
 cursor.execute(INSERT INTO History (autoinc) VALUES (12);)
 
 this line does not
 cursor.execute(INSERT INTO History (Site Name) VALUES ('test');)
 
 can you not have spaces in a field name ? is the quotes gone awry?
 
 dont know what to do next.
 please help !
 
 thanks
 
 
 
 
 On 07/18/2005 03:06:34 PM, Alberto Troiano wrote:
  I think it would be better for us if you send us the entire line
  that's giving you problems along with the error its givin you so we
  can start somewhere
 
  Right now I don't know where to look at
 
  Best Regards
 
  Alberto
 
  From: nephish [EMAIL PROTECTED]
  To: tutor@python.org
  Subject: [Tutor] This should be easy
  Date: Mon, 18 Jul 2005 20:02:38 +
 
  ok here is the error i am getting.
  You have an error in your SQL syntax. Check the manual that
  corrosponds
  to your MySQL version for the right syntax near Name ) values  
 ('one',
  'two')
 
  thanks
 
  ___
  Tutor maillist  -  Tutor@python.org
  http://mail.python.org/mailman/listinfo/tutor
 
 
  Gaucho
 
 
 
 
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor
 
 
 Gaucho
 
 
 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] search through a list

2005-07-04 Thread nephish
Danny Yoo wrote:

  

#this function returns the number of lines on record for each log file.
def line_finder(LogsInDir, flag):
flag=flag.strip()
return_next=False
for line in LogsInDir:
if return_next:
return line.strip()
else:
if line.strip() == flag:
return_next = True




Hi Nephish,

Question: what should the program return if return_next is never True?
That is, what happens if the program does not find the flag that you're
looking for?

The comment of this function also seems a bit weird: it appears to try to
return the very next line after the 'flag' line of a file: it's not doing
any counting of numbers, as far as I can tell.


  

the line in question is this one:

NumLinesOnFile=line_finder(LogsRead, LogsInDir[NextLog])
print NumLinesOnFile

if i run this in idle printing NumLinesOnFile gives me a string 14



The function will return None if 'flag' can't be found in the LogsRead
list.  Otherwise, it'll return one of the lines of the file.

So I'd assume for the moment that line_finder can't find what it is trying
to find.  You may want to test this yourself by adding some kind of
debugging statement in line_finder() to make it more clear if t can't find
what it's looking for.  Does this sound reasonable?


Best of wishes to you!


  

Ok, if the return_next is never True, returning None is very useful.
If it is true, yes, i do want it to return the next line of the list.
this is a list of files. It is a file name, followed by the number of 
lines in the file,
this way i can only process the data that is new.

Your suggestion sounds reasonable and i will work with it with a few
more print statements to see exactly where it is failing.

maybe i had something messed up in my string that it is looking for that
wouldn't apply from IDLE.

Thanks for your help.

-shawn

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] search through a list

2005-07-03 Thread nephish
Hey there thanks,

quote:

/try

num_of_lines = line_find(LogsRead, PV050614.LOG)

I am binding num_of_lines to the return value. In an interactive 
session, without the binding, a non-None return value will display on 
screen. But both interactively and in a program binding it makes it 
easier to use later. Indeed, in a program, no binding - no later use.


/this is what worked out for me. i am trying to get as familliar as i 
can in idle because it lets me know as-it-happens when i have something 
messed up.

this put my pieces together.
thanks again
shawn 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] search through a list

2005-07-03 Thread nephish
Hey there, sorry to bother you again about this same problem
but i have a line of code in this same issue that works in idle
but it does not work in a regular script.

that same thing i am trying to do, reading the directory, comparing the 
list of files to a list . just want to catch the newest lines of a 
log file to process later.

here is what i have ( kinda long )


#!/usr/bin/python
# Update Database
import os
print ' '
print ' '

#get a list of log files in the directory
LogsInDir=os.listdir('/home/nephish/Projects/Piv_CGI/logs')

print LogsInDir #testing only, remove later

#read the contents of the log list
LogList = open('/home/nephish/Projects/Piv_CGI/LogList.txt', 'r')
LogsRead=LogList.readlines()
LogList.close()
print 'Lines of LogList.txt'
for i in LogsRead:
print i #testing only, remove later

#this function returns the number of lines on record for each log file.
def line_finder(LogsInDir, flag):
flag=flag.strip()
return_next=False
for line in LogsInDir:
if return_next:
return line.strip()
else:
if line.strip() == flag:
return_next = True


NumLogsInDir = len(LogsInDir)

NextLog = 0

while NextLog  NumLogsInDir:

print 'opening file '+LogsInDir[NextLog]
print ' '
Count_in_Log = 
open('/home/nephish/Projects/Piv_CGI/logs/'+LogsInDir[NextLog], r)

   
Defer = Count_in_Log.readlines()
Count_in_Log.close()

CountEmUp = len(Defer)
print 'number is '
print CountEmUp
   
NumLinesOnFile=line_finder(LogsRead, LogsInDir[NextLog])
print NumLinesOnFile
   
if CountEmUp  int(NumLinesOnFile):
print  +LogsInDir[NextLog]+ is longer than on record
XtraLines = int(NumLinesOnFile) - CountEmUp
print XtraLines
else:
print ' '+LogsInDir[NextLog]+ is not greater than on record
XtraLines=0
print XtraLines
NextLog=NextLog+1
print 'done' 
__

the line in question is this one:

NumLinesOnFile=line_finder(LogsRead, LogsInDir[NextLog])
print NumLinesOnFile

if i run this in idle printing NumLinesOnFile gives me a string 14

when run in a terminal it returns None

dont get it. is it because it is in a while loop?

any ideas would be awesome here.
thanks




___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] search through a list

2005-07-02 Thread nephish
hey there
i have a file that i want to read.
each line in the file is the name of a file.
the next line is how many lines are in that file.

example of loglist.txt

log1.txt
232
log2.txt
332
log3.txt
223

so log1 is a text file that has 232 lines in it.

ok, so what i want to do is read this file, see if the file i am looking 
for is in it
and if so, i need to know how many lines are in the file.

here is what i have so far.

import os

#get a list of Logs in logs folder
LogFiles = os.listdir('/home/nephish/Projects/Piv_GCI/logs')

#open the loglist file and read the lines
LogList = open('home/nephish/Projects/Piv/logs/LogList.txt', 'r')
LogsRead = LogList.readlines()

#see if there is  a new log file.
for i in LogFiles:
if LogFiles[i] not in LogList:
#if there is a new log, open it and read the lines
StrName=(LogFiles[i])
NewLog = open('/home/nephish/Projects/Piv_CGI/logs'+StrName,'r')
NewLogRead=NewLog.readlines()
#print the lines (testing only)
for x in NewLogRead:
print x
print '\n'
print '\n' #end for loop
else: #if the log file is not new,

um this is where i am stuck. i need search the LogList for the name of 
the name of the file in LogFiles and get the line number back so i can 
use it to compare with how many lines are in the log file so i can only 
process the data in the new lines ...  does this make sense ?

i need to find the item in a list, and when found, return the next line.

any takers?

thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] question about comma delineated text

2005-06-19 Thread nephish
Hey there,
i have some log files that i want to be able to work with.
the lines of the log files are comma - delineated.
i want to put those into a database where each piece of info (comma 
delineated)
would be the fields of the database.

ok, so the first obstacle is learning how to make a list or dictionary 
(prefer dictionary) out of
each line of the log.

any suggestions of where to start?

thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] database app

2005-06-18 Thread nephish
Hey there,

i have used the cgi module and dig it.
heres the deal,
my employer wants me to build a dynamic website that will access a 
database and display customer
information on web. ok, easy enough.
heres the trick.
the database is MS Access. - ick.
what could i do to manipulate data in an access database ? can it be 
done ?
all the research i have done just points me to sql, sqlite, etc...
i wouldnt mind if i can find a way to push everything from access to 
another kind of database,
but i dont know where to start.
any ideas?

-thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] database app

2005-06-18 Thread nephish
Exactly what i was looking for.
thanks gents, i didn't even know this module existed.

i guess this access project will not be as intimidating as i thought.

cheers
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor