Re: What's the difference between str and 'hello' ?
hong Yu wrote:
> I am new to python.
> I was confused:
>
> >>> a = list('hello')
>
> >>> a
> ['h', 'e', 'l', 'l', 'o']
>
> I want to combine the items in the list into a string.
> So:
>
> >>> ''.join(a)
> 'hello'
>
> but:
>
> >>> str.join(a)
> Traceback (most recent call last):
> File "", line 1, in ?
> TypeError: descriptor 'join' requires a 'str' object but received a
'list'
>
> So why TypeError raised?
> and
> What's the difference between str and 'hello' ?
>
> Thanks a lot.
str is a class, 'hello' is instance of the class; the method join
expects to receive an instance as its first parameter so:-
>>> str.join( '', a )
'hello'
Regards, Paul
--
http://mail.python.org/mailman/listinfo/python-list
Re: security code whit python
On 10 Nov, 16:04, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > hii my friends; > I want to create picture of security code.can i do it ? > if yes,how , which module will help me? > have you got a example that can create a picture whit my name > pls help me > thansk > oruc You may find the Python Imaging Library (PIL) useful. See http://www.pythonware.com/products/pil/. It has an extensive handbook which includes drawing text on to an image. regards, Paul Clinch -- http://mail.python.org/mailman/listinfo/python-list
Re: Bitmap editor and File-saving
On 10 Nov, 15:44, Johnston Jiaa <[EMAIL PROTECTED]> wrote: > In my Python program (using Tkinter), I would like to have a window > where the user will be able to draw a simple picture. I don't know > where to begin.. can somehow give me a general idea how to do > something like this? > > Also, I'd like for the program to save that picture along with some > text. What would be the best way to go about doing this? Is > pickling a viable option? > > Thanks in advance, > Johnston The Canvas widget provides structured graphics facilities for Tkinter. At http://infohost.nmt.edu/tcc/help/pubs/tkinter.pdf is a useful manual. Regards, Paul Clinch -- http://mail.python.org/mailman/listinfo/python-list
Re: Writing a CGI to query DB
On 10 Nov, 04:33, Bighead <[EMAIL PROTECTED]> wrote: > Hi, > > I am currently working on a CGI deployed on an Apache server, which, > given an arbitrary SQL, fetches raw data from a remote DB server and > return them in a HTML page. This CGI works fine on quick SQLs. > > But when I try to run a slow SQL on this CGI, through a Squid Proxy, I > always get the Error message from Squid: Zero Sized Reply, after 5 > minutes. > > The SQL itself is correct, since I have tried it directly on the DB > server. So what do you think might cause the problem? Thank you. This sounds a lot like an apache server configuration problem. From the squid FAQ; 11.51 Why do I sometimes get ``Zero Sized Reply''? This happens when Squid makes a TCP connection to an origin server, but for some reason, the connection is closed before Squid reads any data. Depending on various factors, Squid may be able to retry the request again. If you see the ``Zero Sized Reply'' error message, it means that Squid was unable to retry, or that all retry attempts also failed. The apache server has a default TimeOut of 300 seconds. This question might be more usefully answered by the apache user group. Regards, Paul Clinch -- http://mail.python.org/mailman/listinfo/python-list
Re: multiprocessing deadlock
On Oct 23, 3:18 am, Brian Quinlan wrote:
> My test reduction:
>
> import multiprocessing
> import queue
>
> def _process_worker(q):
> while True:
> try:
> something = q.get(block=True, timeout=0.1)
> except queue.Empty:
> return
> else:
> print('Grabbed item from queue:', something)
>
> def _make_some_processes(q):
> processes = []
> for _ in range(10):
> p = multiprocessing.Process(target=_process_worker, args=(q,))
> p.start()
> processes.append(p)
> return processes
>
> def _do(i):
> print('Run:', i)
> q = multiprocessing.Queue()
> for j in range(30):
> q.put(i*30+j)
> processes = _make_some_processes(q)
>
> while not q.empty():
> pass
>
> # The deadlock only occurs on Mac OS X and only when these lines
> # are commented out:
> # for p in processes:
> # p.join()
>
> for i in range(100):
> _do(i)
>
> --
>
> Output (on Mac OS X using the svn version of py3k):
> % ~/bin/python3.2 moprocessmoproblems.py
> Run: 0
> Grabbed item from queue: 0
> Grabbed item from queue: 1
> Grabbed item from queue: 2
> ...
> Grabbed item from queue: 29
> Run: 1
>
> At this point the script produces no additional output. If I uncomment
> the lines above then the script produces the expected output. I don't
> see any docs that would explain this problem and I don't know what the
> rule would be e.g. you just join every process that uses a queue before
> the queue is garbage collected.
>
> Any ideas why this is happening?
>
> Cheers,
> Brian
I can't promise a definitive answer but looking at the doc.s:-
isAlive()
Return whether the thread is alive.
Roughly, a thread is alive from the moment the start() method
returns until its run() method terminates. The module function
enumerate() returns a list of all alive threads.
I guess that the word 'roughly' indicates that returning from the start
() call does not mean that all the threads have actually started, and
so calling join is illegal. Try calling isAlive on all the threads
before returning from _make_some_processes.
Regards, Paul C.
--
http://mail.python.org/mailman/listinfo/python-list
Re: multiprocessing deadlock
> > Hey Paul, > > I guess I was unclear in my explanation - the deadlock only happens > when I *don't* call join. > > Cheers, > Brian Whoops, my bad. Have you tried replacing prints with writing a another output Queue? I'm wondering if sys.stdout has a problem. Regards, Paul C. -- http://mail.python.org/mailman/listinfo/python-list
