Sort dictionary

2006-01-02 Thread Markus Franz
Hi! I have: x = {'a':3, 'b':2, 'c':4} How can I sort x by value? (I tried using sorted() with x.items() - but I didn't get a dictionary as response.) My second question: How can I reduce the dictionary to 2 items (so delete everything after the first two items) Thanks in advance. Best regards

Re: cpu usage limit

2005-05-27 Thread Markus Franz
> Are you looping during a cpu intensive task? If so, make it sleep a bit > like this: > > for x in cpu_task: > time.sleep(0.5) > do(x) No, I don't use an intensive loop. I have about 1200 lines of code inside a process - is there nothing like xyz.setlimit(xyz.cpu, 0.30) ??? Thank. M

Use string in URLs

2005-04-07 Thread Markus Franz
Hi. I want to use the string "rüffer" in a get-request, so I tried to encode it. My problem: But with urllib.quote I always get "r%FCffer", but I want to get "r%C3%BCffer" (with is correct in my opinion). Thanks. Markus -- http://mail.python.org/mailman/listinfo/python-list

Re: Get document as normal text and not as binary data

2005-03-29 Thread Markus Franz
Kent Johnson wrote: My guess is the html is utf-8 encoded - your sample looks like utf-8-interpreted-as-latin-1. Try contents = f.read().decode('utf-8') YES! That helped! I used the following: ... contents = f.read().decode('utf-8') contents = contents.encode('iso-8859-15') ... That was the perfec

Re: Get document as normal text and not as binary data

2005-03-29 Thread Markus Franz
Diez B. Roggisch wrote: Addendum: If you give us the url you're fetching data from, we might be able to look at the delivered data ourselves. To guess my problem please have a look at the document title of Markus -- http://mail.python.org/mailman/l

Re: Get document as normal text and not as binary data

2005-03-28 Thread Markus Franz
Diez B. Roggisch wrote: You get what the server sends. That is always binary - either it _is_ a binary file, or maybe in an unknown encoding. And how can I convert those binary data to a "normal" string with "normal" characters? Best regards Markus -- http://mail.python.org/mailman/listinfo/pyth

Get document as normal text and not as binary data

2005-03-27 Thread Markus Franz
Hi. I used urllib2 to load a html-document through http. But my problem is: The loaded contents are returned as binary data, that means that every character is displayed like lÀÃt, for example. How can I get the contents as normal text? My script was: import urllib2 req = urllib2.Request(url) f

Re: Embedding Python

2005-03-26 Thread Markus Franz
Diez B. Roggisch wrote: /home/mmf/tmp/ccVD2V4h.o(.text+0x1d): In function `main': : undefined reference to `Py_Initialize' /home/mmf/tmp/ccVD2V4h.o(.text+0x2a): In function `main': : undefined reference to `PyRun_SimpleString' /home/mmf/tmp/ccVD2V4h.o(.text+0x32): In function `main': : undefined re

Embedding Python

2005-03-26 Thread Markus Franz
Hi! I wanted to run some Python code from inside a C program, so I did it like it was explained in the Python manual: #include int main(int argc, char *argv[]) { Py_Initialize(); PyRun_SimpleString("print 'Hallo World!'\n"); Py_Finalize(); return 0; } Then I trie

Handle user abort inside of a CGI-script

2005-02-25 Thread Markus Franz
Hallo! I use Python mostly for CGI (Apache). And now I habe a problem: How can I handle the situation if a user clicks on "abort" in the browser? It seems that a CGI-script is NOT stopped at this point. Is there any signal send to the CGI-process if the user clicks on "abort"? Thank you. Best r

Handle user abort

2005-02-25 Thread Markus Franz
Hallo! I use Python mostly for CGI (using Apache). And now I habe a problem: How can I handle the situation if a user clicks on ?abort? in the browser? It seems that a CGI-script is NOT stopped at this point. Is there any signal send to the CGI-process if the user clicks on ?abort?? Thank you. Be

Execute code after death of all child processes - (corrected posting)

2004-12-25 Thread Markus Franz
Hallo! I have a problem with this little script written in Python: import sys, os, time texts = ['this is text1', 'this is text 2'] for current_text in env_sources[0:]: pid = os.fork() if pid == 0: time.sleep(2) print current_text break As you is create some child processes depending o

Execute code after death of all child processes

2004-12-24 Thread Markus Franz
Hallo! I have a problem with this little script written in Python: import sys, os, time texts = ['this is text1', 'this is text 2'] for current_text in env_sources[0:]: pid = os.fork() if pid == 0: time.sleep(2) print current_text

Processes and their childs

2004-12-21 Thread Markus Franz
Hi! Inside a Python script (I use Python 2.4) several different child processes are created by using os.fork(). My problem: I want only the parent process to print some output and then create the child processes. But even If I use print BEFORE using os.fork, everything that was printed by the pa

Change vars in the parent process

2004-12-21 Thread Markus Franz
Hi! Is there any possibility to change vars inside a parent process from the inside of a child process? Thanks Markus -- http://mail.python.org/mailman/listinfo/python-list