Re: --> Running shell script with python
On 08/18/2016 11:16 AM, Lawrence D’Oliveiro wrote: On Thursday, August 18, 2016 at 8:00:51 PM UTC+12, gm wrote: os.system("python /home/pi/test/testserver.sh") command How to run shell ( not python ) script, from python code ? Take out the “python” from the command. :-) Damn :-). Thank you ! Tell me, do you know how can i send CTRl+C command from python to terminate this external shell script ? -- https://mail.python.org/mailman/listinfo/python-list
Raspberry model b --> program
Hi ! I have one small program that should be completed till tomorrow so if someone can help am ready to pay this ( btw. budget for this is $40 ). Project: - usb scanner is connected to the PI. - when the user gets his e.g. coffe bill with barcode, he put this bill in from of scanner and scanner reads value. If the value is the same as the value in database - GPIO is triggered and signal is send to relay board - relay board opens the parking ramp. The cash register PC and RPI are connected over lan cable and they are on the same network. When the compare is over we are deleting the file that is on the PC side but when the new bill will be created, the new csv file will be created too. So nothing special. One csv file with barcode is on the PC side and db is on the RPI side. What we have done so far: - part for reading the data from scanner - mysql db with defined tables - connection to DB - successful test for GPIO What i need: - to hook up all this together and to test it. RPI is connected to my PC over SSH so there is no problem to make some "remote programming" and testing. If there is someone who can help, i am willing to pay for this. G. -- https://mail.python.org/mailman/listinfo/python-list
lotto number generator
Hi. I am new to python so am still in learning phase. I was thinking to make one program that will print out all possible combinations of 10 pairs. I think this is a good way for something "bigger" :-). This is how this looks like: 1.) 1 2 2.) 1 2 3.) 1 2 4.) 1 2 5.) 1 2 6.) 1 2 7.) 1 2 8.) 1 2 9.) 1 2 10.) 1 2 So, i want to print out (in rows) each possible configuration but for all 10 pairs. example: 1 1 1 2 2 2 2 1 1 1 2 2 2 1 1 1 1 2 2 2 1 1 2 2 1 1 2 2 1 1 etc. What would be the best way to make something like this ? Maybe some tutorial ? GM -- https://mail.python.org/mailman/listinfo/python-list
Convert to big5 to unicode
Dear all, Could you all give me some guide on how to convert my big5 string to unicode using python? I already knew that I might use cjkcodecs or python 2.4 but I still don't have idea on what exactly I should do. Please give me some sample code if you could. Thanks a lot Regards, Gary -- http://mail.python.org/mailman/listinfo/python-list
Problem on getting various character set from pop3.retr
Dear all, The problem that I am facing now is that, when I use poplib to get a email message with chinese character set like big5, the character string is changed automatically to sth like =B8=D5=ACQ=AAM...the OS I am using is red hat ES4 and the python version I am using is 2.3.4 (it seems python 2.4 is not available for red hat). My application goal is to receive the email and convert all character set to UTF-8 and then store in file. Solong way to go for me, please give me some help for that, thx~ Regards, Gary -- http://mail.python.org/mailman/listinfo/python-list
Trapping the segfault of a subprocess.Popen
All, I need to run a third-party binary from a python script and retrieve its output (and its error messages). I use something like >>> process = subprocess.Popen(options, stdout=subprocess.PIPE, >>> stderr=subprocess.PIPE) >>> (info_out, info_err) = process.communicate() That works fine, except that the third-party binary in question doesn't behave very nicely and tend to segfaults without returning any error. In that case, `process.communicate` hangs for ever. I thought about calling a `threading.Timer` that would call `process.terminate` if `process.wait` doesn't return after a given time... But it's not really a solution: the process in question can sometimes take a long time to run, and I wouldn't want to kill a process still running. I also thought about polling every x s and stopping when the result of a subprocess.Popen(["ps","-p",str(initialprocess.pid)], stdout=subprocess.PIPE) becomes only the header line, but my script needs to run on Windows as well (and no ps over there)... Any suggestion welcome, Thx in advance P. -- http://mail.python.org/mailman/listinfo/python-list
Re: Trapping the segfault of a subprocess.Popen
On Apr 7, 1:58 am, Nobody wrote: > On Wed, 06 Apr 2011 02:20:22 -0700, Pierre GM wrote: > > I need to run a third-party binary from a python script and retrieve > > its output (and its error messages). I use something like > >>>> process = subprocess.Popen(options, stdout=subprocess.PIPE, > > stderr=subprocess.PIPE) > >>>> (info_out, info_err) = process.communicate() > > That works fine, except that the third-party binary in question doesn't > > behave very nicely and tend to segfaults without returning any error. In > > that case, `process.communicate` hangs for ever. > > Odd. The .communicate method should return once both stdout and stderr > report EOF and the process is no longer running. Whether it terminates > normally or on a signal makes no difference. > > The only thing I can think of which would cause the situation which you > describe is if the child process spawns a child of its own before > terminating. In that case, stdout/stderr won't report EOF until any > processes which inherited them have terminated. I think you nailed it. Running the incriminating command line in a terminal doesn't return to the prompt. In fact, a ps shows that the process is sleeping in the foreground. Guess I should change the subject of this thread... > > I thought about calling a `threading.Timer` that would call > > `process.terminate` if `process.wait` doesn't return after a given > > time... But it's not really a solution: the process in question can > > sometimes take a long time to run, and I wouldn't want to kill a > > process still running. > > I also thought about polling every x s and stopping when the result of > > a subprocess.Popen(["ps","-p",str(initialprocess.pid)], > > stdout=subprocess.PIPE) becomes only the header line, but my script > > needs to run on Windows as well (and no ps over there)... > > It should suffice to call .poll() on the process. In case that doesn't > work, the usual alternative would be to send signal 0 to the process (this > will fail with ESRCH if the process doesn't exist and do nothing > otherwise), e.g.: > > import os > import errno > > def exists(process): > try: > os.kill(process.pid, 0) > except OSError, e: > if e.errno == errno.ESRCH: > return False > raise > return True OK, gonna try that, thx. > You might need to take a different approach for Windows, but the above is > preferable to trying to parse "ps" output. Note that this only tells you > if /some/ process exists with the given PID, not whether the original > process exists; that information can only be obtained from the Popen > object. -- http://mail.python.org/mailman/listinfo/python-list
Re: Trapping the segfault of a subprocess.Popen
On Apr 7, 5:12 am, Terry Reedy wrote: > On 4/6/2011 7:58 PM, Nobody wrote: > > > On Wed, 06 Apr 2011 02:20:22 -0700, Pierre GM wrote: > > >> I need to run a third-party binary from a python script and retrieve > >> its output (and its error messages). I use something like > >>>>> process = subprocess.Popen(options, stdout=subprocess.PIPE, > >> stderr=subprocess.PIPE) > >>>>> (info_out, info_err) = process.communicate() > >> That works fine, except that the third-party binary in question doesn't > >> behave very nicely and tend to segfaults without returning any error. In > >> that case, `process.communicate` hangs for ever. > > I am not sure this will help you now, but > Victor Stinner has added a new module to Python 3.3 that tries to catch > segfaults and other fatal signals and produce a traceback before Python > disappears. Unfortunately, I'm limited to Python 2.5.x for this project. But good to know, thanks... -- http://mail.python.org/mailman/listinfo/python-list
Re: Thunderbird access to this newsgroup
On Jun 18, 1:23 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > You might find, as many others do, that it's convenient to read this > group using the Gmane service - it's group gmane.comp.python.general on > server news.gmane.org. I tried news.gmane.org in Thunderbird and I keep on getting a error saying it can not find the server. Your friend, Scott -- http://mail.python.org/mailman/listinfo/python-list
C Python Network Performance
Hello, I am writing an application bulk of which is sending and receving UDP data. I was evaluating which language will be a better fit for the job. I wrote following small pieces of code in Python and C respectively: from socket import * import sys if __name__ == '__main__': s = socket(AF_INET, SOCK_DGRAM) while True: s.sendto("hello", (sys.argv[1], int(sys.argv[2]))) #include #include #include #include #include #define true 1 #define false 0 int main(int len, char** args){ int s = socket(AF_INET, SOCK_DGRAM, 0); struct sockaddr_in s_addr; inet_pton(AF_INET, args[1], &(s_addr.sin_addr)); printf("%s:%s\n", args[1], args[2]); in_port_t port; sscanf(args[2], "%u", &port); s_addr.sin_port = htons(port); s_addr.sin_family = AF_INET; char* msg = "hello"; int msg_len = 6; int addr_len = sizeof(struct sockaddr); struct sockaddr* s_g_addr = (struct sockaddr*) &s_addr; while(true){ int success = sendto(s, msg, msg_len, 0, s_g_addr, addr_len); } } Both pieces of code, take IP address and port on command line initely send UDP messages to the target. In this experiment target is another machine of mine and I record the data rate received at that machine. I was surpirised to see that python code was able to achieve 4-10 times higher data rate than C. I was expecting C code to perform the same, if not better. Can anyone please explain why this is the case? Thanks Ghulam Memon - Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online.-- http://mail.python.org/mailman/listinfo/python-list
Re: what is wrong with my python code?
On Wednesday 07 February 2007 12:43:34 Dongsheng Ruan wrote: > I got feed back saying" list object is not callable". But I can't figure > out what is wrong with my code. > for i in range(l): > print A(i) You're calling A, when you want to access one of its elements: use the straight brackets [ for i in range(l): print A[i] -- http://mail.python.org/mailman/listinfo/python-list
Logging exceptions to a file
All, I need to log messages to both the console and a given file. I use the following code (on Python 2.5) >>> import logging >>> # >>> logging.basicConfig(level=logging.DEBUG,) >>> logfile = logging.FileHandler('log.log') >>> logfile.setLevel(level=logging.INFO) >>> logging.getLogger('').addHandler(logfile) >>> # >>> mylogger = logging.getLogger('mylogger') >>> # >>> mylogger.info("an info message") So far so good, but I'd like to record (possibly unhandled) exceptions in the logfile. * Do I need to explicitly trap every single exception ? * In that case, won't I get 2 log messages on the console (as illustrated in the code below: >>> try: >>> 1/0 >>> except ZeroDivisionError: >>> mylogger.exception(":(") >>> raise Any comments/idea welcomed Cheers. -- http://mail.python.org/mailman/listinfo/python-list
Re: Logging exceptions to a file
On May 7, 5:32 am, Lie Ryan wrote: > Pierre GM wrote: > > All, > > I need to log messages to both the console and a given file. I use the > > following code (on Python 2.5) > > >>>> import logging > >>>> # > >>>> logging.basicConfig(level=logging.DEBUG,) > >>>> logfile = logging.FileHandler('log.log') > >>>> logfile.setLevel(level=logging.INFO) > >>>> logging.getLogger('').addHandler(logfile) > >>>> # > >>>> mylogger = logging.getLogger('mylogger') > >>>> # > >>>> mylogger.info("an info message") > > > So far so good, but I'd like to record (possibly unhandled) exceptions > > in the logfile. > > * Do I need to explicitly trap every single exception ? > > * In that case, won't I get 2 log messages on the console (as > > illustrated in the code below: > >>>> try: > >>>> 1/0 > >>>> except ZeroDivisionError: > >>>> mylogger.exception(":(") > >>>> raise > > > Any comments/idea welcomed > > Cheers. > > Although it is usually not recommended to use a catch-all except, this > is the case where it might be useful. JUST DON'T FORGET TO RE-RAISE THE > EXCEPTION. > > if __name__ == '__main__': > try: > main(): > except Exception, e: > # log('Unhandled Exception', e) > raise OK for a simple script, but the (unhandled) exceptions need to be caught at the module level. Any idea? -- http://mail.python.org/mailman/listinfo/python-list
Re: [Glitch?] Python has just stopped working
W dniu wtorek, 16 lutego 2016 21:09:50 UTC+1 użytkownik Theo Hamilton napisał: > I woke up two days ago to find out that python literally won't work any > more. I have looked everywhere, asked multiple Stack Overflow questions, > and am ready to give up. Whenever I run python (3.5), I get the following > message: > > Fatal Python error: Py_initialize: unable to load the file system codec > ImportError: No module named 'encodings' > > Current thread 0x2168 (most recent call first): > > If there's anything you know that I could do to fix this, then please tell > me. I've tried uninstalling and reparing, so it's not those. Thanks! You have to set your PYTHONHOME variable in Windows. for example PYTHONHOME='E:\Python36' I had the same problem and this worked. -- https://mail.python.org/mailman/listinfo/python-list