Is it more CPU-efficient to read/write config file or read/write sqlite database?

2013-12-14 Thread JL
I have a number of python processes which communicate with each other through 
writing/reading config text files. The python ConfigParser is used. I am 
wondering if it is more CPU-efficient to switch to using sqlite database 
instead of using configuration files. If the software does plenty of 
reading/writing, is it more efficient to use config text files or sqlite 
database?

Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Is it possible to mix python with php?

2013-12-13 Thread JL
Python is my favorite language. Very often, I am forced to use other languages 
like php because of better library support for web applications. Is it possible 
to write functions in python and then get php to call these functions?

Thank you
-- 
https://mail.python.org/mailman/listinfo/python-list


Is there any advantage to using a main() in python scripts?

2013-12-11 Thread JL
Python scripts can run without a main(). What is the advantage to using a 
main()? Is it necessary to use a main() when the script uses command line 
arguments? (See script below)

#!/usr/bin/python

import sys

def main():
# print command line arguments
for arg in sys.argv[1:]:
print arg

if __name__ == __main__:
main()
-- 
https://mail.python.org/mailman/listinfo/python-list


How to catch error messages in ftplib?

2013-11-19 Thread JL
I have the following code;

try:
session = FTP(ftp_server_ip,ftp_user,ftp_password)
file = open(filename,'rb') # file to send
session.storbinary('STOR ' +  filename, file) # send the file
except Exception, errObj:
print Exception
print errObj
file.close() # close file and FTP
session.quit()

I deliberately placed an invalid ip address for the ftp_server_ip to see 
whether error messages can be caught. However, no exception was thrown. Can 
someone more experienced point to me what did I do wrong?

Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to catch error messages in ftplib?

2013-11-19 Thread JL
I repost the original code segment to make it more complete;

from ftplib import FTP
try:
session = FTP(ftp_server_ip,ftp_user,ftp_password)
file = open(filename,'rb') # file to send
session.storbinary('STOR ' +  filename, file) # send the file
except Exception, errObj:
print Exception
print errObj
file.close() # close file and FTP
session.quit()

On Tuesday, November 19, 2013 6:18:07 PM UTC+8, JL wrote:
 I have the following code;
 
 
 
 try:
 
 session = FTP(ftp_server_ip,ftp_user,ftp_password)
 
 file = open(filename,'rb') # file to send
 
 session.storbinary('STOR ' +  filename, file) # send the file
 
 except Exception, errObj:
 
 print Exception
 
 print errObj
 
 file.close() # close file and FTP
 
 session.quit()
 
 
 
 I deliberately placed an invalid ip address for the ftp_server_ip to see 
 whether error messages can be caught. However, no exception was thrown. Can 
 someone more experienced point to me what did I do wrong?
 
 
 
 Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Implementing #define macros similar to C on python

2013-11-15 Thread JL
Thanks! This is the answer which I am seeking. However, I am not able to get 
the following line to work. I am using python 2.7.5

debug_print = print

Can we assign a function into a variable in this manner?

On Friday, November 15, 2013 11:49:52 AM UTC+8, Chris Angelico wrote:
 On Fri, Nov 15, 2013 at 1:29 PM, JL lightai...@gmail.com wrote:
 
  One of my favorite tools in C/C++ language is the preprocessor macros.
 
 
 
  One example is switching certain print messages for debugging use only
 
 
 
  #ifdef DEBUG_ENABLE
 
  DEBUG_PRINT   print
 
  #else
 
  DEBUG_PRINT
 
 
 
  Is it possible to implement something similar in python? Thank you.
 
 
 
 There are usually other ways to do things. For instance, you can
 
 define a function to either do something or do nothing:
 
 
 
 if debug_mode:
 
 debug_print = print
 
 else:
 
 debug_print = lambda: None
 
 
 
 debug_print(This won't be shown unless we're in debug mode!)
 
 
 
 But as Dave says, you could write a preprocessor if you need one.
 
 
 
 ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Implementing #define macros similar to C on python

2013-11-15 Thread JL
On Saturday, November 16, 2013 8:22:25 AM UTC+8, Mark Lawrence wrote:

 Yes but please don't top post.  Actually print is a statement in Python 
 2 so your code should work if you use
 from __future__ import print_function
 at the top of your code.
 Would you also be kind enough to read and action this 
 https://wiki.python.org/moin/GoogleGroupsPython to prevent the double 
 line spacing shown above, thanks.

Thank you for the tip. Will try that out. Hope I get the posting etiquette 
right this time.
-- 
https://mail.python.org/mailman/listinfo/python-list


Implementing #define macros similar to C on python

2013-11-14 Thread JL
One of my favorite tools in C/C++ language is the preprocessor macros.

One example is switching certain print messages for debugging use only

#ifdef DEBUG_ENABLE
DEBUG_PRINT   print
#else
DEBUG_PRINT

Is it possible to implement something similar in python? Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Implementing a multivibrator function with python

2013-11-12 Thread JL
I am actually running python on raspberry pi. The trigger event is a 
button-press.

On Monday, November 11, 2013 6:56:03 PM UTC+8, Dave Angel wrote:
 On Mon, 11 Nov 2013 01:41:58 -0800 (PST), JL lightai...@gmail.com 
 
 wrote:
 
  - If the event happens again before the 5secs expire, the high 
 
 duration will be extended by another 5 secs. This works like a 
 
 retriggerable multivibrator for those who are into electronics.
 
 
 
 More precisely a retriggerable monostable multivibrator.
 
 
 
 The question makes little sense unless you're running in an event 
 
 driven environment, such as a gui. Name the environment and somebody 
 
 can probably help.
 
 
 
 -- 
 
 DaveA
-- 
https://mail.python.org/mailman/listinfo/python-list


Implementing a multivibrator function with python

2013-11-11 Thread JL
I am trying to implement a multivibrator function with python. This is how it 
works; 

- An trigger event happens
- Upon receiving the event, a variable goes high for 5secs, then go low.
- If the event happens again before the 5secs expire, the high duration will be 
extended by another 5 secs. This works like a retriggerable multivibrator for 
those who are into electronics. 

Is there some sample code for this problem or can someone point me to using the 
right library for this feature?

Thank you very much.
-- 
https://mail.python.org/mailman/listinfo/python-list


Multiple scripts versus single multi-threaded script

2013-10-03 Thread JL
What is the difference between running multiple python scripts and a single 
multi-threaded script? May I know what are the pros and cons of each approach? 
Right now, my preference is to run multiple separate python scripts because it 
is simpler.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyGame, window is not closing, tut not helping

2008-05-12 Thread JL
If the game runs normally without IDLE, then, to run it from IDLE, add
pygame.quit() at the end of the script:

if __name__ == __main__:
MainWindow = PyManMain()
MainWindow.MainLoop()
pygame.quit()

... and just before the sys.exit():

def MainLoop(self):
This is the Main Loop of the Game
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
--
http://mail.python.org/mailman/listinfo/python-list


pickle and __slots__

2007-10-04 Thread JL
Hello,

I am trying to pickle an object, and I get:

TypeError: a class that defines __slots__ without defining
__getstate__ cannot be pickled

I didn't find __slots__ in the object or the class. Is there a way to
find it, or to to know which object or class causes the problem?

Thanks

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


Re: pickle and __slots__

2007-10-04 Thread JL
 Is this a subclass?  Look at the parent classes.

Its class is a subclass of a similar class, but it indirectly
references instances of subclasses of asyncore.dispatcher or
asynchat.async_chat. I don't think there are other particular classes.
If I remove the first references, pickle works. Anyway it seems that I
will have to mask the asyncore.dispatcher and asynchat.async_chat
subclass instances which will not be relevant at unpickle time.

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


Re: pickle and __slots__

2007-10-04 Thread JL
I added the following method to the 2 subclasses of
asyncore.dispatcher and asynchat.async_chat and now pickle works:

def __getstate__(self):
return

Later I will probably modify this method so it returns something more
interesting.
Thanks for your help! I was confused because I am not sure what can be
pickled or not.

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